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 (1 or more, comma separated) of the issue state(s) the linked issues must be in to allow the workflow transition.
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 Every transition that used this condition required complex if/else logic so I had to create a 'meta-condition' which contained calls to multiple conditionals. You environment might differ. Regardless, to use this condition call it from a java class as shown in the skeleton at the linked page shown below. |
Custom Workflow Condition Skeleton -> go here to get frame to use below subroutine.
public boolean blockingLinksClosed( GenericValue issue , String linkValidStates ) { try { // Inward links are links made from other issues to the passed 'issue' List inwardLinks = ComponentManager.getInstance().getIssueLinkManager().getInwardLinks(issue.getLong("id")); // Make sure all linked issues of link type equal to passed link name for (int i = 0; i < inwardLinks.size(); i++) { IssueLink link = (IssueLink) inwardLinks.get(i); //log.error("issueLinkName: " + link.getIssueLinkType().getName()); if("Blocking".equals(link.getIssueLinkType().getName())) { String issueStatus = ((GenericValue ) link.getSource()).getString("status"); //log.error("issueStatus: " + issueStatus); boolean isClosed = false; String[] validStates = linkValidStates.split(","); for (int j = 0; j < validStates.length; j++) { String validState = validStates[j]; if(issueStatus.equals(validState)) { //log.error(" validState: " + validState); isClosed = true; break; } } //log.error(" returning: " + isClosed); return isClosed; } } return true; } catch(Exception e) { log.error("Exception verifying all blockingLinks are closed: " + e, e); return false; } }
Install Instructions
You can deploy this subroutine into your instance by wrapping it in a custom workflow element plugin.

Comments (6)
Oct 18, 2005
paolo says:
I'm really interested in workin on this feature. Is it possible to have the comp...I'm really interested in workin on this feature. Is it possible to have the complete jar for this plugin, or some more instructions. I would really appreciate.
Oct 19, 2005
Jeff Turner says:
Paolo, I guess this code snippet was just intended as a guide. You would need to...Paolo,
I guess this code snippet was just intended as a guide. You would need to follow the instructions at:
http://confluence.atlassian.com/pages/viewpage.action?pageId=11764
to create a workflow condition, and use this code in it.
Cheers,
Jeff
Mar 10
Tal Abramson says:
Just made this one worked best way is to take the example of Parent Issue Blocki...Just made this one worked
best way is to take the example of Parent Issue Blocking Condition, which can be found in the development kit
and change what need to be changed ( almost everything , but it still gives you a good skeleton)
Anyway , i created from this one , the opposite condition - Origin issues cannot be closed if linked issue are not closed :
Mar 10
Erin says:
I've just implemented this code in 3.12.2. I found that the code is buggy though...I've just implemented this code in 3.12.2. I found that the code is buggy though -- it doesn't properly handle issues with more than 1 blocking issue linked. It returns true if at least 1 blocking issue is closed, but does not require that ALL be closed.
Jun 24
Quimicefa says:
I've just packaged a version of the code snipped shown below as I need it to fit...I've just packaged a version of the code snipped shown below as I need it to fit some functionalities in my Jira installations.
It's tested against Jira 3.10.X, but it should work with lastest releases. The main difference with the code shown, is that this condition doesn't allow transtition if the issue is linked against other issue in a non-valid state.
The plugin page:
http://code.google.com/p/jira-blockinglinks-condition
Jul 28
Sai T says:
Quimicefa, Your code works fine. One issue is that it is not limited to an...Quimicefa,
Your code works fine. One issue is that it is not limited to any specific type of linking. Say, we have cloners, links and blockers. I would like this to work only for the blockers. The rest have links which are clones/links but the blocking condition should not apply. Any suggestions?