RED-3554 Added flag to Resize endpoint to update dictionary
This commit is contained in:
parent
0463dbce56
commit
5cd160ffbb
@ -20,6 +20,7 @@ public class ResizeRedactionRequest {
|
||||
private String comment;
|
||||
private int page;
|
||||
private String value;
|
||||
private Boolean updateDictionary;
|
||||
|
||||
@Builder.Default
|
||||
private List<Rectangle> positions = new ArrayList<>();
|
||||
|
||||
@ -1,18 +1,29 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ -39,6 +50,8 @@ public class ManualResizeRedactionEntity implements IBaseAnnotation {
|
||||
private int page;
|
||||
@Column(length = 4000)
|
||||
private String value;
|
||||
@Column
|
||||
private Boolean updateDictionary;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private FileEntity fileStatus;
|
||||
|
||||
@ -7,6 +7,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -41,6 +42,7 @@ import com.iqser.red.service.persistence.management.v1.processor.exception.NotFo
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierTemplatePersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.EntryPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.AddRedactionPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.CommentPersistenceService;
|
||||
@ -96,11 +98,14 @@ public class ManualRedactionService {
|
||||
private final StopwordService stopwordService;
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final EntryPersistenceService entryPersistenceService;
|
||||
private final RedactionLogService redactionLogService;
|
||||
|
||||
private final HashFunction hashFunction = Hashing.murmur3_128();
|
||||
|
||||
|
||||
public List<ManualAddResponse> addAddRedaction(String dossierId, String fileId, List<AddRedactionRequest> addRedactionRequests) {
|
||||
|
||||
var response = new ArrayList<ManualAddResponse>();
|
||||
|
||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
@ -468,11 +473,35 @@ public class ManualRedactionService {
|
||||
List<ResizeRedactionRequest> resizeRedactionRequests) {
|
||||
|
||||
var response = new ArrayList<ManualAddResponse>();
|
||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
|
||||
for (var resizeRedactionRequest : resizeRedactionRequests) {
|
||||
boolean reprocess = false;
|
||||
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId, true, true);
|
||||
|
||||
for (ResizeRedactionRequest resizeRedactionRequest : resizeRedactionRequests) {
|
||||
resizeRedactionPersistenceService.insert(fileId, resizeRedactionRequest);
|
||||
|
||||
if (resizeRedactionRequest.getUpdateDictionary() != null && resizeRedactionRequest.getUpdateDictionary()) {
|
||||
|
||||
Optional<RedactionLogEntry> redactionLogEntry = redactionLog.getRedactionLogEntry()
|
||||
.stream()
|
||||
.filter(r -> r.getId().equals(resizeRedactionRequest.getAnnotationId()))
|
||||
.findFirst();
|
||||
if (redactionLogEntry.isPresent() && (redactionLogEntry.get().isDictionaryEntry() || redactionLogEntry.get().isDossierDictionaryEntry())) {
|
||||
|
||||
String typeId = redactionLogEntry.get().getType() + ":" + dossier.getDossierTemplateId();
|
||||
|
||||
if (redactionLogEntry.get().getValue().length() > resizeRedactionRequest.getValue().length()) {
|
||||
log.info("Remove old value '{}' from dictionary", redactionLogEntry.get().getValue());
|
||||
entryPersistenceService.deleteEntries(typeId, List.of(redactionLogEntry.get().getValue()), redactionLog.getAnalysisVersion(), DictionaryEntryType.ENTRY);
|
||||
}
|
||||
|
||||
log.info("Add new value '{}' to dictionary", resizeRedactionRequest.getValue());
|
||||
entryPersistenceService.addEntries(typeId, new HashSet<>(Collections.singleton(resizeRedactionRequest.getValue())), redactionLog.getAnalysisVersion(), DictionaryEntryType.ENTRY);
|
||||
reprocess = true;
|
||||
}
|
||||
}
|
||||
|
||||
Long commentId = null;
|
||||
if (resizeRedactionRequest.getComment() != null) {
|
||||
|
||||
@ -482,10 +511,11 @@ public class ManualRedactionService {
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder().resizeRedactions(Set.of(loaded)).build();
|
||||
addManualRedactionToAnalysisQueue(dossierId, fileId, manualRedactions);
|
||||
|
||||
response.add(ManualAddResponse.builder()
|
||||
.annotationId(resizeRedactionRequest.getAnnotationId())
|
||||
.commentId(commentId)
|
||||
.build());
|
||||
response.add(ManualAddResponse.builder().annotationId(resizeRedactionRequest.getAnnotationId()).commentId(commentId).build());
|
||||
}
|
||||
|
||||
if (reprocess) {
|
||||
reprocess(dossierId, fileId);
|
||||
}
|
||||
|
||||
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: add-update-dictionary-to-manual-resize-redactions
|
||||
author: philipp
|
||||
changes:
|
||||
- addColumn:
|
||||
columns:
|
||||
- column:
|
||||
name: update_dictionary
|
||||
type: BOOLEAN
|
||||
tableName: manual_resize_redaction
|
||||
|
||||
@ -67,3 +67,5 @@ databaseChangeLog:
|
||||
file: db/changelog/sql/26-initiliaze-application-configuration-table.sql
|
||||
- include:
|
||||
file: db/changelog/sql/27-update-soft-delete-date.sql
|
||||
- include:
|
||||
file: db/changelog/28-add-update-dictionary-to-manual-resize-redactions.yaml
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user