Skip to content

Commit

Permalink
[P4ADEV-1726] fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedetta-fabbri committed Jan 8, 2025
1 parent 6172952 commit 4c1b859
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 66 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package it.gov.pagopa.pu.debtpositions.citizen.enums;

public enum PersonalDataType {
INSTALLMENT,
RECEIPT
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.gov.pagopa.pu.debtpositions.citizen.service;


import it.gov.pagopa.pu.debtpositions.citizen.Constants;
import it.gov.pagopa.pu.debtpositions.citizen.enums.PersonalDataType;
import it.gov.pagopa.pu.debtpositions.citizen.model.PersonalData;
import it.gov.pagopa.pu.debtpositions.citizen.repository.PersonalDataRepository;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,7 +18,7 @@ public PersonalDataService(PersonalDataRepository repository, DataCipherService
this.dataCipherService = dataCipherService;
}

public long insert(Object pii, Constants.PERSONAL_DATA_TYPE type) {
public long insert(Object pii, PersonalDataType type) {
return repository.save(PersonalData.builder()
.type(type.name())
.data(dataCipherService.encryptObj(pii))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
@AllArgsConstructor
public class InstallmentPIIDTO {

private String uniqueIdentifierType;
private String uniqueIdentifierCode;
private String fullName;
private String address;
private String civic;
private String postalCode;
private String location;
private String province;
private String nation;
private String email;
private Person debtor;

}
4 changes: 2 additions & 2 deletions src/main/java/it/gov/pagopa/pu/debtpositions/dto/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@AllArgsConstructor
public class Person {

private String uniqueIdentifierType;
private String uniqueIdentifierCode;
private String entityType;
private String fiscalCode;
private String fullName;
private String address;
private String civic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import it.gov.pagopa.pu.debtpositions.citizen.service.DataCipherService;
import it.gov.pagopa.pu.debtpositions.dto.Installment;
import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO;
import it.gov.pagopa.pu.debtpositions.dto.Person;
import it.gov.pagopa.pu.debtpositions.model.InstallmentNoPII;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -36,8 +35,8 @@ public Pair<InstallmentNoPII, InstallmentPIIDTO> map(Installment installment) {
installmentNoPII.setHumanFriendlyRemittanceInformation(installment.getHumanFriendlyRemittanceInformation());
installmentNoPII.setBalance(installment.getBalance());
installmentNoPII.setLegacyPaymentMetadata(installment.getLegacyPaymentMetadata());
installmentNoPII.setDebtorEntityType(installment.getDebtor().getUniqueIdentifierType().charAt(0));
installmentNoPII.setDebtorFiscalCodeHash(dataCipherService.hash(installment.getDebtor().getUniqueIdentifierCode()));
installmentNoPII.setDebtorEntityType(installment.getDebtor().getEntityType().charAt(0));
installmentNoPII.setDebtorFiscalCodeHash(dataCipherService.hash(installment.getDebtor().getFiscalCode()));
installmentNoPII.setCreationDate(installment.getCreationDate());
installmentNoPII.setUpdateDate(installment.getUpdateDate());
installmentNoPII.setUpdateOperatorExternalId(installment.getUpdateOperatorExternalId());
Expand All @@ -46,24 +45,9 @@ public Pair<InstallmentNoPII, InstallmentPIIDTO> map(Installment installment) {
installmentNoPII.setPersonalDataId(installment.getNoPII().getPersonalDataId());
}

Person debtor = installment.getDebtor();
InstallmentPIIDTO installmentPIIDTO = getInstallmentPIIDTO(debtor);
InstallmentPIIDTO installmentPIIDTO = InstallmentPIIDTO.builder()
.debtor(installment.getDebtor()).build();

return Pair.of(installmentNoPII, installmentPIIDTO);
}

private static InstallmentPIIDTO getInstallmentPIIDTO(Person debtor) {
InstallmentPIIDTO installmentPIIDTO = new InstallmentPIIDTO();
installmentPIIDTO.setUniqueIdentifierType(debtor.getUniqueIdentifierType());
installmentPIIDTO.setUniqueIdentifierCode(debtor.getUniqueIdentifierCode());
installmentPIIDTO.setFullName(debtor.getFullName());
installmentPIIDTO.setAddress(debtor.getAddress());
installmentPIIDTO.setCivic(debtor.getCivic());
installmentPIIDTO.setPostalCode(debtor.getPostalCode());
installmentPIIDTO.setLocation(debtor.getLocation());
installmentPIIDTO.setProvince(debtor.getProvince());
installmentPIIDTO.setNation(debtor.getNation());
installmentPIIDTO.setEmail(debtor.getEmail());
return installmentPIIDTO;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package it.gov.pagopa.pu.debtpositions.repository;

import it.gov.pagopa.pu.debtpositions.dto.Installment;
import org.springframework.stereotype.Repository;

@Repository
public interface InstallmentPIIRepository {

long save(Installment installment);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.pu.debtpositions.repository;

import it.gov.pagopa.pu.debtpositions.citizen.Constants;
import it.gov.pagopa.pu.debtpositions.citizen.enums.PersonalDataType;
import it.gov.pagopa.pu.debtpositions.citizen.service.PersonalDataService;
import it.gov.pagopa.pu.debtpositions.dto.Installment;
import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO;
Expand All @@ -25,7 +25,7 @@ public InstallmentPIIRepositoryImpl(InstallmentPIIMapper installmentPIIMapper, P
@Override
public long save(Installment installment) {
Pair<InstallmentNoPII, InstallmentPIIDTO> p = installmentPIIMapper.map(installment);
long personalDataId = personalDataService.insert(p.getSecond(), Constants.PERSONAL_DATA_TYPE.INSTALLMENT);
long personalDataId = personalDataService.insert(p.getSecond(), PersonalDataType.INSTALLMENT);
p.getFirst().setPersonalDataId(personalDataId);
installment.setNoPII(p.getFirst());
long newId = installmentNoPIIRepository.save(p.getFirst()).getInstallmentId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.pu.debtpositions.citizen.service;

import it.gov.pagopa.pu.debtpositions.citizen.Constants;
import it.gov.pagopa.pu.debtpositions.citizen.enums.PersonalDataType;
import it.gov.pagopa.pu.debtpositions.citizen.model.PersonalData;
import it.gov.pagopa.pu.debtpositions.citizen.repository.PersonalDataRepository;
import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO;
Expand Down Expand Up @@ -57,7 +57,7 @@ void testInsert() {
Mockito.when(repositoryMock.save(personalDataInput)).thenReturn(personalDataOutput);

// When
long insert = service.insert(pii, Constants.PERSONAL_DATA_TYPE.INSTALLMENT);
long insert = service.insert(pii, PersonalDataType.INSTALLMENT);

// Then
Assertions.assertEquals(piiId, insert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void testMap(){

Installment installment = buildInstallment();
byte[] expectedHashedCF = {};
Mockito.when(dataCipherServiceMock.hash(installment.getDebtor().getUniqueIdentifierCode())).thenReturn(expectedHashedCF);
Mockito.when(dataCipherServiceMock.hash(installment.getDebtor().getFiscalCode())).thenReturn(expectedHashedCF);

Pair<InstallmentNoPII, InstallmentPIIDTO> result = mapper.map(installment);

Expand All @@ -60,7 +60,7 @@ void testMapWithNoPIINotNull(){
Installment installment = buildInstallment();
installment.setNoPII(installmentNoPIIExpected);
byte[] expectedHashedCF = {};
Mockito.when(dataCipherServiceMock.hash(installment.getDebtor().getUniqueIdentifierCode())).thenReturn(expectedHashedCF);
Mockito.when(dataCipherServiceMock.hash(installment.getDebtor().getFiscalCode())).thenReturn(expectedHashedCF);

Pair<InstallmentNoPII, InstallmentPIIDTO> result = mapper.map(installment);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.pu.debtpositions.repository;

import it.gov.pagopa.pu.debtpositions.citizen.Constants;
import it.gov.pagopa.pu.debtpositions.citizen.enums.PersonalDataType;
import it.gov.pagopa.pu.debtpositions.citizen.service.PersonalDataService;
import it.gov.pagopa.pu.debtpositions.dto.Installment;
import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO;
Expand Down Expand Up @@ -43,7 +43,7 @@ void testInsert(){
Mockito.when(mapperMock.map(installment)).thenReturn(p);

long piiId = -1L;
Mockito.when(personalDataServiceMock.insert(p.getSecond(), Constants.PERSONAL_DATA_TYPE.INSTALLMENT)).thenReturn(piiId);
Mockito.when(personalDataServiceMock.insert(p.getSecond(), PersonalDataType.INSTALLMENT)).thenReturn(piiId);

long insertedId = -2L;
Mockito.when(installmentNoPIIRepository.save(p.getFirst())).thenReturn(installmentNoPII);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,7 @@ public static InstallmentNoPII buildInstallmentNoPII(){

public static InstallmentPIIDTO buildInstallmentPIIDTO(){
return InstallmentPIIDTO.builder()
.uniqueIdentifierType("F")
.uniqueIdentifierCode("uniqueIdentifierCode")
.fullName("fullName")
.address("address")
.civic("civic")
.postalCode("postalCode")
.location("location")
.province("province")
.nation("nation")
.email("[email protected]")
.debtor(buildPerson())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class PersonFaker {

public static Person buildPerson(){
return Person.builder()
.uniqueIdentifierType("F")
.uniqueIdentifierCode("uniqueIdentifierCode")
.entityType("F")
.fiscalCode("uniqueIdentifierCode")
.fullName("fullName")
.address("address")
.civic("civic")
Expand Down

0 comments on commit 4c1b859

Please sign in to comment.