Skip to content

Commit

Permalink
chore: merge DeletedOwnerModel and mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Oct 8, 2024
1 parent 1f76407 commit bfabe07
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 162 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.dossierfacile.common.entity.Owner;
import fr.dossierfacile.common.entity.OwnerLog;
import fr.dossierfacile.common.enums.OwnerLogType;
import fr.dossierfacile.common.mapper.log.DeletedOwnerMapper;
import fr.dossierfacile.common.utils.MapperUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -17,7 +18,6 @@
public class OwnerLogServiceImpl implements OwnerLogService {
private final OwnerLogRepository repository;
private final DeletedOwnerMapper deletedOwnerMapper;

private final ObjectMapper objectMapper = MapperUtil.newObjectMapper();

private void saveLog(OwnerLog log) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fr.dossierfacile.api.dossierfacileapiowner.log;
package fr.dossierfacile.common.mapper.log;

import com.google.common.hash.Hashing;
import fr.dossierfacile.common.entity.Owner;
import fr.dossierfacile.common.model.log.DeletedOwnerModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
Expand All @@ -21,9 +22,9 @@ static String hash(String value) {
return Hashing.sha256().hashString(value, StandardCharsets.UTF_8).toString();
}

@Mapping(target = "hEmail", source = "email", qualifiedByName = "hashString")
@Mapping(target = "hFirstName", source = "firstName", qualifiedByName = "hashString")
@Mapping(target = "hLastName", source = "lastName", qualifiedByName = "hashString")
@Mapping(target = "hPreferredName", source = "preferredName", qualifiedByName = "hashString")
@Mapping(target = "hashedEmail", source = "email", qualifiedByName = "hashString")
@Mapping(target = "hashedLastname", source = "lastName", qualifiedByName = "hashString")
@Mapping(target = "hashedFirstname", source = "firstName", qualifiedByName = "hashString")
@Mapping(target = "hashedPreferredName", source = "preferredName", qualifiedByName = "hashString")
DeletedOwnerModel toDeletedOwnerModel(Owner owner);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fr.dossierfacile.common.mapper.log;

import com.google.common.hash.Hashing;
import fr.dossierfacile.common.entity.Document;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.model.log.DeletedTenantModel;
import fr.dossierfacile.common.model.apartment_sharing.DocumentModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@Mapper(componentModel = "spring")
public interface DeletedTenantMapper {
@Named("hashString")
static String hash(String value) {
if (value == null) {
return "";
}
return Hashing.sha256().hashString(value, StandardCharsets.UTF_8).toString();
}

@Mapping(target = "hashedEmail", source = "email", qualifiedByName = "hashString")
@Mapping(target = "hashedLastname", source = "lastName", qualifiedByName = "hashString")
@Mapping(target = "hashedFirstname", source = "firstName", qualifiedByName = "hashString")
@Mapping(target = "hashedPreferredName", source = "preferredName", qualifiedByName = "hashString")
@Mapping(target = "applicationType", expression = "java((tenant.getApartmentSharing() != null )? tenant.getApartmentSharing().getApplicationType() : null)")
@Mapping(target = "apartmentSharingId", expression = "java((tenant.getApartmentSharing() != null )? tenant.getApartmentSharing().getId() : null)")
DeletedTenantModel toDeletedTenantModel(Tenant tenant);

@Mapping(target = "name", expression = "java((document.getWatermarkFile() != null )? document.getWatermarkFile().getName() : null)")
DocumentModel toDocumentModel(Document document);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package fr.dossierfacile.common.model.apartment_sharing;
package fr.dossierfacile.common.model.log;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import fr.dossierfacile.common.enums.ApplicationType;
import fr.dossierfacile.common.enums.TenantFileStatus;
import fr.dossierfacile.common.enums.TenantType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Data
@AllArgsConstructor
Expand All @@ -28,9 +24,9 @@ public class DeletedOwnerModel {
private String hashedPreferredName;
private Boolean franceConnect;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
private LocalDateTime creationDateTime;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
private LocalDateTime lastUpdateDate;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.dossierfacile.common.model.apartment_sharing;
package fr.dossierfacile.common.model.log;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -7,6 +7,8 @@
import fr.dossierfacile.common.enums.ApplicationType;
import fr.dossierfacile.common.enums.TenantFileStatus;
import fr.dossierfacile.common.enums.TenantType;
import fr.dossierfacile.common.model.apartment_sharing.DocumentModel;
import fr.dossierfacile.common.model.apartment_sharing.GuarantorModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import fr.dossierfacile.common.enums.ApplicationType;
import fr.dossierfacile.common.enums.LogType;
import fr.dossierfacile.common.enums.OwnerLogType;
import fr.dossierfacile.common.mapper.DeletedOwnerCommonMapper;
import fr.dossierfacile.common.mapper.DeletedTenantCommonMapper;
import fr.dossierfacile.common.mapper.log.DeletedOwnerMapper;
import fr.dossierfacile.common.mapper.log.DeletedTenantMapper;
import fr.dossierfacile.common.model.log.ApplicationTypeChange;
import fr.dossierfacile.common.model.log.EditedDocument;
import fr.dossierfacile.common.model.log.EditedStep;
Expand All @@ -34,8 +34,8 @@ public class LogServiceImpl implements LogService {

private final TenantLogRepository repository;
private final OwnerLogCommonRepository ownerLogRepository;
private final DeletedTenantCommonMapper deletedTenantCommonMapper;
private final DeletedOwnerCommonMapper deletedOwnerCommonMapper;
private final DeletedTenantMapper deletedTenantMapper;
private final DeletedOwnerMapper deletedOwnerMapper;
private final ObjectMapper objectMapper;

private void saveLog(TenantLog log) {
Expand Down Expand Up @@ -65,7 +65,7 @@ public void saveLogWithOwnerData(OwnerLogType logType, Owner owner) {
.logType(logType)
.ownerId(owner.getId())
.creationDateTime(LocalDateTime.now())
.jsonProfile(writeAsString(deletedOwnerCommonMapper.toDeletedOwnerModel(owner)))
.jsonProfile(writeAsString(deletedOwnerMapper.toDeletedOwnerModel(owner)))
.build()
);
}
Expand All @@ -79,7 +79,7 @@ public void saveLogWithTenantData(LogType logType, Tenant tenant) {
.creationDateTime(LocalDateTime.now())
.userApis(tenant.getTenantsUserApi().stream()
.mapToLong(tenantUserApi -> tenantUserApi.getUserApi().getId()).toArray())
.jsonProfile(writeAsString(deletedTenantCommonMapper.toDeletedTenantModel(tenant)))
.jsonProfile(writeAsString(deletedTenantMapper.toDeletedTenantModel(tenant)))
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,7 @@
<include file="db/migration/20240925110000-add-column-warning-owner.xml"/>
<include file="db/migration/202409250000-create-application-log.xml"/>
<include file="db/migration/202409300000-update-userapi.xml"/>
<include file="db/migration/202410070000-update-jsonprofile-owner_log.xml"/>


</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

<changeSet id="202410070000-01" author="fabien">
<sql>
<![CDATA[
UPDATE owner_log
SET json_profile = jsonb_set(
jsonb_set(
jsonb_set(
jsonb_set(
json_profile,
'{hashedEmail}',
COALESCE(json_profile->'hemail', 'null'::jsonb) -- Si 'hemail' est absent, on utilise 'null'
),
'{hashedLastname}',
COALESCE(json_profile->'hlastName', 'null'::jsonb) -- Si 'hlastName' est absent
),
'{hashedFirstname}',
COALESCE(json_profile->'hfirstName', 'null'::jsonb) -- Si 'hfirstName' est absent
),
'{hashedPreferredName}',
COALESCE(json_profile->'hpreferredName', 'null'::jsonb) -- Si 'hpreferredName' est absent
)
- 'hemail' - 'hlastName' - 'hfirstName' - 'hpreferredName'
WHERE log_type = 'ACCOUNT_DELETED';
]]>
</sql>
</changeSet>

</databaseChangeLog>

0 comments on commit bfabe07

Please sign in to comment.