Compare commits

...

1 Commits

2 changed files with 16 additions and 17 deletions

View File

@ -64,7 +64,7 @@ public class DownloadStatusEntity {
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
DossierEntity dossier; DossierEntity dossier;
@ManyToMany @ManyToMany(fetch = FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT) @Fetch(FetchMode.SUBSELECT)
List<FileEntity> files = new ArrayList<>(); List<FileEntity> files = new ArrayList<>();

View File

@ -132,7 +132,6 @@ public class DownloadPreparationService {
} }
@Transactional
public void createDownload(RedactionResultMessage reportResultMessage) { public void createDownload(RedactionResultMessage reportResultMessage) {
DownloadStatusEntity downloadStatus = downloadStatusPersistenceService.getStatus(reportResultMessage.getDownloadId()); DownloadStatusEntity downloadStatus = downloadStatusPersistenceService.getStatus(reportResultMessage.getDownloadId());
@ -142,7 +141,7 @@ public class DownloadPreparationService {
try (FileSystemBackedArchiver fileSystemBackedArchiver = new FileSystemBackedArchiver()) { try (FileSystemBackedArchiver fileSystemBackedArchiver = new FileSystemBackedArchiver()) {
generateAndAddFiles(downloadStatus, reportResultMessage, fileSystemBackedArchiver); generateAndAddFiles(downloadStatus, reportResultMessage, fileSystemBackedArchiver);
addReports(reportResultMessage.getDownloadId(), storedFileInformations, fileSystemBackedArchiver); addReports(reportResultMessage.getDownloadId(), downloadStatus, storedFileInformations, fileSystemBackedArchiver);
storeZipFile(downloadStatus, fileSystemBackedArchiver); storeZipFile(downloadStatus, fileSystemBackedArchiver);
updateStatusToReady(downloadStatus, fileSystemBackedArchiver); updateStatusToReady(downloadStatus, fileSystemBackedArchiver);
@ -175,15 +174,13 @@ public class DownloadPreparationService {
int i = 1; int i = 1;
long fileGenerationStart = System.currentTimeMillis(); long fileGenerationStart = System.currentTimeMillis();
var fileIds = downloadStatus.getFiles().stream().map(FileEntity::getId).collect(Collectors.toList()); for (FileEntity file : downloadStatus.getFiles()) {
for (String fileId : fileIds) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
FileEntity fileStatus = fileStatusPersistenceService.getStatus(fileId); byte[] original = fileManagementStorageService.getStoredObjectBytes(file.getDossierId(), file.getId(), FileType.ORIGIN);
byte[] original = fileManagementStorageService.getStoredObjectBytes(fileStatus.getDossierId(), fileId, FileType.ORIGIN);
var isFileApproved = WorkflowStatus.APPROVED.equals(fileStatus.getWorkflowStatus()); var isFileApproved = WorkflowStatus.APPROVED.equals(file.getWorkflowStatus());
String filename = isFileApproved ? fileStatus.getFilename() : "UNAPPROVED_" + fileStatus.getFilename(); String filename = isFileApproved ? file.getFilename() : "UNAPPROVED_" + file.getFilename();
for (DownloadFileType downloadFileType : downloadStatus.getDownloadFileTypes()) { for (DownloadFileType downloadFileType : downloadStatus.getDownloadFileTypes()) {
if (downloadFileType.name().equals(DownloadFileType.ORIGINAL.name())) { if (downloadFileType.name().equals(DownloadFileType.ORIGINAL.name())) {
@ -191,21 +188,21 @@ public class DownloadPreparationService {
} }
if (downloadFileType.name().equals(DownloadFileType.PREVIEW.name())) { if (downloadFileType.name().equals(DownloadFileType.PREVIEW.name())) {
fileSystemBackedArchiver.addEntry(new FileSystemBackedArchiver.ArchiveModel("Preview", addSuffix(filename, "highlighted"), // fileSystemBackedArchiver.addEntry(new FileSystemBackedArchiver.ArchiveModel("Preview", addSuffix(filename, "highlighted"), //
getPreview(fileId, reportResultMessage.getRedactionResultDetails()))); getPreview(file.getId(), reportResultMessage.getRedactionResultDetails())));
} }
if (downloadFileType.name().equals(DownloadFileType.DELTA_PREVIEW.name())) { if (downloadFileType.name().equals(DownloadFileType.DELTA_PREVIEW.name())) {
fileSystemBackedArchiver.addEntry(new FileSystemBackedArchiver.ArchiveModel("Delta Preview", addSuffix(filename, "delta_highlighted"), // fileSystemBackedArchiver.addEntry(new FileSystemBackedArchiver.ArchiveModel("Delta Preview", addSuffix(filename, "delta_highlighted"), //
getDeltaPreview(fileId, reportResultMessage.getRedactionResultDetails()))); getDeltaPreview(file.getId(), reportResultMessage.getRedactionResultDetails())));
} }
if (downloadFileType.name().equals(DownloadFileType.REDACTED.name()) && isFileApproved) { if (downloadFileType.name().equals(DownloadFileType.REDACTED.name()) && isFileApproved) {
fileSystemBackedArchiver.addEntry(new FileSystemBackedArchiver.ArchiveModel("Redacted", addSuffix(fileStatus.getFilename(), "redacted"), // fileSystemBackedArchiver.addEntry(new FileSystemBackedArchiver.ArchiveModel("Redacted", addSuffix(file.getFilename(), "redacted"), //
getRedacted(fileId, reportResultMessage.getRedactionResultDetails()))); getRedacted(file.getId(), reportResultMessage.getRedactionResultDetails())));
} }
} }
log.info("Successfully added file {}/{} for downloadId {}, took {}", i, fileIds.size(), downloadStatus.getStorageId(), System.currentTimeMillis() - start); log.info("Successfully added file {}/{} for downloadId {}, took {}", i, downloadStatus.getFiles().size(), downloadStatus.getStorageId(), System.currentTimeMillis() - start);
i++; i++;
} }
log.info("Successfully added {} files for downloadId {}, took {}", fileIds, downloadStatus.getStorageId(), System.currentTimeMillis() - fileGenerationStart); log.info("Successfully added {} files for downloadId {}, took {}", downloadStatus.getFiles().stream().map(FileEntity::getId).toList(), downloadStatus.getStorageId(), System.currentTimeMillis() - fileGenerationStart);
} }
@ -242,16 +239,18 @@ public class DownloadPreparationService {
} }
private void addReports(String downloadId, List<StoredFileInformation> storedFileInformations, FileSystemBackedArchiver fileSystemBackedArchiver) { private void addReports(String downloadId, DownloadStatusEntity downloadStatus, List<StoredFileInformation> storedFileInformations, FileSystemBackedArchiver fileSystemBackedArchiver) {
long addReportsStart = System.currentTimeMillis(); long addReportsStart = System.currentTimeMillis();
Map<String, FileEntity> fileById = downloadStatus.getFiles().stream().collect(Collectors.toMap(FileEntity::getId, a -> a));
for (StoredFileInformation storedFileInformation : storedFileInformations) { for (StoredFileInformation storedFileInformation : storedFileInformations) {
FileEntity fileStatus = null; FileEntity fileStatus = null;
if (storedFileInformation.getFileId() != null) { if (storedFileInformation.getFileId() != null) {
fileStatus = fileStatusPersistenceService.getStatus(storedFileInformation.getFileId()); fileStatus = fileById.get(storedFileInformation.getFileId());
} }
ReportTemplateEntity reportTemplate = reportTemplatePersistenceService.find(storedFileInformation.getTemplateId()); ReportTemplateEntity reportTemplate = reportTemplatePersistenceService.find(storedFileInformation.getTemplateId());