Skip to content

Commit

Permalink
aligning ingestion flow file model
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioT90 committed Jan 2, 2025
1 parent e3f0343 commit 9b0fcda
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private IngestionFlowFileDTO findIngestionFlowFileRecord(Long ingestionFlowFileI
*/
private File retrieveFile(IngestionFlowFileDTO ingestionFlowFileDTO) throws IOException {
List<Path> paths = ingestionFlowFileRetrieverService
.retrieveAndUnzipFile(Path.of(ingestionFlowFileDTO.getFilePath()), ingestionFlowFileDTO.getFileName());
.retrieveAndUnzipFile(Path.of(ingestionFlowFileDTO.getFilePathName()), ingestionFlowFileDTO.getFileName());
return paths.getFirst().toFile();
}

Expand Down Expand Up @@ -142,8 +142,8 @@ private Pair<String, List<PaymentsReportingDTO>> parseData(File ingestionFlowFil
* @throws IOException if an error occurs during file movement or directory creation.
*/
private void archive(IngestionFlowFileDTO ingestionFlowFileDTO) throws IOException {
Path originalFilePath = Paths.get(ingestionFlowFileDTO.getFilePath(), ingestionFlowFileDTO.getFileName());
Path targetDirectory = Paths.get(ingestionFlowFileDTO.getFilePath(), archiveDirectory);
Path originalFilePath = Paths.get(ingestionFlowFileDTO.getFilePathName(), ingestionFlowFileDTO.getFileName());
Path targetDirectory = Paths.get(ingestionFlowFileDTO.getFilePathName(), archiveDirectory);
ingestionFlowFileArchiverService.archive(List.of(originalFilePath), targetDirectory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ private IngestionFlowFileDTO findIngestionFlowFileRecord(Long ingestionFlowFileI
private List<Path> retrieveFiles(IngestionFlowFileDTO ingestionFlowFileDTO) throws IOException {

return ingestionFlowFileRetrieverService
.retrieveAndUnzipFile(Path.of(ingestionFlowFileDTO.getFilePath()), ingestionFlowFileDTO.getFileName());
.retrieveAndUnzipFile(Path.of(ingestionFlowFileDTO.getFilePathName()), ingestionFlowFileDTO.getFileName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;

@Data
@Builder(toBuilder = true)
Expand All @@ -18,25 +18,25 @@ public class IngestionFlowFileDTO implements Serializable {

private Long ingestionFlowFileId;
private IngestionFlowFileType flowFileType;
private String mappedExternalUserId;
private int version;
private OrganizationDTO org;
private String status;
private String iuf;
private Long numTotalRows;
private Long numCorrectlyImportedRows;
private Date creationDate;
private Date lastUpdateDate;
private Instant creationDate;
private Instant lastUpdateDate;
private boolean flagActive;
private String operatorName;
private String operatorExternalUserId;
private Boolean flagSpontaneous;
private String filePath;
private String filePathName;
private String fileName;
private Long pdfGenerated;
private String codRequestToken;
private String codError;
private String pspIdentifier;
private LocalDateTime flowDateTime;
private Long fileSize;
private String fileSourceCode;
private String discardFileName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public IngestionFlowFileEmailDestinationRetrieverService(AuthzService authzServi
}

public void configure(IngestionFlowFileDTO ingestionFlowFileDTO, EmailDTO emailDTO) {
UserInfo userInfoDTO = authzService.getOperatorInfo(ingestionFlowFileDTO.getMappedExternalUserId());
UserInfo userInfoDTO = authzService.getOperatorInfo(ingestionFlowFileDTO.getOperatorExternalUserId());
Optional<OrganizationDTO> organizationDTO = organizationService.getOrganizationByIpaCode(ingestionFlowFileDTO.getOrg().getIpaCode());

emailDTO.setTo(new String[]{userInfoDTO.getEmail()});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<PaymentsReportingDTO> mapToDtoList(CtFlussoRiversamento ctFlussoRive
PaymentsReportingDTO.PaymentsReportingDTOBuilder builder = PaymentsReportingDTO.builder()
.creationDate(Instant.now())
.lastUpdateDate(Instant.now())
.acquiringDate(ingestionFlowFileDTO.getCreationDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())
.acquiringDate(ingestionFlowFileDTO.getCreationDate().atZone(ZoneId.systemDefault()).toLocalDate())
.organizationId(ingestionFlowFileDTO.getOrg().getOrgId())
.ingestionFlowFileId(ingestionFlowFileDTO.getIngestionFlowFileId())
.pspIdentifier(ctFlussoRiversamento.getIstitutoMittente().getDenominazioneMittente())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import org.mockito.junit.jupiter.MockitoExtension;

import static it.gov.pagopa.payhub.activities.utility.faker.DebtPositionFaker.buildDebtPositionDTO;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
public class SaveDebtPositionActivityTest {
class SaveDebtPositionActivityTest {

@Mock
private DebtPositionDao debtPositionDao;
Expand All @@ -29,12 +29,13 @@ void init(){

@Test
void givenSaveDebtPositionThenSuccess() {
Mockito.when(debtPositionDao.save(buildDebtPositionDTO())).thenReturn(buildDebtPositionDTO());
DebtPositionDTO debtPosition = buildDebtPositionDTO();
Mockito.when(debtPositionDao.save(debtPosition)).thenReturn(debtPosition);

DebtPositionDTO debtPosition =
saveDebtPositionActivity.saveDebtPosition(buildDebtPositionDTO());
DebtPositionDTO result =
saveDebtPositionActivity.saveDebtPosition(debtPosition);

verify(debtPositionDao, times(1)).save(buildDebtPositionDTO());
assertEquals(debtPosition, buildDebtPositionDTO());
verify(debtPositionDao, times(1)).save(debtPosition);
assertSame(result, debtPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ void givenSuccessfullConditionsWhenProcessFileThenOk() throws IOException {
IngestionFlowFileDTO mockFlowDTO = IngestionFlowFileDTO.builder()
.ingestionFlowFileId(ingestionFlowFileId)
.fileName("valid-file.zip")
.filePath(workingDir.toString())
.filePathName(workingDir.toString())
.flowFileType(FLOW_FILE_TYPE)
.build();
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePath()).resolve(mockFlowDTO.getFileName()));
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());
Expand All @@ -102,14 +102,14 @@ void givenSuccessfullConditionsWhenProcessFileThenOk() throws IOException {

when(ingestionFlowFileDaoMock.findById(ingestionFlowFileId)).thenReturn(Optional.of(mockFlowDTO));
doReturn(mockedListPath).when(ingestionFlowFileRetrieverServiceMock)
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());
when(flussoRiversamentoUnmarshallerServiceMock.unmarshal(filePath.toFile())).thenReturn(ctFlussoRiversamento);

doNothing().when(paymentsReportingIngestionFlowFileValidatorServiceMock).validateOrganization(ctFlussoRiversamento, mockFlowDTO);
when(paymentsReportingMapperServiceMock.mapToDtoList(ctFlussoRiversamento, mockFlowDTO)).thenReturn(dtoList);
doReturn(dtoList).when(paymentsReportingDaoMock).saveAll(dtoList);
doNothing().when(ingestionFlowFileArchiverServiceMock)
.archive(mockedListPath, Path.of(mockFlowDTO.getFilePath(), TARGET_DIR));
.archive(mockedListPath, Path.of(mockFlowDTO.getFilePathName(), TARGET_DIR));

// When
PaymentsReportingIngestionFlowFileActivityResult result = ingestionActivity.processFile(ingestionFlowFileId);
Expand Down Expand Up @@ -140,15 +140,15 @@ void givenIngestionFlowFileRetrieverServiceExceptionWhenProcessFileThenFails() t
IngestionFlowFileDTO mockFlowDTO = IngestionFlowFileDTO.builder()
.ingestionFlowFileId(ingestionFlowFileId)
.fileName("valid-file.zip")
.filePath(workingDir.toString())
.filePathName(workingDir.toString())
.flowFileType(FLOW_FILE_TYPE)
.build();

when(ingestionFlowFileDaoMock.findById(ingestionFlowFileId)).thenReturn(Optional.of(mockFlowDTO));

doThrow(new RuntimeException("Setup process failed"))
.when(ingestionFlowFileRetrieverServiceMock)
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());

// When
PaymentsReportingIngestionFlowFileActivityResult result = ingestionActivity.processFile(ingestionFlowFileId);
Expand All @@ -157,7 +157,7 @@ void givenIngestionFlowFileRetrieverServiceExceptionWhenProcessFileThenFails() t
assertFalse(result.isSuccess());
verify(ingestionFlowFileDaoMock, times(1)).findById(ingestionFlowFileId);
verify(ingestionFlowFileRetrieverServiceMock, times(1))
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());
}

@Test
Expand All @@ -167,17 +167,17 @@ void givenUnmarshallingExceptionWhenProcessFileThenFails() throws Exception {
IngestionFlowFileDTO mockFlowDTO = IngestionFlowFileDTO.builder()
.ingestionFlowFileId(ingestionFlowFileId)
.fileName("valid-file.zip")
.filePath(workingDir.toString())
.filePathName(workingDir.toString())
.flowFileType(FLOW_FILE_TYPE)
.build();
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePath()).resolve(mockFlowDTO.getFileName()));
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePathName()).resolve(mockFlowDTO.getFileName()));
List<Path> mockedListPath = List.of(filePath);
PaymentsReportingIngestionFlowFileActivityResult expected =
new PaymentsReportingIngestionFlowFileActivityResult(Collections.emptyList(), false, "error occured");

when(ingestionFlowFileDaoMock.findById(ingestionFlowFileId)).thenReturn(Optional.of(mockFlowDTO));
doReturn(mockedListPath).when(ingestionFlowFileRetrieverServiceMock)
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());
when(flussoRiversamentoUnmarshallerServiceMock.unmarshal(filePath.toFile())).thenThrow(new ActivitiesException("error occured"));
// When
PaymentsReportingIngestionFlowFileActivityResult result = ingestionActivity.processFile(ingestionFlowFileId);
Expand Down Expand Up @@ -210,19 +210,19 @@ void givenValidationExceptionWhenProcessFileThenFails() throws Exception {
IngestionFlowFileDTO mockFlowDTO = IngestionFlowFileDTO.builder()
.ingestionFlowFileId(ingestionFlowFileId)
.fileName("valid-file.zip")
.filePath(workingDir.toString())
.filePathName(workingDir.toString())
.flowFileType(FLOW_FILE_TYPE)
.org(OrganizationDTO.builder().orgFiscalCode("0").build())
.build();
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePath()).resolve(mockFlowDTO.getFileName()));
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePathName()).resolve(mockFlowDTO.getFileName()));
List<Path> mockedListPath = List.of(filePath);
ctFlussoRiversamento.setIdentificativoFlusso("idFlow");
PaymentsReportingIngestionFlowFileActivityResult expected =
new PaymentsReportingIngestionFlowFileActivityResult(Collections.emptyList(), false, "invalid");

when(ingestionFlowFileDaoMock.findById(ingestionFlowFileId)).thenReturn(Optional.of(mockFlowDTO));
doReturn(mockedListPath).when(ingestionFlowFileRetrieverServiceMock)
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());
when(flussoRiversamentoUnmarshallerServiceMock.unmarshal(filePath.toFile())).thenReturn(ctFlussoRiversamento);
doThrow(new InvalidIngestionFlowFileDataException("invalid"))
.when(paymentsReportingIngestionFlowFileValidatorServiceMock).validateOrganization(ctFlussoRiversamento, mockFlowDTO);
Expand All @@ -241,10 +241,10 @@ void givenPaymentsReportingExceptionWhenProcessFileThenFails() throws Exception
IngestionFlowFileDTO mockFlowDTO = IngestionFlowFileDTO.builder()
.ingestionFlowFileId(ingestionFlowFileId)
.fileName("valid-file.zip")
.filePath(workingDir.toString())
.filePathName(workingDir.toString())
.flowFileType(FLOW_FILE_TYPE)
.build();
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePath()).resolve(mockFlowDTO.getFileName()));
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePathName()).resolve(mockFlowDTO.getFileName()));
List<Path> mockedListPath = List.of(filePath);
ctFlussoRiversamento = new CtFlussoRiversamento();
ctFlussoRiversamento.setIdentificativoFlusso("idFlow");
Expand All @@ -255,7 +255,7 @@ void givenPaymentsReportingExceptionWhenProcessFileThenFails() throws Exception

