From 50394b364ee4d49fa3628ffbc8fd4110f6b05a36 Mon Sep 17 00:00:00 2001 From: Eugen Begiqi Date: Wed, 10 Jul 2024 19:07:23 +0200 Subject: [PATCH 1/4] [SELC-5169] feat : Refactored and added environment variables to disable the PecNotification --- .../resources/config/core-config.properties | 3 +- connector-api/pom.xml | 4 +++ .../pecnotification/PecNotification.java | 4 +-- .../dao/model/PecNotificationEntity.java | 6 ++-- .../mapper/PecNotificationEntityMapper.java | 2 +- .../mscore/core/OnboardingServiceImpl.java | 25 +++++++++------ .../core/OnboardingServiceImplTest.java | 32 +++++++++++++++++++ .../env/dev-pnpg/terraform.tfvars | 4 +++ infra/container_apps/env/dev/terraform.tfvars | 4 +++ .../env/prod-pnpg/terraform.tfvars | 4 +++ .../container_apps/env/prod/terraform.tfvars | 4 +++ .../env/uat-pnpg/terraform.tfvars | 4 +++ infra/container_apps/env/uat/terraform.tfvars | 4 +++ 13 files changed, 85 insertions(+), 15 deletions(-) diff --git a/app/src/main/resources/config/core-config.properties b/app/src/main/resources/config/core-config.properties index 9a5ec02e..74d5dfd9 100644 --- a/app/src/main/resources/config/core-config.properties +++ b/app/src/main/resources/config/core-config.properties @@ -28,4 +28,5 @@ mscore.aws-ses-secret-key=${AWS_SES_SECRET_ACCESS_KEY:secret-key-example} mscore.aws-ses-region=${AWS_SES_REGION:eu-south-1} mscore.sending-frequency-pec-notification=${SENDING_FREQUENCY_PEC_NOTIFICATION:30} -mscore.epoch-date-pec-notification=${EPOCH_DATE_PEC_NOTIFICATION:2024-01-01} \ No newline at end of file +mscore.epoch-date-pec-notification=${EPOCH_DATE_PEC_NOTIFICATION:2024-01-01} +mscore.pec-notification.disabled=${PEC_NOTIFICATION_DISABLED:false} \ No newline at end of file diff --git a/connector-api/pom.xml b/connector-api/pom.xml index a2f0c268..777cc1d9 100644 --- a/connector-api/pom.xml +++ b/connector-api/pom.xml @@ -35,6 +35,10 @@ onboarding-sdk-product 0.1.15 + + org.mongodb + bson + diff --git a/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java b/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java index c3680259..c438a4ab 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java @@ -5,14 +5,14 @@ import lombok.NoArgsConstructor; import java.time.OffsetDateTime; -import java.util.List; +import org.bson.types.ObjectId; @Data @NoArgsConstructor @AllArgsConstructor public class PecNotification { - private Object id; + private ObjectId id; private String institutionId; private String productId; private Integer moduleDayOfTheEpoch; diff --git a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java index 9251ffc4..59086956 100644 --- a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java +++ b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java @@ -3,6 +3,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.FieldNameConstants; +import org.bson.codecs.pojo.annotations.BsonId; +import org.bson.types.ObjectId; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Sharded; @@ -16,8 +18,8 @@ @FieldNameConstants(asEnum = true) public class PecNotificationEntity { - @Id - private Object id; + @BsonId + private ObjectId id; private String institutionId; private String productId; private Integer moduleDayOfTheEpoch; diff --git a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/mapper/PecNotificationEntityMapper.java b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/mapper/PecNotificationEntityMapper.java index fe31aad7..0151eaf1 100644 --- a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/mapper/PecNotificationEntityMapper.java +++ b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/mapper/PecNotificationEntityMapper.java @@ -10,7 +10,7 @@ @Mapper(componentModel = "spring", imports = UUID.class) public interface PecNotificationEntityMapper { - @Mapping(target = "id", defaultExpression = "java(UUID.randomUUID().toString())") + @Mapping(target = "id", defaultExpression = "java(org.bson.types.ObjectId.get())") PecNotificationEntity convertToPecNotificationEntity(PecNotification institution); PecNotification convertToPecNotification(PecNotificationEntity entity); diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java index 91e636ff..0cdc5edf 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java @@ -13,6 +13,7 @@ import it.pagopa.selfcare.mscore.model.pecnotification.PecNotification; import lombok.extern.slf4j.Slf4j; +import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -23,7 +24,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.UUID; import static it.pagopa.selfcare.mscore.constant.GenericError.*; @@ -34,16 +34,19 @@ public class OnboardingServiceImpl implements OnboardingService { private final InstitutionService institutionService; private final InstitutionConnector institutionConnector; private final PecNotificationConnector pecNotificationConnector; - private Integer sendingFrequencyPecNotification; - private String epochDatePecNotification; - private LocalDate currentDate = LocalDate.now(); + private final Integer sendingFrequencyPecNotification; + private final String epochDatePecNotification; + private final LocalDate currentDate = LocalDate.now(); + + private final Boolean disabledPecNotification; public OnboardingServiceImpl(OnboardingDao onboardingDao, InstitutionService institutionService, InstitutionConnector institutionConnector, PecNotificationConnector pecNotificationConnector, @Value("${mscore.sending-frequency-pec-notification}") Integer sendingFrequencyPecNotification, - @Value("${mscore.epoch-date-pec-notification}") String epochDatePecNotification) { + @Value("${mscore.epoch-date-pec-notification}") String epochDatePecNotification, + @Value("${mscore.pec-notification.disabled}") Boolean disabledPecNotification) { this.onboardingDao = onboardingDao; this.institutionService = institutionService; @@ -51,6 +54,7 @@ public OnboardingServiceImpl(OnboardingDao onboardingDao, this.pecNotificationConnector = pecNotificationConnector; this.sendingFrequencyPecNotification = sendingFrequencyPecNotification; this.epochDatePecNotification = epochDatePecNotification; + this.disabledPecNotification = disabledPecNotification; } @Override @@ -82,7 +86,7 @@ public void verifyOnboardingInfoByFilters(VerifyOnboardingFilters filters) { public void insertPecNotification(String institutionId, String productId, String digitalAddress) { PecNotification pecNotification = new PecNotification(); - pecNotification.setId(UUID.randomUUID().toString()); + pecNotification.setId(ObjectId.get()); pecNotification.setCreatedAt(OffsetDateTime.now()); pecNotification.setProductId(productId); pecNotification.setInstitutionId(institutionId); @@ -98,8 +102,7 @@ public void insertPecNotification(String institutionId, String productId, String public int calculateModuleDayOfTheEpoch() { LocalDate epochStart = LocalDate.parse(this.epochDatePecNotification); long daysDiff = ChronoUnit.DAYS.between(epochStart, this.currentDate); - int moduleDayOfTheEpoch = (int) (daysDiff % this.sendingFrequencyPecNotification); - return moduleDayOfTheEpoch; + return (int) (daysDiff % this.sendingFrequencyPecNotification); } @Override @@ -107,7 +110,11 @@ public Institution persistOnboarding(String institutionId, String productId, Onboarding onboarding, StringBuilder httpStatus) { Institution institution = persistAndGetInstitution(institutionId, productId, onboarding, httpStatus); - this.insertPecNotification(institutionId, productId, institution.getDigitalAddress()); + + if (!disabledPecNotification){ + this.insertPecNotification(institutionId, productId, institution.getDigitalAddress()); + } + return institution; } diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java index 6fda8bad..e3c1f77a 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java @@ -136,6 +136,7 @@ void persistOnboarding_whenUserExistsOnRegistry() { ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); + ReflectionTestUtils.setField(onboardingServiceImpl, "disabledPecNotification", false); Onboarding onboarding = dummyOnboarding(); onboarding.setStatus(UtilEnumList.VALID_RELATIONSHIP_STATES.get(0)); @@ -159,6 +160,36 @@ void persistOnboarding_whenUserExistsOnRegistry() { assertEquals(HttpStatus.OK.value(), Integer.parseInt(statusCode.toString())); } + @Test + void persistOnboarding_whenPecNotificationIsDisabled() { + + ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); + ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); + ReflectionTestUtils.setField(onboardingServiceImpl, "disabledPecNotification", true); + + Onboarding onboarding = dummyOnboarding(); + onboarding.setStatus(UtilEnumList.VALID_RELATIONSHIP_STATES.get(0)); + Institution institution = new Institution(); + institution.setId("institutionId"); + institution.setOnboarding(List.of(onboarding, dummyOnboarding())); + + when(institutionConnector.findById(institution.getId())).thenReturn(institution); + + String institutionId = institution.getId(); + + String productId = onboarding.getProductId(); + Onboarding onb = new Onboarding(); + + StringBuilder statusCode = new StringBuilder(); + + onboardingServiceImpl.persistOnboarding(institutionId, + productId, onb, statusCode); + + verify(pecNotificationConnector, never()).insertPecNotification(any(PecNotification.class)); + + assertEquals(HttpStatus.OK.value(), Integer.parseInt(statusCode.toString())); + } + /** @@ -201,6 +232,7 @@ void persistOnboarding_whenUserNotExistsOnRegistry() { ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); + ReflectionTestUtils.setField(onboardingServiceImpl, "disabledPecNotification", false); String pricingPlan = "pricingPlan"; String productId = "productId"; diff --git a/infra/container_apps/env/dev-pnpg/terraform.tfvars b/infra/container_apps/env/dev-pnpg/terraform.tfvars index d7857b7f..9bec420f 100644 --- a/infra/container_apps/env/dev-pnpg/terraform.tfvars +++ b/infra/container_apps/env/dev-pnpg/terraform.tfvars @@ -117,6 +117,10 @@ app_settings = [ { name = "MAIL_SENDER_ADDRESS" value = "noreply@areariservata.pagopa.it" + }, + { + name = "PEC_NOTIFICATION_DISABLED" + value = "true" } ] diff --git a/infra/container_apps/env/dev/terraform.tfvars b/infra/container_apps/env/dev/terraform.tfvars index a4471baf..82284b0c 100644 --- a/infra/container_apps/env/dev/terraform.tfvars +++ b/infra/container_apps/env/dev/terraform.tfvars @@ -123,6 +123,10 @@ app_settings = [ { name = "MAIL_SENDER_ADDRESS" value = "noreply@areariservata.pagopa.it" + }, + { + name = "PEC_NOTIFICATION_DISABLED" + value = "true" } ] diff --git a/infra/container_apps/env/prod-pnpg/terraform.tfvars b/infra/container_apps/env/prod-pnpg/terraform.tfvars index b88bfa3f..b3f91b06 100644 --- a/infra/container_apps/env/prod-pnpg/terraform.tfvars +++ b/infra/container_apps/env/prod-pnpg/terraform.tfvars @@ -116,6 +116,10 @@ app_settings = [ { name = "MAIL_SENDER_ADDRESS" value = "noreply@areariservata.pagopa.it" + }, + { + name = "PEC_NOTIFICATION_DISABLED" + value = "true" } ] diff --git a/infra/container_apps/env/prod/terraform.tfvars b/infra/container_apps/env/prod/terraform.tfvars index 5d75a281..7a438980 100644 --- a/infra/container_apps/env/prod/terraform.tfvars +++ b/infra/container_apps/env/prod/terraform.tfvars @@ -121,6 +121,10 @@ app_settings = [ { name = "MAIL_SENDER_ADDRESS" value = "noreply@areariservata.pagopa.it" + }, + { + name = "PEC_NOTIFICATION_DISABLED" + value = "true" } ] diff --git a/infra/container_apps/env/uat-pnpg/terraform.tfvars b/infra/container_apps/env/uat-pnpg/terraform.tfvars index 2426434e..b66e1d85 100644 --- a/infra/container_apps/env/uat-pnpg/terraform.tfvars +++ b/infra/container_apps/env/uat-pnpg/terraform.tfvars @@ -109,6 +109,10 @@ app_settings = [ { name = "MAIL_SENDER_ADDRESS" value = "noreply@areariservata.pagopa.it" + }, + { + name = "PEC_NOTIFICATION_DISABLED" + value = "true" } ] diff --git a/infra/container_apps/env/uat/terraform.tfvars b/infra/container_apps/env/uat/terraform.tfvars index 64f9ff60..3af6669c 100644 --- a/infra/container_apps/env/uat/terraform.tfvars +++ b/infra/container_apps/env/uat/terraform.tfvars @@ -112,6 +112,10 @@ app_settings = [ { name = "MAIL_SENDER_ADDRESS" value = "noreply@areariservata.pagopa.it" + }, + { + name = "PEC_NOTIFICATION_DISABLED" + value = "true" } ] From d4f48c4c0a693b410ff6374b3ee48e924d56ed0d Mon Sep 17 00:00:00 2001 From: Eugen Begiqi Date: Thu, 11 Jul 2024 12:06:28 +0200 Subject: [PATCH 2/4] [SELC-5169] feat : changed date type of the createdAt field to Instant --- .../selfcare/mscore/model/pecnotification/PecNotification.java | 3 ++- .../mscore/connector/dao/model/PecNotificationEntity.java | 3 ++- .../it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java b/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java index c438a4ab..3dca8c28 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java @@ -4,6 +4,7 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.time.Instant; import java.time.OffsetDateTime; import org.bson.types.ObjectId; @@ -18,7 +19,7 @@ public class PecNotification { private Integer moduleDayOfTheEpoch; private String digitalAddress; - private OffsetDateTime createdAt; + private Instant createdAt; private OffsetDateTime updatedAt; diff --git a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java index 59086956..671fc7df 100644 --- a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java +++ b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java @@ -9,6 +9,7 @@ import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Sharded; +import java.time.Instant; import java.time.OffsetDateTime; @Data @@ -25,7 +26,7 @@ public class PecNotificationEntity { private Integer moduleDayOfTheEpoch; private String digitalAddress; - private OffsetDateTime createdAt; + private Instant createdAt; private OffsetDateTime updatedAt; } \ No newline at end of file diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java index 0cdc5edf..1092ae43 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import java.time.Instant; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; @@ -87,7 +88,7 @@ public void insertPecNotification(String institutionId, String productId, String PecNotification pecNotification = new PecNotification(); pecNotification.setId(ObjectId.get()); - pecNotification.setCreatedAt(OffsetDateTime.now()); + pecNotification.setCreatedAt(Instant.now()); pecNotification.setProductId(productId); pecNotification.setInstitutionId(institutionId); pecNotification.setModuleDayOfTheEpoch(calculateModuleDayOfTheEpoch()); From eef996c2d64aa467898cc2128acc690e4c0049b3 Mon Sep 17 00:00:00 2001 From: Eugen Begiqi Date: Thu, 11 Jul 2024 12:11:28 +0200 Subject: [PATCH 3/4] [SELC-5169] feat : enabled PecNotification --- infra/container_apps/env/dev/terraform.tfvars | 2 +- infra/container_apps/env/prod/terraform.tfvars | 2 +- infra/container_apps/env/uat/terraform.tfvars | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/infra/container_apps/env/dev/terraform.tfvars b/infra/container_apps/env/dev/terraform.tfvars index 82284b0c..bb308440 100644 --- a/infra/container_apps/env/dev/terraform.tfvars +++ b/infra/container_apps/env/dev/terraform.tfvars @@ -126,7 +126,7 @@ app_settings = [ }, { name = "PEC_NOTIFICATION_DISABLED" - value = "true" + value = "false" } ] diff --git a/infra/container_apps/env/prod/terraform.tfvars b/infra/container_apps/env/prod/terraform.tfvars index 7a438980..dd5712f5 100644 --- a/infra/container_apps/env/prod/terraform.tfvars +++ b/infra/container_apps/env/prod/terraform.tfvars @@ -124,7 +124,7 @@ app_settings = [ }, { name = "PEC_NOTIFICATION_DISABLED" - value = "true" + value = "false" } ] diff --git a/infra/container_apps/env/uat/terraform.tfvars b/infra/container_apps/env/uat/terraform.tfvars index 3af6669c..e7da9c9b 100644 --- a/infra/container_apps/env/uat/terraform.tfvars +++ b/infra/container_apps/env/uat/terraform.tfvars @@ -115,7 +115,7 @@ app_settings = [ }, { name = "PEC_NOTIFICATION_DISABLED" - value = "true" + value = "false" } ] From d8c1e9c8abd1d24daf498d01e3680b87b55a3c92 Mon Sep 17 00:00:00 2001 From: Eugen Begiqi Date: Thu, 11 Jul 2024 12:26:07 +0200 Subject: [PATCH 4/4] [SELC-5169] feat : changed date type of the updatedAt field to Instant --- .../selfcare/mscore/model/pecnotification/PecNotification.java | 2 +- .../mscore/connector/dao/model/PecNotificationEntity.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java b/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java index 3dca8c28..dfcf44e1 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/mscore/model/pecnotification/PecNotification.java @@ -20,7 +20,7 @@ public class PecNotification { private String digitalAddress; private Instant createdAt; - private OffsetDateTime updatedAt; + private Instant updatedAt; } diff --git a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java index 671fc7df..71af7c2a 100644 --- a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java +++ b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/model/PecNotificationEntity.java @@ -27,6 +27,6 @@ public class PecNotificationEntity { private String digitalAddress; private Instant createdAt; - private OffsetDateTime updatedAt; + private Instant updatedAt; } \ No newline at end of file