Can't fire a custom event

Şafak Şahin June 26, 2018

Hi,

I want to fire a custom event for a specific projects issue's creation.

To do that i create an event and trying to firing it from a plugin which i wrote.

I create this plugin because i need some arguments from the plugin's vm(view) and send these arguments to my listener where my business code is.

Here is my post-function execute method:

@SuppressWarnings("rawtypes")
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
try {
fireCustomCreateIssueEvent(args, getIssue(transientVars));
} catch (Exception e) {
Utils.printError(e, log);
}
}

Here is my firing an event method :

private void fireCustomCreateIssueEvent(Map args, Issue issue) throws Exception {
log.debug("*********************** Fire Custom Event Started ***********************");
log.debug("ISsue Key : " + issue.getKey());
log.debug("Selected Arguments " + args.toString());

long customCreateIssueEvent = 10003;

EventType eventType = ComponentAccessor.getEventTypeManager().getEventType(customCreateIssueEvent);
log.debug("Event name : " + eventType.getName() + " id : " + eventType.getId());
this.superUser = ComponentAccessor.getUserManager().getUserByName((String) args.get(Constants.USERNAME));

IssueEventManager issueEventManager = ComponentAccessor.getIssueEventManager();
IssueEventBundleFactory issueEventBundleFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class);
IssueEvent issueEvent = new IssueEvent(issue, args, superUser, eventType.getId());
IssueEventBundle issueEventBundle = issueEventBundleFactory.wrapInBundle(issueEvent);
issueEventManager.dispatchEvent(issueEventBundle);

log.debug("*********************** Fire Custom Event Executed ***********************");
}

 

Here is my listener:

@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
log.debug("******************** Event Listener Started ********************");
Long tekIssueCreatedEventId = Long.valueOf("10003");
Long eventTypeId = issueEvent.getEventTypeId();
Map args = issueEvent.getParams();
Issue issue = issueEvent.getIssue();
log.debug("Issue Event Type Id : " + eventTypeId);
log.debug("Event Arguments : " + args.toString());
log.debug("Issue Key : " + issue.getKey());

if(eventTypeId.equals(tekIssueCreatedEventId)) {
log.debug("***tek issue created event***");
foo(issue, args);
}
log.debug("******************** Event Listener Executed ********************");
}

 

Where do i wrong, can you help me please? 

1 answer

7 votes
Jonathan Muse _Appfire_
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.
July 24, 2018

Sorry but I don't know how to debug your script, looks pretty complicated. However, can I suggest something a little easier than building a whole add-on just to solve this one use case? With an add-on called Power Scripts you could basically do this in one line of code.

raiseEvent(event_name, issue, user);

 Actually, you wouldn't even need to do that. You could just raise the event using a standard Jira post function. You wouldn't need to pass any additional data because the listener script would have access to all the information in the ticket. Like this:

string eventID = argv[1];

if(eventID = "10003" && project == "PROJ" && type == "Bug") {

    //do something

}

I know this is not the answer to the question you were asking and you probably don't want to purchase another add-on. However, how much time did you spend writing that complicated looking script? How much time did you spend debugging it? How much time did you loose waiting for someone to answer this question? If you added all that time up what dollar amount would you give it? I spent more time writing this paragraph then I did writing all the code it would take to solve your use case. Something to think about.

Suggest an answer

Log in or Sign up to answer