RemoteIssueLinkCreateEvent doesn't have id when custom jira listener catches it

Dmitrii March 9, 2020

Hi Community,

Could you please help with issue below? Did you face this problem?

Now we are implementing custom listener for our system, listener must catch moments when user create/delete remote issue links on local server and noticed that object of RemoteIssueLinkCreateEvent doesn't have id when listener catches it. We suppose this is a bug, but we didn't find bug ticket for this.

Also we noticed that jira has another such event RemoteIssueLinkUICreateEvent and it's working well, because RemoteIssueLinkCreateEvent has id and we can work with this. But we cannot use it because it works just in case user creates remote link by jira UI, so such way cannot catch moment when user creates remote links by rest api http://localhost:8080/rest/api/latest/issue/TEST-1018/remotelink .

We use JIRA server with version: 8.2.1

Below you can find an example how we test of catching such events:

public class RemoteIssueLinksListener extends AbstractIssueEventListener
{

private final RemoteIssueLinkManager remoteIssueLinkManager;

public RemoteIssueLinksListener(RemoteIssueLinkManager remoteIssueLinkManager, JiraAuthenticationContext jiraAuthenticationContext)
{
this.remoteIssueLinkManager = remoteIssueLinkManager;
this.jiraAuthenticationContext = jiraAuthenticationContext;
}

@EventListener
public void onCreateRemoteIssueLinkEvent(RemoteIssueLinkCreateEvent remoteIssueLinkCreateEvent)
{
LOG.error("Create - TEST");
LOG.error("Create -: "+ remoteIssueLinkCreateEvent.getRemoteIssueLinkId());
LOG.error("Create -: "+ remoteIssueLinkCreateEvent.getGlobalId());

LOG.error("TEST: "+ (remoteIssueLinkManager == null));
Long id = remoteIssueLinkCreateEvent.getRemoteIssueLinkId();
LOG.error("id: "+ id);

RemoteIssueLink remoteIssueLink = remoteIssueLinkManager.getRemoteIssueLink(id);
LOG.error("Link: "+ (remoteIssueLink == null));
}

@EventListener
public void onCreateUiRemoteIssueLinkEvent(RemoteIssueLinkUICreateEvent remoteIssueLinkUiCreateEvent) {
LOG.error("Create UI - TEST");
LOG.error("Create UI -: "+ remoteIssueLinkUiCreateEvent.getRemoteIssueLinkId());
LOG.error("Create UI-: "+ remoteIssueLinkUiCreateEvent.getGlobalId());

LOG.error("TEST: UI"+ (remoteIssueLinkManager == null));
Long id = remoteIssueLinkUiCreateEvent.getRemoteIssueLinkId();
LOG.error("id: "+ id);

RemoteIssueLink remoteIssueLink = remoteIssueLinkManager.getRemoteIssueLink(id);
LOG.error("Link: "+ (remoteIssueLink == null));

}
}

4 answers

0 votes
Robert P January 28, 2021

Hi,

is there a "workaround" for web links also?

I understand Atlassian is not willing to fix https://jira.atlassian.com/browse/JRASERVER-45989. However, I would have to implement a listener that fires when an external web link is added to an issue. So I thought the "RemoteIssueLinkCreateEvent" would be the way to go - however, all the properties are empty/null:

[c.o.scriptrunner.runner.ScriptBindingsManager] <com.atlassian.jira.event.issue.link.RemoteIssueLinkCreateEvent@7591499 applicationType=null remoteIssueLinkId=null globalId=null>

I'm kind of stuck here... :-(

 

PS: sorry, obviously this is not an answer but I didn't want to start another topic for the same problem.

0 votes
Dmitrii March 31, 2020

@Vladimir Kibe , Hi, we thought about the solution you have suggested, but we investigated this issue and got root cause of issue is a bug in DefaultRemoteIssueLinkManager in Jira sources (8,2.1) in function createRemoteIssueLink. 

...
eventPublisher
.publish(new RemoteIssueLinkCreateEvent(remoteIssueLink)) 
... 

 "remoteIssueLink" is temporary object that used for creating remote link in DB of Jira and it also doesn't contain id of remote link.

We got from Atlassian Support answer, that they don't support support such developing request from clients, so we was forced to fix bug ourself. Below you can find we fixed this issue in soruces

...
eventPublisher
.publish(new RemoteIssueLinkCreateEvent(created));
...

 "created" is object that was generated after creating new remote link in jira db.

Also if you like this fix and you have access to jira sources, you can find below article from Atlassian How to compile jira sources

https://developer.atlassian.com/server/jira/platform/building-jira-from-source/

0 votes
Vladimir Kibe March 30, 2020
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.link.RemoteIssueLinkCreateEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

if(event instanceof RemoteIssueLinkCreateEvent) {
RemoteIssueLinkManager rm = ComponentAccessor.getComponent(RemoteIssueLinkManager.class)
IssueManager im = ComponentAccessor.getIssueManager()

RemoteIssueLinkCreateEvent event = (RemoteIssueLinkCreateEvent) event

List<RemoteIssueLink> links = rm.findRemoteIssueLinksByGlobalIds([event.globalId])

for (RemoteIssueLink link : links) {
Issue issue = im.getIssueObject(557230)
log.error(issue.key)
}
}






Like that you get issue object
0 votes
Vladimir Kibe March 30, 2020

i'm too looking solve this problem....

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events