@Test(expected = ProcessingStorageWorkspaceException.class) public void getProcessWorkflowTestException() throws Exception { doThrow(new ContentAddressableStorageServerException("fail")).when(workspaceClient).getObject(anyString(), anyString()); processDataManagement.getProcessWorkflow("folder", "asyncId"); }
@Override public ProcessWorkflow getProcessWorkflow(String folderName, String asyncId) throws ProcessingStorageWorkspaceException, InvalidParseOperationException { Response response = null; try (WorkspaceClient client = workspaceClientFactory.getClient()) { response = client.getObject(PROCESS_CONTAINER, getPathToObjectFromFolder(folderName, asyncId)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); ProcessWorkflow processWorkflow = JsonHandler.getFromInputStream(is, ProcessWorkflow.class); return processWorkflow; } else { client.consumeAnyEntityAndClose(response); throw new ProcessingStorageWorkspaceException("Workspace error: " + response.getStatusInfo() .getReasonPhrase()); } } catch (ContentAddressableStorageServerException | ContentAddressableStorageNotFoundException exc) { throw new ProcessingStorageWorkspaceException(exc); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } }
WorkspaceProcessDataManagement implements ProcessDataManagement { @Override public ProcessWorkflow getProcessWorkflow(String folderName, String asyncId) throws ProcessingStorageWorkspaceException, InvalidParseOperationException { Response response = null; try (WorkspaceClient client = workspaceClientFactory.getClient()) { response = client.getObject(PROCESS_CONTAINER, getPathToObjectFromFolder(folderName, asyncId)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); ProcessWorkflow processWorkflow = JsonHandler.getFromInputStream(is, ProcessWorkflow.class); return processWorkflow; } else { client.consumeAnyEntityAndClose(response); throw new ProcessingStorageWorkspaceException("Workspace error: " + response.getStatusInfo() .getReasonPhrase()); } } catch (ContentAddressableStorageServerException | ContentAddressableStorageNotFoundException exc) { throw new ProcessingStorageWorkspaceException(exc); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } } }
WorkspaceProcessDataManagement implements ProcessDataManagement { @Override public ProcessWorkflow getProcessWorkflow(String folderName, String asyncId) throws ProcessingStorageWorkspaceException, InvalidParseOperationException { Response response = null; try (WorkspaceClient client = workspaceClientFactory.getClient()) { response = client.getObject(PROCESS_CONTAINER, getPathToObjectFromFolder(folderName, asyncId)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); ProcessWorkflow processWorkflow = JsonHandler.getFromInputStream(is, ProcessWorkflow.class); return processWorkflow; } else { client.consumeAnyEntityAndClose(response); throw new ProcessingStorageWorkspaceException("Workspace error: " + response.getStatusInfo() .getReasonPhrase()); } } catch (ContentAddressableStorageServerException | ContentAddressableStorageNotFoundException exc) { throw new ProcessingStorageWorkspaceException(exc); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } } private  WorkspaceProcessDataManagement(); @VisibleForTesting  WorkspaceProcessDataManagement(WorkspaceClientFactory workspaceClientFactory); }
WorkspaceProcessDataManagement implements ProcessDataManagement { @Override public ProcessWorkflow getProcessWorkflow(String folderName, String asyncId) throws ProcessingStorageWorkspaceException, InvalidParseOperationException { Response response = null; try (WorkspaceClient client = workspaceClientFactory.getClient()) { response = client.getObject(PROCESS_CONTAINER, getPathToObjectFromFolder(folderName, asyncId)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); ProcessWorkflow processWorkflow = JsonHandler.getFromInputStream(is, ProcessWorkflow.class); return processWorkflow; } else { client.consumeAnyEntityAndClose(response); throw new ProcessingStorageWorkspaceException("Workspace error: " + response.getStatusInfo() .getReasonPhrase()); } } catch (ContentAddressableStorageServerException | ContentAddressableStorageNotFoundException exc) { throw new ProcessingStorageWorkspaceException(exc); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } } private  WorkspaceProcessDataManagement(); @VisibleForTesting  WorkspaceProcessDataManagement(WorkspaceClientFactory workspaceClientFactory); static ProcessDataManagement getInstance(); @Override boolean createProcessContainer(); @Override boolean isProcessContainerExist(); @Override boolean createFolder(String folderName); @Override boolean isFolderExist(String folderName); @Override boolean removeFolder(String folderName); @Override void persistProcessWorkflow(String folderName, ProcessWorkflow processWorkflow); @Override void persistDistributorIndex(String folderName, String fileName, DistributorIndex distributorIndex); @Override Optional<DistributorIndex> getDistributorIndex(String folderName, String fileName); @Override ProcessWorkflow getProcessWorkflow(String folderName, String asyncId); @Override void removeProcessWorkflow(String folderName, String asyncId); @Override Map<String, ProcessWorkflow> getProcessWorkflowFor(Integer tenantId, String folderName); }
WorkspaceProcessDataManagement implements ProcessDataManagement { @Override public ProcessWorkflow getProcessWorkflow(String folderName, String asyncId) throws ProcessingStorageWorkspaceException, InvalidParseOperationException { Response response = null; try (WorkspaceClient client = workspaceClientFactory.getClient()) { response = client.getObject(PROCESS_CONTAINER, getPathToObjectFromFolder(folderName, asyncId)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); ProcessWorkflow processWorkflow = JsonHandler.getFromInputStream(is, ProcessWorkflow.class); return processWorkflow; } else { client.consumeAnyEntityAndClose(response); throw new ProcessingStorageWorkspaceException("Workspace error: " + response.getStatusInfo() .getReasonPhrase()); } } catch (ContentAddressableStorageServerException | ContentAddressableStorageNotFoundException exc) { throw new ProcessingStorageWorkspaceException(exc); } finally { DefaultClient.staticConsumeAnyEntityAndClose(response); } } private  WorkspaceProcessDataManagement(); @VisibleForTesting  WorkspaceProcessDataManagement(WorkspaceClientFactory workspaceClientFactory); static ProcessDataManagement getInstance(); @Override boolean createProcessContainer(); @Override boolean isProcessContainerExist(); @Override boolean createFolder(String folderName); @Override boolean isFolderExist(String folderName); @Override boolean removeFolder(String folderName); @Override void persistProcessWorkflow(String folderName, ProcessWorkflow processWorkflow); @Override void persistDistributorIndex(String folderName, String fileName, DistributorIndex distributorIndex); @Override Optional<DistributorIndex> getDistributorIndex(String folderName, String fileName); @Override ProcessWorkflow getProcessWorkflow(String folderName, String asyncId); @Override void removeProcessWorkflow(String folderName, String asyncId); @Override Map<String, ProcessWorkflow> getProcessWorkflowFor(Integer tenantId, String folderName);  }