This condition can be used to not allow users to transition an issue which has 'open' subtasks.
This subroutine can be used to not allow users to transition an issue which is linked via linktype 'Blocking' to issues not in a user specified state. (you could easily extend this routine to allow the linktype to be user-specified as well)
When using the condition in a JIRA workflow the user must supply a single parameter 'closedstate' which contains the 'id' primary key value of the issue state(s) the subtask issues must be in to allow the workflow transition.
Obviously the issue state doesn't have to have anything to do with the word 'closed' - it could be any valid workflow issuestatus primary key.
One big shortcoming to this simple task - no overriding of the condition is possible. In itself this is ok as you can just have it in a 'or' clause with an additional check for the groups the user is a member of. If however you wish to have more complicated logic - i.e.:
if (the user is a member of project-admin group AND all subtasks are closed) OR (user is a jira-administrator)
you have to create a 'meta-condition' class which contains the logic for the 'and' conditions. There is supposed to be a supported syntax with the JIRA 3.0.3 opensymphony osworkflow library but I haven't determined what this is yet.
| How to use Build a jar file containing this class (rename as appropriate). Deploy the jar file to <jira deploy dir>/WEB-INF/lib. |
<condition type="class"> <arg name="class.name">com.newisys.jira.workflow.condition.SubTasksClosedCondition</arg> <arg name="closedstate">11</arg> </condition>
Custom Workflow Condition Skeleton -> go here to get frame to use below subroutine.
public static boolean subTasksClosed( GenericValue issue
, String closedState )
{
// Make sure all subtasks to this issue are closed
List subtasks = ComponentManager.getInstance().getSubTaskManager().getSubTaskIssueLinks(issue);
for (int i = 0; i < subtasks.size(); i++)
{
IssueLink link = (IssueLink) subtasks.get(i);
GenericValue subtask = link.getDestination();
//log.error("validStateList: " + validStateList);
//log.error(" issue status: " + subtask.getString("status"));
if(!closedState.equals(subtask.getString("status"))) return false;
}
return true;
}
