diff --git a/src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java b/src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java index c02ca749..b7f64a6c 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/service/treasury/TreasuryOpiParserService.java @@ -39,11 +39,14 @@ public TreasuryIufResult parseData(Path treasuryOpiFilePath, IngestionFlowFileDT .findFirst() .orElseThrow(() -> new TreasuryOpiInvalidFileException("Cannot parse treasury Opi file " + ingestionFlowFile)); - List stringListMap = op2TreasuriesMap.get(TreasuryOperationEnum.INSERT); - stringListMap.forEach(treasuryDTO -> { - treasuryDao.insert(treasuryDTO); - iufList.add(treasuryDTO.getIuf()); - }); + List newTreasuries = op2TreasuriesMap.get(TreasuryOperationEnum.INSERT); + List iufList = stringListMap.stream() + .map(treasuryDTO -> { + treasuryDao.insert(treasuryDTO); + return treasuryDTO.getIuf(); + }) + .distinct() + .toList(); return new TreasuryIufResult(iufList.stream().toList(), true); }