RED-8702: Explore document databases to store entityLog
* added new CRUD operations to repositories and services * removed cascade logic as updates and deletes are not trivial to implement, and thus it is better to do all CRUD operations alike
This commit is contained in:
parent
a6037f448d
commit
d53da45b5f
@ -1,54 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongo;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InaccessibleObjectException;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class CascadeCallback implements ReflectionUtils.FieldCallback {
|
|
||||||
|
|
||||||
private Object source;
|
|
||||||
private MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doWith(@NotNull final Field field) throws IllegalArgumentException, IllegalAccessException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
ReflectionUtils.makeAccessible(field);
|
|
||||||
|
|
||||||
if (field.isAnnotationPresent(DBRef.class) && field.isAnnotationPresent(CascadeSave.class)) {
|
|
||||||
final Object fieldValue = field.get(getSource());
|
|
||||||
|
|
||||||
if(Collection.class.isAssignableFrom(field.getType())) {
|
|
||||||
Collection<?> collection = (Collection<?>) fieldValue;
|
|
||||||
mongoTemplate.insertAll(collection);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if (fieldValue != null) {
|
|
||||||
//final FieldCallback callback = new FieldCallback();
|
|
||||||
//ReflectionUtils.doWithFields(fieldValue.getClass(), callback);
|
|
||||||
|
|
||||||
mongoTemplate.insert(fieldValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InaccessibleObjectException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongo;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.FIELD)
|
|
||||||
public @interface CascadeSave {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongo;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.mongodb.core.MongoOperations;
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
|
|
||||||
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
|
|
||||||
public class CascadeSaveMongoEventListener extends AbstractMongoEventListener<Object> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBeforeConvert(BeforeConvertEvent<Object> event) {
|
|
||||||
Object source = event.getSource();
|
|
||||||
ReflectionUtils.doWithFields(source.getClass(),
|
|
||||||
new CascadeCallback(source, mongoTemplate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,6 +5,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.index.IndexDirection;
|
||||||
|
import org.springframework.data.mongodb.core.index.Indexed;
|
||||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
|
|||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogLegalBasis;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogLegalBasis;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -20,20 +23,23 @@ import lombok.Setter;
|
|||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
@Document(collection = "entity-logs")
|
@Document(collection = "entity-logs")
|
||||||
public class EntityLogDocument {
|
public class EntityLogDocument {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@EqualsAndHashCode.Include
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String dossierId;
|
private String dossierId;
|
||||||
private String fileId;
|
private String fileId;
|
||||||
|
|
||||||
private long analysisVersion;
|
private long analysisVersion;
|
||||||
|
|
||||||
|
//@Indexed(direction = IndexDirection.DESCENDING)
|
||||||
private int analysisNumber;
|
private int analysisNumber;
|
||||||
|
|
||||||
@DBRef
|
@DBRef
|
||||||
@CascadeSave
|
|
||||||
private List<EntityLogEntryDocument> entityLogEntryDocument = new ArrayList<>();
|
private List<EntityLogEntryDocument> entityLogEntryDocument = new ArrayList<>();
|
||||||
|
|
||||||
private List<EntityLogLegalBasis> legalBasis = new ArrayList<>();
|
private List<EntityLogLegalBasis> legalBasis = new ArrayList<>();
|
||||||
|
|||||||
@ -6,7 +6,10 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||||
|
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
import org.springframework.data.redis.core.index.Indexed;
|
||||||
|
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Change;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Change;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Engine;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Engine;
|
||||||
@ -26,12 +29,15 @@ import lombok.experimental.FieldDefaults;
|
|||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
@FieldDefaults(level = AccessLevel.PRIVATE)
|
@FieldDefaults(level = AccessLevel.PRIVATE)
|
||||||
@Document(collection = "entity-log-entries")
|
@Document(collection = "entity-log-entries")
|
||||||
public class EntityLogEntryDocument {
|
/**@CompoundIndexes({
|
||||||
|
@CompoundIndex(name = "changes_analysisNumber", def = "{ 'changes.analysisNumber': 1 }")
|
||||||
|
})**/ public class EntityLogEntryDocument {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@EqualsAndHashCode.Include
|
||||||
String id;
|
String id;
|
||||||
String entryId;
|
String entryId;
|
||||||
String entityLogId;
|
String entityLogId;
|
||||||
@ -62,10 +68,8 @@ public class EntityLogEntryDocument {
|
|||||||
|
|
||||||
boolean excluded;
|
boolean excluded;
|
||||||
|
|
||||||
@EqualsAndHashCode.Exclude
|
|
||||||
List<Change> changes = new ArrayList<>();
|
List<Change> changes = new ArrayList<>();
|
||||||
|
|
||||||
@EqualsAndHashCode.Exclude
|
|
||||||
List<ManualChange> manualChanges = new ArrayList<>();
|
List<ManualChange> manualChanges = new ArrayList<>();
|
||||||
|
|
||||||
Set<Engine> engines = new HashSet<>();
|
Set<Engine> engines = new HashSet<>();
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongo;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InaccessibleObjectException;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class FieldCallback implements ReflectionUtils.FieldCallback {
|
|
||||||
|
|
||||||
private boolean idFound;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doWith(@NotNull final Field field) throws IllegalArgumentException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
ReflectionUtils.makeAccessible(field);
|
|
||||||
|
|
||||||
if (field.isAnnotationPresent(Id.class)) {
|
|
||||||
idFound = true;
|
|
||||||
}
|
|
||||||
} catch (InaccessibleObjectException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongodeprecated;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocument;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentRepository;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.experimental.FieldDefaults;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class EntityLogDocumentService {
|
|
||||||
|
|
||||||
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
|
||||||
|
|
||||||
|
|
||||||
public EntityLogDocumentService(EntityLogDocumentRepository entityLogDocumentRepository) {this.entityLogDocumentRepository = entityLogDocumentRepository;}
|
|
||||||
|
|
||||||
|
|
||||||
public EntityLogDocument saveEntityLogDocument(EntityLogDocument entityLogDocument) {
|
|
||||||
return entityLogDocumentRepository.save(entityLogDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<EntityLogDocument> findEntityLogDocumentById(String id) {
|
|
||||||
return entityLogDocumentRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean entityLogDocumentExists(String id) {
|
|
||||||
return entityLogDocumentRepository.existsById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongodeprecated;
|
|
||||||
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocument;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.experimental.FieldDefaults;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class _EntityLogDocumentRepository {
|
|
||||||
|
|
||||||
MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
public EntityLogDocument saveEntityLogDocument(EntityLogDocument entityLogDocument) {
|
|
||||||
return mongoTemplate.save(entityLogDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityLogDocument findEntityLogDocumentById(String id) {
|
|
||||||
return mongoTemplate.findById(id, EntityLogDocument.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user