Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get remote/web Issue links using Java

shashank_shekhar August 7, 2014

I followed this tutorial to create an event listner, and I now need to perform certain actions if the issue has certain labels and links .

I am able to extract the labels using

Issue issue =issueEvent.getIssue();

Set<Label> labels =issue.getLabels();

for(Label label :labels){
			if(label.getLabel().contains("xyz")){
				hasDeskLabel=true;
				break;
			}
		}

I have tried extracting links using

List<IssueLink> links =ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

but this gives me the list of internal links, not external web links.

Is there a way to get those ?

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Benu Gupta August 10, 2014

I think you are referring to remote links for an issue. Try the following code:

final UserManager userManager = ComponentAccessor.getComponentOfType(UserManager.class);

final IssueManager issueManager = ComponentAccessor.getComponentOfType(IssueManager.class);

RemoteIssueLinkListResult linkResult = ComponentAccessor.getComponentOfType(RemoteIssueLinkService.class).getRemoteIssueLinksForIssue(userManager.getUserObject('username'), issueManager.getIssueObject('pkey'));

List<RemoteIssueLink> remoteLinks = result.getRemoteIssueLinks();

0 votes
Paresh Gandhi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 9, 2014

()

import com.atlassian.jira.ComponentManager
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ManagerFactory
import static org.apache.log4j.Level.DEBUG
import org.apache.log4j.Category
import org.apache.log4j.Level
import org.apache.log4j.Category
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import org.apache.log4j.Logger
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager

class CloseParentIssue extends AbstractIssueEventListener {
    Logger log = Logger.getLogger(CloseParentIssue.class)    
	@Override
    void workflowEvent (IssueEvent event) {
		log.setLevel(org.apache.log4j.Level.DEBUG)
		def itsdIssue
		Issue issue = event.getIssue()
		def issuestatus = issue.getStatusObject().getName().toUpperCase()
		def issueType = issue.issueTypeObject.name
		def linkedIssue
		if (issuestatus == "CLOSED" && issueType == "New Feature" ) { //change issue type
			def componentManager = ComponentManager.getInstance()
			def issueLinkManager = componentManager.getIssueLinkManager()
			def allLinkedIssueInWardClosed = false				
			def itsdFound = false
			issueLinkManager.getInwardLinks(issue.id).each {issueLink ->				
				linkedIssue = issueLink.sourceObject
				String linkedIssueTemp = linkedIssue.key				
				if(linkedIssueTemp.contains("TEST")){ //change it to ITSD
					itsdFound = true
					itsdIssue = linkedIssue					
				}		
				log.debug "Inward linked issue: " + linkedIssue.key
				if(linkedIssueTemp.contains("TEST") == false) { //change it to ITSD
					if (linkedIssue.getStatusObject().getName().toUpperCase() == "CLOSED" ) {
						allLinkedIssueInWardClosed = true			
					}
					else {
						allLinkedIssueInWardClosed = false
					}
				}						
			}
			def allLinkedIssueOutWardClosed = false	
			issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->				
				linkedIssue = issueLink.destinationObject	
				String linkedIssueTemp = linkedIssue.key
				log.debug "Outward linked issue: " + linkedIssue.key
				if(linkedIssueTemp.contains("TEST") == false) { //change it to ITSD
					if (linkedIssue.getStatusObject().getName().toUpperCase() == "CLOSED" ) {
						allLinkedIssueOutWardClosed = true			
					}
					else {
						allLinkedIssueOutWardClosed = false
					}
				}						
			}
			if(itsdFound)
				if(allLinkedIssueOutWardClosed && allLinkedIssueInWardClosed){
					issuestatus = itsdIssue.getStatusObject().getName().toUpperCase()
					if (issuestatus == "WAITING FOR SUPPORT" || issuestatus == "WAITING FOR CUSTOMER" || issuestatus == "WAITING FOR TRIAGE"){
						int actionid = 0
						if (issuestatus == "WAITING FOR SUPPORT")
								actionid = 801 //change action id
						else if (issuestatus == "WAITING FOR CUSTOMER")
								actionid = 761 //change action id
						else if (issuestatus == "WAITING FOR TRIAGE")
								actionid = 831 //change action id
								 
						def user = itsdIssue.getAssignee()					
						IssueService issueService = ComponentManager.getInstance().getIssueService()
						IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
						TransitionValidationResult validationResult = issueService.validateTransition(user, itsdIssue.id, actionid, issueInputParameters)
						issueService.transition(user, validationResult)
						log.debug itsdIssue.key + " got resolved"
					}
				}
		}		
	}
}

0 votes
Paresh Gandhi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2014
shashank_shekhar August 8, 2014

I restart fixed the issue, but now I only get list of internal jira links.
If you can help me with getting external links (e.g. www.google.com) I will mark your answer as accepted

Paresh Gandhi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 9, 2014
attached code shall give you both inward and outward linked issue.
Please remove additional logic.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events