From 90dd51ed381cddfa9220a09477d1e386eeeb9a0d Mon Sep 17 00:00:00 2001 From: Eugen Begiqi Date: Tue, 3 Sep 2024 17:53:24 +0200 Subject: [PATCH] SELC-5438: Refactoring --- ...vAggregate.java => CsvAggregateAppIo.java} | 34 +++++++++++---- .../onboarding/model/CsvAggregatePagoPa.java | 16 ++++--- .../onboarding/model/CsvAggregateSend.java | 8 ++-- .../service/AggregatesServiceDefault.java | 42 +++++++++---------- 4 files changed, 61 insertions(+), 39 deletions(-) rename apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/{CsvAggregate.java => CsvAggregateAppIo.java} (66%) diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregate.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIo.java similarity index 66% rename from apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregate.java rename to apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIo.java index 7a560d681..2681153ce 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregate.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIo.java @@ -4,23 +4,40 @@ import lombok.Data; @Data -public class CsvAggregate implements Csv { +public class CsvAggregateAppIo implements Csv { @CsvBindByPosition(position = 0) - private String taxCode; + private String aggregateName; + @CsvBindByPosition(position = 1) - private String description; + private String pec; + @CsvBindByPosition(position = 2) - private String vatNumber; + private String taxCode; + @CsvBindByPosition(position = 3) - private String subunitType; + private String vatNumber; + @CsvBindByPosition(position = 4) - private String subunitCode; - @CsvBindByPosition(position = 5) private String address; + + @CsvBindByPosition(position = 5) + private String city; + @CsvBindByPosition(position = 6) - private String originId; + private String province; + + @CsvBindByPosition(position = 7) + private String ipaCode; + @CsvBindByPosition(position = 8) + private String subunitType; + + @CsvBindByPosition(position = 9) + private String subunitCode; + + @CsvBindByPosition(position = 10) + private String originId; private Integer rowNumber; @Override @@ -28,5 +45,4 @@ public void setRowNumber(int lineNumber) { this.rowNumber = lineNumber; } - } diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java index c1e7cedbf..436db2113 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java @@ -10,7 +10,7 @@ public class CsvAggregatePagoPa implements Csv { private String aggregateName; @CsvBindByPosition(position = 1) - private String emailPec; + private String pec; @CsvBindByPosition(position = 2) private String taxNumber; @@ -22,18 +22,24 @@ public class CsvAggregatePagoPa implements Csv { private String address; @CsvBindByPosition(position = 5) - private String taxCodePT; + private String city; @CsvBindByPosition(position = 6) - private String vatNumberPT; + private String province; @CsvBindByPosition(position = 7) - private String iban; + private String aggragateNamePT; @CsvBindByPosition(position = 8) - private String service; + private String taxCodePT; @CsvBindByPosition(position = 9) + private String iban; + + @CsvBindByPosition(position = 10) + private String service; + + @CsvBindByPosition(position = 11) private String syncAsyncMode; private Integer rowNumber; diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java index 27d710e6a..1eab9cded 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java @@ -40,16 +40,16 @@ public class CsvAggregateSend implements Csv { private String subunitCode; @CsvBindByPosition(position = 11) - private String adminAgreggateName; + private String adminAggregateName; @CsvBindByPosition(position = 12) - private String adminAgreggateSurname; + private String adminAggregateSurname; @CsvBindByPosition(position = 13) - private String adminAgreggateTaxCode; + private String adminAggregateTaxCode; @CsvBindByPosition(position = 14) - private String adminAgreggateEmail; + private String adminAggregateEmail; private Integer rowNumber; @Override public void setRowNumber(int lineNumber) { diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java index ca336bac5..6277428f6 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java @@ -64,7 +64,7 @@ public class AggregatesServiceDefault implements AggregatesService{ @Override public Uni validateAppIoAggregatesCsv(File file){ - AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregate.class); + AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregateAppIo.class); List csvAggregates = aggregatesCsvResponse.getCsvAggregateList(); return Multi.createFrom().iterable(csvAggregates) .onItem().transformToUniAndMerge(csvAggregate -> checkCsvAggregateAppIoAndFillAggregateOrErrorList(csvAggregate, aggregatesCsvResponse)) @@ -104,11 +104,11 @@ public Uni validatePagoPaAggregatesCsv(File file) { } private Uni checkCsvAggregateAppIoAndFillAggregateOrErrorList(Csv csv, AggregatesCsvResponse aggregatesCsvResponse) { - CsvAggregate csvAggregate = (CsvAggregate) csv; - return checkCsvAggregateAppIo(csvAggregate) - .onItem().invoke(() -> aggregatesCsvResponse.getValidAggregates().add(csvAggregate)) - .onFailure(ResourceNotFoundException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregate, throwable, aggregatesCsvResponse)) - .onFailure(InvalidRequestException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregate, throwable, aggregatesCsvResponse)); + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + return checkCsvAggregateAppIo(csvAggregateAppIo) + .onItem().invoke(() -> aggregatesCsvResponse.getValidAggregates().add(csvAggregateAppIo)) + .onFailure(ResourceNotFoundException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregateAppIo, throwable, aggregatesCsvResponse)) + .onFailure(InvalidRequestException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregateAppIo, throwable, aggregatesCsvResponse)); } private Uni checkCsvAggregateSendAndFillAggregateOrErrorList(Csv csv, AggregatesCsvResponse aggregatesCsvResponse) { @@ -137,8 +137,8 @@ private Uni checkCsvAggregatePagoPaAndFillAggregateOrErrorList(Csv csv, Ag } private static Uni mapToErrorRow(Csv csv, Throwable throwable, AggregatesCsvResponse aggregatesCsvResponse) { - CsvAggregate csvAggregate = (CsvAggregate) csv; - aggregatesCsvResponse.getRowErrorList().add(new RowError(csvAggregate.getRowNumber(), csvAggregate.getTaxCode(), throwable.getMessage())); + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + aggregatesCsvResponse.getRowErrorList().add(new RowError(csvAggregateAppIo.getRowNumber(), csvAggregateAppIo.getTaxCode(), throwable.getMessage())); return Uni.createFrom().voidItem(); } @@ -157,18 +157,18 @@ private Uni checkCsvAggregatePagoPa(CsvAggregatePagoPa csvAggregate) { } private Uni checkSubunitTypeAppIo(Csv csv) { - CsvAggregate csvAggregate = (CsvAggregate) csv; + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; - if (StringUtils.isEmpty(csvAggregate.getSubunitType())) { - return institutionApi.findInstitutionUsingGET(csvAggregate.getTaxCode(), null, null) + if (StringUtils.isEmpty(csvAggregateAppIo.getSubunitType())) { + return institutionApi.findInstitutionUsingGET(csvAggregateAppIo.getTaxCode(), null, null) .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) .replaceWith(Uni.createFrom().voidItem()); - } else if (InstitutionPaSubunitType.AOO.name().equals(csvAggregate.getSubunitType())) { - return aooApi.findByUnicodeUsingGET(csvAggregate.getSubunitCode(), null) + } else if (InstitutionPaSubunitType.AOO.name().equals(csvAggregateAppIo.getSubunitType())) { + return aooApi.findByUnicodeUsingGET(csvAggregateAppIo.getSubunitCode(), null) .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) .replaceWith(Uni.createFrom().voidItem()); - } else if (InstitutionPaSubunitType.UO.name().equals(csvAggregate.getSubunitType())) { - return uoApi.findByUnicodeUsingGET1(csvAggregate.getSubunitCode(), null) + } else if (InstitutionPaSubunitType.UO.name().equals(csvAggregateAppIo.getSubunitType())) { + return uoApi.findByUnicodeUsingGET1(csvAggregateAppIo.getSubunitCode(), null) .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) .replaceWith(Uni.createFrom().voidItem()); } else { @@ -200,15 +200,15 @@ private boolean checkIfNotFound(Throwable throwable) { } private Uni checkRequiredFieldsAppIo(Csv csv) { - CsvAggregate csvAggregate = (CsvAggregate) csv; - if (StringUtils.isEmpty(csvAggregate.getTaxCode())) { + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + if (StringUtils.isEmpty(csvAggregateAppIo.getTaxCode())) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_TAXCODE)); - } else if (StringUtils.isEmpty(csvAggregate.getDescription())) { + } else if (StringUtils.isEmpty(csvAggregateAppIo.getDescription())) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_DESCRIPTION)); - } else if (StringUtils.isEmpty(csvAggregate.getVatNumber())) { + } else if (StringUtils.isEmpty(csvAggregateAppIo.getVatNumber())) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_VATNUMBER)); - } else if ((StringUtils.isEmpty(csvAggregate.getSubunitType()) && StringUtils.isNotEmpty(csvAggregate.getSubunitCode())) - || (StringUtils.isNotEmpty(csvAggregate.getSubunitType()) && StringUtils.isEmpty(csvAggregate.getSubunitCode()))) { + } else if ((StringUtils.isEmpty(csvAggregateAppIo.getSubunitType()) && StringUtils.isNotEmpty(csvAggregateAppIo.getSubunitCode())) + || (StringUtils.isNotEmpty(csvAggregateAppIo.getSubunitType()) && StringUtils.isEmpty(csvAggregateAppIo.getSubunitCode()))) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_AOO_UO)); } return Uni.createFrom().voidItem();