Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Display Event Listener Result on Page

Joe bosch August 7, 2019

Hi, I am working on integrating a machine learning model I made into Jira. I have the model hosted on a server and I am attempting to integrate this such that whenever the description or another custom field is updated a request is sent to be evaluated. This request contains the text in the description and custom field and once assessed returns the value from the model. I want to display this result back to the user as a form of instant feedback.

I have currently been able to make an event listener to determine when either field is updated and send the fields to be assessed. I can't figure out at all how to show this result back to the user however. Ideally after an update there would be a bar alongside the description and custom field which shows the value from the model.

This is my plugin so far:

@Component
public class IssueCreatedResolvedListener implements InitializingBean, DisposableBean {
private static final Logger log = LoggerFactory.getLogger(IssueCreatedResolvedListener.class);

@
JiraImport
private final EventPublisher eventPublisher;

@Autowired
public IssueCreatedResolvedListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}

@Override
public void afterPropertiesSet() throws Exception {
log.info("Enabling Plugin");
eventPublisher.register(this);
}

@Override
public void destroy() throws Exception {
log.info("Killing Plugin");
eventPublisher.unregister(this);
}

@EventListener
public void onIssueEvent(IssueEvent issueEvent) throws Exception {
Long eventTypeID = issueEvent.getEventTypeId();
if(eventTypeID.equals(EventType.ISSUE_UPDATED_ID)) {
Issue issue = issueEvent.getIssue();
List changeItems = issueEvent.getChangeLog().getRelated("ChildChangeItem");
Iterator iter = changeItems.iterator();

while(iter.hasNext()) {
Map item = (Map) iter.next();
String request = "";
if(item.get("field").equals("description")) {
request += (String) item.get("newstring") + " " + (String) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Incident Resolution Comment"));
}
else if(item.get("field").equals("Incident Resolution Comment")) {
request += issue.getDescription() + " " + (String) item.get("newstring");
}
else
continue;
log.info("{} to be evaluated.", request);
URL url = new URL("http://127.0.0.1:8000/model/");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");

String urlParameters = "details=" + request;
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
log.info("Issue {} has the quality {}.", issue.getKey(), response.toString());
}
}
}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer