99% working
This commit is contained in:
parent
801c30de52
commit
addbb2bee7
@ -0,0 +1,5 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model;
|
||||
|
||||
//TODO CLASSPATH FIX FOR CYCLIC DEPS
|
||||
public class ManualRedactions {
|
||||
}
|
||||
@ -12,5 +12,5 @@ import lombok.NoArgsConstructor;
|
||||
public class ManualAddResponse {
|
||||
|
||||
private String annotationId;
|
||||
private String commentId;
|
||||
private Long commentId;
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.data.annotations;
|
||||
|
||||
//TODO CLASSPATH FIX FOR CYCLIC DEPS
|
||||
public class AnnotationStatus {
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.data.annotations;
|
||||
|
||||
//TODO CLASSPATH FIX FOR CYCLIC DEPS
|
||||
public class Comment {
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.data.configuration;
|
||||
|
||||
//TODO CLASSPATH FIX FOR CYCLIC DEPS
|
||||
public class DigitalSignature {
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.data.configuration;
|
||||
|
||||
//TODO CLASSPATH FIX FOR CYCLIC DEPS
|
||||
public class LegalBasis {
|
||||
}
|
||||
@ -17,7 +17,7 @@ import java.io.Serializable;
|
||||
public class AnnotationEntityId implements Serializable {
|
||||
|
||||
@Column
|
||||
private String id;
|
||||
private String annotationId;
|
||||
@Column
|
||||
private String fileId;
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
@ -55,15 +55,15 @@ public class ExcludeFromAnalysisService {
|
||||
|
||||
// wipe force redactions
|
||||
var forceRedactions = forceRedactionPersistenceService.findForceRedactions(fileId, false);
|
||||
forceRedactions.forEach(f -> forceRedactionPersistenceService.softDelete(fileId, f.getId().getId(), now));
|
||||
forceRedactions.forEach(f -> forceRedactionPersistenceService.softDelete(fileId, f.getId().getAnnotationId(), now));
|
||||
|
||||
// wipe add manual redactions
|
||||
var addRedactions = addRedactionPersistenceService.findAddRedactions(fileId, false);
|
||||
addRedactions.forEach(f -> addRedactionPersistenceService.softDelete(fileId, f.getId().getId(), now));
|
||||
addRedactions.forEach(f -> addRedactionPersistenceService.softDelete(fileId, f.getId().getAnnotationId(), now));
|
||||
|
||||
// wipe removeRedactions
|
||||
var removeRedactions = removeRedactionPersistenceService.findRemoveRedactions(fileId, false);
|
||||
removeRedactions.forEach(f -> removeRedactionPersistenceService.softDelete(fileId, f.getId().getId(), now));
|
||||
removeRedactions.forEach(f -> removeRedactionPersistenceService.softDelete(fileId, f.getId().getAnnotationId(), now));
|
||||
|
||||
fileStatusPersistenceService.updateHasComments(fileId, false);
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Arrays;
|
||||
@ -102,36 +101,36 @@ public class FileService {
|
||||
public void softDeleteFile(String dossierId, String fileId, OffsetDateTime softDeletedTime) {
|
||||
|
||||
forceRedactionPersistenceService.findForceRedactions(fileId, false).forEach(annotation -> {
|
||||
forceRedactionPersistenceService.softDelete(fileId, annotation.getId().getId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), false).forEach(comment -> {
|
||||
forceRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
|
||||
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
|
||||
});
|
||||
});
|
||||
|
||||
removeRedactionPersistenceService.findRemoveRedactions(fileId, false).forEach(annotation -> {
|
||||
removeRedactionPersistenceService.softDelete(fileId, annotation.getId().getId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), false).forEach(comment -> {
|
||||
removeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
|
||||
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
|
||||
});
|
||||
});
|
||||
|
||||
addRedactionPersistenceService.findAddRedactions(fileId, false).forEach(annotation -> {
|
||||
addRedactionPersistenceService.softDelete(fileId, annotation.getId().getId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), false).forEach(comment -> {
|
||||
addRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
|
||||
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
|
||||
});
|
||||
});
|
||||
|
||||
recategorizationPersistenceService.findRecategorizations(fileId, false).forEach(recatigorization -> {
|
||||
recategorizationPersistenceService.softDelete(fileId, recatigorization.getId().getId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getId(), false).forEach(comment -> {
|
||||
recategorizationPersistenceService.softDelete(fileId, recatigorization.getId().getAnnotationId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), false).forEach(comment -> {
|
||||
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
|
||||
});
|
||||
});
|
||||
|
||||
legalBasisChangePersistenceService.findLegalBasisChanges(fileId, false).forEach(legalBasisChange -> {
|
||||
legalBasisChangePersistenceService.softDelete(fileId, legalBasisChange.getId().getId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, legalBasisChange.getId().getId(), false)
|
||||
legalBasisChangePersistenceService.softDelete(fileId, legalBasisChange.getId().getAnnotationId(), softDeletedTime);
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, legalBasisChange.getId().getAnnotationId(), false)
|
||||
.forEach(comment -> {
|
||||
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
|
||||
});
|
||||
@ -147,29 +146,29 @@ public class FileService {
|
||||
);
|
||||
|
||||
forceRedactionPersistenceService.findForceRedactions(fileId, true).forEach(annotation -> {
|
||||
forceRedactionPersistenceService.hardDelete(fileId, annotation.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), true).forEach(comment -> {
|
||||
forceRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
commentPersistenceService.hardDelete(comment.getId());
|
||||
});
|
||||
});
|
||||
|
||||
removeRedactionPersistenceService.findRemoveRedactions(fileId, true).forEach(annotation -> {
|
||||
removeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), true).forEach(comment -> {
|
||||
removeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
commentPersistenceService.hardDelete(comment.getId());
|
||||
});
|
||||
});
|
||||
|
||||
addRedactionPersistenceService.findAddRedactions(fileId, true).forEach(annotation -> {
|
||||
addRedactionPersistenceService.hardDelete(fileId, annotation.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), true).forEach(comment -> {
|
||||
addRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
commentPersistenceService.hardDelete(comment.getId());
|
||||
});
|
||||
});
|
||||
|
||||
recategorizationPersistenceService.findRecategorizations(fileId, true).forEach(recatigorization -> {
|
||||
recategorizationPersistenceService.hardDelete(fileId, recatigorization.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getId(), true).forEach(comment -> {
|
||||
recategorizationPersistenceService.hardDelete(fileId, recatigorization.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
commentPersistenceService.hardDelete(comment.getId());
|
||||
});
|
||||
});
|
||||
@ -179,8 +178,8 @@ public class FileService {
|
||||
public void undeleteFile(String dossierTemplateId, String dossierId, String fileId, OffsetDateTime softDeletedTime) {
|
||||
forceRedactionPersistenceService.findForceRedactions(fileId, true).forEach(annotation -> {
|
||||
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
forceRedactionPersistenceService.undelete(fileId, annotation.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), true).forEach(comment -> {
|
||||
forceRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
commentPersistenceService.undelete(comment.getId());
|
||||
}
|
||||
@ -190,8 +189,8 @@ public class FileService {
|
||||
|
||||
removeRedactionPersistenceService.findRemoveRedactions(fileId, true).forEach(annotation -> {
|
||||
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
removeRedactionPersistenceService.undelete(fileId, annotation.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), true).forEach(comment -> {
|
||||
removeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
commentPersistenceService.undelete(comment.getId());
|
||||
}
|
||||
@ -201,8 +200,8 @@ public class FileService {
|
||||
|
||||
addRedactionPersistenceService.findAddRedactions(fileId, true).forEach(annotation -> {
|
||||
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
addRedactionPersistenceService.undelete(fileId, annotation.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getId(), true).forEach(comment -> {
|
||||
addRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
commentPersistenceService.undelete(comment.getId());
|
||||
}
|
||||
@ -212,8 +211,8 @@ public class FileService {
|
||||
|
||||
recategorizationPersistenceService.findRecategorizations(fileId, true).forEach(recatigorization -> {
|
||||
if (recatigorization.getSoftDeletedTime().equals(softDeletedTime) || recatigorization.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
recategorizationPersistenceService.undelete(fileId, recatigorization.getId().getId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getId(), true).forEach(comment -> {
|
||||
recategorizationPersistenceService.undelete(fileId, recatigorization.getId().getAnnotationId());
|
||||
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true).forEach(comment -> {
|
||||
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
|
||||
commentPersistenceService.undelete(comment.getId());
|
||||
}
|
||||
|
||||
@ -60,10 +60,10 @@ public class ManualRedactionService {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
addRedactionPersistenceService.insert(fileId, annotationId, addRedactionRequest);
|
||||
|
||||
String commentId = null;
|
||||
Long commentId = null;
|
||||
if (addRedactionRequest.getComment() != null) {
|
||||
|
||||
addComment(fileId, annotationId, addRedactionRequest.getComment(), addRedactionRequest.getUser());
|
||||
commentId = addComment(fileId, annotationId, addRedactionRequest.getComment(), addRedactionRequest.getUser()).getId();
|
||||
}
|
||||
|
||||
handleAddToDictionary(fileId, annotationId, addRedactionRequest.getType(), addRedactionRequest.getValue(), addRedactionRequest
|
||||
@ -87,11 +87,11 @@ public class ManualRedactionService {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
removeRedactionPersistenceService.insert(fileId, removeRedactionRequest);
|
||||
|
||||
String commentId = null;
|
||||
Long commentId = null;
|
||||
if (removeRedactionRequest.getComment() != null) {
|
||||
|
||||
addComment(fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getComment(), removeRedactionRequest
|
||||
.getUser());
|
||||
commentId = addComment(fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getComment(), removeRedactionRequest
|
||||
.getUser()).getId();
|
||||
}
|
||||
|
||||
handleRemoveFromDictionary(dossierId, fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getStatus(),
|
||||
@ -118,11 +118,11 @@ public class ManualRedactionService {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
forceRedactionPersistenceService.insert(fileId, forceRedactionRequest);
|
||||
|
||||
String commentId = null;
|
||||
Long commentId = null;
|
||||
if (forceRedactionRequest.getComment() != null) {
|
||||
|
||||
addComment(fileId, forceRedactionRequest.getAnnotationId(), forceRedactionRequest.getComment(), forceRedactionRequest
|
||||
.getUser());
|
||||
commentId = addComment(fileId, forceRedactionRequest.getAnnotationId(), forceRedactionRequest.getComment(), forceRedactionRequest
|
||||
.getUser()).getId();
|
||||
}
|
||||
|
||||
if (forceRedactionRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
|
||||
@ -146,11 +146,11 @@ public class ManualRedactionService {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
legalBasisChangePersistenceService.insert(fileId, legalBasisChangeRequest);
|
||||
|
||||
String commentId = null;
|
||||
Long commentId = null;
|
||||
if (legalBasisChangeRequest.getComment() != null) {
|
||||
|
||||
addComment(fileId, legalBasisChangeRequest.getAnnotationId(), legalBasisChangeRequest.getComment(), legalBasisChangeRequest
|
||||
.getUser());
|
||||
commentId =addComment(fileId, legalBasisChangeRequest.getAnnotationId(), legalBasisChangeRequest.getComment(), legalBasisChangeRequest
|
||||
.getUser()).getId();
|
||||
}
|
||||
|
||||
if (legalBasisChangeRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
|
||||
@ -174,11 +174,11 @@ public class ManualRedactionService {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
recategorizationPersistenceService.insert(fileId, imageRecategorizationRequest);
|
||||
|
||||
String commentId = null;
|
||||
Long commentId = null;
|
||||
if (imageRecategorizationRequest.getComment() != null) {
|
||||
|
||||
addComment(fileId, imageRecategorizationRequest.getAnnotationId(), imageRecategorizationRequest.getComment(), imageRecategorizationRequest
|
||||
.getUser());
|
||||
commentId = addComment(fileId, imageRecategorizationRequest.getAnnotationId(), imageRecategorizationRequest.getComment(), imageRecategorizationRequest
|
||||
.getUser()).getId();
|
||||
}
|
||||
|
||||
if (imageRecategorizationRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
|
||||
@ -344,7 +344,7 @@ public class ManualRedactionService {
|
||||
RedactionLog redactionLog = fileManagementStorageService.getRedactionLog(dossierId, fileId);
|
||||
Optional<RedactionLogEntry> redactionLogEntryOptional = redactionLog.getRedactionLogEntry()
|
||||
.stream()
|
||||
.filter(entry -> entry.getId().equals(idRemoval.getId().getId()))
|
||||
.filter(entry -> entry.getId().equals(idRemoval.getId().getAnnotationId()))
|
||||
.findFirst();
|
||||
|
||||
if(!redactionLogEntryOptional.isPresent()) {
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
package com.iqser.red.service.peristence.v1.server.utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.common.Page;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -14,17 +17,8 @@ public class MagicConverter {
|
||||
|
||||
@SneakyThrows
|
||||
public static <S, T> Page<T> convert(org.springframework.data.domain.Page<S> sources, Class<T> target) {
|
||||
var noArgsConstructor = target.getConstructor();
|
||||
|
||||
List<T> targetList = new ArrayList<>();
|
||||
for (var s : sources) {
|
||||
var newInstance = noArgsConstructor.newInstance();
|
||||
BeanUtils.copyProperties(s, newInstance);
|
||||
targetList.add(newInstance);
|
||||
}
|
||||
|
||||
Page<T> result = new Page<>();
|
||||
result.setElements(targetList);
|
||||
result.setElements(convert(Lists.newArrayList(sources), target));
|
||||
result.setPage(sources.getNumber());
|
||||
result.setPageSize(sources.getSize());
|
||||
result.setTotalHits(sources.getTotalElements());
|
||||
@ -38,9 +32,7 @@ public class MagicConverter {
|
||||
|
||||
List<T> targetList = new ArrayList<>();
|
||||
for (var s : sources) {
|
||||
var newInstance = noArgsConstructor.newInstance();
|
||||
BeanUtils.copyProperties(s, newInstance);
|
||||
targetList.add(newInstance);
|
||||
targetList.add(convertOne(s, target, noArgsConstructor));
|
||||
}
|
||||
return targetList;
|
||||
|
||||
@ -52,9 +44,7 @@ public class MagicConverter {
|
||||
|
||||
Set<T> targetList = new HashSet<>();
|
||||
for (var s : sources) {
|
||||
var newInstance = noArgsConstructor.newInstance();
|
||||
BeanUtils.copyProperties(s, newInstance);
|
||||
targetList.add(newInstance);
|
||||
targetList.add(convertOne(s, target, noArgsConstructor));
|
||||
}
|
||||
return targetList;
|
||||
|
||||
@ -63,10 +53,33 @@ public class MagicConverter {
|
||||
@SneakyThrows
|
||||
public static <S, T> T convert(S source, Class<T> target) {
|
||||
var noArgsConstructor = target.getConstructor();
|
||||
return convertOne(source, target, noArgsConstructor);
|
||||
}
|
||||
|
||||
var newInstance = noArgsConstructor.newInstance();
|
||||
|
||||
@SneakyThrows
|
||||
public static <S, T> T convertOne(S source, Class<T> target, Constructor<T> constructor) {
|
||||
var newInstance = constructor.newInstance();
|
||||
BeanUtils.copyProperties(source, newInstance);
|
||||
|
||||
for (var field : target.getDeclaredFields()) {
|
||||
if (field.getAnnotation(EmbeddedId.class) != null) {
|
||||
field.setAccessible(true);
|
||||
var id = field.getType().getConstructor().newInstance();
|
||||
BeanUtils.copyProperties(source, id);
|
||||
field.set(newInstance, id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (var field : source.getClass().getDeclaredFields()) {
|
||||
if (field.getAnnotation(EmbeddedId.class) != null) {
|
||||
field.setAccessible(true);
|
||||
var sourceId = field.get(source);
|
||||
BeanUtils.copyProperties(sourceId, newInstance);
|
||||
}
|
||||
}
|
||||
|
||||
return newInstance;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user