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-6144] feat: mapping placeholders in send aggregates contract #670

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -307,26 +307,23 @@ private File createPdfFileContract(
String contractTemplateText = azureBlobClient.getFileAsText(contractTemplatePath);
// Create a temporary PDF file to store the contract.
Path temporaryPdfFile = Files.createTempFile(builder, ".pdf");
// Setting baseUrl used to construct aggregates csv url
String baseUrl = templatePlaceholdersConfig.rejectOnboardingUrlValue();
// Prepare common data for the contract document.
Map<String, Object> data = setUpCommonData(manager, users, onboarding);

StringBuilder baseUrl =
new StringBuilder(templatePlaceholdersConfig.rejectOnboardingUrlValue());

Map<String, Object> data = setUpCommonData(manager, users, onboarding, baseUrl);
// Customize data based on the product and institution type.
if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId)
&& InstitutionType.PSP == institution.getInstitutionType()) {
setupPSPData(data, manager, onboarding);
} else if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId)
&& InstitutionType.PRV == institution.getInstitutionType() || InstitutionType.GPU == institution.getInstitutionType()) {
setupPRVData(data, onboarding, baseUrl.toString(), users);
setupPRVData(data, onboarding, users);
} else if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId)
&& InstitutionType.PSP != institution.getInstitutionType()
&& InstitutionType.PT != institution.getInstitutionType()) {
setECData(data, onboarding);
} else if (PROD_IO.getValue().equalsIgnoreCase(productId)) {
setupProdIODataAggregates(onboarding, data, manager, baseUrl.toString());
} else if (PROD_IO_PREMIUM.getValue().equalsIgnoreCase(productId)
} else if (PROD_IO.getValue().equalsIgnoreCase(productId)
|| PROD_IO_PREMIUM.getValue().equalsIgnoreCase(productId)
|| PROD_IO_SIGN.getValue().equalsIgnoreCase(productId)) {
setupProdIOData(onboarding, data, manager);
} else if (PROD_PN.getValue().equalsIgnoreCase(productId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package it.pagopa.selfcare.onboarding.utils;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO;
import static it.pagopa.selfcare.onboarding.utils.GenericError.MANAGER_EMAIL_NOT_FOUND;

import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.Origin;
import it.pagopa.selfcare.onboarding.common.PricingPlan;
import it.pagopa.selfcare.onboarding.entity.Billing;
import it.pagopa.selfcare.onboarding.entity.GeographicTaxonomy;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.User;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.exception.GenericOnboardingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring;
import org.openapi.quarkus.user_registry_json.model.UserResource;

import java.util.*;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_PN;
import static it.pagopa.selfcare.onboarding.utils.GenericError.MANAGER_EMAIL_NOT_FOUND;

public class PdfMapper {

private static final String UNDERSCORE = "_______________";
Expand All @@ -42,14 +35,15 @@ public class PdfMapper {
"<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 CSV_AGGREGATES_LABEL =
"&emsp;- <span class=\"c3\" style=\"color:blue\"><a class=\"c15\" href=\"%s\"><u>%s</u></a></span>";
public static final String CSV_AGGREGATES_TEXT_PAGOPA = "Dati di Enti Aggregati";
public static final String CSV_AGGREGATES_LABEL_SEND = "<span class=\"c3\" style=\"color:blue\"><a class=\"c15\" href=\"%s\"><u>%s</u></a></span>";
public static final String CSV_AGGREGATES_TEXT = "Dati di Enti Aggregati";
public static final String CSV_AGGREGATES_TEXT_IO = "Dati degli Enti Aggregati_IO";
public static final String INSTITUTION_RECIPIENT_CODE = "institutionRecipientCode";

private PdfMapper() {}

public static Map<String, Object> setUpCommonData(
UserResource manager, List<UserResource> users, Onboarding onboarding) {
UserResource manager, List<UserResource> users, Onboarding onboarding, String baseUrl) {

Institution institution = onboarding.getInstitution();
Billing billing = onboarding.getBilling();
Expand Down Expand Up @@ -86,14 +80,18 @@ public static Map<String, Object> setUpCommonData(
map.put("institutionMail", institution.getDigitalAddress());
map.put("managerTaxCode", manager.getFiscalCode());
map.put("managerEmail", mailManager);
map.put("managerPhone", "_____________");
map.put("delegates", delegatesToText(users, onboarding.getUsers()));
map.put("delegatesSend", delegatesSendToText(users, onboarding.getUsers()));
map.put("institutionType", decodeInstitutionType(institution.getInstitutionType()));
map.put(
"institutionVatNumber",
Optional.ofNullable(billing).map(Billing::getVatNumber).orElse(UNDERSCORE));
map.put(
"taxCodeInvoicing",
Optional.ofNullable(billing).map(Billing::getTaxCodeInvoicing).orElse(UNDERSCORE));
addAggregatesCsvLink(onboarding, map, baseUrl);


if (!geographicTaxonomies.isEmpty()) {
map.put("institutionGeoTaxonomies", geographicTaxonomies);
Expand Down Expand Up @@ -199,7 +197,7 @@ public static void setECData(Map<String, Object> map, Onboarding onboarding) {
}

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

map.put("delegatesPrv", delegatesPrvToText(users, onboarding.getUsers()));
Expand All @@ -213,7 +211,6 @@ public static void setupPRVData(
map.put("isAggregatorCheckbox", Boolean.TRUE.equals(onboarding.getIsAggregator()) ? "X" : "");

setECData(map, onboarding);
addAggregatesCsvLink(onboarding, map, baseUrl);
}

public static void setupProdIOData(
Expand Down Expand Up @@ -260,12 +257,6 @@ public static void setupProdIOData(
addPricingPlan(onboarding.getPricingPlan(), map);
}

public static void setupProdIODataAggregates(
Onboarding onboarding, Map<String, Object> map, UserResource validManager, String baseUrl) {
setupProdIOData(onboarding, map, validManager);
addAggregatesCsvLink(onboarding, map, baseUrl);
}

public static void setupSAProdInteropData(Map<String, Object> map, Institution institution) {

map.put(INSTITUTION_REA, Optional.ofNullable(institution.getRea()).orElse(UNDERSCORE));
Expand Down Expand Up @@ -319,8 +310,11 @@ private static void addAggregatesCsvLink(
String csvText =
PROD_IO.getValue().equals(onboarding.getProductId())
? CSV_AGGREGATES_TEXT_IO
: CSV_AGGREGATES_TEXT_PAGOPA;
csvLink = String.format(CSV_AGGREGATES_LABEL, url, csvText);
: CSV_AGGREGATES_TEXT;
csvLink =
PROD_PN.getValue().equals(onboarding.getProductId())
? String.format(CSV_AGGREGATES_LABEL_SEND, url, csvText)
: String.format(CSV_AGGREGATES_LABEL, url, csvText);
}

map.put(CSV_AGGREGATES_LABEL_VALUE, csvLink);
Expand Down Expand Up @@ -433,6 +427,35 @@ private static String delegatesPrvToText(List<UserResource> userResources, List<
return builder.toString();
}

private static String delegatesSendToText(List<UserResource> userResources, List<User> users) {
StringBuilder builder = new StringBuilder();
builder.append("<p class=\"c2\"><span class=\"c1\"><ol class=\"c34 lst-kix_list_23-0 start\" start=\"1\"");
userResources.forEach(
userResource -> {
builder
.append("<br><li class=\"c2 c16 li-bullet-3\"><span class=\"c1\">")
.append("Nome e Cognome: ")
.append(getStringValue(userResource.getName()))
.append(" ")
.append(getStringValue(userResource.getFamilyName()))
.append("</span></li>")
.append("<li class=\"c2 c16 li-bullet-3\"><span class=\"c1\">")
.append("Codice Fiscale: ")
.append(userResource.getFiscalCode())
.append("</span></li>")
.append("<li class=\"c2 c16 li-bullet-3\"><span class=\"c1\">")
.append("Posta Elettronica aziendale: ");

printUserWorkEmail(users, userResource, builder);

builder.append("</span></li><br>"); // Close list item
});

builder.append("</ol></span></p>");

return builder.toString();
}

private static void printUserWorkEmail(
List<User> users, UserResource userResource, StringBuilder builder) {
users.stream()
Expand Down
Loading