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

[SELC-6241] SAP: set Origin = SELC if not IPA #652

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.onboarding.utils;

import it.pagopa.selfcare.onboarding.common.Origin;
import it.pagopa.selfcare.onboarding.common.PricingPlan;
import it.pagopa.selfcare.onboarding.common.ProductId;
import it.pagopa.selfcare.onboarding.config.NotificationConfig;
Expand All @@ -21,56 +22,60 @@
import java.util.UUID;

public class SapNotificationBuilder extends BaseNotificationBuilder
implements NotificationUserBuilder {
implements NotificationUserBuilder {
private final UoApi proxyRegistryUoApi;
private final AooApi proxyRegistryAooApi;

public SapNotificationBuilder(
String alternativeEmail,
NotificationConfig.Consumer consumer,
InstitutionApi proxyRegistryInstitutionApi,
GeographicTaxonomiesApi geographicTaxonomiesApi,
org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi,
UoApi proxyRegistryUoApi,
AooApi proxyRegistryAooApi) {
String alternativeEmail,
NotificationConfig.Consumer consumer,
InstitutionApi proxyRegistryInstitutionApi,
GeographicTaxonomiesApi geographicTaxonomiesApi,
org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi,
UoApi proxyRegistryUoApi,
AooApi proxyRegistryAooApi) {
super(
alternativeEmail,
consumer,
proxyRegistryInstitutionApi,
geographicTaxonomiesApi,
coreInstitutionApi);
alternativeEmail,
consumer,
proxyRegistryInstitutionApi,
geographicTaxonomiesApi,
coreInstitutionApi);
this.proxyRegistryUoApi = proxyRegistryUoApi;
this.proxyRegistryAooApi = proxyRegistryAooApi;
}

@Override
public NotificationToSend buildNotificationToSend(
Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) {
Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) {
NotificationToSend notificationToSend =
super.buildNotificationToSend(onboarding, token, institution, queueEvent);
super.buildNotificationToSend(onboarding, token, institution, queueEvent);
notificationToSend.setId(UUID.randomUUID().toString());
notificationToSend.setInstitutionId(institution.getId());
notificationToSend.setType(NotificationType.getNotificationTypeFromQueueEvent(queueEvent));
setNotificationToSendInstitutionDescription(notificationToSend);
notificationToSend.getInstitution().setFileName(notificationToSend.getFileName());
notificationToSend.getInstitution().setContentType(notificationToSend.getContentType());
if (Objects.nonNull(onboarding.getBilling())
&& Objects.nonNull(onboarding.getBilling().getTaxCodeInvoicing())) {
&& Objects.nonNull(onboarding.getBilling().getTaxCodeInvoicing())) {
// If there is tax code invoicing in billing, set it as taxCode in the institution
notificationToSend.getInstitution().setTaxCode(onboarding.getBilling().getTaxCodeInvoicing());
}
// set Origin = SELC if not IPA
if (!notificationToSend.getInstitution().getOrigin().equals(Origin.IPA.getValue())) {
notificationToSend.getInstitution().setOrigin(Origin.SELC.getValue());
}
return notificationToSend;
}

private static void setNotificationToSendInstitutionDescription(
NotificationToSend notificationToSend) {
NotificationToSend notificationToSend) {
if (notificationToSend.getInstitution().getRootParent() != null) {
notificationToSend
.getInstitution()
.setDescription(
notificationToSend.getInstitution().getRootParent().getDescription()
+ " - "
+ notificationToSend.getInstitution().getDescription());
.getInstitution()
.setDescription(
notificationToSend.getInstitution().getRootParent().getDescription()
+ " - "
+ notificationToSend.getInstitution().getDescription());
}
}

Expand All @@ -87,7 +92,7 @@ public BillingToSend retrieveBilling(Onboarding onboarding) {

@Override
public InstitutionToNotify retrieveInstitution(
InstitutionResponse institution, Onboarding onboarding) {
InstitutionResponse institution, Onboarding onboarding) {
InstitutionToNotify institutionToNotify = super.retrieveInstitution(institution, onboarding);

// Field not allowed in SAP schema
Expand All @@ -102,51 +107,51 @@ public void retrieveAndSetGeographicData(InstitutionToNotify institutionToNotify
switch (Objects.requireNonNull(institutionToNotify.getSubUnitType())) {
case "UO" -> {
UOResource organizationUnit =
proxyRegistryUoApi.findByUnicodeUsingGET1(institutionToNotify.getSubUnitCode(), null);
proxyRegistryUoApi.findByUnicodeUsingGET1(institutionToNotify.getSubUnitCode(), null);
institutionToNotify.setIstatCode(organizationUnit.getCodiceComuneISTAT());
geographicTaxonomies =
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(
organizationUnit.getCodiceComuneISTAT());
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(
organizationUnit.getCodiceComuneISTAT());
}
case "AOO" -> {
AOOResource homogeneousOrganizationalArea =
proxyRegistryAooApi.findByUnicodeUsingGET(institutionToNotify.getSubUnitCode(), null);
proxyRegistryAooApi.findByUnicodeUsingGET(institutionToNotify.getSubUnitCode(), null);
institutionToNotify.setIstatCode(homogeneousOrganizationalArea.getCodiceComuneISTAT());
geographicTaxonomies =
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(
homogeneousOrganizationalArea.getCodiceComuneISTAT());
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(
homogeneousOrganizationalArea.getCodiceComuneISTAT());
}
default -> {
InstitutionResource proxyInfo =
proxyRegistryInstitutionApi.findInstitutionUsingGET(
institutionToNotify.getTaxCode(), null, null);
proxyRegistryInstitutionApi.findInstitutionUsingGET(
institutionToNotify.getTaxCode(), null, null);
institutionToNotify.setIstatCode(proxyInfo.getIstatCode());
geographicTaxonomies =
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(proxyInfo.getIstatCode());
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(proxyInfo.getIstatCode());
}
}
} else {
InstitutionResource proxyInfo =
proxyRegistryInstitutionApi.findInstitutionUsingGET(
institutionToNotify.getTaxCode(), null, null);
proxyRegistryInstitutionApi.findInstitutionUsingGET(
institutionToNotify.getTaxCode(), null, null);
institutionToNotify.setIstatCode(proxyInfo.getIstatCode());
geographicTaxonomies =
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(proxyInfo.getIstatCode());
geographicTaxonomiesApi.retrieveGeoTaxonomiesByCodeUsingGET(proxyInfo.getIstatCode());
}

if (geographicTaxonomies != null) {
institutionToNotify.setCounty(geographicTaxonomies.getProvinceAbbreviation());
institutionToNotify.setCountry(geographicTaxonomies.getCountryAbbreviation());
institutionToNotify.setCity(
geographicTaxonomies.getDesc().replace(DESCRIPTION_TO_REPLACE_REGEX, ""));
geographicTaxonomies.getDesc().replace(DESCRIPTION_TO_REPLACE_REGEX, ""));
}
}

@Override
public boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) {
return isProductAllowed(onboarding)
&& isAllowedInstitutionType(institution)
&& isAllowedOrigin(institution.getOrigin());
&& isAllowedInstitutionType(institution)
&& isAllowedOrigin(institution.getOrigin());
}

private boolean isProductAllowed(Onboarding onboarding) {
Expand All @@ -158,7 +163,7 @@ private boolean isProductAllowed(Onboarding onboarding) {

private boolean isAllowedInstitutionType(InstitutionResponse institution) {
return isNullOrEmpty(consumer.allowedInstitutionTypes())
|| consumer.allowedInstitutionTypes().contains(institution.getInstitutionType());
|| consumer.allowedInstitutionTypes().contains(institution.getInstitutionType());
}

private boolean isAllowedOrigin(String origin) {
Expand All @@ -171,15 +176,15 @@ private boolean isNullOrEmpty(Set<String> set) {

@Override
public NotificationUserToSend buildUserNotificationToSend(
Onboarding onboarding,
Token token,
InstitutionResponse institution,
String createdAt,
String updatedAt,
String status,
String userId,
String partyRole,
String productRole) {
Onboarding onboarding,
Token token,
InstitutionResponse institution,
String createdAt,
String updatedAt,
String status,
String userId,
String partyRole,
String productRole) {
return null;
}
}
Loading