Merge branch 'RED-9205' into 'master'

RED-9205 - Fix download job failing

Closes RED-9205

See merge request redactmanager/persistence-service!498
This commit is contained in:
Andrei Isvoran 2024-05-24 13:43:42 +02:00
commit f962037aaa
2 changed files with 50 additions and 23 deletions

View File

@ -1,5 +1,19 @@
package com.iqser.red.service.persistence.management.v1.processor.service.download;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.pdftron.redaction.v1.api.model.RedactionMessage;
@ -39,32 +53,28 @@ import lombok.SneakyThrows;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class DownloadPreparationService {
DownloadStatusPersistenceService downloadStatusPersistenceService;
FileManagementStorageService fileManagementStorageService;
ReportTemplatePersistenceService reportTemplatePersistenceService;
NotificationPersistenceService notificationPersistenceService;
RabbitTemplate rabbitTemplate;
ObjectMapper objectMapper;
DownloadReportCleanupService downloadReportCleanupService;
ColorsService colorsService;
FileManagementServiceSettings settings;
DossierTemplatePersistenceService dossierTemplatePersistenceService;
DownloadRedactionFileStatusRepository downloadRedactionFileStatusRepository;
WebsocketService websocketService;
private final DownloadStatusPersistenceService downloadStatusPersistenceService;
private final FileManagementStorageService fileManagementStorageService;
private final ReportTemplatePersistenceService reportTemplatePersistenceService;
private final NotificationPersistenceService notificationPersistenceService;
private final RabbitTemplate rabbitTemplate;
private final ObjectMapper objectMapper;
private final DownloadReportCleanupService downloadReportCleanupService;
private final ColorsService colorsService;
private final FileManagementServiceSettings settings;
private final DossierTemplatePersistenceService dossierTemplatePersistenceService;
private final DownloadRedactionFileStatusRepository downloadRedactionFileStatusRepository;
private final WebsocketService websocketService;
@Value("${storage.backend}")
private String storageBackend;
private static final String REPORT_INFO = "/REPORT_INFO.json";
@Transactional
@ -356,13 +366,30 @@ public class DownloadPreparationService {
@SneakyThrows
private List<StoredFileInformation> getStoredFileInformation(String downloadId) {
var storageId = downloadId.substring(0, downloadId.length() - 3) + "/REPORT_INFO.json";
String storageId;
if (storageBackend.equals("s3")) {
storageId = generateReportJsonStorageIdForS3(downloadId);
} else {
storageId = generateReportJsonStorageIdForAzure(downloadId);
}
return objectMapper.readValue(fileManagementStorageService.getStoredObjectBytes(storageId), new TypeReference<>() {
});
}
private String generateReportJsonStorageIdForS3(String storageId) {
return storageId.substring(0, storageId.length() - 3) + REPORT_INFO;
}
private String generateReportJsonStorageIdForAzure(String storageId) {
return storageId.substring(0, storageId.length() - 4) + REPORT_INFO;
}
private String createFileName(FileEntity fileStatus, ReportTemplateEntity reportTemplate) {
if (fileStatus != null) {

View File

@ -23,7 +23,7 @@ public interface RemoveRedactionRepository extends JpaRepository<IdRemovalEntity
Optional<IdRemovalEntity> findByIdAndNotSoftDeleted(@Param("annotationEntityId") AnnotationEntityId annotationEntityId);
@Query("select idr from IdRemovalEntity idr where idr.id.fileId = :fileId and (:includeDeletions = true or idr.softDeletedTime is null)")
@Query("select idr from IdRemovalEntity idr left join fetch idr.typeIdsOfModifiedDictionaries where idr.id.fileId = :fileId and (:includeDeletions = true or idr.softDeletedTime is null)")
List<IdRemovalEntity> findByFileIdIncludeDeletions(@Param("fileId") String fileId, @Param("includeDeletions") boolean includeDeletions);