@Test @RunWithCustomExecutor public void testGetOneObjectFromObjectGroupRealData_WARN() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); setAccessLogInfoInVitamSession(); when(metaDataClient.selectObjectGrouptbyId(any(), any())) .thenReturn(JsonHandler.getFromFile(PropertiesUtils.getResourceFile(REAL_DATA_RESULT_MULTI_PATH))); final Response responseMock = mock(Response.class); when(responseMock.readEntity(InputStream.class)) .thenReturn(PropertiesUtils.getResourceAsStream(REAL_DATA_RESULT_MULTI_PATH)); when(storageClient.getContainerAsync(isNull(), any(), any(), any())) .thenReturn(responseMock); Response reponseFinal = accessModuleImpl.getOneObjectFromObjectGroup(ID, "Thumbnail", 0, "unit0"); assertNotNull(reponseFinal); InputStream entity = (InputStream) reponseFinal.getEntity(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); StreamUtils.copy(entity, output); byte[] src = output.toByteArray(); JsonNode jsonNode = JsonHandler.getFromBytes(src); assertNotNull(jsonNode); assertEquals("image/png", jsonNode.get("$results").get(0).get("#qualifiers").get(0).get("versions").get(0) .get("FormatIdentification").get("MimeType").asText()); assertEquals("Wrong name", jsonNode.get("$results").get(0).get("#qualifiers").get(0).get("versions").get(0) .get("FormatIdentification").get("Filename").asText()); }
@Override public Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit) throws StorageNotFoundException, AccessInternalExecutionException, MetaDataNotFoundException, InvalidParseOperationException { ParametersChecker.checkParameter("ObjectGroup id should be filled", idObjectGroup); ParametersChecker.checkParameter("You must specify a valid object qualifier", qualifier); Integer tenantId = ParameterHelper.getTenantParameter(); ParametersChecker.checkParameter("You must specify a valid tenant", tenantId); ParametersChecker.checkValue("version", version, 0); final SelectMultiQuery request = new SelectMultiQuery(); request.addRoots(idObjectGroup); request.setProjectionSliceOnQualifier("FormatIdentification", "FileInfo", "Size", "_storage"); final JsonNode jsonResponse = selectObjectGroupById(request.getFinalSelect(), idObjectGroup); if (jsonResponse == null) { throw new AccessInternalExecutionException("Null json response node from metadata"); } ObjectGroupResponse objectGroupResponse = JsonHandler.getFromJsonNode(jsonResponse.get(RESULTS), ObjectGroupResponse.class); VersionsModel finalversionsResponse = null; if (objectGroupResponse.getQualifiers() != null) { final String dataObjectVersion = qualifier + "_" + version; for (QualifiersModel qualifiersResponse : objectGroupResponse.getQualifiers()) { if (qualifiersResponse.getQualifier() != null && qualifiersResponse.getQualifier().contains("_")) { qualifiersResponse.setQualifier(qualifiersResponse .getQualifier().split("_")[0]); } if (qualifier.equals(qualifiersResponse.getQualifier())) { for (VersionsModel versionResponse : qualifiersResponse.getVersions()) { if (dataObjectVersion.equals(versionResponse.getDataObjectVersion())) { finalversionsResponse = versionResponse; break; } } } } } String strategyId = null; String mimetype = MediaType.APPLICATION_OCTET_STREAM; String filename = null; String objectId = null; Long size = null; if (finalversionsResponse != null) { if (finalversionsResponse.getFormatIdentification() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFormatIdentification().getMimeType())) { mimetype = finalversionsResponse.getFormatIdentification().getMimeType(); } if (finalversionsResponse.getFileInfoModel() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFileInfoModel().getFilename())) { filename = finalversionsResponse.getFileInfoModel().getFilename(); } objectId = finalversionsResponse.getId(); size = finalversionsResponse.getSize(); if (finalversionsResponse.getStorage() != null) { strategyId = finalversionsResponse.getStorage().getStrategyId(); } } if (Strings.isNullOrEmpty(filename)) { filename = objectId; } AccessLogInfoModel logInfo = AccessLogUtils.getInfoForAccessLog(qualifier, version, VitamThreadUtils.getVitamSession(), size, idUnit); try (StorageClient storageClient = storageClientFactory.getClient()) { final Response response = storageClient.getContainerAsync(strategyId, objectId, DataCategory.OBJECT, logInfo); Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, mimetype); headers.put(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\""); headers.put(GlobalDataRest.X_QUALIFIER, qualifier); headers.put(GlobalDataRest.X_VERSION, Integer.toString(version)); return new VitamAsyncInputStreamResponse(response, Status.OK, headers); } catch (final StorageServerClientException e) { throw new AccessInternalExecutionException(e); } }
AccessInternalModuleImpl implements AccessInternalModule { @Override public Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit) throws StorageNotFoundException, AccessInternalExecutionException, MetaDataNotFoundException, InvalidParseOperationException { ParametersChecker.checkParameter("ObjectGroup id should be filled", idObjectGroup); ParametersChecker.checkParameter("You must specify a valid object qualifier", qualifier); Integer tenantId = ParameterHelper.getTenantParameter(); ParametersChecker.checkParameter("You must specify a valid tenant", tenantId); ParametersChecker.checkValue("version", version, 0); final SelectMultiQuery request = new SelectMultiQuery(); request.addRoots(idObjectGroup); request.setProjectionSliceOnQualifier("FormatIdentification", "FileInfo", "Size", "_storage"); final JsonNode jsonResponse = selectObjectGroupById(request.getFinalSelect(), idObjectGroup); if (jsonResponse == null) { throw new AccessInternalExecutionException("Null json response node from metadata"); } ObjectGroupResponse objectGroupResponse = JsonHandler.getFromJsonNode(jsonResponse.get(RESULTS), ObjectGroupResponse.class); VersionsModel finalversionsResponse = null; if (objectGroupResponse.getQualifiers() != null) { final String dataObjectVersion = qualifier + "_" + version; for (QualifiersModel qualifiersResponse : objectGroupResponse.getQualifiers()) { if (qualifiersResponse.getQualifier() != null && qualifiersResponse.getQualifier().contains("_")) { qualifiersResponse.setQualifier(qualifiersResponse .getQualifier().split("_")[0]); } if (qualifier.equals(qualifiersResponse.getQualifier())) { for (VersionsModel versionResponse : qualifiersResponse.getVersions()) { if (dataObjectVersion.equals(versionResponse.getDataObjectVersion())) { finalversionsResponse = versionResponse; break; } } } } } String strategyId = null; String mimetype = MediaType.APPLICATION_OCTET_STREAM; String filename = null; String objectId = null; Long size = null; if (finalversionsResponse != null) { if (finalversionsResponse.getFormatIdentification() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFormatIdentification().getMimeType())) { mimetype = finalversionsResponse.getFormatIdentification().getMimeType(); } if (finalversionsResponse.getFileInfoModel() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFileInfoModel().getFilename())) { filename = finalversionsResponse.getFileInfoModel().getFilename(); } objectId = finalversionsResponse.getId(); size = finalversionsResponse.getSize(); if (finalversionsResponse.getStorage() != null) { strategyId = finalversionsResponse.getStorage().getStrategyId(); } } if (Strings.isNullOrEmpty(filename)) { filename = objectId; } AccessLogInfoModel logInfo = AccessLogUtils.getInfoForAccessLog(qualifier, version, VitamThreadUtils.getVitamSession(), size, idUnit); try (StorageClient storageClient = storageClientFactory.getClient()) { final Response response = storageClient.getContainerAsync(strategyId, objectId, DataCategory.OBJECT, logInfo); Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, mimetype); headers.put(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\""); headers.put(GlobalDataRest.X_QUALIFIER, qualifier); headers.put(GlobalDataRest.X_VERSION, Integer.toString(version)); return new VitamAsyncInputStreamResponse(response, Status.OK, headers); } catch (final StorageServerClientException e) { throw new AccessInternalExecutionException(e); } } }
AccessInternalModuleImpl implements AccessInternalModule { @Override public Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit) throws StorageNotFoundException, AccessInternalExecutionException, MetaDataNotFoundException, InvalidParseOperationException { ParametersChecker.checkParameter("ObjectGroup id should be filled", idObjectGroup); ParametersChecker.checkParameter("You must specify a valid object qualifier", qualifier); Integer tenantId = ParameterHelper.getTenantParameter(); ParametersChecker.checkParameter("You must specify a valid tenant", tenantId); ParametersChecker.checkValue("version", version, 0); final SelectMultiQuery request = new SelectMultiQuery(); request.addRoots(idObjectGroup); request.setProjectionSliceOnQualifier("FormatIdentification", "FileInfo", "Size", "_storage"); final JsonNode jsonResponse = selectObjectGroupById(request.getFinalSelect(), idObjectGroup); if (jsonResponse == null) { throw new AccessInternalExecutionException("Null json response node from metadata"); } ObjectGroupResponse objectGroupResponse = JsonHandler.getFromJsonNode(jsonResponse.get(RESULTS), ObjectGroupResponse.class); VersionsModel finalversionsResponse = null; if (objectGroupResponse.getQualifiers() != null) { final String dataObjectVersion = qualifier + "_" + version; for (QualifiersModel qualifiersResponse : objectGroupResponse.getQualifiers()) { if (qualifiersResponse.getQualifier() != null && qualifiersResponse.getQualifier().contains("_")) { qualifiersResponse.setQualifier(qualifiersResponse .getQualifier().split("_")[0]); } if (qualifier.equals(qualifiersResponse.getQualifier())) { for (VersionsModel versionResponse : qualifiersResponse.getVersions()) { if (dataObjectVersion.equals(versionResponse.getDataObjectVersion())) { finalversionsResponse = versionResponse; break; } } } } } String strategyId = null; String mimetype = MediaType.APPLICATION_OCTET_STREAM; String filename = null; String objectId = null; Long size = null; if (finalversionsResponse != null) { if (finalversionsResponse.getFormatIdentification() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFormatIdentification().getMimeType())) { mimetype = finalversionsResponse.getFormatIdentification().getMimeType(); } if (finalversionsResponse.getFileInfoModel() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFileInfoModel().getFilename())) { filename = finalversionsResponse.getFileInfoModel().getFilename(); } objectId = finalversionsResponse.getId(); size = finalversionsResponse.getSize(); if (finalversionsResponse.getStorage() != null) { strategyId = finalversionsResponse.getStorage().getStrategyId(); } } if (Strings.isNullOrEmpty(filename)) { filename = objectId; } AccessLogInfoModel logInfo = AccessLogUtils.getInfoForAccessLog(qualifier, version, VitamThreadUtils.getVitamSession(), size, idUnit); try (StorageClient storageClient = storageClientFactory.getClient()) { final Response response = storageClient.getContainerAsync(strategyId, objectId, DataCategory.OBJECT, logInfo); Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, mimetype); headers.put(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\""); headers.put(GlobalDataRest.X_QUALIFIER, qualifier); headers.put(GlobalDataRest.X_VERSION, Integer.toString(version)); return new VitamAsyncInputStreamResponse(response, Status.OK, headers); } catch (final StorageServerClientException e) { throw new AccessInternalExecutionException(e); } } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit) throws StorageNotFoundException, AccessInternalExecutionException, MetaDataNotFoundException, InvalidParseOperationException { ParametersChecker.checkParameter("ObjectGroup id should be filled", idObjectGroup); ParametersChecker.checkParameter("You must specify a valid object qualifier", qualifier); Integer tenantId = ParameterHelper.getTenantParameter(); ParametersChecker.checkParameter("You must specify a valid tenant", tenantId); ParametersChecker.checkValue("version", version, 0); final SelectMultiQuery request = new SelectMultiQuery(); request.addRoots(idObjectGroup); request.setProjectionSliceOnQualifier("FormatIdentification", "FileInfo", "Size", "_storage"); final JsonNode jsonResponse = selectObjectGroupById(request.getFinalSelect(), idObjectGroup); if (jsonResponse == null) { throw new AccessInternalExecutionException("Null json response node from metadata"); } ObjectGroupResponse objectGroupResponse = JsonHandler.getFromJsonNode(jsonResponse.get(RESULTS), ObjectGroupResponse.class); VersionsModel finalversionsResponse = null; if (objectGroupResponse.getQualifiers() != null) { final String dataObjectVersion = qualifier + "_" + version; for (QualifiersModel qualifiersResponse : objectGroupResponse.getQualifiers()) { if (qualifiersResponse.getQualifier() != null && qualifiersResponse.getQualifier().contains("_")) { qualifiersResponse.setQualifier(qualifiersResponse .getQualifier().split("_")[0]); } if (qualifier.equals(qualifiersResponse.getQualifier())) { for (VersionsModel versionResponse : qualifiersResponse.getVersions()) { if (dataObjectVersion.equals(versionResponse.getDataObjectVersion())) { finalversionsResponse = versionResponse; break; } } } } } String strategyId = null; String mimetype = MediaType.APPLICATION_OCTET_STREAM; String filename = null; String objectId = null; Long size = null; if (finalversionsResponse != null) { if (finalversionsResponse.getFormatIdentification() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFormatIdentification().getMimeType())) { mimetype = finalversionsResponse.getFormatIdentification().getMimeType(); } if (finalversionsResponse.getFileInfoModel() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFileInfoModel().getFilename())) { filename = finalversionsResponse.getFileInfoModel().getFilename(); } objectId = finalversionsResponse.getId(); size = finalversionsResponse.getSize(); if (finalversionsResponse.getStorage() != null) { strategyId = finalversionsResponse.getStorage().getStrategyId(); } } if (Strings.isNullOrEmpty(filename)) { filename = objectId; } AccessLogInfoModel logInfo = AccessLogUtils.getInfoForAccessLog(qualifier, version, VitamThreadUtils.getVitamSession(), size, idUnit); try (StorageClient storageClient = storageClientFactory.getClient()) { final Response response = storageClient.getContainerAsync(strategyId, objectId, DataCategory.OBJECT, logInfo); Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, mimetype); headers.put(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\""); headers.put(GlobalDataRest.X_QUALIFIER, qualifier); headers.put(GlobalDataRest.X_VERSION, Integer.toString(version)); return new VitamAsyncInputStreamResponse(response, Status.OK, headers); } catch (final StorageServerClientException e) { throw new AccessInternalExecutionException(e); } } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); @Override JsonNode selectUnit(JsonNode jsonQuery); @Override JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit); @Override JsonNode selectObjectGroupById(JsonNode jsonQuery, String idObjectGroup); @Override Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit); @Override Response getAccessLog(JsonNode params); void checkClassificationLevel(JsonNode query); @Override JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId); @Override Response findDIPByOperationId(String id); @Override Response findTransferSIPByOperationId(String id); @Override JsonNode selectObjects(JsonNode jsonQuery); @Override JsonNode selectUnitsWithInheritedRules(JsonNode jsonQuery); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit) throws StorageNotFoundException, AccessInternalExecutionException, MetaDataNotFoundException, InvalidParseOperationException { ParametersChecker.checkParameter("ObjectGroup id should be filled", idObjectGroup); ParametersChecker.checkParameter("You must specify a valid object qualifier", qualifier); Integer tenantId = ParameterHelper.getTenantParameter(); ParametersChecker.checkParameter("You must specify a valid tenant", tenantId); ParametersChecker.checkValue("version", version, 0); final SelectMultiQuery request = new SelectMultiQuery(); request.addRoots(idObjectGroup); request.setProjectionSliceOnQualifier("FormatIdentification", "FileInfo", "Size", "_storage"); final JsonNode jsonResponse = selectObjectGroupById(request.getFinalSelect(), idObjectGroup); if (jsonResponse == null) { throw new AccessInternalExecutionException("Null json response node from metadata"); } ObjectGroupResponse objectGroupResponse = JsonHandler.getFromJsonNode(jsonResponse.get(RESULTS), ObjectGroupResponse.class); VersionsModel finalversionsResponse = null; if (objectGroupResponse.getQualifiers() != null) { final String dataObjectVersion = qualifier + "_" + version; for (QualifiersModel qualifiersResponse : objectGroupResponse.getQualifiers()) { if (qualifiersResponse.getQualifier() != null && qualifiersResponse.getQualifier().contains("_")) { qualifiersResponse.setQualifier(qualifiersResponse .getQualifier().split("_")[0]); } if (qualifier.equals(qualifiersResponse.getQualifier())) { for (VersionsModel versionResponse : qualifiersResponse.getVersions()) { if (dataObjectVersion.equals(versionResponse.getDataObjectVersion())) { finalversionsResponse = versionResponse; break; } } } } } String strategyId = null; String mimetype = MediaType.APPLICATION_OCTET_STREAM; String filename = null; String objectId = null; Long size = null; if (finalversionsResponse != null) { if (finalversionsResponse.getFormatIdentification() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFormatIdentification().getMimeType())) { mimetype = finalversionsResponse.getFormatIdentification().getMimeType(); } if (finalversionsResponse.getFileInfoModel() != null && !Strings.isNullOrEmpty(finalversionsResponse.getFileInfoModel().getFilename())) { filename = finalversionsResponse.getFileInfoModel().getFilename(); } objectId = finalversionsResponse.getId(); size = finalversionsResponse.getSize(); if (finalversionsResponse.getStorage() != null) { strategyId = finalversionsResponse.getStorage().getStrategyId(); } } if (Strings.isNullOrEmpty(filename)) { filename = objectId; } AccessLogInfoModel logInfo = AccessLogUtils.getInfoForAccessLog(qualifier, version, VitamThreadUtils.getVitamSession(), size, idUnit); try (StorageClient storageClient = storageClientFactory.getClient()) { final Response response = storageClient.getContainerAsync(strategyId, objectId, DataCategory.OBJECT, logInfo); Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, mimetype); headers.put(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\""); headers.put(GlobalDataRest.X_QUALIFIER, qualifier); headers.put(GlobalDataRest.X_VERSION, Integer.toString(version)); return new VitamAsyncInputStreamResponse(response, Status.OK, headers); } catch (final StorageServerClientException e) { throw new AccessInternalExecutionException(e); } } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); @Override JsonNode selectUnit(JsonNode jsonQuery); @Override JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit); @Override JsonNode selectObjectGroupById(JsonNode jsonQuery, String idObjectGroup); @Override Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit); @Override Response getAccessLog(JsonNode params); void checkClassificationLevel(JsonNode query); @Override JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId); @Override Response findDIPByOperationId(String id); @Override Response findTransferSIPByOperationId(String id); @Override JsonNode selectObjects(JsonNode jsonQuery); @Override JsonNode selectUnitsWithInheritedRules(JsonNode jsonQuery);  }