@Test @RunWithCustomExecutor public void testPrepareTraceabilityOK() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); prepareTraceabilityCheckProcessActionHandler = new PrepareTraceabilityCheckProcessActionHandler(logbookOperationsClientFactory, storageClientFactory); action.addOutIOParameters(out); Mockito.doReturn(getTraceabilityDetails(SAMPLE_TRACEABILITY_FILENAME)).when(logbookOperationsClient) .selectOperation(any()); Mockito.doReturn(false).when(workspaceClient).isExistingContainer(any()); Mockito.doNothing().when(workspaceClient).createContainer(any()); Mockito.doNothing().when(workspaceClient).uncompressObject(any(), any(), any(), any()); Mockito.doReturn( new FakeInboundResponse(Status.OK, IOUtils.toInputStream("Fake Content", Charset.defaultCharset()), MediaType.APPLICATION_OCTET_STREAM_TYPE, null)) .when(storageClient) .getContainerAsync(any(), any(), any(), any()); final ItemStatus response = prepareTraceabilityCheckProcessActionHandler.execute(params, action); assertEquals(StatusCode.OK, response.getGlobalStatus()); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); LogbookOperation operationToCheck; try (LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient()) { RequestResponseOK requestResponseOK = RequestResponseOK.getFromJsonNode(logbookOperationsClient .selectOperation( JsonHandler.getFromString(param.getMapParameters().get(WorkerParameterName.logbookRequest)))); List<ObjectNode> foundOperation = requestResponseOK.getResults(); if (foundOperation == null || foundOperation.isEmpty() || foundOperation.size() > 1) { itemStatus.increment(StatusCode.KO); return itemStatus; } operationToCheck = new LogbookOperation(foundOperation.get(0)); String operationType = (String) operationToCheck.get(LogbookMongoDbName.eventTypeProcess.getDbname()); if (!LogbookTypeProcess.TRACEABILITY.equals(LogbookTypeProcess.valueOf(operationType))) { itemStatus.increment(StatusCode.KO); return itemStatus; } } catch (InvalidParseOperationException | LogbookClientException | IllegalArgumentException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); return itemStatus; } Response response = null; try (WorkspaceClient workspaceClient = handler.getWorkspaceClientFactory().getClient(); StorageClient storageClient = storageClientFactory.getClient()) { String evDetData = operationToCheck.getString(LogbookMongoDbName.eventDetailData.getDbname()); JsonNode eventDetail = JsonHandler.getFromString(evDetData); TraceabilityEvent traceabilityEvent = JsonHandler.getFromJsonNode(eventDetail, TraceabilityEvent.class); String fileName = traceabilityEvent.getFileName(); DataCategory dataCategory = getDataCategory(traceabilityEvent); response = storageClient.getContainerAsync(VitamConfiguration.getDefaultStrategy(), fileName, dataCategory, AccessLogUtils.getNoLogAccessLog()); if (workspaceClient.isExistingContainer(param.getContainerName())) { try { workspaceClient.deleteContainer(param.getContainerName(), true); LOGGER.warn("Container was already existing, step is being replayed"); } catch (ContentAddressableStorageNotFoundException e) { LOGGER.warn("The container could not be deleted", e); } } handler.unzipInputStreamOnWorkspace(param.getContainerName(), SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, CommonMediaType.ZIP, response.readEntity(InputStream.class), false); extractTraceabilityOperationDetails(handler, traceabilityEvent); itemStatus.increment(StatusCode.OK); } catch (StorageServerClientException | StorageNotFoundException | ContentAddressableStorageException | InvalidParseOperationException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }
PrepareTraceabilityCheckProcessActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); LogbookOperation operationToCheck; try (LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient()) { RequestResponseOK requestResponseOK = RequestResponseOK.getFromJsonNode(logbookOperationsClient .selectOperation( JsonHandler.getFromString(param.getMapParameters().get(WorkerParameterName.logbookRequest)))); List<ObjectNode> foundOperation = requestResponseOK.getResults(); if (foundOperation == null || foundOperation.isEmpty() || foundOperation.size() > 1) { itemStatus.increment(StatusCode.KO); return itemStatus; } operationToCheck = new LogbookOperation(foundOperation.get(0)); String operationType = (String) operationToCheck.get(LogbookMongoDbName.eventTypeProcess.getDbname()); if (!LogbookTypeProcess.TRACEABILITY.equals(LogbookTypeProcess.valueOf(operationType))) { itemStatus.increment(StatusCode.KO); return itemStatus; } } catch (InvalidParseOperationException | LogbookClientException | IllegalArgumentException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); return itemStatus; } Response response = null; try (WorkspaceClient workspaceClient = handler.getWorkspaceClientFactory().getClient(); StorageClient storageClient = storageClientFactory.getClient()) { String evDetData = operationToCheck.getString(LogbookMongoDbName.eventDetailData.getDbname()); JsonNode eventDetail = JsonHandler.getFromString(evDetData); TraceabilityEvent traceabilityEvent = JsonHandler.getFromJsonNode(eventDetail, TraceabilityEvent.class); String fileName = traceabilityEvent.getFileName(); DataCategory dataCategory = getDataCategory(traceabilityEvent); response = storageClient.getContainerAsync(VitamConfiguration.getDefaultStrategy(), fileName, dataCategory, AccessLogUtils.getNoLogAccessLog()); if (workspaceClient.isExistingContainer(param.getContainerName())) { try { workspaceClient.deleteContainer(param.getContainerName(), true); LOGGER.warn("Container was already existing, step is being replayed"); } catch (ContentAddressableStorageNotFoundException e) { LOGGER.warn("The container could not be deleted", e); } } handler.unzipInputStreamOnWorkspace(param.getContainerName(), SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, CommonMediaType.ZIP, response.readEntity(InputStream.class), false); extractTraceabilityOperationDetails(handler, traceabilityEvent); itemStatus.increment(StatusCode.OK); } catch (StorageServerClientException | StorageNotFoundException | ContentAddressableStorageException | InvalidParseOperationException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } }
PrepareTraceabilityCheckProcessActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); LogbookOperation operationToCheck; try (LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient()) { RequestResponseOK requestResponseOK = RequestResponseOK.getFromJsonNode(logbookOperationsClient .selectOperation( JsonHandler.getFromString(param.getMapParameters().get(WorkerParameterName.logbookRequest)))); List<ObjectNode> foundOperation = requestResponseOK.getResults(); if (foundOperation == null || foundOperation.isEmpty() || foundOperation.size() > 1) { itemStatus.increment(StatusCode.KO); return itemStatus; } operationToCheck = new LogbookOperation(foundOperation.get(0)); String operationType = (String) operationToCheck.get(LogbookMongoDbName.eventTypeProcess.getDbname()); if (!LogbookTypeProcess.TRACEABILITY.equals(LogbookTypeProcess.valueOf(operationType))) { itemStatus.increment(StatusCode.KO); return itemStatus; } } catch (InvalidParseOperationException | LogbookClientException | IllegalArgumentException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); return itemStatus; } Response response = null; try (WorkspaceClient workspaceClient = handler.getWorkspaceClientFactory().getClient(); StorageClient storageClient = storageClientFactory.getClient()) { String evDetData = operationToCheck.getString(LogbookMongoDbName.eventDetailData.getDbname()); JsonNode eventDetail = JsonHandler.getFromString(evDetData); TraceabilityEvent traceabilityEvent = JsonHandler.getFromJsonNode(eventDetail, TraceabilityEvent.class); String fileName = traceabilityEvent.getFileName(); DataCategory dataCategory = getDataCategory(traceabilityEvent); response = storageClient.getContainerAsync(VitamConfiguration.getDefaultStrategy(), fileName, dataCategory, AccessLogUtils.getNoLogAccessLog()); if (workspaceClient.isExistingContainer(param.getContainerName())) { try { workspaceClient.deleteContainer(param.getContainerName(), true); LOGGER.warn("Container was already existing, step is being replayed"); } catch (ContentAddressableStorageNotFoundException e) { LOGGER.warn("The container could not be deleted", e); } } handler.unzipInputStreamOnWorkspace(param.getContainerName(), SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, CommonMediaType.ZIP, response.readEntity(InputStream.class), false); extractTraceabilityOperationDetails(handler, traceabilityEvent); itemStatus.increment(StatusCode.OK); } catch (StorageServerClientException | StorageNotFoundException | ContentAddressableStorageException | InvalidParseOperationException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } PrepareTraceabilityCheckProcessActionHandler();  PrepareTraceabilityCheckProcessActionHandler(
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        StorageClientFactory storageClientFactory); }
PrepareTraceabilityCheckProcessActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); LogbookOperation operationToCheck; try (LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient()) { RequestResponseOK requestResponseOK = RequestResponseOK.getFromJsonNode(logbookOperationsClient .selectOperation( JsonHandler.getFromString(param.getMapParameters().get(WorkerParameterName.logbookRequest)))); List<ObjectNode> foundOperation = requestResponseOK.getResults(); if (foundOperation == null || foundOperation.isEmpty() || foundOperation.size() > 1) { itemStatus.increment(StatusCode.KO); return itemStatus; } operationToCheck = new LogbookOperation(foundOperation.get(0)); String operationType = (String) operationToCheck.get(LogbookMongoDbName.eventTypeProcess.getDbname()); if (!LogbookTypeProcess.TRACEABILITY.equals(LogbookTypeProcess.valueOf(operationType))) { itemStatus.increment(StatusCode.KO); return itemStatus; } } catch (InvalidParseOperationException | LogbookClientException | IllegalArgumentException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); return itemStatus; } Response response = null; try (WorkspaceClient workspaceClient = handler.getWorkspaceClientFactory().getClient(); StorageClient storageClient = storageClientFactory.getClient()) { String evDetData = operationToCheck.getString(LogbookMongoDbName.eventDetailData.getDbname()); JsonNode eventDetail = JsonHandler.getFromString(evDetData); TraceabilityEvent traceabilityEvent = JsonHandler.getFromJsonNode(eventDetail, TraceabilityEvent.class); String fileName = traceabilityEvent.getFileName(); DataCategory dataCategory = getDataCategory(traceabilityEvent); response = storageClient.getContainerAsync(VitamConfiguration.getDefaultStrategy(), fileName, dataCategory, AccessLogUtils.getNoLogAccessLog()); if (workspaceClient.isExistingContainer(param.getContainerName())) { try { workspaceClient.deleteContainer(param.getContainerName(), true); LOGGER.warn("Container was already existing, step is being replayed"); } catch (ContentAddressableStorageNotFoundException e) { LOGGER.warn("The container could not be deleted", e); } } handler.unzipInputStreamOnWorkspace(param.getContainerName(), SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, CommonMediaType.ZIP, response.readEntity(InputStream.class), false); extractTraceabilityOperationDetails(handler, traceabilityEvent); itemStatus.increment(StatusCode.OK); } catch (StorageServerClientException | StorageNotFoundException | ContentAddressableStorageException | InvalidParseOperationException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } PrepareTraceabilityCheckProcessActionHandler();  PrepareTraceabilityCheckProcessActionHandler(
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        StorageClientFactory storageClientFactory); static final String getId(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); }
PrepareTraceabilityCheckProcessActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); LogbookOperation operationToCheck; try (LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient()) { RequestResponseOK requestResponseOK = RequestResponseOK.getFromJsonNode(logbookOperationsClient .selectOperation( JsonHandler.getFromString(param.getMapParameters().get(WorkerParameterName.logbookRequest)))); List<ObjectNode> foundOperation = requestResponseOK.getResults(); if (foundOperation == null || foundOperation.isEmpty() || foundOperation.size() > 1) { itemStatus.increment(StatusCode.KO); return itemStatus; } operationToCheck = new LogbookOperation(foundOperation.get(0)); String operationType = (String) operationToCheck.get(LogbookMongoDbName.eventTypeProcess.getDbname()); if (!LogbookTypeProcess.TRACEABILITY.equals(LogbookTypeProcess.valueOf(operationType))) { itemStatus.increment(StatusCode.KO); return itemStatus; } } catch (InvalidParseOperationException | LogbookClientException | IllegalArgumentException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); return itemStatus; } Response response = null; try (WorkspaceClient workspaceClient = handler.getWorkspaceClientFactory().getClient(); StorageClient storageClient = storageClientFactory.getClient()) { String evDetData = operationToCheck.getString(LogbookMongoDbName.eventDetailData.getDbname()); JsonNode eventDetail = JsonHandler.getFromString(evDetData); TraceabilityEvent traceabilityEvent = JsonHandler.getFromJsonNode(eventDetail, TraceabilityEvent.class); String fileName = traceabilityEvent.getFileName(); DataCategory dataCategory = getDataCategory(traceabilityEvent); response = storageClient.getContainerAsync(VitamConfiguration.getDefaultStrategy(), fileName, dataCategory, AccessLogUtils.getNoLogAccessLog()); if (workspaceClient.isExistingContainer(param.getContainerName())) { try { workspaceClient.deleteContainer(param.getContainerName(), true); LOGGER.warn("Container was already existing, step is being replayed"); } catch (ContentAddressableStorageNotFoundException e) { LOGGER.warn("The container could not be deleted", e); } } handler.unzipInputStreamOnWorkspace(param.getContainerName(), SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, CommonMediaType.ZIP, response.readEntity(InputStream.class), false); extractTraceabilityOperationDetails(handler, traceabilityEvent); itemStatus.increment(StatusCode.OK); } catch (StorageServerClientException | StorageNotFoundException | ContentAddressableStorageException | InvalidParseOperationException e) { LOGGER.error(e.getMessage(), e); itemStatus.increment(StatusCode.FATAL); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } PrepareTraceabilityCheckProcessActionHandler();  PrepareTraceabilityCheckProcessActionHandler(
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        StorageClientFactory storageClientFactory); static final String getId(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler);  }