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

fix: add debtor-fiscal-code validation [PAGOPA-1649] #50

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
public class PaymentNoticeVerifier implements BeanVerifier<PaymentNotice>{
private final Set<String> unique = new HashSet<>();
private List<EcConfigEntity> organizationsList = new ArrayList<>();

private static final int DEBTOR_FISCAL_CODE_LENGTH = 11;

public PaymentNoticeVerifier (List<EcConfigEntity> organizationsList) {
this.organizationsList = organizationsList;
}
Expand All @@ -42,6 +43,11 @@ public boolean verifyBean(PaymentNotice bean) throws CsvConstraintViolationExcep
if (bean.getAmount() <= 0) {
errors.add("The amount must be greater than zero.");
}

// check debtor fiscal code length
if (bean.getDebtorFiscalCode().length() != DEBTOR_FISCAL_CODE_LENGTH) {
errors.add(String.format("The debtor fiscal code length must be equal to %s.", DEBTOR_FISCAL_CODE_LENGTH));
}

// check existence of the organization fiscal code if valued in csv file
if (null != bean.getPaIdFiscalCode() && !bean.getPaIdFiscalCode().isBlank() && !checkIsPresentOrganizationFiscalCode(bean.getPaIdFiscalCode())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void parseCsv() throws InvalidKeyException, URISyntaxException, StorageException
StringWriter csv = new StringWriter();

String headers = "id;pa_id_istat;pa_id_catasto;pa_id_fiscal_code;pa_id_cbill;pa_pec_email;pa_referent_email;pa_referent_name;amount;debtor_id_fiscal_code;debtor_name;debtor_email;payment_notice_number;note";
String row = "1;;C125;;;;;;383700;123456;Spa;spa@pec.spa.it;;";
String row = "1;;C125;;;;;;383700;12345678910;Spa;spa@pec.spa.it;;";

csv.append(headers);
csv.append(System.lineSeparator());
Expand Down Expand Up @@ -209,7 +209,7 @@ void parseCsv2() throws InvalidKeyException, URISyntaxException, StorageExceptio
StringWriter csv = new StringWriter();

String headers = "id;pa_id_istat;pa_id_catasto;pa_id_fiscal_code;pa_id_cbill;pa_pec_email;pa_referent_email;pa_referent_name;amount;debtor_id_fiscal_code;debtor_name;debtor_email;payment_notice_number;note";
String row = "1;;C125;;;;;;383700;123456;Spa;spa@pec.spa.it;;";
String row = "1;;C125;;;;;;383700;12345678910;Spa;spa@pec.spa.it;;";

csv.append(headers);
csv.append(System.lineSeparator());
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/2021-04-21_pagcorp0007_0101108TS.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id;pa_id_istat;pa_id_catasto;pa_id_fiscal_code;pa_id_cbill;pa_pec_email;pa_referent_email;pa_referent_name;amount;debtor_id_fiscal_code;debtor_name;debtor_email;payment_notice_number;note
1;;C123;;;;;;383700;123456;Spa;spa@pec.spa.it;;
1;;C123;;;;;;383700;12345678910;Spa;spa@pec.spa.it;;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id;pa_id_istat;pa_id_catasto;pa_id_fiscal_code;pa_id_cbill;pa_pec_email;pa_referent_email;pa_referent_name;amount;debtor_id_fiscal_code;debtor_name;debtor_email;payment_notice_number;note
000001;;C123;C123;;;;;123456;0123456789;SPA;spa@pec.spa.it;;
000001;;C123;C123;;;;;123456;12345678910;SPA;spa@pec.spa.it;;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id;pa_id_istat;pa_id_catasto;pa_id_fiscal_code;pa_id_cbill;pa_pec_email;pa_referent_email;pa_referent_name;amount;debtor_id_fiscal_code;debtor_name;debtor_email;payment_notice_number;note
1;;XXXXX;;;;;;383700;123456;Spa;spa@pec.spa.it;;
1;;XXXXX;;;;;;383700;12345678910;Spa;spa@pec.spa.it;;