diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/entity/dossier/FileEntity.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/entity/dossier/FileEntity.java index e15b2678b..ea25aaed0 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/entity/dossier/FileEntity.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/entity/dossier/FileEntity.java @@ -127,6 +127,9 @@ public class FileEntity { @Column private int analysisVersion; + @Column + private OffsetDateTime annotationModificationDate; + @ElementCollection(fetch = FetchType.EAGER) private Set excludedPages = new HashSet<>(); diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/FileStatusPersistenceService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/FileStatusPersistenceService.java index 77b95344e..27e05ef03 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/FileStatusPersistenceService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/FileStatusPersistenceService.java @@ -71,7 +71,7 @@ public class FileStatusPersistenceService { if (isFileDeleted(fileId)) { return; } - fileRepository.updateFlags(fileId, OffsetDateTime.now(), hasRedactions, hasHints, hasImages, hasSuggestions, hasComments, hasUpdates); + fileRepository.updateFlags(fileId, OffsetDateTime.now(), hasRedactions, hasHints, hasImages, hasSuggestions, hasComments, hasUpdates); } @@ -83,7 +83,7 @@ public class FileStatusPersistenceService { } fileRepository.updateWorkflowStatus(fileId, workflowStatus, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), - approval ? OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS) : null); + approval ? OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS) : null); } @@ -97,9 +97,9 @@ public class FileStatusPersistenceService { if (processingStatus == ProcessingStatus.PROCESSED) { // In case the file is updated to "processed", "lastProcessed" date should be updated to "now" fileRepository.updateProcessingStatus(fileId, processingStatus, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), - OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); + OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); } else { - fileRepository.updateProcessingStatus(fileId, processingStatus, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); + fileRepository.updateProcessingStatus(fileId, processingStatus, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); } } @@ -112,7 +112,7 @@ public class FileStatusPersistenceService { } fileRepository.setUpdateStatusIndexingSuccessful(fileId, ProcessingStatus.PROCESSED, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), - OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); + OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); } @@ -122,7 +122,7 @@ public class FileStatusPersistenceService { if (isFileDeleted(fileId)) { return; } - fileRepository.updateLastOCRTime(fileId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), time); + fileRepository.updateLastOCRTime(fileId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), time); } @@ -132,7 +132,7 @@ public class FileStatusPersistenceService { if (isFileDeleted(fileId)) { return; } - fileRepository.updateHasComments(fileId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), hasComments); + fileRepository.updateHasComments(fileId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), hasComments); } @@ -142,7 +142,7 @@ public class FileStatusPersistenceService { if (isFileDeleted(fileId)) { return; } - fileRepository.updateLastManualRedaction(fileId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), date); + fileRepository.updateLastManualRedaction(fileId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), date); } @@ -154,7 +154,7 @@ public class FileStatusPersistenceService { return; } fileRepository.setUpdateLastManualRedactionAndHasSuggestions(fileId, - OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), date, hasSuggestions); + OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), date, hasSuggestions); } @@ -171,7 +171,7 @@ public class FileStatusPersistenceService { var fileAttributeEntities = convertFileAttributes(dossierId, file, fileAttributes); file.setLastFileAttributeChange(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); file.setLastUpdated(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); - file.setFileAttributes(fileAttributeEntities); + file.setFileAttributes(fileAttributeEntities); }, () -> { throw new NotFoundException("Unknown file=" + fileId); }); @@ -188,7 +188,7 @@ public class FileStatusPersistenceService { file.setLastManualRedaction(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); file.setLastUpdated(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); - file.setExcludedPages(excludedPages); + file.setExcludedPages(excludedPages); }, () -> { throw new NotFoundException("Unknown file=" + fileId); }); @@ -224,7 +224,7 @@ public class FileStatusPersistenceService { public void softDelete(String fileId, OffsetDateTime softDeletedTime) { int countUpdate = fileRepository.setSoftDelete(fileId, ProcessingStatus.DELETED, - OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), softDeletedTime); + OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), softDeletedTime); if (countUpdate == 0) { throw new NotFoundException("Unknown file=" + fileId); } @@ -237,7 +237,7 @@ public class FileStatusPersistenceService { int countUpdate = fileRepository.setHardDelete(fileId, ProcessingStatus.DELETED, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), - OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); + OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); if (countUpdate == 0) { throw new NotFoundException("Unknown file=" + fileId); } @@ -279,7 +279,7 @@ public class FileStatusPersistenceService { if (isFileDeleted(fileId)) { return; } - int countUpdate = fileRepository.toggleExclusion(fileId, excluded, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); + int countUpdate = fileRepository.toggleExclusion(fileId, excluded, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); if (countUpdate == 0) { throw new NotFoundException("Unknown file=" + fileId); } @@ -296,13 +296,19 @@ public class FileStatusPersistenceService { int countUpdate = fileRepository.overwriteFile(fileId, filename, uploader, ProcessingStatus.FULLREPROCESS, WorkflowStatus.NEW, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), - OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); + OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS)); if (countUpdate == 0) { throw new NotFoundException("Unknown file=" + fileId); } } + @Transactional + public void setLastAnnotationModificationDateForFile(String fileId, OffsetDateTime changeDate) { + fileRepository.setLastAnnotationModificationDateForFile(fileId, changeDate); + } + + private List convertFileAttributes(String dossierId, FileEntity file, Map fileAttributesMap) { @@ -322,7 +328,6 @@ public class FileStatusPersistenceService { }).collect(Collectors.toList()); } - private boolean isFileDeleted(String fileId) { return fileRepository.findById(fileId).map(FileEntity::isSoftOrHardDeleted).orElse(false); } diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/FileRepository.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/FileRepository.java index a6faf05be..7ce3ab05d 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/FileRepository.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/FileRepository.java @@ -125,7 +125,11 @@ public interface FileRepository extends JpaRepository { int countSoftDeletedFiles(String dossierId); @Query("select distinct f.dossierId from FileEntity f where f.lastUpdated > :since") - List findDossierChangeByLastUpdatedIsAfter(OffsetDateTime since); + List findDossierChangeByLastUpdatedIsAfter(OffsetDateTime since); + + @Modifying(clearAutomatically = true) + @Query("update FileEntity f set f.annotationModificationDate = :annotationModificationDate where f.id = :fileId") + void setLastAnnotationModificationDateForFile(String fileId, OffsetDateTime annotationModificationDate); } diff --git a/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/AnalysisFlagsCalculationService.java b/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/AnalysisFlagsCalculationService.java index 556abc071..ddf719ce0 100644 --- a/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/AnalysisFlagsCalculationService.java +++ b/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/AnalysisFlagsCalculationService.java @@ -44,6 +44,7 @@ public class AnalysisFlagsCalculationService { boolean hasUpdates = false; boolean hasComments = false; + OffsetDateTime lastModification = null; for (RedactionLogEntry entry : redactionLog.getRedactionLogEntry()) { if (entry.isExcluded()) { @@ -75,6 +76,10 @@ public class AnalysisFlagsCalculationService { var lastChange = entry.getChanges().isEmpty() ? null : entry.getChanges().get(entry.getChanges().size() - 1); + if(lastModification == null || lastChange.getDateTime().isAfter(lastModification)){ + lastModification = lastChange.getDateTime(); + } + var viewedPage = entry.getPositions().isEmpty() ? null : viewedPages.get(entry.getPositions().get(0).getPage()); if (lastChange != null && lastChange.getDateTime() != null && viewedPage != null && viewedPage.isBefore(lastChange.getDateTime())) { @@ -96,6 +101,9 @@ public class AnalysisFlagsCalculationService { fileStatusPersistenceService.updateFlags(fileId, hasRedactions, hasHints, hasImages, hasSuggestions, hasComments, hasUpdates); } + if(file.getAnnotationModificationDate() == null || file.getAnnotationModificationDate().isBefore(lastModification)) { + fileStatusPersistenceService.setLastAnnotationModificationDateForFile(fileId, lastModification); + } } diff --git a/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/3-added-annotation-modification-date.changelog.yaml b/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/3-added-annotation-modification-date.changelog.yaml new file mode 100644 index 000000000..d01828ead --- /dev/null +++ b/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/3-added-annotation-modification-date.changelog.yaml @@ -0,0 +1,11 @@ +databaseChangeLog: + - changeSet: + id: add-annotation-modification-date + author: ali + changes: + - addColumn: + columns: + - column: + name: annotation_modification_date + type: TIMESTAMP WITHOUT TIME ZONE + tableName: file diff --git a/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/db.changelog-master.yaml b/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/db.changelog-master.yaml index a37b99cd4..299e46549 100644 --- a/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/persistence-service-v1/persistence-service-server-v1/src/main/resources/db/changelog/db.changelog-master.yaml @@ -3,3 +3,5 @@ databaseChangeLog: file: db/changelog/1-initial-schema.changelog.yaml - include: file: db/changelog/2-ignored-hint-color.changelog.yaml + - include: + file: db/changelog/3-added-annotation-modification-date.changelog.yaml