-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
feat: P4ADEV-1658 wf treasury opi ingestion file reading validating save data #50
Conversation
…on-file-operation
…ration' into P4ADEV-1568-WF-TreasuryOpiIngestion-file-reading-validating-save-data
…ion' into P4ADEV-1568-WF-TreasuryOpiIngestion-file-reading-validating-save-data
…ding-validating-save-data
…ding-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
…y/TreasuryOpiIngestionActivityImpl.java Co-authored-by: antonioT90 <[email protected]>
…-Opi-validation' into P4ADEV-1657-TreasuryOpiIngestion-Opi-validation
…ding-validating-save-data
…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
|
||
import it.gov.pagopa.payhub.activities.dto.treasury.FlussoTesoreriaPIIDTO; | ||
|
||
public interface FlussoTesoreriaPIIDao { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted FlussoTesoreriaPIIDTO
private byte[] taxCodeHash; | ||
private byte[] vatNumberHash; | ||
private byte[] lastNameHash; | ||
|
||
private Long personalDataId; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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:
- TreasuryOpiv14HandlerService
- 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);
There was a problem hiding this comment.
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
src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
…/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
Quality Gate failedFailed conditions |
|
||
Long insert(TreasuryDTO treasuryDto); | ||
|
||
int deleteByIdEnteAndCodBollettaAndAnnoBolletta(Long id, String codBolletta, String annoBolletta); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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>>> { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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
Description
List of Changes
Motivation and Context
Reading files and validate them. save data
How Has This Been Tested?
Types of changes
Checklist: