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-1625 classifyiufactivity-retrieve-iuvs-save #48

Merged
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
54f4cda
implementation
silvanotamburini Dec 10, 2024
02e1ee4
add tests
silvanotamburini Dec 10, 2024
537d88e
change version
silvanotamburini Dec 10, 2024
eaa34ae
implementation of Iuf Classification Activity save
silvanotamburini Dec 11, 2024
c588181
Merge branch 'main' into P4ADEV-1625-classifyiufactivity-retrieve-iuv…
silvanotamburini Dec 11, 2024
8dcc24c
deleted wrong parameter
silvanotamburini Dec 11, 2024
09ded78
fix problems in Exception handling
silvanotamburini Dec 11, 2024
e364913
change Exception handling
silvanotamburini Dec 11, 2024
7a94b3f
delete function not correctly merged with main
silvanotamburini Dec 11, 2024
7ff7d0b
change Exception handling
silvanotamburini Dec 11, 2024
74a101c
add tests
silvanotamburini Dec 11, 2024
84ea58a
Merge branch 'main' into P4ADEV-1625-classifyiufactivity-retrieve-iuv…
silvanotamburini Dec 11, 2024
283170c
review implementation
silvanotamburini Dec 13, 2024
026986f
Merge branch 'main' into P4ADEV-1625-classifyiufactivity-retrieve-iuv…
silvanotamburini Dec 13, 2024
4db2509
fix issues
silvanotamburini Dec 13, 2024
f07ec0e
add new tests
silvanotamburini Dec 13, 2024
2f02d74
delete wrong message
silvanotamburini Dec 13, 2024
746200a
changed wrong method
silvanotamburini Dec 13, 2024
3de5b75
Merge branch 'main' into P4ADEV-1625-classifyiufactivity-retrieve-iuv…
silvanotamburini Dec 18, 2024
d4430b7
Merge remote-tracking branch 'origin/main' into P4ADEV-1625-classifyi…
silvanotamburini Dec 18, 2024
b8655d2
added temporal annotations in IufClassificationActivity interface
silvanotamburini Dec 18, 2024
5380b53
Update version
silvanotamburini Dec 18, 2024
bb4be55
partial adding of requested changes, waiting other merge
silvanotamburini Dec 19, 2024
9bc81f6
change version
silvanotamburini Dec 19, 2024
1d4a86d
Merge remote-tracking branch 'origin/main' into P4ADEV-1625-classifyi…
silvanotamburini Dec 19, 2024
252eb5f
add requested changes
silvanotamburini Dec 19, 2024
3a055ce
add requested changes anche changed dtos
silvanotamburini Dec 19, 2024
d832a07
small change of implementation
silvanotamburini Dec 19, 2024
0ebb3a2
change version
silvanotamburini Dec 19, 2024
5764283
renamed DTO
silvanotamburini Dec 19, 2024
e541827
renamed DTO in Dao
silvanotamburini Dec 19, 2024
c5c5dd7
change activity and implementation classify method parameters
silvanotamburini Dec 19, 2024
3e58446
change tests according to activity implementation
silvanotamburini Dec 19, 2024
6bcd856
change version
silvanotamburini Dec 19, 2024
901caf4
delete useless local method
silvanotamburini Dec 20, 2024
7e40522
fix maintanability issue on previous code change
silvanotamburini Dec 20, 2024
fb9d24f
requested changes made
silvanotamburini Dec 20, 2024
1734488
rename wrong naming of test class
silvanotamburini Dec 20, 2024
44b51ae
Merge branch 'main' into P4ADEV-1625-classifyiufactivity-retrieve-iuv…
silvanotamburini Dec 20, 2024
467d07f
fix list veriification
silvanotamburini Dec 20, 2024
8962b12
insert verify on mocks
silvanotamburini Dec 23, 2024
b140b6f
change version
silvanotamburini Dec 23, 2024
ee161d4
change version
silvanotamburini Dec 23, 2024
4029eeb
Merge branch 'main' into P4ADEV-1625-classifyiufactivity-retrieve-iuv…
silvanotamburini Dec 23, 2024
97a6921
chenge test
silvanotamburini Dec 23, 2024
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
@@ -1,15 +1,23 @@
package it.gov.pagopa.payhub.activities.activity.classifications;

import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityMethod;
import it.gov.pagopa.payhub.activities.dto.classifications.IufClassificationActivityResult;

