RED-7784 - Add position to UnprocessedManualEntity
This commit is contained in:
parent
3d10dd97f9
commit
a2b130f75f
@ -1,7 +1,10 @@
|
||||
package com.iqser.red.service.redaction.v1.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Position;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -24,4 +27,6 @@ public class UnprocessedManualEntity {
|
||||
private String section;
|
||||
private float[] color;
|
||||
private List<Integer> containingNodeId;
|
||||
@Builder.Default
|
||||
private List<Position> positions = new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -2,12 +2,14 @@ package com.iqser.red.service.redaction.v1.server.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Position;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualRedactions;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualRedactionEntry;
|
||||
import com.iqser.red.service.redaction.v1.model.UnprocessedManualEntity;
|
||||
@ -40,32 +42,41 @@ public class UnprocessedChangesService {
|
||||
List<ManualEntity> notFoundManualEntities = manualEntityCreationService.toTextEntity(manualEntitiesConverter(manualRedactions), document);
|
||||
|
||||
document.getEntities().forEach(textEntity -> {
|
||||
unprocessedManualEntities.add(UnprocessedManualEntity.builder()
|
||||
.annotationId(annotationIds.stream().filter(textEntity::matchesAnnotationId).findFirst().orElse(""))
|
||||
.closestHeadline(textEntity.getDeepestFullyContainingNode().getHeadline().getTextBlock().getSearchText())
|
||||
.color(getColor(textEntity.getType(), dossierTemplateId, textEntity.applied(), textEntity.getEntityType().equals(EntityType.HINT)))
|
||||
.startOffset(textEntity.getTextRange().start())
|
||||
.endOffset(textEntity.getTextRange().end())
|
||||
.containingNodeId(textEntity.getDeepestFullyContainingNode().getTreeId())
|
||||
.textBefore(textEntity.getTextBefore())
|
||||
.textAfter(textEntity.getTextAfter())
|
||||
.section(textEntity.getManualOverwrite().getSection().orElse(textEntity.getDeepestFullyContainingNode().toString()))
|
||||
.build());
|
||||
Set<String> processedIds = new HashSet<>();
|
||||
for (var positionsOnPerPage : textEntity.getPositionsOnPagePerPage()) {
|
||||
if (processedIds.contains(positionsOnPerPage.getId())) {
|
||||
continue;
|
||||
}
|
||||
processedIds.add(positionsOnPerPage.getId());
|
||||
List<Position> positions = positionsOnPerPage.getRectanglePerLine().stream().map(rectangle2D -> new Position(rectangle2D, positionsOnPerPage.getPage().getNumber()))
|
||||
.toList();
|
||||
unprocessedManualEntities.add(UnprocessedManualEntity.builder()
|
||||
.annotationId(annotationIds.stream().filter(textEntity::matchesAnnotationId).findFirst().orElse(""))
|
||||
.closestHeadline(textEntity.getDeepestFullyContainingNode().getHeadline().getTextBlock().getSearchText())
|
||||
.color(getColor(textEntity.getType(), dossierTemplateId, textEntity.applied(), textEntity.getEntityType().equals(EntityType.HINT)))
|
||||
.startOffset(textEntity.getTextRange().start())
|
||||
.endOffset(textEntity.getTextRange().end())
|
||||
.containingNodeId(textEntity.getDeepestFullyContainingNode().getTreeId())
|
||||
.textBefore(textEntity.getTextBefore())
|
||||
.textAfter(textEntity.getTextAfter())
|
||||
.section(textEntity.getManualOverwrite().getSection().orElse(textEntity.getDeepestFullyContainingNode().toString()))
|
||||
.positions(positions)
|
||||
.build());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
notFoundManualEntities.forEach(manualEntity -> {
|
||||
unprocessedManualEntities.add(UnprocessedManualEntity.builder()
|
||||
.annotationId(manualEntity.getId())
|
||||
.color(getColor(manualEntity.getType(), dossierTemplateId, manualEntity.applied(), manualEntity.getEntityType().equals(EntityType.HINT)))
|
||||
.closestHeadline("")
|
||||
.startOffset(-1)
|
||||
.endOffset(-1)
|
||||
.containingNodeId(Collections.emptyList())
|
||||
.textAfter("")
|
||||
.textBefore("")
|
||||
.section("")
|
||||
.build());
|
||||
});
|
||||
notFoundManualEntities.forEach(manualEntity -> unprocessedManualEntities.add(UnprocessedManualEntity.builder()
|
||||
.annotationId(manualEntity.getId())
|
||||
.color(getColor(manualEntity.getType(), dossierTemplateId, manualEntity.applied(), manualEntity.getEntityType().equals(EntityType.HINT)))
|
||||
.closestHeadline("")
|
||||
.startOffset(-1)
|
||||
.endOffset(-1)
|
||||
.containingNodeId(Collections.emptyList())
|
||||
.textAfter("")
|
||||
.textBefore("")
|
||||
.section("")
|
||||
.build()));
|
||||
|
||||
return unprocessedManualEntities;
|
||||
}
|
||||
|
||||
@ -148,6 +148,10 @@ public class UnprocessedChangesServiceTest extends AbstractRedactionIntegrationT
|
||||
assertEquals(unprocessedManualEntity.getColor()[0], 0f);
|
||||
assertEquals(unprocessedManualEntity.getColor()[1], 0f);
|
||||
assertEquals(unprocessedManualEntity.getColor()[2], 0f);
|
||||
assertEquals(unprocessedManualEntity.getPositions().get(0).x(), 355.53775f);
|
||||
assertEquals(unprocessedManualEntity.getPositions().get(0).y(), 266.49002f);
|
||||
assertEquals(unprocessedManualEntity.getPositions().get(0).w(), 29.322266f);
|
||||
assertEquals(unprocessedManualEntity.getPositions().get(0).h(), 11.017679f);
|
||||
|
||||
Optional<UnprocessedManualEntity> optionalNotFoundUnprocessedManualEntity = unprocessedManualEntities.stream().filter(manualEntity -> manualEntity.getAnnotationId().equals(notFoundId)).findFirst();
|
||||
assertTrue(optionalNotFoundUnprocessedManualEntity.isPresent());
|
||||
@ -163,5 +167,6 @@ public class UnprocessedChangesServiceTest extends AbstractRedactionIntegrationT
|
||||
assertEquals(unprocessedNotFoundManualEntity.getColor()[0], 0f);
|
||||
assertEquals(unprocessedNotFoundManualEntity.getColor()[1], 0f);
|
||||
assertEquals(unprocessedNotFoundManualEntity.getColor()[2], 0f);
|
||||
assertTrue(unprocessedNotFoundManualEntity.getPositions().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user