circus
circus

Reputation: 2600

Creating and retrieving JIRA remote issue links

I am trying to write a transition post function for JIRA v5.x. It should check if there is already a Confluence page linked with the issue, and create and link the page if not. I am developing this using the a groovy script and the scriptrunner plugin which can access the JAVA API.

While it was fairly easy to create the confluence page, I am struggling with the remote issue links.

This is how I try to create the link:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder

//I use a wrapper class for the moment so I can run via scriptrunner and debug it in IDEA
class myWrapper {

    def doStuff() {

        //get the issue, this would already be available in an post action
        def issueService = ComponentManager.getInstance().getIssueService();
        def authContext = ComponentManager.getInstance().getJiraAuthenticationContext()

        def issueResult = issueService.getIssue(authContext.getUser(), "DEV-1");
        def issue = issueResult.getIssue()

        //build link
        def linkBuilder = new RemoteIssueLinkBuilder()
        linkBuilder.issueId(issue.id)
        linkBuilder.applicationName("myconluence")
        linkBuilder.applicationType("com.atlassian.confluence")
        linkBuilder.relationship("Wiki Page")
        linkBuilder.title("testpage")
        linkBuilder.url("http://localhost:8090/display/LIN/testpage")
        linkBuilder.build()

        def validationResult = RemoteIssueLinkService.validateCreate(authContext.getUser(), linkBuilder)

    }
}

(new myWrapper()).doStuff()

When I run the code I get the following exception:

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.bc.issue.link.RemoteIssueLinkService.validateCreate() is applicable for argument types: (com.atlassian.crowd.embedded.ofbiz.OfBizUser, com.atlassian.jira.issue.link.RemoteIssueLinkBuilder) values: [admin:1, com.atlassian.jira.issue.link.RemoteIssueLinkBuilder@180ca9]

For me it looks like I do not get the RemoteIssueLinkService correctly,but I do not know what I have to do to fix that.

Upvotes: 1

Views: 3900

Answers (1)

circus
circus

Reputation: 2600

I asked the same question in the atlassian forum . Here is the working answer that I received from Jamie Echlin for future reference


It's not a static method, so you need to get an instance of the class first:

def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class)

remoteIssueLinkService.validateCreate(...)

Upvotes: 2

Related Questions