From 985b230b636bf73f43a38e7c63e421bfc8de3913 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Fri, 4 Oct 2024 11:56:34 +0200 Subject: [PATCH 01/29] Update azure linux function app configuration --- .../onboarding-functions/.terraform.lock.hcl | 87 ------------------- .../env/dev-pnpg/terraform.tfvars | 2 + .../env/dev/terraform.tfvars | 14 +-- .../env/prod-pnpg/terraform.tfvars | 2 + .../env/prod/terraform.tfvars | 2 + .../env/uat-pnpg/terraform.tfvars | 2 + .../env/uat/terraform.tfvars | 2 + .../onboarding-functions/functions.tf | 12 +-- .../onboarding-functions/variables.tf | 4 + 9 files changed, 28 insertions(+), 99 deletions(-) delete mode 100644 infra/functions/onboarding-functions/.terraform.lock.hcl diff --git a/infra/functions/onboarding-functions/.terraform.lock.hcl b/infra/functions/onboarding-functions/.terraform.lock.hcl deleted file mode 100644 index 25baf19a8..000000000 --- a/infra/functions/onboarding-functions/.terraform.lock.hcl +++ /dev/null @@ -1,87 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/azuread" { - version = "2.30.0" - constraints = "2.30.0" - hashes = [ - "h1:Uw4TcmJBEJ71h+oCwwidlkk5jFpyFRDPAFCMs/bT/cw=", - "h1:WnSPiREAFwnBUKREokMdHQ8Cjs47MzvS9pG8VS1ktec=", - "zh:1c3e89cf19118fc07d7b04257251fc9897e722c16e0a0df7b07fcd261f8c12e7", - "zh:2e62c193030e04ebb10cc0526119cf69824bf2d7e4ea5a2f45bd5d5fb7221d36", - "zh:2f3c7a35257332d68b778cefc5201a5f044e4914dd03794a4da662ddfe756483", - "zh:35d0d3a1b58fdb8b8c4462d6b7e7016042da43ea9cc734ce897f52a73407d9b0", - "zh:47ede0cd0206ec953d40bf4a80aa6e59af64e26cbbd877614ac424533dbb693b", - "zh:48c190307d4d42ea67c9b8cc544025024753f46cef6ea64db84735e7055a72da", - "zh:6fff9b2c6a962252a70a15b400147789ab369b35a781e9d21cce3804b04d29af", - "zh:7646980cf3438bff29c91ffedb74458febbb00a996638751fbd204ab1c628c9b", - "zh:77aa2fa7ca6d5446afa71d4ff83cb87b70a2f3b72110fc442c339e8e710b2928", - "zh:e20b2b2c37175b89dd0db058a096544d448032e28e3b56e2db368343533a9684", - "zh:eab175b1dfe9865ad9404dccb6d5542899f8c435095aa7c679314b811c717ce7", - "zh:efc862bd78c55d2ff089729e2a34c1831ab4b0644fc11b36ee4ebed00a4797ba", - ] -} - -provider "registry.terraform.io/hashicorp/azurerm" { - version = "3.84.0" - constraints = ">= 3.30.0, <= 3.84.0, <= 3.85.0, <= 3.86.0" - hashes = [ - "h1:1Ucponuagrx5kNeIlcZwG2urqoRXBCTddDKqL265+xM=", - "h1:y/NWRLvnJmyJ5lf/AnLFy25jfyJqp6xwwxLxZnvovAs=", - "zh:14a96daf672541dbc27137d9cc0a96a737710597262ecaaa64a328eb1174e5df", - "zh:16d8e794fdd87ed8e64291fe8a617f420d8263f21672033333a020d06f4c9618", - "zh:64e5cd1bb6a81bccffff0d1f77790286ab46179cf12442134c3f3bca722afc1b", - "zh:7010ada67fbae971ac8b7204a30b1317aee7ccac7227afc6ac27277c642996a1", - "zh:77c2616ecd29685d2a4dc3ec3e9771e5ecf652e127946767d9b7ef19bbf58a21", - "zh:861922cfae724eacf1bd915efd5dbf6c23e4e762a2bbe60993099648e64aedb5", - "zh:8fb797c98bb08e7342995317810d28c41bb519fbc128adaa170896356b9eaebd", - "zh:982e85a4a9d282e3c8f7d7836037ccc98ff3ef50af246fad2e04684a81d16201", - "zh:a2ef29ff907cf6622e58afa0a27e23a3160ba3d70d531795b4d9a6c42c354630", - "zh:c46ccc4eecb79d096bcb652af0cffe300ec480d80a13a5b302c71b1aac9f9f1c", - "zh:cc6a06bf6d5e811fe8c0d9ad652e143b4e94bd16a03fb8a86f5086f0ae5abfa9", - "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - ] -} - -provider "registry.terraform.io/hashicorp/null" { - version = "3.2.2" - hashes = [ - "h1:IMVAUHKoydFrlPrl9OzasDnw/8ntZFerCC9iXw1rXQY=", - "h1:vWAsYRd7MjYr3adj8BVKRohVfHpWQdvkIwUQ2Jf5FVM=", - "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", - "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", - "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", - "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", - "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", - "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", - "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", - "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", - "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", - "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", - ] -} - -provider "registry.terraform.io/integrations/github" { - version = "5.18.3" - constraints = "5.18.3" - hashes = [ - "h1:WbZvLB2qXKVoh4BvOOwFfEds+SZQrkINfSAWPnWFxGo=", - "h1:rv3mwpUeJ0n13sY+KZMI25WAVCSeipX4n8JMWKD1XcE=", - "zh:050b37d96628cb7451137755929ca8d21ea546bc46d11a715652584070e83ff2", - "zh:053051061f1b7f7673b0ceffac1f239ba28b0e5b375999206fd39976e85d9f2b", - "zh:0c300a977ca66d0347ed62bb116fd8fc9abb376a554d4c192d14f3ea71c83500", - "zh:1d5a1a5243eba78819d2f92ff2d504ebf9a9008a6670fb5f5660f44eb6a156d8", - "zh:a13ac15d251ebf4e7dc40acb0e40df066f443f4c7799186a29e2e44addc7d8e7", - "zh:a316d94b885953c036ebc9fba64a23da93974746bc3ac9d207462a6f02d44540", - "zh:a658a00373bff5979cc227052c693cbde8ca4c8f9fef1bc8094a3516f2e2a96d", - "zh:a7bfc6ad8465d5dc11b6f19d6805364de87fffe27622bb4f37da2319bb1c4956", - "zh:d7379a76861f1a6bfc36eca7a20f1f477711247563b105744d69d7bd1f365fad", - "zh:de1cd959fd4821248e8d21570601193408648474e74f49597f1d0c43185a4ab7", - "zh:e0b281240dd6f2aa405b2d6fe329bc15ab877161affe163fb150d1efca2fccdb", - "zh:e372c171358757a983d7aa878abfd05a84484fb4d22167e45c9c1267e78ed060", - "zh:f6d3116526030b3f6905f530cd6c04b23d42890d973fa2abe10ce9c89cb1db80", - "zh:f99eec731e03cc6a28996c875bd435887cd7ea75ec07cc77b9e768bb12da2227", - ] -} diff --git a/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars b/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars index 7be46e15c..2e2a42738 100644 --- a/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars @@ -36,6 +36,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/dev/terraform.tfvars b/infra/functions/onboarding-functions/env/dev/terraform.tfvars index ba41927c2..ebbdde5c9 100644 --- a/infra/functions/onboarding-functions/env/dev/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/dev/terraform.tfvars @@ -21,12 +21,12 @@ cidr_subnet_selc_onboarding_fn = ["10.1.144.0/24"] function_always_on = false app_service_plan_info = { - kind = "Linux" - sku_size = "P1v3" - sku_tier = "PremiumV3" - maximum_elastic_worker_count = 1 - worker_count = 1 - zone_balancing_enabled = false + kind = "Linux" + sku_size = "P1v3" + sku_tier = "PremiumV3" + maximum_elastic_worker_count = 1 + worker_count = 1 + zone_balancing_enabled = false } storage_account_info = { @@ -35,6 +35,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars b/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars index 0f5142dd5..d9d2c923f 100644 --- a/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars @@ -36,6 +36,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = true + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/prod/terraform.tfvars b/infra/functions/onboarding-functions/env/prod/terraform.tfvars index a2a50498f..2821a35dc 100644 --- a/infra/functions/onboarding-functions/env/prod/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/prod/terraform.tfvars @@ -35,6 +35,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = true + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars b/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars index 9d7a9ef3c..eb6a9eab3 100644 --- a/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars @@ -36,6 +36,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/uat/terraform.tfvars b/infra/functions/onboarding-functions/env/uat/terraform.tfvars index 1df034e1f..33c9f4aa3 100644 --- a/infra/functions/onboarding-functions/env/uat/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/uat/terraform.tfvars @@ -35,6 +35,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/functions.tf b/infra/functions/onboarding-functions/functions.tf index 2c7c26f26..8244e8f5f 100644 --- a/infra/functions/onboarding-functions/functions.tf +++ b/infra/functions/onboarding-functions/functions.tf @@ -22,8 +22,13 @@ module "onboarding_fn_snet" { } } +data "azurerm_key_vault" "key_vault" { + resource_group_name = var.key_vault.resource_group_name + name = var.key_vault.name +} + module "selc_onboarding_fn" { - source = "github.com/pagopa/terraform-azurerm-v3.git//function_app?ref=v7.47.2" + source = "github.com/pagopa/terraform-azurerm-v3.git//function_app?ref=v7.77.0" name = local.app_name location = azurerm_resource_group.onboarding_fn_rg.location @@ -47,11 +52,6 @@ module "selc_onboarding_fn" { tags = var.tags } -data "azurerm_key_vault" "key_vault" { - resource_group_name = var.key_vault.resource_group_name - name = var.key_vault.name -} - resource "azurerm_key_vault_access_policy" "keyvault_functions_access_policy" { key_vault_id = data.azurerm_key_vault.key_vault.id tenant_id = data.azurerm_client_config.current.tenant_id diff --git a/infra/functions/onboarding-functions/variables.tf b/infra/functions/onboarding-functions/variables.tf index 14573228a..2858699ba 100644 --- a/infra/functions/onboarding-functions/variables.tf +++ b/infra/functions/onboarding-functions/variables.tf @@ -59,6 +59,8 @@ variable "storage_account_info" { account_replication_type = string access_tier = string advanced_threat_protection_enable = bool + use_legacy_defender_version = bool + public_network_access_enabled = bool }) default = { @@ -67,6 +69,8 @@ variable "storage_account_info" { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = true + use_legacy_defender_version = true + public_network_access_enabled = false } } From ee09253f7d1f98408429ae492a45b828b857d10b Mon Sep 17 00:00:00 2001 From: andrea-putzu <106688558+andrea-putzu@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:13:46 +0200 Subject: [PATCH 02/29] Update azure linux function app configuration (#527) --- .../onboarding-functions/.terraform.lock.hcl | 87 ------------------- .../env/dev-pnpg/terraform.tfvars | 2 + .../env/dev/terraform.tfvars | 14 +-- .../env/prod-pnpg/terraform.tfvars | 2 + .../env/prod/terraform.tfvars | 2 + .../env/uat-pnpg/terraform.tfvars | 2 + .../env/uat/terraform.tfvars | 2 + .../onboarding-functions/functions.tf | 12 +-- .../onboarding-functions/variables.tf | 4 + 9 files changed, 28 insertions(+), 99 deletions(-) delete mode 100644 infra/functions/onboarding-functions/.terraform.lock.hcl diff --git a/infra/functions/onboarding-functions/.terraform.lock.hcl b/infra/functions/onboarding-functions/.terraform.lock.hcl deleted file mode 100644 index 25baf19a8..000000000 --- a/infra/functions/onboarding-functions/.terraform.lock.hcl +++ /dev/null @@ -1,87 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/azuread" { - version = "2.30.0" - constraints = "2.30.0" - hashes = [ - "h1:Uw4TcmJBEJ71h+oCwwidlkk5jFpyFRDPAFCMs/bT/cw=", - "h1:WnSPiREAFwnBUKREokMdHQ8Cjs47MzvS9pG8VS1ktec=", - "zh:1c3e89cf19118fc07d7b04257251fc9897e722c16e0a0df7b07fcd261f8c12e7", - "zh:2e62c193030e04ebb10cc0526119cf69824bf2d7e4ea5a2f45bd5d5fb7221d36", - "zh:2f3c7a35257332d68b778cefc5201a5f044e4914dd03794a4da662ddfe756483", - "zh:35d0d3a1b58fdb8b8c4462d6b7e7016042da43ea9cc734ce897f52a73407d9b0", - "zh:47ede0cd0206ec953d40bf4a80aa6e59af64e26cbbd877614ac424533dbb693b", - "zh:48c190307d4d42ea67c9b8cc544025024753f46cef6ea64db84735e7055a72da", - "zh:6fff9b2c6a962252a70a15b400147789ab369b35a781e9d21cce3804b04d29af", - "zh:7646980cf3438bff29c91ffedb74458febbb00a996638751fbd204ab1c628c9b", - "zh:77aa2fa7ca6d5446afa71d4ff83cb87b70a2f3b72110fc442c339e8e710b2928", - "zh:e20b2b2c37175b89dd0db058a096544d448032e28e3b56e2db368343533a9684", - "zh:eab175b1dfe9865ad9404dccb6d5542899f8c435095aa7c679314b811c717ce7", - "zh:efc862bd78c55d2ff089729e2a34c1831ab4b0644fc11b36ee4ebed00a4797ba", - ] -} - -provider "registry.terraform.io/hashicorp/azurerm" { - version = "3.84.0" - constraints = ">= 3.30.0, <= 3.84.0, <= 3.85.0, <= 3.86.0" - hashes = [ - "h1:1Ucponuagrx5kNeIlcZwG2urqoRXBCTddDKqL265+xM=", - "h1:y/NWRLvnJmyJ5lf/AnLFy25jfyJqp6xwwxLxZnvovAs=", - "zh:14a96daf672541dbc27137d9cc0a96a737710597262ecaaa64a328eb1174e5df", - "zh:16d8e794fdd87ed8e64291fe8a617f420d8263f21672033333a020d06f4c9618", - "zh:64e5cd1bb6a81bccffff0d1f77790286ab46179cf12442134c3f3bca722afc1b", - "zh:7010ada67fbae971ac8b7204a30b1317aee7ccac7227afc6ac27277c642996a1", - "zh:77c2616ecd29685d2a4dc3ec3e9771e5ecf652e127946767d9b7ef19bbf58a21", - "zh:861922cfae724eacf1bd915efd5dbf6c23e4e762a2bbe60993099648e64aedb5", - "zh:8fb797c98bb08e7342995317810d28c41bb519fbc128adaa170896356b9eaebd", - "zh:982e85a4a9d282e3c8f7d7836037ccc98ff3ef50af246fad2e04684a81d16201", - "zh:a2ef29ff907cf6622e58afa0a27e23a3160ba3d70d531795b4d9a6c42c354630", - "zh:c46ccc4eecb79d096bcb652af0cffe300ec480d80a13a5b302c71b1aac9f9f1c", - "zh:cc6a06bf6d5e811fe8c0d9ad652e143b4e94bd16a03fb8a86f5086f0ae5abfa9", - "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - ] -} - -provider "registry.terraform.io/hashicorp/null" { - version = "3.2.2" - hashes = [ - "h1:IMVAUHKoydFrlPrl9OzasDnw/8ntZFerCC9iXw1rXQY=", - "h1:vWAsYRd7MjYr3adj8BVKRohVfHpWQdvkIwUQ2Jf5FVM=", - "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", - "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", - "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", - "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", - "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", - "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", - "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", - "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", - "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", - "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", - ] -} - -provider "registry.terraform.io/integrations/github" { - version = "5.18.3" - constraints = "5.18.3" - hashes = [ - "h1:WbZvLB2qXKVoh4BvOOwFfEds+SZQrkINfSAWPnWFxGo=", - "h1:rv3mwpUeJ0n13sY+KZMI25WAVCSeipX4n8JMWKD1XcE=", - "zh:050b37d96628cb7451137755929ca8d21ea546bc46d11a715652584070e83ff2", - "zh:053051061f1b7f7673b0ceffac1f239ba28b0e5b375999206fd39976e85d9f2b", - "zh:0c300a977ca66d0347ed62bb116fd8fc9abb376a554d4c192d14f3ea71c83500", - "zh:1d5a1a5243eba78819d2f92ff2d504ebf9a9008a6670fb5f5660f44eb6a156d8", - "zh:a13ac15d251ebf4e7dc40acb0e40df066f443f4c7799186a29e2e44addc7d8e7", - "zh:a316d94b885953c036ebc9fba64a23da93974746bc3ac9d207462a6f02d44540", - "zh:a658a00373bff5979cc227052c693cbde8ca4c8f9fef1bc8094a3516f2e2a96d", - "zh:a7bfc6ad8465d5dc11b6f19d6805364de87fffe27622bb4f37da2319bb1c4956", - "zh:d7379a76861f1a6bfc36eca7a20f1f477711247563b105744d69d7bd1f365fad", - "zh:de1cd959fd4821248e8d21570601193408648474e74f49597f1d0c43185a4ab7", - "zh:e0b281240dd6f2aa405b2d6fe329bc15ab877161affe163fb150d1efca2fccdb", - "zh:e372c171358757a983d7aa878abfd05a84484fb4d22167e45c9c1267e78ed060", - "zh:f6d3116526030b3f6905f530cd6c04b23d42890d973fa2abe10ce9c89cb1db80", - "zh:f99eec731e03cc6a28996c875bd435887cd7ea75ec07cc77b9e768bb12da2227", - ] -} diff --git a/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars b/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars index 7be46e15c..2e2a42738 100644 --- a/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/dev-pnpg/terraform.tfvars @@ -36,6 +36,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/dev/terraform.tfvars b/infra/functions/onboarding-functions/env/dev/terraform.tfvars index ba41927c2..ebbdde5c9 100644 --- a/infra/functions/onboarding-functions/env/dev/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/dev/terraform.tfvars @@ -21,12 +21,12 @@ cidr_subnet_selc_onboarding_fn = ["10.1.144.0/24"] function_always_on = false app_service_plan_info = { - kind = "Linux" - sku_size = "P1v3" - sku_tier = "PremiumV3" - maximum_elastic_worker_count = 1 - worker_count = 1 - zone_balancing_enabled = false + kind = "Linux" + sku_size = "P1v3" + sku_tier = "PremiumV3" + maximum_elastic_worker_count = 1 + worker_count = 1 + zone_balancing_enabled = false } storage_account_info = { @@ -35,6 +35,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars b/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars index 0f5142dd5..d9d2c923f 100644 --- a/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/prod-pnpg/terraform.tfvars @@ -36,6 +36,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = true + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/prod/terraform.tfvars b/infra/functions/onboarding-functions/env/prod/terraform.tfvars index a2a50498f..2821a35dc 100644 --- a/infra/functions/onboarding-functions/env/prod/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/prod/terraform.tfvars @@ -35,6 +35,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = true + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars b/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars index 9d7a9ef3c..eb6a9eab3 100644 --- a/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/uat-pnpg/terraform.tfvars @@ -36,6 +36,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/env/uat/terraform.tfvars b/infra/functions/onboarding-functions/env/uat/terraform.tfvars index 1df034e1f..33c9f4aa3 100644 --- a/infra/functions/onboarding-functions/env/uat/terraform.tfvars +++ b/infra/functions/onboarding-functions/env/uat/terraform.tfvars @@ -35,6 +35,8 @@ storage_account_info = { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = false + use_legacy_defender_version = true + public_network_access_enabled = false } app_settings = { diff --git a/infra/functions/onboarding-functions/functions.tf b/infra/functions/onboarding-functions/functions.tf index 2c7c26f26..8244e8f5f 100644 --- a/infra/functions/onboarding-functions/functions.tf +++ b/infra/functions/onboarding-functions/functions.tf @@ -22,8 +22,13 @@ module "onboarding_fn_snet" { } } +data "azurerm_key_vault" "key_vault" { + resource_group_name = var.key_vault.resource_group_name + name = var.key_vault.name +} + module "selc_onboarding_fn" { - source = "github.com/pagopa/terraform-azurerm-v3.git//function_app?ref=v7.47.2" + source = "github.com/pagopa/terraform-azurerm-v3.git//function_app?ref=v7.77.0" name = local.app_name location = azurerm_resource_group.onboarding_fn_rg.location @@ -47,11 +52,6 @@ module "selc_onboarding_fn" { tags = var.tags } -data "azurerm_key_vault" "key_vault" { - resource_group_name = var.key_vault.resource_group_name - name = var.key_vault.name -} - resource "azurerm_key_vault_access_policy" "keyvault_functions_access_policy" { key_vault_id = data.azurerm_key_vault.key_vault.id tenant_id = data.azurerm_client_config.current.tenant_id diff --git a/infra/functions/onboarding-functions/variables.tf b/infra/functions/onboarding-functions/variables.tf index 14573228a..2858699ba 100644 --- a/infra/functions/onboarding-functions/variables.tf +++ b/infra/functions/onboarding-functions/variables.tf @@ -59,6 +59,8 @@ variable "storage_account_info" { account_replication_type = string access_tier = string advanced_threat_protection_enable = bool + use_legacy_defender_version = bool + public_network_access_enabled = bool }) default = { @@ -67,6 +69,8 @@ variable "storage_account_info" { account_replication_type = "LRS" access_tier = "Hot" advanced_threat_protection_enable = true + use_legacy_defender_version = true + public_network_access_enabled = false } } From 004dbb787383774301ce9011468b349ab3aec57b Mon Sep 17 00:00:00 2001 From: andrea-putzu <106688558+andrea-putzu@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:10:54 +0200 Subject: [PATCH 03/29] [SELC-5332] Add gh infra apply pipeline (#535) Co-authored-by: empassaro --- .../workflows/release_dashboard_events.yml | 48 + infra/dashboards/env/dev/backend.ini | 1 + infra/dashboards/env/dev/backend.tfvars | 4 + infra/dashboards/env/dev/terraform.tfvars | 13 + infra/dashboards/env/prod/backend.ini | 1 + infra/dashboards/env/prod/backend.tfvars | 4 + infra/dashboards/env/prod/terraform.tfvars | 13 + infra/dashboards/env/uat/backend.ini | 1 + infra/dashboards/env/uat/backend.tfvars | 4 + infra/dashboards/env/uat/terraform.tfvars | 13 + infra/dashboards/locals.tf | 4 + infra/dashboards/main.tf | 33 + infra/dashboards/monitor.tf | 19 + infra/dashboards/monitoring.json | 895 ++++++++++++++++++ infra/dashboards/terraform.sh | 69 ++ infra/dashboards/variables.tf | 43 + 16 files changed, 1165 insertions(+) create mode 100644 .github/workflows/release_dashboard_events.yml create mode 100644 infra/dashboards/env/dev/backend.ini create mode 100644 infra/dashboards/env/dev/backend.tfvars create mode 100644 infra/dashboards/env/dev/terraform.tfvars create mode 100644 infra/dashboards/env/prod/backend.ini create mode 100644 infra/dashboards/env/prod/backend.tfvars create mode 100644 infra/dashboards/env/prod/terraform.tfvars create mode 100644 infra/dashboards/env/uat/backend.ini create mode 100644 infra/dashboards/env/uat/backend.tfvars create mode 100644 infra/dashboards/env/uat/terraform.tfvars create mode 100644 infra/dashboards/locals.tf create mode 100644 infra/dashboards/main.tf create mode 100644 infra/dashboards/monitor.tf create mode 100644 infra/dashboards/monitoring.json create mode 100755 infra/dashboards/terraform.sh create mode 100644 infra/dashboards/variables.tf diff --git a/.github/workflows/release_dashboard_events.yml b/.github/workflows/release_dashboard_events.yml new file mode 100644 index 000000000..0c933aa8e --- /dev/null +++ b/.github/workflows/release_dashboard_events.yml @@ -0,0 +1,48 @@ +name: Deploy dashboard events infra + +on: + push: + branches: + - main + - releases/* + paths: + - './infra/dashboards' + + workflow_dispatch: + inputs: + env: + type: choice + description: Environment + options: + - dev + - uat + - prod + +jobs: + + release_dev: + uses: ./.github/workflows/call_release_infra.yml + name: '[Dev] Dashboard events Infra Release' + if: ${{ (startsWith(github.ref_name, 'releases/') != true && inputs.env == null) || inputs.env == 'dev' }} + secrets: inherit + with: + environment: dev + dir: ./infra/dashboards + + release_uat: + uses: ./.github/workflows/call_release_infra.yml + name: '[UAT] Dashboard events Infra Release' + if: ${{ (startsWith(github.ref_name, 'releases/') == true && inputs.env == null) || inputs.env == 'uat' }} + secrets: inherit + with: + environment: uat + dir: ./infra/dashboards + + release_prod: + uses: ./.github/workflows/call_release_infra.yml + name: '[Prod] Dashboard events Infra Release' + if: ${{ inputs.env == 'prod' }} + secrets: inherit + with: + environment: prod + dir: ./infra/dashboards \ No newline at end of file diff --git a/infra/dashboards/env/dev/backend.ini b/infra/dashboards/env/dev/backend.ini new file mode 100644 index 000000000..73ee9c6b7 --- /dev/null +++ b/infra/dashboards/env/dev/backend.ini @@ -0,0 +1 @@ +subscription=DEV-SelfCare \ No newline at end of file diff --git a/infra/dashboards/env/dev/backend.tfvars b/infra/dashboards/env/dev/backend.tfvars new file mode 100644 index 000000000..89d9eb889 --- /dev/null +++ b/infra/dashboards/env/dev/backend.tfvars @@ -0,0 +1,4 @@ +resource_group_name = "terraform-state-rg" +storage_account_name = "tfappdevselfcare" +container_name = "terraform-state" +key = "selfcare-onboarding.dashboards.tfstate" \ No newline at end of file diff --git a/infra/dashboards/env/dev/terraform.tfvars b/infra/dashboards/env/dev/terraform.tfvars new file mode 100644 index 000000000..c03dfde15 --- /dev/null +++ b/infra/dashboards/env/dev/terraform.tfvars @@ -0,0 +1,13 @@ +prefix = "selc" +env_short = "d" +location = "westeurope" + +subscription = "1ab5e788-3b98-4c63-bd05-de0c7388c853" + +tags = { + CreatedBy = "Terraform" + Environment = "Dev" + Owner = "SelfCare" + Source = "https://github.com/pagopa/selfcare-onboarding" + CostCenter = "TS310 - PAGAMENTI & SERVIZI" +} diff --git a/infra/dashboards/env/prod/backend.ini b/infra/dashboards/env/prod/backend.ini new file mode 100644 index 000000000..0343b4a0d --- /dev/null +++ b/infra/dashboards/env/prod/backend.ini @@ -0,0 +1 @@ +subscription=PROD-SelfCare \ No newline at end of file diff --git a/infra/dashboards/env/prod/backend.tfvars b/infra/dashboards/env/prod/backend.tfvars new file mode 100644 index 000000000..9401301b3 --- /dev/null +++ b/infra/dashboards/env/prod/backend.tfvars @@ -0,0 +1,4 @@ +resource_group_name = "terraform-state-rg" +storage_account_name = "tfappprodselfcare" +container_name = "terraform-state" +key = "selfcare-onboarding.dashboards.tfstate" \ No newline at end of file diff --git a/infra/dashboards/env/prod/terraform.tfvars b/infra/dashboards/env/prod/terraform.tfvars new file mode 100644 index 000000000..41d61a833 --- /dev/null +++ b/infra/dashboards/env/prod/terraform.tfvars @@ -0,0 +1,13 @@ +prefix = "selc" +env_short = "p" +location = "westeurope" + +subscription = "813119d7-0943-46ed-8ebe-cebe24f9106c" + +tags = { + CreatedBy = "Terraform" + Environment = "Prod" + Owner = "SelfCare" + Source = "https://github.com/pagopa/selfcare-onboarding" + CostCenter = "TS310 - PAGAMENTI & SERVIZI" +} diff --git a/infra/dashboards/env/uat/backend.ini b/infra/dashboards/env/uat/backend.ini new file mode 100644 index 000000000..8cadfd658 --- /dev/null +++ b/infra/dashboards/env/uat/backend.ini @@ -0,0 +1 @@ +subscription=UAT-SelfCare \ No newline at end of file diff --git a/infra/dashboards/env/uat/backend.tfvars b/infra/dashboards/env/uat/backend.tfvars new file mode 100644 index 000000000..54196b241 --- /dev/null +++ b/infra/dashboards/env/uat/backend.tfvars @@ -0,0 +1,4 @@ +resource_group_name = "terraform-state-rg" +storage_account_name = "tfappuatselfcare" +container_name = "terraform-state" +key = "selfcare-onboarding.dashboards.tfstate" \ No newline at end of file diff --git a/infra/dashboards/env/uat/terraform.tfvars b/infra/dashboards/env/uat/terraform.tfvars new file mode 100644 index 000000000..7361726eb --- /dev/null +++ b/infra/dashboards/env/uat/terraform.tfvars @@ -0,0 +1,13 @@ +prefix = "selc" +env_short = "u" +location = "westeurope" + +subscription = "f47d50dc-b874-4e04-9d5c-c27f5053a651" + +tags = { + CreatedBy = "Terraform" + Environment = "Uat" + Owner = "SelfCare" + Source = "https://github.com/pagopa/selfcare-onboarding" + CostCenter = "TS310 - PAGAMENTI & SERVIZI" +} diff --git a/infra/dashboards/locals.tf b/infra/dashboards/locals.tf new file mode 100644 index 000000000..a650b9a4f --- /dev/null +++ b/infra/dashboards/locals.tf @@ -0,0 +1,4 @@ +locals { + pnpg_suffix = var.is_pnpg == true ? "-pnpg" : "" + project = "selc-${var.env_short}" +} \ No newline at end of file diff --git a/infra/dashboards/main.tf b/infra/dashboards/main.tf new file mode 100644 index 000000000..3c733d0f9 --- /dev/null +++ b/infra/dashboards/main.tf @@ -0,0 +1,33 @@ +terraform { + required_version = ">=1.6.0" + + required_providers { + azuread = { + source = "hashicorp/azuread" + version = "2.53.1" + } + azurerm = { + source = "hashicorp/azurerm" + version = "<= 4.3.0" + } + github = { + source = "integrations/github" + version = "5.18.3" + } + } + + backend "azurerm" {} +} + +provider "azurerm" { + features {} + subscription_id = var.subscription +} + +provider "github" { + owner = "pagopa" +} + +data "azurerm_subscription" "current" {} + +data "azurerm_client_config" "current" {} \ No newline at end of file diff --git a/infra/dashboards/monitor.tf b/infra/dashboards/monitor.tf new file mode 100644 index 000000000..939bc76d1 --- /dev/null +++ b/infra/dashboards/monitor.tf @@ -0,0 +1,19 @@ +resource "azurerm_resource_group" "monitor_rg" { + name = "${local.project}-monitor-rg" + location = var.location + + tags = var.tags +} + +resource "azurerm_portal_dashboard" "monitoring_onboarding_event" { + name = "${local.project}-monitoring-onboarding-event" + resource_group_name = azurerm_resource_group.monitor_rg.name + location = azurerm_resource_group.monitor_rg.location + tags = var.tags + + dashboard_properties = templatefile("monitoring.json", + { + subscription_id = data.azurerm_subscription.current.subscription_id + prefix = "${var.prefix}-${var.env_short}" + }) +} \ No newline at end of file diff --git a/infra/dashboards/monitoring.json b/infra/dashboards/monitoring.json new file mode 100644 index 000000000..6fc16bcbd --- /dev/null +++ b/infra/dashboards/monitoring.json @@ -0,0 +1,895 @@ +{ +"lenses": { + "0": { + "order": 0, + "parts": { + "0": { + "position": { + "x": 0, + "y": 0, + "colSpan": 9, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "132be8c1-1242-42a1-a954-836f8a91ad0d", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "P7D", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-CDC\"\n| where customMeasurements contains \"OnboardingsUpdate_successes\"\n| where customDimensions contains \"_id\"\n| extend d=parse_json(customDimensions)\n| extend documentKey = d[\"documentKey\"]\n| project-rename onboardingId = documentKey\n| project timestamp, onboardingId\n| summarize Count = count() by bin(timestamp, 6h)\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "FrameControlChart", + "isOptional": true + }, + { + "name": "SpecificChart", + "value": "Line", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "value": { + "xAxis": { + "name": "timestamp", + "type": "datetime" + }, + "yAxis": [ + { + "name": "Count", + "type": "long" + } + ], + "splitBy": [], + "aggregation": "Sum" + }, + "isOptional": true + }, + { + "name": "LegendOptions", + "value": { + "isEnabled": true, + "position": "Bottom" + }, + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "PartTitle": "Count Notification invocations with success" + } + } + } + }, + "1": { + "position": { + "x": 9, + "y": 0, + "colSpan": 6, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "142201b2-14f6-41ea-a3d7-2863c2e13f52", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "P7D", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-CDC\"\n| where customMeasurements contains \"OnboardingsUpdate_successes\"\n| where customDimensions contains \"_id\"\n| extend d=parse_json(customDimensions)\n| extend documentKey = d[\"documentKey\"]\n| project-rename onboardingId = documentKey\n| project onboardingId\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "AnalyticsGrid", + "isOptional": true + }, + { + "name": "SpecificChart", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "isOptional": true + }, + { + "name": "LegendOptions", + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "GridColumnsWidth": { + "onboardingId": "473.993px" + }, + "PartTitle": "Onboarding id of successfull Notification invocations" + } + } + } + }, + "2": { + "position": { + "x": 0, + "y": 4, + "colSpan": 9, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "3cd8d57f-822a-4186-b0e4-490fe4b17a7d", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "P7D", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-CDC\"\n| where customMeasurements contains \"OnboardingsUpdate_failures\"\n| where customDimensions contains \"_id\"\n| extend d=parse_json(customDimensions)\n| extend documentKey = d[\"documentKey\"]\n| where documentKey contains \"_id\"\n| project-rename onboardingId = documentKey\n| project timestamp, onboardingId\n| summarize Count = count() by bin(timestamp, 6h)\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "FrameControlChart", + "isOptional": true + }, + { + "name": "SpecificChart", + "value": "Line", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "value": { + "xAxis": { + "name": "timestamp", + "type": "datetime" + }, + "yAxis": [ + { + "name": "Count", + "type": "long" + } + ], + "splitBy": [], + "aggregation": "Sum" + }, + "isOptional": true + }, + { + "name": "LegendOptions", + "value": { + "isEnabled": true, + "position": "Bottom" + }, + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "PartTitle": "Count Notification invocations with failure" + } + } + } + }, + "3": { + "position": { + "x": 9, + "y": 4, + "colSpan": 6, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "0720210f-9b58-4ec8-a73e-5847668a9298", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "P7D", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-CDC\"\n| where customMeasurements contains \"OnboardingsUpdate_failures\"\n| where customDimensions contains \"_id\"\n| extend d=parse_json(customDimensions)\n| extend documentKey = d[\"documentKey\"]\n| where documentKey contains \"_id\"\n| project-rename onboardingId = documentKey\n| project onboardingId\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "AnalyticsGrid", + "isOptional": true + }, + { + "name": "SpecificChart", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "isOptional": true + }, + { + "name": "LegendOptions", + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "GridColumnsWidth": { + "onboardingId": "506px" + }, + "PartTitle": "Onboarding id of failed Notification invocations" + } + } + } + }, + "4": { + "position": { + "x": 0, + "y": 8, + "colSpan": 7, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "81d9d129-c43b-4a75-a9a5-0f011489a1d4", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "P7D", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-FN\"\n| extend d=parse_json(customDimensions)\n| where d[\"topic\"] == \"SC-Contracts\"\n| order by timestamp desc\n| project timestamp\n| summarize Count = count() by bin(timestamp, 6h)\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "FrameControlChart", + "isOptional": true + }, + { + "name": "SpecificChart", + "value": "Line", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "value": { + "xAxis": { + "name": "timestamp", + "type": "datetime" + }, + "yAxis": [ + { + "name": "Count", + "type": "long" + } + ], + "splitBy": [], + "aggregation": "Sum" + }, + "isOptional": true + }, + { + "name": "LegendOptions", + "value": { + "isEnabled": true, + "position": "Bottom" + }, + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "PartTitle": "Count Notifications sent on SC-Contracts" + } + } + } + }, + "5": { + "position": { + "x": 7, + "y": 8, + "colSpan": 9, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "11ff3635-154f-4581-8e01-363be8dc88ad", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "P7D", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-FN\"\n| extend d=parse_json(customDimensions)\n| where d[\"topic\"] == \"SC-Contracts\"\n| order by timestamp desc\n| project timestamp, d\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "AnalyticsGrid", + "isOptional": true + }, + { + "name": "SpecificChart", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "isOptional": true + }, + { + "name": "LegendOptions", + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "GridColumnsWidth": { + "d": "595.998px" + }, + "PartTitle": "Notifications sent on SC-Contracts" + } + } + } + }, + "6": { + "position": { + "x": 0, + "y": 12, + "colSpan": 7, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "410407fc-0aa7-4ef1-9998-0136a1110502", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "2024-09-10T06:50:21.000Z/2024-10-04T06:50:21.381Z", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-FN\"\n| extend d=parse_json(customDimensions)\n| where d[\"topic\"] == \"SC-Contracts-SAP\"\n| order by timestamp desc\n| project timestamp\n| summarize Count = count() by bin(timestamp, 6h)\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "FrameControlChart", + "isOptional": true + }, + { + "name": "SpecificChart", + "value": "Line", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "value": { + "xAxis": { + "name": "timestamp", + "type": "datetime" + }, + "yAxis": [ + { + "name": "Count", + "type": "long" + } + ], + "splitBy": [], + "aggregation": "Sum" + }, + "isOptional": true + }, + { + "name": "LegendOptions", + "value": { + "isEnabled": true, + "position": "Bottom" + }, + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "PartTitle": "Count Notifications sent on SC-Contracts-SAP" + } + } + } + }, + "7": { + "position": { + "x": 7, + "y": 12, + "colSpan": 9, + "rowSpan": 4 + }, + "metadata": { + "inputs": [ + { + "name": "resourceTypeMode", + "isOptional": true + }, + { + "name": "ComponentId", + "isOptional": true + }, + { + "name": "Scope", + "value": { + "resourceIds": [ + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-monitor-rg/providers/microsoft.insights/components/${prefix}-appinsights" + ] + }, + "isOptional": true + }, + { + "name": "PartId", + "value": "12f6ef02-2b87-4163-af10-695d5fc7d51f", + "isOptional": true + }, + { + "name": "Version", + "value": "2.0", + "isOptional": true + }, + { + "name": "TimeRange", + "value": "2024-09-10T06:50:21.000Z/2024-10-04T06:50:21.381Z", + "isOptional": true + }, + { + "name": "DashboardId", + "isOptional": true + }, + { + "name": "DraftRequestParameters", + "isOptional": true + }, + { + "name": "Query", + "value": "customEvents\n| where name contains \"ONBOARDING-FN\"\n| extend d=parse_json(customDimensions)\n| where d[\"topic\"] == \"SC-Contracts-SAP\"\n| order by timestamp desc\n| project timestamp, d\n", + "isOptional": true + }, + { + "name": "ControlType", + "value": "AnalyticsGrid", + "isOptional": true + }, + { + "name": "SpecificChart", + "isOptional": true + }, + { + "name": "PartTitle", + "value": "Analytics", + "isOptional": true + }, + { + "name": "PartSubTitle", + "value": "${prefix}-appinsights", + "isOptional": true + }, + { + "name": "Dimensions", + "isOptional": true + }, + { + "name": "LegendOptions", + "isOptional": true + }, + { + "name": "IsQueryContainTimeRange", + "value": false, + "isOptional": true + } + ], + "type": "Extension/Microsoft_OperationsManagementSuite_Workspace/PartType/LogsDashboardPart", + "settings": { + "content": { + "PartTitle": "Notifications sent on SC-Contracts-SAP" + } + } + } + } + } + } +}, +"metadata": { + "model": { + "timeRange": { + "value": { + "relative": { + "duration": 24, + "timeUnit": 1 + } + }, + "type": "MsPortalFx.Composition.Configuration.ValueTypes.TimeRange" + }, + "filterLocale": { + "value": "en-us" + }, + "filters": { + "value": { + "MsPortalFx_TimeRange": { + "model": { + "format": "utc", + "granularity": "auto", + "relative": "24h" + }, + "displayCache": { + "name": "UTC Time", + "value": "Past 24 hours" + }, + "filteredPartIds": [ + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc812f", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc817c", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc81a7", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc81dc", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc8219", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc82ae", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc82fd", + "StartboardPart-LogsDashboardPart-5b5cf61c-c51a-40ae-944f-f80f33cc8355" + ] + } + } + } + } +} +} \ No newline at end of file diff --git a/infra/dashboards/terraform.sh b/infra/dashboards/terraform.sh new file mode 100755 index 000000000..e8fe04251 --- /dev/null +++ b/infra/dashboards/terraform.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -e + +action=$1 +env=$2 +shift 2 +other=$@ +# must be subscription in lower case +subscription="" +BACKEND_CONFIG_PATH="./env/${ENV}/backend.tfvars" + +if [ -z "$action" ]; then + echo "Missed action: init, apply, plan" + exit 0 +fi + +if [ -z "$env" ]; then + echo "env should be: dev, uat or prod." + exit 0 +fi + +source "./env/$env/backend.ini" + +az account set -s "${subscription}" + +# if using cygwin, we have to transcode the WORKDIR +if [[ $WORKDIR == /cygdrive/* ]]; then + WORKDIR=$(cygpath -w $WORKDIR) +fi + +if [ "$action" = "force-unlock" ]; then + echo "🧭 terraform INIT in env: ${env}" + terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" $other + warn_message="You are about to unlock Terraform's remote state. + This is a dangerous task you want to be aware of before going on. + This operation won't affect your infrastructure directly. + However, please note that you may lose pieces of information about partially-applied configurations. + + Please refer to the official Terraform documentation about the command: + https://developer.hashicorp.com/terraform/cli/commands/force-unlock" + printf "\n\e[33m%s\e[0m\n\n" "$warn_message" + + read -r -p "Please enter the LOCK ID: " lock_id + terraform force-unlock "$lock_id" + + exit 0 # this line prevents the script to go on +fi + +if echo "init plan apply refresh import output state taint destroy" | grep -w "$action" > /dev/null; then + if [ "$action" = "init" ]; then + echo "🧭 terraform INIT in env: ${env}" + terraform "$action" -reconfigure -backend-config="./env/$env/backend.tfvars" $other + elif [ "$action" = "output" ] || [ "$action" = "state" ] || [ "$action" = "taint" ]; then + # init terraform backend + echo "🧭 terraform (output|state|taint) launched with action: ${action} in env: ${env}" + terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" + terraform "$action" $other + else + # init terraform backend + echo "🧭 terraform launched with action: ${action} in env: ${env}" + + terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" + terraform "$action" -var-file="./env/$env/terraform.tfvars" $other + fi +else + echo "Action not allowed." + exit 1 +fi \ No newline at end of file diff --git a/infra/dashboards/variables.tf b/infra/dashboards/variables.tf new file mode 100644 index 000000000..c4a9b8ffa --- /dev/null +++ b/infra/dashboards/variables.tf @@ -0,0 +1,43 @@ +variable "is_pnpg" { + type = bool + default = false + description = "(Optional) True if you want to apply changes to PNPG environment" +} + +variable "prefix" { + description = "Domain prefix" + type = string + default = "selc" + validation { + condition = ( + length(var.prefix) <= 6 + ) + error_message = "Max length is 6 chars." + } +} + +variable "env_short" { + description = "Environment short name" + type = string + validation { + condition = ( + length(var.env_short) <= 1 + ) + error_message = "Max length is 1 chars." + } +} + +variable "tags" { + type = map(any) +} + + +variable "subscription" { + type = string +} + + +variable "location" { + type = string + default = "westeurope" +} From 3861fdd2728c9f610300661431786f92752082cb Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 12:32:45 +0200 Subject: [PATCH 04/29] chore: Working on send user notification --- .../NotificationEventServiceDefault.java | 18 ++++++-- .../utils/NotificationUserBuilderFactory.java | 45 +++++++++++++++++++ .../utils/NotificationUserFDBuilder.java | 25 +++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index e6727ae16..b41fa8971 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -79,7 +79,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que @Override public void send(ExecutionContext context, Onboarding onboarding, QueueEvent queueEvent, String notificationEventTraceId) { context.getLogger().info(() -> String.format("Starting send method for onboarding with ID %s", onboarding.getId())); - if(isNotInstitutionOnboarding(onboarding)) { + if (isNotInstitutionOnboarding(onboarding)) { context.getLogger().info(() -> String.format("Onboarding with ID %s doesn't refer to an institution onboarding, skipping send notification", onboarding.getId())); return; } @@ -91,7 +91,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que return; } - if(Objects.isNull(queueEvent)) { + if (Objects.isNull(queueEvent)) { queueEvent = queueEventExaminer.determineEventType(onboarding); } @@ -103,6 +103,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que for (String consumer : product.getConsumers()) { NotificationConfig.Consumer consumerConfig = notificationConfig.consumers().get(consumer.toLowerCase()); prepareAndSendNotification(context, product, consumerConfig, notificationsResources, notificationEventTraceId); + prepareAndSendUserNotification(context, product, consumerConfig, notificationsResources, notificationEventTraceId); } } @@ -117,6 +118,17 @@ private void prepareAndSendNotification(ExecutionContext context, Product produc } } + private void prepareAndSendUserNotification(ExecutionContext context, Product product, NotificationConfig.Consumer consumer, NotificationsResources notificationsResources, String notificationEventTraceId) { + NotificationBuilder notificationBuilder = notificationBuilderFactory.create(consumer); + if (notificationBuilder.shouldSendNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { + NotificationToSend notificationToSend = notificationBuilder.buildNotificationToSend(notificationsResources.getOnboarding(), notificationsResources.getToken(), notificationsResources.getInstitution(), notificationsResources.getQueueEvent()); + sendNotification(context, consumer.topic(), notificationToSend, notificationEventTraceId); + sendTestEnvProductsNotification(context, product, consumer.topic(), notificationToSend, notificationEventTraceId); + } else { + context.getLogger().info(() -> String.format("It was not necessary to send a notification on the topic %s because the onboarding with ID %s did not pass filter verification", notificationsResources.getOnboarding().getId(), consumer.topic())); + } + } + private void sendNotification(ExecutionContext context, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { String message = null; try { @@ -129,7 +141,7 @@ private void sendNotification(ExecutionContext context, String topic, Notificati } eventHubRestClient.sendMessage(topic, message); - telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); + telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); } private void sendTestEnvProductsNotification(ExecutionContext context, Product product, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java new file mode 100644 index 000000000..80f5bbf41 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java @@ -0,0 +1,45 @@ +package it.pagopa.selfcare.onboarding.utils; + +import it.pagopa.selfcare.onboarding.config.NotificationConfig; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.openapi.quarkus.party_registry_proxy_json.api.AooApi; +import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; +import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import org.openapi.quarkus.party_registry_proxy_json.api.UoApi; + +import static it.pagopa.selfcare.onboarding.entity.Topic.*; + +@ApplicationScoped +public class NotificationUserBuilderFactory { + @Inject + @RestClient + InstitutionApi proxyRegistryInstitutionApi; + @Inject + @RestClient + GeographicTaxonomiesApi geographicTaxonomiesApi; + @Inject + @RestClient + UoApi proxyRegistryUoApi; + @Inject + @RestClient + AooApi proxyRegistryAooApi; + @Inject + @RestClient + org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi; + private final String alternativeEmail; + + public NotificationUserBuilderFactory(@ConfigProperty(name = "onboarding-functions.sender-mail") String alternativeEmail) { + this.alternativeEmail = alternativeEmail; + } + + public NotificationBuilder create(NotificationConfig.Consumer consumer) { + if (SC_CONTRACTS_FD.getValue().equalsIgnoreCase(consumer.topic())) { + return new FdNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); + } + return null; + } + +} diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java new file mode 100644 index 000000000..1f95657a1 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java @@ -0,0 +1,25 @@ +package it.pagopa.selfcare.onboarding.utils; + +import it.pagopa.selfcare.onboarding.dto.BillingToSend; +import it.pagopa.selfcare.onboarding.dto.InstitutionToNotify; +import it.pagopa.selfcare.onboarding.dto.NotificationToSend; +import it.pagopa.selfcare.onboarding.dto.QueueEvent; +import it.pagopa.selfcare.onboarding.entity.Onboarding; +import it.pagopa.selfcare.onboarding.entity.Token; +import org.openapi.quarkus.core_json.model.InstitutionResponse; + +public interface NotificationUserFDBuilder { + NotificationToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent); + +// default boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) { +// return true; +// } +// +// InstitutionToNotify retrieveInstitution(InstitutionResponse institution); +// +// void setTokenData(NotificationToSend notificationToSend, Token token); +// +// void retrieveAndSetGeographicData(InstitutionToNotify institution); +// +// BillingToSend retrieveBilling(Onboarding onboarding); +} From be860162020ae5453513a15be3eaa5b5df279a0b Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 17:01:02 +0200 Subject: [PATCH 05/29] chore: Working on send user notification --- .../dto/NotificationUserToSend.java | 195 ++++++++++++++++++ .../onboarding/dto/NotificationUserType.java | 25 +++ .../onboarding/dto/QueueUserEvent.java | 9 + .../selfcare/onboarding/dto/UserToNotify.java | 45 ++++ .../NotificationEventServiceDefault.java | 84 +++++++- .../onboarding/utils/CustomMetricsConst.java | 1 + .../utils/FdNotificationBuilder.java | 46 ++++- .../utils/NotificationUserBuilder.java | 19 ++ .../utils/NotificationUserBuilderFactory.java | 23 ++- .../utils/NotificationUserFDBuilder.java | 25 --- .../utils/SapNotificationBuilder.java | 16 +- .../utils/StandardNotificationBuilder.java | 12 +- libs/onboarding-sdk-product/pom.xml | 2 + 13 files changed, 455 insertions(+), 47 deletions(-) create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java delete mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java new file mode 100644 index 000000000..ce6a05152 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java @@ -0,0 +1,195 @@ +package it.pagopa.selfcare.onboarding.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import it.pagopa.selfcare.onboarding.utils.CustomOffsetDateTimeSerializer; + +import java.nio.file.Paths; +import java.time.OffsetDateTime; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class NotificationUserToSend { + + private String id; + private String institutionId; + private String product; + private String state; + private String filePath; + private String fileName; + private String contentType; + private String onboardingTokenId; + private String pricingPlan; + private BillingToSend billing; + @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) + private OffsetDateTime createdAt; + @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) + private OffsetDateTime closedAt; + @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) + private OffsetDateTime updatedAt; + private QueueUserEvent notificationType; + private NotificationUserType type; + private UserToNotify user; + + + public String getInstitutionId() { + return institutionId; + } + + public void setInstitutionId(String institutionId) { + this.institutionId = institutionId; + } + + + public NotificationUserType getType() { + return type; + } + + public void setType(NotificationUserType type) { + this.type = type; + } + + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getContentType() { + return this.contentType; + } + + public void setContentType(String contractSigned) { + String contractFileName = Objects.isNull(contractSigned) ? "" : Paths.get(contractSigned).getFileName().toString(); + if (contractFileName.isEmpty()) { + this.contentType = ""; + } else if (contractFileName.endsWith(".p7m")) { + this.contentType = "application/pkcs7-mime"; + } else if (contractFileName.endsWith(".pdf")) { + this.contentType = "application/pdf"; + } else { + this.contentType = "application/octet-stream"; + } + } + + public String getOnboardingTokenId() { + return onboardingTokenId; + } + + public void setOnboardingTokenId(String onboardingTokenId) { + this.onboardingTokenId = onboardingTokenId; + } + + public OffsetDateTime getClosedAt() { + return closedAt; + } + + public void setClosedAt(OffsetDateTime closedAt) { + this.closedAt = closedAt; + } + + public QueueUserEvent getNotificationType() { + return notificationType; + } + + public void setNotificationType(QueueUserEvent notificationType) { + this.notificationType = notificationType; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getProduct() { + return product; + } + + public void setProduct(String product) { + this.product = product; + } + + public String getPricingPlan() { + return pricingPlan; + } + + public void setPricingPlan(String pricingPlan) { + this.pricingPlan = pricingPlan; + } + + public BillingToSend getBilling() { + return billing; + } + + public void setBilling(BillingToSend billing) { + this.billing = billing; + } + + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(OffsetDateTime createdAt) { + this.createdAt = createdAt; + } + + public OffsetDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(OffsetDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + public UserToNotify getUser() { + return user; + } + + public void setUser(UserToNotify user) { + this.user = user; + } + + @Override + public String toString() { + return "NotificationToSend{" + + "id='" + id + '\'' + + ", istitutionID='" + institutionId + '\'' + + ", product='" + product + '\'' + + ", state='" + state + '\'' + + ", filePath='" + filePath + '\'' + + ", fileName='" + fileName + '\'' + + ", contentType='" + contentType + '\'' + + ", onboardingTokenId='" + onboardingTokenId + '\'' + + ", pricingPlan='" + pricingPlan + '\'' + + ", billing=" + billing + + ", createdAt=" + createdAt + + ", closedAt=" + closedAt + + ", updatedAt=" + updatedAt + + ", notificationType=" + notificationType + + ", userId=" + user.getUserId() + + '}'; + } + +} \ No newline at end of file diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java new file mode 100644 index 000000000..6d7c90212 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java @@ -0,0 +1,25 @@ +package it.pagopa.selfcare.onboarding.dto; + +public enum NotificationUserType { + ADD_INSTITUTE(QueueUserEvent.ADD_INSTITUTE), + UPDATE_INSTITUTION(QueueUserEvent.UPDATE_INSTITUTION), + ACTIVE_USER(QueueUserEvent.ACTIVE_USER), + SUSPEND_USER(QueueUserEvent.SUSPEND_USER), + DELETE_USER(QueueUserEvent.DELETE_USER); + + + private final QueueUserEvent queueUserEvent; + + NotificationUserType(QueueUserEvent queueUserEvent) { + this.queueUserEvent = queueUserEvent; + } + + public static NotificationUserType getNotificationTypeFromQueueEvent(QueueUserEvent queueEvent) { + for (NotificationUserType notificationType : NotificationUserType.values()) { + if (notificationType.queueUserEvent == queueEvent) { + return notificationType; + } + } + return null; // Return null if no matching NotificationType is found + } +} \ No newline at end of file diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java new file mode 100644 index 000000000..a9cea7683 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java @@ -0,0 +1,9 @@ +package it.pagopa.selfcare.onboarding.dto; + +public enum QueueUserEvent { + ADD_INSTITUTE, + UPDATE_INSTITUTION, + ACTIVE_USER, + SUSPEND_USER, + DELETE_USER +} \ No newline at end of file diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java new file mode 100644 index 000000000..96f9354ea --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java @@ -0,0 +1,45 @@ +package it.pagopa.selfcare.onboarding.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import it.pagopa.selfcare.onboarding.common.PartyRole; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserToNotify { + + private String userId; + private String role; + private String productRole; + private String relationshipStatus; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getProductRole() { + return productRole; + } + + public void setProductRole(String productRole) { + this.productRole = productRole; + } + + public String getRelationshipStatus() { + return relationshipStatus; + } + + public void setRelationshipStatus(String relationshipStatus) { + this.relationshipStatus = relationshipStatus; + } +} diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index b41fa8971..491fee8bf 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -8,17 +8,18 @@ import com.microsoft.applicationinsights.TelemetryConfiguration; import com.microsoft.azure.functions.ExecutionContext; import it.pagopa.selfcare.onboarding.client.eventhub.EventHubRestClient; +import it.pagopa.selfcare.onboarding.common.OnboardingStatus; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.NotificationToSend; +import it.pagopa.selfcare.onboarding.dto.NotificationUserToSend; import it.pagopa.selfcare.onboarding.dto.NotificationsResources; import it.pagopa.selfcare.onboarding.dto.QueueEvent; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.entity.Token; import it.pagopa.selfcare.onboarding.exception.NotificationException; import it.pagopa.selfcare.onboarding.repository.TokenRepository; -import it.pagopa.selfcare.onboarding.utils.NotificationBuilder; -import it.pagopa.selfcare.onboarding.utils.NotificationBuilderFactory; -import it.pagopa.selfcare.onboarding.utils.QueueEventExaminer; +import it.pagopa.selfcare.onboarding.utils.*; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.service.ProductService; import jakarta.enterprise.context.ApplicationScoped; @@ -28,6 +29,9 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; +import org.openapi.quarkus.user_json.model.UserDataResponse; +import org.openapi.quarkus.user_json.model.UserInstitutionResponse; +import org.openapi.quarkus.user_registry_json.api.UserApi; import java.util.*; @@ -46,9 +50,14 @@ public class NotificationEventServiceDefault implements NotificationEventService @Inject InstitutionApi institutionApi; + @RestClient + @Inject + org.openapi.quarkus.user_json.api.UserApi userApi; + private final ProductService productService; private final NotificationConfig notificationConfig; private final NotificationBuilderFactory notificationBuilderFactory; + private final NotificationUserBuilderFactory notificationUserBuilderFactory; private final TokenRepository tokenRepository; private final ObjectMapper mapper; private final QueueEventExaminer queueEventExaminer; @@ -56,12 +65,14 @@ public class NotificationEventServiceDefault implements NotificationEventService public NotificationEventServiceDefault(ProductService productService, NotificationConfig notificationConfig, NotificationBuilderFactory notificationBuilderFactory, + NotificationUserBuilderFactory notificationUserBuilderFactory, TokenRepository tokenRepository, QueueEventExaminer queueEventExaminer, @Context @ConfigProperty(name = "onboarding-functions.appinsights.connection-string") String appInsightsConnectionString) { this.productService = productService; this.notificationConfig = notificationConfig; this.notificationBuilderFactory = notificationBuilderFactory; + this.notificationUserBuilderFactory = notificationUserBuilderFactory; this.tokenRepository = tokenRepository; this.queueEventExaminer = queueEventExaminer; TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.createDefault(); @@ -119,11 +130,29 @@ private void prepareAndSendNotification(ExecutionContext context, Product produc } private void prepareAndSendUserNotification(ExecutionContext context, Product product, NotificationConfig.Consumer consumer, NotificationsResources notificationsResources, String notificationEventTraceId) { - NotificationBuilder notificationBuilder = notificationBuilderFactory.create(consumer); - if (notificationBuilder.shouldSendNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { - NotificationToSend notificationToSend = notificationBuilder.buildNotificationToSend(notificationsResources.getOnboarding(), notificationsResources.getToken(), notificationsResources.getInstitution(), notificationsResources.getQueueEvent()); - sendNotification(context, consumer.topic(), notificationToSend, notificationEventTraceId); - sendTestEnvProductsNotification(context, product, consumer.topic(), notificationToSend, notificationEventTraceId); + NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); + if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { + List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), null, null, null, null, null, null); + users.forEach(userDataResponse -> { + userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { + if (onboardedProductResponse.getProductId().equals(product.getId())) { + NotificationUserToSend notificationUserToSend = notificationUserBuilder.buildUserNotificationToSend( + notificationsResources.getOnboarding(), + notificationsResources.getToken(), + notificationsResources.getInstitution(), + onboardedProductResponse.getCreatedAt(), + onboardedProductResponse.getUpdatedAt(), + onboardedProductResponse.getStatus().toString(), userDataResponse.getUserId(), onboardedProductResponse.getRole(), + onboardedProductResponse.getProductRole()); + sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); + } + return false; + }); + + + }); + + } else { context.getLogger().info(() -> String.format("It was not necessary to send a notification on the topic %s because the onboarding with ID %s did not pass filter verification", notificationsResources.getOnboarding().getId(), consumer.topic())); } @@ -144,6 +173,21 @@ private void sendNotification(ExecutionContext context, String topic, Notificati telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); } + private void sendUserNotification(ExecutionContext context, String topic, NotificationUserToSend notificationUserToSend, String notificationEventTraceId) { + String message = null; + try { + message = mapper.writeValueAsString(notificationUserToSend); + } catch (JsonProcessingException e) { + throw new NotificationException("Notification User cannot be serialized"); + } finally { + String finalMessage = message; + context.getLogger().info(() -> String.format("Sending notification user on topic: %s with message: %s", topic, finalMessage)); + } + + eventHubRestClient.sendMessage(topic, message); + telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationUserEventMap(notificationUserToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); + } + private void sendTestEnvProductsNotification(ExecutionContext context, Product product, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { context.getLogger().info(() -> String.format("Starting sendTestEnvProductsNotification with testEnv %s", product.getTestEnvProductIds())); if (product.getTestEnvProductIds() != null) { @@ -219,4 +263,28 @@ public static Map notificationEventMap(NotificationToSend notifi return propertiesMap; } + + public static Map notificationUserEventMap(NotificationUserToSend notificationUserToSend, String topic, String notificationEventTraceId) { + Map propertiesMap = new HashMap<>(); + Optional.ofNullable(topic).ifPresent(value -> propertiesMap.put("topic", value)); + Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put("notificationEventTraceId", value)); + Optional.ofNullable(notificationUserToSend.getId()).ifPresent(value -> propertiesMap.put("id", value)); + Optional.ofNullable(notificationUserToSend.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value)); + Optional.ofNullable(notificationUserToSend.getProduct()).ifPresent(value -> propertiesMap.put("product", value)); + Optional.ofNullable(notificationUserToSend.getState()).ifPresent(value -> propertiesMap.put("state", value)); + Optional.ofNullable(notificationUserToSend.getFilePath()).ifPresent(value -> propertiesMap.put("filePath", value)); + Optional.ofNullable(notificationUserToSend.getFileName()).ifPresent(value -> propertiesMap.put("fileName", value)); + Optional.ofNullable(notificationUserToSend.getContentType()).ifPresent(value -> propertiesMap.put("contentType", value)); + Optional.ofNullable(notificationUserToSend.getOnboardingTokenId()).ifPresent(value -> propertiesMap.put("onboardingTokenId", value)); + Optional.ofNullable(notificationUserToSend.getPricingPlan()).ifPresent(value -> propertiesMap.put("pricingPlan", value)); + + if (Optional.ofNullable(notificationUserToSend.getUser()).isPresent()) { + + Optional.ofNullable(notificationUserToSend.getUser().getUserId()).ifPresent(value -> propertiesMap.put("userId", value)); + Optional.ofNullable(notificationUserToSend.getUser().getRole()).ifPresent(value -> propertiesMap.put("role", value)); + Optional.ofNullable(notificationUserToSend.getUser().getRelationshipStatus()).ifPresent(value -> propertiesMap.put("relationshipStatus()", value)); + Optional.ofNullable(notificationUserToSend.getUser().getProductRole()).ifPresent(value -> propertiesMap.put("productRole()", value)); + } + return propertiesMap; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java index 270082f3a..3b7448263 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java @@ -7,5 +7,6 @@ private CustomMetricsConst() { public static final String EVENT_ONBOARDING_FN_NAME = "ONBOARDING-FN"; public static final String EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE = "EventsOnboardingInstitution_failures"; public static final String EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS = "EventsOnboardingInstitution_success"; + public static final String EVENT_ONBOARDING_USER_FN_SUCCESS = "EventsOnboardingUser_success"; } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index 0714a7ae2..8c232a1ea 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -1,5 +1,6 @@ package it.pagopa.selfcare.onboarding.utils; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.*; import it.pagopa.selfcare.onboarding.entity.Onboarding; @@ -8,10 +9,11 @@ import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import java.time.OffsetDateTime; import java.util.Objects; import java.util.UUID; -public class FdNotificationBuilder extends BaseNotificationBuilder { +public class FdNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder { public FdNotificationBuilder( String alternativeEmail, NotificationConfig.Consumer consumer, @@ -44,7 +46,7 @@ public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) @Override public BillingToSend retrieveBilling(Onboarding onboarding) { - if(Objects.isNull(onboarding.getBilling())) { + if (Objects.isNull(onboarding.getBilling())) { return null; } @@ -52,4 +54,44 @@ public BillingToSend retrieveBilling(Onboarding onboarding) { billing.setPublicService(onboarding.getBilling().isPublicServices()); return billing; } + + @Override + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, + OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, + String userId, String partyRole, String productRole) { + NotificationToSend notification = buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE); + NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); + notificationUserToSend.setId(notification.getId()); + notificationUserToSend.setInstitutionId(notification.getInstitutionId()); + notificationUserToSend.setProduct(notification.getProduct()); + notificationUserToSend.setState(notification.getState()); + notificationUserToSend.setFilePath(notification.getFilePath()); + notificationUserToSend.setFileName(notification.getFileName()); + notificationUserToSend.setContentType(notification.getContentType()); + notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId()); + notificationUserToSend.setPricingPlan(notification.getPricingPlan()); + notificationUserToSend.setBilling(notification.getBilling()); + notificationUserToSend.setCreatedAt(createdAt); + notificationUserToSend.setUpdatedAt(updatedAt); + QueueUserEvent queueUserEvent = switch (status) { + case "DELETE" -> QueueUserEvent.DELETE_USER; + case "SUSPEND" -> QueueUserEvent.SUSPEND_USER; + default -> QueueUserEvent.ACTIVE_USER; + }; + notificationUserToSend.setNotificationType(queueUserEvent); + notificationUserToSend.setType(NotificationUserType.getNotificationTypeFromQueueEvent(queueUserEvent)); + UserToNotify user = new UserToNotify(); + user.setUserId(userId); + user.setRole(partyRole); + user.setProductRole(productRole); + user.setRelationshipStatus(status); + notificationUserToSend.setUser(user); + + return notificationUserToSend; + } + + @Override + public boolean shouldSendUserNotification(Onboarding onboarding, InstitutionResponse institution) { + return true; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java new file mode 100644 index 000000000..a9daaee7c --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java @@ -0,0 +1,19 @@ +package it.pagopa.selfcare.onboarding.utils; + +import it.pagopa.selfcare.onboarding.common.PartyRole; +import it.pagopa.selfcare.onboarding.dto.NotificationUserToSend; +import it.pagopa.selfcare.onboarding.entity.Onboarding; +import it.pagopa.selfcare.onboarding.entity.Token; +import org.openapi.quarkus.core_json.model.InstitutionResponse; + +import java.time.OffsetDateTime; + +public interface NotificationUserBuilder { + NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, + OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, + String userId, String partyRole, String productRole); + + default boolean shouldSendUserNotification(Onboarding onboarding, InstitutionResponse institution) { + return false; + } +} diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java index 80f5bbf41..b8a77a88e 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java @@ -22,24 +22,33 @@ public class NotificationUserBuilderFactory { GeographicTaxonomiesApi geographicTaxonomiesApi; @Inject @RestClient - UoApi proxyRegistryUoApi; + org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi; + private final String alternativeEmail; @Inject @RestClient - AooApi proxyRegistryAooApi; + UoApi proxyRegistryUoApi; @Inject @RestClient - org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi; - private final String alternativeEmail; + AooApi proxyRegistryAooApi; public NotificationUserBuilderFactory(@ConfigProperty(name = "onboarding-functions.sender-mail") String alternativeEmail) { this.alternativeEmail = alternativeEmail; } - public NotificationBuilder create(NotificationConfig.Consumer consumer) { + public NotificationUserBuilder create(NotificationConfig.Consumer consumer) { + + NotificationUserBuilder notificationUserBuilder; if (SC_CONTRACTS_FD.getValue().equalsIgnoreCase(consumer.topic())) { - return new FdNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); + notificationUserBuilder = new FdNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); + } else if (SC_CONTRACTS_SAP.getValue().equalsIgnoreCase(consumer.topic())) { + notificationUserBuilder = new SapNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi, proxyRegistryUoApi, proxyRegistryAooApi); + } else if (SC_CONTRACTS.getValue().equalsIgnoreCase(consumer.topic())) { + notificationUserBuilder = new StandardNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); + } else { + throw new IllegalArgumentException("Topic not supported"); } - return null; + + return notificationUserBuilder; } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java deleted file mode 100644 index 1f95657a1..000000000 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserFDBuilder.java +++ /dev/null @@ -1,25 +0,0 @@ -package it.pagopa.selfcare.onboarding.utils; - -import it.pagopa.selfcare.onboarding.dto.BillingToSend; -import it.pagopa.selfcare.onboarding.dto.InstitutionToNotify; -import it.pagopa.selfcare.onboarding.dto.NotificationToSend; -import it.pagopa.selfcare.onboarding.dto.QueueEvent; -import it.pagopa.selfcare.onboarding.entity.Onboarding; -import it.pagopa.selfcare.onboarding.entity.Token; -import org.openapi.quarkus.core_json.model.InstitutionResponse; - -public interface NotificationUserFDBuilder { - NotificationToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent); - -// default boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) { -// return true; -// } -// -// InstitutionToNotify retrieveInstitution(InstitutionResponse institution); -// -// void setTokenData(NotificationToSend notificationToSend, Token token); -// -// void retrieveAndSetGeographicData(InstitutionToNotify institution); -// -// BillingToSend retrieveBilling(Onboarding onboarding); -} diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java index e73d36383..2fe7f69b6 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java @@ -1,5 +1,6 @@ package it.pagopa.selfcare.onboarding.utils; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.common.PricingPlan; import it.pagopa.selfcare.onboarding.common.ProductId; import it.pagopa.selfcare.onboarding.config.NotificationConfig; @@ -16,11 +17,12 @@ import org.openapi.quarkus.party_registry_proxy_json.model.InstitutionResource; import org.openapi.quarkus.party_registry_proxy_json.model.UOResource; +import java.time.OffsetDateTime; import java.util.Objects; import java.util.Set; import java.util.UUID; -public class SapNotificationBuilder extends BaseNotificationBuilder { +public class SapNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder { private final UoApi proxyRegistryUoApi; private final AooApi proxyRegistryAooApi; @@ -37,6 +39,7 @@ public SapNotificationBuilder( this.proxyRegistryUoApi = proxyRegistryUoApi; this.proxyRegistryAooApi = proxyRegistryAooApi; } + @Override public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) { NotificationToSend notificationToSend = super.buildNotificationToSend(onboarding, token, institution, queueEvent); @@ -60,9 +63,10 @@ private static void setNotificationToSendInstitutionDescription(NotificationToSe + " - " + notificationToSend.getInstitution().getDescription()); } } + @Override public BillingToSend retrieveBilling(Onboarding onboarding) { - if(Objects.isNull(onboarding.getBilling())) { + if (Objects.isNull(onboarding.getBilling())) { return null; } @@ -70,6 +74,7 @@ public BillingToSend retrieveBilling(Onboarding onboarding) { billing.setPublicService(onboarding.getBilling().isPublicServices()); return billing; } + @Override public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) { InstitutionToNotify institutionToNotify = super.retrieveInstitution(institution); @@ -78,6 +83,7 @@ public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) institutionToNotify.setCategory(null); return institutionToNotify; } + @Override public void retrieveAndSetGeographicData(InstitutionToNotify institutionToNotify) { GeographicTaxonomyResource geographicTaxonomies; @@ -111,6 +117,7 @@ public void retrieveAndSetGeographicData(InstitutionToNotify institutionToNotify institutionToNotify.setCity(geographicTaxonomies.getDesc().replace(DESCRIPTION_TO_REPLACE_REGEX, "")); } } + @Override public boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) { return isProductAllowed(onboarding) && isAllowedInstitutionType(institution) && isAllowedOrigin(institution.getOrigin()); @@ -133,4 +140,9 @@ private boolean isAllowedOrigin(String origin) { private boolean isNullOrEmpty(Set set) { return Objects.isNull(set) || set.isEmpty(); } + + @Override + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, String userId, String partyRole, String productRole) { + return null; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java index 40d20c37a..2130c92db 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java @@ -1,5 +1,6 @@ package it.pagopa.selfcare.onboarding.utils; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.*; import it.pagopa.selfcare.onboarding.entity.Onboarding; @@ -8,9 +9,10 @@ import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import java.time.OffsetDateTime; import java.util.Objects; -public class StandardNotificationBuilder extends BaseNotificationBuilder { +public class StandardNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder { public StandardNotificationBuilder( String alternativeEmail, NotificationConfig.Consumer consumer, @@ -20,6 +22,7 @@ public StandardNotificationBuilder( ) { super(alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); } + @Override public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) { NotificationToSend notificationToSend = super.buildNotificationToSend(onboarding, token, institution, queueEvent); @@ -31,7 +34,7 @@ public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token t @Override public BillingToSend retrieveBilling(Onboarding onboarding) { - if(Objects.isNull(onboarding.getBilling())) { + if (Objects.isNull(onboarding.getBilling())) { return null; } @@ -61,5 +64,8 @@ private void retrieveAndSetAggregatorInfo(Onboarding onboarding, NotificationToS } } - + @Override + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, String userId, String partyRole, String productRole) { + return null; + } } diff --git a/libs/onboarding-sdk-product/pom.xml b/libs/onboarding-sdk-product/pom.xml index ce7bf49e2..26ac23f8d 100644 --- a/libs/onboarding-sdk-product/pom.xml +++ b/libs/onboarding-sdk-product/pom.xml @@ -7,6 +7,7 @@ 0.3.3 ../onboarding-sdk-pom + onboarding-sdk-product onboarding-sdk-product 0.3.3 @@ -28,6 +29,7 @@ onboarding-sdk-azure-storage ${project.version} + w it.pagopa.selfcare From 2f33ea5ba532ba3accb1cc343916866bdd051e69 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 18:03:39 +0200 Subject: [PATCH 06/29] chore: Working on send user notification --- .../NotificationEventServiceDefaultTest.java | 13 +++++++++++-- libs/onboarding-sdk-product/pom.xml | 2 -- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 6e70f01ea..17c635eee 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -24,7 +24,9 @@ import org.junit.jupiter.api.Test; import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; +import org.openapi.quarkus.user_json.model.UserDataResponse; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -52,6 +54,10 @@ public class NotificationEventServiceDefaultTest { @InjectMock TokenRepository tokenRepository; + @RestClient + @InjectMock + org.openapi.quarkus.user_json.api.UserApi userApi; + @RestClient @InjectMock InstitutionApi institutionApi; @@ -68,6 +74,9 @@ void sendMessage() { mockNotificationMapper(true); when(tokenRepository.findByOnboardingId(any())).thenReturn(Optional.of(new Token())); when(institutionApi.retrieveInstitutionByIdUsingGET(any())).thenReturn(new InstitutionResponse()); + List users = new ArrayList<>(); + when(userApi.usersUserIdInstitutionInstitutionIdGet(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(users); ExecutionContext context = mock(ExecutionContext.class); doReturn(Logger.getGlobal()).when(context).getLogger(); doNothing().when(eventHubRestClient).sendMessage(anyString(), anyString()); @@ -195,7 +204,7 @@ void sendMessageWontProceedsWhenOnboardingIsNotReferredToInstitution() { @Test void notificationEventMapTest() { - NotificationToSend notificationToSend = new NotificationToSend(); + NotificationToSend notificationToSend = new NotificationToSend(); notificationToSend.setId("id"); notificationToSend.setInternalIstitutionID("internal"); notificationToSend.setProduct("prod"); @@ -236,7 +245,7 @@ void notificationEventMapTest() { @Test void notificationEventMapRootParentTest() { - NotificationToSend notificationToSend = new NotificationToSend(); + NotificationToSend notificationToSend = new NotificationToSend(); notificationToSend.setId("id"); notificationToSend.setInternalIstitutionID("internal"); notificationToSend.setProduct("prod"); diff --git a/libs/onboarding-sdk-product/pom.xml b/libs/onboarding-sdk-product/pom.xml index 26ac23f8d..ce7bf49e2 100644 --- a/libs/onboarding-sdk-product/pom.xml +++ b/libs/onboarding-sdk-product/pom.xml @@ -7,7 +7,6 @@ 0.3.3 ../onboarding-sdk-pom - onboarding-sdk-product onboarding-sdk-product 0.3.3 @@ -29,7 +28,6 @@ onboarding-sdk-azure-storage ${project.version} - w it.pagopa.selfcare From e4e53dabd357cc68c43b23ea3cd7f66b72128ef7 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 18:45:33 +0200 Subject: [PATCH 07/29] chore: Adding Test --- .../NotificationEventServiceDefault.java | 4 +- .../utils/FdNotificationBuilderTest.java | 88 ++++++++++++++++++- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 491fee8bf..6edb12bd9 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -142,7 +142,9 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr notificationsResources.getInstitution(), onboardedProductResponse.getCreatedAt(), onboardedProductResponse.getUpdatedAt(), - onboardedProductResponse.getStatus().toString(), userDataResponse.getUserId(), onboardedProductResponse.getRole(), + onboardedProductResponse.getStatus().toString(), + userDataResponse.getUserId(), + onboardedProductResponse.getRole(), onboardedProductResponse.getProductRole()); sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java index 9e51d7ce7..0c14c0056 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java @@ -4,8 +4,7 @@ import io.quarkus.test.junit.QuarkusTest; import it.pagopa.selfcare.onboarding.common.OnboardingStatus; import it.pagopa.selfcare.onboarding.config.NotificationConfig; -import it.pagopa.selfcare.onboarding.dto.NotificationToSend; -import it.pagopa.selfcare.onboarding.dto.NotificationType; +import it.pagopa.selfcare.onboarding.dto.*; import it.pagopa.selfcare.onboarding.dto.QueueEvent; import it.pagopa.selfcare.onboarding.entity.Billing; import it.pagopa.selfcare.onboarding.entity.Onboarding; @@ -16,8 +15,11 @@ import org.openapi.quarkus.core_json.model.InstitutionResponse; import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import org.openapi.quarkus.user_json.model.*; import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; import static it.pagopa.selfcare.onboarding.entity.Topic.SC_CONTRACTS_FD; import static it.pagopa.selfcare.onboarding.utils.NotificationBuilderTestUtil.*; @@ -37,6 +39,9 @@ class FdNotificationBuilderTest { @InjectMock @RestClient org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi; + @RestClient + @InjectMock + org.openapi.quarkus.user_json.api.UserApi userApi; FdNotificationBuilder fdNotificationBuilder; @@ -88,4 +93,83 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventAdd() { assertEquals(onboarding.getBilling().isPublicServices(), notification.getBilling().isPublicService()); assertNull(notification.getFilePath()); } + + @Test + void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { + + // Create Onboarding + Onboarding onboarding = createOnboarding( + OnboardingStatus.COMPLETED, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + OffsetDateTime.parse("2020-11-02T10:02:00Z"), // activatedAt + OffsetDateTime.parse("2020-11-02T10:05:00Z"), // updatedAt + null // deletedAt + ); + + Billing billing = new Billing(); + billing.setTaxCodeInvoicing("taxCodeInvoicing"); + onboarding.setBilling(billing); + + // Create Institution + InstitutionResponse institution = createInstitution(); + // Create Token + Token token = createToken(); + + InstitutionResponse institutionParentResource = new InstitutionResponse(); + institutionParentResource.setOriginId("parentOriginId"); + when(coreInstitutionApi.retrieveInstitutionByIdUsingGET(any())) + .thenReturn(institutionParentResource); + + OnboardedProductResponse productResponse = new OnboardedProductResponse(); + productResponse.setProductId(productId); + productResponse.setStatus(OnboardedProductState.ACTIVE); + productResponse.setProductRole("security"); + productResponse.setRole("OPERATOR"); + productResponse.setEnv(Env.PROD); + productResponse.setCreatedAt(OffsetDateTime.now()); + productResponse.setUpdatedAt(OffsetDateTime.now()); + + UserResponse userResponse = new UserResponse(); + userResponse.id("userId1"); + + + List users = new ArrayList<>(); + UserDataResponse userDataResponse = new UserDataResponse(); + userDataResponse.setId("userDataId1"); + userDataResponse.setUserId("userId1"); + userDataResponse.setInstitutionId(institution.getId()); + userDataResponse.setInstitutionDescription(institution.getDescription()); + userDataResponse.setUserMailUuid("usermail1"); + userDataResponse.setRole("OPERATOR"); + userDataResponse.setStatus("ACTIVE"); + userDataResponse.setProducts(List.of(productResponse)); + userDataResponse.setUserResponse(userResponse); + + users.add(userDataResponse); + + + when(userApi.usersUserIdInstitutionInstitutionIdGet(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(users); + + NotificationUserToSend notification = fdNotificationBuilder.buildUserNotificationToSend( + onboarding, + token, + institution, + productResponse.getCreatedAt(), + productResponse.getUpdatedAt(), + "ACTIVE", + userDataResponse.getUserId(), + productResponse.getRole(), + productResponse.getProductRole()); + + assertNotNull(notification); + assertNotEquals(onboarding.getId(), notification.getId()); + assertEquals("ACTIVE", notification.getState()); + assertEquals(tokenId, notification.getOnboardingTokenId()); + assertEquals(productResponse.getCreatedAt().toLocalDateTime(), notification.getCreatedAt().toLocalDateTime()); + assertEquals(productResponse.getUpdatedAt().toLocalDateTime(), notification.getUpdatedAt().toLocalDateTime()); + assertEquals(NotificationUserType.ACTIVE_USER, notification.getType()); + assertEquals(productResponse.getProductRole(), notification.getUser().getProductRole()); + assertEquals(productResponse.getRole(), notification.getUser().getRole()); + } } \ No newline at end of file From 584035044c3f52ba2e01cfb3a1c3744a4c1cf747 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 20:43:09 +0200 Subject: [PATCH 08/29] chore: Adding Test --- .../NotificationEventServiceDefault.java | 4 --- ...cationEventResenderServiceDefaultTest.java | 28 ++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 6edb12bd9..cefbaeeef 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -8,8 +8,6 @@ import com.microsoft.applicationinsights.TelemetryConfiguration; import com.microsoft.azure.functions.ExecutionContext; import it.pagopa.selfcare.onboarding.client.eventhub.EventHubRestClient; -import it.pagopa.selfcare.onboarding.common.OnboardingStatus; -import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.NotificationToSend; import it.pagopa.selfcare.onboarding.dto.NotificationUserToSend; @@ -30,8 +28,6 @@ import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; import org.openapi.quarkus.user_json.model.UserDataResponse; -import org.openapi.quarkus.user_json.model.UserInstitutionResponse; -import org.openapi.quarkus.user_registry_json.api.UserApi; import java.util.*; diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java index bdb5fe1a8..73047ddef 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java @@ -186,7 +186,7 @@ void resendNotificationsEndsWithMoreElementsToRetrieve() { private List getMockedList(int i) { List onboardings = new ArrayList<>(); - for(int j = 0; j < i; j++) { + for (int j = 0; j < i; j++) { Onboarding onboarding = new Onboarding(); onboarding.setId("id" + j); onboarding.setStatus(OnboardingStatus.COMPLETED); @@ -196,4 +196,30 @@ private List getMockedList(int i) { return onboardings; } + + @Test + void resendNotifications_withUserNotification() { + /* Test that the resendNotifications method works correctly when there are two onboardings 1 COMPLETED (which should produce one notification) and 1 DELETED (which should produce two notifications) and no range is specified */ + // Arrange + ResendNotificationsFilters filters = ResendNotificationsFilters.builder().onboardingId("test").build(); + ExecutionContext context = getMockedContext(); + + Onboarding onboarding = new Onboarding(); + onboarding.setId("id1"); + onboarding.setStatus(OnboardingStatus.COMPLETED); + onboarding.setProductId("prod-fd"); + onboarding.setActivatedAt(LocalDateTime.of(2023, 2, 1, 0, 0)); + + + when(onboardingService.getOnboardingsToResend(filters, 0, 100)).thenReturn(List.of(onboarding)); + doNothing().when(notificationEventService).send(any(), any(), any(), any()); + + // Act + ResendNotificationsFilters resendNotificationsFilters = notificationEventResenderServiceDefault.resendNotifications(filters, context); + + // Assert + verify(notificationEventService, times(1)).send(any(), any(), any(), any()); + verify(onboardingService).getOnboardingsToResend(filters, 0, 100); + assertNull(resendNotificationsFilters); + } } \ No newline at end of file From 85b15a0c2fe4053def46b82e49799531fd6e7be6 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 21:15:16 +0200 Subject: [PATCH 09/29] chore: Adding Test --- .../NotificationEventServiceDefault.java | 32 ++++--- .../NotificationEventServiceDefaultTest.java | 90 ++++++++++++++----- .../utils/FdNotificationBuilderTest.java | 75 +++++++++------- 3 files changed, 128 insertions(+), 69 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index cefbaeeef..d4d5ca62e 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -27,6 +27,7 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; +import org.openapi.quarkus.user_json.model.OnboardedProductResponse; import org.openapi.quarkus.user_json.model.UserDataResponse; import java.util.*; @@ -132,16 +133,7 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr users.forEach(userDataResponse -> { userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { if (onboardedProductResponse.getProductId().equals(product.getId())) { - NotificationUserToSend notificationUserToSend = notificationUserBuilder.buildUserNotificationToSend( - notificationsResources.getOnboarding(), - notificationsResources.getToken(), - notificationsResources.getInstitution(), - onboardedProductResponse.getCreatedAt(), - onboardedProductResponse.getUpdatedAt(), - onboardedProductResponse.getStatus().toString(), - userDataResponse.getUserId(), - onboardedProductResponse.getRole(), - onboardedProductResponse.getProductRole()); + NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); } return false; @@ -156,6 +148,22 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr } } + public static NotificationUserToSend getNotificationUserToSend(NotificationsResources notificationsResources, + UserDataResponse userDataResponse, + OnboardedProductResponse onboardedProductResponse, + NotificationUserBuilder notificationUserBuilder) { + return notificationUserBuilder.buildUserNotificationToSend( + notificationsResources.getOnboarding(), + notificationsResources.getToken(), + notificationsResources.getInstitution(), + onboardedProductResponse.getCreatedAt(), + onboardedProductResponse.getUpdatedAt(), + onboardedProductResponse.getStatus().toString(), + userDataResponse.getUserId(), + onboardedProductResponse.getRole(), + onboardedProductResponse.getProductRole()); + } + private void sendNotification(ExecutionContext context, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { String message = null; try { @@ -280,8 +288,8 @@ public static Map notificationUserEventMap(NotificationUserToSen Optional.ofNullable(notificationUserToSend.getUser().getUserId()).ifPresent(value -> propertiesMap.put("userId", value)); Optional.ofNullable(notificationUserToSend.getUser().getRole()).ifPresent(value -> propertiesMap.put("role", value)); - Optional.ofNullable(notificationUserToSend.getUser().getRelationshipStatus()).ifPresent(value -> propertiesMap.put("relationshipStatus()", value)); - Optional.ofNullable(notificationUserToSend.getUser().getProductRole()).ifPresent(value -> propertiesMap.put("productRole()", value)); + Optional.ofNullable(notificationUserToSend.getUser().getRelationshipStatus()).ifPresent(value -> propertiesMap.put("relationshipStatus", value)); + Optional.ofNullable(notificationUserToSend.getUser().getProductRole()).ifPresent(value -> propertiesMap.put("productRole", value)); } return propertiesMap; } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 17c635eee..675ef4f53 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -204,19 +204,9 @@ void sendMessageWontProceedsWhenOnboardingIsNotReferredToInstitution() { @Test void notificationEventMapTest() { - NotificationToSend notificationToSend = new NotificationToSend(); - notificationToSend.setId("id"); - notificationToSend.setInternalIstitutionID("internal"); - notificationToSend.setProduct("prod"); - notificationToSend.setState("state"); - notificationToSend.setFileName("fileName"); - notificationToSend.setFilePath("filePath"); - notificationToSend.setContentType("contentType"); + NotificationToSend notificationToSend = getNotificationBaseToSend(); - InstitutionToNotify institution = new InstitutionToNotify(); - institution.setDescription("description"); - institution.setInstitutionType(InstitutionType.SA); - institution.setDigitalAddress("mail"); + InstitutionToNotify institution = getInstitutionToNotify(); notificationToSend.setInstitution(institution); BillingToSend billing = new BillingToSend(); @@ -245,19 +235,9 @@ void notificationEventMapTest() { @Test void notificationEventMapRootParentTest() { - NotificationToSend notificationToSend = new NotificationToSend(); - notificationToSend.setId("id"); - notificationToSend.setInternalIstitutionID("internal"); - notificationToSend.setProduct("prod"); - notificationToSend.setState("state"); - notificationToSend.setFileName("fileName"); - notificationToSend.setFilePath("filePath"); - notificationToSend.setContentType("contentType"); + NotificationToSend notificationToSend = getNotificationBaseToSend(); - InstitutionToNotify institution = new InstitutionToNotify(); - institution.setDescription("description"); - institution.setInstitutionType(InstitutionType.SA); - institution.setDigitalAddress("mail"); + InstitutionToNotify institution = getInstitutionToNotify(); RootParent rootParent = new RootParent(); rootParent.setDescription("RootDescription"); rootParent.setId("RootId"); @@ -348,4 +328,66 @@ private Product createProduct() { return product; } + + @Test + void notificationEventUserMapTest() { + NotificationUserToSend notificationUserToSend = getNotificationUserBaseToSend(); + UserToNotify user = new UserToNotify(); + user.setUserId("userId"); + user.setRole("OPERATOR"); + user.setProductRole("api"); + user.setRelationshipStatus("ACTIVE"); + notificationUserToSend.setUser(user); + + + Map properties = NotificationEventServiceDefault.notificationUserEventMap(notificationUserToSend, "topic", "traceId"); + assertNotNull(properties); + assertEquals("traceId", properties.get("notificationEventTraceId")); + assertEquals("id", properties.get("id")); + assertEquals("internal", properties.get("institutionId")); + assertEquals("prod", properties.get("product")); + assertEquals("state", properties.get("state")); + assertEquals("fileName", properties.get("fileName")); + assertEquals(properties.get("filePath"), "filePath"); + assertEquals(properties.get("contentType"), "application/octet-stream"); + + + assertEquals("userId", properties.get("userId")); + assertEquals("OPERATOR", properties.get("role")); + assertEquals("ACTIVE", properties.get("relationshipStatus")); + assertEquals("api", properties.get("productRole")); + + } + + private static InstitutionToNotify getInstitutionToNotify() { + InstitutionToNotify institution = new InstitutionToNotify(); + institution.setDescription("description"); + institution.setInstitutionType(InstitutionType.SA); + institution.setDigitalAddress("mail"); + return institution; + } + + private static NotificationToSend getNotificationBaseToSend() { + NotificationToSend notificationToSend = new NotificationToSend(); + notificationToSend.setId("id"); + notificationToSend.setInternalIstitutionID("internal"); + notificationToSend.setProduct("prod"); + notificationToSend.setState("state"); + notificationToSend.setFileName("fileName"); + notificationToSend.setFilePath("filePath"); + notificationToSend.setContentType("contentType"); + return notificationToSend; + } + + private static NotificationUserToSend getNotificationUserBaseToSend() { + NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); + notificationUserToSend.setId("id"); + notificationUserToSend.setInstitutionId("internal"); + notificationUserToSend.setProduct("prod"); + notificationUserToSend.setState("state"); + notificationUserToSend.setFileName("fileName"); + notificationUserToSend.setFilePath("filePath"); + notificationUserToSend.setContentType("contentType"); + return notificationUserToSend; + } } \ No newline at end of file diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java index 0c14c0056..17b02c129 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java @@ -56,13 +56,7 @@ public void setup() { void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventAdd() { // Create Onboarding - Onboarding onboarding = createOnboarding( - OnboardingStatus.COMPLETED, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - OffsetDateTime.parse("2020-11-02T10:02:00Z"), // activatedAt - OffsetDateTime.parse("2020-11-02T10:05:00Z"), // updatedAt - null // deletedAt - ); + Onboarding onboarding = getOnboardingTest(); Billing billing = new Billing(); billing.setTaxCodeInvoicing("taxCodeInvoicing"); onboarding.setBilling(billing); @@ -98,13 +92,7 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventAdd() { void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { // Create Onboarding - Onboarding onboarding = createOnboarding( - OnboardingStatus.COMPLETED, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - OffsetDateTime.parse("2020-11-02T10:02:00Z"), // activatedAt - OffsetDateTime.parse("2020-11-02T10:05:00Z"), // updatedAt - null // deletedAt - ); + Onboarding onboarding = getOnboardingTest(); Billing billing = new Billing(); billing.setTaxCodeInvoicing("taxCodeInvoicing"); @@ -120,31 +108,15 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { when(coreInstitutionApi.retrieveInstitutionByIdUsingGET(any())) .thenReturn(institutionParentResource); - OnboardedProductResponse productResponse = new OnboardedProductResponse(); - productResponse.setProductId(productId); - productResponse.setStatus(OnboardedProductState.ACTIVE); - productResponse.setProductRole("security"); - productResponse.setRole("OPERATOR"); - productResponse.setEnv(Env.PROD); - productResponse.setCreatedAt(OffsetDateTime.now()); - productResponse.setUpdatedAt(OffsetDateTime.now()); + OnboardedProductResponse productResponse = getOnboardedProductResponse(); UserResponse userResponse = new UserResponse(); userResponse.id("userId1"); - List users = new ArrayList<>(); - UserDataResponse userDataResponse = new UserDataResponse(); - userDataResponse.setId("userDataId1"); - userDataResponse.setUserId("userId1"); - userDataResponse.setInstitutionId(institution.getId()); - userDataResponse.setInstitutionDescription(institution.getDescription()); - userDataResponse.setUserMailUuid("usermail1"); - userDataResponse.setRole("OPERATOR"); - userDataResponse.setStatus("ACTIVE"); - userDataResponse.setProducts(List.of(productResponse)); - userDataResponse.setUserResponse(userResponse); + UserDataResponse userDataResponse = getUserDataResponse(institution, productResponse, userResponse); + List users = new ArrayList<>(); users.add(userDataResponse); @@ -172,4 +144,41 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { assertEquals(productResponse.getProductRole(), notification.getUser().getProductRole()); assertEquals(productResponse.getRole(), notification.getUser().getRole()); } + + private static UserDataResponse getUserDataResponse(InstitutionResponse institution, OnboardedProductResponse productResponse, UserResponse userResponse) { + UserDataResponse userDataResponse = new UserDataResponse(); + userDataResponse.setId("userDataId1"); + userDataResponse.setUserId("userId1"); + userDataResponse.setInstitutionId(institution.getId()); + userDataResponse.setInstitutionDescription(institution.getDescription()); + userDataResponse.setUserMailUuid("usermail1"); + userDataResponse.setRole("OPERATOR"); + userDataResponse.setStatus("ACTIVE"); + userDataResponse.setProducts(List.of(productResponse)); + userDataResponse.setUserResponse(userResponse); + return userDataResponse; + } + + private static OnboardedProductResponse getOnboardedProductResponse() { + OnboardedProductResponse productResponse = new OnboardedProductResponse(); + productResponse.setProductId(productId); + productResponse.setStatus(OnboardedProductState.ACTIVE); + productResponse.setProductRole("security"); + productResponse.setRole("OPERATOR"); + productResponse.setEnv(Env.PROD); + productResponse.setCreatedAt(OffsetDateTime.now()); + productResponse.setUpdatedAt(OffsetDateTime.now()); + return productResponse; + } + + private static Onboarding getOnboardingTest() { + Onboarding onboarding = createOnboarding( + OnboardingStatus.COMPLETED, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + OffsetDateTime.parse("2020-11-02T10:02:00Z"), // activatedAt + OffsetDateTime.parse("2020-11-02T10:05:00Z"), // updatedAt + null // deletedAt + ); + return onboarding; + } } \ No newline at end of file From c8c2135622ad36311b39b34cfce16a6ff7fe121f Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 21:32:45 +0200 Subject: [PATCH 10/29] chore: Adding Test --- .../pagopa/selfcare/onboarding/dto/NotificationUserToSend.java | 2 +- .../selfcare/onboarding/utils/FdNotificationBuilderTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java index ce6a05152..ca7492867 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java @@ -175,7 +175,7 @@ public void setUser(UserToNotify user) { public String toString() { return "NotificationToSend{" + "id='" + id + '\'' + - ", istitutionID='" + institutionId + '\'' + + ", institutionId='" + institutionId + '\'' + ", product='" + product + '\'' + ", state='" + state + '\'' + ", filePath='" + filePath + '\'' + diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java index 17b02c129..7f245b87c 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java @@ -143,6 +143,9 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { assertEquals(NotificationUserType.ACTIVE_USER, notification.getType()); assertEquals(productResponse.getProductRole(), notification.getUser().getProductRole()); assertEquals(productResponse.getRole(), notification.getUser().getRole()); + + assertTrue(notification.toString().contains("institutionId='" + notification.getInstitutionId() + "'")); + } private static UserDataResponse getUserDataResponse(InstitutionResponse institution, OnboardedProductResponse productResponse, UserResponse userResponse) { From 3d19a11392e3ece5ef05e823c08e3cf95ec4d827 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 22:09:40 +0200 Subject: [PATCH 11/29] chore: Adding Logs --- .../onboarding/service/NotificationEventServiceDefault.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index d4d5ca62e..8425dcbdf 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -129,11 +129,14 @@ private void prepareAndSendNotification(ExecutionContext context, Product produc private void prepareAndSendUserNotification(ExecutionContext context, Product product, NotificationConfig.Consumer consumer, NotificationsResources notificationsResources, String notificationEventTraceId) { NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { + context.getLogger().info(() -> String.format("prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), null, null, null, null, null, null); users.forEach(userDataResponse -> { + context.getLogger().info(() -> String.format("userDataResponse %s [%s]", userDataResponse.getUserId(), consumer.topic())); userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { if (onboardedProductResponse.getProductId().equals(product.getId())) { NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); + context.getLogger().info(() -> String.format("Sending user notification %s", notificationUserToSend.toString())); sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); } return false; From 33a7e2a7b444071c8edf5fb8d5313c00edf0a9c4 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 22:22:05 +0200 Subject: [PATCH 12/29] chore: Adding Logs --- .../NotificationEventServiceDefault.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 8425dcbdf..e7d813130 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -130,19 +130,20 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { context.getLogger().info(() -> String.format("prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); - List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), null, null, null, null, null, null); - users.forEach(userDataResponse -> { - context.getLogger().info(() -> String.format("userDataResponse %s [%s]", userDataResponse.getUserId(), consumer.topic())); - userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { - if (onboardedProductResponse.getProductId().equals(product.getId())) { - NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); - context.getLogger().info(() -> String.format("Sending user notification %s", notificationUserToSend.toString())); - sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); - } - return false; - }); - + notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { + List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), null, null, null, null, null); + users.forEach(userDataResponse -> { + context.getLogger().info(() -> String.format("userDataResponse %s [%s]", userDataResponse.getUserId(), consumer.topic())); + userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { + if (onboardedProductResponse.getProductId().equals(product.getId())) { + NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); + context.getLogger().info(() -> String.format("Sending user notification %s", notificationUserToSend.toString())); + sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); + } + return false; + }); + }); }); From 66e8ffa8b8d0e46b44c6a297af35cb0edb23ec23 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 23:07:59 +0200 Subject: [PATCH 13/29] chore: Set createdAt as string --- .../onboarding/dto/NotificationUserToSend.java | 16 ++++++++-------- .../onboarding/utils/FdNotificationBuilder.java | 4 ++-- .../utils/NotificationUserBuilder.java | 2 +- .../onboarding/utils/SapNotificationBuilder.java | 2 +- .../utils/StandardNotificationBuilder.java | 2 +- .../src/main/openapi/user.json | 1 - .../utils/FdNotificationBuilderTest.java | 8 ++++---- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java index ca7492867..9a1cb0b3a 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java @@ -21,12 +21,12 @@ public class NotificationUserToSend { private String onboardingTokenId; private String pricingPlan; private BillingToSend billing; - @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) - private OffsetDateTime createdAt; + + private String createdAt; @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) private OffsetDateTime closedAt; - @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) - private OffsetDateTime updatedAt; + + private String updatedAt; private QueueUserEvent notificationType; private NotificationUserType type; private UserToNotify user; @@ -147,19 +147,19 @@ public void setBilling(BillingToSend billing) { this.billing = billing; } - public OffsetDateTime getCreatedAt() { + public String getCreatedAt() { return createdAt; } - public void setCreatedAt(OffsetDateTime createdAt) { + public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index 8c232a1ea..e787c1a53 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -57,7 +57,7 @@ public BillingToSend retrieveBilling(Onboarding onboarding) { @Override public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, - OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, + String createdAt, String updatedAt, String status, String userId, String partyRole, String productRole) { NotificationToSend notification = buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE); NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); @@ -71,7 +71,7 @@ public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId()); notificationUserToSend.setPricingPlan(notification.getPricingPlan()); notificationUserToSend.setBilling(notification.getBilling()); - notificationUserToSend.setCreatedAt(createdAt); + notificationUserToSend.setCreatedAt(createdAt.toString()); notificationUserToSend.setUpdatedAt(updatedAt); QueueUserEvent queueUserEvent = switch (status) { case "DELETE" -> QueueUserEvent.DELETE_USER; diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java index a9daaee7c..a3d1f7c8a 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java @@ -10,7 +10,7 @@ public interface NotificationUserBuilder { NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, - OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, + String createdAt, String updatedAt, String status, String userId, String partyRole, String productRole); default boolean shouldSendUserNotification(Onboarding onboarding, InstitutionResponse institution) { diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java index 2fe7f69b6..f7da85d81 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java @@ -142,7 +142,7 @@ private boolean isNullOrEmpty(Set set) { } @Override - public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, String userId, String partyRole, String productRole) { + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, String createdAt, String updatedAt, String status, String userId, String partyRole, String productRole) { return null; } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java index 2130c92db..f839fd05f 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java @@ -65,7 +65,7 @@ private void retrieveAndSetAggregatorInfo(Onboarding onboarding, NotificationToS } @Override - public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, OffsetDateTime createdAt, OffsetDateTime updatedAt, String status, String userId, String partyRole, String productRole) { + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, String createdAt, String updatedAt, String status, String userId, String partyRole, String productRole) { return null; } } diff --git a/apps/onboarding-functions/src/main/openapi/user.json b/apps/onboarding-functions/src/main/openapi/user.json index 4644cbf9a..53db2ad15 100644 --- a/apps/onboarding-functions/src/main/openapi/user.json +++ b/apps/onboarding-functions/src/main/openapi/user.json @@ -1388,7 +1388,6 @@ "type": "string" }, "LocalDateTime": { - "format": "date-time", "type": "string", "example": "2022-03-10T12:15:50" }, diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java index 7f245b87c..6372e9723 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java @@ -138,8 +138,8 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { assertNotEquals(onboarding.getId(), notification.getId()); assertEquals("ACTIVE", notification.getState()); assertEquals(tokenId, notification.getOnboardingTokenId()); - assertEquals(productResponse.getCreatedAt().toLocalDateTime(), notification.getCreatedAt().toLocalDateTime()); - assertEquals(productResponse.getUpdatedAt().toLocalDateTime(), notification.getUpdatedAt().toLocalDateTime()); + assertEquals(productResponse.getCreatedAt(), notification.getCreatedAt()); + assertEquals(productResponse.getUpdatedAt(), notification.getUpdatedAt()); assertEquals(NotificationUserType.ACTIVE_USER, notification.getType()); assertEquals(productResponse.getProductRole(), notification.getUser().getProductRole()); assertEquals(productResponse.getRole(), notification.getUser().getRole()); @@ -169,8 +169,8 @@ private static OnboardedProductResponse getOnboardedProductResponse() { productResponse.setProductRole("security"); productResponse.setRole("OPERATOR"); productResponse.setEnv(Env.PROD); - productResponse.setCreatedAt(OffsetDateTime.now()); - productResponse.setUpdatedAt(OffsetDateTime.now()); + productResponse.setCreatedAt("2024-10-10T10:35:42.144Z"); + productResponse.setUpdatedAt("2024-10-10T10:35:42.144Z"); return productResponse; } From ae6392ca2961bcb2335d5480bc905e4b06ef3786 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 23:17:11 +0200 Subject: [PATCH 14/29] chore: Set createdAt as string --- .../onboarding/service/NotificationEventServiceDefault.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index e7d813130..4684dcb98 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -129,14 +129,16 @@ private void prepareAndSendNotification(ExecutionContext context, Product produc private void prepareAndSendUserNotification(ExecutionContext context, Product product, NotificationConfig.Consumer consumer, NotificationsResources notificationsResources, String notificationEventTraceId) { NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { - context.getLogger().info(() -> String.format("prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); + context.getLogger().info(() -> String.format("[APZ] prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), null, null, null, null, null); users.forEach(userDataResponse -> { - context.getLogger().info(() -> String.format("userDataResponse %s [%s]", userDataResponse.getUserId(), consumer.topic())); + context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.getUserId(), consumer.topic())); userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { + context.getLogger().info(() -> String.format("[APZ] onboardedProductResponse %s [%s]", onboardedProductResponse.getProductId(), consumer.topic())); if (onboardedProductResponse.getProductId().equals(product.getId())) { + context.getLogger().info(() -> String.format("[APZ] getNotificationUserToSend %s [%s]", userDataResponse.getUserId(), consumer.topic())); NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); context.getLogger().info(() -> String.format("Sending user notification %s", notificationUserToSend.toString())); sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); From 879763c64e018edd93199243d3d599b5c6f1fb8e Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 23:31:06 +0200 Subject: [PATCH 15/29] chore: Set createdAt as string --- .../onboarding/service/NotificationEventServiceDefault.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 4684dcb98..e38a6b892 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -132,9 +132,10 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr context.getLogger().info(() -> String.format("[APZ] prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { + context.getLogger().info(() -> String.format("[APZ] onboardingUser %s [%s]", onboardingUser.getId(), consumer.topic())); List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), null, null, null, null, null); users.forEach(userDataResponse -> { - context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.getUserId(), consumer.topic())); + context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.toString(), consumer.topic())); userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { context.getLogger().info(() -> String.format("[APZ] onboardedProductResponse %s [%s]", onboardedProductResponse.getProductId(), consumer.topic())); if (onboardedProductResponse.getProductId().equals(product.getId())) { From 8a0fdb324ddc433549ee25fdf318e1d335145e06 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 23:31:41 +0200 Subject: [PATCH 16/29] chore: Set createdAt as string --- .../onboarding/service/NotificationEventServiceDefault.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index e38a6b892..cea83c7ac 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -137,7 +137,7 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr users.forEach(userDataResponse -> { context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.toString(), consumer.topic())); userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { - context.getLogger().info(() -> String.format("[APZ] onboardedProductResponse %s [%s]", onboardedProductResponse.getProductId(), consumer.topic())); + context.getLogger().info(() -> String.format("[APZ] onboardedProductResponse %s [%s]", onboardedProductResponse.toString(), consumer.topic())); if (onboardedProductResponse.getProductId().equals(product.getId())) { context.getLogger().info(() -> String.format("[APZ] getNotificationUserToSend %s [%s]", userDataResponse.getUserId(), consumer.topic())); NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); From 4492f5a967fe3bfa7fbd7a24f40a1d52d2ced793 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Tue, 15 Oct 2024 23:39:10 +0200 Subject: [PATCH 17/29] chore: Set createdAt as string --- .../onboarding/service/NotificationEventServiceDefault.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index cea83c7ac..bc04b0b06 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -136,7 +136,7 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), null, null, null, null, null); users.forEach(userDataResponse -> { context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.toString(), consumer.topic())); - userDataResponse.getProducts().stream().filter(onboardedProductResponse -> { + userDataResponse.getProducts().forEach(onboardedProductResponse -> { context.getLogger().info(() -> String.format("[APZ] onboardedProductResponse %s [%s]", onboardedProductResponse.toString(), consumer.topic())); if (onboardedProductResponse.getProductId().equals(product.getId())) { context.getLogger().info(() -> String.format("[APZ] getNotificationUserToSend %s [%s]", userDataResponse.getUserId(), consumer.topic())); @@ -144,7 +144,6 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr context.getLogger().info(() -> String.format("Sending user notification %s", notificationUserToSend.toString())); sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); } - return false; }); }); }); From b00d704c86c7117e0b6786ba50567012a45a8d7c Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Wed, 16 Oct 2024 11:59:06 +0200 Subject: [PATCH 18/29] chore: Update model --- .../dto/NotificationUserToSend.java | 79 +------------------ .../selfcare/onboarding/dto/UserToNotify.java | 21 ++--- .../utils/FdNotificationBuilder.java | 25 +++--- 3 files changed, 24 insertions(+), 101 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java index 9a1cb0b3a..173ab2dbd 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java @@ -14,20 +14,15 @@ public class NotificationUserToSend { private String id; private String institutionId; private String product; - private String state; - private String filePath; - private String fileName; - private String contentType; + private String onboardingTokenId; - private String pricingPlan; - private BillingToSend billing; private String createdAt; @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) private OffsetDateTime closedAt; private String updatedAt; - private QueueUserEvent notificationType; + private NotificationUserType type; private UserToNotify user; @@ -50,47 +45,6 @@ public void setType(NotificationUserType type) { } - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getFilePath() { - return filePath; - } - - public void setFilePath(String filePath) { - this.filePath = filePath; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public String getContentType() { - return this.contentType; - } - - public void setContentType(String contractSigned) { - String contractFileName = Objects.isNull(contractSigned) ? "" : Paths.get(contractSigned).getFileName().toString(); - if (contractFileName.isEmpty()) { - this.contentType = ""; - } else if (contractFileName.endsWith(".p7m")) { - this.contentType = "application/pkcs7-mime"; - } else if (contractFileName.endsWith(".pdf")) { - this.contentType = "application/pdf"; - } else { - this.contentType = "application/octet-stream"; - } - } - public String getOnboardingTokenId() { return onboardingTokenId; } @@ -107,13 +61,6 @@ public void setClosedAt(OffsetDateTime closedAt) { this.closedAt = closedAt; } - public QueueUserEvent getNotificationType() { - return notificationType; - } - - public void setNotificationType(QueueUserEvent notificationType) { - this.notificationType = notificationType; - } public String getId() { return id; @@ -131,21 +78,6 @@ public void setProduct(String product) { this.product = product; } - public String getPricingPlan() { - return pricingPlan; - } - - public void setPricingPlan(String pricingPlan) { - this.pricingPlan = pricingPlan; - } - - public BillingToSend getBilling() { - return billing; - } - - public void setBilling(BillingToSend billing) { - this.billing = billing; - } public String getCreatedAt() { return createdAt; @@ -177,17 +109,10 @@ public String toString() { "id='" + id + '\'' + ", institutionId='" + institutionId + '\'' + ", product='" + product + '\'' + - ", state='" + state + '\'' + - ", filePath='" + filePath + '\'' + - ", fileName='" + fileName + '\'' + - ", contentType='" + contentType + '\'' + ", onboardingTokenId='" + onboardingTokenId + '\'' + - ", pricingPlan='" + pricingPlan + '\'' + - ", billing=" + billing + ", createdAt=" + createdAt + ", closedAt=" + closedAt + ", updatedAt=" + updatedAt + - ", notificationType=" + notificationType + ", userId=" + user.getUserId() + '}'; } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java index 96f9354ea..cea745b85 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java @@ -3,13 +3,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import it.pagopa.selfcare.onboarding.common.PartyRole; +import java.util.List; + @JsonInclude(JsonInclude.Include.NON_NULL) public class UserToNotify { private String userId; private String role; - private String productRole; - private String relationshipStatus; + private List roles; public String getUserId() { return userId; @@ -27,19 +28,11 @@ public void setRole(String role) { this.role = role; } - public String getProductRole() { - return productRole; - } - - public void setProductRole(String productRole) { - this.productRole = productRole; - } - - public String getRelationshipStatus() { - return relationshipStatus; + public List getRoles() { + return roles; } - public void setRelationshipStatus(String relationshipStatus) { - this.relationshipStatus = relationshipStatus; + public void setRoles(List roles) { + this.roles = roles; } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index e787c1a53..1d7b407e8 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -10,6 +10,7 @@ import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; import java.time.OffsetDateTime; +import java.util.List; import java.util.Objects; import java.util.UUID; @@ -61,32 +62,36 @@ public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, String userId, String partyRole, String productRole) { NotificationToSend notification = buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE); NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); + notificationUserToSend.setId(notification.getId()); notificationUserToSend.setInstitutionId(notification.getInstitutionId()); notificationUserToSend.setProduct(notification.getProduct()); - notificationUserToSend.setState(notification.getState()); - notificationUserToSend.setFilePath(notification.getFilePath()); - notificationUserToSend.setFileName(notification.getFileName()); - notificationUserToSend.setContentType(notification.getContentType()); notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId()); - notificationUserToSend.setPricingPlan(notification.getPricingPlan()); - notificationUserToSend.setBilling(notification.getBilling()); - notificationUserToSend.setCreatedAt(createdAt.toString()); + notificationUserToSend.setCreatedAt(createdAt); notificationUserToSend.setUpdatedAt(updatedAt); QueueUserEvent queueUserEvent = switch (status) { case "DELETE" -> QueueUserEvent.DELETE_USER; case "SUSPEND" -> QueueUserEvent.SUSPEND_USER; default -> QueueUserEvent.ACTIVE_USER; }; - notificationUserToSend.setNotificationType(queueUserEvent); notificationUserToSend.setType(NotificationUserType.getNotificationTypeFromQueueEvent(queueUserEvent)); UserToNotify user = new UserToNotify(); user.setUserId(userId); user.setRole(partyRole); - user.setProductRole(productRole); - user.setRelationshipStatus(status); + user.setRoles(List.of(productRole)); notificationUserToSend.setUser(user); + +// notificationUserToSend.setState(notification.getState()); +// notificationUserToSend.setFilePath(notification.getFilePath()); +// notificationUserToSend.setFileName(notification.getFileName()); +// notificationUserToSend.setContentType(notification.getContentType()); +// +// notificationUserToSend.setPricingPlan(notification.getPricingPlan()); +// notificationUserToSend.setBilling(notification.getBilling()); +// notificationUserToSend.setNotificationType(queueUserEvent); + + return notificationUserToSend; } From c418c55bbbbe271e918384ff0313a16d1e66e326 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Wed, 16 Oct 2024 12:01:58 +0200 Subject: [PATCH 19/29] chore: Update model --- .../service/NotificationEventServiceDefault.java | 8 -------- .../service/NotificationEventServiceDefaultTest.java | 8 -------- .../onboarding/utils/FdNotificationBuilderTest.java | 2 -- 3 files changed, 18 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index bc04b0b06..49ebf30c1 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -283,19 +283,11 @@ public static Map notificationUserEventMap(NotificationUserToSen Optional.ofNullable(notificationUserToSend.getId()).ifPresent(value -> propertiesMap.put("id", value)); Optional.ofNullable(notificationUserToSend.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value)); Optional.ofNullable(notificationUserToSend.getProduct()).ifPresent(value -> propertiesMap.put("product", value)); - Optional.ofNullable(notificationUserToSend.getState()).ifPresent(value -> propertiesMap.put("state", value)); - Optional.ofNullable(notificationUserToSend.getFilePath()).ifPresent(value -> propertiesMap.put("filePath", value)); - Optional.ofNullable(notificationUserToSend.getFileName()).ifPresent(value -> propertiesMap.put("fileName", value)); - Optional.ofNullable(notificationUserToSend.getContentType()).ifPresent(value -> propertiesMap.put("contentType", value)); Optional.ofNullable(notificationUserToSend.getOnboardingTokenId()).ifPresent(value -> propertiesMap.put("onboardingTokenId", value)); - Optional.ofNullable(notificationUserToSend.getPricingPlan()).ifPresent(value -> propertiesMap.put("pricingPlan", value)); if (Optional.ofNullable(notificationUserToSend.getUser()).isPresent()) { - Optional.ofNullable(notificationUserToSend.getUser().getUserId()).ifPresent(value -> propertiesMap.put("userId", value)); Optional.ofNullable(notificationUserToSend.getUser().getRole()).ifPresent(value -> propertiesMap.put("role", value)); - Optional.ofNullable(notificationUserToSend.getUser().getRelationshipStatus()).ifPresent(value -> propertiesMap.put("relationshipStatus", value)); - Optional.ofNullable(notificationUserToSend.getUser().getProductRole()).ifPresent(value -> propertiesMap.put("productRole", value)); } return propertiesMap; } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 675ef4f53..248fb8231 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -335,11 +335,8 @@ void notificationEventUserMapTest() { UserToNotify user = new UserToNotify(); user.setUserId("userId"); user.setRole("OPERATOR"); - user.setProductRole("api"); - user.setRelationshipStatus("ACTIVE"); notificationUserToSend.setUser(user); - Map properties = NotificationEventServiceDefault.notificationUserEventMap(notificationUserToSend, "topic", "traceId"); assertNotNull(properties); assertEquals("traceId", properties.get("notificationEventTraceId")); @@ -351,7 +348,6 @@ void notificationEventUserMapTest() { assertEquals(properties.get("filePath"), "filePath"); assertEquals(properties.get("contentType"), "application/octet-stream"); - assertEquals("userId", properties.get("userId")); assertEquals("OPERATOR", properties.get("role")); assertEquals("ACTIVE", properties.get("relationshipStatus")); @@ -384,10 +380,6 @@ private static NotificationUserToSend getNotificationUserBaseToSend() { notificationUserToSend.setId("id"); notificationUserToSend.setInstitutionId("internal"); notificationUserToSend.setProduct("prod"); - notificationUserToSend.setState("state"); - notificationUserToSend.setFileName("fileName"); - notificationUserToSend.setFilePath("filePath"); - notificationUserToSend.setContentType("contentType"); return notificationUserToSend; } } \ No newline at end of file diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java index 6372e9723..e50eaac23 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java @@ -136,12 +136,10 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { assertNotNull(notification); assertNotEquals(onboarding.getId(), notification.getId()); - assertEquals("ACTIVE", notification.getState()); assertEquals(tokenId, notification.getOnboardingTokenId()); assertEquals(productResponse.getCreatedAt(), notification.getCreatedAt()); assertEquals(productResponse.getUpdatedAt(), notification.getUpdatedAt()); assertEquals(NotificationUserType.ACTIVE_USER, notification.getType()); - assertEquals(productResponse.getProductRole(), notification.getUser().getProductRole()); assertEquals(productResponse.getRole(), notification.getUser().getRole()); assertTrue(notification.toString().contains("institutionId='" + notification.getInstitutionId() + "'")); From d6bbf19c39465d84a1289ad81461a5c89861c931 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Wed, 16 Oct 2024 12:06:14 +0200 Subject: [PATCH 20/29] chore: Update model --- .../service/NotificationEventServiceDefault.java | 1 + .../service/NotificationEventServiceDefaultTest.java | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 49ebf30c1..33a88b75c 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -288,6 +288,7 @@ public static Map notificationUserEventMap(NotificationUserToSen if (Optional.ofNullable(notificationUserToSend.getUser()).isPresent()) { Optional.ofNullable(notificationUserToSend.getUser().getUserId()).ifPresent(value -> propertiesMap.put("userId", value)); Optional.ofNullable(notificationUserToSend.getUser().getRole()).ifPresent(value -> propertiesMap.put("role", value)); + //Optional.ofNullable(notificationUserToSend.getUser().getRoles()).ifPresent(value -> propertiesMap.put("roles", value.toString())); } return propertiesMap; } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 248fb8231..7183355f6 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -343,15 +343,10 @@ void notificationEventUserMapTest() { assertEquals("id", properties.get("id")); assertEquals("internal", properties.get("institutionId")); assertEquals("prod", properties.get("product")); - assertEquals("state", properties.get("state")); - assertEquals("fileName", properties.get("fileName")); - assertEquals(properties.get("filePath"), "filePath"); - assertEquals(properties.get("contentType"), "application/octet-stream"); assertEquals("userId", properties.get("userId")); assertEquals("OPERATOR", properties.get("role")); - assertEquals("ACTIVE", properties.get("relationshipStatus")); - assertEquals("api", properties.get("productRole")); + } From 1f85a87c8f5f10b557e27bd14cbdd4694042175f Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Wed, 16 Oct 2024 12:09:29 +0200 Subject: [PATCH 21/29] chore: Update model adding Z to date --- .../selfcare/onboarding/utils/FdNotificationBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index 1d7b407e8..f4bc3f673 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -67,8 +67,8 @@ public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, notificationUserToSend.setInstitutionId(notification.getInstitutionId()); notificationUserToSend.setProduct(notification.getProduct()); notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId()); - notificationUserToSend.setCreatedAt(createdAt); - notificationUserToSend.setUpdatedAt(updatedAt); + notificationUserToSend.setCreatedAt(createdAt + "Z"); + notificationUserToSend.setUpdatedAt(updatedAt + "Z"); QueueUserEvent queueUserEvent = switch (status) { case "DELETE" -> QueueUserEvent.DELETE_USER; case "SUSPEND" -> QueueUserEvent.SUSPEND_USER; From 03bafe8d150342bda8cb7a914690405288132012 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Wed, 16 Oct 2024 12:13:17 +0200 Subject: [PATCH 22/29] chore: Fix test model adding Z to date --- .../selfcare/onboarding/utils/FdNotificationBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index f4bc3f673..3a511b4d4 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -67,8 +67,8 @@ public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, notificationUserToSend.setInstitutionId(notification.getInstitutionId()); notificationUserToSend.setProduct(notification.getProduct()); notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId()); - notificationUserToSend.setCreatedAt(createdAt + "Z"); - notificationUserToSend.setUpdatedAt(updatedAt + "Z"); + notificationUserToSend.setCreatedAt(createdAt.endsWith("Z") ? createdAt : createdAt + "Z"); + notificationUserToSend.setUpdatedAt(updatedAt.endsWith("Z") ? createdAt : createdAt + "Z"); QueueUserEvent queueUserEvent = switch (status) { case "DELETE" -> QueueUserEvent.DELETE_USER; case "SUSPEND" -> QueueUserEvent.SUSPEND_USER; From 58674123c716a4362d42d2eec988f1cb91135695 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Wed, 16 Oct 2024 12:26:11 +0200 Subject: [PATCH 23/29] chore: Removing unused code --- .../onboarding/utils/FdNotificationBuilder.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index 3a511b4d4..a94bc8cb8 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -62,7 +62,6 @@ public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, String userId, String partyRole, String productRole) { NotificationToSend notification = buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE); NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); - notificationUserToSend.setId(notification.getId()); notificationUserToSend.setInstitutionId(notification.getInstitutionId()); notificationUserToSend.setProduct(notification.getProduct()); @@ -80,18 +79,6 @@ public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, user.setRole(partyRole); user.setRoles(List.of(productRole)); notificationUserToSend.setUser(user); - - -// notificationUserToSend.setState(notification.getState()); -// notificationUserToSend.setFilePath(notification.getFilePath()); -// notificationUserToSend.setFileName(notification.getFileName()); -// notificationUserToSend.setContentType(notification.getContentType()); -// -// notificationUserToSend.setPricingPlan(notification.getPricingPlan()); -// notificationUserToSend.setBilling(notification.getBilling()); -// notificationUserToSend.setNotificationType(queueUserEvent); - - return notificationUserToSend; } From e03a5b174de13e3b0f61d39a1ff0b674818ffa29 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Thu, 17 Oct 2024 11:17:09 +0200 Subject: [PATCH 24/29] chore: Avoiding send too user notification --- .../onboarding/service/NotificationEventServiceDefault.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 33a88b75c..ce2527f85 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -133,7 +133,7 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { context.getLogger().info(() -> String.format("[APZ] onboardingUser %s [%s]", onboardingUser.getId(), consumer.topic())); - List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), null, null, null, null, null); + List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), onboardingUser.getId(), null, List.of(product.getId()), null, null); users.forEach(userDataResponse -> { context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.toString(), consumer.topic())); userDataResponse.getProducts().forEach(onboardedProductResponse -> { From 0f41cb719d135519d550e93ab4fb086c7b1c145c Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Mon, 21 Oct 2024 10:15:53 +0200 Subject: [PATCH 25/29] chore: Update test --- .../functions/OnboardingFunctions.java | 23 +++--- .../functions/OnboardingFunctionsTest.java | 70 +++++++++---------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index 9bc17708d..55a6ffe98 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -83,7 +83,7 @@ public HttpResponseMessage startOrchestration( try { /* if timeout is null, caller wants response asynchronously */ - if(Objects.isNull(timeoutString)) { + if (Objects.isNull(timeoutString)) { return durableContext.createCheckStatusResponse(request, instanceId); } @@ -94,11 +94,11 @@ public HttpResponseMessage startOrchestration( true); boolean isFailed = Optional.ofNullable(metadata) - .map(orchestration -> OrchestrationRuntimeStatus.FAILED.equals(orchestration.getRuntimeStatus()) ) + .map(orchestration -> OrchestrationRuntimeStatus.FAILED.equals(orchestration.getRuntimeStatus())) .orElse(true); return isFailed - ? request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + ? request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) .build() : request.createResponseBuilder(HttpStatus.OK) .build(); @@ -107,6 +107,7 @@ public HttpResponseMessage startOrchestration( return durableContext.createCheckStatusResponse(request, instanceId); } } + @FunctionName(ONBOARDINGS_AGGREGATE_ORCHESTRATOR) public void onboardingsAggregateOrchestrator( @DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx, @@ -115,7 +116,7 @@ public void onboardingsAggregateOrchestrator( try { String onboardingAggregate = ctx.getInput(String.class); boolean existsDelegation = Boolean.parseBoolean(ctx.callActivity(EXISTS_DELEGATION_ACTIVITY, onboardingAggregate, optionsRetry, String.class).await()); - if(!existsDelegation) { + if (!existsDelegation) { onboardingId = ctx.callActivity(CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY, onboardingAggregate, optionsRetry, String.class).await(); ctx.callSubOrchestrator("Onboardings", onboardingId, String.class).await(); } @@ -148,15 +149,19 @@ public void onboardingsOrchestrator( .orElseThrow(() -> new ResourceNotFoundException(String.format("Onboarding with id %s not found!", onboardingId))); switch (onboarding.getWorkflowType()) { - case CONTRACT_REGISTRATION -> workflowExecutor = new WorkflowExecutorContractRegistration(objectMapper, optionsRetry); - case CONTRACT_REGISTRATION_AGGREGATOR -> workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); - case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry); + case CONTRACT_REGISTRATION -> + workflowExecutor = new WorkflowExecutorContractRegistration(objectMapper, optionsRetry); + case CONTRACT_REGISTRATION_AGGREGATOR -> + workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); + case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry); case FOR_APPROVE_PT -> workflowExecutor = new WorkflowExecutorForApprovePt(objectMapper, optionsRetry); case CONFIRMATION -> workflowExecutor = new WorkflowExecutorConfirmation(objectMapper, optionsRetry); - case CONFIRMATION_AGGREGATE -> workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry); + case CONFIRMATION_AGGREGATE -> + workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry); case IMPORT -> workflowExecutor = new WorkflowExecutorImport(objectMapper, optionsRetry); case USERS -> workflowExecutor = new WorkflowExecutorForUsers(objectMapper, optionsRetry); - case INCREMENT_REGISTRATION_AGGREGATOR -> workflowExecutor = new WorkflowExecutorIncrementRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); + case INCREMENT_REGISTRATION_AGGREGATOR -> + workflowExecutor = new WorkflowExecutorIncrementRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); case USERS_PG -> workflowExecutor = new WorkflowExecutorForUsersPg(objectMapper, optionsRetry); default -> throw new IllegalArgumentException("Workflow options not found!"); } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index 8185220d0..aeda14cbd 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -69,8 +69,7 @@ class OnboardingFunctionsTest { @Test void startAndWaitOrchestration_failedOrchestration() throws Exception { // Setup - @SuppressWarnings("unchecked") - final HttpRequestMessage> req = mock(HttpRequestMessage.class); + @SuppressWarnings("unchecked") final HttpRequestMessage> req = mock(HttpRequestMessage.class); final Map queryParams = new HashMap<>(); final String onboardingId = "onboardingId"; @@ -152,7 +151,7 @@ void onboardingOrchestratorContractRegistrationAggregator() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(4)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_AGGREGATES_CSV_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1)); assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(2)); @@ -186,7 +185,7 @@ void onboardingOrchestratorContractRegistrationAggregator_Pending() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); Mockito.verify(orchestrationContext, times(6)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -204,7 +203,7 @@ void onboardingOrchestratorContractRegistrationAggregator_Pending() { } @Test - void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationAlreadyExists(){ + void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationAlreadyExists() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -226,7 +225,7 @@ void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationAlre } @Test - void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationNotExists(){ + void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationNotExists() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -251,9 +250,6 @@ void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationNotE } - - - @Test void onboardingsOrchestratorNewAdminRequest() { Onboarding onboarding = new Onboarding(); @@ -311,7 +307,7 @@ void onboardingsOrchestratorForApproveWhenToBeValidated() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(3)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(0)); assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1)); assertEquals(SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -334,7 +330,7 @@ void onboardingsOrchestratorConfirmation() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(6)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -361,7 +357,7 @@ void onboardingsOrchestratorConfirmationWithTestProductIds() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(8)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -376,7 +372,7 @@ void onboardingsOrchestratorConfirmationWithTestProductIds() { } @Test - void onboardingOrchestratorConfirmAggregate(){ + void onboardingOrchestratorConfirmAggregate() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -390,7 +386,7 @@ void onboardingOrchestratorConfirmAggregate(){ ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); Mockito.verify(orchestrationContext, times(6)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -405,7 +401,7 @@ void onboardingOrchestratorConfirmAggregate(){ } @Test - void onboardingsAggregateOrchestrator(){ + void onboardingsAggregateOrchestrator() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -421,16 +417,17 @@ void onboardingsAggregateOrchestrator(){ function.onboardingsAggregateOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(2)) + .callActivity(captorActivity.capture(), any(), any(), any()); verify(orchestrationContext, times(1)) .callSubOrchestrator(eq("Onboardings"), any(), any()); assertEquals(EXISTS_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY, captorActivity.getAllValues().get(1)); } + @Test - void onboardingsAggregateOrchestrator_resourceNotFound(){ + void onboardingsAggregateOrchestrator_resourceNotFound() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -448,14 +445,14 @@ void onboardingsAggregateOrchestrator_resourceNotFound(){ ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(EXISTS_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(0)); verify(service, times(1)).updateOnboardingStatusAndInstanceId(null, OnboardingStatus.FAILED, orchestrationContext.getInstanceId()); } @Test - void onboardingsAggregateOrchestrator_taskFailed(){ + void onboardingsAggregateOrchestrator_taskFailed() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -473,7 +470,7 @@ void onboardingsAggregateOrchestrator_taskFailed(){ ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(EXISTS_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(0)); verify(service, times(1)).updateOnboardingStatusAndInstanceId(null, OnboardingStatus.FAILED, orchestrationContext.getInstanceId()); @@ -495,7 +492,7 @@ void onboardingsOrchestratorImport() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(4)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -520,7 +517,7 @@ void onboardingsOrchestratorNewAdmin() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(3)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(1)); assertEquals(SEND_MAIL_COMPLETION_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -543,7 +540,7 @@ void onboardingsOrchestratorRegistrationRequestApprove() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(2)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(SEND_MAIL_REGISTRATION_REQUEST_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(SEND_MAIL_REGISTRATION_APPROVE_ACTIVITY, captorActivity.getAllValues().get(1)); @@ -564,8 +561,8 @@ void onboardingsOrchestratorForApprovePtWhenToBeValidated() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(5)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(6)) + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -584,8 +581,8 @@ TaskOrchestrationContext mockTaskOrchestrationContext(Onboarding onboarding) { when(completionService.existsDelegation(any())).thenReturn("false"); Task task = mock(Task.class); - when(orchestrationContext.callActivity(any(),any(),any(),any())).thenReturn(task); - when(orchestrationContext.callSubOrchestrator(any(),any())).thenReturn(task); + when(orchestrationContext.callActivity(any(), any(), any(), any())).thenReturn(task); + when(orchestrationContext.callSubOrchestrator(any(), any())).thenReturn(task); when(task.await()).thenReturn("false"); when(orchestrationContext.allOf(anyList())).thenReturn(task); return orchestrationContext; @@ -598,8 +595,8 @@ TaskOrchestrationContext mockTaskOrchestrationContextForIncrementAggregator(Onbo when(completionService.existsDelegation(any())).thenReturn("true"); Task task = mock(Task.class); - when(orchestrationContext.callActivity(any(),any(),any(),any())).thenReturn(task); - when(orchestrationContext.callSubOrchestrator(any(),any())).thenReturn(task); + when(orchestrationContext.callActivity(any(), any(), any(), any())).thenReturn(task); + when(orchestrationContext.callSubOrchestrator(any(), any())).thenReturn(task); when(task.await()).thenReturn(returnValue); when(orchestrationContext.allOf(anyList())).thenReturn(task); return orchestrationContext; @@ -701,8 +698,8 @@ void onboardingCompletionOrchestrator() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(5)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(6)) + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -729,7 +726,7 @@ void onboardingRejectedOrchestrator() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(SEND_MAIL_REJECTION_ACTIVITY, captorActivity.getAllValues().get(0)); } @@ -747,8 +744,8 @@ void usersPgOrchestrator_whenStatusPending() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(4)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(3)) + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(DELETE_MANAGERS_BY_IC_AND_ADE, captorActivity.getAllValues().get(0)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(2)); @@ -769,7 +766,7 @@ void usersPgOrchestrator_whenStatusRequest() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(0)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); } @Test @@ -874,6 +871,7 @@ void createAggregateOnboardingRequest() { Mockito.verify(completionService, times(1)) .createAggregateOnboardingRequest(any()); } + @Test void createDelegationForAggregation() { final String onboardingString = "{\"onboardingId\":\"onboardingId\"}"; From 731b4ca796c7b5c862a2087dbc182068604a6a68 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Mon, 21 Oct 2024 10:38:38 +0200 Subject: [PATCH 26/29] chore: Update test --- .../onboarding/service/NotificationEventServiceDefault.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index ce2527f85..1828f4105 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -131,7 +131,7 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { context.getLogger().info(() -> String.format("[APZ] prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); - notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { + /*notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { context.getLogger().info(() -> String.format("[APZ] onboardingUser %s [%s]", onboardingUser.getId(), consumer.topic())); List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), onboardingUser.getId(), null, List.of(product.getId()), null, null); users.forEach(userDataResponse -> { @@ -146,7 +146,7 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr } }); }); - }); + });*/ } else { From e50904afa4cb6c08003d41eda179fb4c0f3468a8 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Mon, 21 Oct 2024 11:01:08 +0200 Subject: [PATCH 27/29] chore: Update test --- .../NotificationEventServiceDefaultTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 7183355f6..07c112583 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -202,6 +202,22 @@ void sendMessageWontProceedsWhenOnboardingIsNotReferredToInstitution() { verifyNoInteractions(eventHubRestClient); } + @Test + void onboardingEventMapTest() { + final Onboarding onboarding = createOnboarding(); + onboarding.setId("ID"); + Map properties = NotificationEventServiceDefault.onboardingEventMap(onboarding); + assertNotNull(properties); + assertEquals("ID", properties.get("id")); + } + + @Test + void onboardingEventFailureMapTest() { + final Onboarding onboarding = createOnboarding(); + Map properties = NotificationEventServiceDefault.onboardingEventFailureMap(onboarding, new Exception()); + assertNotNull(properties); + } + @Test void notificationEventMapTest() { NotificationToSend notificationToSend = getNotificationBaseToSend(); @@ -346,7 +362,7 @@ void notificationEventUserMapTest() { assertEquals("userId", properties.get("userId")); assertEquals("OPERATOR", properties.get("role")); - + } From 4adc6c46907883dcf1bf0818f55a47a8e5333d6b Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Mon, 21 Oct 2024 12:36:57 +0200 Subject: [PATCH 28/29] chore: Update test --- .../NotificationEventServiceDefaultTest.java | 70 ++++++++++++++++--- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 07c112583..12b1b1368 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -8,15 +8,15 @@ import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.onboarding.common.WorkflowType; import it.pagopa.selfcare.onboarding.dto.*; +import it.pagopa.selfcare.onboarding.dto.QueueEvent; +import it.pagopa.selfcare.onboarding.dto.UserToNotify; import it.pagopa.selfcare.onboarding.entity.Billing; import it.pagopa.selfcare.onboarding.entity.Institution; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.entity.Token; import it.pagopa.selfcare.onboarding.exception.NotificationException; import it.pagopa.selfcare.onboarding.repository.TokenRepository; -import it.pagopa.selfcare.onboarding.utils.BaseNotificationBuilder; -import it.pagopa.selfcare.onboarding.utils.NotificationBuilderFactory; -import it.pagopa.selfcare.onboarding.utils.QueueEventExaminer; +import it.pagopa.selfcare.onboarding.utils.*; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.service.ProductService; import jakarta.inject.Inject; @@ -24,12 +24,9 @@ import org.junit.jupiter.api.Test; import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; -import org.openapi.quarkus.user_json.model.UserDataResponse; +import org.openapi.quarkus.user_json.model.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.*; @@ -51,6 +48,9 @@ public class NotificationEventServiceDefaultTest { @InjectMock NotificationBuilderFactory notificationBuilderFactory; + @InjectMock + NotificationUserBuilderFactory notificationUserBuilderFactory; + @InjectMock TokenRepository tokenRepository; @@ -362,10 +362,63 @@ void notificationEventUserMapTest() { assertEquals("userId", properties.get("userId")); assertEquals("OPERATOR", properties.get("role")); + } + @Test + void getNotificationUserToSendTest() { + Onboarding onboarding = createOnboarding(); + InstitutionResponse institutionResponse = new InstitutionResponse(); + Token token = new Token(); + NotificationsResources notificationsResources = new NotificationsResources(onboarding, + institutionResponse, token, QueueEvent.ADD); + + OnboardedProductResponse onboardedProductResponse = new OnboardedProductResponse(); + onboardedProductResponse.productId("prod-fd-garantito"); + onboardedProductResponse.setEnv(Env.ROOT); + onboardedProductResponse.setStatus(OnboardedProductState.ACTIVE); + + + UserResponse userResponse = new UserResponse(); + userResponse.setId("userId"); + userResponse.setTaxCode("taxcode"); + userResponse.setName("Name"); + userResponse.setSurname("Surname"); + userResponse.setEmail("prv@email"); + HashMap workContacts = new HashMap(); + workContacts.put("email", "work@email"); + userResponse.setWorkContacts(workContacts); + + UserDataResponse userDataResponse = new UserDataResponse(); + userDataResponse.setId("userId"); + userDataResponse.institutionId("institutionId"); + userDataResponse.setInstitutionDescription("Institution Name"); + userDataResponse.setUserMailUuid("userMailId"); + userDataResponse.role("MANAGER"); + userDataResponse.setStatus("ADD"); + userDataResponse.setProducts(List.of(onboardedProductResponse)); + userDataResponse.setUserResponse(userResponse); + + NotificationUserToSend notificationUserToSendMock = new NotificationUserToSend(); + notificationUserToSendMock.setId("eventId"); + notificationUserToSendMock.setInstitutionId("institutionId"); + notificationUserToSendMock.setProduct("prod-fd-garantito"); + notificationUserToSendMock.setOnboardingTokenId("onboardingId"); + + FdNotificationBuilder fdNotificationBuilder = mock(FdNotificationBuilder.class); + when(notificationUserBuilderFactory.create(any())).thenReturn(fdNotificationBuilder); + when(fdNotificationBuilder.buildUserNotificationToSend(any(), any(), any(), any(), any(), any(), any(), + any(), any())).thenReturn(notificationUserToSendMock); + when(fdNotificationBuilder.shouldSendUserNotification(any(), any())).thenReturn(true); + doNothing().when(eventHubRestClient).sendMessage(anyString(), anyString()); + + NotificationUserToSend notificationUserToSend = NotificationEventServiceDefault.getNotificationUserToSend(notificationsResources, userDataResponse, + onboardedProductResponse, fdNotificationBuilder); + + assertNotNull(notificationUserToSend); } + private static InstitutionToNotify getInstitutionToNotify() { InstitutionToNotify institution = new InstitutionToNotify(); institution.setDescription("description"); @@ -393,4 +446,5 @@ private static NotificationUserToSend getNotificationUserBaseToSend() { notificationUserToSend.setProduct("prod"); return notificationUserToSend; } + } \ No newline at end of file From f92e90912abf7c6e4a0c197834295bb667516f21 Mon Sep 17 00:00:00 2001 From: andrea putzu Date: Mon, 21 Oct 2024 13:09:48 +0200 Subject: [PATCH 29/29] chore: Update test --- .../service/NotificationEventServiceDefault.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index 1828f4105..108219f2a 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -127,11 +127,11 @@ private void prepareAndSendNotification(ExecutionContext context, Product produc } private void prepareAndSendUserNotification(ExecutionContext context, Product product, NotificationConfig.Consumer consumer, NotificationsResources notificationsResources, String notificationEventTraceId) { - NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); + /*NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { context.getLogger().info(() -> String.format("[APZ] prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); - /*notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { + notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { context.getLogger().info(() -> String.format("[APZ] onboardingUser %s [%s]", onboardingUser.getId(), consumer.topic())); List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), onboardingUser.getId(), null, List.of(product.getId()), null, null); users.forEach(userDataResponse -> { @@ -146,12 +146,12 @@ private void prepareAndSendUserNotification(ExecutionContext context, Product pr } }); }); - });*/ + }); } else { context.getLogger().info(() -> String.format("It was not necessary to send a notification on the topic %s because the onboarding with ID %s did not pass filter verification", notificationsResources.getOnboarding().getId(), consumer.topic())); - } + }*/ } public static NotificationUserToSend getNotificationUserToSend(NotificationsResources notificationsResources, @@ -185,7 +185,7 @@ private void sendNotification(ExecutionContext context, String topic, Notificati telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); } - private void sendUserNotification(ExecutionContext context, String topic, NotificationUserToSend notificationUserToSend, String notificationEventTraceId) { + /*private void sendUserNotification(ExecutionContext context, String topic, NotificationUserToSend notificationUserToSend, String notificationEventTraceId) { String message = null; try { message = mapper.writeValueAsString(notificationUserToSend); @@ -198,7 +198,7 @@ private void sendUserNotification(ExecutionContext context, String topic, Notifi eventHubRestClient.sendMessage(topic, message); telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationUserEventMap(notificationUserToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); - } + }*/ private void sendTestEnvProductsNotification(ExecutionContext context, Product product, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { context.getLogger().info(() -> String.format("Starting sendTestEnvProductsNotification with testEnv %s", product.getTestEnvProductIds()));