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

feat: P4ADEV-1633 classify-iuv-activity-retrieve-tes-iuf #66

Merged
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 @@ -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) {
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
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
@@ -0,0 +1,17 @@
package it.gov.pagopa.payhub.activities.dao;

import it.gov.pagopa.payhub.activities.dto.treasury.TreasuryDTO;


public interface TreasuryDao {

/**
* 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
@@ -0,0 +1,59 @@
package it.gov.pagopa.payhub.activities.dto.treasury;

import lombok.*;

import java.math.BigDecimal;
import java.util.Date;

/**
* DTO for the TreasuryDto
*/
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class TreasuryDTO {
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
private Long treasuryId;
private String billYear;
private String billCode;
private String accountCode;
private String domainIdCode;
private String transactionTypeCode;
private String remittanceCode;
private String remittanceInformation;
private BigDecimal billIpNumber;
private Date billDate;
private Date receptionDate;
private String documentYear;
private String documentCode;
private String sealCode;
private String lastName;
private String firstName;
private String address;
private String postalCode;
private String city;
private String fiscalCode;
private String vatNumber;
private String abiCode;
private String cabCode;
private String accountRegistryCode;
private String provisionalAe;
private String provisionalCode;
private String ibanCode;
private Character accountTypeCode;
private String processCode;
private String executionPgCode;
private String transferPgCode;
private Long processPgNumber;
private Date regionValueDate;
private Long organizationId;
private String iuf;
private String iuv;
private Date creationDate;
private Date lastUpdateDate;
private boolean isRegularized;
private Long ingestionFlowFileId;
private Date actualSuspensionDate;
private String managementProvisionalCode;
private String endToEndId;
}
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.23.11t add .-SNAPSHOT
Loading