Pull request #624: RED-6310 3.6

Merge in RED/persistence-service from RED-6310-3.6 to release/1.363.x

* commit '18ee468ca15ac07ff8ec6adc2712ccf42129df91':
  RED-6310: Changed element-collection fetch to eager because lazy loading runs into timing based errors
  RED-6310: Updated test for download preparation test to execute all preparation steps.
This commit is contained in:
Viktor Seifert 2023-03-13 16:56:01 +01:00
commit cfa9dfcc6f
4 changed files with 67 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import java.util.List;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Table;
@ -39,11 +40,11 @@ public class NotificationPreferencesEntity {
@Column
private EmailNotificationType emailNotificationType;
@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT)
private List<String> emailNotifications = new ArrayList<>();
@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT)
private List<String> inAppNotifications = new ArrayList<>();

View File

@ -141,7 +141,7 @@ public class DownloadPreparationService {
addReports(reportResultMessage.getDownloadId(), storedFileInformations, fileSystemBackedArchiver);
storeZipFile(downloadStatus, fileSystemBackedArchiver);
downloadStatusPersistenceService.updateStatus(downloadStatus.getStorageId(), DownloadStatusValue.READY, fileSystemBackedArchiver.getContentLength());
updateStatusToReady(downloadStatus, fileSystemBackedArchiver);
notificationPersistenceService.insertNotification(AddNotificationRequest.builder()
.userId(downloadStatus.getUserId())
@ -161,6 +161,15 @@ public class DownloadPreparationService {
}
private void updateStatusToReady(DownloadStatusEntity downloadStatus, FileSystemBackedArchiver fileSystemBackedArchiver) {
downloadStatusPersistenceService.updateStatus(downloadStatus.getStorageId(), DownloadStatusValue.READY, fileSystemBackedArchiver.getContentLength());
if (!Objects.equals(downloadStatus.getStatus(), DownloadStatusValue.READY)) {
downloadStatus.setStatus(DownloadStatusValue.READY);
}
}
private void generateAndAddFiles(DownloadStatusEntity downloadStatus, RedactionResultMessage reportResultMessage, FileSystemBackedArchiver fileSystemBackedArchiver) {
int i = 1;

View File

@ -40,6 +40,12 @@ public class RedactionResultMessageReceiver {
redactionResultMessage.getDownloadId()));
}
receive(redactionResultMessage);
}
public void receive(RedactionResultMessage redactionResultMessage) {
log.info("Received redaction results for downloadId:{}", redactionResultMessage.getDownloadId());
downloadPreparationService.createDownload(redactionResultMessage);

View File

@ -5,11 +5,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.pdftron.redaction.v1.api.model.RedactionResultMessage;
import com.iqser.red.service.peristence.v1.server.integration.client.DossierClient;
import com.iqser.red.service.peristence.v1.server.integration.client.DownloadClient;
import com.iqser.red.service.peristence.v1.server.integration.client.FileClient;
@ -19,9 +23,12 @@ import com.iqser.red.service.peristence.v1.server.integration.service.DossierTes
import com.iqser.red.service.peristence.v1.server.integration.service.FileTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.peristence.v1.server.service.download.DownloadReportMessageReceiver;
import com.iqser.red.service.peristence.v1.server.service.download.RedactionResultMessageReceiver;
import com.iqser.red.service.persistence.management.v1.processor.utils.multitenancy.TenantContext;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplateUploadRequest;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.CreateOrUpdateDossierRequest;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.WorkflowStatus;
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadWithOptionRequest;
import com.iqser.red.service.redaction.report.v1.api.model.ReportResultMessage;
@ -35,6 +42,9 @@ public class DownloadPreparationTest extends AbstractPersistenceServerServiceTes
@Autowired
private DownloadReportMessageReceiver downloadReportMessageReceiver;
@Autowired
private RedactionResultMessageReceiver redactionResultMessageReceiver;
@Autowired
private StorageService storageService;
@ -60,10 +70,19 @@ public class DownloadPreparationTest extends AbstractPersistenceServerServiceTes
private FileClient fileClient;
@Before
public void before() {
TenantContext.setTenantId("redaction");
}
@Test
@SneakyThrows
public void testReceiveDownloadPackage() {
String userId = "1";
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
var dossier = dossierTesterAndProvider.provideTestDossier(dossierTemplate);
@ -102,34 +121,50 @@ public class DownloadPreparationTest extends AbstractPersistenceServerServiceTes
assertThat(updatedDossier.getReportTemplateIds()).isNotEmpty();
downloadClient.prepareDownload(DownloadWithOptionRequest.builder()
.userId("1")
.userId(userId)
.dossierId(dossier.getId())
.fileIds(Collections.singletonList(file.getId()))
.redactionPreviewColor("#aaaaaa")
.build());
var statuses = downloadClient.getDownloadStatus("1");
var statuses = downloadClient.getDownloadStatus(userId);
assertThat(statuses).isNotEmpty();
assertThat(statuses.iterator().next().getLastDownload()).isNull();
// FIXME Check if this is still needed.
// This variable seems to do nothing, if it is not needed it can be removed.
String downloadId = statuses.iterator().next().getStorageId();
addStoredFileInformationToStorage(file, availableTemplates, downloadId);
ReportResultMessage reportResultMessage = new ReportResultMessage();
reportResultMessage.setUserId(userId);
reportResultMessage.setDownloadId(downloadId);
downloadReportMessageReceiver.receive(reportResultMessage);
redactionResultMessageReceiver.receive(RedactionResultMessage.builder()
.downloadId(downloadId)
.dossierId(dossier.getId())
.redactionResultDetails(Collections.emptyList())
.build());
}
@SneakyThrows
private void addStoredFileInformationToStorage(FileModel file, List<ReportTemplate> availableTemplates, String downloadId) {
var storedFileInformationstorageId = downloadId.substring(0, downloadId.length() - 3) + "/REPORT_INFO.json";
String reportStorageId = "XYZ";
var sivList = new ArrayList<StoredFileInformation>();
var siv = new StoredFileInformation();
siv.setFileId(file.getId());
siv.setStorageId("XYZ");
siv.setStorageId(reportStorageId);
siv.setTemplateId(availableTemplates.iterator().next().getTemplateId());
sivList.add(siv);
// FIXME Check if this is still needed.
storageService.storeObject("XYZ", new ByteArrayInputStream(new byte[]{1, 2, 3, 4}));
ReportResultMessage reportResultMessage = new ReportResultMessage();
reportResultMessage.setUserId("1");
reportResultMessage.setDownloadId(statuses.iterator().next().getStorageId());
downloadReportMessageReceiver.receive(reportResultMessage);
storageService.storeObject(storedFileInformationstorageId, new ByteArrayInputStream(new ObjectMapper().writeValueAsBytes(sivList)));
storageService.storeObject(reportStorageId, new ByteArrayInputStream(new byte[]{1, 2, 3, 4}));
}
}