Merge remote-tracking branch 'origin/RED-8702' into RED-8702
# Conflicts: # redaction-service-v1/redaction-service-server-v1/build.gradle.kts # redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/EntityChangeLogService.java
This commit is contained in:
commit
1337bd8c05
@ -12,11 +12,11 @@ plugins {
|
|||||||
description = "redaction-service-server-v1"
|
description = "redaction-service-server-v1"
|
||||||
|
|
||||||
|
|
||||||
val layoutParserVersion = "maverick-mongo-eval"
|
val layoutParserVersion = "0.107.0"
|
||||||
val jacksonVersion = "2.15.2"
|
val jacksonVersion = "2.15.2"
|
||||||
val droolsVersion = "9.44.0.Final"
|
val droolsVersion = "9.44.0.Final"
|
||||||
val pdfBoxVersion = "3.0.0"
|
val pdfBoxVersion = "3.0.0"
|
||||||
val persistenceServiceVersion = "2.380.0"
|
val persistenceServiceVersion = "2.383.0"
|
||||||
val springBootStarterVersion = "3.1.5"
|
val springBootStarterVersion = "3.1.5"
|
||||||
val springCloudVersion = "4.0.4"
|
val springCloudVersion = "4.0.4"
|
||||||
val testContainersVersion = "1.19.7"
|
val testContainersVersion = "1.19.7"
|
||||||
@ -33,7 +33,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation(project(":redaction-service-api-v1")) { exclude(group = "com.iqser.red.service", module = "persistence-service-internal-api-v1") }
|
implementation(project(":redaction-service-api-v1")) { exclude(group = "com.iqser.red.service", module = "persistence-service-internal-api-v1") }
|
||||||
implementation("com.iqser.red.service:persistence-service-internal-api-v1:${persistenceServiceVersion}") { exclude(group = "org.springframework.boot") }
|
implementation("com.iqser.red.service:persistence-service-internal-api-v1:${persistenceServiceVersion}") { exclude(group = "org.springframework.boot") }
|
||||||
implementation("com.iqser.red.service:persistence-service-processor-v1:${persistenceServiceVersion}")
|
implementation("com.iqser.red.service:persistence-service-shared-mongo-v1:${persistenceServiceVersion}")
|
||||||
implementation("com.knecon.fforesight:layoutparser-service-internal-api:${layoutParserVersion}")
|
implementation("com.knecon.fforesight:layoutparser-service-internal-api:${layoutParserVersion}")
|
||||||
|
|
||||||
implementation("com.iqser.red.commons:spring-commons:6.2.0")
|
implementation("com.iqser.red.commons:spring-commons:6.2.0")
|
||||||
@ -41,8 +41,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation("com.iqser.red.commons:dictionary-merge-commons:1.5.0")
|
implementation("com.iqser.red.commons:dictionary-merge-commons:1.5.0")
|
||||||
implementation("com.iqser.red.commons:storage-commons:2.45.0")
|
implementation("com.iqser.red.commons:storage-commons:2.45.0")
|
||||||
implementation("com.knecon.fforesight:tenant-commons:maverick-mongo")
|
implementation("com.knecon.fforesight:tenant-commons:0.23.0")
|
||||||
implementation("com.knecon.fforesight:mongo-database-commons:maverick-mongo6")
|
|
||||||
implementation("com.knecon.fforesight:tracing-commons:0.5.0")
|
implementation("com.knecon.fforesight:tracing-commons:0.5.0")
|
||||||
|
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:${jacksonVersion}")
|
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:${jacksonVersion}")
|
||||||
@ -60,17 +59,12 @@ dependencies {
|
|||||||
implementation("org.springframework.boot:spring-boot-starter-amqp:${springBootStarterVersion}")
|
implementation("org.springframework.boot:spring-boot-starter-amqp:${springBootStarterVersion}")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-cache:${springBootStarterVersion}")
|
implementation("org.springframework.boot:spring-boot-starter-cache:${springBootStarterVersion}")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-redis:${springBootStarterVersion}")
|
implementation("org.springframework.boot:spring-boot-starter-data-redis:${springBootStarterVersion}")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-mongodb:${springBootStarterVersion}")
|
|
||||||
|
|
||||||
implementation("net.logstash.logback:logstash-logback-encoder:7.4")
|
implementation("net.logstash.logback:logstash-logback-encoder:7.4")
|
||||||
implementation("ch.qos.logback:logback-classic")
|
implementation("ch.qos.logback:logback-classic")
|
||||||
|
|
||||||
implementation("org.reflections:reflections:0.10.2")
|
implementation("org.reflections:reflections:0.10.2")
|
||||||
|
|
||||||
//todo 8702: remove this
|
|
||||||
implementation("org.liquibase:liquibase-core:4.20.0")
|
|
||||||
implementation("org.liquibase.ext:liquibase-mongodb:4.20.0")
|
|
||||||
|
|
||||||
testImplementation(project(":rules-management"))
|
testImplementation(project(":rules-management"))
|
||||||
testImplementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
testImplementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
||||||
testImplementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
testImplementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.service;
|
package com.iqser.red.service.redaction.v1.server.service;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -26,61 +27,57 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
public class EntityChangeLogService {
|
public class EntityChangeLogService {
|
||||||
|
|
||||||
@Timed("redactmanager_computeChanges")
|
@Timed("redactmanager_computeChanges")
|
||||||
public boolean computeChanges(List<EntityLogEntry> previousEntityLogEntries, List<EntityLogEntry> newEntityLogEntries, int analysisNumber) {
|
public EntryChanges computeChanges(List<EntityLogEntry> previousEntityLogEntries, List<EntityLogEntry> newEntityLogEntries, int analysisNumber) {
|
||||||
|
|
||||||
var now = OffsetDateTime.now();
|
var now = OffsetDateTime.now();
|
||||||
if (previousEntityLogEntries.isEmpty()) {
|
if (previousEntityLogEntries.isEmpty()) {
|
||||||
newEntityLogEntries.forEach(entry -> entry.getChanges().add(new Change(analysisNumber, ChangeType.ADDED, now)));
|
newEntityLogEntries.forEach(entry -> entry.getChanges().add(new Change(analysisNumber, ChangeType.ADDED, now)));
|
||||||
return true;
|
return new EntryChanges(newEntityLogEntries, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasChanges = false;
|
List<EntityLogEntry> toInsert = new ArrayList<>();
|
||||||
|
List<EntityLogEntry> toUpdate = new ArrayList<>();
|
||||||
for (EntityLogEntry entityLogEntry : newEntityLogEntries) {
|
for (EntityLogEntry entityLogEntry : newEntityLogEntries) {
|
||||||
|
|
||||||
Optional<EntityLogEntry> optionalPreviousEntity = previousEntityLogEntries.stream()
|
Optional<EntityLogEntry> optionalPreviousEntity = previousEntityLogEntries.stream()
|
||||||
.filter(entry -> entry.getId().equals(entityLogEntry.getId()))
|
.filter(entry -> entry.getId().equals(entityLogEntry.getId()))
|
||||||
.findAny();
|
.findAny();
|
||||||
|
|
||||||
if (optionalPreviousEntity.isEmpty()) {
|
if (optionalPreviousEntity.isEmpty()) {
|
||||||
hasChanges = true;
|
|
||||||
entityLogEntry.getChanges().add(new Change(analysisNumber, ChangeType.ADDED, now));
|
entityLogEntry.getChanges().add(new Change(analysisNumber, ChangeType.ADDED, now));
|
||||||
|
toInsert.add(entityLogEntry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityLogEntry previousEntity = optionalPreviousEntity.get();
|
EntityLogEntry previousEntity = optionalPreviousEntity.get();
|
||||||
|
|
||||||
entityLogEntry.getChanges().addAll(previousEntity.getChanges());
|
entityLogEntry.getChanges().addAll(previousEntity.getChanges());
|
||||||
|
|
||||||
if (!previousEntity.getState().equals(entityLogEntry.getState())) {
|
if (!previousEntity.getState().equals(entityLogEntry.getState())) {
|
||||||
hasChanges = true;
|
|
||||||
ChangeType changeType = calculateChangeType(entityLogEntry.getState(), previousEntity.getState());
|
ChangeType changeType = calculateChangeType(entityLogEntry.getState(), previousEntity.getState());
|
||||||
entityLogEntry.getChanges().add(new Change(analysisNumber, changeType, now));
|
entityLogEntry.getChanges().add(new Change(analysisNumber, changeType, now));
|
||||||
|
toUpdate.add(entityLogEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addRemovedEntriesAsRemoved(previousEntityLogEntries, newEntityLogEntries, analysisNumber, now);
|
toUpdate.addAll(addRemovedEntriesAsRemoved(previousEntityLogEntries, newEntityLogEntries, analysisNumber, now));
|
||||||
|
return new EntryChanges(toInsert, toUpdate);
|
||||||
return hasChanges;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addRemovedEntriesAsRemoved(List<EntityLogEntry> previousEntityLogEntries, List<EntityLogEntry> newEntityLogEntries, int analysisNumber, OffsetDateTime now) {
|
private List<EntityLogEntry> addRemovedEntriesAsRemoved(List<EntityLogEntry> previousEntityLogEntries,
|
||||||
|
List<EntityLogEntry> newEntityLogEntries,
|
||||||
|
int analysisNumber,
|
||||||
|
OffsetDateTime now) {
|
||||||
|
|
||||||
Set<String> existingIds = newEntityLogEntries.stream()
|
Set<String> existingIds = newEntityLogEntries.stream()
|
||||||
.map(EntityLogEntry::getId)
|
.map(EntityLogEntry::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
List<EntityLogEntry> removedEntries = previousEntityLogEntries.stream()
|
List<EntityLogEntry> removedEntries = previousEntityLogEntries.stream()
|
||||||
.filter(entry -> !existingIds.contains(entry.getId()))
|
.filter(entry -> !existingIds.contains(entry.getId()))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
removedEntries.stream()
|
removedEntries.stream()
|
||||||
.filter(entry -> !entry.getState().equals(EntryState.REMOVED))
|
.filter(entry -> !entry.getState().equals(EntryState.REMOVED))
|
||||||
.peek(entry -> entry.getChanges().add(new Change(analysisNumber, ChangeType.REMOVED, now)))
|
.peek(entry -> entry.getChanges().add(new Change(analysisNumber, ChangeType.REMOVED, now)))
|
||||||
.forEach(entry -> entry.setState(EntryState.REMOVED));
|
.forEach(entry -> entry.setState(EntryState.REMOVED));
|
||||||
|
|
||||||
newEntityLogEntries.addAll(removedEntries);
|
newEntityLogEntries.addAll(removedEntries);
|
||||||
|
return removedEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,4 +101,9 @@ public class EntityChangeLogService {
|
|||||||
return (state.equals(EntryState.REMOVED) || state.equals(EntryState.IGNORED));
|
return (state.equals(EntryState.REMOVED) || state.equals(EntryState.IGNORED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public record EntryChanges(List<EntityLogEntry> inserted, List<EntityLogEntry> updated) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user