Source:
<code>public File downloadTargetEntry(String toolpath, ToolDescriptor.TypeEnum type, boolean unzip, File directory) throws IOException { String[] parts = toolpath.split(":"); String path = parts[0]; String tag = (parts.length > 1) ? parts[1] : "master"; Workflow workflow = getDockstoreWorkflowByPath(path); Optional<WorkflowVersion> first = workflow.getWorkflowVersions().stream().filter(foo -> foo.getName().equalsIgnoreCase(tag)) .findFirst(); if (!first.isPresent()) { first = workflow.getWorkflowVersions().stream().max(Comparator.comparing(WorkflowVersion::getLastModified)); System.out.println("Could not locate workflow with version '" + tag + "'. Using last modified version '" <START> + first.get().getName() + "' instead."); <END> } if (first.isPresent()) { boolean isValid = first.get().isValid(); if (!isValid) { errorMessage("Cannot use workflow version '" + first.get().getName() + "' because it is not valid. Please pick a" + " workflow version that is recognized as valid by Dockstore.", CLIENT_ERROR); } Long versionId = first.get().getId(); workflowsApi.getApiClient().setDebugging(false); byte[] arbitraryURL = SwaggerUtility .getArbitraryURL("/workflows/" + workflow.getId() + "/zip/" + versionId, new GenericType<byte[]>() { }, workflowsApi.getApiClient()); workflowsApi.getApiClient().setDebugging(Client.DEBUG.get()); File zipFile = new File(zipFilename(workflow)); FileUtils.writeByteArrayToFile(zipFile, arbitraryURL, false); if (unzip) { SwaggerUtility.unzipFile(zipFile, directory); } return new File(directory, first.get().getWorkflowPath()); } else { throw new RuntimeException("version not found"); } }</code><technical_language>Is guaranteed present? If not, get error first.get</technical_language>

Target:
public File downloadTargetEntry(String toolpath, ToolDescriptor.TypeEnum type, boolean unzip, File directory) throws IOException { String[] parts = toolpath.split(":"); String path = parts[0]; String tag = (parts.length > 1) ? parts[1] : "master"; Workflow workflow = getDockstoreWorkflowByPath(path); Optional<WorkflowVersion> first = workflow.getWorkflowVersions().stream().filter(foo -> foo.getName().equalsIgnoreCase(tag)) .findFirst(); if (!first.isPresent()) { first = workflow.getWorkflowVersions().stream().max(Comparator.comparing(WorkflowVersion::getLastModified)); if (first.isPresent()) { System.out.println("Could not locate workflow with version '" + tag + "'. Using last modified version '" + first.get().getName() + "' instead."); } } if (first.isPresent()) { boolean isValid = first.get().isValid(); if (!isValid) { errorMessage("Cannot use workflow version '" + first.get().getName() + "' because it is not valid. Please pick a" + " workflow version that is recognized as valid by Dockstore.", CLIENT_ERROR); } Long versionId = first.get().getId(); workflowsApi.getApiClient().setDebugging(false); byte[] arbitraryURL = SwaggerUtility .getArbitraryURL("/workflows/" + workflow.getId() + "/zip/" + versionId, new GenericType<byte[]>() { }, workflowsApi.getApiClient()); workflowsApi.getApiClient().setDebugging(Client.DEBUG.get()); File zipFile = new File(zipFilename(workflow)); FileUtils.writeByteArrayToFile(zipFile, arbitraryURL, false); if (unzip) { SwaggerUtility.unzipFile(zipFile, directory); } return new File(directory, first.get().getWorkflowPath()); } else { throw new RuntimeException("version not found"); } }