@Test @RunWithCustomExecutor public void testSuccessGetObjectAsInputStream() throws Exception { when(accessExternalClient.getObjectStreamByUnitId( any(), eq(ID_OBJECT_GROUP), eq("usage"), eq(1))) .thenReturn(new AbstractMockClient.FakeInboundResponse(Status.OK, StreamUtils.toInputStream("Vitam Test"), MediaType.APPLICATION_OCTET_STREAM_TYPE, null)); assertTrue(userInterfaceTransactionManager.getObjectAsInputStream(asynResponse, ID_OBJECT_GROUP, "usage", 1, "vitam_test", context, null)); }
public boolean getObjectAsInputStream(AsyncResponse asyncResponse, String unitId, String usage, int version, String filename, VitamContext context, List<MediaType> allowedMediaTypes) throws UnsupportedEncodingException, VitamClientException { Response response = null; String downloadMethod = "attachment"; try (AccessExternalClient client = accessExternalClientFactory.getClient()) { response = client.getObjectStreamByUnitId( context, unitId, usage, version); final AsyncInputStreamHelper helper = new AsyncInputStreamHelper(asyncResponse, response); if (isAllowedToVisualize(allowedMediaTypes, response.getMediaType())) { downloadMethod = "inline"; } final Response.ResponseBuilder responseBuilder = Response.status(response.getStatus()) .header(GlobalDataRest.X_QUALIFIER, response.getHeaderString(GlobalDataRest.X_QUALIFIER)) .header(GlobalDataRest.X_VERSION, response.getHeaderString(GlobalDataRest.X_VERSION)) .header("Content-Disposition", downloadMethod + "; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"") .type(response.getMediaType()); helper.writeResponse(responseBuilder); } finally { if (response != null && response.getStatus() != Response.Status.OK.getStatusCode()) { try { if (response.hasEntity()) { final Object object = response.getEntity(); if (object instanceof InputStream) { StreamUtils.closeSilently((InputStream) object); } } } catch (final IllegalStateException | ProcessingException e) { LOGGER.debug(e); } finally { response.close(); } } } return true; }
UserInterfaceTransactionManager { public boolean getObjectAsInputStream(AsyncResponse asyncResponse, String unitId, String usage, int version, String filename, VitamContext context, List<MediaType> allowedMediaTypes) throws UnsupportedEncodingException, VitamClientException { Response response = null; String downloadMethod = "attachment"; try (AccessExternalClient client = accessExternalClientFactory.getClient()) { response = client.getObjectStreamByUnitId( context, unitId, usage, version); final AsyncInputStreamHelper helper = new AsyncInputStreamHelper(asyncResponse, response); if (isAllowedToVisualize(allowedMediaTypes, response.getMediaType())) { downloadMethod = "inline"; } final Response.ResponseBuilder responseBuilder = Response.status(response.getStatus()) .header(GlobalDataRest.X_QUALIFIER, response.getHeaderString(GlobalDataRest.X_QUALIFIER)) .header(GlobalDataRest.X_VERSION, response.getHeaderString(GlobalDataRest.X_VERSION)) .header("Content-Disposition", downloadMethod + "; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"") .type(response.getMediaType()); helper.writeResponse(responseBuilder); } finally { if (response != null && response.getStatus() != Response.Status.OK.getStatusCode()) { try { if (response.hasEntity()) { final Object object = response.getEntity(); if (object instanceof InputStream) { StreamUtils.closeSilently((InputStream) object); } } } catch (final IllegalStateException | ProcessingException e) { LOGGER.debug(e); } finally { response.close(); } } } return true; } }
UserInterfaceTransactionManager { public boolean getObjectAsInputStream(AsyncResponse asyncResponse, String unitId, String usage, int version, String filename, VitamContext context, List<MediaType> allowedMediaTypes) throws UnsupportedEncodingException, VitamClientException { Response response = null; String downloadMethod = "attachment"; try (AccessExternalClient client = accessExternalClientFactory.getClient()) { response = client.getObjectStreamByUnitId( context, unitId, usage, version); final AsyncInputStreamHelper helper = new AsyncInputStreamHelper(asyncResponse, response); if (isAllowedToVisualize(allowedMediaTypes, response.getMediaType())) { downloadMethod = "inline"; } final Response.ResponseBuilder responseBuilder = Response.status(response.getStatus()) .header(GlobalDataRest.X_QUALIFIER, response.getHeaderString(GlobalDataRest.X_QUALIFIER)) .header(GlobalDataRest.X_VERSION, response.getHeaderString(GlobalDataRest.X_VERSION)) .header("Content-Disposition", downloadMethod + "; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"") .type(response.getMediaType()); helper.writeResponse(responseBuilder); } finally { if (response != null && response.getStatus() != Response.Status.OK.getStatusCode()) { try { if (response.hasEntity()) { final Object object = response.getEntity(); if (object instanceof InputStream) { StreamUtils.closeSilently((InputStream) object); } } } catch (final IllegalStateException | ProcessingException e) { LOGGER.debug(e); } finally { response.close(); } } } return true; } UserInterfaceTransactionManager(); @VisibleForTesting  UserInterfaceTransactionManager(
        AccessExternalClientFactory accessExternalClientFactory,
        AdminExternalClientFactory adminExternalClientFactory,
        AccessExternalClientV2Factory accessExternalClientV2Factory,
        DslQueryHelper dslQueryHelper); }
UserInterfaceTransactionManager { public boolean getObjectAsInputStream(AsyncResponse asyncResponse, String unitId, String usage, int version, String filename, VitamContext context, List<MediaType> allowedMediaTypes) throws UnsupportedEncodingException, VitamClientException { Response response = null; String downloadMethod = "attachment"; try (AccessExternalClient client = accessExternalClientFactory.getClient()) { response = client.getObjectStreamByUnitId( context, unitId, usage, version); final AsyncInputStreamHelper helper = new AsyncInputStreamHelper(asyncResponse, response); if (isAllowedToVisualize(allowedMediaTypes, response.getMediaType())) { downloadMethod = "inline"; } final Response.ResponseBuilder responseBuilder = Response.status(response.getStatus()) .header(GlobalDataRest.X_QUALIFIER, response.getHeaderString(GlobalDataRest.X_QUALIFIER)) .header(GlobalDataRest.X_VERSION, response.getHeaderString(GlobalDataRest.X_VERSION)) .header("Content-Disposition", downloadMethod + "; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"") .type(response.getMediaType()); helper.writeResponse(responseBuilder); } finally { if (response != null && response.getStatus() != Response.Status.OK.getStatusCode()) { try { if (response.hasEntity()) { final Object object = response.getEntity(); if (object instanceof InputStream) { StreamUtils.closeSilently((InputStream) object); } } } catch (final IllegalStateException | ProcessingException e) { LOGGER.debug(e); } finally { response.close(); } } } return true; } UserInterfaceTransactionManager(); @VisibleForTesting  UserInterfaceTransactionManager(
        AccessExternalClientFactory accessExternalClientFactory,
        AdminExternalClientFactory adminExternalClientFactory,
        AccessExternalClientV2Factory accessExternalClientV2Factory,
        DslQueryHelper dslQueryHelper); static UserInterfaceTransactionManager getInstance(); RequestResponse<JsonNode> searchUnits(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> searchObjects(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> getArchiveUnitDetails(JsonNode preparedDslQuery, String unitId,
        VitamContext context); RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode preparedDslQuery,
        VitamContext context); RequestResponse<JsonNode> startEliminationAnalysis(EliminationRequestBody parameters,
        VitamContext context); RequestResponse<JsonNode> startEliminationAction(EliminationRequestBody parameters,
        VitamContext context); RequestResponse<JsonNode> massiveUnitsUpdate(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> computinheritedrules(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> deleteComputedInheritedRules(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> massiveRulesUpdate(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> updateUnits(JsonNode parameters, String unitId, VitamContext context); RequestResponse<JsonNode> selectObjectbyId(JsonNode preparedDslQuery, String objectId,
        VitamContext context); boolean getObjectAsInputStream(AsyncResponse asyncResponse,
        String unitId, String usage, int version, String filename, VitamContext context,
        List<MediaType> allowedMediaTypes); RequestResponse<LogbookLifecycle> selectUnitLifeCycleById(String unitLifeCycleId,
        VitamContext context); RequestResponse<LogbookOperation> selectOperation(JsonNode query, VitamContext context); RequestResponse<LogbookOperation> selectOperationbyId(String operationId, VitamContext context); RequestResponse<LogbookLifecycle> selectObjectGroupLifeCycleById(String objectGroupLifeCycleId,
        VitamContext context); RequestResponse<AccessionRegisterSummaryModel> findAccessionRegisterSummary(String options,
        VitamContext context); RequestResponse<AccessionRegisterSymbolicModel> findAccessionRegisterSymbolic(String options,
        VitamContext context); RequestResponse<JsonNode> findAccessionRegisterDetail(String originatingAgency, String options, VitamContext context); RequestResponse<JsonNode> checkTraceabilityOperation(JsonNode query, VitamContext context); JsonNode extractInformationFromTimestamp(String timestamp); RequestResponse evidenceAudit(JsonNode query, VitamContext context); RequestResponse exportProbativeValue(ProbativeValueRequest request, VitamContext context); RequestResponse<JsonNode> exportDIP(DipRequest dipRequest, VitamContext context); RequestResponse<JsonNode> transferSIP(TransferRequest transferRequest, VitamContext context); boolean downloadExports(AsyncResponse asyncResponse, String exportId, VitamContext context, boolean isTransfer); VitamContext getVitamContext(HttpServletRequest request); VitamContext getVitamContext(Integer tenantId, String contractId, String personalCert); VitamContext getVitamContext(Integer tenantId, String contractId, HttpServletRequest request); String getPersonalCertificate(HttpServletRequest request); String getContractId(HttpServletRequest request); Integer getTenantId(HttpServletRequest request); String getAppSessionId(); }
UserInterfaceTransactionManager { public boolean getObjectAsInputStream(AsyncResponse asyncResponse, String unitId, String usage, int version, String filename, VitamContext context, List<MediaType> allowedMediaTypes) throws UnsupportedEncodingException, VitamClientException { Response response = null; String downloadMethod = "attachment"; try (AccessExternalClient client = accessExternalClientFactory.getClient()) { response = client.getObjectStreamByUnitId( context, unitId, usage, version); final AsyncInputStreamHelper helper = new AsyncInputStreamHelper(asyncResponse, response); if (isAllowedToVisualize(allowedMediaTypes, response.getMediaType())) { downloadMethod = "inline"; } final Response.ResponseBuilder responseBuilder = Response.status(response.getStatus()) .header(GlobalDataRest.X_QUALIFIER, response.getHeaderString(GlobalDataRest.X_QUALIFIER)) .header(GlobalDataRest.X_VERSION, response.getHeaderString(GlobalDataRest.X_VERSION)) .header("Content-Disposition", downloadMethod + "; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"") .type(response.getMediaType()); helper.writeResponse(responseBuilder); } finally { if (response != null && response.getStatus() != Response.Status.OK.getStatusCode()) { try { if (response.hasEntity()) { final Object object = response.getEntity(); if (object instanceof InputStream) { StreamUtils.closeSilently((InputStream) object); } } } catch (final IllegalStateException | ProcessingException e) { LOGGER.debug(e); } finally { response.close(); } } } return true; } UserInterfaceTransactionManager(); @VisibleForTesting  UserInterfaceTransactionManager(
        AccessExternalClientFactory accessExternalClientFactory,
        AdminExternalClientFactory adminExternalClientFactory,
        AccessExternalClientV2Factory accessExternalClientV2Factory,
        DslQueryHelper dslQueryHelper); static UserInterfaceTransactionManager getInstance(); RequestResponse<JsonNode> searchUnits(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> searchObjects(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> getArchiveUnitDetails(JsonNode preparedDslQuery, String unitId,
        VitamContext context); RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode preparedDslQuery,
        VitamContext context); RequestResponse<JsonNode> startEliminationAnalysis(EliminationRequestBody parameters,
        VitamContext context); RequestResponse<JsonNode> startEliminationAction(EliminationRequestBody parameters,
        VitamContext context); RequestResponse<JsonNode> massiveUnitsUpdate(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> computinheritedrules(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> deleteComputedInheritedRules(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> massiveRulesUpdate(JsonNode parameters, VitamContext context); RequestResponse<JsonNode> updateUnits(JsonNode parameters, String unitId, VitamContext context); RequestResponse<JsonNode> selectObjectbyId(JsonNode preparedDslQuery, String objectId,
        VitamContext context); boolean getObjectAsInputStream(AsyncResponse asyncResponse,
        String unitId, String usage, int version, String filename, VitamContext context,
        List<MediaType> allowedMediaTypes); RequestResponse<LogbookLifecycle> selectUnitLifeCycleById(String unitLifeCycleId,
        VitamContext context); RequestResponse<LogbookOperation> selectOperation(JsonNode query, VitamContext context); RequestResponse<LogbookOperation> selectOperationbyId(String operationId, VitamContext context); RequestResponse<LogbookLifecycle> selectObjectGroupLifeCycleById(String objectGroupLifeCycleId,
        VitamContext context); RequestResponse<AccessionRegisterSummaryModel> findAccessionRegisterSummary(String options,
        VitamContext context); RequestResponse<AccessionRegisterSymbolicModel> findAccessionRegisterSymbolic(String options,
        VitamContext context); RequestResponse<JsonNode> findAccessionRegisterDetail(String originatingAgency, String options, VitamContext context); RequestResponse<JsonNode> checkTraceabilityOperation(JsonNode query, VitamContext context); JsonNode extractInformationFromTimestamp(String timestamp); RequestResponse evidenceAudit(JsonNode query, VitamContext context); RequestResponse exportProbativeValue(ProbativeValueRequest request, VitamContext context); RequestResponse<JsonNode> exportDIP(DipRequest dipRequest, VitamContext context); RequestResponse<JsonNode> transferSIP(TransferRequest transferRequest, VitamContext context); boolean downloadExports(AsyncResponse asyncResponse, String exportId, VitamContext context, boolean isTransfer); VitamContext getVitamContext(HttpServletRequest request); VitamContext getVitamContext(Integer tenantId, String contractId, String personalCert); VitamContext getVitamContext(Integer tenantId, String contractId, HttpServletRequest request); String getPersonalCertificate(HttpServletRequest request); String getContractId(HttpServletRequest request); Integer getTenantId(HttpServletRequest request); String getAppSessionId();  }