Skip to content

Commit

Permalink
[SELC-6170] feat: Updated PdfMapper for GPU Data
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpaolodidato89 authored Dec 12, 2024
1 parent 2f236fa commit 8f5acbc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class BusinessData {
private String businessRegisterNumber;
private String legalRegisterNumber;
private String legalRegisterName;
private boolean longTermPayments;

public String getBusinessRegisterNumber() {
return businessRegisterNumber;
Expand All @@ -29,4 +30,12 @@ public String getLegalRegisterName() {
public void setLegalRegisterName(String legalRegisterName) {
this.legalRegisterName = legalRegisterName;
}

public boolean isLongTermPayments() {
return longTermPayments;
}

public void setLongTermPayments(boolean longTermPayments) {
this.longTermPayments = longTermPayments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void saveTokenWithAttachment(OnboardingAttachment onboardingAttachment) {

private boolean checkTokenExist(Onboarding onboarding) {
// Skip if token already exists
Optional<Token> optToken = tokenRepository.findByOnboardingId(onboarding.getId());
Optional<Token> optToken = tokenRepository.findByIdOptional(onboarding.getId());
if (optToken.isPresent()) {
log.debug("Token has already exists for onboarding {}", onboarding.getId());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public static Map<String, Object> setUpCommonData(

public static Map<String, Object> setUpAttachmentData(Onboarding onboarding) {
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());
if (Objects.nonNull(onboarding.getInstitution().getGpuData())) {
map.put(
"businessRegisterNumber",
Expand All @@ -122,19 +125,12 @@ public static Map<String, Object> setUpAttachmentData(Onboarding onboarding) {
"legalRegisterName",
Optional.ofNullable(onboarding.getInstitution().getGpuData().getLegalRegisterName())
.orElse(UNDERSCORE));
map.put("manager", onboarding.getInstitution().getGpuData().isManager() ? "Si" : "No");
map.put(
"managerAuthorized",
onboarding.getInstitution().getGpuData().isManagerAuthorized() ? "Si" : "No");
map.put(
"managerEligible",
onboarding.getInstitution().getGpuData().isManagerEligible() ? "Si" : "No");
map.put(
"managerProsecution",
onboarding.getInstitution().getGpuData().isManagerProsecution() ? "Si" : "No");
map.put(
"institutionCourtMeasures",
onboarding.getInstitution().getGpuData().isInstitutionCourtMeasures() ? "Si" : "No");
map.put("businessRegisterCheckbox1", StringUtils.isNotEmpty(onboarding.getInstitution().getGpuData().getBusinessRegisterNumber()) ? "X" : "");
map.put("businessRegisterCheckbox2", StringUtils.isEmpty(onboarding.getInstitution().getGpuData().getBusinessRegisterNumber()) ? "X" : "");
map.put("publicServicesCheckbox1", StringUtils.isNotEmpty(onboarding.getInstitution().getGpuData().getLegalRegisterName()) ? "X" : "");
map.put("publicServicesCheckbox2", StringUtils.isEmpty(onboarding.getInstitution().getGpuData().getLegalRegisterName()) ? "X" : "");
map.put("longTermPaymentsCheckbox1", onboarding.getInstitution().getGpuData().isLongTermPayments() ? "X" : "");
map.put("longTermPaymentsCheckbox2", !onboarding.getInstitution().getGpuData().isLongTermPayments() ? "X" : "");
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ void saveToken_shouldSkipIfTokenExists() {
Token token = createDummyToken();
onboardingWorkflow.setOnboarding(onboarding);

when(tokenRepository.findByOnboardingId(onboarding.getId())).thenReturn(Optional.of(token));
when(tokenRepository.findByIdOptional(onboarding.getId())).thenReturn(Optional.of(token));

onboardingService.saveTokenWithContract(onboardingWorkflow);

Mockito.verify(tokenRepository, Mockito.times(1)).findByOnboardingId(onboarding.getId());
Mockito.verify(tokenRepository, Mockito.times(1)).findByIdOptional(onboarding.getId());
Mockito.verifyNoMoreInteractions(tokenRepository);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public Uni<Onboarding> customValidation(Product product) {
protected boolean isWorkflowTypeAllowed(WorkflowType workflowType) {
return workflowType == WorkflowType.FOR_APPROVE ||
workflowType == WorkflowType.IMPORT ||
workflowType == WorkflowType.FOR_APPROVE_PT;
workflowType == WorkflowType.FOR_APPROVE_PT ||
workflowType == WorkflowType.FOR_APPROVE_GPU;
}

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

import static it.pagopa.selfcare.onboarding.common.TokenType.ATTACHMENT;
import static it.pagopa.selfcare.onboarding.common.TokenType.INSTITUTION;

import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
Expand Down Expand Up @@ -30,7 +31,7 @@ public Uni<List<Token>> getToken(String onboardingId) {
}
@Override
public Uni<RestResponse<File>> retrieveContractNotSigned(String onboardingId) {
return Token.find("onboardingId", onboardingId)
return Token.find("onboardingId = ?1 and type = ?2", onboardingId, INSTITUTION.name())
.firstResult()
.map(Token.class::cast)
.onItem().transformToUni(token ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.pagopa.selfcare.onboarding.service;

import static it.pagopa.selfcare.onboarding.common.TokenType.ATTACHMENT;
import static it.pagopa.selfcare.onboarding.common.TokenType.INSTITUTION;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -15,6 +16,7 @@
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
import it.pagopa.selfcare.onboarding.common.TokenType;
import it.pagopa.selfcare.onboarding.entity.Token;
import jakarta.inject.Inject;
import java.io.File;
Expand Down Expand Up @@ -52,11 +54,12 @@ void getToken() {
void retrieveContractNotSigned() {
Token token = new Token();
token.setContractFilename("fileName");
token.setType(TokenType.INSTITUTION);
ReactivePanacheQuery queryPage = mock(ReactivePanacheQuery.class);
when(queryPage.firstResult()).thenReturn(Uni.createFrom().item(token));

PanacheMock.mock(Token.class);
when(Token.find("onboardingId", onboardingId))
when(Token.find("onboardingId = ?1 and type = ?2", onboardingId, INSTITUTION.name()))
.thenReturn(queryPage);

when(azureBlobClient.getFileAsPdf(anyString())).thenReturn(new File("fileName"));
Expand Down

0 comments on commit 8f5acbc

Please sign in to comment.