RED-7834: fix migration stuff

This commit is contained in:
Kilian Schuettler 2023-12-05 10:25:10 +01:00
parent b73b3a74cf
commit 7f94f0c1e4
3 changed files with 57 additions and 10 deletions

View File

@ -60,7 +60,9 @@ public class EntityLogCreatorService {
}
public EntityLog createInitialEntityLog(AnalyzeRequest analyzeRequest, Document document, List<ManualEntity> notFoundManualEntities,
public EntityLog createInitialEntityLog(AnalyzeRequest analyzeRequest,
Document document,
List<ManualEntity> notFoundManualEntities,
DictionaryVersion dictionaryVersion,
long rulesVersion) {
@ -124,8 +126,8 @@ public class EntityLogCreatorService {
List<EntityLogEntry> previousEntriesFromReAnalyzedSections = previousEntityLog.getEntityLogEntry()
.stream()
.filter(entry -> !entry.getType()
.equals(ImportedRedactionService.IMPORTED_REDACTION_TYPE) && (newEntityIds.contains(entry.getId()) || entry.getContainingNodeId().isEmpty() || sectionsToReanalyseIds.contains(entry.getContainingNodeId().get(0))))
.filter(entry -> !entry.getType().equals(ImportedRedactionService.IMPORTED_REDACTION_TYPE) && (newEntityIds.contains(entry.getId()) || entry.getContainingNodeId()
.isEmpty() || sectionsToReanalyseIds.contains(entry.getContainingNodeId().get(0))))
.toList();
previousEntityLog.getEntityLogEntry().removeAll(previousEntriesFromReAnalyzedSections);
@ -176,7 +178,9 @@ public class EntityLogCreatorService {
EntityLogEntry entityLogEntries = createEntityLogEntry(textEntity, dossierTemplateId);
entityLogEntries.setId(positionOnPage.getId());
List<Position> rectanglesPerLine = positionOnPage.getRectanglePerLine().stream().map(rectangle2D -> new Position(rectangle2D, positionOnPage.getPage().getNumber()))
List<Position> rectanglesPerLine = positionOnPage.getRectanglePerLine()
.stream()
.map(rectangle2D -> new Position(rectangle2D, positionOnPage.getPage().getNumber()))
.toList();
entityLogEntries.setPositions(rectanglesPerLine);
@ -207,7 +211,8 @@ public class EntityLogCreatorService {
.section(image.getManualOverwrite().getSection().orElse(image.getParent().toString()))
.imageHasTransparency(image.isTransparent())
.manualChanges(manualChangeFactory.toManualChangeList(image.getManualOverwrite().getManualChangeLog(), isHint))
.state(buildEntryState(image)).entryType(isHint ? EntryType.IMAGE_HINT : EntryType.IMAGE)
.state(buildEntryState(image))
.entryType(isHint ? EntryType.IMAGE_HINT : EntryType.IMAGE)
.build();
}

View File

@ -43,7 +43,7 @@ import com.iqser.red.service.redaction.v1.server.migration.RedactionLogToEntityL
import lombok.SneakyThrows;
@Disabled
//@Disabled
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Import(MigrationIntegrationTest.TestConfiguration.class)
@ -143,16 +143,16 @@ public class MigrationIntegrationTest extends BuildDocumentIntegrationTest {
if (p1.getPage() != p2.getPageNumber()) {
return false;
}
if (Math.abs(p1.getHeight() - p2.getRectangle()[3]) > tolerance) {
if (Math.abs(p1.getHeight() - p2.h()) > tolerance) {
return false;
}
if (Math.abs(p1.getWidth() - p2.getRectangle()[2]) > tolerance) {
if (Math.abs(p1.getWidth() - p2.w()) > tolerance) {
return false;
}
if (Math.abs(p1.getTopLeft().getX() - p2.getRectangle()[0]) > tolerance) {
if (Math.abs(p1.getTopLeft().getX() - p2.x()) > tolerance) {
return false;
}
if (Math.abs(p1.getTopLeft().getY() - p2.getRectangle()[1]) > tolerance) {
if (Math.abs(p1.getTopLeft().getY() - p2.y()) > tolerance) {
return false;
}
}

View File

@ -0,0 +1,42 @@
package com.iqser.red.service.redaction.v1.server;
import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import com.iqser.red.commons.jackson.ObjectMapperFactory;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import lombok.SneakyThrows;
public class RedactionLogCrawler {
@Test
@SneakyThrows
public void findRedactionLogVersion0() {
String redactionLogsDir = "/home/kschuettler/Nextcloud/redaction_logs/";
Files.walk(Path.of(redactionLogsDir))
.map(Path::toFile)
.filter(File::isFile)
.filter(file -> file.toString().endsWith("redactionlog.json"))
.peek(System.out::println)
.map(this::parseRedactionLog)
.filter(log -> log.getAnalysisVersion() == 0)
.count();
}
@SneakyThrows
private RedactionLog parseRedactionLog(File file) {
var mapper = ObjectMapperFactory.create();
try (var in = new FileInputStream(file)) {
return mapper.readValue(in.readAllBytes(), RedactionLog.class);
}
}
}