/**
* Interface for defining an activity to process payment reporting classifications based on IUF.
*/
@ActivityInterface
public interface IufClassificationActivity {

/**
* Processes IUF classification based on the provided parameters.
*
* @param organizationId the unique identifier of the organization
* @param treasuryId the unique identifier of treasury
* @param iuf the unique identifier of the payment reporting flow (IUF)
* @return true if the classification is successful, false otherwise
* @return IufClassificationActivityResult containing a list of payments and success flag
*/
boolean classify(String organizationId, String iuf);
@ActivityMethod
IufClassificationActivityResult classify(Long organizationId, Long treasuryId, String iuf);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package it.gov.pagopa.payhub.activities.activity.classifications;

import it.gov.pagopa.payhub.activities.dao.ClassificationDao;
import it.gov.pagopa.payhub.activities.dao.PaymentsReportingDao;
import it.gov.pagopa.payhub.activities.dto.classifications.ClassificationDTO;
import it.gov.pagopa.payhub.activities.dto.classifications.IufClassificationActivityResult;
import it.gov.pagopa.payhub.activities.dto.classifications.ClassifyResultDTO;
import it.gov.pagopa.payhub.activities.enums.ClassificationsEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Lazy
@Component
public class IufClassificationActivityImpl implements IufClassificationActivity {
private final PaymentsReportingDao paymentsReportingDao;
private final ClassificationDao classificationDao;

public IufClassificationActivityImpl(PaymentsReportingDao paymentsReportingDao, ClassificationDao classificationDao) {
this.paymentsReportingDao = paymentsReportingDao;
this.classificationDao = classificationDao;
}

@Override
public IufClassificationActivityResult classify(Long organizationId, Long treasuryId, String iuf) {
log.debug("Starting IUF Classification for organization id {} and iuf {}", organizationId,iuf);

List<ClassifyResultDTO> classifyResultDTOS =
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
paymentsReportingDao.findByOrganizationIdFlowIdentifierCode(organizationId, iuf)
.stream()
.map(paymentsReportingDTO ->
ClassifyResultDTO.builder()
.organizationId(paymentsReportingDTO.getOrganizationId())
.creditorReferenceId(paymentsReportingDTO.getCreditorReferenceId())
.regulationUniqueIdentifier(paymentsReportingDTO.getRegulationUniqueIdentifier())
.transferIndex(paymentsReportingDTO.getTransferIndex())
.build())
.toList();

log.debug("Saving payments reporting found for organization id {} and iuf: {}", organizationId, iuf);
saveClassification(organizationId, treasuryId, iuf);
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved

return IufClassificationActivityResult.builder()
.classifyResultDTOS(classifyResultDTOS)
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
.success(true)
.build();
}

/**
* save classification data
*
* @param organizationId organization id
* @param treasuryId treasury id
* @param iuf flow unique identifier
*/
private void saveClassification(Long organizationId, Long treasuryId, String iuf) {
log.debug("Saving classification TES_NO_MATCH for organizationId: {} - treasuryId: {} - iuf: {}", organizationId, treasuryId, iuf);

classificationDao.save(ClassificationDTO.builder()
.organizationId(organizationId)
.treasuryId(treasuryId)
.iuf(iuf)
.classificationsEnum(ClassificationsEnum.TES_NO_MATCH)
.build());
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package it.gov.pagopa.payhub.activities.dao;

import it.gov.pagopa.payhub.activities.dto.classifications.ClassificationDTO;
import it.gov.pagopa.payhub.activities.enums.ClassificationsEnum;

/**
* Data Access Object interface for saving payments classification
* Data Access Object interface for saving payments classification
*/
public interface ClassificationDao {
/**
* save classification
*
* @param organizationId organization id
* @param iuf fow identifier
* @param classification classification to delete
* @return true for success deletion
*/
* @param classificationDTO dto classification to save
*/
void save(ClassificationDTO classificationDTO);

/**
* delete classification
*
* @param organizationId organization id
* @param iuf fow identifier
* @param classification classification to delete
* @return true for success deletion
*/
boolean deleteClassificationByIuf(Long organizationId, String iuf, ClassificationsEnum classification);
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ public interface PaymentsReportingDao {
* fields (e.g., generated IDs or timestamps).
*/
List<PaymentsReportingDTO> saveAll(List<PaymentsReportingDTO> dtos);

/**
*
* @param organizationId organization id
* @param flowIdentifierCode identifies a specific reporting code
* @return List of PaymentsReportingDTO objects that may be an empty list
*/
List<PaymentsReportingDTO> findByOrganizationIdFlowIdentifierCode(Long organizationId, String flowIdentifierCode);
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved

}
15 changes: 15 additions & 0 deletions src/main/java/it/gov/pagopa/payhub/activities/dao/TreasuryDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.gov.pagopa.payhub.activities.dao;

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

import java.util.List;

public interface TreasuryDao {
/**
* retrieve treasury for the same iuf
*
* @param iuf flow unique identifier
* @return list of treasury records associated to the iuf
*/
List<TreasuryDTO> searchByIuf(String iuf);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.gov.pagopa.payhub.activities.dto.classifications;

import it.gov.pagopa.payhub.activities.enums.ClassificationsEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class ClassificationDTO implements Serializable {
private Long organizationId;
private Long transferId;
private Long paymentNotifyId;
private Long paymentReportingId;
private Long treasuryId;
private String iuf;
private String iud;
private String iuv;
private String iur;
private int transferIndex;
private ClassificationsEnum classificationsEnum;
private LocalDate creationDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.gov.pagopa.payhub.activities.dto.classifications;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class ClassifyResultDTO {
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
private Long organizationId;
private String creditorReferenceId;
private String regulationUniqueIdentifier;
private int transferIndex;
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.gov.pagopa.payhub.activities.dto.classifications;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class IufClassificationActivityResult {
private List<ClassifyResultDTO> classifyResultDTOS;
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
private boolean success;
}
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package it.gov.pagopa.payhub.activities.dto.treasury;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

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

/**
* DTO for the TreasuryDto
*/
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class TreasuryDTO {
private Long mygovFlussoTesoreriaId;
private String deAnnoBolletta;
private String codBolletta;
private String codConto;
private String codIdDominio;
private String codTipoMovimento;
private String codCausale;
private BigDecimal numIpBolletta;
private Date dtBolletta;
private Date dtRicezione;
private String deAnnoDocumento;
private String codDocumento;
private String codBollo;
private String deAeProvvisorio;
private String codProvvisorio;
private Character codTipoConto;
private String codProcesso;
private String codPgEsecuzione;
private String codPgTrasferimento;
private Long numPgProcesso;
private Date dtDataValutaRegione;
private Long mygovEnteId;
private String codIdUnivocoFlusso;
private String codIdUnivocoVersamento;
private Date dtCreazione;
private Date dtUltimaModifica;
private boolean flgRegolarizzata;
private Long mygovManageFlussoId;
private Date dtEffettivaSospeso;
private String codiceGestionaleProvvisorio;
private String endToEndId;

private byte[] codCodiceFiscaleHash;
private byte[] codPartitaIvaHash;
private byte[] deCognomeHash;

private Long personalDataId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package it.gov.pagopa.payhub.activities.activity.classifications;

import it.gov.pagopa.payhub.activities.dao.ClassificationDao;
import it.gov.pagopa.payhub.activities.dao.PaymentsReportingDao;
import it.gov.pagopa.payhub.activities.dto.classifications.ClassifyResultDTO;
import it.gov.pagopa.payhub.activities.dto.classifications.IufClassificationActivityResult;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.PaymentsReportingDTO;
import it.gov.pagopa.payhub.activities.utility.faker.PaymentsReportingFaker;
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.junit.jupiter.MockitoExtension;

import java.util.ArrayList;
import java.util.List;

import static it.gov.pagopa.payhub.activities.utility.faker.ClassifyResultFaker.buildClassifyResultDTO;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class IufClassificationActivitySaveTest {
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
@Mock
private PaymentsReportingDao paymentsReportingDao;

@Mock
private ClassificationDao classificationDao;

private IufClassificationActivity iufClassificationActivity;

private static final Long ORGANIZATIONID = 1L;
private static final Long TREASURYID = 1L;
private static final String FLOWIDENTIFIERCODE = "FLOW";


@BeforeEach
void init() {
iufClassificationActivity = new IufClassificationActivityImpl(paymentsReportingDao, classificationDao);
}


@Test
void saveClassificationSuccess() {
PaymentsReportingDTO expectedPaymentsReportingDTO = PaymentsReportingFaker.buildClassifyResultDTO();
List<PaymentsReportingDTO> expectedPaymentsReportingDTOS = new ArrayList<>();
expectedPaymentsReportingDTOS.add(expectedPaymentsReportingDTO);

ClassifyResultDTO expectedClassifyResultDTO = buildClassifyResultDTO(ORGANIZATIONID);
List<ClassifyResultDTO> expectedClassifyResultDTOS = new ArrayList<>();
expectedClassifyResultDTOS.add(expectedClassifyResultDTO);

IufClassificationActivityResult expectedIufClassificationActivityResult =
IufClassificationActivityResult
.builder()
.classifyResultDTOS(expectedClassifyResultDTOS)
.success(true)
.build();

when(paymentsReportingDao.findByOrganizationIdFlowIdentifierCode(ORGANIZATIONID, FLOWIDENTIFIERCODE))
.thenReturn(expectedPaymentsReportingDTOS);

IufClassificationActivityResult iufClassificationActivityResult =
iufClassificationActivity.classify(ORGANIZATIONID, TREASURYID, FLOWIDENTIFIERCODE);
assertEquals(iufClassificationActivityResult,expectedIufClassificationActivityResult);
}

@Test
void saveClassificationNoPayments() {
List<ClassifyResultDTO> classifyResultDTOS = new ArrayList<>();

IufClassificationActivityResult expectedIufClassificationActivityResult =
IufClassificationActivityResult
.builder()
.classifyResultDTOS(classifyResultDTOS)
.success(true)
.build();

IufClassificationActivityResult iufClassificationActivityResult =
iufClassificationActivity.classify(ORGANIZATIONID, TREASURYID, FLOWIDENTIFIERCODE);

assertEquals(iufClassificationActivityResult,expectedIufClassificationActivityResult);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.gov.pagopa.payhub.activities.utility.faker;

import it.gov.pagopa.payhub.activities.dto.classifications.ClassifyResultDTO;

public class ClassifyResultFaker {

public static ClassifyResultDTO buildClassifyResultDTO(Long organizationId){
return ClassifyResultDTO.builder()
.organizationId(organizationId)
.creditorReferenceId("IUV")
.regulationUniqueIdentifier("IUR")
.transferIndex(1)
.build();
}
}
Loading
Loading