Skip to content

Commit

Permalink
Merge branch 'release/2023.12.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
juliette-derancourt committed Dec 19, 2023
2 parents ba7763c + 0d4d309 commit 1c5a20b
Show file tree
Hide file tree
Showing 145 changed files with 2,483 additions and 785 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@


import com.google.gson.Gson;
import fr.dossierfacile.api.front.amqp.model.DocumentModel;
import fr.dossierfacile.common.FileAnalysisCriteria;
import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.File;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -16,8 +15,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.TreeMap;
import java.util.Collections;

@Component
@Slf4j
Expand All @@ -31,27 +29,21 @@ public class Producer {
private String exchangeFileProcess;
@Value("${rabbitmq.routing.key.file.analyze}")
private String routingKeyAnalyzeFile;

@Value("${rabbitmq.routing.key.document.analyze}")
private String routingKeyAnalyzeDocument;
//Pdf generation
@Value("${rabbitmq.exchange.pdf.generator}")
private String exchangePdfGenerator;
@Value("${rabbitmq.routing.key.pdf.generator.watermark-document}")
private String routingKeyPdfGenerator;
@Value("${rabbitmq.routing.key.pdf.generator.apartment-sharing}")
private String routingKeyPdfGeneratorApartmentSharing;
@Value("${rabbitmq.routing.key.pdf.generator.watermark-document}")
private String routingKeyPdfGeneratorWatermarkDocument;

@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Async
public void generatePdf(Long documentId, Long logId) {
DocumentModel documentModel = DocumentModel.builder().id(documentId).logId(logId).build();
log.info("Sending document with ID [" + documentId + "] for pdf generation");
amqpTemplate.convertAndSend(exchangePdfGenerator, routingKeyPdfGenerator, gson.toJson(documentModel));
}

@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Async
public void generateFullPdf(Long apartmentSharingId) {
Message msg = messageWithId(apartmentSharingId);
Message msg = new Message(gson.toJson(Collections.singletonMap("id", String.valueOf( apartmentSharingId))).getBytes());
log.info("Sending apartmentSharing with ID [" + apartmentSharingId + "] for Full PDF generation");
amqpTemplate.send(exchangePdfGenerator, routingKeyPdfGeneratorApartmentSharing, msg);
}
Expand All @@ -61,13 +53,33 @@ public void generateFullPdf(Long apartmentSharingId) {
public void analyzeFile(File file) {
Long fileId = file.getId();
log.info("Sending file with ID [{}] for analysis", fileId);
amqpTemplate.send(exchangeFileProcess, routingKeyAnalyzeFile, messageWithId(fileId));
MessageProperties properties = new MessageProperties();
properties.setHeader("timestamp", System.currentTimeMillis());
Message msg = new Message(gson.toJson(Collections.singletonMap("id", String.valueOf( fileId))).getBytes(), properties);
amqpTemplate.send(exchangeFileProcess, routingKeyAnalyzeFile, msg);
}

private Message messageWithId(Long id) {
Map<String, String> body = new TreeMap<>();
body.putIfAbsent("id", String.valueOf(id));
return new Message(gson.toJson(body).getBytes(), new MessageProperties());
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Async
public void sendDocumentForAnalysis(Document document) {
log.debug("Sending document with ID [{}] for analysis", document.getId());
MessageProperties properties = new MessageProperties();
properties.setHeader("timestamp", System.currentTimeMillis());
Message msg = new Message(
gson.toJson(Collections.singletonMap("id", String.valueOf( document.getId()))).getBytes(),
properties);
amqpTemplate.send(exchangeFileProcess, routingKeyAnalyzeDocument, msg);
}

@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Async
public void sendDocumentForPdfGeneration(Document document) {
log.debug("Sending document with ID [{}] for pdf generation", document.getId());
MessageProperties properties = new MessageProperties();
properties.setHeader("timestamp", System.currentTimeMillis());
Message msg = new Message(
gson.toJson(Collections.singletonMap("id", String.valueOf( document.getId()))).getBytes(),
properties);
amqpTemplate.send(exchangePdfGenerator, routingKeyPdfGeneratorWatermarkDocument, msg);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package fr.dossierfacile.api.front.controller;

import fr.dossierfacile.api.front.amqp.Producer;
import fr.dossierfacile.api.front.exception.FileNotFoundException;
import fr.dossierfacile.api.front.repository.FileRepository;
import fr.dossierfacile.api.front.security.interfaces.AuthenticationFacade;
import fr.dossierfacile.api.front.service.interfaces.DocumentService;
import fr.dossierfacile.api.front.service.interfaces.FileService;
import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.DocumentPdfGenerationLog;
import fr.dossierfacile.common.entity.File;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.repository.DocumentPdfGenerationLogRepository;
import fr.dossierfacile.common.service.interfaces.FileStorageService;
import fr.dossierfacile.common.service.interfaces.SharedFileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
Expand All @@ -35,25 +29,14 @@
public class FileController {
private static final String FILE_NO_EXIST = "The file does not exist";
private final FileService fileService;
private final SharedFileService sharedFileService;
private final DocumentService documentService;
private final Producer producer;
private final AuthenticationFacade authenticationFacade;
private final FileRepository fileRepository;
private final FileStorageService fileStorageService;
private final DocumentPdfGenerationLogRepository documentPdfGenerationLogRepository;

@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
var tenant = authenticationFacade.getLoggedTenant();
Document document = fileService.delete(id, tenant);
if (document != null) {
documentService.initializeFieldsToProcessPdfGeneration(document);
producer.generatePdf(document.getId(),
documentPdfGenerationLogRepository.save(DocumentPdfGenerationLog.builder()
.documentId(document.getId())
.build()).getId());
}
fileService.delete(id, tenant);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package fr.dossierfacile.api.front.controller;

import fr.dossierfacile.api.front.model.tenant.PartnerAccessModel;
import fr.dossierfacile.api.front.security.interfaces.AuthenticationFacade;
import fr.dossierfacile.api.front.service.interfaces.PartnerAccessService;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.utils.DateBasedFeatureToggle;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.ResponseEntity.ok;

@RestController
@AllArgsConstructor
@RequestMapping("/api/tenant/partners")
@Slf4j
public class PartnerAccessController {

private final AuthenticationFacade authenticationFacade;
private final PartnerAccessService partnerAccessService;
private final PartnerAccessRevocationToggle toggle;

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PartnerAccessModel>> getPartnerAccesses() {
if (toggle.isNotActive()) {
return ok(List.of());
}
Tenant tenant = authenticationFacade.getLoggedTenant();
return ok(partnerAccessService.getExternalPartners(tenant));
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> revokePartnerAccess(@PathVariable("id") Long userApiId) {
log.info("Requesting access revocation for partner {}", userApiId);
if (toggle.isNotActive()) {
return ResponseEntity.status(FORBIDDEN).build();
}
Tenant tenant = authenticationFacade.getLoggedTenant();
partnerAccessService.deleteAccess(tenant, userApiId);
return ok().build();
}

@Component
// TODO delete after activation
static class PartnerAccessRevocationToggle extends DateBasedFeatureToggle {

public PartnerAccessRevocationToggle(@Value("${toggle.partners.revocation.activation.date:}") String activationDate) {
super(activationDate);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.dossierfacile.api.front.mapper;

import fr.dossierfacile.api.front.model.tenant.PartnerAccessModel;
import fr.dossierfacile.common.entity.TenantUserApi;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.stereotype.Component;

@Component
@Mapper(componentModel = "spring")
public interface PartnerAccessMapper {

@Mapping(source = "userApi.id", target = "id")
@Mapping(source = "userApi.name2", target = "name")
@Mapping(source = "userApi.logoUrl", target = "logoUrl")
PartnerAccessModel toModel(TenantUserApi tenantUserApi);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fr.dossierfacile.api.front.model.tenant;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PartnerAccessModel {

private Long id;
private String name;
private String logoUrl;
private LocalDate accessGrantedDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import fr.dossierfacile.api.front.amqp.Producer;
import fr.dossierfacile.api.front.exception.FileNotFoundException;
import fr.dossierfacile.api.front.repository.FileRepository;
import fr.dossierfacile.api.front.service.interfaces.DocumentService;
import fr.dossierfacile.api.front.service.interfaces.FileService;
import fr.dossierfacile.api.front.service.interfaces.TenantService;
import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.DocumentPdfGenerationLog;
import fr.dossierfacile.common.entity.File;
import fr.dossierfacile.common.repository.DocumentPdfGenerationLogRepository;
import fr.dossierfacile.common.service.interfaces.FileStorageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,25 +30,16 @@
@Slf4j
public class ApiPartnerFileController {
private final FileService fileService;
private final DocumentService documentService;
private final Producer producer;
private final TenantService tenantService;
private final FileRepository fileRepository;
private final FileStorageService fileStorageService;
private final DocumentPdfGenerationLogRepository documentPdfGenerationLogRepository;

@PreAuthorize("hasPermissionOnTenant(#tenantId)")
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id, @PathVariable Long tenantId) {
var tenant = tenantService.findById(tenantId);
Document document = fileService.delete(id, tenant);
if (document != null) {
documentService.initializeFieldsToProcessPdfGeneration(document);
producer.generatePdf(document.getId(),
documentPdfGenerationLogRepository.save(DocumentPdfGenerationLog.builder()
.documentId(document.getId())
.build()).getId());
}

return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import fr.dossierfacile.api.front.service.interfaces.DocumentService;
import fr.dossierfacile.api.front.util.TransactionalUtil;
import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.DocumentPdfGenerationLog;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.enums.PartnerCallBackType;
import fr.dossierfacile.common.enums.TenantFileStatus;
import fr.dossierfacile.common.repository.DocumentPdfGenerationLogRepository;
import fr.dossierfacile.common.repository.TenantCommonRepository;
import fr.dossierfacile.common.service.interfaces.LogService;
import fr.dossierfacile.common.service.interfaces.PartnerCallBackService;
Expand All @@ -28,17 +26,15 @@ public abstract class AbstractDocumentSaveStep<T extends DocumentForm> implement
@Autowired
private TenantMapper tenantMapper;
@Autowired
private Producer producer;
@Autowired
private DocumentPdfGenerationLogRepository documentPdfGenerationLogRepository;
@Autowired
private DocumentService documentService;
@Autowired
private PartnerCallBackService partnerCallBackService;
@Autowired
private TenantCommonRepository tenantCommonRepository;
@Autowired
private LogService logService;
@Autowired
private Producer producer;

@Override
@Transactional
Expand All @@ -51,12 +47,13 @@ public TenantModel saveStep(Tenant tenant, T documentForm) {

Document document = saveDocument(tenant, documentForm);
logService.saveDocumentEditedLog(document, tenant);
documentService.markDocumentAsEdited(document);

TransactionalUtil.afterCommit(() -> {
producer.sendDocumentForAnalysis(document);
producer.sendDocumentForPdfGeneration(document);
});

Long logId = documentPdfGenerationLogRepository.save(
DocumentPdfGenerationLog.builder()
.documentId(document.getId())
.build()).getId();
TransactionalUtil.afterCommit(() -> producer.generatePdf(document.getId(), logId));
return tenantMapper.toTenantModel(document.getTenant() != null ? document.getTenant() : document.getGuarantor().getTenant());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected Document saveDocument(Tenant tenant, DocumentIdentificationGuarantorLe

saveFiles(documentIdentificationGuarantorLegalPersonForm, document);

documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.IDENTIFICATION_LEGAL_PERSON);
tenantStatusService.updateTenantStatus(tenant);
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ protected Document saveDocument(Tenant tenant, DocumentIdentificationRepresentan

saveFiles(documentIdentificationRepresentanGuarantorLegalPersonForm, document);

documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.IDENTIFICATION);
tenantStatusService.updateTenantStatus(tenant);
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected Document saveDocument(Tenant tenant, DocumentFinancialGuarantorNatural
document.setCustomText(documentFinancialGuarantorNaturalPersonForm.getCustomText());
}
documentRepository.save(document);
documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.FINANCIAL);
if (tenant.getStatus() == TenantFileStatus.VALIDATED) {
documentService.resetValidatedDocumentsStatusOfSpecifiedCategoriesToToProcess(guarantor.getDocuments(), List.of(DocumentCategory.PROFESSIONAL, DocumentCategory.FINANCIAL, DocumentCategory.TAX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected Document saveDocument(Tenant tenant, DocumentIdentificationGuarantorNa

saveFiles(documentIdentificationGuarantorNaturalPersonForm, document);

documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.IDENTIFICATION);
tenantStatusService.updateTenantStatus(tenant);
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected Document saveDocument(Tenant tenant, DocumentIdentificationGuarantorNa

saveFiles(documentIdentificationGuarantorNaturalPersonFileForm, document);

documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.IDENTIFICATION);
tenantStatusService.updateTenantStatus(tenant);
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected Document saveDocument(Tenant tenant, DocumentProfessionalGuarantorNatu

saveFiles(documentProfessionalGuarantorNaturalPersonForm, document);

documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.PROFESSIONAL);
if (tenant.getStatus() == TenantFileStatus.VALIDATED) {
documentService.resetValidatedDocumentsStatusOfSpecifiedCategoriesToToProcess(guarantor.getDocuments(), List.of(DocumentCategory.PROFESSIONAL, DocumentCategory.FINANCIAL, DocumentCategory.TAX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected Document saveDocument(Tenant tenant, DocumentResidencyGuarantorNatural

saveFiles(documentResidencyGuarantorNaturalPersonForm, document);

documentService.initializeFieldsToProcessPdfGeneration(document);
tenant.lastUpdateDateProfile(LocalDateTime.now(), DocumentCategory.RESIDENCY);
tenantStatusService.updateTenantStatus(tenant);
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
Expand Down
Loading

0 comments on commit 1c5a20b

Please sign in to comment.