Merge branch 'RED-8371' into 'master'
RED-8371: after initial file upload flag calculation does not work Closes RED-8371 See merge request redactmanager/persistence-service!322
This commit is contained in:
commit
c2d4b0fd28
@ -68,6 +68,22 @@ public class MigrationStatusController implements MigrationStatusResource {
|
|||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<?> revertMigrationForFile(String dossierId, String fileId) {
|
||||||
|
|
||||||
|
if (!fileStatusService.fileExists(fileId)) {
|
||||||
|
throw new NotFoundException(String.format("File with id %s does not exist", fileId));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!saasMigrationStatusPersistenceService.findById(fileId).getStatus().equals(FINISHED)) {
|
||||||
|
throw new BadRequestException(String.format("File with id %s is not migrated yet, can't revert.", fileId));
|
||||||
|
}
|
||||||
|
|
||||||
|
saasMigrationService.revertMigrationForFile(dossierId, fileId);
|
||||||
|
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<?> requeueErrorFiles() {
|
public ResponseEntity<?> requeueErrorFiles() {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ public interface MigrationStatusResource {
|
|||||||
|
|
||||||
String MIGRATION_STATUS_REST_PATH = ExternalApi.BASE_PATH + "/migration-status";
|
String MIGRATION_STATUS_REST_PATH = ExternalApi.BASE_PATH + "/migration-status";
|
||||||
String START_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/start_migration";
|
String START_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/start_migration";
|
||||||
|
String REVERT_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/revert_migration";
|
||||||
String RETRY_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/retry_migration";
|
String RETRY_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/retry_migration";
|
||||||
|
|
||||||
String FILE_ID = "fileId";
|
String FILE_ID = "fileId";
|
||||||
@ -34,6 +35,12 @@ public interface MigrationStatusResource {
|
|||||||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
|
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
|
||||||
ResponseEntity<?> startMigrationForFile(@RequestParam(value = DOSSIER_ID) String dossierId, @RequestParam(value = FILE_ID) String fileId);
|
ResponseEntity<?> startMigrationForFile(@RequestParam(value = DOSSIER_ID) String dossierId, @RequestParam(value = FILE_ID) String fileId);
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping(value = REVERT_MIGRATION_REST_PATH + FILE_ID_PATH_VARIABLE + DOSSIER_ID_PATH_VARIABLE)
|
||||||
|
@Operation(summary = "Start SAAS migration for specific file", description = "None")
|
||||||
|
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
|
||||||
|
ResponseEntity<?> revertMigrationForFile(@RequestParam(value = DOSSIER_ID) String dossierId, @RequestParam(value = FILE_ID) String fileId);
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PostMapping(value = RETRY_MIGRATION_REST_PATH)
|
@PostMapping(value = RETRY_MIGRATION_REST_PATH)
|
||||||
@Operation(summary = "Restart SAAS migration for all files in error state", description = "None")
|
@Operation(summary = "Restart SAAS migration for all files in error state", description = "None")
|
||||||
|
|||||||
@ -208,8 +208,28 @@ public class SaasMigrationService implements TenantSyncService {
|
|||||||
|
|
||||||
MigratedIds migratedIds = getMigratedIds(dossierId, fileId);
|
MigratedIds migratedIds = getMigratedIds(dossierId, fileId);
|
||||||
Map<String, String> oldToNewMapping = migratedIds.buildOldToNewMapping();
|
Map<String, String> oldToNewMapping = migratedIds.buildOldToNewMapping();
|
||||||
|
updateAnnotationIds(dossierId, fileId, oldToNewMapping);
|
||||||
|
saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED);
|
||||||
|
|
||||||
|
log.info("AnnotationIds migration finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId);
|
||||||
|
finalizeMigration();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void revertMigrationForFile(String dossierId, String fileId) {
|
||||||
|
|
||||||
|
log.info("Reverting Migration for dossierId {} and fileId {}", dossierId, fileId);
|
||||||
|
MigratedIds migratedIds = getMigratedIds(dossierId, fileId);
|
||||||
|
Map<String, String> newToOldMapping = migratedIds.buildNewToOldMapping();
|
||||||
|
updateAnnotationIds(dossierId, fileId, newToOldMapping);
|
||||||
|
saasMigrationStatusPersistenceService.createMigrationRequiredStatus(dossierId, fileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void updateAnnotationIds(String dossierId, String fileId, Map<String, String> idMapping) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
updateAnnotationIds(fileId, oldToNewMapping);
|
updateAnnotationIds(fileId, idMapping);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String message = String.format("Error during annotation id migration for tenant %s dossier %s and file %s, cause %s",
|
String message = String.format("Error during annotation id migration for tenant %s dossier %s and file %s, cause %s",
|
||||||
TenantContext.getTenantId(),
|
TenantContext.getTenantId(),
|
||||||
@ -220,10 +240,6 @@ public class SaasMigrationService implements TenantSyncService {
|
|||||||
log.error(message);
|
log.error(message);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED);
|
|
||||||
|
|
||||||
log.info("AnnotationIds migration finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId);
|
|
||||||
finalizeMigration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -236,11 +252,11 @@ public class SaasMigrationService implements TenantSyncService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateAnnotationIds(String fileId, Map<String, String> oldToNewMapping) {
|
public void updateAnnotationIds(String fileId, Map<String, String> idMapping) {
|
||||||
|
|
||||||
AtomicInteger numUpdates = new AtomicInteger(0);
|
AtomicInteger numUpdates = new AtomicInteger(0);
|
||||||
AtomicInteger numCommentUpdates = new AtomicInteger(0);
|
AtomicInteger numCommentUpdates = new AtomicInteger(0);
|
||||||
oldToNewMapping.forEach((key, value) -> {
|
idMapping.forEach((key, value) -> {
|
||||||
AnnotationEntityId oldAnnotationEntityId = buildAnnotationId(fileId, key);
|
AnnotationEntityId oldAnnotationEntityId = buildAnnotationId(fileId, key);
|
||||||
AnnotationEntityId newAnnotationEntityId = buildAnnotationId(fileId, value);
|
AnnotationEntityId newAnnotationEntityId = buildAnnotationId(fileId, value);
|
||||||
numUpdates.getAndAdd(saasAnnotationIdMigrationService.updateManualAddRedaction(oldAnnotationEntityId, newAnnotationEntityId));
|
numUpdates.getAndAdd(saasAnnotationIdMigrationService.updateManualAddRedaction(oldAnnotationEntityId, newAnnotationEntityId));
|
||||||
|
|||||||
@ -28,7 +28,6 @@ public class FileStatusProcessingUpdateService {
|
|||||||
private final FileStatusService fileStatusService;
|
private final FileStatusService fileStatusService;
|
||||||
private final IndexingService indexingService;
|
private final IndexingService indexingService;
|
||||||
private final DossierPersistenceService dossierPersistenceService;
|
private final DossierPersistenceService dossierPersistenceService;
|
||||||
private final AnalysisFlagsCalculationService analysisFlagsCalculationService;
|
|
||||||
private final ManualRedactionService manualRedactionService;
|
private final ManualRedactionService manualRedactionService;
|
||||||
private final FileManagementServiceSettings settings;
|
private final FileManagementServiceSettings settings;
|
||||||
private final FileStatusPersistenceService fileStatusPersistenceService;
|
private final FileStatusPersistenceService fileStatusPersistenceService;
|
||||||
|
|||||||
@ -299,7 +299,12 @@ public interface FileRepository extends JpaRepository<FileEntity, String> {
|
|||||||
*
|
*
|
||||||
* @return a List of Tuples of fileIds and dossierIds, where a flag calculation is necessary
|
* @return a List of Tuples of fileIds and dossierIds, where a flag calculation is necessary
|
||||||
*/
|
*/
|
||||||
@Query("select distinct f.id, f.dossierId from FileEntity f, ViewedPageEntity v where (f.lastFlagCalculation is NULL and f.lastProcessed is not NULL) or f.lastManualChangeDate > f.lastFlagCalculation or f.lastProcessed > f.lastFlagCalculation or (v.file.id = f.id and v.id.userId = f.assignee and f.lastFlagCalculation < v.viewedTime)")
|
@Query("""
|
||||||
|
select distinct f.id, f.dossierId
|
||||||
|
from FileEntity f
|
||||||
|
left join ViewedPageEntity v on f.id = v.file.id and v.id.userId = f.assignee
|
||||||
|
where (f.lastFlagCalculation is NULL and f.lastProcessed is not NULL) or f.lastManualChangeDate > f.lastFlagCalculation or f.lastProcessed > f.lastFlagCalculation or f.lastFlagCalculation < v.viewedTime
|
||||||
|
""")
|
||||||
List<Tuple> getFileIdentifiersWhereAnalysisFlagCalculationIsRequired();
|
List<Tuple> getFileIdentifiersWhereAnalysisFlagCalculationIsRequired();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user