Skip to content

Commit

Permalink
Merge branch 'main' into P4ADEV-1658-WF-TreasuryOpiIngestion-file-rea…
Browse files Browse the repository at this point in the history
…ding-validating-save-data

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/dao/TreasuryDao.java
#	src/main/java/it/gov/pagopa/payhub/activities/dto/treasury/TreasuryDTO.java
  • Loading branch information
domenicogi committed Jan 7, 2025
2 parents 0a75468 + 5a8d875 commit 8f5d085
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public IufClassificationActivityResult classify(Long organizationId, Long treasu
.stream()
.map(paymentsReportingDTO ->
Transfer2ClassifyDTO.builder()
.iuv(paymentsReportingDTO.getCreditorReferenceId())
.iur(paymentsReportingDTO.getRegulationUniqueIdentifier())
.iuv(paymentsReportingDTO.getIuv())
.iur(paymentsReportingDTO.getIur())
.transferIndex(paymentsReportingDTO.getTransferIndex())
.build())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import it.gov.pagopa.payhub.activities.dao.ClassificationDao;
import it.gov.pagopa.payhub.activities.dao.PaymentsReportingDao;
import it.gov.pagopa.payhub.activities.dao.TransferDao;
import it.gov.pagopa.payhub.activities.dao.TreasuryDao;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.PaymentsReportingDTO;
import it.gov.pagopa.payhub.activities.exception.ClassificationException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

Expand All @@ -16,13 +18,16 @@ public class TransferClassificationActivityImpl implements TransferClassificatio
private final ClassificationDao classificationDao;
private final TransferDao transferDao;
private final PaymentsReportingDao paymentsReportingDao;
private final TreasuryDao treasuryDao;

public TransferClassificationActivityImpl(ClassificationDao classificationDao,
TransferDao transferDao,
PaymentsReportingDao paymentsReportingDao) {
PaymentsReportingDao paymentsReportingDao,
TreasuryDao treasuryDao) {
this.classificationDao = classificationDao;
this.transferDao = transferDao;
this.paymentsReportingDao = paymentsReportingDao;
this.treasuryDao = treasuryDao;
}

@Override
Expand All @@ -35,5 +40,10 @@ public void classify(Long orgId, String iuv, String iur, int transferIndex) {

log.info("Retrieve payment reporting for organization id: {} and iuv: {} and iur {} and transfer index: {}", orgId, iuv, iur, transferIndex);
PaymentsReportingDTO paymentsReportingDTO = paymentsReportingDao.findBySemanticKey(orgId, iuv, iur, transferIndex);
if (paymentsReportingDTO!=null) {
String iuf = paymentsReportingDTO.getIuf();
log.info("Retrieve treasury for organization id: {} and iuf {}", orgId, iuf);
treasuryDao.getByOrganizationIdAndIuf(orgId, iuf);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public interface TreasuryDao {

TreasuryDTO getByOrganizationIdAndBillCodeAndBillYear(Long organizationId, String billCode, String billYear);








/**
* search for treasury of a specific organization associated to a payment reporting identifier
*
* @param organizationId organization id
* @param iuf payment reporting identifier
* @return TreasuryDTO object containing treasury data
*/
TreasuryDTO getByOrganizationIdAndIuf(Long organizationId, String iuf);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PaymentsReportingDTO {
private Long organizationId;
private Long ingestionFlowFileId;
private String pspIdentifier;
private String flowIdentifierCode;
private String iuf;
private LocalDateTime flowDateTime;
private String regulationUniqueIdentifier;
private LocalDate regulationDate;
Expand All @@ -34,8 +34,8 @@ public class PaymentsReportingDTO {
private String receiverOrganizationName;
private long totalPayments;
private Long totalAmountCents;
private String creditorReferenceId;
private String regulationId;
private String iuv;
private String iur;
private Long amountPaidCents;
private String paymentOutcomeCode;
private LocalDate payDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class TreasuryDTO {
private Long processPgNumber;
private Date regionValueDate;
private Long organizationId;
private String flowIdentifierCode;
private String iuf;
private String iuv;
private Date creationDate;
private Date lastUpdateDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<PaymentsReportingDTO> mapToDtoList(CtFlussoRiversamento ctFlussoRive
.organizationId(ingestionFlowFileDTO.getOrg().getOrgId())
.ingestionFlowFileId(ingestionFlowFileDTO.getIngestionFlowFileId())
.pspIdentifier(ctFlussoRiversamento.getIstitutoMittente().getDenominazioneMittente())
.flowIdentifierCode(ctFlussoRiversamento.getIdentificativoFlusso())
.iuf(ctFlussoRiversamento.getIdentificativoFlusso())
.flowDateTime(ctFlussoRiversamento.getDataOraFlusso().toGregorianCalendar().toZonedDateTime().toLocalDateTime())
.regulationUniqueIdentifier(ctFlussoRiversamento.getIdentificativoUnivocoRegolamento())
.regulationDate(ctFlussoRiversamento.getDataRegolamento().toGregorianCalendar().toZonedDateTime().toLocalDate())
Expand All @@ -52,8 +52,8 @@ public List<PaymentsReportingDTO> mapToDtoList(CtFlussoRiversamento ctFlussoRive

return ctFlussoRiversamento.getDatiSingoliPagamenti().stream()
.map(item -> builder
.creditorReferenceId(item.getIdentificativoUnivocoVersamento())
.regulationId(item.getIdentificativoUnivocoRiscossione())
.iuv(item.getIdentificativoUnivocoVersamento())
.iur(item.getIdentificativoUnivocoRiscossione())
.transferIndex(item.getIndiceDatiSingoloPagamento())
.amountPaidCents(item.getSingoloImportoPagato().movePointRight(2).longValueExact())
.paymentOutcomeCode(item.getCodiceEsitoSingoloPagamento())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void givenReportedTransferWhenClassifyThenOk() {
.stream()
.map(paymentsReportingDTO ->
Transfer2ClassifyDTO.builder()
.iuv(paymentsReportingDTO.getCreditorReferenceId())
.iur(paymentsReportingDTO.getRegulationUniqueIdentifier())
.iuv(paymentsReportingDTO.getIuv())
.iur(paymentsReportingDTO.getIur())
.transferIndex(paymentsReportingDTO.getTransferIndex())
.build())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import it.gov.pagopa.payhub.activities.dao.ClassificationDao;
import it.gov.pagopa.payhub.activities.dao.PaymentsReportingDao;
import it.gov.pagopa.payhub.activities.dao.TransferDao;
import it.gov.pagopa.payhub.activities.dao.TreasuryDao;
import it.gov.pagopa.payhub.activities.dto.TransferDTO;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.PaymentsReportingDTO;
import it.gov.pagopa.payhub.activities.dto.treasury.TreasuryDTO;
import it.gov.pagopa.payhub.activities.exception.ClassificationException;
import it.gov.pagopa.payhub.activities.utility.faker.PaymentsReportingFaker;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -20,6 +25,7 @@ class TransferClassificationActivityImplTest {
private static final Long ORGANIZATION = 123L;
private static final String IUV = "01011112222333345";
private static final String IUR = "IUR";
private static final String IUF = "IUF";
private static final int INDEX = 1;

@Mock
Expand All @@ -31,32 +37,101 @@ class TransferClassificationActivityImplTest {
@Mock
private PaymentsReportingDao paymentsReportingDaoMock;

@Mock
private TreasuryDao treasuryDaoMock;

private TransferClassificationActivity activity;

@BeforeEach
void setUp() {
activity = new TransferClassificationActivityImpl(classificationDaoMock, transferDaoMock, paymentsReportingDaoMock);
activity = new TransferClassificationActivityImpl(
classificationDaoMock, transferDaoMock, paymentsReportingDaoMock, treasuryDaoMock);
}

@AfterEach
void verifyNoMoreInteractions(){
Mockito.verifyNoMoreInteractions(
classificationDaoMock, transferDaoMock, paymentsReportingDaoMock, treasuryDaoMock);
}

@Test
void classificationSuccess() {
PaymentsReportingDTO paymentsReportingDTO = PaymentsReportingFaker.buildClassifyResultDTO();
when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE);
when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(new TransferDTO());
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(new PaymentsReportingDTO());
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(paymentsReportingDTO);
when(treasuryDaoMock.getByOrganizationIdAndIuf(ORGANIZATION, IUF)).thenReturn(new TreasuryDTO());

assertDoesNotThrow(() -> activity.classify(ORGANIZATION, IUV, IUR, INDEX));

Mockito.verify(classificationDaoMock, Mockito.times(1)).deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(transferDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(paymentsReportingDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(treasuryDaoMock, Mockito.times(1)).getByOrganizationIdAndIuf(ORGANIZATION, IUF);
}

@Test
void givenFailedDeletePreviousClassificationWhenClassifyThenClassificationFailed() {
when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.FALSE);
assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed");

Mockito.verify(classificationDaoMock, Mockito.times(1)).deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(transferDaoMock, Mockito.times(0)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(paymentsReportingDaoMock, Mockito.times(0)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(treasuryDaoMock, Mockito.times(0)).getByOrganizationIdAndIuf(ORGANIZATION, IUF);
}

@Test
void givenFailedFindTransferWhenClassifyThenClassificationFailed() {
when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE);
when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenThrow(new ClassificationException("retrieving failed"));
assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed");

Mockito.verify(classificationDaoMock, Mockito.times(1)).deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(transferDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(paymentsReportingDaoMock, Mockito.times(0)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(treasuryDaoMock, Mockito.times(0)).getByOrganizationIdAndIuf(ORGANIZATION, IUF);
}

@Test
void givenFailedFindPaymentsReportingWhenClassifyThenClassificationFailed() {
when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE);
when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(new TransferDTO());
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenThrow(new ClassificationException("payments reporting find failed"));
assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed");

Mockito.verify(classificationDaoMock, Mockito.times(1)).deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(transferDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(paymentsReportingDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(treasuryDaoMock, Mockito.times(0)).getByOrganizationIdAndIuf(ORGANIZATION, IUF);
}

@Test
void whenPaymentsReportingDTOIsNullShouldNotCallTreasury() {
when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE);
when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(new TransferDTO());
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(null);
assertDoesNotThrow(() -> activity.classify(ORGANIZATION, IUV, IUR, INDEX));

Mockito.verify(classificationDaoMock, Mockito.times(1)).deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(transferDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(paymentsReportingDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(treasuryDaoMock, Mockito.times(0)).getByOrganizationIdAndIuf(ORGANIZATION, IUF);
}

@Test
void givenFailedFindTreasuryWhenClassifyThenClassificationFailed() {
PaymentsReportingDTO paymentsReportingDTO = PaymentsReportingFaker.buildClassifyResultDTO();
when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE);
when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(new TransferDTO());
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(paymentsReportingDTO);
when(treasuryDaoMock.getByOrganizationIdAndIuf(ORGANIZATION, IUF)).thenThrow(new ClassificationException("treasury find failed"));
assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed");

Mockito.verify(classificationDaoMock, Mockito.times(1)).deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(transferDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(paymentsReportingDaoMock, Mockito.times(1)).findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX);
Mockito.verify(treasuryDaoMock, Mockito.times(1)).getByOrganizationIdAndIuf(ORGANIZATION, IUF);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void givenSuccessfullConditionsWhenProcessFileThenOk() throws IOException {
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePathName()).resolve(mockFlowDTO.getFileName()));
List<Path> mockedListPath = List.of(filePath);
ctFlussoRiversamento.setIdentificativoFlusso("idFlow");
List<PaymentsReportingDTO> dtoList = List.of(PaymentsReportingDTO.builder().flowIdentifierCode("idFlow").build());
List<PaymentsReportingDTO> dtoList = List.of(PaymentsReportingDTO.builder().iuf("idFlow").build());

PaymentsReportingIngestionFlowFileActivityResult expected =
new PaymentsReportingIngestionFlowFileActivityResult(List.of(ctFlussoRiversamento.getIdentificativoFlusso()), true, null);
Expand Down Expand Up @@ -248,7 +248,7 @@ void givenPaymentsReportingExceptionWhenProcessFileThenFails() throws Exception
List<Path> mockedListPath = List.of(filePath);
ctFlussoRiversamento = new CtFlussoRiversamento();
ctFlussoRiversamento.setIdentificativoFlusso("idFlow");
List<PaymentsReportingDTO> dtoList = List.of(PaymentsReportingDTO.builder().flowIdentifierCode("idFlow").build());
List<PaymentsReportingDTO> dtoList = List.of(PaymentsReportingDTO.builder().iuf("idFlow").build());

PaymentsReportingIngestionFlowFileActivityResult expected =
new PaymentsReportingIngestionFlowFileActivityResult(Collections.emptyList(), false, "saving fails");
Expand Down Expand Up @@ -283,7 +283,7 @@ void givenIOExceptionWhenProcessFileThenFails() throws IOException {
List<Path> mockedListPath = List.of(filePath);
ctFlussoRiversamento = new CtFlussoRiversamento();
ctFlussoRiversamento.setIdentificativoFlusso("idFlow");
List<PaymentsReportingDTO> dtoList = List.of(PaymentsReportingDTO.builder().flowIdentifierCode("idFlow").build());
List<PaymentsReportingDTO> dtoList = List.of(PaymentsReportingDTO.builder().iuf("idFlow").build());

PaymentsReportingIngestionFlowFileActivityResult expected =
new PaymentsReportingIngestionFlowFileActivityResult(Collections.emptyList(), false, "error occured");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ void testMapper() throws DatatypeConfigurationException {
PaymentsReportingDTO firstDTO = result.getFirst();
// Then
assertEquals(1, result.size());
assertEquals("flow123", firstDTO.getFlowIdentifierCode());
assertEquals("flow123", firstDTO.getIuf());
assertEquals("PSP Mittente", firstDTO.getSenderPspName());
assertEquals("Org Ricevente", firstDTO.getReceiverOrganizationName());
assertEquals(1L, firstDTO.getTotalPayments());
assertEquals(100_050L, firstDTO.getTotalAmountCents());
assertEquals("vers123", firstDTO.getCreditorReferenceId());
assertEquals("ris123", firstDTO.getRegulationId());
assertEquals("vers123", firstDTO.getIuv());
assertEquals("ris123", firstDTO.getIur());
assertEquals(1, firstDTO.getTransferIndex());
assertEquals(20_000L, firstDTO.getAmountPaidCents());
assertEquals("OK", firstDTO.getPaymentOutcomeCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class PaymentsReportingFaker {
public static PaymentsReportingDTO buildClassifyResultDTO(){
return PaymentsReportingDTO.builder()
.organizationId(1L)
.creditorReferenceId("IUV")
.regulationUniqueIdentifier("IUR")
.iuf("IUF")
.iuv("IUV")
.iur("IUR")
.transferIndex(1)
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.23.4
1.24.0

0 comments on commit 8f5d085

Please sign in to comment.