diff --git a/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantLogService.java b/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantLogService.java index e68ba42f5..2bec93271 100644 --- a/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantLogService.java +++ b/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantLogService.java @@ -4,9 +4,11 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import fr.dossierfacile.common.entity.Document; +import fr.dossierfacile.common.entity.File; 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.EditedFile; import fr.dossierfacile.common.model.log.EditionType; import fr.dossierfacile.common.model.log.UpdateMonthlySum; import fr.dossierfacile.common.service.interfaces.TenantLogCommonService; @@ -71,6 +73,17 @@ public void addDeleteDocumentLog(Long tenantId, Long operatorId, Document docume tenantLogCommonService.saveTenantLog(log); } + public void addDeleteFileLog(Long tenantId, Long operatorId, File file) { + TenantLog log = TenantLog.builder() + .logType(LogType.ACCOUNT_EDITED) + .tenantId(tenantId) + .operatorId(operatorId) + .creationDateTime(LocalDateTime.now()) + .logDetails(writeAsObjectNode(EditedFile.from(file, EditionType.DELETE))) + .build(); + tenantLogCommonService.saveTenantLog(log); + } + public void addUpdateAmountLog(Long tenantId, Long operatorId, Document document, Integer newSum) { TenantLog log = TenantLog.builder() .logType(LogType.ACCOUNT_EDITED) diff --git a/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java b/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java index 5cb00a2ab..e6b5ff2a0 100644 --- a/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java +++ b/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java @@ -881,6 +881,8 @@ public Tenant deleteFile(Long fileId, User operator) { } Tenant tenant = document.getGuarantor() == null ? document.getTenant() : document.getGuarantor().getTenant(); + tenantLogService.addDeleteFileLog(tenant.getId(), operator.getId(), file); + document.getFiles().remove(file); file.setDocument(null); sharedFileRepository.delete(file); diff --git a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/TenantLog.java b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/TenantLog.java index dcadc4ea1..805fcdf7a 100644 --- a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/TenantLog.java +++ b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/TenantLog.java @@ -86,7 +86,8 @@ public String getTitle() { } if (this.getLogDetails() != null) { if (this.getLogDetails().get("editionType") != null) { - builder.append(" : DOCUMENT "); + String subject = this.getLogDetails().get("fileId") != null ? " : FILE " : " : DOCUMENT "; + builder.append(subject); String editionType = this.getLogDetails().get("editionType").asText().equals("ADD") ? "ADDED" : "DELETED"; builder.append(editionType); } @@ -104,6 +105,10 @@ public String getSubtitle() { builder.append(details.get("documentCategory").asText()); builder.append(" - "); builder.append(details.get(DOCUMENT_SUB_CATEGORY).asText()); + if (details.get("fileName") != null) { + builder.append(" - "); + builder.append(details.get("fileName").asText()); + } } if (details != null && details.get(OLD_SUM) != null && details.get(NEW_SUM) != null) { builder.append(" - OLD AMOUNT: "); diff --git a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/model/log/EditedFile.java b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/model/log/EditedFile.java new file mode 100644 index 000000000..2f6ec4f7e --- /dev/null +++ b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/model/log/EditedFile.java @@ -0,0 +1,56 @@ +package fr.dossierfacile.common.model.log; + +import com.fasterxml.jackson.annotation.JsonInclude; +import fr.dossierfacile.common.entity.Document; +import fr.dossierfacile.common.entity.File; +import fr.dossierfacile.common.entity.Guarantor; +import fr.dossierfacile.common.entity.StorageFile; +import fr.dossierfacile.common.entity.Tenant; +import fr.dossierfacile.common.enums.DocumentCategory; +import fr.dossierfacile.common.enums.DocumentSubCategory; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Optional; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class EditedFile { + + private DocumentCategory documentCategory; + private DocumentSubCategory documentSubCategory; + private Long tenantId; + private Long guarantorId; + private Long documentId; + private Long fileId; + private String fileName; + private EditionType editionType; + + public static EditedFile from(File file, EditionType editionType) { + Document document = file.getDocument(); + return EditedFile.builder() + .documentCategory(Optional.ofNullable(document) + .map(Document::getDocumentCategory).orElse(null)) + .documentSubCategory(Optional.ofNullable(document) + .map(Document::getDocumentSubCategory).orElse(null)) + .documentId(Optional.ofNullable(document) + .map(Document::getId).orElse(null)) + .tenantId(Optional.ofNullable(document) + .map(Document::getTenant) + .map(Tenant::getId).orElse(null)) + .guarantorId(Optional.ofNullable(document) + .map(Document::getGuarantor) + .map(Guarantor::getId).orElse(null)) + .fileId(file.getId()) + .fileName(Optional.ofNullable(file.getStorageFile()) + .map(StorageFile::getName).orElse(null)) + .editionType(editionType) + .build(); + } + +}