Skip to content

Commit

Permalink
Merge branch 'release/2024.03.27'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Mar 27, 2024
2 parents d2aed7c + 49ecba2 commit aa557d1
Show file tree
Hide file tree
Showing 41 changed files with 755 additions and 537 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mockstorage/
.DS_Store
static-front/
logs/
hs_err_pid*.log

### STS ###
.apt_generated
Expand Down
Binary file added .tessdata/digits.traineddata
Binary file not shown.
Binary file added .tessdata/fra.traineddata
Binary file not shown.
4 changes: 1 addition & 3 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
ttf-mscorefonts-installer
tesseract-ocr
tesseract-ocr-fra
tesseract-ocr-eng
tesseract-ocr
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
<levelValue>[ignore]</levelValue>
</fieldNames>
<customFields>{"application":"${APPLICATION_NAME}", "environment":"${ENVIRONMENT}", "profiles":"${APPLICATION_PROFILES}"}</customFields>
<includeMdcKeyName>client</includeMdcKeyName>
<includeMdcKeyName>user</includeMdcKeyName>
<includeMdcKeyName>uri</includeMdcKeyName>
<includeMdcKeyName>request_id</includeMdcKeyName>
<includeMdcKeyName>response_status</includeMdcKeyName>
<includeMdcKeyName>email</includeMdcKeyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
import fr.dossierfacile.api.front.exception.ApartmentSharingUnexpectedException;
import fr.dossierfacile.api.front.service.interfaces.ApartmentSharingService;
import fr.dossierfacile.common.model.apartment_sharing.ApplicationModel;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.util.UUID;

