diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index d359adf78..588c6bcf9 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -43,8 +43,8 @@ "name" : "Token", "description" : "Token Controller" }, { - "name" : "scheduler", - "description" : "Scheduler Controller" + "name" : "kafka", + "description" : "Queue Notification Controller" } ], "paths" : { "/migration/institution" : { @@ -4488,12 +4488,12 @@ } ] } }, - "/scheduler" : { + "/notification-event/contracts" : { "post" : { - "tags" : [ "scheduler" ], - "summary" : "start", - "description" : "Service to start scheduler to resend old messages to DL", - "operationId" : "startUsingPOST", + "tags" : [ "kafka" ], + "summary" : "resendContracts", + "description" : "Service to resend contract notifications on SC-Contracts topic", + "operationId" : "resendContractsUsingPOST", "parameters" : [ { "name" : "size", "in" : "query", @@ -4555,12 +4555,12 @@ } ] } }, - "/scheduler/users" : { + "/notification-event/users" : { "post" : { - "tags" : [ "scheduler" ], - "summary" : "startUsers", + "tags" : [ "kafka" ], + "summary" : "resendUsers", "description" : "Service to resend old user onboardings to the SCUsers kafka queue, it can send the onboardings of a single user or also retrieve all the users for a given set of products in a paged manner by passing page and size", - "operationId" : "startUsersUsingPOST", + "operationId" : "resendUsersUsingPOST", "parameters" : [ { "name" : "size", "in" : "query", diff --git a/app/src/test/java/it/pagopa/selfcare/mscore/web/config/SwaggerConfigTest.java b/app/src/test/java/it/pagopa/selfcare/mscore/web/config/SwaggerConfigTest.java index 56a5b7c2e..32aa4f481 100644 --- a/app/src/test/java/it/pagopa/selfcare/mscore/web/config/SwaggerConfigTest.java +++ b/app/src/test/java/it/pagopa/selfcare/mscore/web/config/SwaggerConfigTest.java @@ -50,7 +50,7 @@ class SwaggerConfigTest { UserService userService; @MockBean - SchedulerService schedulerService; + QueueNotificationService queueNotificationService; @Autowired WebApplicationContext context; diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java index 8d91ad7a0..3b2aa6e1e 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java @@ -20,12 +20,12 @@ public class DelegationServiceImpl implements DelegationService { private final DelegationConnector delegationConnector; - private final NotificationService notificationService; + private final MailNotificationService notificationService; private final InstitutionService institutionService; private static final String PROD_PAGOPA = "prod-pagopa"; public DelegationServiceImpl(DelegationConnector delegationConnector, - NotificationService notificationService, + MailNotificationService notificationService, InstitutionService institutionService) { this.delegationConnector = delegationConnector; this.notificationService = notificationService; diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/NotificationService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/MailNotificationService.java similarity index 97% rename from core/src/main/java/it/pagopa/selfcare/mscore/core/NotificationService.java rename to core/src/main/java/it/pagopa/selfcare/mscore/core/MailNotificationService.java index d7161b989..ce8de685c 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/NotificationService.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/MailNotificationService.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Map; -public interface NotificationService { +public interface MailNotificationService { void setCompletedPGOnboardingMail(String destinationMail, String businessName); diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/NotificationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/MailNotificationServiceImpl.java similarity index 93% rename from core/src/main/java/it/pagopa/selfcare/mscore/core/NotificationServiceImpl.java rename to core/src/main/java/it/pagopa/selfcare/mscore/core/MailNotificationServiceImpl.java index 3316d439d..dfc22f0a6 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/NotificationServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/MailNotificationServiceImpl.java @@ -26,7 +26,7 @@ @Slf4j @Service -public class NotificationServiceImpl implements NotificationService { +public class MailNotificationServiceImpl implements MailNotificationService { private static final String MAIL_PARAMETER_LOG = "mailParameters: {}"; private static final String DESTINATION_MAIL_LOG = "destinationMails: {}"; @@ -42,15 +42,15 @@ public class NotificationServiceImpl implements NotificationService { private final CoreConfig coreConfig; @Autowired - public NotificationServiceImpl(NotificationServiceConnector notificationConnector, - FileStorageConnector fileStorageConnector, - InstitutionConnector institutionConnector, - ProductConnector productConnector, - ObjectMapper mapper, - MailTemplateConfig mailTemplateConfig, - EmailConnector emailConnector, - MailParametersMapper mailParametersMapper, - CoreConfig coreConfig) { + public MailNotificationServiceImpl(NotificationServiceConnector notificationConnector, + FileStorageConnector fileStorageConnector, + InstitutionConnector institutionConnector, + ProductConnector productConnector, + ObjectMapper mapper, + MailTemplateConfig mailTemplateConfig, + EmailConnector emailConnector, + MailParametersMapper mailParametersMapper, + CoreConfig coreConfig) { this.notificationConnector = notificationConnector; this.fileStorageConnector = fileStorageConnector; this.institutionConnector = institutionConnector; 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 f53ad2930..43d6d4d38 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 @@ -23,7 +23,6 @@ import it.pagopa.selfcare.mscore.model.QueueEvent; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter; -import it.pagopa.selfcare.mscore.model.institution.Billing; import it.pagopa.selfcare.mscore.model.institution.Institution; import it.pagopa.selfcare.mscore.model.institution.Onboarding; import it.pagopa.selfcare.mscore.model.onboarding.*; @@ -57,7 +56,7 @@ public class OnboardingServiceImpl implements OnboardingService { private final UserRelationshipService userRelationshipService; private final UserEventService userEventService; private final ContractService contractService; - private final NotificationService notificationService; + private final MailNotificationService notificationService; private final UserNotificationService userNotificationService; private final PagoPaSignatureConfig pagoPaSignatureConfig; private final MailTemplateConfig mailTemplateConfig; @@ -71,7 +70,7 @@ public OnboardingServiceImpl(OnboardingDao onboardingDao, UserRelationshipService userRelationshipService, ContractService contractService, UserEventService userEventService, - NotificationService notificationService, + MailNotificationService notificationService, UserNotificationService userNotificationService, PagoPaSignatureConfig pagoPaSignatureConfig, OnboardingInstitutionStrategyFactory institutionStrategyFactory, diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java new file mode 100644 index 000000000..dfc047801 --- /dev/null +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java @@ -0,0 +1,11 @@ +package it.pagopa.selfcare.mscore.core; + +import java.util.List; +import java.util.Optional; + +public interface QueueNotificationService { + + void sendContracts(Optional size, List productsFilter); + + void sendUsers(Optional size, Optional page, List productsFilter, Optional userId); +} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/SchedulerServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java similarity index 77% rename from core/src/main/java/it/pagopa/selfcare/mscore/core/SchedulerServiceImpl.java rename to core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java index f92302899..9772df109 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/SchedulerServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java @@ -4,7 +4,6 @@ import it.pagopa.selfcare.mscore.api.TokenConnector; import it.pagopa.selfcare.mscore.api.UserConnector; import it.pagopa.selfcare.mscore.constant.RelationshipState; -import it.pagopa.selfcare.mscore.core.config.SchedulerConfig; import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; import it.pagopa.selfcare.mscore.model.QueueEvent; import it.pagopa.selfcare.mscore.model.institution.Institution; @@ -15,14 +14,13 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import java.time.OffsetDateTime; import java.util.EnumSet; import java.util.List; import java.util.Optional; @Service @Slf4j -public class SchedulerServiceImpl implements SchedulerService{ +public class QueueNotificationServiceImpl implements QueueNotificationService { public static final int TOKEN_PAGE_SIZE = 100; public static final int USER_PAGE_SIZE = 100; @@ -36,27 +34,25 @@ public class SchedulerServiceImpl implements SchedulerService{ private final UserConnector userConnector; - private final SchedulerConfig schedulerConfig; @Autowired - public SchedulerServiceImpl(ContractService contractService, - UserEventService userEventService, SchedulerConfig schedulerConfig, - TokenConnector tokenConnector, - InstitutionConnector institutionConnector, UserConnector userConnector) { + public QueueNotificationServiceImpl(ContractService contractService, + UserEventService userEventService, + TokenConnector tokenConnector, + InstitutionConnector institutionConnector, UserConnector userConnector) { this.userEventService = userEventService; this.userConnector = userConnector; - log.info("Initializing {}...", SchedulerServiceImpl.class.getSimpleName()); + log.info("Initializing {}...", QueueNotificationServiceImpl.class.getSimpleName()); this.contractService = contractService; - this.schedulerConfig = schedulerConfig; this.tokenConnector = tokenConnector; this.institutionConnector = institutionConnector; } @Async - public void regenerateQueueNotifications() { + public void regenerateContractsNotifications() { log.trace("regenerateQueueNotifications start"); - if (schedulerConfig.getSendOldEvent() && productsFilter.isPresent()) { + if (productsFilter.isPresent()) { for (String productId: productsFilter.get()) { log.debug("Regenerating notifications on queue with product filter {}", productId); @@ -66,7 +62,7 @@ public void regenerateQueueNotifications() { List tokens = tokenConnector.findByStatusAndProductId(EnumSet.of(RelationshipState.ACTIVE, RelationshipState.DELETED), productId, page, page_size_api.orElse(TOKEN_PAGE_SIZE)); log.debug("[KAFKA] TOKEN NUMBER {} PAGE {}", tokens.size(), page); - sendDataLakeNotifications(tokens); + sendScContractNotifications(tokens); page += 1; if (tokens.size() < TOKEN_PAGE_SIZE) { @@ -77,14 +73,11 @@ public void regenerateQueueNotifications() { } while (nextPage); } page_size_api = Optional.empty(); - schedulerConfig.setScheduler(false); } - - log.info("Next scheduled check at {}", OffsetDateTime.now().plusSeconds(schedulerConfig.getFixedDelay() / 1000)); log.trace("regenerateQueueNotifications end"); } - private void sendDataLakeNotifications(List tokens) { + private void sendScContractNotifications(List tokens) { tokens.forEach(token -> { try { Institution institution = institutionConnector.findById(token.getInstitutionId()); @@ -126,7 +119,6 @@ public void regenerateUserNotifications(Optional userId){ }while(nextPage); } page_size_api = Optional.empty(); - schedulerConfig.setScheduler(false); } } @@ -134,15 +126,14 @@ public void regenerateUserNotifications(Optional userId){ } @Override - public void startScheduler(Optional size, List productsFilter) { + public void sendContracts(Optional size, List productsFilter) { this.page_size_api = size; this.productsFilter = Optional.ofNullable(productsFilter); - schedulerConfig.setScheduler(true); - regenerateQueueNotifications(); + regenerateContractsNotifications(); } @Override - public void startUsersScheduler(Optional size, Optional page, List productsFilter, Optional userId) { + public void sendUsers(Optional size, Optional page, List productsFilter, Optional userId) { this.page_size_api = size; this.productsFilter = Optional.ofNullable(productsFilter); this.page=page; diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/SchedulerService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/SchedulerService.java deleted file mode 100644 index 26a454f04..000000000 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/SchedulerService.java +++ /dev/null @@ -1,11 +0,0 @@ -package it.pagopa.selfcare.mscore.core; - -import java.util.List; -import java.util.Optional; - -public interface SchedulerService { - - void startScheduler(Optional size, List productsFilter); - - void startUsersScheduler(Optional size,Optional page, List productsFilter, Optional userId); -} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/config/SchedulerConfig.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/config/SchedulerConfig.java deleted file mode 100644 index da07b2b8d..000000000 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/config/SchedulerConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -package it.pagopa.selfcare.mscore.core.config; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.SchedulingConfigurer; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.scheduling.config.ScheduledTaskRegistrar; - -@Configuration -@EnableScheduling -@PropertySource("classpath:config/core-config.properties") -public class SchedulerConfig implements SchedulingConfigurer { - - @Value("${scheduler.threads.max-number}") - private int maxScheduleThreadNumber; - - @Value("${scheduler.fixed-delay.delay}") - private Long fixedDelay; - - @Value("${scheduler.regenerate-kafka-queue-config.name}") - private String regenerateKafkaQueueConfigName; - - @Value("${scheduler.regenerate-kafka-queue.enabled}") - private boolean regnerateKafkaQueueEnabled; - - @Override - public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { - ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); - taskScheduler.setPoolSize(maxScheduleThreadNumber); - taskScheduler.setWaitForTasksToCompleteOnShutdown(true); - taskScheduler.initialize(); - taskRegistrar.setTaskScheduler(taskScheduler); - } - - private boolean sendOldEvent; - public boolean getSendOldEvent() { - return sendOldEvent; - } - - public void setScheduler(boolean sendOldEvent) { - this.sendOldEvent = sendOldEvent; - } - - public Long getFixedDelay(){ - return fixedDelay; - } - - public String getRegenerateKafkaQueueConfigName() { - return regenerateKafkaQueueConfigName; - } - - public boolean getRegnerateKafkaQueueEnabled() { - return regnerateKafkaQueueEnabled; - } - -} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java index 7c43d870e..56ccc50ca 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java @@ -45,20 +45,20 @@ public class OnboardingInstitutionStrategyFactory { private final CoreConfig coreConfig; private final FileStorageConnector fileStorageConnector; private final UserEventService userEventService; - private final NotificationService notificationService; + private final MailNotificationService mailNotificationService; public OnboardingInstitutionStrategyFactory(OnboardingDao onboardingDao, ContractService contractService, UserService userService, InstitutionService institutionService, CoreConfig coreConfig, - NotificationService notificationService, FileStorageConnector fileStorageConnector, UserEventService userEventService) { + MailNotificationService mailNotificationService, FileStorageConnector fileStorageConnector, UserEventService userEventService) { this.onboardingDao = onboardingDao; this.contractService = contractService; this.userService = userService; this.institutionService = institutionService; this.coreConfig = coreConfig; - this.notificationService = notificationService; + this.mailNotificationService = mailNotificationService; this.fileStorageConnector = fileStorageConnector; this.userEventService = userEventService; } @@ -202,7 +202,7 @@ private Consumer createContractAndPerformDig private Consumer sendConfirmationMail() { return strategyInput -> { try { - notificationService.setCompletedPGOnboardingMail(strategyInput.getOnboardingRequest().getInstitutionUpdate().getDigitalAddress(), strategyInput.getInstitution().getDescription()); + mailNotificationService.setCompletedPGOnboardingMail(strategyInput.getOnboardingRequest().getInstitutionUpdate().getDigitalAddress(), strategyInput.getInstitution().getDescription()); } catch (Exception e) { log.warn("Error during send completed email for product: {}", PROD_PN); } @@ -213,7 +213,7 @@ private Consumer sendEmailWithDigestOrRollba return strategyInput -> { try { User user = userService.retrieveUserFromUserRegistry(strategyInput.getPrincipal().getId()); - notificationService.sendMailWithContract(strategyInput.getPdf(), strategyInput.getInstitution(), user, strategyInput.getOnboardingRequest(), strategyInput.getOnboardingRollback().getToken().getId(), false); + mailNotificationService.sendMailWithContract(strategyInput.getPdf(), strategyInput.getInstitution(), user, strategyInput.getOnboardingRequest(), strategyInput.getOnboardingRollback().getToken().getId(), false); } catch (Exception e) { onboardingDao.rollbackSecondStep(strategyInput.getToUpdate(), strategyInput.getToDelete(), strategyInput.getInstitution().getId(), strategyInput.getOnboardingRollback().getToken(), strategyInput.getOnboardingRollback().getOnboarding(), strategyInput.getOnboardingRollback().getProductMap()); @@ -226,10 +226,10 @@ private Consumer sendEmailWithoutDigestOrRol try { User user = userService.retrieveUserFromUserRegistry(strategyInput.getPrincipal().getId()); if (!InstitutionType.PT.equals(strategyInput.getOnboardingRequest().getInstitutionUpdate().getInstitutionType())) { - notificationService.sendMailForApprove(user, strategyInput.getOnboardingRequest(), strategyInput.getOnboardingRollback().getToken().getId()); + mailNotificationService.sendMailForApprove(user, strategyInput.getOnboardingRequest(), strategyInput.getOnboardingRollback().getToken().getId()); } else { - notificationService.sendMailForRegistration(user, strategyInput.getInstitution(), strategyInput.getOnboardingRequest()); - notificationService.sendMailForRegistrationNotificationApprove(user, strategyInput.getOnboardingRequest(), strategyInput.getOnboardingRollback().getToken().getId()); + mailNotificationService.sendMailForRegistration(user, strategyInput.getInstitution(), strategyInput.getOnboardingRequest()); + mailNotificationService.sendMailForRegistrationNotificationApprove(user, strategyInput.getOnboardingRequest(), strategyInput.getOnboardingRollback().getToken().getId()); } } catch (Exception e) { onboardingDao.rollbackSecondStep(strategyInput.getToUpdate(), strategyInput.getToDelete(), strategyInput.getInstitution().getId(), @@ -252,7 +252,7 @@ private Consumer sendEmailWithLogoOrRollback if (strategyInput.getOnboardingRequest().getSendCompleteOnboardingEmail() == null || Boolean.TRUE.equals(strategyInput.getOnboardingRequest().getSendCompleteOnboardingEmail())) { - notificationService.sendAutocompleteMail(destinationMails, new HashMap<>(), logoFile, NotificationServiceImpl.PAGOPA_LOGO_FILENAME, strategyInput.getOnboardingRequest().getProductName()); + mailNotificationService.sendAutocompleteMail(destinationMails, new HashMap<>(), logoFile, MailNotificationServiceImpl.PAGOPA_LOGO_FILENAME, strategyInput.getOnboardingRequest().getProductName()); } } diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java index c1b7d22fe..2d26bc29b 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java @@ -29,7 +29,7 @@ class DelegationServiceImplTest { private DelegationServiceImpl delegationServiceImpl; @Mock - private NotificationService notificationService; + private MailNotificationService mailNotificationService; @Mock private InstitutionService institutionService; @@ -42,7 +42,7 @@ void testCreateDelegation() { Delegation delegation = new Delegation(); delegation.setId("id"); when(delegationConnector.save(any())).thenReturn(delegation); - doNothing().when(notificationService).sendMailForDelegation(any(), any(), any()); + doNothing().when(mailNotificationService).sendMailForDelegation(any(), any(), any()); Delegation response = delegationServiceImpl.createDelegation(delegation); verify(delegationConnector).save(any()); assertNotNull(response); @@ -61,7 +61,7 @@ void testCreateDelegationForProductPagopa() { Institution institution = new Institution(); institution.setId("id"); when(delegationConnector.save(any())).thenReturn(delegation); - doNothing().when(notificationService).sendMailForDelegation(any(), any(), any()); + doNothing().when(mailNotificationService).sendMailForDelegation(any(), any(), any()); when(institutionService.getInstitutions(any(), any())).thenReturn(List.of(institution)); Delegation response = delegationServiceImpl.createDelegation(delegation); verify(delegationConnector).save(any()); diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/NotificationServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/MailNotificationServiceImplTest.java similarity index 98% rename from core/src/test/java/it/pagopa/selfcare/mscore/core/NotificationServiceImplTest.java rename to core/src/test/java/it/pagopa/selfcare/mscore/core/MailNotificationServiceImplTest.java index b71b5a66c..b3922ee40 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/NotificationServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/MailNotificationServiceImplTest.java @@ -34,10 +34,10 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -class NotificationServiceImplTest { +class MailNotificationServiceImplTest { @InjectMocks - private NotificationServiceImpl notificationService; + private MailNotificationServiceImpl notificationService; @Mock private NotificationServiceConnector notificationConnector; 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 a601c5d9d..c83c116ed 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 @@ -66,7 +66,7 @@ class OnboardingServiceImplTest { @Mock private UserService userService; @Mock - private NotificationService emailService; + private MailNotificationService emailService; @Mock private UserRelationshipService userRelationshipService; diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/SchedulerServiceTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java similarity index 78% rename from core/src/test/java/it/pagopa/selfcare/mscore/core/SchedulerServiceTest.java rename to core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java index a519e45d1..e38ba06ed 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/SchedulerServiceTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java @@ -4,7 +4,6 @@ import it.pagopa.selfcare.mscore.api.TokenConnector; import it.pagopa.selfcare.mscore.api.UserConnector; import it.pagopa.selfcare.mscore.constant.RelationshipState; -import it.pagopa.selfcare.mscore.core.config.SchedulerConfig; import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; import it.pagopa.selfcare.mscore.model.QueueEvent; import it.pagopa.selfcare.mscore.model.institution.Institution; @@ -30,9 +29,9 @@ @ExtendWith(MockitoExtension.class) -class SchedulerServiceTest { +class QueueNotificationServiceTest { @InjectMocks - private SchedulerServiceImpl schedulerService; + private QueueNotificationServiceImpl schedulerService; @Mock private ContractService contractService; @@ -41,8 +40,6 @@ class SchedulerServiceTest { @Mock private UserEventService userEventService; @Mock - private SchedulerConfig scheduledConfig; - @Mock private InstitutionConnector institutionConnector; @Mock private TokenConnector tokenConnector; @@ -57,15 +54,13 @@ void startScheduler() { token.setInstitutionUpdate(institutionUpdate); final Institution institution = mockInstance(new Institution()); - schedulerService = new SchedulerServiceImpl(contractService, userEventService, scheduledConfig, tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService, userEventService,tokenConnector, institutionConnector, null); when(institutionConnector.findById(anyString())).thenReturn(institution); when(tokenConnector.findByStatusAndProductId(any(), any(), any(), any())).thenReturn(List.of(token)); - - when(scheduledConfig.getSendOldEvent()).thenReturn(true); //when - Executable executable = () -> schedulerService.startScheduler(Optional.of(1), List.of("product")); + Executable executable = () -> schedulerService.sendContracts(Optional.of(1), List.of("product")); //then assertDoesNotThrow(executable); verify(tokenConnector, times(1)).findByStatusAndProductId(EnumSet.of(RelationshipState.ACTIVE, RelationshipState.DELETED), "product", 0, 1); @@ -82,15 +77,13 @@ void startSchedulerUpdate(){ token.setInstitutionUpdate(institutionUpdate); final Institution institution = mockInstance(new Institution()); - schedulerService = new SchedulerServiceImpl(contractService, userEventService, scheduledConfig, tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService, userEventService, tokenConnector, institutionConnector, null); when(institutionConnector.findById(anyString())).thenReturn(institution); when(tokenConnector.findByStatusAndProductId(any(), any(), any(), any())).thenReturn(List.of(token)); - - when(scheduledConfig.getSendOldEvent()).thenReturn(true); //when - Executable executable = () -> schedulerService.startScheduler(Optional.of(1), List.of("product")); + Executable executable = () -> schedulerService.sendContracts(Optional.of(1), List.of("product")); //then assertDoesNotThrow(executable); verify(tokenConnector, times(1)).findByStatusAndProductId(EnumSet.of(RelationshipState.ACTIVE, RelationshipState.DELETED), "product", 0, 1); @@ -98,21 +91,25 @@ void startSchedulerUpdate(){ verify(contractService, times(1)).sendDataLakeNotification(institution, token, QueueEvent.UPDATE); } + @Test + void startContractScheduler_productNotPresent(){ + + } + @Test void institutionNotFound(){ //given final Token token = mockInstance(new Token()); token.setStatus(RelationshipState.DELETED); - schedulerService = new SchedulerServiceImpl(contractService, userEventService, scheduledConfig, tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService, userEventService, tokenConnector, institutionConnector, null); when(institutionConnector.findById(anyString())).thenThrow(ResourceNotFoundException.class); when(tokenConnector.findByStatusAndProductId(any(), any(), any(), any())).thenReturn(List.of(token)); - when(scheduledConfig.getSendOldEvent()).thenReturn(true); //when - Executable executable = () -> schedulerService.startScheduler(Optional.of(1), List.of("product")); + Executable executable = () -> schedulerService.sendContracts(Optional.of(1), List.of("product")); //then assertDoesNotThrow(executable); verify(tokenConnector, times(1)).findByStatusAndProductId(EnumSet.of(RelationshipState.ACTIVE, RelationshipState.DELETED), "product", 0, 1); @@ -121,13 +118,13 @@ void institutionNotFound(){ @Test void schedulerNotStarted(){ - Executable executable = () -> schedulerService.startScheduler(Optional.of(1), List.of("product")); + Executable executable = () -> schedulerService.sendContracts(Optional.of(1), List.of("product")); verifyNoInteractions(tokenConnector, institutionConnector, contractService); } @Test void productsFilterNotPresent(){ - Executable executable = () -> schedulerService.startScheduler(Optional.of(1), null); + Executable executable = () -> schedulerService.sendContracts(Optional.of(1), null); verifyNoInteractions(tokenConnector, institutionConnector, contractService); } @@ -140,7 +137,7 @@ void startUserScheduler(){ final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); when(userConnector.findAllValidUsers(any(), any(), any())).thenReturn(List.of(onboardedUser)); //when - Executable executable = () -> schedulerService.startUsersScheduler(size, page, productIds, Optional.empty()); + Executable executable = () -> schedulerService.sendUsers(size, page, productIds, Optional.empty()); //then assertDoesNotThrow(executable); verify(userEventService, times(1)).sendOnboardedUserNotification(onboardedUser, productIds.get(0)); @@ -156,7 +153,7 @@ void startUserScheduler_singleUser(){ final Optional userId = Optional.of("userId"); when(userConnector.findById(any())).thenReturn(onboardedUser); //when - Executable executable = () -> schedulerService.startUsersScheduler(size, page, productIds, userId); + Executable executable = () -> schedulerService.sendUsers(size, page, productIds, userId); //then assertDoesNotThrow(executable); verify(userEventService, times(1)).sendOnboardedUserNotification(onboardedUser, productIds.get(0)); @@ -171,7 +168,7 @@ void startUserScheduler_noProducts(){ final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); final Optional userId = Optional.of("userId"); //when - Executable executable = () -> schedulerService.startUsersScheduler(size, page, null, null); + Executable executable = () -> schedulerService.sendUsers(size, page, null, null); //then assertDoesNotThrow(executable); verifyNoInteractions(userEventService, userConnector); @@ -186,7 +183,7 @@ void startUserScheduler_pageDefault(){ final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); when(userConnector.findAllValidUsers(any(), any(), any())).thenReturn(List.of(onboardedUser)); //when - Executable executable = () -> schedulerService.startUsersScheduler(Optional.empty(), Optional.empty(), productIds, Optional.empty()); + Executable executable = () -> schedulerService.sendUsers(Optional.empty(), Optional.empty(), productIds, Optional.empty()); //then assertDoesNotThrow(executable); verify(userEventService, times(1)).sendOnboardedUserNotification(onboardedUser, productIds.get(0)); @@ -199,7 +196,7 @@ void startScheduler_emptyProductList(){ final List productIds = new ArrayList<>(); final Optional size = Optional.of(1); //when - Executable executable = () -> schedulerService.startUsersScheduler(Optional.empty(), Optional.empty(), productIds, Optional.empty()); + Executable executable = () -> schedulerService.sendUsers(Optional.empty(), Optional.empty(), productIds, Optional.empty()); //then assertDoesNotThrow(executable); verifyNoInteractions(userEventService); diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java index 416849cc4..7233e1593 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java @@ -50,7 +50,7 @@ class OnboardingInstitutionStrategyTest { @Mock private UserService userService; @Mock - private NotificationService notificationService; + private MailNotificationService mailNotificationService; @Mock private FileStorageConnector fileStorageConnector; @@ -62,7 +62,7 @@ class OnboardingInstitutionStrategyTest { @BeforeEach void beforeAll() { strategyFactory = new OnboardingInstitutionStrategyFactory(onboardingDao, - contractService,userService, institutionService, coreConfig, notificationService, fileStorageConnector, userEventService); + contractService,userService, institutionService, coreConfig, mailNotificationService, fileStorageConnector, userEventService); } diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java new file mode 100644 index 000000000..f1297a7af --- /dev/null +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java @@ -0,0 +1,44 @@ +package it.pagopa.selfcare.mscore.web.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import it.pagopa.selfcare.mscore.core.QueueNotificationService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Optional; + +@RestController +@Slf4j +@RequestMapping("/notification-event") +@Api(tags = "kafka") +public class QueueNotificationController { + + private final QueueNotificationService queueNotificationService; + + public QueueNotificationController(QueueNotificationService queueNotificationService) { + this.queueNotificationService = queueNotificationService; + } + @ApiOperation(value = "", notes = "${swagger.ms-core.notification-event.api.start}") + @PostMapping(value = "/contracts") + @ResponseStatus(HttpStatus.OK) + public void resendContracts(@RequestParam(name = "size", required = false) Optional size, + @RequestParam(name = "productsFilter") List productsFilter){ + + log.trace("Resend contracts events started"); + queueNotificationService.sendContracts(size, productsFilter); + } + + @ApiOperation(value = "", notes = "${swagger.ms-core.notification-event.api.start.users}") + @PostMapping(value = "/users") + @ResponseStatus(HttpStatus.OK) + public void resendUsers(@RequestParam(name = "size", required = false)Optional size, + @RequestParam(name = "page", required = false)Optional page, + @RequestParam(name = "productsFilter")List productsFilter, + @RequestParam(name = "userId", required = false)Optional userId){ + log.trace("Resend users events started"); + queueNotificationService.sendUsers(size, page, productsFilter, userId); + } +} \ No newline at end of file diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/SchedulerController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/SchedulerController.java deleted file mode 100644 index ae370aaea..000000000 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/SchedulerController.java +++ /dev/null @@ -1,44 +0,0 @@ -package it.pagopa.selfcare.mscore.web.controller; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import it.pagopa.selfcare.mscore.core.SchedulerService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Optional; - -@RestController -@Slf4j -@RequestMapping("/scheduler") -@Api(tags = "scheduler") -public class SchedulerController { - - private final SchedulerService schedulerService; - - public SchedulerController(SchedulerService schedulerService) { - this.schedulerService = schedulerService; - } - @ApiOperation(value = "", notes = "${swagger.ms-core.scheduler.api.start}") - @PostMapping(value = "") - @ResponseStatus(HttpStatus.OK) - public void start(@RequestParam(name = "size", required = false) Optional size, - @RequestParam(name = "productsFilter") List productsFilter){ - - log.trace("Scheduler Started"); - schedulerService.startScheduler(size, productsFilter); - } - - @ApiOperation(value = "", notes = "${swagger.ms-core.scheduler.api.start.users}") - @PostMapping(value = "/users") - @ResponseStatus(HttpStatus.OK) - public void startUsers(@RequestParam(name = "size", required = false)Optional size, - @RequestParam(name = "page", required = false)Optional page, - @RequestParam(name = "productsFilter")List productsFilter, - @RequestParam(name = "userId", required = false)Optional userId){ - log.trace("Scheduler started for Users"); - schedulerService.startUsersScheduler(size, page, productsFilter, userId); - } -} \ No newline at end of file diff --git a/web/src/main/resources/swagger/swagger_en.properties b/web/src/main/resources/swagger/swagger_en.properties index 014c48158..4913f7176 100644 --- a/web/src/main/resources/swagger/swagger_en.properties +++ b/web/src/main/resources/swagger/swagger_en.properties @@ -7,8 +7,8 @@ swagger.mscore.external.institution.products=retrieves the products related to I swagger.mscore.external.geotaxonomies=retrieves the geographic taxonomies related to Institution. swagger.mscore.external.institution.relationships=returns the relationships related to the institution swagger.mscore.institutions=Gets institutions filtering by taxCode and/or subunitCode -swagger.ms-core.scheduler.api.start=Service to start scheduler to resend old messages to DL -swagger.ms-core.scheduler.api.start.users=Service to resend old user onboardings to the SCUsers kafka queue, it can send the onboardings of a single user or also retrieve all the users for a given set of products in a paged manner by passing page and size +swagger.ms-core.notification-event.api.start=Service to resend contract notifications on SC-Contracts topic +swagger.ms-core.notification-event.api.start.users=Service to resend old user onboardings to the SCUsers kafka queue, it can send the onboardings of a single user or also retrieve all the users for a given set of products in a paged manner by passing page and size swagger.mscore.institution.create.from-ipa=create an institution from ipa registry swagger.mscore.institution.create.from-ivass=create an institution from ivass CSV swagger.mscore.institution.create.from-infocamere=create an institution from infocamere registry diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/SchedulerControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java similarity index 66% rename from web/src/test/java/it/pagopa/selfcare/mscore/web/controller/SchedulerControllerTest.java rename to web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java index 8629c6d26..6ddc58d8b 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/SchedulerControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java @@ -1,7 +1,7 @@ package it.pagopa.selfcare.mscore.web.controller; import com.fasterxml.jackson.databind.ObjectMapper; -import it.pagopa.selfcare.mscore.core.SchedulerService; +import it.pagopa.selfcare.mscore.core.QueueNotificationService; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -17,33 +17,33 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(value = {SchedulerController.class}, excludeAutoConfiguration = SecurityAutoConfiguration.class) -@ContextConfiguration(classes = {SchedulerController.class}) -class SchedulerControllerTest { - private static final String BASE_URL = "/scheduler"; +@WebMvcTest(value = {QueueNotificationController.class}, excludeAutoConfiguration = SecurityAutoConfiguration.class) +@ContextConfiguration(classes = {QueueNotificationController.class}) +class QueueNotificationControllerTest { + private static final String BASE_URL = "/notification-event"; @Autowired protected MockMvc mvc; @MockBean - private SchedulerService schedulerService; + private QueueNotificationService queueNotificationService; @Autowired private ObjectMapper objectMapper; @Test - void startScheduler() throws Exception { + void sendContracts() throws Exception { Integer size = 1; String productId = "product"; mvc.perform(MockMvcRequestBuilders - .post(BASE_URL) + .post(BASE_URL+"/contracts") .param("size", String.valueOf(size)) .param("productsFilter", productId)) .andExpect(status().isOk()); - Mockito.verify(schedulerService, Mockito.times(1)).startScheduler(Optional.of(size), List.of(productId)); + Mockito.verify(queueNotificationService, Mockito.times(1)).sendContracts(Optional.of(size), List.of(productId)); } @Test - void startSchedulerUsers() throws Exception{ + void sendUsers() throws Exception{ Integer size = 1; Integer page = 0; String productId = "product"; @@ -54,6 +54,6 @@ void startSchedulerUsers() throws Exception{ .param("productsFilter", productId)) .andExpect(status().isOk()); - Mockito.verify(schedulerService, Mockito.times(1)).startUsersScheduler(Optional.of(size),Optional.of(page), List.of(productId), Optional.empty()); + Mockito.verify(queueNotificationService, Mockito.times(1)).sendUsers(Optional.of(size),Optional.of(page), List.of(productId), Optional.empty()); } } \ No newline at end of file