Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PN-13423] Modifica flusso delivery-push per recupero domicilio digitale per PF. #1121

Open
wants to merge 3 commits into
base: feature/PN-13419
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@ pn.delivery-push.time-params.attachment-retention-time-after-validation=120d
pn.delivery-push.time-params.check-attachment-time-before-expiration=10d

# Time to add when attachment retention is expiring
pn.delivery-push.time-params.attachment-retention-time-to-add-after-expiration=120d
pn.delivery-push.time-params.attachment-retention-time-to-add-after-expiration=120d

pn.delivery-push.pfnewworkflowstart=2099-02-13T23:00:00Z
pn.delivery-push.pfnewworkflowend=2099-03-31T23:00:00Z
4 changes: 3 additions & 1 deletion scripts/aws/cfn/microservice-dev-cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"FutureActionTtlExtraDays": "10",
"AttemptTimeoutSec": "7",
"NumRetry": "3",
"AdditionalLangsEnabled": "true"
"AdditionalLangsEnabled": "true",
"pfNewWorkflowStart": "2099-07-14T20:00:00Z",
"pfNewWorkflowStop": "2099-07-14T23:59:59Z"
}
}
12 changes: 12 additions & 0 deletions scripts/aws/cfn/microservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ Parameters:
AllowedValues: [ true, false ]
Default: false

pfNewWorkflowStart:
Type: String
Description: 'Start date for new workflow for PF recipient'
Default: '2021-01-01T00:00:00Z'

pfNewWorkflowStop:
Type: String
Description: 'End date for new workflow for PF recipient'
Default: '2021-01-01T00:00:00Z'

