Skip to content

Commit

Permalink
SELC-5438: Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenbegiqi committed Sep 3, 2024
1 parent bd16437 commit 90dd51e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,45 @@
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
public void setRowNumber(int lineNumber) {
this.rowNumber = lineNumber;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class AggregatesServiceDefault implements AggregatesService{

@Override
public Uni<VerifyAggregateResponse> validateAppIoAggregatesCsv(File file){
AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregate.class);
AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregateAppIo.class);
List<Csv> csvAggregates = aggregatesCsvResponse.getCsvAggregateList();
return Multi.createFrom().iterable(csvAggregates)
.onItem().transformToUniAndMerge(csvAggregate -> checkCsvAggregateAppIoAndFillAggregateOrErrorList(csvAggregate, aggregatesCsvResponse))
Expand Down Expand Up @@ -104,11 +104,11 @@ public Uni<VerifyAggregateResponse> validatePagoPaAggregatesCsv(File file) {
}

private Uni<Void> 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<Void> checkCsvAggregateSendAndFillAggregateOrErrorList(Csv csv, AggregatesCsvResponse aggregatesCsvResponse) {
Expand Down Expand Up @@ -137,8 +137,8 @@ private Uni<Void> checkCsvAggregatePagoPaAndFillAggregateOrErrorList(Csv csv, Ag
}

private static Uni<Void> 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();
}

Expand All @@ -157,18 +157,18 @@ private Uni<Void> checkCsvAggregatePagoPa(CsvAggregatePagoPa csvAggregate) {
}

private Uni<Void> 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 {
Expand Down Expand Up @@ -200,15 +200,15 @@ private boolean checkIfNotFound(Throwable throwable) {
}

private Uni<Void> 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();
Expand Down

0 comments on commit 90dd51e

Please sign in to comment.