RED-2429: As a user I want to resize a redaction

This commit is contained in:
aoezyetimoglu 2021-10-22 10:34:04 +02:00
parent 3dc0218a28
commit b4d00a5602
5 changed files with 29 additions and 10 deletions

View File

@ -22,6 +22,7 @@ public class ManualResizeRedaction {
private OffsetDateTime requestDate;
private OffsetDateTime processedDate;
private OffsetDateTime softDeletedTime;
private String value;
@Builder.Default
private List<Rectangle> positions = new ArrayList<>();

View File

@ -19,6 +19,7 @@ public class ResizeRedactionRequest {
private AnnotationStatus status;
private String comment;
private int page;
private String value;
@Builder.Default
private List<Rectangle> positions = new ArrayList<>();

View File

@ -44,6 +44,8 @@ public class ManualResizeRedactionEntity {
private OffsetDateTime softDeletedTime;
@Column
private int page;
@Column
private String value;
@ManyToOne
private FileEntity fileStatus;

View File

@ -1,7 +1,8 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
import static com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter.convert;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -18,8 +19,6 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ResizeRedactionRequest;
import static com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter.convert;
import lombok.RequiredArgsConstructor;
@Service
@ -28,6 +27,7 @@ public class ResizeRedactionPersistenceService {
private final ResizeRedactionRepository resizeRedactionRepository;
@Transactional
public void insert(String fileId, ResizeRedactionRequest resizeRedactionRequest) {
@ -40,8 +40,10 @@ public class ResizeRedactionPersistenceService {
resizeRedactionRepository.save(manualResizeRedaction);
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now());
mre.setStatus(annotationStatus);
@ -51,31 +53,42 @@ public class ResizeRedactionPersistenceService {
@Transactional
public void hardDelete(String fileId, String annotationId) {
resizeRedactionRepository.deleteById(new AnnotationEntityId(annotationId, fileId));
}
@Transactional
public void softDelete(String fileId, String annotationId, OffsetDateTime softDeleteTime) {
resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId))
.ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
}
@Transactional
public void undelete(String fileId, String annotationId) {
resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(null));
resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId))
.ifPresent(mre -> mre.setSoftDeletedTime(null));
}
public ManualResizeRedactionEntity findResizeRedaction(String fileId, String annotationId) {
return resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId))
.filter(mre -> mre.getSoftDeletedTime() == null)
.orElseThrow(() ->
new NotFoundException("Unknown file/annotation combination: " + fileId + "/" + annotationId));
.orElseThrow(() -> new NotFoundException("Unknown file/annotation combination: " + fileId + "/" + annotationId));
}
public Set<ManualResizeRedactionEntity> findResizeRedactions(String fileId, boolean includeDeletions) {
return resizeRedactionRepository.findByIdFileId(fileId).stream().filter(mre -> includeDeletions || mre.getSoftDeletedTime() == null).collect(Collectors.toSet());
return resizeRedactionRepository.findByIdFileId(fileId)
.stream()
.filter(mre -> includeDeletions || mre.getSoftDeletedTime() == null)
.collect(Collectors.toSet());
}
}

View File

@ -169,11 +169,12 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
assertThat(loadedImageRecategorization2.getStatus()).isEqualTo(AnnotationStatus.REQUESTED);
var resizeRedaction = manualRedactionClient.addResizeRedaction(dossier.getId(), file.getId(), ResizeRedactionRequest.builder()
.annotationId(addRedaction.getAnnotationId()).page(1).comment("comment").status(AnnotationStatus.REQUESTED).positions(List.of(Rectangle.builder().topLeftY(2).topLeftX(2).height(2).width(2).build())).user("test").build());
.annotationId(addRedaction.getAnnotationId()).page(1).comment("comment").status(AnnotationStatus.REQUESTED).positions(List.of(Rectangle.builder().topLeftY(2).topLeftX(2).height(2).width(2).build())).user("test").value("some value").build());
var loadedResizeRedaction = manualRedactionClient.getResizeRedaction(file.getId(), resizeRedaction.getAnnotationId());
assertThat(loadedResizeRedaction.getStatus()).isEqualTo(AnnotationStatus.REQUESTED);
assertThat(loadedResizeRedaction.getUser()).isEqualTo("test");
assertThat(loadedResizeRedaction.getPositions()).isNotEmpty();
assertThat(loadedResizeRedaction.getValue()).isEqualTo("some value");
manualRedactionClient.updateResizeRedactionStatus(dossier.getId(), file.getId(), resizeRedaction.getAnnotationId(), JSONPrimitive.of(AnnotationStatus.APPROVED));
loadedResizeRedaction = manualRedactionClient.getResizeRedaction(file.getId(), resizeRedaction.getAnnotationId());
@ -229,11 +230,12 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
manualRedactions.getLegalBasisChanges().forEach(e -> manualRedactionClient.deleteLegalBasisChange(dossier.getId(), file.getId(), e.getAnnotationId()));
var resizeRedaction2 = manualRedactionClient.addResizeRedaction(dossier.getId(), file.getId(), ResizeRedactionRequest.builder()
.annotationId(addRedaction.getAnnotationId()).page(1).comment("comment").status(AnnotationStatus.APPROVED).positions(List.of(Rectangle.builder().topLeftY(2).topLeftX(2).height(2).width(2).build())).user("test").build());
.annotationId(addRedaction.getAnnotationId()).page(1).comment("comment").status(AnnotationStatus.APPROVED).positions(List.of(Rectangle.builder().topLeftY(2).topLeftX(2).height(2).width(2).build())).user("test").value("some value").build());
var loadedResizeRedaction2 = manualRedactionClient.getResizeRedaction(file.getId(), resizeRedaction2.getAnnotationId());
assertThat(loadedResizeRedaction2.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
assertThat(loadedResizeRedaction2.getUser()).isEqualTo("test");
assertThat(loadedResizeRedaction2.getPositions()).isNotEmpty();
assertThat(loadedResizeRedaction2.getValue()).isEqualTo("some value");
manualRedactionClient.updateResizeRedactionStatus(dossier.getId(), file.getId(), resizeRedaction2.getAnnotationId(), JSONPrimitive.of(AnnotationStatus.REQUESTED));
loadedResizeRedaction2 = manualRedactionClient.getResizeRedaction(file.getId(), resizeRedaction2.getAnnotationId());