@Test @RunWithCustomExecutor public void testVerifyTimeStampWithErrorWorkspaceThenFATAL() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); in = new ArrayList<>(); in.add(new IOParameter() .setUri(new ProcessingUri(UriPrefix.MEMORY, "TraceabilityOperationDetails/EVENT_DETAIL_DATA.json"))); handlerIO.addOutIOParameters(in); handlerIO.addOutputResult(0, PropertiesUtils.getResourceFile(DETAIL_EVENT_TRACEABILITY), false); handlerIO.reset(); handlerIO.addInIOParameters(in); verifyTimeStampActionHandler = new VerifyTimeStampActionHandler(); when(workspaceClient.getObject(any(), eq(SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + "token.tsp"))).thenThrow(new ContentAddressableStorageNotFoundException("Token is not existing")); final ItemStatus response = verifyTimeStampActionHandler.execute(params, handlerIO); assertEquals(StatusCode.FATAL, response.getGlobalStatus()); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream tokenFile = null; try { JsonNode traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK)); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + TIMESTAMP_FILENAME; tokenFile = handler.getInputStreamFromWorkspace(operationFilePath); String encodedTimeStampToken = IOUtils.toString(tokenFile, "UTF-8"); final ItemStatus subItemStatusTokenComparison = new ItemStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP); try { compareTimeStamps(encodedTimeStampToken, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps are not equal", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenValidation = new ItemStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP); try { validateTimestamp(encodedTimeStampToken); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenVerification = new ItemStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP); try { String computingInformationPath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_COMPUTING_INFORMATION); String merkleTreePath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_MERKLE_TREE); verifyTimestamp(encodedTimeStampToken, computingInformationPath, merkleTreePath, handler); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } } catch (InvalidParseOperationException | ContentAddressableStorageNotFoundException | IOException | ContentAddressableStorageServerException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(tokenFile); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }
VerifyTimeStampActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream tokenFile = null; try { JsonNode traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK)); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + TIMESTAMP_FILENAME; tokenFile = handler.getInputStreamFromWorkspace(operationFilePath); String encodedTimeStampToken = IOUtils.toString(tokenFile, "UTF-8"); final ItemStatus subItemStatusTokenComparison = new ItemStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP); try { compareTimeStamps(encodedTimeStampToken, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps are not equal", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenValidation = new ItemStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP); try { validateTimestamp(encodedTimeStampToken); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenVerification = new ItemStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP); try { String computingInformationPath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_COMPUTING_INFORMATION); String merkleTreePath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_MERKLE_TREE); verifyTimestamp(encodedTimeStampToken, computingInformationPath, merkleTreePath, handler); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } } catch (InvalidParseOperationException | ContentAddressableStorageNotFoundException | IOException | ContentAddressableStorageServerException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(tokenFile); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } }
VerifyTimeStampActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream tokenFile = null; try { JsonNode traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK)); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + TIMESTAMP_FILENAME; tokenFile = handler.getInputStreamFromWorkspace(operationFilePath); String encodedTimeStampToken = IOUtils.toString(tokenFile, "UTF-8"); final ItemStatus subItemStatusTokenComparison = new ItemStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP); try { compareTimeStamps(encodedTimeStampToken, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps are not equal", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenValidation = new ItemStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP); try { validateTimestamp(encodedTimeStampToken); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenVerification = new ItemStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP); try { String computingInformationPath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_COMPUTING_INFORMATION); String merkleTreePath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_MERKLE_TREE); verifyTimestamp(encodedTimeStampToken, computingInformationPath, merkleTreePath, handler); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } } catch (InvalidParseOperationException | ContentAddressableStorageNotFoundException | IOException | ContentAddressableStorageServerException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(tokenFile); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }  }
VerifyTimeStampActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream tokenFile = null; try { JsonNode traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK)); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + TIMESTAMP_FILENAME; tokenFile = handler.getInputStreamFromWorkspace(operationFilePath); String encodedTimeStampToken = IOUtils.toString(tokenFile, "UTF-8"); final ItemStatus subItemStatusTokenComparison = new ItemStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP); try { compareTimeStamps(encodedTimeStampToken, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps are not equal", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenValidation = new ItemStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP); try { validateTimestamp(encodedTimeStampToken); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenVerification = new ItemStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP); try { String computingInformationPath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_COMPUTING_INFORMATION); String merkleTreePath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_MERKLE_TREE); verifyTimestamp(encodedTimeStampToken, computingInformationPath, merkleTreePath, handler); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } } catch (InvalidParseOperationException | ContentAddressableStorageNotFoundException | IOException | ContentAddressableStorageServerException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(tokenFile); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }  static final String getId(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); }
VerifyTimeStampActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream tokenFile = null; try { JsonNode traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK)); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + TIMESTAMP_FILENAME; tokenFile = handler.getInputStreamFromWorkspace(operationFilePath); String encodedTimeStampToken = IOUtils.toString(tokenFile, "UTF-8"); final ItemStatus subItemStatusTokenComparison = new ItemStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP); try { compareTimeStamps(encodedTimeStampToken, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps are not equal", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_TOKEN_TIMESTAMP, subItemStatusTokenComparison.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenValidation = new ItemStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP); try { validateTimestamp(encodedTimeStampToken); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VALIDATE_TOKEN_TIMESTAMP, subItemStatusTokenValidation.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } final ItemStatus subItemStatusTokenVerification = new ItemStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP); try { String computingInformationPath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_COMPUTING_INFORMATION); String merkleTreePath = String.format("%s/%s", SedaConstants.TRACEABILITY_OPERATION_DIRECTORY, TRACEABILITY_MERKLE_TREE); verifyTimestamp(encodedTimeStampToken, computingInformationPath, merkleTreePath, handler); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.OK)); } catch (ProcessingException e) { LOGGER.error("Timestamps is not valid", e); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_VERIFY_TOKEN_TIMESTAMP, subItemStatusTokenVerification.increment(StatusCode.KO)); return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } } catch (InvalidParseOperationException | ContentAddressableStorageNotFoundException | IOException | ContentAddressableStorageServerException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(tokenFile); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }  static final String getId(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler);  }