Linking with a remote artifact

To create a link with a remote artifact, you need to know:

Then, a link and back link can be created with the following:

	URI source = ... // the remote artifact URI
	URI target = ... // the Jira artifact URI

	LinkType linkType = LinkType.RELATED_CHANGE_REQUEST; // the link type, choose the one you want
    
	// create link in remote app, targeting Jira artifact
	DirectedLink link = new DirectedLink();
	link.setPropertyDefinition(linkType.getPropertyDefinition());
	link.setSource(source);
	link.setTarget(new Link(target, "Test link"));
	new AddLink(client, link).call();
    
	// create back link in Jira, targeting remote artifact
	DirectedLink backLink = new DirectedLink();
	backLink.setPropertyDefinition(linkType.getBacklink().get());
	backLink.setSource(target);
	backLink.setTarget(new Link(source, "Test backlink"));
	new AddLink(client, backLink).call();

Note that depending on the nature of the link type and of the remote application, some links may end up not being stored on the remote artifact. Instead, these links may be stored only in Jira and discovered dynamically by the remote application.