Skip to content

Commit

Permalink
Merge branch 'release/2024.01.05'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Jan 5, 2024
2 parents 2936a66 + cdb99d4 commit 0c28759
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fr.dossierfacile.api.front.validator.anotation.tenant.financial.NumberOfDocumentFinancial;
import fr.dossierfacile.common.enums.DocumentCategory;
import fr.dossierfacile.common.enums.DocumentSubCategory;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -31,6 +32,7 @@
@NumberOfPages(category = DocumentCategory.FINANCIAL, max = 50)
public class DocumentFinancialForm extends DocumentForm {

@Parameter(description = "Identifiant du document est nécessaire poour les mises à jour")
private Long id;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.gouv.bo.dto;

import fr.dossierfacile.common.entity.DocumentAnalysisReport;
import fr.dossierfacile.common.entity.DocumentDeniedReasons;
import fr.dossierfacile.common.enums.DocumentCategory;
import fr.dossierfacile.common.enums.DocumentSubCategory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public enum DocumentRule {
R_TAX_LEAF( Level.CRITICAL, "Veuillez fournir les feuillets des avis"),
R_TAX_ALL_LEAF( Level.WARN, "Veuillez fournir tous les feuillets des avis"),// feuillet 1 founi
R_TAX_N3( Level.CRITICAL, "Les avis d'imposition antérieur à N-3 ne sont pas autorisé"),
R_TAX_NAMES( Level.CRITICAL, "Les noms et prénoms ne correspondent pas");
R_TAX_NAMES( Level.CRITICAL, "Les noms et prénoms ne correspondent pas"),

R_GUARANTEE_NAMES( Level.CRITICAL, "Les noms et prénoms ne correspondent pas"),
R_GUARANTEE_EXIRED( Level.CRITICAL, "La garantie a expiré");

public enum Level{
CRITICAL, WARN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ public interface Person {

String getLastName();

default String getPreferredName(){
return getLastName();
}
List<Document> getDocuments();
}
2 changes: 1 addition & 1 deletion dossierfacile-pdf-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.13.4.20221013</version>
<version>2.13.5</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service
Expand All @@ -32,12 +33,16 @@ public void processDocument(Long documentId) {
}
try {
List<RulesValidationService> rulesValidationServices = documentRulesValidationServiceFactory.getServices(document);
if (!CollectionUtils.isEmpty(rulesValidationServices )) {
if (!CollectionUtils.isEmpty(rulesValidationServices)) {
Optional.ofNullable(document.getDocumentAnalysisReport()).ifPresent((report) -> {
document.setDocumentAnalysisReport(null);
documentAnalysisReportRepository.delete(report);
});
DocumentAnalysisReport report = DocumentAnalysisReport.builder()
.document(document)
.brokenRules(new LinkedList<>())
.build();
rulesValidationServices.stream().forEach( rulesService -> rulesService.process(document, report) );
rulesValidationServices.stream().forEach(rulesService -> rulesService.process(document, report));
document.setDocumentAnalysisReport(report);
documentAnalysisReportRepository.save(report);
documentRepository.save(document);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,83 @@
package fr.dossierfacile.process.file.service.documentrules;

import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.DocumentAnalysisReport;
import fr.dossierfacile.common.entity.DocumentAnalysisStatus;
import fr.dossierfacile.common.entity.*;
import fr.dossierfacile.common.entity.ocr.GuaranteeProviderFile;
import fr.dossierfacile.common.enums.DocumentCategory;
import fr.dossierfacile.common.enums.DocumentSubCategory;
import fr.dossierfacile.common.enums.ParsedStatus;
import fr.dossierfacile.process.file.util.PersonNameComparator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Service
@RequiredArgsConstructor
@Slf4j
public class GuaranteeProviderRulesValidationService implements RulesValidationService {
@Override
public boolean shouldBeApplied(Document document){
public boolean shouldBeApplied(Document document) {
return document.getDocumentCategory() == DocumentCategory.IDENTIFICATION
&& document.getDocumentSubCategory() == DocumentSubCategory.CERTIFICATE_VISA;
&& document.getDocumentSubCategory() == DocumentSubCategory.CERTIFICATE_VISA
&& !CollectionUtils.isEmpty(document.getFiles())
&& document.getFiles().stream().anyMatch((f) -> f.getParsedFileAnalysis() != null
&& f.getParsedFileAnalysis().getParsedFile() != null);
}


private boolean checkNamesRule(Document document, GuaranteeProviderFile parsedFile) {
Tenant tenant = document.getTenant();
return parsedFile.getNames().stream().anyMatch(
(fullname) -> PersonNameComparator.bearlyEqualsTo(fullname.firstName(), tenant.getFirstName())
&& PersonNameComparator.bearlyEqualsTo(fullname.lastName(), tenant.getLastName()));
}

private boolean checkValidityRule(GuaranteeProviderFile parsedFile) {
LocalDate validityDate = LocalDate.parse(parsedFile.getValidityDate(), DateTimeFormatter.ofPattern("dd/MM/yyyy"));
return validityDate.isAfter(LocalDate.now());
}

@Override
public DocumentAnalysisReport process(Document document, DocumentAnalysisReport report) {
log.debug("TODO");
// TODO Currently there is not implemented rules
return DocumentAnalysisReport.builder().analysisStatus(DocumentAnalysisStatus.UNDEFINED).document(document).build();

try {
if (CollectionUtils.isEmpty(document.getFiles())
|| document.getFiles().get(0).getParsedFileAnalysis() == null
|| document.getFiles().get(0).getParsedFileAnalysis().getParsedFile() == null) {
report.setAnalysisStatus(DocumentAnalysisStatus.UNDEFINED);
return report;
}

GuaranteeProviderFile parsedFile = (GuaranteeProviderFile) document.getFiles().get(0).getParsedFileAnalysis().getParsedFile();
if (parsedFile.getStatus() == ParsedStatus.INCOMPLETE) {
log.error("Document was not correctly parsed :" + document.getTenant().getId());
report.setAnalysisStatus(DocumentAnalysisStatus.UNDEFINED);
} else if (!checkNamesRule(document, parsedFile)) {
log.error("Document names mismatches :" + document.getTenant().getId());
report.getBrokenRules().add(DocumentBrokenRule.builder()
.rule(DocumentRule.R_GUARANTEE_NAMES)
.message(DocumentRule.R_GUARANTEE_NAMES.getDefaultMessage())
.build());
report.setAnalysisStatus(DocumentAnalysisStatus.DENIED);
} else if (!checkValidityRule(parsedFile)) {
log.error("Document is expired :" + document.getTenant().getId());
report.getBrokenRules().add(DocumentBrokenRule.builder()
.rule(DocumentRule.R_GUARANTEE_EXIRED)
.message(DocumentRule.R_GUARANTEE_EXIRED.getDefaultMessage())
.build());
report.setAnalysisStatus(DocumentAnalysisStatus.DENIED);
} else {
report.setAnalysisStatus(DocumentAnalysisStatus.CHECKED);
}

} catch (Exception e) {
log.error("Error during the rules validation execution pocess");
report.setAnalysisStatus(DocumentAnalysisStatus.UNDEFINED);
}
return report;
}

}
Loading

0 comments on commit 0c28759

Please sign in to comment.