I have created a machine learning model to provide instant feedback on issues. I am attempting to integrate this by using an event listener so that when the description or a custom field is updated to send the field to my model and then return the result to the user.
I have been able to integrate the event listener to send and receive the result from my model however I am unable to find anyway to display this back to the user. Ideally it would be a small meter next to the description or custom field. What is the method that is supposed to be used to display the results from an event listener?
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());
}
}
}
}