Skip to content

Commit

Permalink
Merge branch 'main' into feature/SELC-5816
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarcoplutino committed Nov 12, 2024
2 parents 4a54947 + 706c8bc commit 0bb7c0b
Show file tree
Hide file tree
Showing 6 changed files with 531 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.OnboardingStatus;
import it.pagopa.selfcare.onboarding.common.Origin;
import it.pagopa.selfcare.onboarding.common.WorkflowType;
import it.pagopa.selfcare.onboarding.config.NotificationConfig;
import it.pagopa.selfcare.onboarding.dto.*;
import it.pagopa.selfcare.onboarding.entity.Billing;
Expand Down Expand Up @@ -50,20 +51,21 @@ public BaseNotificationBuilder(
this.coreInstitutionApi = coreInstitutionApi;
}

public NotificationToSend buildNotificationToSend(
Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) {
NotificationToSend notificationToSend = new NotificationToSend();
if (queueEvent.equals(QueueEvent.ADD)) {
notificationToSend.setId(onboarding.getId());
} else {
notificationToSend.setId(UUID.randomUUID().toString());
}
notificationToSend.setState(convertOnboardingStatusToNotificationStatus(onboarding.getStatus()));
mapDataFromOnboarding(onboarding, notificationToSend, queueEvent);
notificationToSend.setInstitution(retrieveInstitution(institution));
if (Objects.nonNull(token)) {
setTokenData(notificationToSend, token);
}
public NotificationToSend buildNotificationToSend(
Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) {
NotificationToSend notificationToSend = new NotificationToSend();
if (queueEvent.equals(QueueEvent.ADD)) {
notificationToSend.setId(onboarding.getId());
} else {
notificationToSend.setId(UUID.randomUUID().toString());
}
notificationToSend.setState(
convertOnboardingStatusToNotificationStatus(onboarding.getStatus()));
mapDataFromOnboarding(onboarding, notificationToSend, queueEvent);
notificationToSend.setInstitution(retrieveInstitution(institution, onboarding));
if (Objects.nonNull(token)) {
setTokenData(notificationToSend, token);
}

return notificationToSend;
}
Expand Down Expand Up @@ -116,64 +118,80 @@ private String convertOnboardingStatusToNotificationStatus(OnboardingStatus stat
}
}

