Skip to content

Commit

Permalink
fix: upgrade names rules on income tax
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Dec 20, 2023
1 parent a8aba27 commit bc559f4
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.text.Normalizer;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.LinkedList;
Expand Down Expand Up @@ -49,6 +50,14 @@ private TaxIncomeMainFile fromQR(BarCodeFileAnalysis barCodeFileAnalysis) {
.referenceAvis(dataWithLabel.get(TwoDDocDataType.ID_44.getLabel())).build();
}

private static String normalizeName(String name) {
if (name == null)
return null;
String normalized = Normalizer.normalize(name, Normalizer.Form.NFD);
return normalized.replace('-', ' ')
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "").toUpperCase().trim();
}

@Override
@Transactional
public DocumentAnalysisReport process(Document document) {
Expand Down Expand Up @@ -152,17 +161,17 @@ public DocumentAnalysisReport process(Document document) {
// Firstname LastName
Person documentOwner = Optional.ofNullable((Person) document.getTenant()).orElseGet(() -> document.getGuarantor());
String firstName = documentOwner.getFirstName();
String lastName = document.getName();
String lastName = documentOwner.getLastName();
for (File dfFile : document.getFiles()) {
BarCodeFileAnalysis analysis = dfFile.getFileAnalysis();
if (analysis.getDocumentType() == BarCodeDocumentType.TAX_ASSESSMENT) {
TaxIncomeMainFile qrDocument = fromQR(dfFile.getFileAnalysis());

if (!(qrDocument.getDeclarant1Nom().contains(firstName)
&& qrDocument.getDeclarant1Nom().contains(lastName)
if (!(normalizeName(qrDocument.getDeclarant1Nom()).contains(normalizeName(firstName))
&& normalizeName(qrDocument.getDeclarant1Nom()).contains(normalizeName(lastName))
|| (qrDocument.getDeclarant2Nom() != null &&
qrDocument.getDeclarant2Nom().contains(firstName)
&& qrDocument.getDeclarant2Nom().contains(lastName)
normalizeName(qrDocument.getDeclarant2Nom()).contains(normalizeName(firstName))
&& normalizeName(qrDocument.getDeclarant2Nom()).contains(normalizeName(lastName))
))) {
log.error("Le nom/prenom ne correpond pas à l'uilitsation tenantId:" + document.getTenant().getId() + " firstname: " + firstName);
brokenRules.add(DocumentBrokenRule.builder()
Expand Down

0 comments on commit bc559f4

Please sign in to comment.