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..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 @@ -4,22 +4,23 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.time.Instant; 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; private String digitalAddress; - private OffsetDateTime createdAt; - private OffsetDateTime updatedAt; + private Instant createdAt; + 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 9251ffc4..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 @@ -3,10 +3,13 @@ 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; +import java.time.Instant; import java.time.OffsetDateTime; @Data @@ -16,14 +19,14 @@ @FieldNameConstants(asEnum = true) public class PecNotificationEntity { - @Id - private Object id; + @BsonId + private ObjectId id; private String institutionId; private String productId; private Integer moduleDayOfTheEpoch; private String digitalAddress; - private OffsetDateTime createdAt; - private OffsetDateTime updatedAt; + private Instant createdAt; + private Instant updatedAt; } \ No newline at end of file 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..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 @@ -13,17 +13,18 @@ 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; +import java.time.Instant; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; 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 +35,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 +55,7 @@ public OnboardingServiceImpl(OnboardingDao onboardingDao, this.pecNotificationConnector = pecNotificationConnector; this.sendingFrequencyPecNotification = sendingFrequencyPecNotification; this.epochDatePecNotification = epochDatePecNotification; + this.disabledPecNotification = disabledPecNotification; } @Override @@ -82,8 +87,8 @@ public void verifyOnboardingInfoByFilters(VerifyOnboardingFilters filters) { public void insertPecNotification(String institutionId, String productId, String digitalAddress) { PecNotification pecNotification = new PecNotification(); - pecNotification.setId(UUID.randomUUID().toString()); - pecNotification.setCreatedAt(OffsetDateTime.now()); + pecNotification.setId(ObjectId.get()); + pecNotification.setCreatedAt(Instant.now()); pecNotification.setProductId(productId); pecNotification.setInstitutionId(institutionId); pecNotification.setModuleDayOfTheEpoch(calculateModuleDayOfTheEpoch()); @@ -98,8 +103,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 +111,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..bb308440 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 = "false" } ] 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..dd5712f5 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 = "false" } ] 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..e7da9c9b 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 = "false" } ]