RED-7821: Added migration to fix wrong dossier dictionary entries in redaction logs #196
@ -0,0 +1,89 @@
|
||||
package com.iqser.red.service.peristence.v1.server.migration.migrations;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.migration.Migration;
|
||||
import com.iqser.red.service.peristence.v1.server.service.DossierService;
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileManagementStorageService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Setter
|
||||
@Service
|
||||
public class FixDossierDictionaryEntryInRedactionLog14 extends Migration {
|
||||
|
||||
private static final String NAME = "Fix dossier dictionary entries in redactionLog for non dossier dictionaries";
|
||||
private static final long VERSION = 14;
|
||||
|
||||
@Autowired
|
||||
private FileStatusPersistenceService fileStatusPersistenceService;
|
||||
|
||||
@Autowired
|
||||
private FileManagementStorageService fileManagementStorageService;
|
||||
|
||||
@Autowired
|
||||
private DossierService dossierService;
|
||||
|
||||
|
||||
public FixDossierDictionaryEntryInRedactionLog14() {
|
||||
|
||||
super(NAME, VERSION);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void migrate() {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
var dossiers = dossierService.getAllDossiers().stream().filter(dossier -> dossier.getHardDeletedTime() == null).toList();
|
||||
|
||||
int processedDossiers = 0;
|
||||
int numberOfErrors = 0;
|
||||
|
||||
for (var dossier : dossiers) {
|
||||
|
||||
long dossierStart = System.currentTimeMillis();
|
||||
var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId()).stream().filter(file -> file.getHardDeletedTime() == null).toList();
|
||||
|
||||
int processedFiles = 0;
|
||||
for (var file : files) {
|
||||
try {
|
||||
var redactionLog = fileManagementStorageService.getRedactionLog(dossier.getId(), file.getId());
|
||||
|
||||
boolean modified = false;
|
||||
for (var redactionLogEntry : redactionLog.getRedactionLogEntry()) {
|
||||
|
||||
if (redactionLogEntry.isDossierDictionaryEntry() && !redactionLogEntry.getType().equals("dossier_redaction")) {
|
||||
redactionLogEntry.setDossierDictionaryEntry(false);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info("Unable to update redactionLog for dossier {} and file {}, message {}", dossier.getId(), file.getId(), e.getMessage());
|
||||
numberOfErrors++;
|
||||
}
|
||||
processedFiles++;
|
||||
log.info("Processed {} of {} files from dossier {}", processedFiles, files.size(), dossier.getId());
|
||||
}
|
||||
processedDossiers++;
|
||||
log.info("Processed {} of {} dossiers, took: {}", processedDossiers, dossiers.size(), System.currentTimeMillis() - dossierStart);
|
||||
}
|
||||
|
||||
log.info("Successfully migrated all redactionLogs, took: {} with {} errors", System.currentTimeMillis() - start, numberOfErrors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user