@Override
public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) {
InstitutionToNotify toNotify = new InstitutionToNotify();
toNotify.setInstitutionType(InstitutionType.valueOf(institution.getInstitutionType()));
toNotify.setDescription(institution.getDescription());
toNotify.setDigitalAddress(
institution.getDigitalAddress() == null
? alternativeEmail
: institution.getDigitalAddress());
toNotify.setAddress(institution.getAddress());
toNotify.setTaxCode(institution.getTaxCode());
toNotify.setOrigin(institution.getOrigin());
toNotify.setOriginId(institution.getOriginId());
toNotify.setZipCode(institution.getZipCode());
toNotify.setPaymentServiceProvider(toSetPaymentServiceProvider(institution.getPaymentServiceProvider()));
toNotify.setSupportEmail(institution.getSupportEmail());
if (institution.getSubunitType() != null && !"EC".equals(institution.getSubunitType())) {
toNotify.setSubUnitType(institution.getSubunitType());
toNotify.setSubUnitCode(institution.getSubunitCode());
}
RootParent rootParent = new RootParent();
if (Objects.nonNull(institution.getRootParent())) {
rootParent.setId(institution.getRootParent().getId());
rootParent.setDescription(institution.getRootParent().getDescription());
InstitutionResponse parentInstitution = coreInstitutionApi.retrieveInstitutionByIdUsingGET(rootParent.getId());
rootParent.setOriginId(Objects.nonNull(parentInstitution) ? parentInstitution.getOriginId() : null);
toNotify.setRootParent(rootParent);
}
if (Objects.nonNull(institution.getAttributes()) && !institution.getAttributes().isEmpty()) {
toNotify.setCategory(institution.getAttributes().get(0).getCode());
} else if (institution.getInstitutionType().equals(InstitutionType.GSP.name()) && institution.getOrigin().equals(Origin.SELC.name())) {
toNotify.setCategory("L37");
}
if (Objects.isNull(institution.getCity())
&& institution.getInstitutionType().equals(InstitutionRequest.InstitutionTypeEnum.PA.name())) {
retrieveAndSetGeographicData(toNotify);
} else {
toNotify.setCounty(institution.getCounty());
toNotify.setCountry(institution.getCountry());
toNotify.setIstatCode(institution.getIstatCode());
toNotify.setCity(institution.getCity().replace(DESCRIPTION_TO_REPLACE_REGEX, ""));
}
return toNotify;
@Override
public InstitutionToNotify retrieveInstitution(
InstitutionResponse institution, Onboarding onboarding) {
InstitutionToNotify toNotify = new InstitutionToNotify();
toNotify.setInstitutionType(InstitutionType.valueOf(institution.getInstitutionType()));
toNotify.setDescription(institution.getDescription());
toNotify.setDigitalAddress(
institution.getDigitalAddress() == null
? alternativeEmail
: institution.getDigitalAddress());
toNotify.setAddress(institution.getAddress());
toNotify.setTaxCode(institution.getTaxCode());
toNotify.setOrigin(institution.getOrigin());
toNotify.setOriginId(institution.getOriginId());
toNotify.setZipCode(institution.getZipCode());
toNotify.setPaymentServiceProvider(
toSetPaymentServiceProvider(institution.getPaymentServiceProvider(), onboarding));
if (institution.getSubunitType() != null && !"EC".equals(institution.getSubunitType())) {
toNotify.setSubUnitType(institution.getSubunitType());
toNotify.setSubUnitCode(institution.getSubunitCode());
}
RootParent rootParent = new RootParent();
if (Objects.nonNull(institution.getRootParent())) {
rootParent.setId(institution.getRootParent().getId());
rootParent.setDescription(institution.getRootParent().getDescription());
InstitutionResponse parentInstitution =
coreInstitutionApi.retrieveInstitutionByIdUsingGET(rootParent.getId());
rootParent.setOriginId(
Objects.nonNull(parentInstitution) ? parentInstitution.getOriginId() : null);
toNotify.setRootParent(rootParent);
}
if (Objects.nonNull(institution.getAttributes()) && !institution.getAttributes().isEmpty()) {
toNotify.setCategory(institution.getAttributes().get(0).getCode());
} else if (institution.getInstitutionType().equals(InstitutionType.GSP.name())
&& institution.getOrigin().equals(Origin.SELC.name())) {
toNotify.setCategory("L37");
}
if (Objects.isNull(institution.getCity())
&& institution
.getInstitutionType()
.equals(InstitutionRequest.InstitutionTypeEnum.PA.name())) {
retrieveAndSetGeographicData(toNotify);
} else {
toNotify.setCounty(institution.getCounty());
toNotify.setCountry(institution.getCountry());
toNotify.setIstatCode(institution.getIstatCode());
toNotify.setCity(institution.getCity().replace(DESCRIPTION_TO_REPLACE_REGEX, ""));
}
return toNotify;
}

private PaymentServiceProvider toSetPaymentServiceProvider(
PaymentServiceProviderResponse psp, Onboarding onboarding) {
PaymentServiceProvider paymentServiceProviderToNotify = new PaymentServiceProvider();
if (Objects.isNull(psp)) {
return null;
}

private PaymentServiceProvider toSetPaymentServiceProvider(PaymentServiceProviderResponse psp) {
PaymentServiceProvider paymentServiceProviderToNotify = new PaymentServiceProvider();
if (Objects.isNull(psp)) {
return null;
}

paymentServiceProviderToNotify.setAbiCode(psp.getAbiCode());
paymentServiceProviderToNotify.setBusinessRegisterNumber(psp.getBusinessRegisterNumber());
paymentServiceProviderToNotify.setLegalRegisterName(psp.getLegalRegisterName());
paymentServiceProviderToNotify.setLegalRegisterNumber(psp.getLegalRegisterNumber());
paymentServiceProviderToNotify.setVatNumberGroup(psp.getVatNumberGroup());
return paymentServiceProviderToNotify;
paymentServiceProviderToNotify.setAbiCode(psp.getAbiCode());
paymentServiceProviderToNotify.setBusinessRegisterNumber(psp.getBusinessRegisterNumber());
paymentServiceProviderToNotify.setLegalRegisterName(psp.getLegalRegisterName());
paymentServiceProviderToNotify.setLegalRegisterNumber(psp.getLegalRegisterNumber());
paymentServiceProviderToNotify.setVatNumberGroup(psp.getVatNumberGroup());
if (InstitutionType.PSP.equals(onboarding.getInstitution().getInstitutionType())
&& WorkflowType.IMPORT.equals(onboarding.getWorkflowType())) {
paymentServiceProviderToNotify.setProviderNames(
onboarding.getInstitution().getPaymentServiceProvider().getProviderNames());
paymentServiceProviderToNotify.setContractId(
onboarding.getInstitution().getPaymentServiceProvider().getContractId());
paymentServiceProviderToNotify.setContractType(
onboarding.getInstitution().getPaymentServiceProvider().getContractType());
}
return paymentServiceProviderToNotify;
}

@Override
public void retrieveAndSetGeographicData(InstitutionToNotify institution) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.pagopa.selfcare.onboarding.utils;

import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.config.NotificationConfig;
import it.pagopa.selfcare.onboarding.dto.*;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
Expand All @@ -9,81 +8,99 @@
import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi;
import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class FdNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder {
public FdNotificationBuilder(
String alternativeEmail,
NotificationConfig.Consumer consumer,
InstitutionApi proxyRegistryInstitutionApi,
GeographicTaxonomiesApi geographicTaxonomiesApi,
org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi
) {
super(alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi);
}

@Override
public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) {
NotificationToSend notificationToSend = super.buildNotificationToSend(onboarding, token, institution, queueEvent);
notificationToSend.setId(UUID.randomUUID().toString());
notificationToSend.setInstitutionId(institution.getId());
notificationToSend.setType(NotificationType.getNotificationTypeFromQueueEvent(queueEvent));
notificationToSend.getInstitution().setFileName(notificationToSend.getFileName());
notificationToSend.getInstitution().setContentType(notificationToSend.getContentType());
return notificationToSend;
}
public class FdNotificationBuilder extends BaseNotificationBuilder
implements NotificationUserBuilder {
public FdNotificationBuilder(
String alternativeEmail,
NotificationConfig.Consumer consumer,
InstitutionApi proxyRegistryInstitutionApi,
GeographicTaxonomiesApi geographicTaxonomiesApi,
org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi) {
super(
alternativeEmail,
consumer,
proxyRegistryInstitutionApi,
geographicTaxonomiesApi,
coreInstitutionApi);
}

@Override
public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) {
InstitutionToNotify institutionToNotify = super.retrieveInstitution(institution);
@Override
public NotificationToSend buildNotificationToSend(
Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) {
NotificationToSend notificationToSend =
super.buildNotificationToSend(onboarding, token, institution, queueEvent);
notificationToSend.setId(UUID.randomUUID().toString());
notificationToSend.setInstitutionId(institution.getId());
notificationToSend.setType(NotificationType.getNotificationTypeFromQueueEvent(queueEvent));
notificationToSend.getInstitution().setFileName(notificationToSend.getFileName());
notificationToSend.getInstitution().setContentType(notificationToSend.getContentType());
return notificationToSend;
}

// Field not allowed in FD schema
institutionToNotify.setCategory(null);
return institutionToNotify;
}
@Override
public InstitutionToNotify retrieveInstitution(
InstitutionResponse institution, Onboarding onboarding) {
InstitutionToNotify institutionToNotify = super.retrieveInstitution(institution, onboarding);

@Override
public BillingToSend retrieveBilling(Onboarding onboarding) {
if (Objects.isNull(onboarding.getBilling())) {
return null;
}
// Field not allowed in FD schema
institutionToNotify.setCategory(null);
return institutionToNotify;
}

BillingToSend billing = super.retrieveBilling(onboarding);
billing.setPublicService(onboarding.getBilling().isPublicServices());
return billing;
@Override
public BillingToSend retrieveBilling(Onboarding onboarding) {
if (Objects.isNull(onboarding.getBilling())) {
return null;
}

@Override
public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution,
String createdAt, String updatedAt, String status,
String userId, String partyRole, String productRole) {
NotificationToSend notification = buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE);
NotificationUserToSend notificationUserToSend = new NotificationUserToSend();
notificationUserToSend.setId(notification.getId());
notificationUserToSend.setInstitutionId(notification.getInstitutionId());
notificationUserToSend.setProduct(notification.getProduct());
notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId());
notificationUserToSend.setCreatedAt(createdAt.endsWith("Z") ? createdAt : createdAt + "Z");
notificationUserToSend.setUpdatedAt(updatedAt.endsWith("Z") ? createdAt : createdAt + "Z");
QueueUserEvent queueUserEvent = switch (status) {
case "DELETE" -> QueueUserEvent.DELETE_USER;
case "SUSPEND" -> QueueUserEvent.SUSPEND_USER;
default -> QueueUserEvent.ACTIVE_USER;
BillingToSend billing = super.retrieveBilling(onboarding);
billing.setPublicService(onboarding.getBilling().isPublicServices());
return billing;
}

@Override
public NotificationUserToSend buildUserNotificationToSend(
Onboarding onboarding,
Token token,
InstitutionResponse institution,
String createdAt,
String updatedAt,
String status,
String userId,
String partyRole,
String productRole) {
NotificationToSend notification =
buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE);
NotificationUserToSend notificationUserToSend = new NotificationUserToSend();
notificationUserToSend.setId(notification.getId());
notificationUserToSend.setInstitutionId(notification.getInstitutionId());
notificationUserToSend.setProduct(notification.getProduct());
notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId());
notificationUserToSend.setCreatedAt(createdAt.endsWith("Z") ? createdAt : createdAt + "Z");
notificationUserToSend.setUpdatedAt(updatedAt.endsWith("Z") ? createdAt : createdAt + "Z");
QueueUserEvent queueUserEvent =
switch (status) {
case "DELETE" -> QueueUserEvent.DELETE_USER;
case "SUSPEND" -> QueueUserEvent.SUSPEND_USER;
default -> QueueUserEvent.ACTIVE_USER;
};
notificationUserToSend.setType(NotificationUserType.getNotificationTypeFromQueueEvent(queueUserEvent));
UserToNotify user = new UserToNotify();
user.setUserId(userId);
user.setRole(partyRole);
user.setRoles(List.of(productRole));
notificationUserToSend.setUser(user);
return notificationUserToSend;
}
notificationUserToSend.setType(
NotificationUserType.getNotificationTypeFromQueueEvent(queueUserEvent));
UserToNotify user = new UserToNotify();
user.setUserId(userId);
user.setRole(partyRole);
user.setRoles(List.of(productRole));
notificationUserToSend.setUser(user);
return notificationUserToSend;
}

@Override
public boolean shouldSendUserNotification(Onboarding onboarding, InstitutionResponse institution) {
return true;
}
@Override
public boolean shouldSendUserNotification(
Onboarding onboarding, InstitutionResponse institution) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
import org.openapi.quarkus.core_json.model.InstitutionResponse;

public interface NotificationBuilder {
NotificationToSend buildNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent);
default boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) {
return true;
}
InstitutionToNotify retrieveInstitution(InstitutionResponse institution);
void setTokenData(NotificationToSend notificationToSend, Token token);
void retrieveAndSetGeographicData(InstitutionToNotify institution);
BillingToSend retrieveBilling(Onboarding onboarding);
NotificationToSend buildNotificationToSend(
Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent);

default boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) {
return true;
}

InstitutionToNotify retrieveInstitution(InstitutionResponse institution, Onboarding onboarding);

void setTokenData(NotificationToSend notificationToSend, Token token);

void retrieveAndSetGeographicData(InstitutionToNotify institution);

BillingToSend retrieveBilling(Onboarding onboarding);
}
Loading

0 comments on commit 0bb7c0b

Please sign in to comment.