Source:
<code>protected List<Workflow> githubWebhookDelete(String repository, String gitReference, String username, String installationId) { Optional<String> gitReferenceName = GitHelper.parseGitHubReference(gitReference); if (gitReferenceName.isEmpty()) { String msg = "Reference " + gitReference + " is not of the valid form"; LOG.error(msg); sessionFactory.getCurrentSession().clear(); LambdaEvent lambdaEvent = createBasicEvent(repository, gitReference, username, LambdaEvent.LambdaEventType.DELETE); lambdaEvent.setMessage(msg); lambdaEvent.setSuccess(false); lambdaEventDAO.create(lambdaEvent); sessionFactory.getCurrentSession().getTransaction().commit(); throw new CustomWebApplicationException(msg, LAMBDA_FAILURE); } List<Workflow> workflows = workflowDAO.findAllByPath("github.com/" + repository, false).stream().filter(workflow -> Objects.equals(workflow.getMode(), DOCKSTORE_YML)).collect( Collectors.toList()); <START> workflows.forEach(workflow -> { <END> if (workflow.getActualDefaultVersion() != null && workflow.getActualDefaultVersion().getName().equals(gitReferenceName.get())) { workflow.setActualDefaultVersion(null); } }); workflows.forEach(workflow -> workflow.getWorkflowVersions().removeIf(workflowVersion -> Objects.equals(workflowVersion.getName(), gitReferenceName.get()) && !workflowVersion.isFrozen())); LambdaEvent lambdaEvent = createBasicEvent(repository, gitReference, username, LambdaEvent.LambdaEventType.DELETE); lambdaEventDAO.create(lambdaEvent); return workflows; }</code><technical_language>D'oh</technical_language>

Target:
protected List<Workflow> githubWebhookDelete(String repository, String gitReference, String username, String installationId) { Optional<String> gitReferenceName = GitHelper.parseGitHubReference(gitReference); if (gitReferenceName.isEmpty()) { String msg = "Reference " + gitReference + " is not of the valid form"; LOG.error(msg); sessionFactory.getCurrentSession().clear(); LambdaEvent lambdaEvent = createBasicEvent(repository, gitReference, username, LambdaEvent.LambdaEventType.DELETE); lambdaEvent.setMessage(msg); lambdaEvent.setSuccess(false); lambdaEventDAO.create(lambdaEvent); sessionFactory.getCurrentSession().getTransaction().commit(); throw new CustomWebApplicationException(msg, LAMBDA_FAILURE); } List<Workflow> workflows = workflowDAO.findAllByPath("github.com/" + repository, false).stream().filter(workflow -> Objects.equals(workflow.getMode(), DOCKSTORE_YML)).collect( Collectors.toList()); workflows.forEach(workflow -> { if (workflow.getActualDefaultVersion() != null && workflow.getActualDefaultVersion().getName().equals(gitReferenceName.get())) { Optional<WorkflowVersion> max = workflow.getWorkflowVersions().stream() .filter(v -> !Objects.equals(v.getName(), gitReferenceName.get())) .max(Comparator.comparingLong(ver -> ver.getDate().getTime())); workflow.setActualDefaultVersion(max.orElse(null)); } }); workflows.forEach(workflow -> workflow.getWorkflowVersions().removeIf(workflowVersion -> Objects.equals(workflowVersion.getName(), gitReferenceName.get()) && !workflowVersion.isFrozen())); LambdaEvent lambdaEvent = createBasicEvent(repository, gitReference, username, LambdaEvent.LambdaEventType.DELETE); lambdaEventDAO.create(lambdaEvent); return workflows; }