Pull request #211: RED-3243: Removed unneeded code for imported redactions

Merge in RED/persistence-service from RED-3243-8 to master

* commit '98d4a65638f517e98d90b3ac1784b347fca9fa59':
  RED-3243: Removed unneeded code for imported redactions
This commit is contained in:
Philipp Schramm 2022-01-31 15:46:51 +01:00 committed by Dominique Eiflaender
commit cdee2f8ff5
21 changed files with 141 additions and 672 deletions

View File

@ -1,25 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.model.annotations;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AddImportedAnnotationRequest {
private String annotationId;
private List<Rectangle> positions = new ArrayList<>();
private ImportedAnnotationStatus status;
private String userId;
private String comment;
}

View File

@ -1,26 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.model.annotations;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ImportedAnnotation {
private String annotationId;
private String fileId;
private List<Rectangle> positions = new ArrayList<>();
private ImportedAnnotationStatus status;
private String user;
private String comment;
private OffsetDateTime processedDate;
}

View File

@ -1,8 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.model.annotations;
public enum ImportedAnnotationStatus {
NEW,
APPROVED,
DECLINED,
ADDED
}

View File

@ -1,18 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.model.annotations;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UpdateImportedAnnotationStatusRequest {
private ImportedAnnotationStatus status;
private String user;
private String comment;
}

View File

@ -1,46 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.resources;
import java.util.List;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AddImportedAnnotationRequest;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotation;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.UpdateImportedAnnotationStatusRequest;
public interface ImportedAnnotationResource {
String IMPORTED_ANNOTATION_PATH = "/imported-annotation";
String FILE_ID_PARAM = "fileId";
String FILE_ID_PATH_PARAM = "/{" + FILE_ID_PARAM + "}";
String ANNOTATION_ID_PARAM = "annotationId";
String ANNOTATION_ID_PATH_PARAM = "/{" + ANNOTATION_ID_PARAM + "}";
@GetMapping(value = IMPORTED_ANNOTATION_PATH + FILE_ID_PATH_PARAM, produces = MediaType.APPLICATION_JSON_VALUE)
List<ImportedAnnotation> getByFileId(@PathVariable(FILE_ID_PARAM) String fileId);
@DeleteMapping(value = IMPORTED_ANNOTATION_PATH + FILE_ID_PATH_PARAM + ANNOTATION_ID_PATH_PARAM)
void delete(@PathVariable(FILE_ID_PARAM) String fileId,
@PathVariable(ANNOTATION_ID_PARAM) String annotationId);
@PostMapping(value = IMPORTED_ANNOTATION_PATH + FILE_ID_PATH_PARAM, consumes = MediaType.APPLICATION_JSON_VALUE)
void insert(@PathVariable(FILE_ID_PARAM) String fileId,
@RequestBody AddImportedAnnotationRequest annotation);
@PostMapping(value = IMPORTED_ANNOTATION_PATH + FILE_ID_PATH_PARAM + ANNOTATION_ID_PATH_PARAM, consumes = MediaType.APPLICATION_JSON_VALUE)
void updateStatus(@PathVariable(FILE_ID_PARAM) String fileId,
@PathVariable(ANNOTATION_ID_PARAM) String annotationId,
@RequestBody UpdateImportedAnnotationStatusRequest UpdateImportedAnnotationRequest);
}

View File

@ -1,54 +0,0 @@
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.ManyToOne;
import javax.persistence.Table;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotationStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "imported_annotation")
public class ImportedAnnotationEntity {
@EmbeddedId
private AnnotationEntityId id;
@Column(name = "user_id")
private String user;
@Column
@Enumerated(EnumType.STRING)
private ImportedAnnotationStatus status;
@Column
private OffsetDateTime processedDate;
@ElementCollection
private List<RectangleEntity> positions = new ArrayList<>();
@ManyToOne
private FileEntity fileStatus;
@Column
private String comment;
}

View File