#quickWorkAroundForPN-9116
SendMoreThan20GramsDefaultValue:
Type: String
Expand Down Expand Up @@ -1000,6 +1010,8 @@ Resources:
ContainerEnvEntry80: !Sub 'PN_DELIVERYPUSH_TOPICS_DELIVERYVALIDATIONEVENTS=${DeliveryPushValidationInputsQueueName}'
ContainerEnvEntry81: !Sub 'PN_DELIVERYPUSH_WEBHOOK_MAXSTREAMS=${WebhookMaxStreams}'
ContainerEnvEntry82: !Sub 'PN_DELIVERYPUSH_ADDITIONALLANGSENABLED=${AdditionalLangsEnabled}'
ContainerEnvEntry83: !Sub 'PN_DELIVERYPUSH_PFNEWWORKFLOWSTART=${pfNewWorkflowStart}'
ContainerEnvEntry84: !Sub 'PN_DELIVERYPUSH_PFNEWWORKFLOWSTOP=${pfNewWorkflowStop}'
ContainerSecret1: !Sub 'PN_DELIVERYPUSH_ADDRESSMANAGERAPIKEY=arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:pn-DeliveryPush-Secrets:AddressManagerApiKey:AWSCURRENT:'
MicroServiceSecretPrefix: pn-DeliveryPush-Secrets
JavaToolOptions: '-Dreactor.netty.ioWorkerCount=50'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import it.pagopa.pn.deliverypush.dto.timeline.details.ContactPhaseInt;
import it.pagopa.pn.deliverypush.dto.timeline.details.ProbableDateAnalogWorkflowDetailsInt;
import it.pagopa.pn.deliverypush.middleware.queue.producer.abstractions.actionspool.ActionType;
import it.pagopa.pn.deliverypush.service.NotificationService;
import it.pagopa.pn.deliverypush.service.NationalRegistriesService;
import it.pagopa.pn.deliverypush.service.NotificationService;
import it.pagopa.pn.deliverypush.service.SchedulerService;
import it.pagopa.pn.deliverypush.service.TimelineService;
import it.pagopa.pn.deliverypush.utils.FeatureEnabledUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
Expand All @@ -32,6 +33,7 @@ public class ChooseDeliveryModeHandler {
private final ChooseDeliveryModeUtils chooseDeliveryUtils;
private final NotificationService notificationService;
private final TimelineService timelineService;
private final FeatureEnabledUtils featureEnabledUtils;


/**
Expand All @@ -46,37 +48,51 @@ public void chooseDeliveryTypeAndStartWorkflow(String iun, Integer recIndex) {
log.info("Start ChooseDeliveryTypeAndStartWorkflow process - iun={} recipientIndex={}", iun, recIndex);

NotificationInt notification = notificationService.getNotificationByIun(iun);

Optional<LegalDigitalAddressInt> platformAddressOpt = chooseDeliveryUtils.getPlatformAddress(notification, recIndex);

//Verifico presenza indirizzo di piattaforma, ...
if (platformAddressOpt.isPresent()) {
log.info("Platform address is present, Digital workflow can be started - iun={} recipientIndex={}", notification.getIun(), recIndex);
LegalDigitalAddressInt platformAddress = platformAddressOpt.get();

chooseDeliveryUtils.addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.PLATFORM, true);
digitalWorkFlowHandler.startDigitalWorkflow(notification, platformAddress, DigitalAddressSourceInt.PLATFORM, recIndex);
if (featureEnabledUtils.isPfNewWorkflowEnabled(notification.getSentAt())) {
getGeneralAddress(recIndex, notification);
} else {
log.info("Platform address isn't present - iun={} recipientIndex={}", notification.getIun(), recIndex);
chooseDeliveryUtils.addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.PLATFORM, false);

// ... se non lo trovo, verifico presenza indirizzo speciale, ...
LegalDigitalAddressInt specialAddress = chooseDeliveryUtils.getDigitalDomicile(notification, recIndex);
if (specialAddress != null && StringUtils.hasText(specialAddress.getAddress())) {
log.info("Special address is present, Digital workflow can be started - iun={} id={}", notification.getIun(), recIndex);
pfStartOldWorkflow(recIndex, notification);
}
log.info("END chooseDeliveryTypeAndStartWorkflow process - iun={} recipientIndex={}", notification.getIun(), recIndex);
}

chooseDeliveryUtils.addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.SPECIAL, true);
private void pfStartOldWorkflow(Integer recIndex, NotificationInt notification) {
//Verifico presenza indirizzo di piattaforma, ...
Optional<LegalDigitalAddressInt> platformAddressOpt = chooseDeliveryUtils.retrievePlatformAddress(notification, recIndex);
// ... se non lo trovo, verifico presenza indirizzo speciale, ...
if (platformAddressOpt.isEmpty()) {
LegalDigitalAddressInt specialAddress = chooseDeliveryUtils.retrieveSpecialAddress(notification, recIndex);
if (specialAddress == null || !StringUtils.hasText(specialAddress.getAddress())) {
// ... se non lo trovo, verifico presenza indirizzo generale
getGeneralAddress(recIndex, notification);
}else{
digitalWorkFlowHandler.startDigitalWorkflow(notification, specialAddress, DigitalAddressSourceInt.SPECIAL, recIndex);
} else {
log.info("Special address isn't present, need to get General address async - iun={} recipientIndex={}", notification.getIun(), recIndex);
chooseDeliveryUtils.addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.SPECIAL, false);
}
}else{
digitalWorkFlowHandler.startDigitalWorkflow(notification, platformAddressOpt.get(), DigitalAddressSourceInt.PLATFORM, recIndex);
}
}

// ... se non lo trovo, lancio ricerca asincrona dell'indirizzo generale
nationalRegistriesService.sendRequestForGetDigitalGeneralAddress(notification, recIndex, ContactPhaseInt.CHOOSE_DELIVERY, ChooseDeliveryModeUtils.ZERO_SENT_ATTEMPT_NUMBER, null);
private void checkSpecialAndPlatformAddress(NotificationInt notification, Integer recIndex) {
//Verifico presenza indirizzo speciale, ...
LegalDigitalAddressInt specialAddress = chooseDeliveryUtils.retrieveSpecialAddress(notification, recIndex);
// ... se non lo trovo, verifico presenza indirizzo di piattaforma, ...
if (specialAddress == null) {
Optional<LegalDigitalAddressInt> platformAddressOpt = chooseDeliveryUtils.retrievePlatformAddress(notification, recIndex);
// ... se non lo trovo, parte il flusso di invio notifica analogica.
if (platformAddressOpt.isEmpty()) {
scheduleAnalogWorkflow(notification, recIndex);
}else{
digitalWorkFlowHandler.startDigitalWorkflow(notification, platformAddressOpt.get(), DigitalAddressSourceInt.PLATFORM, recIndex);
}
}
else {
digitalWorkFlowHandler.startDigitalWorkflow(notification, specialAddress, DigitalAddressSourceInt.SPECIAL, recIndex);
}
}

log.info("END chooseDeliveryTypeAndStartWorkflow process - iun={} recipientIndex={}", notification.getIun(), recIndex);
private void getGeneralAddress(Integer recIndex, NotificationInt notification) {
nationalRegistriesService.sendRequestForGetDigitalGeneralAddress(notification, recIndex, ContactPhaseInt.CHOOSE_DELIVERY, ChooseDeliveryModeUtilsImpl.ZERO_SENT_ATTEMPT_NUMBER, null);
}

/**
Expand All @@ -98,7 +114,12 @@ public void handleGeneralAddressResponse(NationalRegistriesResponse response, No
} else {
log.info("General address is not present, digital workflow can't be started. Starting Analog Workflow - iun={} id={}", notification.getIun(), recIndex);
chooseDeliveryUtils.addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.GENERAL, false);
scheduleAnalogWorkflow(notification, recIndex);
if (featureEnabledUtils.isPfNewWorkflowEnabled(notification.getSentAt())) {
log.info("New workflow is enabled - iun={} id={}", notification.getIun(), recIndex);
checkSpecialAndPlatformAddress(notification, recIndex);
} else {
scheduleAnalogWorkflow(notification, recIndex);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,27 @@
package it.pagopa.pn.deliverypush.action.choosedeliverymode;

import it.pagopa.pn.deliverypush.action.utils.CourtesyMessageUtils;
import it.pagopa.pn.deliverypush.action.utils.NotificationUtils;
import it.pagopa.pn.deliverypush.action.utils.TimelineUtils;
import it.pagopa.pn.deliverypush.dto.address.DigitalAddressSourceInt;
import it.pagopa.pn.deliverypush.dto.address.LegalDigitalAddressInt;
import it.pagopa.pn.deliverypush.dto.ext.delivery.notification.NotificationInt;
import it.pagopa.pn.deliverypush.dto.ext.delivery.notification.NotificationRecipientInt;
import it.pagopa.pn.deliverypush.dto.timeline.TimelineElementInternal;
import it.pagopa.pn.deliverypush.dto.timeline.details.SendCourtesyMessageDetailsInt;
import it.pagopa.pn.deliverypush.service.AddressBookService;
import it.pagopa.pn.deliverypush.service.TimelineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.Comparator;
import java.util.Optional;

@Component
@Slf4j
public class ChooseDeliveryModeUtils {
public static final int ZERO_SENT_ATTEMPT_NUMBER = 0;
public static final int ONE_SENT_ATTEMPT_NUMBER = 1;
public interface ChooseDeliveryModeUtils {

private final TimelineService timelineService;
private final TimelineUtils timelineUtils;
private final CourtesyMessageUtils courtesyMessageUtils;
private final AddressBookService addressBookService;
private final NotificationUtils notificationUtils;
void addAvailabilitySourceToTimeline(Integer recIndex, NotificationInt notification, DigitalAddressSourceInt addressSource, boolean isAvailable);

public ChooseDeliveryModeUtils(TimelineService timelineService, TimelineUtils timelineUtils, CourtesyMessageUtils courtesyMessageUtils,
AddressBookService addressBookService, NotificationUtils notificationUtils) {
this.timelineService = timelineService;
this.timelineUtils = timelineUtils;
this.courtesyMessageUtils = courtesyMessageUtils;
this.addressBookService = addressBookService;
this.notificationUtils = notificationUtils;
}
void addScheduleAnalogWorkflowToTimeline(Integer recIndex, NotificationInt notification, Instant schedulingDate);

public void addAvailabilitySourceToTimeline(Integer recIndex, NotificationInt notification, DigitalAddressSourceInt addressSource, boolean isAvailable) {
TimelineElementInternal element = timelineUtils.buildAvailabilitySourceTimelineElement(recIndex, notification, addressSource, isAvailable, ZERO_SENT_ATTEMPT_NUMBER);
timelineService.addTimelineElement(element, notification);
}
Optional<SendCourtesyMessageDetailsInt> getFirstSentCourtesyMessage(String iun, Integer recIndex);

public void addScheduleAnalogWorkflowToTimeline(Integer recIndex, NotificationInt notification, Instant schedulingDate) {
TimelineElementInternal element = timelineUtils.buildScheduleAnalogWorkflowTimeline(notification, recIndex, schedulingDate);
timelineService.addTimelineElement(element, notification);
}
Optional<LegalDigitalAddressInt> getPlatformAddress(NotificationInt notification, Integer recIndex);

public Optional<SendCourtesyMessageDetailsInt> getFirstSentCourtesyMessage(String iun, Integer recIndex) {
return courtesyMessageUtils.getSentCourtesyMessagesDetails(iun, recIndex).stream().min(Comparator.comparing(SendCourtesyMessageDetailsInt::getSendDate));
}
LegalDigitalAddressInt getDigitalDomicile(NotificationInt notification, Integer recIndex);

Optional<LegalDigitalAddressInt> retrievePlatformAddress(NotificationInt notification, Integer recIndex);

LegalDigitalAddressInt retrieveSpecialAddress(NotificationInt notification, Integer recIndex);

public Optional<LegalDigitalAddressInt> getPlatformAddress(NotificationInt notification, Integer recIndex) {
NotificationRecipientInt notificationRecipient = notificationUtils.getRecipientFromIndex(notification,recIndex);

return addressBookService.getPlatformAddresses(notificationRecipient.getInternalId(), notification.getSender().getPaId());
}

public LegalDigitalAddressInt getDigitalDomicile(NotificationInt notification, Integer recIndex){
NotificationRecipientInt notificationRecipient = notificationUtils.getRecipientFromIndex(notification,recIndex);
return notificationRecipient.getDigitalDomicile();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package it.pagopa.pn.deliverypush.action.choosedeliverymode;

import it.pagopa.pn.deliverypush.action.utils.CourtesyMessageUtils;
import it.pagopa.pn.deliverypush.action.utils.NotificationUtils;
import it.pagopa.pn.deliverypush.action.utils.TimelineUtils;
import it.pagopa.pn.deliverypush.dto.address.DigitalAddressSourceInt;
import it.pagopa.pn.deliverypush.dto.address.LegalDigitalAddressInt;
import it.pagopa.pn.deliverypush.dto.ext.delivery.notification.NotificationInt;
import it.pagopa.pn.deliverypush.dto.ext.delivery.notification.NotificationRecipientInt;
import it.pagopa.pn.deliverypush.dto.timeline.TimelineElementInternal;
import it.pagopa.pn.deliverypush.dto.timeline.details.SendCourtesyMessageDetailsInt;
import it.pagopa.pn.deliverypush.service.AddressBookService;
import it.pagopa.pn.deliverypush.service.TimelineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.time.Instant;
import java.util.Comparator;
import java.util.Optional;

@Component
@Slf4j
public class ChooseDeliveryModeUtilsImpl implements ChooseDeliveryModeUtils{
public static final int ZERO_SENT_ATTEMPT_NUMBER = 0;
public static final int ONE_SENT_ATTEMPT_NUMBER = 1;

private final TimelineService timelineService;
private final TimelineUtils timelineUtils;
private final CourtesyMessageUtils courtesyMessageUtils;
private final AddressBookService addressBookService;
private final NotificationUtils notificationUtils;

public ChooseDeliveryModeUtilsImpl(TimelineService timelineService, TimelineUtils timelineUtils, CourtesyMessageUtils courtesyMessageUtils,
AddressBookService addressBookService, NotificationUtils notificationUtils) {
this.timelineService = timelineService;
this.timelineUtils = timelineUtils;
this.courtesyMessageUtils = courtesyMessageUtils;
this.addressBookService = addressBookService;
this.notificationUtils = notificationUtils;
}

public void addAvailabilitySourceToTimeline(Integer recIndex, NotificationInt notification, DigitalAddressSourceInt addressSource, boolean isAvailable) {
TimelineElementInternal element = timelineUtils.buildAvailabilitySourceTimelineElement(recIndex, notification, addressSource, isAvailable, ZERO_SENT_ATTEMPT_NUMBER);
timelineService.addTimelineElement(element, notification);
}

public void addScheduleAnalogWorkflowToTimeline(Integer recIndex, NotificationInt notification, Instant schedulingDate) {
TimelineElementInternal element = timelineUtils.buildScheduleAnalogWorkflowTimeline(notification, recIndex, schedulingDate);
timelineService.addTimelineElement(element, notification);
}

public Optional<SendCourtesyMessageDetailsInt> getFirstSentCourtesyMessage(String iun, Integer recIndex) {
return courtesyMessageUtils.getSentCourtesyMessagesDetails(iun, recIndex).stream().min(Comparator.comparing(SendCourtesyMessageDetailsInt::getSendDate));
}

public Optional<LegalDigitalAddressInt> getPlatformAddress(NotificationInt notification, Integer recIndex) {
NotificationRecipientInt notificationRecipient = notificationUtils.getRecipientFromIndex(notification,recIndex);

return addressBookService.getPlatformAddresses(notificationRecipient.getInternalId(), notification.getSender().getPaId());
}

public LegalDigitalAddressInt getDigitalDomicile(NotificationInt notification, Integer recIndex){
NotificationRecipientInt notificationRecipient = notificationUtils.getRecipientFromIndex(notification,recIndex);
return notificationRecipient.getDigitalDomicile();
}

@Override
public Optional<LegalDigitalAddressInt> retrievePlatformAddress(NotificationInt notification, Integer recIndex) {
Optional<LegalDigitalAddressInt> platformAddressOpt = getPlatformAddress(notification, recIndex);
if (platformAddressOpt.isPresent()) {
log.info("Platform address is present, Digital workflow can be started - iun={} recipientIndex={}", notification.getIun(), recIndex);
addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.PLATFORM, true);
} else {
log.info("Platform address isn't present - iun={} recipientIndex={}", notification.getIun(), recIndex);
addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.PLATFORM, false);
}
return platformAddressOpt;
}

@Override
public LegalDigitalAddressInt retrieveSpecialAddress(NotificationInt notification, Integer recIndex) {
LegalDigitalAddressInt specialAddress = getDigitalDomicile(notification, recIndex);
if (specialAddress != null && StringUtils.hasText(specialAddress.getAddress())) {
log.info("Special address is present, Digital workflow can be started - iun={} id={}", notification.getIun(), recIndex);
addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.SPECIAL, true);
} else {
log.info("Special address isn't present, need to get General address async - iun={} recipientIndex={}", notification.getIun(), recIndex);
addAvailabilitySourceToTimeline(recIndex, notification, DigitalAddressSourceInt.SPECIAL, false);
}
return specialAddress;
}
}
Loading
Loading