when(ingestionFlowFileDaoMock.findById(ingestionFlowFileId)).thenReturn(Optional.of(mockFlowDTO));
doReturn(mockedListPath).when(ingestionFlowFileRetrieverServiceMock)
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());
when(flussoRiversamentoUnmarshallerServiceMock.unmarshal(filePath.toFile())).thenReturn(ctFlussoRiversamento);

doNothing().when(paymentsReportingIngestionFlowFileValidatorServiceMock).validateOrganization(ctFlussoRiversamento, mockFlowDTO);
Expand All @@ -276,10 +276,10 @@ void givenIOExceptionWhenProcessFileThenFails() throws IOException {
IngestionFlowFileDTO mockFlowDTO = IngestionFlowFileDTO.builder()
.ingestionFlowFileId(ingestionFlowFileId)
.fileName("valid-file.zip")
.filePath(workingDir.toString())
.filePathName(workingDir.toString())
.flowFileType(FLOW_FILE_TYPE)
.build();
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePath()).resolve(mockFlowDTO.getFileName()));
Path filePath = Files.createFile(Path.of(mockFlowDTO.getFilePathName()).resolve(mockFlowDTO.getFileName()));
List<Path> mockedListPath = List.of(filePath);
ctFlussoRiversamento = new CtFlussoRiversamento();
ctFlussoRiversamento.setIdentificativoFlusso("idFlow");
Expand All @@ -290,15 +290,15 @@ void givenIOExceptionWhenProcessFileThenFails() throws IOException {

when(ingestionFlowFileDaoMock.findById(ingestionFlowFileId)).thenReturn(Optional.of(mockFlowDTO));
doReturn(mockedListPath).when(ingestionFlowFileRetrieverServiceMock)
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePath()), mockFlowDTO.getFileName());
.retrieveAndUnzipFile(Path.of(mockFlowDTO.getFilePathName()), mockFlowDTO.getFileName());
when(flussoRiversamentoUnmarshallerServiceMock.unmarshal(filePath.toFile())).thenReturn(ctFlussoRiversamento);

