Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions scripts/aws/cfn/microservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ Resources:
ContainerEnvEntry11: !Sub 'PN_WORKFLOWMANAGER_ACTIONMANAGERBASEURL=http://${ApplicationLoadBalancerDomain}:8080'
ContainerEnvEntry12: !Sub 'PN_WORKFLOWMANAGER_IOCONNECTORBASEURL=http://${ApplicationLoadBalancerDomain}:8080'
ContainerEnvEntry13: !Sub 'PN_WORKFLOWMANAGER_TEMPLATEENGINEBASEURL=http://${ApplicationLoadBalancerDomain}:8080'
ContainerEnvEntry14: !Sub 'PN_WORKFLOWMANAGER_PAPERMESSAGESCLIENTBASEURL=http://${ApplicationLoadBalancerDomain}:8080'
ApplicativeEnvFileChecksum: !Ref ApplicativeEnvFileChecksum
JavaToolOptions: '-Dreactor.netty.ioWorkerCount=50'
MappedPaths: '/workflow-manager-not-available'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PnWorkflowManagerConfigs {
private String deliveryBaseUrl;
private String templateEngineBaseUrl;
private String ioConnectorBaseUrl;
private String paperMessagesClientBaseUrl;

private Integer ioPollingMaxMins;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package it.pagopa.pn.workflowmanager.config.msclient;

import it.pagopa.pn.deliverypushworkflow.generated.openapi.msclient.paperchannel.ApiClient;
import it.pagopa.pn.deliverypushworkflow.generated.openapi.msclient.paperchannel.api.PaperMessagesApi;
import it.pagopa.pn.workflowmanager.config.PnWorkflowManagerConfigs;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.client.RestTemplate;

@Configuration
public class PaperMessagesApiConfigurator {
@Bean
@Primary
public PaperMessagesApi paperMessagesApi(@Qualifier("withTracing") RestTemplate restTemplate, PnWorkflowManagerConfigs cfg){
ApiClient newApiClient = new ApiClient(restTemplate);
newApiClient.setBasePath(cfg.getPaperMessagesClientBaseUrl());
return new PaperMessagesApi( newApiClient );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public class PhysicalAddressInt {
private String municipalityDetails;
private String province;
private String foreignState;

public enum ANALOG_TYPE{
REGISTERED_LETTER_890,
SIMPLE_REGISTERED_LETTER,
AR_REGISTERED_LETTER
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.pagopa.pn.workflowmanager.dto.ext.paperchannel;

import it.pagopa.pn.workflowmanager.dto.address.PhysicalAddressInt;
import it.pagopa.pn.workflowmanager.dto.ext.delivery.notification.NotificationInt;
import it.pagopa.pn.workflowmanager.dto.ext.delivery.notification.NotificationRecipientInt;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@Builder(toBuilder = true)
@EqualsAndHashCode
@AllArgsConstructor
public class PaperChannelPrepareRequest {
private final NotificationInt notificationInt;
private final NotificationRecipientInt recipientInt;
private final PhysicalAddressInt paAddress;
private final String requestId;
private final PhysicalAddressInt.ANALOG_TYPE analogType;
private final List<String> attachments;
private final String relatedRequestId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.pagopa.pn.workflowmanager.dto.ext.paperchannel;

import it.pagopa.pn.workflowmanager.dto.address.PhysicalAddressInt;
import it.pagopa.pn.workflowmanager.dto.ext.delivery.notification.NotificationInt;
import it.pagopa.pn.workflowmanager.dto.ext.delivery.notification.NotificationRecipientInt;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@AllArgsConstructor
@Builder
@EqualsAndHashCode
public class PaperChannelSendRequest {
private final NotificationInt notificationInt;
private final NotificationRecipientInt recipientInt;
private final PhysicalAddressInt receiverAddress;
private final String requestId;
private final String productType;
private final List<String> attachments;
private final PhysicalAddressInt arAddress;
private final PhysicalAddressInt senderAddress;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.pagopa.pn.workflowmanager.exceptions;

import it.pagopa.pn.commons.exceptions.PnRuntimeException;
import org.springframework.http.HttpStatus;

import static it.pagopa.pn.workflowmanager.exceptions.WorkflowManagerExceptionCodes.ERROR_CODE_WORKFLOWMANAGER_PAPERCHANNELSENDCOSTCHANGED;

public class PnPaperChannelChangedCostException extends PnRuntimeException {

public PnPaperChannelChangedCostException() {
this(null);
}

public PnPaperChannelChangedCostException(Throwable ex) {
super("Send cost is different from prepare, need to redo prepare", "Send cost is different from prepare, need to redo prepare", HttpStatus.UNPROCESSABLE_ENTITY.value(), ERROR_CODE_WORKFLOWMANAGER_PAPERCHANNELSENDCOSTCHANGED, null, null, ex);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class WorkflowManagerExceptionCodes extends PnExceptionsCodes {
public static final String ERROR_CODE_WORKFLOWMANAGER_ROUTER_HANDLER_NOT_FOUND = "PN_WORKFLOWMANAGER_ROUTER_NOT_FOUND";
public static final String ERROR_CODE_WORKFLOWMANAGER_HANDLEEVENTFAILED = "PN_WORKFLOWMANAGER_HANDLEEVENTFAILED";
public static final String ERROR_CODE_DELIVERYPUSH_ACTION_CONFLICT = "PN_ACTIONMANAGER_ERROR_CODE_ACTION_CONFLICT";
public static final String ERROR_CODE_WORKFLOWMANAGER_PAPERCHANNELSENDCOSTCHANGED = "PN_WORKFLOWMANAGER_PAPERCHANNELSENDCOSTCHANGED";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.pn.workflowmanager.middleware.externalclient.pnclient.paperchannel;

import it.pagopa.pn.deliverypushworkflow.generated.openapi.msclient.paperchannel.model.SendResponse;
import it.pagopa.pn.workflowmanager.dto.ext.paperchannel.PaperChannelPrepareRequest;
import it.pagopa.pn.workflowmanager.dto.ext.paperchannel.PaperChannelSendRequest;

public interface PaperMessagesClient {
String CLIENT_ID = "pn-workflow-manager";
String CLIENT_NAME = "pn-paper-messages";
String PREPARE_ANALOG_NOTIFICATION = "PREPARE ANALOG NOTIFICATION";
String SEND_ANALOG_NOTIFICATION = "SEND ANALOG NOTIFICATION";
String PRINT_TYPE_BN_FRONTE_RETRO = "BN_FRONTE_RETRO";

void prepare(PaperChannelPrepareRequest paperChannelPrepareRequest);
SendResponse send(PaperChannelSendRequest paperChannelSendRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package it.pagopa.pn.workflowmanager.middleware.externalclient.pnclient.paperchannel;

import it.pagopa.pn.commons.exceptions.PnHttpResponseException;
import it.pagopa.pn.commons.utils.LogUtils;
import it.pagopa.pn.deliverypushworkflow.generated.openapi.msclient.paperchannel.api.PaperMessagesApi;
import it.pagopa.pn.deliverypushworkflow.generated.openapi.msclient.paperchannel.model.*;
import it.pagopa.pn.workflowmanager.config.PnWorkflowManagerConfigs;
import it.pagopa.pn.workflowmanager.dto.address.PhysicalAddressInt;
import it.pagopa.pn.workflowmanager.dto.ext.paperchannel.PaperChannelPrepareRequest;
import it.pagopa.pn.workflowmanager.dto.ext.paperchannel.PaperChannelSendRequest;
import it.pagopa.pn.workflowmanager.exceptions.PnPaperChannelChangedCostException;
import lombok.CustomLog;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import java.time.Instant;

@CustomLog
@RequiredArgsConstructor
@Component
public class PaperMessagesClientImpl implements PaperMessagesClient {
private final PaperMessagesApi paperMessagesApi;
private final PnWorkflowManagerConfigs cfg;

@Override
public void prepare(PaperChannelPrepareRequest paperChannelPrepareRequest) {
log.logInvokingAsyncExternalService(CLIENT_NAME, PREPARE_ANALOG_NOTIFICATION, paperChannelPrepareRequest.getRequestId());
log.debug("[enter] prepare iun={} address={} recipient={} requestId={} attachments={} relatedRequestId={}", paperChannelPrepareRequest.getNotificationInt().getIun(), LogUtils.maskGeneric(paperChannelPrepareRequest.getPaAddress()==null?"null":paperChannelPrepareRequest.getPaAddress().getAddress()), LogUtils.maskGeneric(paperChannelPrepareRequest.getRecipientInt().getDenomination()), paperChannelPrepareRequest.getRequestId(), paperChannelPrepareRequest.getAttachments(), paperChannelPrepareRequest.getRelatedRequestId());

//TODO rivedere campi necessari per notifiche bonarie
PrepareRequest prepareRequest = new PrepareRequest();
prepareRequest.setRequestId(paperChannelPrepareRequest.getRequestId());
prepareRequest.setIun(paperChannelPrepareRequest.getNotificationInt().getIun());
prepareRequest.setPrintType(PRINT_TYPE_BN_FRONTE_RETRO);
prepareRequest.setProposalProductType(getProductType(paperChannelPrepareRequest.getAnalogType()));
prepareRequest.setReceiverAddress(mapInternalToExternal(paperChannelPrepareRequest.getPaAddress()));
prepareRequest.setAttachmentUrls(paperChannelPrepareRequest.getAttachments());
prepareRequest.setReceiverFiscalCode(paperChannelPrepareRequest.getRecipientInt().getTaxId());
prepareRequest.setReceiverType(paperChannelPrepareRequest.getRecipientInt().getRecipientType().getValue());
prepareRequest.setNotificationSentAt(paperChannelPrepareRequest.getNotificationInt().getSentAt());
prepareRequest.setSenderPaId(paperChannelPrepareRequest.getNotificationInt().getSender().getPaId());
//prepareRequest.setSenderPriority(paperChannelPrepareRequest.getNotificationInt().getSender().getPhysicalCommunicationPriority());
prepareRequest.setRelatedRequestId(paperChannelPrepareRequest.getRelatedRequestId());
//prepareRequest.setDiscoveredAddress(mapInternalToExternal(paperChannelPrepareRequest.getDiscoveredAddress()));
//prepareRequest.setAarWithRadd(paperChannelPrepareRequest.getAarWithRadd());

paperMessagesApi.sendPaperPrepareRequest(paperChannelPrepareRequest.getRequestId(), prepareRequest, CLIENT_ID);

log.debug("[exit] prepare iun={} address={} recipient={} requestId={} attachments={} relatedRequestId={}",
paperChannelPrepareRequest.getNotificationInt().getIun(), LogUtils.maskGeneric(paperChannelPrepareRequest.getPaAddress()==null?"null":paperChannelPrepareRequest.getPaAddress().getAddress()), LogUtils.maskGeneric(paperChannelPrepareRequest.getRecipientInt().getDenomination()), paperChannelPrepareRequest.getRequestId(), paperChannelPrepareRequest.getAttachments(), paperChannelPrepareRequest.getRelatedRequestId());
}

@Override
public SendResponse send(PaperChannelSendRequest paperChannelSendRequest) {
try {
log.logInvokingAsyncExternalService(CLIENT_NAME, SEND_ANALOG_NOTIFICATION, paperChannelSendRequest.getRequestId());
log.debug("[enter] send iun={} address={} recipient={} requestId={} attachments={}", paperChannelSendRequest.getNotificationInt().getIun(), LogUtils.maskGeneric(paperChannelSendRequest.getReceiverAddress().getAddress()), LogUtils.maskGeneric(paperChannelSendRequest.getRecipientInt().getDenomination()), paperChannelSendRequest.getRequestId(), paperChannelSendRequest.getAttachments());

//TODO rivedere campi necessari per notifiche bonarie
SendRequest sendRequest = new SendRequest();
sendRequest.setIun(paperChannelSendRequest.getNotificationInt().getIun());
sendRequest.setRequestId(paperChannelSendRequest.getRequestId());
sendRequest.setPrintType(PRINT_TYPE_BN_FRONTE_RETRO);
sendRequest.setProductType(ProductTypeEnum.fromValue(paperChannelSendRequest.getProductType()));
sendRequest.setReceiverAddress(mapInternalToExternal(paperChannelSendRequest.getReceiverAddress()));
sendRequest.setAttachmentUrls(paperChannelSendRequest.getAttachments());
sendRequest.setReceiverFiscalCode(paperChannelSendRequest.getRecipientInt().getTaxId());
sendRequest.setReceiverType(paperChannelSendRequest.getRecipientInt().getRecipientType().getValue());
sendRequest.setArAddress(mapInternalToExternal(paperChannelSendRequest.getArAddress()));
sendRequest.setSenderAddress(mapInternalToExternal(paperChannelSendRequest.getSenderAddress()));
sendRequest.setRequestPaId(paperChannelSendRequest.getNotificationInt().getSender().getPaTaxId());
sendRequest.setClientRequestTimeStamp(Instant.now());

SendResponse response = paperMessagesApi.sendPaperSendRequest(paperChannelSendRequest.getRequestId(), sendRequest);
log.debug("[exit] send iun={} address={} recipient={} requestId={} attachments={} amount={}", paperChannelSendRequest.getNotificationInt().getIun(), LogUtils.maskGeneric(paperChannelSendRequest.getReceiverAddress().getAddress()), LogUtils.maskGeneric(paperChannelSendRequest.getRecipientInt().getDenomination()), paperChannelSendRequest.getRequestId(), paperChannelSendRequest.getAttachments(), response.getAmount());
return response;
} catch (PnHttpResponseException e) {
if (e.getStatusCode() == HttpStatus.UNPROCESSABLE_ENTITY.value()) {
log.error("received unprocessable from paper-channel, it means that send cost is different from prepare, and need to recompute prepare", e);
throw new PnPaperChannelChangedCostException(e);
} else {
throw e;
}
}
}

private AnalogAddress mapInternalToExternal(PhysicalAddressInt physicalAddress){
if (physicalAddress == null)
return null;

AnalogAddress analogAddress = new AnalogAddress();
analogAddress.setFullname(physicalAddress.getFullname());
analogAddress.setNameRow2(physicalAddress.getAt());
analogAddress.setAddress(physicalAddress.getAddress());
analogAddress.setAddressRow2(physicalAddress.getAddressDetails());
analogAddress.setCap(physicalAddress.getZip());
analogAddress.setCity(physicalAddress.getMunicipality());
analogAddress.setCity2(physicalAddress.getMunicipalityDetails());
analogAddress.setCountry(physicalAddress.getForeignState());
analogAddress.setPr(physicalAddress.getProvince());
return analogAddress;
}

private ProposalTypeEnum getProductType(PhysicalAddressInt.ANALOG_TYPE serviceLevelType)
{
return switch (serviceLevelType) {
case REGISTERED_LETTER_890 -> ProposalTypeEnum._890;
case AR_REGISTERED_LETTER -> ProposalTypeEnum.AR;
case SIMPLE_REGISTERED_LETTER -> ProposalTypeEnum.RS;
};
}

}
Loading
Loading