RED-8702: Explore document databases to store entityLog
* added new update service for partial updates to entity log documents without modification to entry documents
This commit is contained in:
parent
e7e9d88238
commit
45d75dc147
@ -256,4 +256,36 @@ public class EntityLogMongoServiceTest extends AbstractPersistenceServerServiceT
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testUpdateEntityLogWithoutEntries() {
|
||||||
|
|
||||||
|
var file = new ClassPathResource(ENTITY_LOG3_BEFORE);
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.registerModule(new JavaTimeModule());
|
||||||
|
|
||||||
|
EntityLog entityLog = objectMapper.readValue(file.getInputStream(), EntityLog.class);
|
||||||
|
|
||||||
|
entityLogMongoService.insertEntityLog(TEST_DOSSIER_ID, TEST_FILE3_ID, entityLog);
|
||||||
|
|
||||||
|
Optional<EntityLog> found = entityLogMongoService.findEntityLogByDossierIdAndFileId(TEST_DOSSIER_ID, TEST_FILE3_ID);
|
||||||
|
assertTrue(found.isPresent());
|
||||||
|
assertEquals(found.get().getEntityLogEntry().size(), 1706);
|
||||||
|
|
||||||
|
file = new ClassPathResource(ENTITY_LOG3_AFTER);
|
||||||
|
|
||||||
|
entityLog = objectMapper.readValue(file.getInputStream(), EntityLog.class);
|
||||||
|
entityLog.setAnalysisNumber(entityLog.getAnalysisNumber() + 1);
|
||||||
|
|
||||||
|
entityLogMongoService.saveEntityLogWithoutEntries(TEST_DOSSIER_ID, TEST_FILE3_ID, entityLog);
|
||||||
|
|
||||||
|
found = entityLogMongoService.findEntityLogByDossierIdAndFileId(TEST_DOSSIER_ID, TEST_FILE3_ID);
|
||||||
|
assertTrue(found.isPresent());
|
||||||
|
assertEquals(found.get().getEntityLogEntry().size(), 1706);
|
||||||
|
assertEquals(found.get().getAnalysisNumber(), 9);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog;
|
package com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -12,6 +15,7 @@ import lombok.NoArgsConstructor;
|
|||||||
public class EntityLogChanges {
|
public class EntityLogChanges {
|
||||||
|
|
||||||
private EntityLog entityLog;
|
private EntityLog entityLog;
|
||||||
private boolean hasChanges;
|
private List<EntityLogEntry> newEntityLogEntries = new ArrayList<>();
|
||||||
|
private List<EntityLogEntry> updatedEntityLogEntries = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,6 @@ public interface EntityLogDocumentMapper {
|
|||||||
@Mapping(target = "entityLogEntry", source = "entityLogEntryDocuments")
|
@Mapping(target = "entityLogEntry", source = "entityLogEntryDocuments")
|
||||||
EntityLog fromLogDocument(EntityLogDocument entityLogDocument);
|
EntityLog fromLogDocument(EntityLogDocument entityLogDocument);
|
||||||
|
|
||||||
|
|
||||||
@Mapping(target = "id", source = "entityLogEntryDocument.entryId")
|
@Mapping(target = "id", source = "entityLogEntryDocument.entryId")
|
||||||
EntityLogEntry fromLogEntryDocument(EntityLogEntryDocument entityLogEntryDocument);
|
EntityLogEntry fromLogEntryDocument(EntityLogEntryDocument entityLogEntryDocument);
|
||||||
|
|
||||||
|
|||||||
@ -14,4 +14,9 @@ public interface EntityLogDocumentRepository extends MongoRepository<EntityLogDo
|
|||||||
|
|
||||||
@Query(value = "{ '_id' : ?0 }", fields = "{ 'analysisNumber' : 1 }")
|
@Query(value = "{ '_id' : ?0 }", fields = "{ 'analysisNumber' : 1 }")
|
||||||
Optional<EntityLogDocument> findAnalysisNumberById(@Param("_id") String id);
|
Optional<EntityLogDocument> findAnalysisNumberById(@Param("_id") String id);
|
||||||
|
|
||||||
|
|
||||||
|
@Query(value = "{ '_id': ?0 }", fields = "{ 'entityLogEntryDocuments': 0 }")
|
||||||
|
Optional<EntityLogDocument> findEntityLogDocumentWithoutEntriesById(String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,15 @@ public interface EntityLogEntryDocumentRepository extends MongoRepository<Entity
|
|||||||
@Query("{ 'entityLogId' : ?0}")
|
@Query("{ 'entityLogId' : ?0}")
|
||||||
List<EntityLogEntryDocument> findByEntityLogId(String entityLogId);
|
List<EntityLogEntryDocument> findByEntityLogId(String entityLogId);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("{ 'entityLogId' : ?0, 'containingNodeId' : { $exists: true, $not: { $size: 0 } } }")
|
||||||
|
List<EntityLogEntryDocument> findByEntityLogIdAndContainingNodeIdNotEmpty(String entityLogId);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("{ 'id' : { $in: ?0 }, 'containingNodeId' : { $exists: true, $not: { $size: 0 } } }")
|
||||||
|
List<EntityLogEntryDocument> findAllByIdAndContainingNodeIdNotEmpty(List<String> ids);
|
||||||
|
|
||||||
|
|
||||||
@Query(value = "{ 'entityLogId' : ?0}", delete = true)
|
@Query(value = "{ 'entityLogId' : ?0}", delete = true)
|
||||||
void deleteByEntityLogId(String entityLogId);
|
void deleteByEntityLogId(String entityLogId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.service;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.document.EntityLogDocument;
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.mapper.EntityLogDocumentMapper;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EntityLogDocumentUpdateService {
|
||||||
|
|
||||||
|
private final MongoTemplate mongoTemplate;
|
||||||
|
private final EntityLogDocumentMapper mapper = EntityLogDocumentMapper.INSTANCE;
|
||||||
|
|
||||||
|
|
||||||
|
public EntityLogDocumentUpdateService(MongoTemplate mongoTemplate) {this.mongoTemplate = mongoTemplate;}
|
||||||
|
|
||||||
|
|
||||||
|
public void updateEntityLogDocumentWithoutEntries(String dossierId, String fileId, EntityLog entityLog) {
|
||||||
|
|
||||||
|
Document doc = new Document();
|
||||||
|
mongoTemplate.getConverter().write(mapper.toLogDocument(dossierId, fileId, entityLog), doc);
|
||||||
|
doc.remove("entityLogEntryDocuments");
|
||||||
|
Update update = new Update();
|
||||||
|
doc.forEach(update::set);
|
||||||
|
mongoTemplate.updateFirst(Query.query(Criteria.where("_id").is(mapper.getLogId(dossierId, fileId))), update, EntityLogDocument.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.service;
|
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -20,12 +21,16 @@ public class EntityLogMongoService {
|
|||||||
|
|
||||||
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
||||||
private final EntityLogEntryDocumentRepository entityLogEntryDocumentRepository;
|
private final EntityLogEntryDocumentRepository entityLogEntryDocumentRepository;
|
||||||
|
private final EntityLogDocumentUpdateService entityLogDocumentUpdateService;
|
||||||
private final EntityLogDocumentMapper mapper = EntityLogDocumentMapper.INSTANCE;
|
private final EntityLogDocumentMapper mapper = EntityLogDocumentMapper.INSTANCE;
|
||||||
|
|
||||||
public EntityLogMongoService(EntityLogDocumentRepository entityLogDocumentRepository, EntityLogEntryDocumentRepository entityLogEntryDocumentRepository) {
|
|
||||||
|
public EntityLogMongoService(EntityLogDocumentRepository entityLogDocumentRepository, EntityLogEntryDocumentRepository entityLogEntryDocumentRepository,
|
||||||
|
EntityLogDocumentUpdateService entityLogDocumentUpdateService) {
|
||||||
|
|
||||||
this.entityLogDocumentRepository = entityLogDocumentRepository;
|
this.entityLogDocumentRepository = entityLogDocumentRepository;
|
||||||
this.entityLogEntryDocumentRepository = entityLogEntryDocumentRepository;
|
this.entityLogEntryDocumentRepository = entityLogEntryDocumentRepository;
|
||||||
|
this.entityLogDocumentUpdateService = entityLogDocumentUpdateService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +115,7 @@ public class EntityLogMongoService {
|
|||||||
.toList());
|
.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void deleteEntityLogEntries(String dossierId, String fileId, List<EntityLogEntry> entityLogEntries) {
|
public void deleteEntityLogEntries(String dossierId, String fileId, List<EntityLogEntry> entityLogEntries) {
|
||||||
|
|
||||||
String entityLogId = mapper.getLogId(dossierId, fileId);
|
String entityLogId = mapper.getLogId(dossierId, fileId);
|
||||||
@ -159,6 +165,7 @@ public class EntityLogMongoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<EntityLogEntry> findAllEntityLogEntriesWithManualChanges(String dossierId, String fileId) {
|
public List<EntityLogEntry> findAllEntityLogEntriesWithManualChanges(String dossierId, String fileId) {
|
||||||
|
|
||||||
return entityLogEntryDocumentRepository.findByEntityLogIdAndManualChangesNotEmpty(mapper.getLogId(dossierId, fileId))
|
return entityLogEntryDocumentRepository.findByEntityLogIdAndManualChangesNotEmpty(mapper.getLogId(dossierId, fileId))
|
||||||
@ -177,12 +184,36 @@ public class EntityLogMongoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<EntityLogEntry> findAllEntriesByDossierIdAndFileId(String dossierId, String fileId) {
|
public List<EntityLogEntry> findAllEntityLogEntriesWithContainingNodeIdsWithEntryIdsIn(String dossierId, String fileId, Collection<String> entryIds) {
|
||||||
|
|
||||||
return entityLogEntryDocumentRepository.findByEntityLogId(mapper.getLogId(dossierId, fileId))
|
String entityLogId = mapper.getLogId(dossierId, fileId);
|
||||||
|
List<String> ids = entryIds.stream()
|
||||||
|
.map(entryId -> mapper.getLogEntryId(entityLogId, entryId))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return entityLogEntryDocumentRepository.findAllByIdAndContainingNodeIdNotEmpty(ids)
|
||||||
.stream()
|
.stream()
|
||||||
.map(mapper::fromLogEntryDocument)
|
.map(mapper::fromLogEntryDocument)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EntityLogEntry> findAllEntityLogEntriesWithContainingNodeIds(String dossierId, String fileId) {
|
||||||
|
|
||||||
|
return entityLogEntryDocumentRepository.findByEntityLogIdAndContainingNodeIdNotEmpty(mapper.getLogId(dossierId, fileId))
|
||||||
|
.stream()
|
||||||
|
.map(mapper::fromLogEntryDocument)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<EntityLog> findEntityLogWithoutEntries(String dossierId, String fileId) {
|
||||||
|
return entityLogDocumentRepository.findEntityLogDocumentWithoutEntriesById(mapper.getLogId(dossierId, fileId))
|
||||||
|
.map(mapper::fromLogDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void saveEntityLogWithoutEntries(String dossierId, String fileId, EntityLog entityLog) {
|
||||||
|
entityLogDocumentUpdateService.updateEntityLogDocumentWithoutEntries(dossierId, fileId, entityLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user