Hi,
i,ve got a code fiding a 'parent' issue and transistioning it depending on the some validation.
Infortunetly it's not working, but i have no more idea why.
It's setting up a comment of the issue but it's not changing it's status.
I have observed that after validation program tries to run script from the begiining.
I have no erors in logs.
{code}
import org.apache.log4j.Category;
import org.ofbiz.core.entity.GenericValue;
import org.ofbiz.core.entity.GenericEntityException;
import com.opensymphony.workflow.Condition;
import com.opensymphony.workflow.spi.WorkflowEntry;
import com.opensymphony.module.propertyset.PropertySet;
import com.atlassian.jira.ManagerFactory;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkType;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.ImportUtils;
import java.util.Map;
import java.util.List;
import java.util.Iterator;
import java.util.Collection;
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.comments.CommentManager;
//Data
IssueLink innerlink; // Dla globalnego podgladu danej
String linkType = Testy; // Rodzaj lacza - nazwa
String validStateOut = 1; // Status kroku testowego
String validStateIn = 1; // Status błędu
boolean stat = true; // nie ruszać
int actionId = 81; // akcja do wykonania
List outwardLinks = ComponentManager.getInstance().getIssueLinkManager().getOutwardLinks(issue.getLong(id));
for (int i = 0; i < outwardLinks.size(); i++)
{
IssueLink link = (IssueLink) outwardLinks.get(i);
if(linkType.equals(link.getIssueLinkType().getName()))
{
String issueStatus = ((GenericValue ) link.getDestination()).getString(status);
if(issueStatus.equals(validStateOut))
{
List inwardLinks = ComponentManager.getInstance().getIssueLinkManager().getInwardLinks(link.getDestinationId());
for (int j = 0; j < inwardLinks.size(); j++)
{
innerlink = (IssueLink) inwardLinks.get(j);
if(linkType.equals(innerlink.getIssueLinkType().getName()))
{
String issueStatusB = ((GenericValue ) innerlink.getSource()).getString(status);
if(issueStatusB.equals(!validStateIn))
{
stat = false;
break;
}
}
}
if(stat==true)
{
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
MutableIssue parent = link.getDestinationObject() as MutableIssue;
String currentUser = ((WorkflowContext) transientVars.get(context)).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(parent);
workflowTransitionUtil.setUsername(currentUser);
workflowTransitionUtil.setAction (actionId);
// Add a comment so people have a clue why the child has been closed
CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
String comment = Wykonano przez automat.;
commentManager.create(parent, currentUser, comment, true);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
ImportUtils.setIndexIssues(wasIndexing);
}
}
else
{
log.error(validStateout else: + validStateOut);
}
}
}
{code}
Have done something similar here . below is my method which does auto-transition for Jira 4.3.
private void postCreationTasks() { MutableIssue issue1=getIssueObject(); final String remoteuser=ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName(); WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); workflowTransitionUtil.setIssue(issue1); workflowTransitionUtil.setUsername(remoteuser); workflowTransitionUtil.setAction(5); workflowTransitionUtil.progress(); }
I've done it the same way, infortunetly in my case, i'm trying to move other issue than i'm operating on, when i'm progressing it, it's changing it's fields values, but the status is still the same... i've got really no idea what it could be...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.