package uk.org.sappho.jira.workflow.approvals;

import java.util.Map;

import org.apache.log4j.Logger;

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.MutableIssue;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.user.User;
import com.opensymphony.workflow.WorkflowException;

public class CleanupApprovalsAction extends BulkApprovalsAction {

    private final ComponentManager componentManager = ComponentManager.getInstance();
    private static final Logger log = Logger.getLogger(CleanupApprovalsAction.class);

    @SuppressWarnings("rawtypes")
    public void execute(Map transientVars, Map params, PropertySet propertySet) throws WorkflowException {

        MutableIssue mainIssue = (MutableIssue) transientVars.get("issue");

        User user = componentManager.getJiraAuthenticationContext().getUser();
        log.warn(user.getFullName() + " has triggered the death of child zombies of " + mainIssue.getKey());

        for (MutableIssue subTask : mainIssue.getSubTaskObjects()) {
            if (subTask.getStatusObject().getName().equals("Approval Sought")) {
                transitionIssue(subTask, 51, user);
            }
        }
    }
}

@@ -187,16 +187,352 @@
 eIssue;%0A
+import com.atlassian.jira.util.ErrorCollection;%0Aimport com.atlassian.jira.util.ImportUtils;%0Aimport com.atlassian.jira.util.JiraUtils;%0Aimport com.atlassian.jira.workflow.WorkflowTransitionUtil;%0Aimport com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;%0Aimport com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;%0A
 import c
@@ -579,16 +579,16 @@
 rtySet;%0A
-
 import c
@@ -715,27 +715,36 @@
 nds 
-BulkApprovalsAction
+AbstractJiraFunctionProvider
  %7B%0A%0A
@@ -1490,16 +1490,20 @@
         
+int 
 transiti
@@ -1508,31 +1508,1245 @@
 tion
-Issue(subTask, 51, user
+ActionId = 51;%0A                log.warn(%22Running workflow transition action id %22 + transitionActionId + %22 on %22 + subTask.getKey());%0A                boolean wasIndexing = ImportUtils.isIndexIssues();%0A                ImportUtils.setIndexIssues(true);%0A                WorkflowTransitionUtil workflowTransitionUtil = JiraUtils%0A                        .loadComponent(WorkflowTransitionUtilImpl.class);%0A                workflowTransitionUtil.setIssue(subTask);%0A                workflowTransitionUtil.setUsername(user.getName());%0A                workflowTransitionUtil.setAction(transitionActionId);%0A                ErrorCollection errors = workflowTransitionUtil.validate();%0A                if (errors.hasAnyErrors())%0A                    throw new WorkflowException(%22Unable to validate transition %22 + subTask.getKey()%0A                            + %22! Caused by %22%0A                            + errors);%0A                errors = workflowTransitionUtil.progress();%0A                ImportUtils.setIndexIssues(wasIndexing);%0A                if (errors.hasAnyErrors())%0A                    throw new WorkflowException(%22Unable to progress transition %22 + subTask.getKey()%0A                            + %22! Caused by %22%0A                            + errors
 );%0A 

Implement an approvals reverter. More on this. (reverse-merged from commit 557ce60e92e1e11ea4f768b7b7486c84a9c6e472) SAPPHO-1: Implement an approvals reverter. (reverse-merged from commit 8462d29148d4c5ee0b32348b9fa66fd562e02768)