@Test @RunWithCustomExecutor public void givenInputEndDateBeforeFileDateThenCheckNbFilesPutInWorkspace() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); initMocksForAccessLog(); ObjectNode params = JsonHandler.createObjectNode(); params.set("EndDate", new TextNode("2018-08-10T12:00:00.000Z")); accessModuleImpl.getAccessLog(params); verify(workspaceClient, times(2)).putObject(any(), any(), any()); }
@Override public Response getAccessLog(JsonNode params) throws AccessInternalExecutionException, StorageNotFoundException, ParseException { Date startDate = null; JsonNode startNode = params.get("StartDate"); if (startNode != null) { String startString = startNode.textValue(); if (startString != null) { startDate = LocalDateUtil.getDate(startString); } } Date endDate = null; JsonNode endNode = params.get("EndDate"); if (endNode != null) { String endString = endNode.textValue(); if (endString != null) { endDate = LocalDateUtil.getDate(endString); } } String containerName = DataCategory.STORAGEACCESSLOG.getCollectionName() + "_" + VitamThreadUtils.getVitamSession().getRequestId(); String outFileName = "accessLog"; if (startDate != null) { outFileName += "_" + LocalDateUtil.getFormattedSimpleDate(startDate); } if (endDate != null) { outFileName += "-" + LocalDateUtil.getFormattedSimpleDate(endDate); } outFileName += ".zip"; try (StorageClient storageClient = storageClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); CloseableIterator<ObjectEntry> filesInfo = storageClient.listContainer(VitamConfiguration.getDefaultStrategy(), DataCategory.STORAGEACCESSLOG); ) { if (filesInfo.hasNext()) { workspaceClient.createContainer(containerName); } List<String> fileNames = new ArrayList<>(); while (filesInfo.hasNext()) { String fileName = filesInfo.next().getObjectId(); if (!AccessLogUtils.checkFileInRequestedDates(fileName, startDate, endDate)) { continue; } Response fileResponse = getAccessLogFile(fileName); InputStream stream = (InputStream) fileResponse.getEntity(); workspaceClient.putObject(containerName, fileName, stream); fileNames.add(fileName); } zipWorkspace(workspaceClient, outFileName, containerName, fileNames); Response response = workspaceClient.getObject(containerName, outFileName); StreamingOutput so = new WorkspaceAutoCleanableStreamingOutput((InputStream) response.getEntity(), workspaceClient, containerName); return Response.ok(so).build(); } catch (final StorageServerClientException | ContentAddressableStorageException e) { throw new AccessInternalExecutionException(e); } }
AccessInternalModuleImpl implements AccessInternalModule { @Override public Response getAccessLog(JsonNode params) throws AccessInternalExecutionException, StorageNotFoundException, ParseException { Date startDate = null; JsonNode startNode = params.get("StartDate"); if (startNode != null) { String startString = startNode.textValue(); if (startString != null) { startDate = LocalDateUtil.getDate(startString); } } Date endDate = null; JsonNode endNode = params.get("EndDate"); if (endNode != null) { String endString = endNode.textValue(); if (endString != null) { endDate = LocalDateUtil.getDate(endString); } } String containerName = DataCategory.STORAGEACCESSLOG.getCollectionName() + "_" + VitamThreadUtils.getVitamSession().getRequestId(); String outFileName = "accessLog"; if (startDate != null) { outFileName += "_" + LocalDateUtil.getFormattedSimpleDate(startDate); } if (endDate != null) { outFileName += "-" + LocalDateUtil.getFormattedSimpleDate(endDate); } outFileName += ".zip"; try (StorageClient storageClient = storageClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); CloseableIterator<ObjectEntry> filesInfo = storageClient.listContainer(VitamConfiguration.getDefaultStrategy(), DataCategory.STORAGEACCESSLOG); ) { if (filesInfo.hasNext()) { workspaceClient.createContainer(containerName); } List<String> fileNames = new ArrayList<>(); while (filesInfo.hasNext()) { String fileName = filesInfo.next().getObjectId(); if (!AccessLogUtils.checkFileInRequestedDates(fileName, startDate, endDate)) { continue; } Response fileResponse = getAccessLogFile(fileName); InputStream stream = (InputStream) fileResponse.getEntity(); workspaceClient.putObject(containerName, fileName, stream); fileNames.add(fileName); } zipWorkspace(workspaceClient, outFileName, containerName, fileNames); Response response = workspaceClient.getObject(containerName, outFileName); StreamingOutput so = new WorkspaceAutoCleanableStreamingOutput((InputStream) response.getEntity(), workspaceClient, containerName); return Response.ok(so).build(); } catch (final StorageServerClientException | ContentAddressableStorageException e) { throw new AccessInternalExecutionException(e); } } }
AccessInternalModuleImpl implements AccessInternalModule { @Override public Response getAccessLog(JsonNode params) throws AccessInternalExecutionException, StorageNotFoundException, ParseException { Date startDate = null; JsonNode startNode = params.get("StartDate"); if (startNode != null) { String startString = startNode.textValue(); if (startString != null) { startDate = LocalDateUtil.getDate(startString); } } Date endDate = null; JsonNode endNode = params.get("EndDate"); if (endNode != null) { String endString = endNode.textValue(); if (endString != null) { endDate = LocalDateUtil.getDate(endString); } } String containerName = DataCategory.STORAGEACCESSLOG.getCollectionName() + "_" + VitamThreadUtils.getVitamSession().getRequestId(); String outFileName = "accessLog"; if (startDate != null) { outFileName += "_" + LocalDateUtil.getFormattedSimpleDate(startDate); } if (endDate != null) { outFileName += "-" + LocalDateUtil.getFormattedSimpleDate(endDate); } outFileName += ".zip"; try (StorageClient storageClient = storageClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); CloseableIterator<ObjectEntry> filesInfo = storageClient.listContainer(VitamConfiguration.getDefaultStrategy(), DataCategory.STORAGEACCESSLOG); ) { if (filesInfo.hasNext()) { workspaceClient.createContainer(containerName); } List<String> fileNames = new ArrayList<>(); while (filesInfo.hasNext()) { String fileName = filesInfo.next().getObjectId(); if (!AccessLogUtils.checkFileInRequestedDates(fileName, startDate, endDate)) { continue; } Response fileResponse = getAccessLogFile(fileName); InputStream stream = (InputStream) fileResponse.getEntity(); workspaceClient.putObject(containerName, fileName, stream); fileNames.add(fileName); } zipWorkspace(workspaceClient, outFileName, containerName, fileNames); Response response = workspaceClient.getObject(containerName, outFileName); StreamingOutput so = new WorkspaceAutoCleanableStreamingOutput((InputStream) response.getEntity(), workspaceClient, containerName); return Response.ok(so).build(); } catch (final StorageServerClientException | ContentAddressableStorageException 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 getAccessLog(JsonNode params) throws AccessInternalExecutionException, StorageNotFoundException, ParseException { Date startDate = null; JsonNode startNode = params.get("StartDate"); if (startNode != null) { String startString = startNode.textValue(); if (startString != null) { startDate = LocalDateUtil.getDate(startString); } } Date endDate = null; JsonNode endNode = params.get("EndDate"); if (endNode != null) { String endString = endNode.textValue(); if (endString != null) { endDate = LocalDateUtil.getDate(endString); } } String containerName = DataCategory.STORAGEACCESSLOG.getCollectionName() + "_" + VitamThreadUtils.getVitamSession().getRequestId(); String outFileName = "accessLog"; if (startDate != null) { outFileName += "_" + LocalDateUtil.getFormattedSimpleDate(startDate); } if (endDate != null) { outFileName += "-" + LocalDateUtil.getFormattedSimpleDate(endDate); } outFileName += ".zip"; try (StorageClient storageClient = storageClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); CloseableIterator<ObjectEntry> filesInfo = storageClient.listContainer(VitamConfiguration.getDefaultStrategy(), DataCategory.STORAGEACCESSLOG); ) { if (filesInfo.hasNext()) { workspaceClient.createContainer(containerName); } List<String> fileNames = new ArrayList<>(); while (filesInfo.hasNext()) { String fileName = filesInfo.next().getObjectId(); if (!AccessLogUtils.checkFileInRequestedDates(fileName, startDate, endDate)) { continue; } Response fileResponse = getAccessLogFile(fileName); InputStream stream = (InputStream) fileResponse.getEntity(); workspaceClient.putObject(containerName, fileName, stream); fileNames.add(fileName); } zipWorkspace(workspaceClient, outFileName, containerName, fileNames); Response response = workspaceClient.getObject(containerName, outFileName); StreamingOutput so = new WorkspaceAutoCleanableStreamingOutput((InputStream) response.getEntity(), workspaceClient, containerName); return Response.ok(so).build(); } catch (final StorageServerClientException | ContentAddressableStorageException 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 getAccessLog(JsonNode params) throws AccessInternalExecutionException, StorageNotFoundException, ParseException { Date startDate = null; JsonNode startNode = params.get("StartDate"); if (startNode != null) { String startString = startNode.textValue(); if (startString != null) { startDate = LocalDateUtil.getDate(startString); } } Date endDate = null; JsonNode endNode = params.get("EndDate"); if (endNode != null) { String endString = endNode.textValue(); if (endString != null) { endDate = LocalDateUtil.getDate(endString); } } String containerName = DataCategory.STORAGEACCESSLOG.getCollectionName() + "_" + VitamThreadUtils.getVitamSession().getRequestId(); String outFileName = "accessLog"; if (startDate != null) { outFileName += "_" + LocalDateUtil.getFormattedSimpleDate(startDate); } if (endDate != null) { outFileName += "-" + LocalDateUtil.getFormattedSimpleDate(endDate); } outFileName += ".zip"; try (StorageClient storageClient = storageClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); CloseableIterator<ObjectEntry> filesInfo = storageClient.listContainer(VitamConfiguration.getDefaultStrategy(), DataCategory.STORAGEACCESSLOG); ) { if (filesInfo.hasNext()) { workspaceClient.createContainer(containerName); } List<String> fileNames = new ArrayList<>(); while (filesInfo.hasNext()) { String fileName = filesInfo.next().getObjectId(); if (!AccessLogUtils.checkFileInRequestedDates(fileName, startDate, endDate)) { continue; } Response fileResponse = getAccessLogFile(fileName); InputStream stream = (InputStream) fileResponse.getEntity(); workspaceClient.putObject(containerName, fileName, stream); fileNames.add(fileName); } zipWorkspace(workspaceClient, outFileName, containerName, fileNames); Response response = workspaceClient.getObject(containerName, outFileName); StreamingOutput so = new WorkspaceAutoCleanableStreamingOutput((InputStream) response.getEntity(), workspaceClient, containerName); return Response.ok(so).build(); } catch (final StorageServerClientException | ContentAddressableStorageException 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);  }