I need to list all linked issues with in project AAA(Which created using jira service desk), in format of :
source issue id - issue summary Links.
Got code below, but looks like msssing lots of links
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import java.util.Collection;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.ofbiz.core.entity.GenericEntityException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
String projectKey = "AAA";
IssueManager issueManager = ComponentAccessor.getIssueManager();
Long projectId = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey).getId();
Collection<Long> issueIdsForProject = issueManager.getIssueIdsForProject(projectId);
int issuesInTransition = 0;
String results = "<h3><b>Issues under Project: " + projectKey + "</b></h3></br>";
results = results + "<table border=1><tr><th>Issue</th><th>Links</th></tr>";
for (Long issueId : issueIdsForProject) {
MutableIssue issue = issueManager.getIssueObject(issueId);
results = results + "<tr><td>" + issue.getKey() + " - " + issue.getSummary() + "</td><td>";
//Linked Issues
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
String key = issueLink.getDestinationObject().getKey();
results = results + key + "(" + issueLink.getIssueLinkType().getName() + "), ";
}
results = results + "</td></tr>";
issuesInTransition++;
}
results = results + "</table><br/><b> No. of Lined Issues: " + issuesInTransition + "</b>";
return results;
You get only outward links but there are also inward links. There must be 2 loops in your code one with outward links (you have it now) and the second one with inward links:
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
String key = issueLink.getSourceObject().getKey();
results = results + key + "(" + issueLink.getIssueLinkType().getName() + "), ";
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.