RED-8702: Explore document databases to store entityLog

* changed indices
This commit is contained in:
maverickstuder 2024-03-28 11:50:46 +01:00
parent 7212b43693
commit 9ab0910a26
5 changed files with 104 additions and 11 deletions

View File

@ -140,7 +140,7 @@ public class FileManagementStorageService {
@SneakyThrows
public void saveEntityLog(String dossierId, String fileId, EntityLog entityLog) {
entityLogMongoService.saveEntityLog(dossierId, fileId, entityLog);
entityLogMongoService.upsertEntityLog(dossierId, fileId, entityLog);
}

View File

@ -10,24 +10,35 @@
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"_id": 1,
"positions.pageNumber": 1
"entityLogId": 1,
}
</ext:keys>
<ext:options>
{name: "positions_pageNumber_index"}
{name: "entityLogId_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"_id": 1,
"changes.analysisNumber": -1
"entityLogId": 1,
"positions.pageNumber": 1
}
</ext:keys>
<ext:options>
{name: "changes_analysisNumber_index"}
{name: "entityLogId_positionsPageNumber_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"entityLogId": 1,
"containingNodeId": 1
}
</ext:keys>
<ext:options>
{name: "entityLogId_containingNodeId_index"}
</ext:options>
</ext:createIndex>

View File

@ -0,0 +1,84 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="createIndicesForEntries" author="maverick">
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"entityLogId": 1,
}
</ext:keys>
<ext:options>
{name: "entityLogId_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"entityLogId": 1,
"positions.pageNumber": 1
}
</ext:keys>
<ext:options>
{name: "entityLogId_positionsPageNumber_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"entityLogId": 1,
"changes.analysisNumber": -1
}
</ext:keys>
<ext:options>
{name: "entityLogId_changesAnalysisNumber_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"entityLogId": 1,
"containingNodeId": 1
}
</ext:keys>
<ext:options>
{name: "entityLogId_containingNodeId_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"id": 1,
"containingNodeId": 1
}
</ext:keys>
<ext:options>
{name: "id_containingNodeId_index"}
</ext:options>
</ext:createIndex>
<ext:createIndex collectionName="entity-log-entries">
<ext:keys>
{
"entityLogId": 1,
"type": 1
}
</ext:keys>
<ext:options>
{name: "entityLogId_type_index"}
</ext:options>
</ext:createIndex>
</changeSet>
</databaseChangeLog>

View File

@ -247,7 +247,7 @@ public class EntityLogMongoServiceTest extends AbstractPersistenceServerServiceT
entityLog = objectMapper.readValue(file.getInputStream(), EntityLog.class);
entityLog.setAnalysisNumber(entityLog.getAnalysisNumber() + 1);
entityLogMongoService.saveEntityLog(TEST_DOSSIER_ID, TEST_FILE3_ID, entityLog);
entityLogMongoService.upsertEntityLog(TEST_DOSSIER_ID, TEST_FILE3_ID, entityLog);
found = entityLogMongoService.findEntityLogByDossierIdAndFileId(TEST_DOSSIER_ID, TEST_FILE3_ID);
assertTrue(found.isPresent());

View File

@ -49,12 +49,10 @@ public class EntityLogMongoService {
// this does everything : insert when not found and update if found
// todo: remove and replace when services use insert,update,delete correctly
public void saveEntityLog(String dossierId, String fileId, EntityLog entityLog) {
public void upsertEntityLog(String dossierId, String fileId, EntityLog entityLog) {
Optional<EntityLogDocument> optionalEntityLogDocument = entityLogDocumentRepository.findById(mapper.getLogId(dossierId, fileId));
if (optionalEntityLogDocument.isEmpty()) {
// throw new EntityLogDocumentNotFoundException(String.format("Entity log for dossier %s and file %s not found.", dossierId, fileId));
insertEntityLog(dossierId, fileId, entityLog);
return;
}