Source:
public List<Workflow> addUserToDockstoreWorkflows(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user", in = ParameterIn.HEADER) @Auth User authUser, @ApiParam(name = "userId", required = true, value = "User to update") @PathParam("userId") @Parameter(name = "userId", in = ParameterIn.PATH, description = "User to update", required = true) long userId, @ApiParam(name = "emptyBody", value = APPEASE_SWAGGER_PATCH) @Parameter(description = APPEASE_SWAGGER_PATCH, name = "emptyBody") String emptyBody) { final User user = userDAO.findById(authUser.getId()); if (!Objects.equals(userId, user.getId())) { throw new CustomWebApplicationException("The user Id provided does not match the logged-in user id.", HttpStatus.SC_BAD_REQUEST); } List<SourceControl> sourceControls = Arrays.stream(SourceControl.values()).filter(sourceControl -> !Objects.equals(sourceControl, SourceControl.DOCKSTORE)).collect( Collectors.toList()); List<Token> scTokens = getAndRefreshTokens(user, tokenDAO, client, bitbucketClientID, bitbucketClientSecret) .stream() .filter(token -> sourceControls.contains(token.getTokenSource().getSourceControl())) .collect(Collectors.toList()); scTokens.stream().forEach(token -> { SourceCodeRepoInterface sourceCodeRepo = SourceCodeRepoFactory.createSourceCodeRepo(token, client); Map<String, String> gitUrlToRepositoryId = sourceCodeRepo.getWorkflowGitUrl2RepositoryId(); Set<String> organizations = gitUrlToRepositoryId.values().stream().map(repository -> repository.split("/")[0]).collect(Collectors.toSet()); organizations.forEach(organization -> { List<Workflow> workflows = workflowDAO.findByOrganization(token.getTokenSource().getSourceControl(), organization); workflows.stream().forEach(workflow -> workflow.getUsers().add(user)); }); }); return getStrippedBioworkflows(userDAO.findById(user.getId())); }

Target:
public List<Workflow> addUserToDockstoreWorkflows(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user", in = ParameterIn.HEADER) @Auth User authUser, @ApiParam(name = "userId", required = true, value = "User to update") @PathParam("userId") @Parameter(name = "userId", in = ParameterIn.PATH, description = "User to update", required = true) long userId, @ApiParam(name = "emptyBody", value = APPEASE_SWAGGER_PATCH) @Parameter(description = APPEASE_SWAGGER_PATCH, name = "emptyBody") String emptyBody) { final User user = userDAO.findById(authUser.getId()); if (user == null || !Objects.equals(userId, user.getId())) { throw new CustomWebApplicationException("The user id provided does not match the logged-in user id.", HttpStatus.SC_BAD_REQUEST); } List<SourceControl> sourceControls = Arrays.stream(SourceControl.values()).filter(sourceControl -> !Objects.equals(sourceControl, SourceControl.DOCKSTORE)).collect( Collectors.toList()); List<Token> scTokens = getAndRefreshTokens(user, tokenDAO, client, bitbucketClientID, bitbucketClientSecret) .stream() .filter(token -> sourceControls.contains(token.getTokenSource().getSourceControl())) .collect(Collectors.toList()); scTokens.stream().forEach(token -> { SourceCodeRepoInterface sourceCodeRepo = SourceCodeRepoFactory.createSourceCodeRepo(token, client); Map<String, String> gitUrlToRepositoryId = sourceCodeRepo.getWorkflowGitUrl2RepositoryId(); Set<String> organizations = gitUrlToRepositoryId.values().stream().map(repository -> repository.split("/")[0]).collect(Collectors.toSet()); organizations.forEach(organization -> { List<Workflow> workflows = workflowDAO.findByOrganization(token.getTokenSource().getSourceControl(), organization); workflows.stream().forEach(workflow -> workflow.getUsers().add(user)); }); }); return getStrippedBioworkflows(userDAO.findById(user.getId())); }