generated from pagopa/template-payments-java-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: P4ADEV-1625 classifyiufactivity-retrieve-iuvs-save (#48)
- Loading branch information
1 parent
2ca15ce
commit f9462fa
Showing
11 changed files
with
312 additions
and
9 deletions.
There are no files selected for viewing
12 changes: 10 additions & 2 deletions
12
...a/it/gov/pagopa/payhub/activities/activity/classifications/IufClassificationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
71 changes: 71 additions & 0 deletions
71
.../gov/pagopa/payhub/activities/activity/classifications/IufClassificationActivityImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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.Transfer2ClassifyDTO; | ||
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; | ||
|
||
@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<Transfer2ClassifyDTO> transfers2classify = | ||
paymentsReportingDao.findByOrganizationIdAndIuf(organizationId, iuf) | ||
.stream() | ||
.map(paymentsReportingDTO -> | ||
Transfer2ClassifyDTO.builder() | ||
.iuv(paymentsReportingDTO.getCreditorReferenceId()) | ||
.iur(paymentsReportingDTO.getRegulationUniqueIdentifier()) | ||
.transferIndex(paymentsReportingDTO.getTransferIndex()) | ||
.build()) | ||
.toList(); | ||
|
||
if (transfers2classify.isEmpty()) { | ||
log.debug("Saving payments reporting found for organization id {} and iuf: {}", organizationId, iuf); | ||
saveClassification(organizationId, treasuryId, iuf); | ||
} | ||
|
||
return IufClassificationActivityResult.builder() | ||
.organizationId(organizationId) | ||
.transfers2classify(transfers2classify) | ||
.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()); | ||
} | ||
} |
21 changes: 15 additions & 6 deletions
21
src/main/java/it/gov/pagopa/payhub/activities/dao/ClassificationDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/it/gov/pagopa/payhub/activities/dto/classifications/ClassificationDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
18 changes: 18 additions & 0 deletions
18
.../it/gov/pagopa/payhub/activities/dto/classifications/IufClassificationActivityResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 Long organizationId; | ||
private List<Transfer2ClassifyDTO> transfers2classify; | ||
private boolean success; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/it/gov/pagopa/payhub/activities/dto/classifications/Transfer2ClassifyDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 Transfer2ClassifyDTO { | ||
private String iuv; | ||
private String iur; | ||
private int transferIndex; | ||
} |
112 changes: 112 additions & 0 deletions
112
.../gov/pagopa/payhub/activities/activity/classifications/IufClassificationActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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.Transfer2ClassifyDTO; | ||
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.ClassificationFaker; | ||
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 java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class IufClassificationActivityTest { | ||
@Mock | ||
private PaymentsReportingDao paymentsReportingDaoMock; | ||
|
||
@Mock | ||
private ClassificationDao classificationDaoMock; | ||
|
||
private IufClassificationActivity iufClassificationActivity; | ||
|
||
private static final Long ORGANIZATIONID = 1L; | ||
private static final Long TREASURYID = 1L; | ||
private static final String IUF = "IUF"; | ||
|
||
@BeforeEach | ||
void init() { | ||
iufClassificationActivity = new IufClassificationActivityImpl(paymentsReportingDaoMock, classificationDaoMock); | ||
} | ||
|
||
@AfterEach | ||
void verifyNoMoreInteractions(){ | ||
Mockito.verifyNoMoreInteractions(paymentsReportingDaoMock,classificationDaoMock); | ||
} | ||
|
||
@Test | ||
void givenReportedTransferWhenClassifyThenOk() { | ||
ClassificationDTO classificationDTO = ClassificationFaker.buildClassificationDTO(); | ||
|
||
PaymentsReportingDTO expectedPaymentsReportingDTO = PaymentsReportingFaker.buildClassifyResultDTO(); | ||
List<PaymentsReportingDTO> expectedPaymentsReportingDTOS = new ArrayList<>(); | ||
expectedPaymentsReportingDTOS.add(expectedPaymentsReportingDTO); | ||
|
||
List<Transfer2ClassifyDTO> expectedTransfer2ClassifyDTOS = | ||
expectedPaymentsReportingDTOS | ||
.stream() | ||
.map(paymentsReportingDTO -> | ||
Transfer2ClassifyDTO.builder() | ||
.iuv(paymentsReportingDTO.getCreditorReferenceId()) | ||
.iur(paymentsReportingDTO.getRegulationUniqueIdentifier()) | ||
.transferIndex(paymentsReportingDTO.getTransferIndex()) | ||
.build()) | ||
.toList(); | ||
|
||
IufClassificationActivityResult expectedIufClassificationActivityResult = | ||
IufClassificationActivityResult | ||
.builder() | ||
.organizationId(1L) | ||
.transfers2classify(expectedTransfer2ClassifyDTOS) | ||
.success(true) | ||
.build(); | ||
|
||
when(paymentsReportingDaoMock.findByOrganizationIdAndIuf(ORGANIZATIONID, IUF)) | ||
.thenReturn(expectedPaymentsReportingDTOS); | ||
|
||
IufClassificationActivityResult iufClassificationActivityResult = | ||
iufClassificationActivity.classify(ORGANIZATIONID, TREASURYID, IUF); | ||
|
||
assertEquals(iufClassificationActivityResult,expectedIufClassificationActivityResult); | ||
|
||
Mockito.verify(paymentsReportingDaoMock, Mockito.times(1)).findByOrganizationIdAndIuf(ORGANIZATIONID, IUF); | ||
Mockito.verify(classificationDaoMock, Mockito.times(0)).save(classificationDTO); | ||
} | ||
|
||
@Test | ||
void givenNoReportedTransferWhenClassifyThenAnomalyClassificationSave() { | ||
ClassificationDTO classificationDTO = ClassificationFaker.buildClassificationDTO(); | ||
|
||
IufClassificationActivityResult expectedIufClassificationActivityResult = | ||
IufClassificationActivityResult | ||
.builder() | ||
.organizationId(1L) | ||
.transfers2classify(new ArrayList<>()) | ||
.success(true) | ||
.build(); | ||
|
||
when(paymentsReportingDaoMock.findByOrganizationIdAndIuf(ORGANIZATIONID, IUF)) | ||
.thenReturn(new ArrayList<>()); | ||
|
||
IufClassificationActivityResult iufClassificationActivityResult = | ||
iufClassificationActivity.classify(ORGANIZATIONID, TREASURYID, IUF); | ||
|
||
assertEquals(iufClassificationActivityResult,expectedIufClassificationActivityResult); | ||
|
||
Mockito.verify(paymentsReportingDaoMock, Mockito.times(1)).findByOrganizationIdAndIuf(ORGANIZATIONID, IUF); | ||
Mockito.verify(classificationDaoMock, Mockito.times(1)).save(classificationDTO); | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
src/test/java/it/gov/pagopa/payhub/activities/utility/faker/ClassificationFaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package it.gov.pagopa.payhub.activities.utility.faker; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.classifications.ClassificationDTO; | ||
import it.gov.pagopa.payhub.activities.enums.ClassificationsEnum; | ||
|
||
public class ClassificationFaker { | ||
|
||
public static ClassificationDTO buildClassificationDTO(){ | ||
return ClassificationDTO.builder() | ||
.organizationId(1L) | ||
.treasuryId(1L) | ||
.iuf("IUF") | ||
.classificationsEnum(ClassificationsEnum.TES_NO_MATCH) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/it/gov/pagopa/payhub/activities/utility/faker/PaymentsReportingFaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.paymentsreporting.PaymentsReportingDTO; | ||
|
||
public class PaymentsReportingFaker { | ||
|
||
public static PaymentsReportingDTO buildClassifyResultDTO(){ | ||
return PaymentsReportingDTO.builder() | ||
.organizationId(1L) | ||
.creditorReferenceId("IUV") | ||
.regulationUniqueIdentifier("IUR") | ||
.transferIndex(1) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.20.0 | ||
1.20.2-SNAPSHOT |