Pull request #55: flag calculations for hasUpdates
Merge in RED/persistence-service from 3.0-efsa-readiness to master * commit 'f7c083b347bc302db11d841cf17931898dfb4848': pmd fix flag calculations for hasUpdates
This commit is contained in:
commit
9e9bbc6098
@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -49,4 +50,7 @@ public class ViewedPagesPersistenceService {
|
||||
}
|
||||
|
||||
|
||||
public void resetViewedPages(String fileId, String currentReviewer, List<Integer> viewedPagesToReset) {
|
||||
viewedPagesRepository.deleteSeenPages(fileId,currentReviewer,viewedPagesToReset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ViewedPageEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -11,4 +13,7 @@ public interface ViewedPagesRepository extends JpaRepository<ViewedPageEntity, V
|
||||
|
||||
List<ViewedPageEntity> findByFileIdAndIdUserId(String fileId, String userId);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM ViewedPageEntity e where e.id.fileId = :fileId and e.id.userId = :currentReviewer and e.id.page in :viewedPagesToReset")
|
||||
void deleteSeenPages(String fileId, String currentReviewer, List<Integer> viewedPagesToReset);
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ import static com.iqser.red.service.persistence.management.v1.processor.utils.Ma
|
||||
public class FileStatusController implements StatusResource {
|
||||
|
||||
private final FileStatusService fileStatusService;
|
||||
private final DossierService dossierService;
|
||||
private final ExcludeFromAnalysisService excludeFromAnalysis;
|
||||
private final AnalysisFlagsCalculationService analysisFlagsCalculationService;
|
||||
private final ReanalysisRequiredStatusService reanalysisRequiredStatusService;
|
||||
|
||||
@ -6,13 +6,17 @@ 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.redaction.v1.model.RedactionLogEntry;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AnalysisFlagsCalculationService {
|
||||
@ -25,6 +29,8 @@ public class AnalysisFlagsCalculationService {
|
||||
@Async
|
||||
public void calculateFlags(String dossierId, String fileId) {
|
||||
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
var file = fileStatusPersistenceService.getStatus(fileId);
|
||||
var redactionLog = redactionLogService.getRedactionLog(dossierId, fileId, true);
|
||||
|
||||
@ -40,7 +46,8 @@ public class AnalysisFlagsCalculationService {
|
||||
boolean hasComments = false;
|
||||
|
||||
|
||||
viewedPagesPersistenceService.findViewedPages(fileId, file.getCurrentReviewer());
|
||||
var viewedPagesToReset = new ArrayList<Integer>();
|
||||
|
||||
|
||||
for (RedactionLogEntry entry : redactionLog.getRedactionLogEntry()) {
|
||||
if (entry.isExcluded()) {
|
||||
@ -49,41 +56,43 @@ public class AnalysisFlagsCalculationService {
|
||||
|
||||
String type = getType(entry.getType());
|
||||
|
||||
if (entry.isRedacted() && !entry.isManual() || entry.isManual() && entry.getStatus()
|
||||
.equals(AnnotationStatus.APPROVED)) {
|
||||
if (!hasRedactions && (entry.isRedacted() && !entry.isManual() || entry.isManual() && entry.getStatus()
|
||||
.equals(AnnotationStatus.APPROVED))) {
|
||||
hasRedactions = true;
|
||||
}
|
||||
|
||||
if (entry.isHint() && !type.equals("false_positive")) {
|
||||
if (!hasHints && entry.isHint() && !type.equals("false_positive")) {
|
||||
hasHints = true;
|
||||
}
|
||||
|
||||
if (entry.isHint() && type.equals("image") || entry.isImage()) {
|
||||
if (!hasImages && (type.equals("image") || entry.isImage())) {
|
||||
hasImages = true;
|
||||
}
|
||||
|
||||
if (entry.isManual() && entry.getStatus()
|
||||
.equals(AnnotationStatus.REQUESTED)) {
|
||||
if (!hasSuggestions && entry.isManual() && entry.getStatus().equals(AnnotationStatus.REQUESTED)) {
|
||||
hasSuggestions = true;
|
||||
}
|
||||
|
||||
if (entry.getComments() != null && !entry.getComments().isEmpty()) {
|
||||
if (!hasComments && entry.getComments() != null && !entry.getComments().isEmpty()) {
|
||||
hasComments = true;
|
||||
}
|
||||
|
||||
var lastChange = entry.getChanges().isEmpty() ? null : entry.getChanges().get(entry.getChanges().size() - 1);
|
||||
|
||||
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())) {
|
||||
viewedPagesToReset.add(entry.getPositions().get(0).getPage());
|
||||
hasUpdates = true;
|
||||
}
|
||||
|
||||
if (hasRedactions && hasHints && hasSuggestions && hasImages && hasComments && hasUpdates) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
viewedPagesPersistenceService.resetViewedPages(fileId, file.getCurrentReviewer(), viewedPagesToReset);
|
||||
fileStatusPersistenceService.updateFlags(fileId, hasRedactions, hasHints, hasImages, hasSuggestions, hasComments, hasUpdates);
|
||||
|
||||
log.info("Flag Calculations for file: {} took: {}ms", fileId, System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user