doNothing().when(paymentsReportingIngestionFlowFileValidatorServiceMock).validateOrganization(ctFlussoRiversamento, mockFlowDTO);
when(paymentsReportingMapperServiceMock.mapToDtoList(ctFlussoRiversamento, mockFlowDTO)).thenReturn(dtoList);
doReturn(dtoList).when(paymentsReportingDaoMock).saveAll(dtoList);

doThrow(new IOException("error occured")).when(ingestionFlowFileArchiverServiceMock)
.archive(mockedListPath, Path.of(mockFlowDTO.getFilePath(), TARGET_DIR));
.archive(mockedListPath, Path.of(mockFlowDTO.getFilePathName(), TARGET_DIR));

// When
PaymentsReportingIngestionFlowFileActivityResult result = ingestionActivity.processFile(ingestionFlowFileId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import it.gov.pagopa.payhub.activities.enums.IngestionFlowFileType;
import it.gov.pagopa.payhub.activities.service.ingestionflow.IngestionFlowFileRetrieverService;
import it.gov.pagopa.payhub.activities.service.treasury.TreasuryOpiParserService;
import it.gov.pagopa.payhub.activities.service.treasury.TreasuryUnmarshallerService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -31,8 +30,6 @@ class TreasuryOpiIngestionActivityTest {
@Mock
private IngestionFlowFileRetrieverService ingestionFlowFileRetrieverService;
@Mock
private TreasuryUnmarshallerService treasuryUnmarshallerService;
@Mock
private TreasuryOpiParserService treasuryOpiParserService;

private TreasuryOpiIngestionActivity treasuryOpiIngestionActivity;
Expand Down Expand Up @@ -60,7 +57,7 @@ void givenValidIngestionFlowWhenProcessFileThenOk() throws IOException {
Long ingestionFlowFileId = 1L;
IngestionFlowFileDTO ingestionFlowFileDTO = new IngestionFlowFileDTO();
ingestionFlowFileDTO.setFlowFileType(IngestionFlowFileType.OPI);
ingestionFlowFileDTO.setFilePath("/test/path");
ingestionFlowFileDTO.setFilePathName("/test/path");
ingestionFlowFileDTO.setFileName("testFile.zip");

Path mockPath = mock(Path.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void givenNoOrganizationWhenConfigureThenOk() {
IngestionFlowFileDTO ingestionFlowFileDTO = IngestionFlowFileFaker.buildIngestionFlowFileDTO();
UserInfo userInfo = UserInfoFaker.buildUserInfo();

Mockito.when(authzServiceMock.getOperatorInfo(ingestionFlowFileDTO.getMappedExternalUserId()))
Mockito.when(authzServiceMock.getOperatorInfo(ingestionFlowFileDTO.getOperatorExternalUserId()))
.thenReturn(userInfo);

Mockito.when(organizationServiceMock.getOrganizationByIpaCode(ingestionFlowFileDTO.getOrg().getIpaCode()))
Expand All @@ -74,7 +74,7 @@ void givenOrganizationWithSameEmailWhenConfigureThenOk() {
OrganizationDTO organizationDTO = OrganizationFaker.buildOrganizationDTO();
organizationDTO.setAdminEmail(userInfo.getEmail());

Mockito.when(authzServiceMock.getOperatorInfo(ingestionFlowFileDTO.getMappedExternalUserId()))
Mockito.when(authzServiceMock.getOperatorInfo(ingestionFlowFileDTO.getOperatorExternalUserId()))
.thenReturn(userInfo);

Mockito.when(organizationServiceMock.getOrganizationByIpaCode(ingestionFlowFileDTO.getOrg().getIpaCode()))
Expand All @@ -97,7 +97,7 @@ void givenOrganizationWithDifferentEmailWhenConfigureThenOk() {
UserInfo userInfo = UserInfoFaker.buildUserInfo();
OrganizationDTO organizationDTO = OrganizationFaker.buildOrganizationDTO();

Mockito.when(authzServiceMock.getOperatorInfo(ingestionFlowFileDTO.getMappedExternalUserId()))
Mockito.when(authzServiceMock.getOperatorInfo(ingestionFlowFileDTO.getOperatorExternalUserId()))
.thenReturn(userInfo);

Mockito.when(organizationServiceMock.getOrganizationByIpaCode(ingestionFlowFileDTO.getOrg().getIpaCode()))
Expand Down
Loading

0 comments on commit 9b0fcda

Please sign in to comment.