@ -1,108 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.stereotype.Service;
import com.iqser.red.service.pdftron.redaction.v1.api.model.Annotation;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ImportedAnnotationEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.RectangleEntity;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.ImportedAnnotationRepository;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AddImportedAnnotationRequest;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotationStatus;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class ImportedAnnotationPersistenceService {
private final ImportedAnnotationRepository importedAnnotationRepository;
@Transactional
public void insert(String fileId, AddImportedAnnotationRequest annotation) {
ImportedAnnotationEntity importedAnnotationEntity = new ImportedAnnotationEntity();
importedAnnotationEntity.setId(new AnnotationEntityId(annotation.getAnnotationId(), fileId));
importedAnnotationEntity.setStatus(annotation.getStatus() != null ? annotation.getStatus() : ImportedAnnotationStatus.NEW);
importedAnnotationEntity.setProcessedDate(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
importedAnnotationEntity.setPositions(convert(annotation.getPositions()));
importedAnnotationEntity.setUser(annotation.getUserId());
importedAnnotationEntity.setComment(annotation.getComment());
importedAnnotationRepository.save(importedAnnotationEntity);
}
@Transactional
public void insert(String fileId, List<Annotation> annotations) {
annotations.forEach(annotation -> insert(fileId, annotation, ImportedAnnotationStatus.NEW, null, null));
}
@Transactional
public void insert(String fileId, Annotation annotation, ImportedAnnotationStatus status, String userId,
String comment) {
ImportedAnnotationEntity importedAnnotationEntity = new ImportedAnnotationEntity();
importedAnnotationEntity.setId(new AnnotationEntityId(annotation.getId(), fileId));
importedAnnotationEntity.setStatus(status);
importedAnnotationEntity.setProcessedDate(status == ImportedAnnotationStatus.ADDED ? OffsetDateTime.now()
.truncatedTo(ChronoUnit.MILLIS) : null);
importedAnnotationEntity.setUser(userId);
importedAnnotationEntity.setComment(comment);
importedAnnotationEntity.setPositions(convert(annotation.getPositions()));
importedAnnotationRepository.save(importedAnnotationEntity);
}
@Transactional
public void updateStatus(String fileId, String annotationId, ImportedAnnotationStatus annotationStatus,
String comment, String userId) {
importedAnnotationRepository.updateStatus(new AnnotationEntityId(annotationId, fileId), OffsetDateTime.now()
.truncatedTo(ChronoUnit.MILLIS), annotationStatus, comment, userId);
}
@Transactional
public void delete(String fileId, String annotationId) {
importedAnnotationRepository.deleteById(new AnnotationEntityId(annotationId, fileId));
}
public List<ImportedAnnotationEntity> findImportedAnnotations(String fileId) {
try {
return importedAnnotationRepository.findByIdFileId(fileId);
} catch (Exception e){
return new ArrayList<>();
}
}
private List<RectangleEntity> convert(List<Rectangle> positions) {
List<RectangleEntity> rectangleEntities = new ArrayList<>();
positions.forEach(p -> {
RectangleEntity re = new RectangleEntity();
re.setTopLeftX(p.getTopLeft().getX());
re.setTopLeftY(p.getTopLeft().getY());
re.setWidth(p.getWidth());
re.setHeight(p.getHeight());
re.setPage(p.getPage());
rectangleEntities.add(re);
});
return rectangleEntities;
}
}

View File

@ -1,24 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;
import java.time.OffsetDateTime;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ImportedAnnotationEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotationStatus;
public interface ImportedAnnotationRepository extends JpaRepository<ImportedAnnotationEntity, AnnotationEntityId> {
List<ImportedAnnotationEntity> findByIdFileId(String fileId);
@Modifying
@Query("update ImportedAnnotationEntity m set m.processedDate = :processedDate, m.status = :annotationStatus, m.comment = :comment, m.user = :userId where m.id = :id")
void updateStatus(AnnotationEntityId id, OffsetDateTime processedDate, ImportedAnnotationStatus annotationStatus,
String comment, String userId);
}

View File

@ -1,58 +0,0 @@
package com.iqser.red.service.peristence.v1.server.controller;
import static com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter.convert;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.peristence.v1.server.utils.ImportedRedactionMapper;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.ImportedAnnotationPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AddImportedAnnotationRequest;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotation;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.UpdateImportedAnnotationStatusRequest;
import com.iqser.red.service.persistence.service.v1.api.resources.ImportedAnnotationResource;
import lombok.RequiredArgsConstructor;
@RestController
@RequiredArgsConstructor
public class ImportedAnnotationController implements ImportedAnnotationResource {
private final ImportedAnnotationPersistenceService importedAnnotationPersistenceService;
@Override
public List<ImportedAnnotation> getByFileId(@PathVariable(FILE_ID_PARAM) String fileId) {
return convert(importedAnnotationPersistenceService.findImportedAnnotations(fileId), ImportedAnnotation.class, new ImportedRedactionMapper());
}
@Override
public void insert(@PathVariable(FILE_ID_PARAM) String fileId,
@RequestBody AddImportedAnnotationRequest annotation) {
importedAnnotationPersistenceService.insert(fileId, annotation);
}
@Override
public void updateStatus(@PathVariable(FILE_ID_PARAM) String fileId,
@PathVariable(ANNOTATION_ID_PARAM) String annotationId,
@RequestBody UpdateImportedAnnotationStatusRequest updateImportedAnnotationStatusRequest) {
importedAnnotationPersistenceService.updateStatus(fileId, annotationId, updateImportedAnnotationStatusRequest.getStatus(), updateImportedAnnotationStatusRequest.getComment(), updateImportedAnnotationStatusRequest.getUser());
}
@Override
public void delete(@PathVariable(FILE_ID_PARAM) String fileId,
@PathVariable(ANNOTATION_ID_PARAM) String annotationId) {
importedAnnotationPersistenceService.delete(fileId, annotationId);
}
}

View File

@ -1,31 +1,37 @@
package com.iqser.red.service.peristence.v1.server.service;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.springframework.stereotype.Service;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.iqser.red.service.pdftron.redaction.v1.api.model.AnnotationExtractionResponse;
import com.iqser.red.service.pdftron.redaction.v1.api.model.DocumentRequest;
import com.iqser.red.service.pdftron.redaction.v1.api.model.PdfTronOptimizeRequest;
import com.iqser.red.service.pdftron.redaction.v1.api.model.PdfTronOptimizeResponse;
import com.iqser.red.service.persistence.management.v1.processor.client.PDFTronRedactionClient;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.*;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.*;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.ViewedPagesPersistenceService;
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;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ForceRedactionPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ImageRecategorizationPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.LegalBasisChangePersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.RemoveRedactionPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ResizeRedactionPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.BinaryFileRequest;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.WorkflowStatus;
import com.iqser.red.service.search.v1.model.IndexMessageType;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Provides the internal interface between upload request and the actual persistence.
@ -50,7 +56,6 @@ public class FileService {
private final LegalBasisChangePersistenceService legalBasisChangePersistenceService;
private final ResizeRedactionPersistenceService resizeRedactionPersistenceService;
private final IndexingService indexingService;
private final ImportedAnnotationPersistenceService importedAnnotationPersistenceService;
public JSONPrimitive<String> upload(BinaryFileRequest request) {
@ -72,26 +77,17 @@ public class FileService {
}
try {
AnnotationExtractionResponse optimized = pdfTronRedactionClient.optimizeGetAndRemoveAnnotations(new DocumentRequest(request.getData()));
importedAnnotationPersistenceService.insert(fileId, optimized.getAnnotations());
pdfTronRedactionClient.saveOptimizedAndAnnotations(new DocumentRequest(request.getDossierId(), fileId, request.getData()));
if (optimized.getNumberOfPages() == 0) {
throw new BadRequestException("Empty document");
}
// if successful update request with linearized PDF
request.setData(optimized.getDocument());
} catch (FeignException e) {
log.warn("Failed to optimize file: {}", request.getFilename(), e);
throw new BadRequestException("Failed to optimize document");
}
fileManagementStorageService.storeObject(request.getDossierId(), fileId, FileType.ORIGIN, request.getData());
if (existingStatus != null) {
// the file is already uploaded, just reanalyse it.
fileStatusService.overwriteFile(request.getDossierId(), fileId, request.getUploader(), request.getFilename(), request
.getData().length);
fileStatusService.overwriteFile(request.getDossierId(), fileId, request.getUploader(), request.getFilename(), request.getData().length);
} else {
// the file is new, should create a new status for it.
log.info("File {} has no status yet, creating one and setting to unprocessed.", request.getFilename());
@ -111,142 +107,171 @@ public class FileService {
}
}
public void softDeleteFile(String dossierId, String fileId, OffsetDateTime softDeletedTime) {
forceRedactionPersistenceService.findForceRedactions(fileId, false).forEach(annotation -> {
forceRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false)
.forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
removeRedactionPersistenceService.findRemoveRedactions(fileId, false).forEach(annotation -> {
removeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false)
.forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
addRedactionPersistenceService.findAddRedactions(fileId, false).forEach(annotation -> {
addRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false)
.forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
recategorizationPersistenceService.findRecategorizations(fileId, false).forEach(recatigorization -> {
recategorizationPersistenceService.softDelete(fileId, recatigorization.getId().getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), false).forEach(comment -> {
recategorizationPersistenceService.softDelete(fileId, recatigorization.getId()
.getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId()
.getAnnotationId(), false).forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
resizeRedactionPersistenceService.findResizeRedactions(fileId, false).forEach(annotation -> {
resizeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false).forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
legalBasisChangePersistenceService.findLegalBasisChanges(fileId, false).forEach(legalBasisChange -> {
legalBasisChangePersistenceService.softDelete(fileId, legalBasisChange.getId().getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, legalBasisChange.getId().getAnnotationId(), false)
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false)
.forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
legalBasisChangePersistenceService.findLegalBasisChanges(fileId, false).forEach(legalBasisChange -> {
legalBasisChangePersistenceService.softDelete(fileId, legalBasisChange.getId()
.getAnnotationId(), softDeletedTime);
commentPersistenceService.findCommentsByAnnotationId(fileId, legalBasisChange.getId()
.getAnnotationId(), false).forEach(comment -> {
commentPersistenceService.softDelete(comment.getId(), softDeletedTime);
});
});
viewedPagesPersistenceService.deleteForFile(fileId);
indexingService.addToIndexingQueue(IndexMessageType.UPDATE, null, dossierId, fileId, 2);
}
public void hardDeleteFile(String dossierId, String fileId) {
Arrays.stream(FileType.values()).forEach(fileType -> {
try {
fileManagementStorageService.deleteObject(dossierId, fileId, fileType);
} catch (Exception e) {
log.warn("Failed to physically delete file: {} with type {}", fileId, fileType);
}
}
);
try {
fileManagementStorageService.deleteObject(dossierId, fileId, fileType);
} catch (Exception e) {
log.warn("Failed to physically delete file: {} with type {}", fileId, fileType);
}
});
forceRedactionPersistenceService.findForceRedactions(fileId, true).forEach(annotation -> {
forceRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
});
removeRedactionPersistenceService.findRemoveRedactions(fileId, true).forEach(annotation -> {
removeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
});
addRedactionPersistenceService.findAddRedactions(fileId, true).forEach(annotation -> {
addRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
});
recategorizationPersistenceService.findRecategorizations(fileId, true).forEach(recatigorization -> {
recategorizationPersistenceService.hardDelete(fileId, recatigorization.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true).forEach(comment -> {
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId()
.getAnnotationId(), true).forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
});
resizeRedactionPersistenceService.findResizeRedactions(fileId, true).forEach(annotation -> {
resizeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
commentPersistenceService.hardDelete(comment.getId());
});
});
indexingService.addToDeleteFromIndexQueue(dossierId, fileId, 2);
}
public void undeleteFile(String dossierTemplateId, String dossierId, String fileId, OffsetDateTime softDeletedTime) {
public void undeleteFile(String dossierTemplateId, String dossierId, String fileId,
OffsetDateTime softDeletedTime) {
forceRedactionPersistenceService.findForceRedactions(fileId, true).forEach(annotation -> {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
forceRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
}
});
removeRedactionPersistenceService.findRemoveRedactions(fileId, true).forEach(annotation -> {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
removeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
}
});
addRedactionPersistenceService.findAddRedactions(fileId, true).forEach(annotation -> {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
addRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
}
});
recategorizationPersistenceService.findRecategorizations(fileId, true).forEach(recatigorization -> {
if (recatigorization.getSoftDeletedTime().equals(softDeletedTime) || recatigorization.getSoftDeletedTime().isAfter(softDeletedTime)) {
if (recatigorization.getSoftDeletedTime().equals(softDeletedTime) || recatigorization.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
recategorizationPersistenceService.undelete(fileId, recatigorization.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true).forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId()
.getAnnotationId(), true).forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
@ -254,13 +279,16 @@ public class FileService {
});
resizeRedactionPersistenceService.findResizeRedactions(fileId, true).forEach(annotation -> {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) {
if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
resizeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId());
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true)
.forEach(comment -> {
if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime()
.isAfter(softDeletedTime)) {
commentPersistenceService.undelete(comment.getId());
}
});
}
});
@ -268,8 +296,11 @@ public class FileService {
}
private String generateFileId(BinaryFileRequest file) {
return hashFunction.hashBytes((file.getFilename() + file.getDossierId()).getBytes(StandardCharsets.UTF_8)).toString();
return hashFunction.hashBytes((file.getFilename() + file.getDossierId()).getBytes(StandardCharsets.UTF_8))
.toString();
}
}

View File

@ -8,14 +8,12 @@ import com.iqser.red.service.peristence.v1.server.configuration.MessagingConfigu
import com.iqser.red.service.peristence.v1.server.controller.RulesController;
import com.iqser.red.service.peristence.v1.server.model.image.ImageServiceRequest;
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
import com.iqser.red.service.peristence.v1.server.utils.ImportedRedactionMapper;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileAttributeEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.UserNotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.*;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.*;
import com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotation;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.ProcessingStatus;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.WorkflowStatus;
@ -54,7 +52,6 @@ public class FileStatusService {
private final AddRedactionPersistenceService addRedactionPersistenceService;
private final ResizeRedactionPersistenceService resizeRedactionPersistenceService;
private final FileManagementServiceSettings settings;
private final ImportedAnnotationPersistenceService importedAnnotationPersistenceService;
public List<FileEntity> getActiveFiles(String dossierId) {
@ -286,8 +283,6 @@ public class FileStatusService {
return;
}
List<ImportedAnnotation> importedAnnotations = MagicConverter.convert(importedAnnotationPersistenceService.findImportedAnnotations(fileId), ImportedAnnotation.class, new ImportedRedactionMapper());
var analyseRequest = AnalyzeRequest.builder()
.messageType(reanalyse ? MessageType.REANALYSE : MessageType.FULL_ANALYSE)
.dossierId(dossierId)
@ -299,7 +294,6 @@ public class FileStatusService {
.lastProcessed(fileStatus.getLastProcessed())
.fileAttributes(convert(fileAttributes))
.excludedPages(fileStatus.getExcludedPages())
.importedAnnotations(importedAnnotations)
.build();
setStatusProcessing(fileId);

View File

@ -1,18 +0,0 @@
package com.iqser.red.service.peristence.v1.server.utils;
import static com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter.convert;
import java.util.function.BiConsumer;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ImportedAnnotationEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotation;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.Rectangle;
public class ImportedRedactionMapper implements BiConsumer<ImportedAnnotationEntity, ImportedAnnotation> {
@Override
public void accept(ImportedAnnotationEntity manualRedactionEntryEntity, ImportedAnnotation manualRedactionEntry) {
manualRedactionEntry.setPositions(convert(manualRedactionEntryEntity.getPositions(), Rectangle.class));
}
}

View File

@ -1,109 +0,0 @@
databaseChangeLog:
- changeSet:
id: imported-annotation
author: philipp
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
primaryKey: true
primaryKeyName: imported_annotation_pkey
name: annotation_id
type: VARCHAR(255)
- column:
constraints:
nullable: false
primaryKey: true
primaryKeyName: imported_annotation_pkey
name: file_id
type: VARCHAR(255)
- column:
name: user_id
type: VARCHAR(255)
- column:
name: status
type: VARCHAR(255)
- column:
name: processed_date
type: TIMESTAMP WITHOUT TIME ZONE
- column:
name: file_status_id
type: VARCHAR(255)
- column:
name: comment
type: VARCHAR(255)
tableName: imported_annotation
- changeSet:
id: imported-annotation_positions
author: generated
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
name: imported_annotation_entity_annotation_id
type: VARCHAR(255)
- column:
constraints:
nullable: false
name: imported_annotation_entity_file_id
type: VARCHAR(255)
- column:
constraints:
nullable: false
name: height
type: FLOAT4
- column:
constraints:
nullable: false
name: page
type: INTEGER
- column:
constraints:
nullable: false
name: top_leftx
type: FLOAT4
- column:
constraints:
nullable: false
name: top_lefty
type: FLOAT4
- column:
constraints:
nullable: false
name: width
type: FLOAT4
tableName: imported_annotation_entity_positions
- changeSet:
id: imported-annotation-file-fk
author: dom
changes:
- addForeignKeyConstraint:
baseColumnNames: file_status_id
baseTableName: imported_annotation
constraintName: fkeur9q7l2tp5n12c2t9dfp3a10
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: file
validate: true
- changeSet:
id: imported-annotation-file-positions
author: dom
changes:
- addForeignKeyConstraint:
baseColumnNames: imported_annotation_entity_annotation_id,imported_annotation_entity_file_id
baseTableName: imported_annotation_entity_positions
constraintName: fkol1r7vwjc1uvu36p5ju7cj28j
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: annotation_id,file_id
referencedTableName: imported_annotation
validate: true

View File

@ -8,8 +8,6 @@ databaseChangeLog:
- include:
file: db/changelog/4-archived-dossier.changelog.yaml
- include:
file: db/changelog/5-imported-annotation.changelog.yaml
file: db/changelog/5-excluded-from-automatic-analysis-file-column.changelog.yaml
- include:
file: db/changelog/6-excluded-from-automatic-analysis-file-column.changelog.yaml
- include:
file: db/changelog/7-dossier-status-table.changelog.yaml
file: db/changelog/6-dossier-status-table.changelog.yaml

View File

@ -1,10 +0,0 @@
package com.iqser.red.service.peristence.v1.server.integration.client;
import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.ImportedAnnotationResource;
@FeignClient(name = "ImportedRedactionClient", url = "http://localhost:${server.port}")
public interface ImportedRedactionClient extends ImportedAnnotationResource {
}

View File

@ -1,56 +0,0 @@
package com.iqser.red.service.peristence.v1.server.integration.tests;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.iqser.red.service.peristence.v1.server.integration.client.ImportedRedactionClient;
import com.iqser.red.service.peristence.v1.server.integration.service.DossierTemplateTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.service.DossierTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.service.FileTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AddImportedAnnotationRequest;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.ImportedAnnotationStatus;
import com.iqser.red.service.redaction.v1.model.Point;
import com.iqser.red.service.redaction.v1.model.Rectangle;
public class ImportedRedactionTest extends AbstractPersistenceServerServiceTest {
@Autowired
private FileTesterAndProvider fileTesterAndProvider;
@Autowired
private DossierTesterAndProvider dossierTesterAndProvider;
@Autowired
private DossierTemplateTesterAndProvider dossierTemplateTesterAndProvider;
@Autowired
private ImportedRedactionClient importedRedactionClient;
@Test
public void testManualRedaction() {
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
var dossier = dossierTesterAndProvider.provideTestDossier(dossierTemplate);
var file = fileTesterAndProvider.testAndProvideFile(dossier);
importedRedactionClient.insert(file.getId(), AddImportedAnnotationRequest.builder()
.positions(List.of(new Rectangle(new Point(1, 1), 1, 1, 1)))
.annotationId("annotationId")
.status(ImportedAnnotationStatus.NEW)
.userId("userId")
.comment("comment")
.build());
var loadedImportedRedaction = importedRedactionClient.getByFileId(file.getId());
assertThat(loadedImportedRedaction.get(0).getPositions().size()).isEqualTo(1);
}
}

View File

@ -5,8 +5,10 @@ import com.iqser.red.service.peristence.v1.server.Application;
import com.iqser.red.service.peristence.v1.server.client.RedactionClient;
import com.iqser.red.service.peristence.v1.server.client.SearchClient;
import com.iqser.red.service.peristence.v1.server.integration.client.FileClient;
import com.iqser.red.service.peristence.v1.server.utils.StorageIdUtils;
import com.iqser.red.service.persistence.management.v1.processor.client.PDFTronRedactionClient;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.*;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.redaction.v1.model.AnnotateResponse;
import com.iqser.red.service.redaction.v1.model.RedactionLog;
import com.iqser.red.service.redaction.v1.model.RedactionResult;
@ -33,6 +35,8 @@ import org.springframework.context.annotation.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
@ -118,11 +122,16 @@ public abstract class AbstractPersistenceServerServiceTest {
when(amqpAdmin.getQueueInfo(Mockito.any())).thenReturn(null);
when(pdfTronRedactionClient.optimizeGetAndRemoveAnnotations(Mockito.any())).thenAnswer((args) -> {
DocumentRequest request = (DocumentRequest) args.getArguments()[0];
int numberOfPages = (request.getDocument().length == 0? 0: 10);
return new AnnotationExtractionResponse(request.getDocument(), numberOfPages, List.of());
});
doAnswer(answer -> {
Object[] args = answer.getArguments();
DocumentRequest d = (DocumentRequest) args[0];
storageService.storeObject(StorageIdUtils.getStorageId(d.getDossierId(), d.getFileId(), FileType.ORIGIN), d.getDocument());
return null;
}).when(pdfTronRedactionClient).saveOptimizedAndAnnotations(any());
when(pdfTronRedactionClient.redact(Mockito.any())).thenAnswer((args) ->
new PdfTronRedactionResult(((PdfTronRedactionRequest) args.getArguments()[0]).getDocument()));
when(pdfTronRedactionClient.redactionPreview(Mockito.any())).thenAnswer((args) ->

View File

@ -16,7 +16,7 @@ import java.util.Map;
public class FileSystemBackedStorageService extends S3StorageService {
private final Map<String, File> dataMap = new HashMap<>();
private Map<String, File> dataMap = new HashMap<>();
public FileSystemBackedStorageService() {
super(null, null);
@ -71,9 +71,6 @@ public class FileSystemBackedStorageService extends S3StorageService {
}
public void clearStorage() {
this.dataMap.forEach((k, v) -> {
v.delete();
});
this.dataMap.clear();
dataMap = new HashMap<>();
}
}

View File

@ -25,9 +25,9 @@
</modules>
<properties>
<redaction-service.version>3.68.0</redaction-service.version>
<redaction-service.version>3.72.0</redaction-service.version>
<search-service.version>2.18.0</search-service.version>
<pdftron-redaction-service.version>3.30.0</pdftron-redaction-service.version>
<pdftron-redaction-service.version>3.31.0</pdftron-redaction-service.version>
<redaction-report-service.version>3.19.0</redaction-report-service.version>
</properties>