Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tenant): Update tenant logs #674

Merged
merged 3 commits into from
Dec 20, 2023
Merged
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 @@ -65,7 +65,7 @@ public ResponseEntity<Void> confirmAccount(@PathVariable String token) {
public ResponseEntity<TenantModel> names(@Validated(Dossier.class) @RequestBody NamesForm namesForm) {
var tenant = authenticationFacade.getTenant(namesForm.getTenantId() );
TenantModel tenantModel = tenantService.saveStepRegister(tenant, namesForm, StepRegister.NAMES);
logService.saveLog(LogType.ACCOUNT_EDITED, tenantModel.getId());
logService.saveStepLog(tenantModel.getId(), StepRegister.NAMES.getClazz().getSimpleName());
Tenant loggedTenant = (namesForm.getTenantId() == null) ? tenant : authenticationFacade.getLoggedTenant();
return ok(tenantMapper.toTenantModel(loggedTenant));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ResponseEntity<TenantModel> account(@Validated(ApiPartner.class) @Request
public ResponseEntity<TenantModel> names(@Validated(ApiPartner.class) @RequestBody NamesForm namesForm) {
var tenant = tenantService.findById(namesForm.getTenantId());
var tenantModel = tenantService.saveStepRegister(tenant, namesForm, StepRegister.NAMES);
logService.saveLog(LogType.ACCOUNT_EDITED, tenantModel.getId());
logService.saveStepLog(tenantModel.getId(), StepRegister.NAMES.getClazz().getSimpleName());
return ok(tenantModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.enums.PartnerCallBackType;
import fr.dossierfacile.common.enums.TenantFileStatus;
import fr.dossierfacile.common.model.log.EditionType;
import fr.dossierfacile.common.repository.TenantCommonRepository;
import fr.dossierfacile.common.service.interfaces.LogService;
import fr.dossierfacile.common.service.interfaces.PartnerCallBackService;
Expand Down Expand Up @@ -46,7 +47,7 @@ public TenantModel saveStep(Tenant tenant, T documentForm) {
}

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

TransactionalUtil.afterCommit(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,39 @@

@Getter
public enum StepRegister {
ACCOUNT_PARTNER_API(AccountApiPartner.class.getName()),
ACCOUNT(Account.class.getName()),
NAMES(Names.class.getName()),
APPLICATION_V1(ApplicationV1.class.getName()),
APPLICATION(Application.class.getName()),
HONOR_DECLARATION(HonorDeclaration.class.getName()),
DOCUMENT_IDENTIFICATION(DocumentIdentification.class.getName()),
DOCUMENT_RESIDENCY(DocumentResidency.class.getName()),
DOCUMENT_PROFESSIONAL(DocumentProfessional.class.getName()),
DOCUMENT_FINANCIAL(DocumentFinancial.class.getName()),
DOCUMENT_TAX(DocumentTax.class.getName()),
NAME_GUARANTOR_NATURAL_PERSON(NameGuarantorNaturalPerson.class.getName()),
DOCUMENT_IDENTIFICATION_GUARANTOR_NATURAL_PERSON_FILE(DocumentIdentificationGuarantorNaturalPersonFile.class.getName()),
DOCUMENT_IDENTIFICATION_GUARANTOR_NATURAL_PERSON(DocumentIdentificationGuarantorNaturalPerson.class.getName()),
DOCUMENT_RESIDENCY_GUARANTOR_NATURAL_PERSON(DocumentResidencyGuarantorNaturalPerson.class.getName()),
DOCUMENT_PROFESSIONAL_GUARANTOR_NATURAL_PERSON(DocumentProfessionalGuarantorNaturalPerson.class.getName()),
DOCUMENT_FINANCIAL_GUARANTOR_NATURAL_PERSON(DocumentFinancialGuarantorNaturalPerson.class.getName()),
DOCUMENT_TAX_GUARANTOR_NATURAL_PERSON(DocumentTaxGuarantorNaturalPerson.class.getName()),
DOCUMENT_IDENTIFICATION_GUARANTOR_ORGANISM(DocumentIdentificationGuarantorOrganism.class.getName()),
DOCUMENT_IDENTIFICATION_GUARANTOR_LEGAL_PERSON(DocumentIdentificationGuarantorLegalPerson.class.getName()),
DOCUMENT_IDENTIFICATION_REPRESENTANT_GUARANTOR_LEGAL_PERSON(DocumentIdentificationRepresentanGuarantorLegalPerson.class.getName()),
GUARANTOR_TYPE(GuarantorType.class.getName()),
NAME_GUARANTOR_LEGAL_PERSON(NameGuarantorLegalPerson.class.getName()),
NAME_IDENTIFICATION_REPRESENTANT_GUARANTOR_LEGAL_PERSON(NameRepresentantGuarantorLegalPerson.class.getName());
private final String label;
ACCOUNT_PARTNER_API(AccountApiPartner.class),
ACCOUNT(Account.class),
NAMES(Names.class),
APPLICATION_V1(ApplicationV1.class),
APPLICATION(Application.class),
HONOR_DECLARATION(HonorDeclaration.class),
DOCUMENT_IDENTIFICATION(DocumentIdentification.class),
DOCUMENT_RESIDENCY(DocumentResidency.class),
DOCUMENT_PROFESSIONAL(DocumentProfessional.class),
DOCUMENT_FINANCIAL(DocumentFinancial.class),
DOCUMENT_TAX(DocumentTax.class),
NAME_GUARANTOR_NATURAL_PERSON(NameGuarantorNaturalPerson.class),
DOCUMENT_IDENTIFICATION_GUARANTOR_NATURAL_PERSON_FILE(DocumentIdentificationGuarantorNaturalPersonFile.class),
DOCUMENT_IDENTIFICATION_GUARANTOR_NATURAL_PERSON(DocumentIdentificationGuarantorNaturalPerson.class),
DOCUMENT_RESIDENCY_GUARANTOR_NATURAL_PERSON(DocumentResidencyGuarantorNaturalPerson.class),
DOCUMENT_PROFESSIONAL_GUARANTOR_NATURAL_PERSON(DocumentProfessionalGuarantorNaturalPerson.class),
DOCUMENT_FINANCIAL_GUARANTOR_NATURAL_PERSON(DocumentFinancialGuarantorNaturalPerson.class),
DOCUMENT_TAX_GUARANTOR_NATURAL_PERSON(DocumentTaxGuarantorNaturalPerson.class),
DOCUMENT_IDENTIFICATION_GUARANTOR_ORGANISM(DocumentIdentificationGuarantorOrganism.class),
DOCUMENT_IDENTIFICATION_GUARANTOR_LEGAL_PERSON(DocumentIdentificationGuarantorLegalPerson.class),
DOCUMENT_IDENTIFICATION_REPRESENTANT_GUARANTOR_LEGAL_PERSON(DocumentIdentificationRepresentanGuarantorLegalPerson.class),
GUARANTOR_TYPE(GuarantorType.class),
NAME_GUARANTOR_LEGAL_PERSON(NameGuarantorLegalPerson.class),
NAME_IDENTIFICATION_REPRESENTANT_GUARANTOR_LEGAL_PERSON(NameRepresentantGuarantorLegalPerson.class);

StepRegister(String label) {
this.label = label;
private final Class<?> clazz;

StepRegister(Class<?> clazz) {
this.clazz = clazz;
}

public String getLabel() {
return clazz.getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ protected void linkEmailToTenants(Tenant tenantCreate, List<Pair<Tenant, String>
}
}

TenantModel saveStep(Tenant tenant, ApplicationType applicationType, List<Tenant> tenantToDelete, List<CoTenantForm> tenantToCreate) {
TenantModel saveStep(Tenant tenant, ApplicationType newApplicationType, List<Tenant> tenantToDelete, List<CoTenantForm> tenantToCreate) {
ApartmentSharing apartmentSharing = tenant.getApartmentSharing();
apartmentSharing.setApplicationType(applicationType);
ApplicationType currentApplicationType = apartmentSharing.getApplicationType();
apartmentSharing.setApplicationType(newApplicationType);
apartmentSharingService.resetDossierPdfGenerated(apartmentSharing);

deleteCoTenants(tenantToDelete);
logService.saveApplicationTypeChangedLog(apartmentSharing.getTenants(), currentApplicationType, newApplicationType);
createCoTenants(tenant, tenantToCreate, apartmentSharing);

LocalDateTime now = LocalDateTime.now();
Expand Down Expand Up @@ -226,7 +228,7 @@ private void createCoTenants(Tenant tenantCreate, List<CoTenantForm> tenants, Ap
}

private void deleteCoTenants(List<Tenant> tenantToDelete) {
tenantToDelete.stream().forEach(t -> userService.deleteAccount(t));
tenantToDelete.forEach(userService::deleteAccount);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
import fr.dossierfacile.api.front.service.interfaces.TenantStatusService;
import fr.dossierfacile.api.front.util.TransactionalUtil;
import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.DocumentAnalysisReport;
import fr.dossierfacile.common.entity.File;
import fr.dossierfacile.common.entity.Person;
import fr.dossierfacile.common.entity.StorageFile;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.enums.DocumentCategory;
import fr.dossierfacile.common.enums.DocumentStatus;
import fr.dossierfacile.common.enums.TenantFileStatus;
import fr.dossierfacile.common.model.log.EditionType;
import fr.dossierfacile.common.repository.DocumentAnalysisReportRepository;
import fr.dossierfacile.common.repository.StorageFileRepository;
import fr.dossierfacile.common.service.interfaces.DocumentHelperService;
import fr.dossierfacile.common.service.interfaces.LogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -46,6 +47,7 @@ public class DocumentServiceImpl implements DocumentService {
private final ApartmentSharingService apartmentSharingService;
private final DocumentHelperService documentHelperService;
private final MinifyFileProducer minifyFileProducer;
private final LogService logService;
private final Producer producer;

@Override
Expand Down Expand Up @@ -98,6 +100,7 @@ public void delete(Long documentId, Tenant referenceTenant) {
Document document = documentRepository.findByIdForApartmentSharing(documentId, referenceTenant.getApartmentSharing().getId())
.orElseThrow(() -> new DocumentNotFoundException(documentId));
delete(document);
logService.saveDocumentEditedLog(document, referenceTenant, EditionType.DELETE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import fr.dossierfacile.common.entity.File;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.enums.DocumentStatus;
import fr.dossierfacile.common.model.log.EditionType;
import fr.dossierfacile.common.service.interfaces.LogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@AllArgsConstructor
@Slf4j
Expand All @@ -36,7 +35,7 @@ public Document delete(Long id, Tenant tenant) {
document.getFiles().remove(file);
fileRepository.delete(file);

logService.saveDocumentEditedLog(document, tenant);
logService.saveDocumentEditedLog(document, tenant, EditionType.DELETE);
documentService.markDocumentAsEdited(document);

if (document.getFiles().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum LogType {
ACCOUNT_CREATED,
ACCOUNT_CREATED_VIA_KC,
ACCOUNT_LINK, // first connection on DF
APPLICATION_TYPE_CHANGED,
ACCOUNT_COMPLETED,
ACCOUNT_DENIED,
ACCOUNT_EDITED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.dossierfacile.common.model.log;

import com.fasterxml.jackson.annotation.JsonInclude;
import fr.dossierfacile.common.enums.ApplicationType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

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

private ApplicationType oldType;
private ApplicationType newType;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.dossierfacile.common.model;
package fr.dossierfacile.common.model.log;

import com.fasterxml.jackson.annotation.JsonInclude;
import fr.dossierfacile.common.entity.Document;
Expand All @@ -18,23 +18,23 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EditedDocumentModel {
public class EditedDocument {

private DocumentCategory documentCategory;
private DocumentSubCategory documentSubCategory;
private Boolean noDocument;
private Long tenantId;
private Long guarantorId;
private EditionType editionType;

public static EditedDocumentModel from(Document document) {
return EditedDocumentModel.builder()
public static EditedDocument from(Document document, EditionType editionType) {
return EditedDocument.builder()
.documentCategory(document.getDocumentCategory())
.documentSubCategory(document.getDocumentSubCategory())
.noDocument(document.getNoDocument())
.tenantId(Optional.ofNullable(document.getTenant())
.map(Tenant::getId).orElse(null))
.guarantorId(Optional.ofNullable(document.getGuarantor())
.map(Guarantor::getId).orElse(null))
.editionType(editionType)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.dossierfacile.common.model.log;

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

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

private String step;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fr.dossierfacile.common.model.log;

public enum EditionType {
ADD,
DELETE
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fr.dossierfacile.common.repository.ApartmentSharingRepository;
import fr.dossierfacile.common.service.interfaces.ApartmentSharingCommonService;
import fr.dossierfacile.common.service.interfaces.FileStorageService;
import fr.dossierfacile.common.service.interfaces.LogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -20,8 +21,10 @@
@AllArgsConstructor
@Slf4j
public class ApartmentSharingCommonServiceImpl implements ApartmentSharingCommonService {
ApartmentSharingRepository apartmentSharingRepository;
FileStorageService fileStorageService;

private final ApartmentSharingRepository apartmentSharingRepository;
private final FileStorageService fileStorageService;
private final LogService logService;

@Override
@Transactional(propagation = Propagation.SUPPORTS)
Expand All @@ -43,7 +46,11 @@ public void resetDossierPdfGenerated(ApartmentSharing apartmentSharing) {
@Transactional(propagation = Propagation.SUPPORTS)
public void removeTenant(ApartmentSharing apartmentSharing, Tenant tenant) {
apartmentSharing.getTenants().remove(tenant);
apartmentSharing.setApplicationType((apartmentSharing.getNumberOfTenants() >= 2) ? ApplicationType.GROUP : ApplicationType.ALONE);

ApplicationType newApplicationType = (apartmentSharing.getNumberOfTenants() >= 2) ? ApplicationType.GROUP : ApplicationType.ALONE;
logService.saveApplicationTypeChangedLog(apartmentSharing.getTenants(), apartmentSharing.getApplicationType(), newApplicationType);
apartmentSharing.setApplicationType(newApplicationType);

resetDossierPdfGenerated(apartmentSharing);
apartmentSharingRepository.save(apartmentSharing);
}
Expand Down
Loading