Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
this.messageId = messageId;
}

public String getTitle() {

Check failure on line 74 in dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/TenantLog.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=MTES-MCT_dossierfacile-backend&issues=AZ4haQZUoNXn05QXSmQD&open=AZ4haQZUoNXn05QXSmQD&pullRequest=1240
StringBuilder builder = new StringBuilder();
if (this.getOperatorId() != null) {
if (this.getLogDetails() != null && this.getLogDetails().get(NEW_SUM) != null) {
Expand All @@ -86,7 +86,8 @@
}
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);
}
Expand All @@ -104,6 +105,10 @@
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: ");
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Loading