Skip to content

Commit

Permalink
first implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanotamburini committed Dec 23, 2024
1 parent 2ca15ce commit e944a99
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityMethod;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.PaymentsReportingDTO;

import java.util.List;

/**
* Interface for defining an activity to process Transfer classifications.
Expand All @@ -19,4 +22,16 @@ public interface TransferClassificationActivity {
*/
@ActivityMethod
void classify(Long orgId, String iuv, String iur, int transferIndex);

/**
* retrieve Transfer data by semantic key
*
* @param orgId the unique identifier of the organization
* @param iuv the unique identifier of the payment (IUV)
* @param iur the identifier of the receipt associated with the payment
* @param transferIndex the index of the transfer to be classified
* @return List of PaymentsReportingDTO object containing data found (may be 1 object)
*/
@ActivityMethod
List<PaymentsReportingDTO> retrievePaymentReportingBySemanticKey(Long orgId, String iuv, String iur, int transferIndex);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
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.dao.TransferDao;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.PaymentsReportingDTO;
import it.gov.pagopa.payhub.activities.exception.ClassificationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

@Lazy
@Slf4j
@Component
public class TransferClassificationActivityImpl implements TransferClassificationActivity {
private final ClassificationDao classificationDao;
private final TransferDao transferDao;
private final PaymentsReportingDao paymentsReportingDao;

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

@Override
Expand All @@ -28,4 +35,11 @@ public void classify(Long orgId, String iuv, String iur, int transferIndex) {
}
transferDao.findBySemanticKey(orgId, iuv, iur, transferIndex);
}

@Override
public List<PaymentsReportingDTO> retrievePaymentReportingBySemanticKey(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);
return paymentsReportingDao.findBySemanticKey(orgId, iuv, iur, transferIndex);
}

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

/**
* find payment reporting by semantic key
*
* @param orgId organization id
* @param iuv payment identifier
* @param iur reporting identifier
* @param transferIndex transfer index
* @return List of objects PaymentsReportingDTO returned (may be 1 object)
*/
List<PaymentsReportingDTO> findBySemanticKey(Long orgId, String iuv, String iur, int transferIndex);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
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.dao.TransferDao;
import it.gov.pagopa.payhub.activities.dto.TransferDTO;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.PaymentsReportingDTO;
import it.gov.pagopa.payhub.activities.exception.ClassificationException;
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.TransferFaker.buildTransferDTO;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;

Expand All @@ -28,11 +32,14 @@ class TransferClassificationActivityImplTest {
@Mock
private TransferDao transferDaoMock;

@Mock
private PaymentsReportingDao paymentsReportingDaoMock;

private TransferClassificationActivity activity;

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

@Test
Expand All @@ -54,4 +61,22 @@ void givenFailedFindTransferWhenClassifyThenClassificationFailed() {
when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenThrow(new ClassificationException("retrieving failed"));
assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed");
}

@Test
void givenRetrievePaymentReportingBySemanticKeySuccess() {
List<PaymentsReportingDTO> paymentsReportingDTOS = new ArrayList<>();
paymentsReportingDTOS.add(new PaymentsReportingDTO());
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX))
.thenReturn(paymentsReportingDTOS);
assertDoesNotThrow(() -> activity.retrievePaymentReportingBySemanticKey(ORGANIZATION, IUV, IUR, INDEX));
}


@Test
void givenRetrievePaymentReportingBySemanticKeyFailed() {
when(paymentsReportingDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX))
.thenThrow(new ClassificationException("retrieving payment reporting failed"));
assertThrows(ClassificationException.class, () -> activity.retrievePaymentReportingBySemanticKey(ORGANIZATION, IUV, IUR, INDEX), "retrievePaymentReportingBySemanticKey failed");
}

}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20.0
1.20.3

0 comments on commit e944a99

Please sign in to comment.