import static org.springframework.http.ResponseEntity.accepted;
import static org.springframework.http.ResponseEntity.ok;
Expand Down Expand Up @@ -47,19 +44,26 @@ public ResponseEntity<ApplicationModel> light(@PathVariable String token) {
@GetMapping(value = "/fullPdf/{token}", produces = MediaType.APPLICATION_PDF_VALUE)
public void downloadFullPdf(@PathVariable("token") String token, HttpServletResponse response) {
try {
ByteArrayOutputStream byteArrayOutputStream = apartmentSharingService.fullPdf(token);
ByteArrayOutputStream byteArrayOutputStream = apartmentSharingService.downloadFullPdf(token);
if (byteArrayOutputStream.size() > 0) {
response.setHeader("Content-Disposition", "attachment; filename=" + UUID.randomUUID() + ".pdf");
response.setHeader("Content-Type", MediaType.APPLICATION_PDF_VALUE);
response.getOutputStream().write(byteArrayOutputStream.toByteArray());
} else {
log.error(DOCUMENT_NOT_EXIST);
response.setStatus(404);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
} catch (IOException e) {
} catch (ApartmentSharingNotFoundException e) {
log.error(e.getMessage(), e.getCause());
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e.getCause());
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
} catch (Exception e) {
log.error(e.getMessage(), e.getCause());
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

}

@PostMapping(value = "/fullPdf/{token}", produces = MediaType.APPLICATION_PDF_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -104,29 +105,12 @@ private LocalDateTime getLastUpdateDate(ApartmentSharing apartmentSharing) {
}

@Override
public ByteArrayOutputStream fullPdf(String token) throws IOException {
public ByteArrayOutputStream downloadFullPdf(String token) throws IOException {
ByteArrayOutputStream outputStreamResult = new ByteArrayOutputStream();

ApartmentSharing apartmentSharing = apartmentSharingRepository.findByToken(token)
.orElseThrow(() -> new ApartmentSharingNotFoundException(token));

// FIXME: temporary fix for partner who does not use POST
//region generate PDF before to get it
if (apartmentSharing.getDossierPdfDocumentStatus() != FileStatus.COMPLETED
&& !apartmentSharing.groupingAllTenantUserApisInTheApartment().isEmpty()) {
Sentry.captureMessage("GenerateFullPdfOnGet:" + token);
// generate the pdf file and wait the treatment
createFullPdf(token);
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
log.error("Unable to sleep process");
}
apartmentSharing = apartmentSharingRepository.findByToken(token)
.orElseThrow(() -> new ApartmentSharingNotFoundException(token));
}
//endregion

if (apartmentSharing.getDossierPdfDocumentStatus() != FileStatus.COMPLETED) {
throw new FileNotFoundException("Full PDF doesn't exist - FileStatus " + apartmentSharing.getDossierPdfDocumentStatus());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public void resetValidatedDocumentsStatusOfSpecifiedCategoriesToToProcess(List<D
.forEach(document -> {
if (document.getDocumentStatus().equals(DocumentStatus.VALIDATED)
&& categoriesToChange.contains(document.getDocumentCategory())) {
if (Boolean.TRUE == document.getNoDocument() && document.getWatermarkFile() != null){
storageFileRepository.delete(document.getWatermarkFile());
document.setWatermarkFile(null);
}
TransactionalUtil.afterCommit(() -> {
producer.sendDocumentForAnalysis(document);// analysis should be relaunched for update rules
if (Boolean.TRUE == document.getNoDocument()){
producer.sendDocumentForPdfGeneration(document);
}
});
document.setDocumentStatus(DocumentStatus.TO_PROCESS);
document.setDocumentDeniedReasons(null);
documentRepository.save(document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private UserRepresentation createUser(String email) {
var userRepresentation = new UserRepresentation();
userRepresentation.setEmail(email);
userRepresentation.setUsername(email);
userRepresentation.setEnabled(false);
userRepresentation.setEnabled(true);
userRepresentation.setEmailVerified(false);
return userRepresentation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ApartmentSharingService {

ApplicationModel light(String token);

ByteArrayOutputStream fullPdf(String token) throws IOException;
ByteArrayOutputStream downloadFullPdf(String token) throws IOException;

void resetDossierPdfGenerated(ApartmentSharing apartmentSharing);

Expand Down
4 changes: 2 additions & 2 deletions dossierfacile-bo/src/main/resources/templates/bo/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
<div class="container">
<form th:method="post" th:action="@{/bo/users}" th:object="${email}" >
<label for="name" id="">Email:</label>
<input pattern="[\w.%+-]+@dossierfacile\.fr" required type="text" name="name" id="name" placeholder="on domain dossierfacile.fr ..."
oninvalid="this.setCustomValidity('wrong entry')"
<input required type="text" name="name" id="name" placeholder="on domain dossierfacile.fr ..."
oninput="setCustomValidity('')" th:field="*{email}"/>
<button style="font-size: initial;float: right;padding: 10px 16px 11px;" type="submit" name='action' value='ROLE_ADMIN' class="btn btn-info">create admin</button>
<button style="margin-right: 10px;font-size: initial;float: right;padding: 10px 16px 11px;" type="submit" name='action' value='ROLE_OPERATOR' class="btn btn-success">create operator</button>
<button style="margin-right: 10px;font-size: initial;float: right;padding: 10px 16px 11px;" type="submit" name='action' value='ROLE_PARTNER' class="btn btn-success">create partner (action db requise)</button>
</form>
</div>
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.dossierfacile.common.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import fr.dossierfacile.common.entity.ocr.ParsedFile;
import fr.dossierfacile.common.enums.ParsedFileClassification;
import fr.dossierfacile.common.enums.ParsedStatus;
Expand All @@ -14,15 +15,11 @@
@ToString
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class FranceIdentiteApiResult implements ParsedFile {
@Builder.Default
ParsedFileClassification classification = ParsedFileClassification.FRANCE_IDENTITE;
ParsedStatus parsedStatus;
String status;
String familyName;
String givenName;
String birthDate;
String birthPlace;
String gender;
String validityDate;
FranceIdentiteApiResultAttributes attributes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.dossierfacile.common.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import fr.dossierfacile.common.entity.ocr.ParsedFile;
import fr.dossierfacile.common.enums.ParsedFileClassification;
import fr.dossierfacile.common.enums.ParsedStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class FranceIdentiteApiResultAttributes implements Serializable {
String familyName;
String givenName;
String birthDate;
String birthPlace;
String validityDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void receiveFile(Map<String, String> message) throws InterruptedException
try {
analysis.get(analysisTimeoutInSeconds, TimeUnit.SECONDS);
} catch (TimeoutException e) {
log.warn("Try to cancel");
analysis.cancel(true);
log.warn("Analysis cancelled because timeout was reached");
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void startProcessing(Long fileId, ActionType actionType) {
MDC.put(FILE, String.valueOf(fileId));
MDC.put(ACTION, actionType.name());
MDC.put(EXECUTION_START, String.valueOf(System.currentTimeMillis()));
log.info("Received " + actionType.name() + " to process");
log.info("Received " + actionType.name() + " to process : " + fileId);
}

static void endProcessing() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package fr.dossierfacile.process.file.service;

import fr.dossierfacile.common.entity.File;
import fr.dossierfacile.process.file.repository.FileRepository;
import fr.dossierfacile.process.file.service.processors.BarCodeFileProcessor;
import fr.dossierfacile.process.file.service.processors.FileParserProcessor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Slf4j
@Service
@AllArgsConstructor
Expand All @@ -16,9 +19,10 @@ public class AnalyzeFile {
private final FileRepository fileRepository;

public void processFile(Long fileId) {
fileRepository.findById(fileId)
.map(barCodeFileProcessor::process)
.map(fileParserProcessor::process);

Optional<File> optFile = fileRepository.findById(fileId);
if (optFile.isPresent()) {
barCodeFileProcessor.process(optFile.get());
fileParserProcessor.process(optFile.get());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public DocumentAnalysisReport process(Document document, DocumentAnalysisReport
// Parse Rule
if (parsedDocument == null
|| parsedDocument.getStatus() == null
|| parsedDocument.getFamilyName() == null
|| parsedDocument.getGivenName() == null
|| parsedDocument.getValidityDate() == null) {
|| parsedDocument.getAttributes().getFamilyName() == null
|| parsedDocument.getAttributes().getGivenName() == null
|| parsedDocument.getAttributes().getValidityDate() == null) {
brokenRules.add(DocumentBrokenRule.builder()
.rule(DocumentRule.R_FRANCE_IDENTITE_STATUS)
.message(DocumentRule.R_FRANCE_IDENTITE_STATUS.getDefaultMessage())
Expand All @@ -72,9 +72,9 @@ public DocumentAnalysisReport process(Document document, DocumentAnalysisReport
// TODO : check that France Identité verifies that names on pdf matches qrcode
Person documentOwner = Optional.ofNullable((Person) document.getTenant()).orElseGet(document::getGuarantor);
String firstName = documentOwner.getFirstName();
String lastName = document.getName();
if (!(normalizeName(parsedDocument.getGivenName()).contains(normalizeName(firstName))
&& (normalizeName(parsedDocument.getFamilyName()).contains(normalizeName(lastName)))
String lastName = documentOwner.getLastName();
if (!(normalizeName(parsedDocument.getAttributes().getGivenName()).contains(normalizeName(firstName))
&& (normalizeName(parsedDocument.getAttributes().getFamilyName()).contains(normalizeName(lastName)))
)) {
log.error("Le nom/prenom ne correpond pas à l'utilisateur tenantId:" + document.getTenant().getId() + " firstname: " + firstName);
brokenRules.add(DocumentBrokenRule.builder()
Expand Down

This file was deleted.

Loading

0 comments on commit aa557d1

Please sign in to comment.