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-1658 wf treasury opi ingestion file reading validating save data #50

Open
wants to merge 89 commits into
base: main
Choose a base branch
from

Conversation

domenicogi
Copy link
Collaborator

Description

List of Changes

Motivation and Context

Reading files and validate them. save data

How Has This Been Tested?

  • Pre-Deploy Test
    • Unit
    • Integration (Narrow)
  • Post-Deploy Test
    • Isolated Microservice
    • Broader Integration
    • Acceptance
    • Performance & Load

Types of changes

  • PATCH - Bug fix (backwards compatible bug fixes)
  • MINOR - New feature (add functionality in a backwards compatible manner)
  • MAJOR - Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

domenicogi and others added 30 commits December 10, 2024 12:20
…ration' into P4ADEV-1568-WF-TreasuryOpiIngestion-file-reading-validating-save-data
…ion' into P4ADEV-1568-WF-TreasuryOpiIngestion-file-reading-validating-save-data
…4ADEV-1658-WF-TreasuryOpiIngestion-file-reading-validating-save-data
…ion-file-operation' into P4ADEV-1656-WF-TreasuryOpiIngestion-file-operation
…ion-file-operation' into P4ADEV-1656-WF-TreasuryOpiIngestion-file-operation
…o P4ADEV-1657-TreasuryOpiIngestion-Opi-validation

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
…4ADEV-1658-WF-TreasuryOpiIngestion-file-reading-validating-save-data

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
…y/TreasuryOpiIngestionActivityImpl.java

Co-authored-by: antonioT90 <[email protected]>
…o P4ADEV-1657-TreasuryOpiIngestion-Opi-validation

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
#	src/test/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityTest.java
domenicogi and others added 17 commits December 20, 2024 10:18
…y/TreasuryOpiIngestionActivityImpl.java

Co-authored-by: antonioT90 <[email protected]>
…-Opi-validation' into P4ADEV-1657-TreasuryOpiIngestion-Opi-validation
…4ADEV-1658-WF-TreasuryOpiIngestion-file-reading-validating-save-data

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
…4ADEV-1658-WF-TreasuryOpiIngestion-file-reading-validating-save-data

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
#	src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java
#	src/test/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityTest.java
#	src/test/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserServiceTest.java
…ding-validating-save-data

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
#	src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java
#	src/test/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityTest.java
#	src/test/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserServiceTest.java
#	src/test/resources/treasury/OPI_GIORNALE_DI_CASSA_V_1_4.VALID.xml
#	src/test/resources/treasury/OPI_GIORNALE_DI_CASSA_V_1_6_1.VALID.xml
@domenicogi domenicogi marked this pull request as ready for review December 20, 2024 17:24

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

