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-1545 fdr ingestion actity implementation retrieval via query file validation #22

Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
615f97d
P4ADEV-1545 FdRIngestionActity added interface implementation and its…
macacia Nov 26, 2024
9e0ada7
P4ADEV-1545 FdRIngestionActity naming refactoring
macacia Nov 26, 2024
9f58e1f
P4ADEV-1545 FdRIngestionActity added service and test
macacia Nov 27, 2024
93450f8
P4ADEV-1545 FdRIngestionActity added utils and its test
macacia Nov 27, 2024
9780f00
P4ADEV-1545 FdRIngestionActity fix
macacia Nov 27, 2024
a5d451d
P4ADEV-1545 FdRIngestionActity fix
macacia Nov 27, 2024
45edff1
P4ADEV-1545 FdRIngestionActity refactored FileUtils.java and its tests
macacia Nov 27, 2024
88e6cea
P4ADEV-1545 FdRIngestionActity added missing test
macacia Nov 27, 2024
476d008
P4ADEV-1545 FdRIngestionActity added missing test
macacia Nov 27, 2024
474ea2f
P4ADEV-1545 FdRIngestionActity resolved sonar issues
macacia Nov 27, 2024
b898521
P4ADEV-1545 FdRIngestionActity fixed with sonar issues
macacia Nov 27, 2024
0789a33
P4ADEV-1545 FdRIngestionActity resolved sonar issues
macacia Nov 27, 2024
cfbdb39
P4ADEV-1545 FdRIngestionActity rename Activity
macacia Nov 28, 2024
d86cf20
P4ADEV-1545 FdRIngestionActity rename Activity
macacia Nov 28, 2024
141cc4b
P4ADEV-1545 ReportingflowIngestionActity added documentation
macacia Nov 28, 2024
7ef1f1f
Merge branch 'main' of https://github.com/pagopa/p4pa-payhub-activiti…
macacia Nov 28, 2024
71c5830
P4ADEV-1545 ReportingFlowIngestionActivity rename Activity
macacia Nov 28, 2024
c1f2cf6
P4ADEV-1545 moved packages
macacia Nov 28, 2024
af747db
feat:P4ADEV-1545-FdRIngestionActity-implementation-retrieval-via-quer…
marcomatteuccieng Nov 28, 2024
81fdcce
P4ADEV-1545 some refactor
macacia Nov 28, 2024
b7bfaef
P4ADEV-1545 fix test
macacia Nov 28, 2024
3ada04e
P4ADEV-1545 added java docs
macacia Nov 28, 2024
bd2bf69
P4ADEV-1545 resolved sonar security issues
macacia Nov 28, 2024
00c89a5
P4ADEV-1545 resolved sonar security issues
macacia Nov 28, 2024
e1ab12c
P4ADEV-1545 fixed
macacia Nov 28, 2024
cad3093
P4ADEV-1545 fixed sonar issues
macacia Nov 28, 2024
c2cbea5
P4ADEV-1545 fixed sonar issues
macacia Nov 28, 2024
cf1d135
P4ADEV-1545 fix to prevent zip bomb
macacia Nov 29, 2024
29ad416
P4ADEV-1545 fix to prevent zip bomb
macacia Nov 29, 2024
ed282f7
P4ADEV-1545 fix
macacia Nov 29, 2024
9ed8d19
Merge remote-tracking branch 'origin/main' into P4ADEV-1545-FdRIngest…
macacia Nov 29, 2024
3628a52
P4ADEV-1545 updated version
macacia Nov 29, 2024
c45eeb5
P4ADEV-1545 fixed sonar issues
macacia Nov 29, 2024
e65f935
P4ADEV-1545 fix sonar issues
macacia Nov 29, 2024
0c319ef
P4ADEV-1545 removed unused declaration
macacia Nov 29, 2024
f373eae
P4ADEV-1545 fixed javadocs
macacia Nov 29, 2024
54f9bee
P4ADEV-1545 resolved requested changes
macacia Dec 3, 2024
aed3a71
P4ADEV-1545 fix on requested changes
macacia Dec 3, 2024
9c5b6ac
P4ADEV-1545 moved variable into constructor
macacia Dec 3, 2024
19e4cd2
P4ADEV-1545 resolved requested changes
macacia Dec 3, 2024
854a661
Merge remote-tracking branch 'origin/main' into P4ADEV-1545-FdRIngest…
macacia Dec 3, 2024
653e8c8
P4ADEV-1545 fix test
macacia Dec 4, 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.payhub.activities.activity.fdr;
package it.gov.pagopa.payhub.activities.activity.ingestionflow;

/**
* Interface for the UpdateIngestionFlowStatusActivity.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.gov.pagopa.payhub.activities.activity.paymentsreporting;
import it.gov.pagopa.payhub.activities.dto.reportingflow.PaymentsReportingIngestionFlowFileActivityResult;

/**
* Interface for the PaymentsReportingIngestionFlowFileActivity.
* Defines methods for processing payments reporting files based on an IngestionFlowFile ID.
*/
public interface PaymentsReportingIngestionFlowFileActivity {

/**
* Processes a payments reporting file based on the provided IngestionFlowFile ID.
*
* @param ingestionFlowFileId the unique identifier related to the file to process.
* @return {@link PaymentsReportingIngestionFlowFileActivityResult} containing the list of IUFs and status.
*/
PaymentsReportingIngestionFlowFileActivityResult processFile(Long ingestionFlowFileId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package it.gov.pagopa.payhub.activities.activity.paymentsreporting;

import it.gov.pagopa.payhub.activities.dao.IngestionFlowFileDao;
import it.gov.pagopa.payhub.activities.dto.paymentsreporting.IngestionFlowFileDTO;
import it.gov.pagopa.payhub.activities.dto.reportingflow.PaymentsReportingIngestionFlowFileActivityResult;
import it.gov.pagopa.payhub.activities.exception.IngestionFlowNotFoundException;
import it.gov.pagopa.payhub.activities.service.ingestionflow.IngestionFlowFileRetrieverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Lazy
@Component
public class PaymentsReportingIngestionFlowFileActivityImpl implements PaymentsReportingIngestionFlowFileActivity {
private final IngestionFlowFileDao ingestionFlowFileDao;
private final IngestionFlowFileRetrieverService ingestionFlowFileRetrieverService;


public PaymentsReportingIngestionFlowFileActivityImpl(IngestionFlowFileDao ingestionFlowFileDao,
IngestionFlowFileRetrieverService ingestionFlowFileRetrieverService) {
this.ingestionFlowFileDao = ingestionFlowFileDao;
this.ingestionFlowFileRetrieverService = ingestionFlowFileRetrieverService;
}


@Override
public PaymentsReportingIngestionFlowFileActivityResult processFile(Long ingestionFlowFileId) {
List<String> iufList = new ArrayList<>();
boolean success = true;

try {
IngestionFlowFileDTO ingestionFlowFileDTO = ingestionFlowFileDao.findById(ingestionFlowFileId)
.orElseThrow(() -> new IngestionFlowNotFoundException("Cannot found ingestionFlow having id: "+ ingestionFlowFileId));

ingestionFlowFileRetrieverService.retrieveAndUnzipFile(Path.of(ingestionFlowFileDTO.getFilePathName()), ingestionFlowFileDTO.getFileName());

} catch (Exception e) {
log.error("Error during PaymentsReportingIngestionFlowFileActivity ingestionFlowFileId {} due to: {}", ingestionFlowFileId, e.getMessage());
success = false;
}
return new PaymentsReportingIngestionFlowFileActivityResult(iufList, success);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.payhub.activities.activity.fdr;
package it.gov.pagopa.payhub.activities.activity.utility;

/**
* Interface for SendEmailIngestionFlowActivity.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.gov.pagopa.payhub.activities.dao;

import it.gov.pagopa.payhub.activities.dto.paymentsreporting.IngestionFlowFileDTO;

import java.util.Optional;

/**
* Data Access Object (DAO) interface for managing ingestion flows.
*
* <p>
* The {@code IngestionFlowFileDao} provides an abstraction for accessing and manipulating
* ingestion flow data. It focuses on retrieving ingestion flow details from the underlying
* data source using defined operations.
* </p>
*
* @see IngestionFlowFileDTO
*/
public interface IngestionFlowFileDao {

/**
* Retrieves the {@link IngestionFlowFileDTO} entity based on the provided ingestion flow ID.
*
* @param ingestionFlowFileId the unique identifier of the ingestion flow to be retrieved.
* @return an {@link Optional} containing the requested {@link IngestionFlowFileDTO} if found,
* or an empty {@link Optional} if no matching entity exists.
*/
Optional<IngestionFlowFileDTO> findById(Long ingestionFlowFileId);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package it.gov.pagopa.payhub.activities.dto.paymentsreporting;

import it.gov.pagopa.payhub.activities.dto.OrganizationDTO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

/**
* Data Transfer Object (DTO) representing the details of an ingestion flow.
*
**/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class IngestionFlowFileDTO {
private Long ingestionFlowFileId;
private int version;
private OrganizationDTO orgId;
private String PspIdentifier;
private String flowIdentifierCode;
private Timestamp flowDateTime;
private String flowType;
private String flowTypeCode;
private String operatorName;
private String status;
private String filePathName;
private String fileName;
private Long downloadedFileSize;
private String requestTokenCode;
private Timestamp creationDate;
private Timestamp lastChangeDate;
private String fileSourceCode;
private String descriptionFileNameScraps;
private String errorCode;
private Long TotalRowsNumber;
private Long numberLinesImportedCorrectly;
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.payhub.activities.dto.fdr;
package it.gov.pagopa.payhub.activities.dto.reportingflow;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -7,12 +7,12 @@
import java.util.List;

/**
* DTO for the FdRIngestionResponse, representing the result of file processing.
* DTO for the PaymentsReportingIngestionFlowFileActivityResult, representing the result of file processing.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FdRIngestionActivityResult {
public class PaymentsReportingIngestionFlowFileActivityResult {
/** List of extracted IUFs */
private List<String> iufs;
/** Success flag for the operation */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package it.gov.pagopa.payhub.activities.exception;

/**
* A custom exception that represents errors related to activities and extends {@link RuntimeException}.
*
*/
public class ActivitiesException extends RuntimeException {

/**
* Constructs a new {@code ActivitiesException} with the specified detail message.
*
* @param message the detail message explaining the cause of the exception.
*/
public ActivitiesException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.gov.pagopa.payhub.activities.exception;

/**
* A custom exception that indicates the absence of an expected ingestion flow
* in the application's processing logic.
*
*/
public class IngestionFlowNotFoundException extends ActivitiesException {

/**
* Constructs a new {@code IngestionFlowNotFoundException} with the specified detail message.
*
* @param message the detail message explaining the cause of the exception.
*/
public IngestionFlowNotFoundException(String message) {
super(message);
}
}

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

/**
* A custom exception that indicates an invalid ingestion file encountered
* during the application's processing operations.
*
*/
public class InvalidIngestionFileException extends ActivitiesException {

/**
* Constructs a new {@code InvalidIngestionFileException} with the specified detail message.
*
* @param message the detail message explaining the cause of the exception.
*/
public InvalidIngestionFileException(String message) {
super(message);
}
}

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

import it.gov.pagopa.payhub.activities.exception.InvalidIngestionFileException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Service class responsible for validation files.
*/
@Lazy
@Slf4j
@Service
public class FileValidatorService {

/**
* Validates that the file exists and is a regular file.
*
* @param filePath the path to the file.
* @throws InvalidIngestionFileException if the file does not exist or is not a regular file.
*/
public void validateFile(Path filePath) {
if (!Files.exists(filePath) || !Files.isRegularFile(filePath)) {
throw new InvalidIngestionFileException("File not found: " + filePath);
}
}

/**
* Checks if the specified file is a valid archive by analyzing its signature.
*
* @param zipFilePath the path to the ZIP file to check.
* @return true if the file is a valid ZIP archive; false otherwise.
* @throws InvalidIngestionFileException if the file is not a valid archive.
*/
public boolean isArchive(Path zipFilePath) {
try (RandomAccessFile raf = new RandomAccessFile(zipFilePath.toFile(), "r")) {
int fileSignature = raf.readInt();
return fileSignature == 0x504B0304 || fileSignature == 0x504B0506 || fileSignature == 0x504B0708;
} catch (IOException e) {
throw new InvalidIngestionFileException("Invalid zip file");
}
}
}
Loading
Loading