Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ application-*.properties
!application-test.properties
document_analysis.properties
.env
dossierfacile-process-file/testResult/
target/
mockstorage/
mock-storage/
Expand All @@ -14,6 +15,7 @@ logs/
hs_err_pid*.log
tmp
**/certs/*
elastalert/dist

### STS ###
.apt_generated
Expand Down
2 changes: 2 additions & 0 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ttf-mscorefonts-installer
tesseract-ocr
imagemagick
libblas-dev
libopencv-dev
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: java $JVM_OPTIONS -Djna.library.path=$JNA_LIBRARY_PATH -jar $APP_DIR/target/$APP_DIR.jar
web: bash bin/start.sh
6 changes: 6 additions & 0 deletions bin/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

ln -s /app/.apt/usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3 /app/.apt/usr/lib/x86_64-linux-gnu/
ln -s /app/.apt/usr/lib/x86_64-linux-gnu/blas/libblas.so.3 /app/.apt/usr/lib/x86_64-linux-gnu/

java $JVM_OPTIONS -Djna.library.path=$JNA_LIBRARY_PATH -jar $APP_DIR/target/$APP_DIR.jar
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class BODocumentDeniedOptionsController {

private static final String EMAIL = "email";
private static final List<String> DOCUMENT_USER_TYPES = List.of("tenant", "guarantor");
private static final List<String> DOCUMENT_USER_TYPES = List.of("tenant", "guarantor", "all");

private final DocumentDeniedOptionsService service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ private static String redirectToTenantPage(Tenant tenant) {
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
}

private List<ItemDetail> getItemDetailForSubcategoryOfDocument(DocumentSubCategory documentSubCategory, String tenantOrGuarantor) {
private List<ItemDetail> getItemDetailForSubcategoryOfDocument(DocumentSubCategory documentSubCategory, String documentUserType) {

List<ItemDetail> itemDetails = new ArrayList<>();
for (DocumentDeniedOptions documentDeniedOptions : documentService.findDocumentDeniedOptionsByDocumentSubCategoryAndDocumentUserType(documentSubCategory, tenantOrGuarantor)) {
for (DocumentDeniedOptions documentDeniedOptions : documentService.findDocumentDeniedOptionsByDocumentSubCategoryAndDocumentUserTypeIncludeGeneric(documentSubCategory, documentUserType)) {
ItemDetail itemDetail1 = ItemDetail.builder()
.check(false)
.message(documentDeniedOptions.getMessageValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.dossierfacile.common.entity.DocumentDeniedOptions;
import fr.dossierfacile.common.enums.DocumentSubCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

Expand All @@ -12,4 +13,17 @@ public interface DocumentDeniedOptionsRepository extends JpaRepository<DocumentD

List<DocumentDeniedOptions> findAllByDocumentSubCategory(DocumentSubCategory documentSubCategory);

@Query(value = """
select *
from document_denied_options
where (document_user_type = 'all' or document_user_type = :documentUserType)
and (document_sub_category = 'UNDEFINED' or document_sub_category = :documentSubCategory)
ORDER BY
CASE
WHEN document_sub_category = 'UNDEFINED' THEN 1
ELSE 0
END, code
""", nativeQuery = true)
List<DocumentDeniedOptions> findAllByDocumentSubCategoryAndDocumentUserTypeIncludeGeneric(String documentSubCategory, String documentUserType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void updateDocumentWithDocumentDeniedReasons(DocumentDeniedReasons docume
documentRepository.updateDocumentWithDocumentDeniedReasons(documentDeniedReasons, documentId);
}

public List<DocumentDeniedOptions> findDocumentDeniedOptionsByDocumentSubCategoryAndDocumentUserType(DocumentSubCategory documentSubCategory, String tenantOrGuarantor) {
return documentDeniedOptionsRepository.findAllByDocumentSubCategoryAndDocumentUserTypeOrderByCode(documentSubCategory, tenantOrGuarantor);
public List<DocumentDeniedOptions> findDocumentDeniedOptionsByDocumentSubCategoryAndDocumentUserTypeIncludeGeneric(DocumentSubCategory documentSubCategory, String documentUserType) {
return documentDeniedOptionsRepository.findAllByDocumentSubCategoryAndDocumentUserTypeIncludeGeneric(documentSubCategory.name(), documentUserType);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package fr.gouv.bo.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.entity.TenantLog;
import fr.dossierfacile.common.enums.LogType;
import fr.dossierfacile.common.model.log.EditedDocument;
import fr.dossierfacile.common.model.log.EditionType;
import fr.gouv.bo.repository.BoTenantLogRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -48,11 +52,22 @@ public void addOperatorCommentLog(Tenant tenant, String operatorComment) {
.logType(LogType.OPERATOR_COMMENT)
.tenantId(tenant.getId())
.creationDateTime(LocalDateTime.now())
.logDetails(writeAsString(Map.of("comment", operatorComment)))
.logDetails(writeAsObjectNode(Map.of("comment", operatorComment)))
.build();
saveByLog(log);
}

public void addDeleteDocumentLog(Long tenantId, Long operatorId, Document document) {
TenantLog log = TenantLog.builder()
.logType(LogType.ACCOUNT_EDITED)
.tenantId(tenantId)
.operatorId(operatorId)
.creationDateTime(LocalDateTime.now())
.logDetails(writeAsObjectNode(EditedDocument.from(document, EditionType.DELETE)))
.build();
saveByLog(log);
}

public List<Object[]> listLastTreatedFilesByOperator(Long operatorId, int minusDays) {
return logRepository.countTreatedFromXDaysGroupByDate(operatorId, minusDays);
}
Expand All @@ -61,12 +76,14 @@ public List<Object[]> listDailyTreatedFilesByOperator() {
return logRepository.countTreatedFromTodayGroupByOperator();
}

private String writeAsString(Object object) {
private ObjectNode writeAsObjectNode(Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
log.error("FATAL: Cannot write log details as string", e);
return (ObjectNode) objectMapper.valueToTree(object);
} catch (IllegalArgumentException e) {
log.error("FATAL: Cannot write log details as object node", e);
}
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ private void processDocumentDeniedReasons(MessageItem messageItem, List<Long> do
if (!documentDeniedReasons.getCheckedOptionsId().isEmpty() || (documentDeniedReasons.getComment() != null && !documentDeniedReasons.getComment().isBlank())) {
Document document = documentRepository.findById(messageItem.getDocumentId()).orElseThrow(() -> new DocumentNotFoundException(messageItem.getDocumentId()));
documentDeniedReasons.setDocument(document);
documentDeniedReasons.setDocumentCategory(document.getDocumentCategory());
documentDeniedReasons.setDocumentSubCategory(document.getDocumentSubCategory());
documentDeniedReasons.setDocumentCategoryStep(document.getDocumentCategoryStep());
if (document.getGuarantor() != null) {
documentDeniedReasons.setDocumentTenantType("guarantor");
} else {
documentDeniedReasons.setDocumentTenantType("tenant");
}
documentDeniedReasonsRepository.save(documentDeniedReasons);
DocumentDeniedReasons documentDeniedReasonsToDelete = document.getDocumentDeniedReasons();
documentService.updateDocumentWithDocumentDeniedReasons(documentDeniedReasons, messageItem.getDocumentId());
Expand Down Expand Up @@ -773,7 +781,9 @@ public Optional<Tenant> getOldestToProcessApplication() {

@Transactional
public Tenant deleteDocument(Long id, User operator) {
Document document = documentService.findDocumentById(id);
Tenant tenant = documentService.deleteDocument(id);
tenantLogService.addDeleteDocumentLog(tenant.getId(), operator.getId(), document);
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
updateTenantStatus(tenant, operator);
return tenant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.gouv.bo.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import fr.dossierfacile.common.entity.*;
import fr.dossierfacile.common.enums.*;
Expand Down Expand Up @@ -89,7 +89,7 @@ private void saveAndDeleteInfoByTenant(Tenant tenant, BOUser operator) {
.logType(LogType.ACCOUNT_DELETE)
.tenantId(tenant.getId())
.operatorId(operator.getId())
.jsonProfile(writeValueAsString(tenantMapper.toTenantModel(tenant)))
.jsonProfile(writeAsObjectNode(tenantMapper.toTenantModel(tenant)))
.creationDateTime(LocalDateTime.now())
.build());
}
Expand Down Expand Up @@ -184,11 +184,11 @@ public void createUserByEmail(String email, Role role) {
addRoles(userRepository.save(user), Collections.singletonList(role));
}

private String writeValueAsString(Object object) {
private ObjectNode writeAsObjectNode(Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
log.error("FATAL: Something very bad happened " + object.getClass(), e);
return objectMapper.valueToTree(object);
} catch (IllegalArgumentException e) {
log.error("FATAL: cannot write jsonProfile as object node", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ <h2>Liste des liens envoyés:</h2>
<div aria-hidden="true" aria-labelledby="exampleModalScrollableTitle" class="modal fade"
role="dialog"
tabindex="-1" th:id="'target'+${tenant.getId()}">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-dialog modal-dialog-scrollable" role="document" style="--bs-modal-width: 600px">
<div class="modal-content">
<div class="modal-header" style="background: cadetblue;">
<h3 class="modal-title" id="exampleModalScrollableTitle"
Expand All @@ -360,9 +360,14 @@ <h2>Liste des liens envoyés:</h2>
<div class="bg-warning-subtle" style="display: grid; padding: 7px;margin-bottom: 10px;"
th:each="log: ${logser.getLogByTenantId(tenant.getId())}">
<div style="font-weight: bold;"
th:text="${log.getLogType()} + ${ (log.getOperatorId() != null)? ' by opId: ' + log.getOperatorId() : ''}">
th:text="${log.getLogType()} + ${ (log.getOperatorId() != null)? ' by opId: ' + log.getOperatorId() : ''} + ${log.getLogDetails() != null && log.getLogDetails().get('editionType') != null ? ' : DOCUMENT ' + (log.getLogDetails().get('editionType').asText().equals('ADD') ? 'ADDED' : 'DELETED'): ''}">
</div>
<span style="padding-left: 5px;"
<span th:if="${log != null && log.getLogDetails() != null && log.getLogDetails().get('documentCategory') != null && log.getLogDetails().get('documentSubCategory') != null}" class="bold" style="font-size: 14px">
<span th:if="${log.getLogDetails().get('guarantorId') != null}">GUARANTOR - </span>
<span th:text="${log.getLogDetails().get('documentCategory').asText()}"></span> -
<span th:text="${log.getLogDetails().get('documentSubCategory').asText()}"></span>
</span>
<span
th:text="'date: ' + ${log.getCreationDateTime().getYear()} + '-' + ${log.getCreationDateTime().getMonthValue()} + '-' + ${log.getCreationDateTime().getDayOfMonth()} + ' ' + ${log.getCreationDateTime().getHour()} + ':' + ${log.getCreationDateTime().getMinute()} + ':' + ${log.getCreationDateTime().getSecond()}">
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fr.dossierfacile.common.entity;

import fr.dossierfacile.common.entity.ocr.BlurryResult;
import fr.dossierfacile.common.enums.BlurryFileAnalysisStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

@Data
@Builder
@Entity
@Table(name = "blurry_file_analysis")
@AllArgsConstructor
@NoArgsConstructor
public class BlurryFileAnalysis implements Serializable {

@Serial
private static final long serialVersionUID = 2405172041950251807L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne(targetEntity = File.class, fetch = FetchType.LAZY)
@JoinColumn(name = "file_id")
private File file;

@Enumerated(EnumType.STRING)
private BlurryFileAnalysisStatus analysisStatus;

@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
private List<BlurryResult> blurryResults;

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package fr.dossierfacile.common.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import fr.dossierfacile.common.enums.DocumentCategory;
import fr.dossierfacile.common.enums.DocumentCategoryStep;
import fr.dossierfacile.common.enums.DocumentSubCategory;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -69,6 +65,21 @@ public class DocumentDeniedReasons implements Serializable {
@Column(name = "creation_date")
private LocalDateTime creationDate = LocalDateTime.now();

@Enumerated(EnumType.STRING)
@Column(name = "document_category")
private DocumentCategory documentCategory;

@Enumerated(EnumType.STRING)
@Column(name = "document_sub_category")
private DocumentSubCategory documentSubCategory;

@Enumerated(EnumType.STRING)
@Column(name = "document_category_step")
private DocumentCategoryStep documentCategoryStep;

@Column(name = "document_tenant_type")
private String documentTenantType;

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public enum DocumentRule {
R_RENT_RECEIPT_NB_DOCUMENTS(Level.WARN, "Un seul document a été détecté"),

R_FRANCE_IDENTITE_NAMES(Level.CRITICAL, "Les noms et prénoms ne correspondent pas"),
R_FRANCE_IDENTITE_STATUS(Level.CRITICAL, "Ce document n'a pas pu être validé par France Identité");
R_FRANCE_IDENTITE_STATUS(Level.CRITICAL, "Ce document n'a pas pu être validé par France Identité"),

R_BLURRY_FILE(Level.CRITICAL, "Votre document semble flou");

public enum Level {
CRITICAL, WARN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import fr.dossierfacile.common.enums.FileStorageStatus;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import org.hibernate.Hibernate;

import java.io.Serial;
Expand Down Expand Up @@ -56,9 +51,13 @@ public class File implements Serializable {
private BarCodeFileAnalysis fileAnalysis;

@Nullable
@OneToOne(mappedBy= "file", fetch = FetchType.LAZY)
@OneToOne(mappedBy = "file", fetch = FetchType.LAZY)
private ParsedFileAnalysis parsedFileAnalysis;

@Nullable
@OneToOne(mappedBy = "file", fetch = FetchType.LAZY)
private BlurryFileAnalysis blurryFileAnalysis;

@PreRemove
void deleteCascade() {
if (storageFile != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
package fr.dossierfacile.common.entity;

import com.fasterxml.jackson.databind.node.ObjectNode;
import fr.dossierfacile.common.enums.LogType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

Expand Down Expand Up @@ -53,11 +43,11 @@ public class TenantLog implements Serializable {

@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
private Object jsonProfile;
private ObjectNode jsonProfile;

@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
private Object logDetails;
private ObjectNode logDetails;

@Column
private Long messageId;
Expand Down
Loading