public interface FlussoTesoreriaPIIDao {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PII segregation is not demanded to the activity, but to the DAO!
Activity should not be aware of such persistence requirement

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted FlussoTesoreriaPIIDao and all references

@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FlussoTesoreriaPIIDTO {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PII segregation is not demanded to the activity, but to the DAO!
Activity should not be aware of such persistence requirement.

ps: please align with @marcomatteuccieng to check if we will store all these info, treasury should not more have PII

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted FlussoTesoreriaPIIDTO

Comment on lines 60 to 64
private byte[] taxCodeHash;
private byte[] vatNumberHash;
private byte[] lastNameHash;

private Long personalDataId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PII segregation is not demanded to the activity, but to the DAO!
Activity should not be aware of such persistence requirement

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted hash properties

return List.of();


assert versione != null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not use assert to throw an errore if a condition fails!
assertions could be disabled, let's just throw an exception...

Anyway, version cannot be null! you could simply remove this line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed assert



assert versione != null;
if (!treasuryValidatorService.validatePageSize(flussoGiornaleDiCassa14, flussoGiornaleDiCassa161, zipFileSize, versione)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having a single method inside which you will write many if/else based on the version, let's just split and move the logics on a separate service, calling it directly on the try/catch above to build the common output of both processes.

You could have 2 Services:

  1. TreasuryOpiv14HandlerService
  2. TreasuryOpiv161HandlerService

These services will work the related DTOs, in order to avoid classes where you are actually using Object and cast, or again a if based on the version field...

Such services could extend a common base abstract class using generics to reference the version related type.
This service will implement the Strategy design pattern (BaseTreasuryOpiHandlerService) which will contain the common algorithm to process the file:

Map<TreasuryOpEnum, List<Pair<TreasuryDTO, FlussoTesoreriaPIIDTO>>> handle(T treasuryOpiData, IngestionFlowFileDTO ingestionFlowFileDTO, int totalNumberOfTreasuryOpiFiles) {
   validateTotalNumberOfPages(treasuryOpiData, totalNumberOfTreasuryOpiFiles);
}

private void validateTotalNumberOfPages(T treasuryOpiData, int totalNumberOfTreasuryOpiFiles) {
   if(getTotalNumberOfTreasuryOpiFiles(treasuryOpiData) != totalNumberOfTreasuryOpiFiles){
      throw new TreasuryOpiInvalidFileException(...); // if you want to log also the file name, add it as input to your methods
   }
...
}

protected abstract int getTotalNumberOfTreasuryOpiFiles(T treasuryOpiData);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done refactor according to Strategy pattern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, split this class in order to have mappers specialized on the particular input instead of using the reflection to get data!

Reflection is a very slow method, very error-prone, to avoid if possible!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done refactor according to Strategy pattern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, split this into separate class specialized on the particular type instead of using reflection

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done refactor according to Strategy pattern

domenicogi and others added 3 commits December 23, 2024 11:07
…/TreasuryOpiParserService.java

Co-authored-by: antonioT90 <[email protected]>
…ding-validating-save-data

# Conflicts:
#	src/main/java/it/gov/pagopa/payhub/activities/activity/treasury/TreasuryOpiIngestionActivityImpl.java
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
22.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud


Long insert(TreasuryDTO treasuryDto);

int deleteByIdEnteAndCodBollettaAndAnnoBolletta(Long id, String codBolletta, String annoBolletta);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new column names

return new TreasuryIufResult(iufList,true);
return ingestionFlowFiles.stream()
.map(path ->treasuryOpiParserService.parseData(path, ingestionFlowFileDTO, ingestionFlowFiles.size()))
.toList().get(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why get(0)?

import java.util.HashMap;
import java.util.Map;

public class TreasuryBaseOpiHandlerService {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this tò retrieve dynamically classes! Spring allow to inject beans using Generic thus this class could be removed (moreover you were using @SuppressWarning which should be avoided! Using It could be and hint of bad design)


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

public interface TreasuryMapperService<T, U> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't U Always the same type?


import java.util.*;

public class TreasuryOpi14MapperService implements TreasuryMapperService<FlussoGiornaleDiCassa, Map<TreasuryOperationEnum, List<TreasuryDTO>>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of handling a List to transform into a map, let's handle a single item at time.
The mapped type should be the same for all mappers, the reduce operatori ti build the final map could be implementer once on the strategy class

public class TreasuryOpi14MapperService implements TreasuryMapperService<FlussoGiornaleDiCassa, Map<TreasuryOperationEnum, List<TreasuryDTO>>> {
@Override
public Map<TreasuryOperationEnum, List<TreasuryDTO>> apply(FlussoGiornaleDiCassa fGC, IngestionFlowFileDTO ingestionFlowFileDTO) {
Map<TreasuryOperationEnum, List<TreasuryDTO>> resultMap = new EnumMap<>(TreasuryOperationEnum.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grouping Logic could be implemented once in the strategy class.
Moreover, this could be written cleaner and more optimized using collection's stream api and groupingBy collector

List<TreasuryErrorDTO> treasuryErrorDTOList;

public TreasuryOpi14ValidatorService() {
treasuryErrorDTOList = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class created for each row?
If not, you cannot use an instance variabile
If yes, probably you could avoid to create a new class for each record just to collect error data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: you could also create n classes for each check, implementing the same interface
Next you could inject It using List<...> type in order to let Spring collect all the validators and execute the checks in a more readable and maintanable way (easier to test because you will have 1 class per check to test)



if (version == TreasuryVersionEnum.V_14) {
TreasuryValidatorService < FlussoGiornaleDiCassa> validatorService =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use dependency injection to ask tò Spring for a Bean of type
private TreasuryValidatorService<...>
Instead of having a class to hold instances

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants