Skip to content

Commit

Permalink
[SELC-5693] feat: Added mapping of values for contract PRV
Browse files Browse the repository at this point in the history
  • Loading branch information
giampieroferrara authored Oct 4, 2024
1 parent 8fc4798 commit efc77ac
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ private File createPdfFileContract(String contractTemplatePath, Onboarding onboa
if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId) &&
InstitutionType.PSP == institution.getInstitutionType()) {
setupPSPData(data, manager, onboarding);
} else if(PROD_PAGOPA.getValue().equalsIgnoreCase(productId) &&
} else if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId) &&
InstitutionType.PRV == institution.getInstitutionType()) {
setupPRVData(data, onboarding);
} else if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId) &&
InstitutionType.PSP != institution.getInstitutionType()
&& InstitutionType.PT != institution.getInstitutionType()) {
setECData(data, onboarding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.pagopa.selfcare.onboarding.common.PricingPlan;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.exception.GenericOnboardingException;
import org.apache.commons.lang3.StringUtils;
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring;
import org.openapi.quarkus.user_registry_json.model.UserResource;

Expand All @@ -29,6 +30,7 @@ public class PdfMapper {
public static final String PRICING_PLAN = "pricingPlan";
public static final String INSTITUTION_REGISTER_LABEL_VALUE = "institutionRegisterLabelValue";
public static final String ORIGIN_ID_LABEL = "<li class=\"c19 c39 li-bullet-0\"><span class=\"c1\">codice di iscrizione all&rsquo;Indice delle Pubbliche Amministrazioni e dei gestori di pubblici servizi (I.P.A.) <span class=\"c3\">${originId}</span> </span><span class=\"c1\"></span></li>";
public static final String INSTITUTION_RECIPIENT_CODE = "institutionRecipientCode";

private PdfMapper() {
}
Expand Down Expand Up @@ -115,6 +117,7 @@ public static void setupPSPData(Map<String, Object> map, UserResource validManag
.findFirst()
.map(userMailUuid -> getMailManager(validManager, userMailUuid))
.ifPresent(mail -> map.put("managerPEC", mail));

}

public static void setECData(Map<String, Object> map, Onboarding onboarding) {
Expand All @@ -124,6 +127,16 @@ public static void setECData(Map<String, Object> map, Onboarding onboarding) {
map.put(INSTITUTION_BUSINESS_REGISTER_PLACE, Optional.ofNullable(institution.getBusinessRegisterPlace()).orElse(UNDERSCORE));
}

public static void setupPRVData(Map<String, Object> map, Onboarding onboarding) {
addInstitutionRegisterLabelValue(onboarding.getInstitution(), map);

if (onboarding.getBilling() != null) {
map.put(INSTITUTION_RECIPIENT_CODE, Optional.ofNullable(onboarding.getBilling().getRecipientCode()).orElse(UNDERSCORE));
}

setECData(map, onboarding);
}

public static void setupProdIOData(Onboarding onboarding, Map<String, Object> map, UserResource validManager) {
final Institution institution = onboarding.getInstitution();
final InstitutionType institutionType = institution.getInstitutionType();
Expand All @@ -135,7 +148,7 @@ public static void setupProdIOData(Onboarding onboarding, Map<String, Object> ma

addInstitutionRegisterLabelValue(institution, map);
if (onboarding.getBilling() != null) {
map.put("institutionRecipientCode",onboarding.getBilling().getRecipientCode());
map.put(INSTITUTION_RECIPIENT_CODE,onboarding.getBilling().getRecipientCode());
}

map.put("GPSinstitutionName", InstitutionType.GSP == institutionType ? institution.getDescription() : UNDERSCORE);
Expand Down Expand Up @@ -164,7 +177,7 @@ public static void setupProdPNData(Map<String, Object> map, Institution institut

addInstitutionRegisterLabelValue(institution, map);
if (billing != null) {
map.put("institutionRecipientCode", billing.getRecipientCode());
map.put(INSTITUTION_RECIPIENT_CODE, billing.getRecipientCode());
}
}

Expand All @@ -188,13 +201,17 @@ private static void addPricingPlan(String pricingPlan, Map<String, Object> map)
}

private static void addInstitutionRegisterLabelValue(Institution institution, Map<String, Object> map) {
if (institution.getPaymentServiceProvider() != null
&& Objects.nonNull(institution.getPaymentServiceProvider().getBusinessRegisterNumber())) {
map.put("number", institution.getPaymentServiceProvider().getBusinessRegisterNumber());
map.put(INSTITUTION_REGISTER_LABEL_VALUE, "<li class=\"c19 c39 li-bullet-0\"><span class=\"c1\">codice di iscrizione all&rsquo;Indice delle Pubbliche Amministrazioni e dei gestori di pubblici servizi (I.P.A.) <span class=\"c3\">${number}</span> </span><span class=\"c1\"></span></li>\n");
} else {
map.put(INSTITUTION_REGISTER_LABEL_VALUE, "");
String businessRegisterNumber = StringUtils.EMPTY;
String businessRegisterNumberLabel = StringUtils.EMPTY;

if (institution.getPaymentServiceProvider() != null) {
businessRegisterNumber = Optional.ofNullable(institution.getPaymentServiceProvider().getBusinessRegisterNumber()).orElse(StringUtils.EMPTY);
businessRegisterNumberLabel = "<li class=\"c19 c39 li-bullet-0\"><span class=\"c1\">codice di iscrizione all&rsquo;Indice delle Pubbliche Amministrazioni e dei gestori di pubblici servizi (I.P.A.) <span class=\"c3\">${number}</span> </span><span class=\"c1\"></span></li>\n";
}

map.put("number", businessRegisterNumber);
map.put(INSTITUTION_REGISTER_LABEL_VALUE, businessRegisterNumberLabel);

}

private static void decodePricingPlan(String pricingPlan, String productId, Map<String, Object> map) {
Expand Down Expand Up @@ -265,4 +282,5 @@ private static String delegatesToText(List<UserResource> userResources, List<Use
private static String getStringValue(CertifiableFieldResourceOfstring resourceOfString) {
return Optional.ofNullable(resourceOfString).map(CertifiableFieldResourceOfstring::getValue).orElse("");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,33 @@ void uploadCsvAggregates() throws IOException {

Mockito.verify(azureBlobClient, times(1))
.uploadFile(any(), any(), any());

}

@Test
void createContractPRV() {
// given
String contractFilepath = "contract";
String contractHtml = "contract";

Onboarding onboarding = createOnboarding();
User userManager = onboarding.getUsers().get(0);
UserResource manager = createDummyUserResource(userManager.getId(), userManager.getUserMailUuid());
onboarding.getInstitution().setInstitutionType(InstitutionType.PRV);
onboarding.setProductId("prod-pagopa");

Mockito.when(azureBlobClient.getFileAsText(contractFilepath)).thenReturn(contractHtml);
Mockito.when(azureBlobClient.uploadFile(any(), any(), any())).thenReturn(contractHtml);

// when
File result = contractService.createContractPDF(contractFilepath, onboarding, manager, List.of(), PRODUCT_NAME_EXAMPLE, PDF_FORMAT_FILENAME);

// then
assertNotNull(result);
Mockito.verify(azureBlobClient, Mockito.times(1)).
getFileAsText(contractFilepath);
Mockito.verify(azureBlobClient, Mockito.times(1)).uploadFile(any(), any(), any());
Mockito.verifyNoMoreInteractions(azureBlobClient);
}

}

0 comments on commit efc77ac

Please sign in to comment.