Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[SELC-3666] feat: refactored code #352

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"name" : "Token",
"description" : "Token Controller"
}, {
"name" : "scheduler",
"description" : "Scheduler Controller"
"name" : "kafka",
"description" : "Queue Notification Controller"
} ],
"paths" : {
"/migration/institution" : {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SwaggerConfigTest {
UserService userService;

@MockBean
SchedulerService schedulerService;
QueueNotificationService queueNotificationService;

@Autowired
WebApplicationContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.List;
import java.util.Map;

public interface NotificationService {
public interface MailNotificationService {

void setCompletedPGOnboardingMail(String destinationMail, String businessName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}";
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand All @@ -71,7 +70,7 @@ public OnboardingServiceImpl(OnboardingDao onboardingDao,
UserRelationshipService userRelationshipService,
ContractService contractService,
UserEventService userEventService,
NotificationService notificationService,
MailNotificationService notificationService,
UserNotificationService userNotificationService,
PagoPaSignatureConfig pagoPaSignatureConfig,
OnboardingInstitutionStrategyFactory institutionStrategyFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.pagopa.selfcare.mscore.core;

import java.util.List;
import java.util.Optional;

public interface QueueNotificationService {

void sendContracts(Optional<Integer> size, List<String> productsFilter);

void sendUsers(Optional<Integer> size, Optional<Integer> page, List<String> productsFilter, Optional<String> userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -66,7 +62,7 @@ public void regenerateQueueNotifications() {
List<Token> 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) {
Expand All @@ -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<Token> tokens) {
private void sendScContractNotifications(List<Token> tokens) {
tokens.forEach(token -> {
try {
Institution institution = institutionConnector.findById(token.getInstitutionId());
Expand Down Expand Up @@ -126,23 +119,21 @@ public void regenerateUserNotifications(Optional<String> userId){
}while(nextPage);
}
page_size_api = Optional.empty();
schedulerConfig.setScheduler(false);
}

}

}

@Override
public void startScheduler(Optional<Integer> size, List<String> productsFilter) {
public void sendContracts(Optional<Integer> size, List<String> productsFilter) {
this.page_size_api = size;
this.productsFilter = Optional.ofNullable(productsFilter);
schedulerConfig.setScheduler(true);
regenerateQueueNotifications();
regenerateContractsNotifications();
}

@Override
public void startUsersScheduler(Optional<Integer> size, Optional<Integer> page, List<String> productsFilter, Optional<String> userId) {
public void sendUsers(Optional<Integer> size, Optional<Integer> page, List<String> productsFilter, Optional<String> userId) {
this.page_size_api = size;
this.productsFilter = Optional.ofNullable(productsFilter);
this.page=page;
Expand Down

This file was deleted.

This file was deleted.

Loading