Unverified Commit 392f2d55 authored by Zerouali's avatar Zerouali Committed by GitHub
Browse files

correct download report issue (#559)

parent 692db820
......@@ -82,6 +82,7 @@ public class LogbookService {
private static final String BATCH_REPORT = "batchreport";
private static final String RULE_REPORT = "report";
private static final String OBJECT_REPORT = "object";
private static final String MASTER_DATA = "MASTERDATA";
private final AccessExternalClient accessExternalClient;
......@@ -217,8 +218,9 @@ public class LogbookService {
if (operation == null || operation.getResults() == null || operation.getResults().size() == 0) {
throw new IllegalArgumentException("Unable to download object of operation " + id + ": the operation does not exist");
}
if (!INGEST_TYPE.equals(operation.getResults().get(0).getEvTypeProc())) {
throw new IllegalArgumentException("Unable to download object of operation " + id + ": the operation is not an ingest one");
if (!INGEST_TYPE.equals(operation.getResults().get(0).getEvTypeProc()) &&
!MASTER_DATA.equals(operation.getResults().get(0).getEvTypeProc())) {
throw new IllegalArgumentException("Unable to download object of operation " + id + ": the operation is not an ingest or master data one");
}
final Response response = ingestExternalClient.downloadObjectAsync(vitamContext, id, collection);
......
......@@ -32,6 +32,14 @@ import static org.mockito.Mockito.spy;
@RunWith(MockitoJUnitRunner.class)
public class LogbookServiceTest {
public static final String MASTER_DATA = "MASTERDATA";
public static final String INGEST = "INGEST";
public static final String DIP_EXPORT = "DIP_EXPORT";
public static final String OTHER = "OTHER";
private LogbookService logbookService;
private AccessExternalClient accessExternalClient;
......@@ -54,7 +62,7 @@ public class LogbookServiceTest {
public void testDownloadManifest_whenIngestOperation() throws VitamClientException {
logbookService = spy(logbookService);
final LogbookOperation operation = new LogbookOperation();
operation.setEvTypeProc("INGEST");
operation.setEvTypeProc(INGEST);
final RequestResponseOK<LogbookOperation> operationResponse = new RequestResponseOK<>();
operationResponse.addResult(operation);
Mockito.when(logbookService.selectOperationbyId(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(operationResponse);
......@@ -67,7 +75,7 @@ public class LogbookServiceTest {
public void testDownloadAtr_whenIngestOperation() throws VitamClientException {
logbookService = spy(logbookService);
final LogbookOperation operation = new LogbookOperation();
operation.setEvTypeProc("INGEST");
operation.setEvTypeProc(INGEST);
final RequestResponseOK<LogbookOperation> operationResponse = new RequestResponseOK<>();
operationResponse.addResult(operation);
Mockito.when(logbookService.selectOperationbyId(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(operationResponse);
......@@ -80,7 +88,7 @@ public class LogbookServiceTest {
public void testDownloadAtr_whenNotIngestOperation() throws VitamClientException {
logbookService = spy(logbookService);
final LogbookOperation operation = new LogbookOperation();
operation.setEvTypeProc("OTHER");
operation.setEvTypeProc(OTHER);
final RequestResponseOK<LogbookOperation> operationResponse = new RequestResponseOK<>();
operationResponse.addResult(operation);
Mockito.when(logbookService.selectOperationbyId(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(operationResponse);
......@@ -109,7 +117,7 @@ public class LogbookServiceTest {
public void testDownloadDip_whenExportIsSuccess() throws Exception {
logbookService = spy(logbookService);
final LogbookOperation operation = new LogbookOperation();
operation.setEvTypeProc("DIP_EXPORT");
operation.setEvTypeProc(DIP_EXPORT);
final Response response = logbookService.downloadReport("aeeaaaaaaggtywctaanl4al3q2moiyyaaaaq", "dip", new VitamContext(10));
VitamRestUtils.checkResponse(response, Response.Status.OK.getStatusCode());
......@@ -118,4 +126,17 @@ public class LogbookServiceTest {
Assertions.assertThat(reportContent).isEqualTo("test");
}
@Test
public void testDownloadAtr_whenMasterDataOperation() throws VitamClientException {
logbookService = spy(logbookService);
final LogbookOperation operation = new LogbookOperation();
operation.setEvTypeProc(MASTER_DATA);
final RequestResponseOK<LogbookOperation> operationResponse = new RequestResponseOK<>();
operationResponse.addResult(operation);
Mockito.when(logbookService.selectOperationbyId(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(operationResponse);
final Response response = logbookService.downloadAtr("vitamId", new VitamContext(10));
VitamRestUtils.checkResponse(response, Response.Status.OK.getStatusCode());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment