This page last changed on Oct 10, 2006 by rosie@atlassian.com.

The following code sample iterates over a list of issues and for each issue retrieves its linked issues. This code can be useful if you are creating a custom report that shows linked issues.

Remember that each link has a direction and a type. Therefore the issues in the Link Collection are grouped by link type and direction.

// A list of GenericValues representing issues
List issues = ...
for (Iterator iterator = issues.iterator(); iterator.hasNext();)
{
    GenericValue issue = (GenericValue) iterator.next();
    // Retrieve a collection of all linked issues and their link types
    LinkCollection linkCollection = getIssueLinkManager().getLinkCollection(issue, authenticationContext.getUser());
    Set linkTypes = linkCollection.getLinkTypes();
    if (linkTypes != null)
    {
        // For each link type
        for (Iterator iterator1 = linkTypes.iterator(); iterator1.hasNext();)
        {
            IssueLinkType linkType = (IssueLinkType) iterator1.next();
            // Get the outward linked issues
            List outwardIssues = linkCollection.getOutwardIssues(linkType.getName());
            if (outwardIssues != null)
            {
                for (Iterator iterator2 = outwardIssues.iterator(); iterator2.hasNext();)
                {
                    GenericValue outwardIssue = (GenericValue) iterator2.next();
                    System.out.println("outwardIssue = " + outwardIssue);
                }
            }
            // And the inward linked issues
            List inwardIssues = linkCollection.getInwardIssues(linkType.getName());
            if (inwardIssues != null)
            {
                for (Iterator iterator2 = inwardIssues.iterator(); iterator2.hasNext();)
                {
                    GenericValue inwardIssue = (GenericValue) iterator2.next();
                    System.out.println("inwardIssue = " + inwardIssue);
                }
            }
        }
    }
}

One way to retrieve a list of issues is to make and run a Search Request.

Please note that the code above uses JiraAuthenticationContext to retrieve the remote user. The easiest way to get access to an instance of the JiraAuthenticationContext is to declare it as a dependency in the constructor of your class. The process is explained in more detail here.

Document generated by Confluence on Oct 06, 2009 00:31