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

hot-fix for release 0.4.7 #649

Merged
merged 3 commits into from
Dec 13, 2024
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 @@ -3,11 +3,10 @@
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.OnboardingAttachment;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow;
import org.openapi.quarkus.user_registry_json.model.UserResource;

import java.io.File;
import java.util.List;
import java.util.Optional;
import org.openapi.quarkus.user_registry_json.model.UserResource;

public interface ContractService {
File createContractPDF(
Expand All @@ -19,7 +18,7 @@ File createContractPDF(
String pdfFormatFilename);

File createAttachmentPDF(
String templatePath, Onboarding onboarding, String productName, String pdfFormatFilename);
String templatePath, Onboarding onboarding, String productName, String pdfFormatFilename, UserResource userResource);

File loadContractPDF(String contractTemplatePath, String onboardingId, String productName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package it.pagopa.selfcare.onboarding.service;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_INTEROP;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO_PREMIUM;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO_SIGN;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_PAGOPA;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_PN;
import static it.pagopa.selfcare.onboarding.utils.GenericError.CREATE_AGGREGATES_CSV_ERROR;
import static it.pagopa.selfcare.onboarding.utils.GenericError.GENERIC_ERROR;
import static it.pagopa.selfcare.onboarding.utils.GenericError.LOAD_AGGREGATES_CSV_ERROR;
import static it.pagopa.selfcare.onboarding.utils.GenericError.UNABLE_TO_DOWNLOAD_FILE;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setECData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setUpAttachmentData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setUpCommonData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setupPRVData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setupPSPData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setupProdIOData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setupProdIODataAggregates;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setupProdPNData;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.setupSAProdInteropData;
import static it.pagopa.selfcare.onboarding.utils.Utils.CONTRACT_FILENAME_FUNC;

import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import com.openhtmltopdf.svgsupport.BatikSVGDrawer;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
Expand All @@ -9,20 +30,14 @@
import it.pagopa.selfcare.onboarding.config.PagoPaSignatureConfig;
import it.pagopa.selfcare.onboarding.crypto.PadesSignService;
import it.pagopa.selfcare.onboarding.crypto.entity.SignatureInformation;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.entity.AggregateInstitution;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.OnboardingAttachment;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow;
import it.pagopa.selfcare.onboarding.exception.GenericOnboardingException;
import it.pagopa.selfcare.onboarding.utils.ClassPathStream;
import jakarta.enterprise.context.ApplicationScoped;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.text.StringSubstitutor;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jsoup.Jsoup;
import org.jsoup.helper.W3CDom;
import org.openapi.quarkus.user_registry_json.model.UserResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
Expand All @@ -33,13 +48,22 @@
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;

import static it.pagopa.selfcare.onboarding.common.ProductId.*;
import static it.pagopa.selfcare.onboarding.utils.GenericError.*;
import static it.pagopa.selfcare.onboarding.utils.PdfMapper.*;
import static it.pagopa.selfcare.onboarding.utils.Utils.CONTRACT_FILENAME_FUNC;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.text.StringSubstitutor;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jsoup.Jsoup;
import org.jsoup.helper.W3CDom;
import org.openapi.quarkus.user_registry_json.model.UserResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApplicationScoped
public class ContractServiceDefault implements ContractService {
Expand Down Expand Up @@ -199,7 +223,7 @@ public File createAttachmentPDF(
String attachmentTemplatePath,
Onboarding onboarding,
String productName,
String attachmentName) {
String attachmentName, UserResource userResource) {

log.info("START - createAttachmentPDF for template: {}", attachmentTemplatePath);

Expand All @@ -211,7 +235,7 @@ public File createAttachmentPDF(
File attachmentPdfFile =
"pdf".equals(fileType)
? azureBlobClient.getFileAsPdf(attachmentTemplatePath)
: createPdfFileAttachment(attachmentTemplatePath, onboarding);
: createPdfFileAttachment(attachmentTemplatePath, onboarding, userResource);

// Define the filename and path for storage.
final String filename =
Expand Down Expand Up @@ -259,7 +283,7 @@ private File createPdfFileContract(
&& InstitutionType.PSP == institution.getInstitutionType()) {
setupPSPData(data, manager, onboarding);
} else if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId)
&& InstitutionType.PRV == institution.getInstitutionType()) {
&& InstitutionType.PRV == institution.getInstitutionType() || InstitutionType.GPU == institution.getInstitutionType()) {
setupPRVData(data, onboarding, baseUrl.toString(), users);
} else if (PROD_PAGOPA.getValue().equalsIgnoreCase(productId)
&& InstitutionType.PSP != institution.getInstitutionType()
Expand All @@ -280,7 +304,7 @@ private File createPdfFileContract(
return temporaryPdfFile.toFile();
}

private File createPdfFileAttachment(String attachmentTemplatePath, Onboarding onboarding)
private File createPdfFileAttachment(String attachmentTemplatePath, Onboarding onboarding, UserResource userResource)
throws IOException {
final String builder =
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
Expand All @@ -293,7 +317,7 @@ private File createPdfFileAttachment(String attachmentTemplatePath, Onboarding o
// Create a temporary PDF file to store the contract.
Path attachmentPdfFile = Files.createTempFile(builder, ".pdf");
// Prepare common data for the contract document.
Map<String, Object> data = setUpAttachmentData(onboarding);
Map<String, Object> data = setUpAttachmentData(onboarding, userResource);

log.debug("data Map for PDF: {}", data);
fillPDFAsFile(attachmentPdfFile, attachmentTemplateText, data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.onboarding.service;

import static it.pagopa.selfcare.onboarding.utils.Utils.*;
import static it.pagopa.selfcare.onboarding.utils.Utils.CONTRACT_FILENAME_FUNC;
import static it.pagopa.selfcare.onboarding.utils.Utils.NOT_ALLOWED_WORKFLOWS_FOR_INSTITUTION_NOTIFICATIONS;

import com.microsoft.azure.functions.ExecutionContext;
Expand All @@ -14,7 +14,11 @@
import it.pagopa.selfcare.onboarding.config.MailTemplatePlaceholdersConfig;
import it.pagopa.selfcare.onboarding.dto.NotificationCountResult;
import it.pagopa.selfcare.onboarding.dto.ResendNotificationsFilters;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.OnboardingAttachment;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow;
import it.pagopa.selfcare.onboarding.entity.Token;
import it.pagopa.selfcare.onboarding.entity.User;
import it.pagopa.selfcare.onboarding.exception.GenericOnboardingException;
import it.pagopa.selfcare.onboarding.repository.OnboardingRepository;
import it.pagopa.selfcare.onboarding.repository.TokenRepository;
Expand All @@ -29,7 +33,11 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bson.Document;
Expand Down Expand Up @@ -84,8 +92,6 @@ public Optional<Onboarding> getOnboarding(String onboardingId) {

public void createContract(OnboardingWorkflow onboardingWorkflow) {
Onboarding onboarding = onboardingWorkflow.getOnboarding();
String validManagerId = getValidManagerId(onboarding.getUsers());
UserResource manager = userRegistryApi.findByIdUsingGET(USERS_WORKS_FIELD_LIST, validManagerId);

List<UserResource> delegates =
onboarding.getUsers().stream()
Expand All @@ -99,19 +105,24 @@ public void createContract(OnboardingWorkflow onboardingWorkflow) {
contractService.createContractPDF(
onboardingWorkflow.getContractTemplatePath(product),
onboarding,
manager,
getUserResource(onboarding),
delegates,
product.getTitle(),
onboardingWorkflow.getPdfFormatFilename());
}

private UserResource getUserResource(Onboarding onboarding) {
String validManagerId = getValidManagerId(onboarding.getUsers());
return userRegistryApi.findByIdUsingGET(USERS_WORKS_FIELD_LIST, validManagerId);
}

public void createAttachment(OnboardingAttachment onboardingAttachment) {
Onboarding onboarding = onboardingAttachment.getOnboarding();
Product product = productService.getProductIsValid(onboarding.getProductId());
AttachmentTemplate attachment = onboardingAttachment.getAttachment();

contractService.createAttachmentPDF(
attachment.getTemplatePath(), onboarding, product.getTitle(), attachment.getName());
attachment.getTemplatePath(), onboarding, product.getTitle(), attachment.getName(), getUserResource(onboarding));
}

public void loadContract(Onboarding onboarding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ public static Map<String, Object> setUpCommonData(
return map;
}

public static Map<String, Object> setUpAttachmentData(Onboarding onboarding) {
public static Map<String, Object> setUpAttachmentData(Onboarding onboarding, UserResource userResource) {
Map<String, Object> map = new HashMap<>();

map.put(INSTITUTION_NAME, onboarding.getInstitution().getDescription());
map.put("institutionTaxCode", Optional.ofNullable(onboarding.getInstitution().getTaxCode()).orElse(UNDERSCORE));
map.put("institutionMail", onboarding.getInstitution().getDigitalAddress());
map.put("managerName", getStringValue(userResource.getName()));
map.put("managerSurname", getStringValue(userResource.getFamilyName()));
if (Objects.nonNull(onboarding.getInstitution().getGpuData())) {
map.put(
"businessRegisterNumber",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package it.pagopa.selfcare.onboarding.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
Expand All @@ -8,8 +17,23 @@
import it.pagopa.selfcare.onboarding.config.MailTemplatePlaceholdersConfig;
import it.pagopa.selfcare.onboarding.config.PagoPaSignatureConfig;
import it.pagopa.selfcare.onboarding.crypto.PadesSignService;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.entity.AggregateInstitution;
import it.pagopa.selfcare.onboarding.entity.GPUData;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowAggregator;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowInstitution;
import it.pagopa.selfcare.onboarding.entity.PaymentServiceProvider;
import it.pagopa.selfcare.onboarding.entity.User;
import jakarta.inject.Inject;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -21,13 +45,6 @@
import org.openapi.quarkus.user_registry_json.model.UserResource;
import org.openapi.quarkus.user_registry_json.model.WorkContactResource;

import java.io.File;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@QuarkusTest
class ContractServiceDefaultTest {

Expand Down Expand Up @@ -237,12 +254,13 @@ void createAttachmentPDF() {
Onboarding onboarding = createOnboarding();

Mockito.when(azureBlobClient.getFileAsText(contractFilepath)).thenReturn(contractHtml);

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

UserResource userResource = createUserResource();

File attachmentPDF =
contractService.createAttachmentPDF(
contractFilepath, onboarding, productNameAccent, pdfFormatFile);
contractFilepath, onboarding, productNameAccent, pdfFormatFile, userResource);

assertNotNull(attachmentPDF);

Expand Down Expand Up @@ -500,4 +518,20 @@ void createContractPRV() {
Mockito.verify(azureBlobClient, Mockito.times(1)).uploadFile(any(), any(), any());
Mockito.verifyNoMoreInteractions(azureBlobClient);
}

private UserResource createUserResource() {
UserResource userResource = new UserResource();
userResource.setId(UUID.randomUUID());

CertifiableFieldResourceOfstring resourceOfName = new CertifiableFieldResourceOfstring();
resourceOfName.setCertification(CertifiableFieldResourceOfstring.CertificationEnum.NONE);
resourceOfName.setValue("name");
userResource.setName(resourceOfName);

CertifiableFieldResourceOfstring resourceOfSurname = new CertifiableFieldResourceOfstring();
resourceOfSurname.setCertification(CertifiableFieldResourceOfstring.CertificationEnum.NONE);
resourceOfSurname.setValue("surname");
userResource.setFamilyName(resourceOfSurname);
return userResource;
}
}
Loading
Loading