Skip to content

Commit

Permalink
ConDec-507: Fix that event listeners are not working (#146)
Browse files Browse the repository at this point in the history
* Change import package for Component annotation in ConDecEventListener class to fix that event listeners are not working

* Rename DecXtractEventListener into JiraIssueTextExtractionEventListener

* Catch IllegalArgumentException in WebhookConnector post method that is thrown for invalid URLs

* Remove ignore annotation from TestPluginInitializer class

* Increment version to 2.2.1
  • Loading branch information
kleebaum authored Jun 26, 2019
1 parent e885166 commit 07a61c7
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.uhd.ifi.se.decision</groupId>
<artifactId>management.jira</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
<organization>
<name>Software Engineering Research Group, Heidelberg University</name>
<url>https://github.com/cures-hub</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener;

import aQute.bnd.annotation.component.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent;
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent;
import com.atlassian.plugin.spring.scanner.annotation.imports.JiraImport;

import de.uhd.ifi.se.decision.management.jira.model.DecisionKnowledgeElement;
import de.uhd.ifi.se.decision.management.jira.model.impl.DecisionKnowledgeElementImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
* This class is responsible for all the event listeners used in this plug-in.
*
* @see JiraIssueTextExtractionEventListener
* @see SummarizationEventListener
* @see WebhookEventListener
*/
@Component
public class ConDecEventListener implements InitializingBean, DisposableBean {

@JiraImport
private final EventPublisher eventPublisher;
private WebhookEventListener webhookEventListener;
private DecXtractEventListener decXtractEventListener;
private JiraIssueTextExtractionEventListener jiraIssueTextExtractionEventListener;
private SummarizationEventListener summarizationEventListener;

protected static final Logger LOGGER = LoggerFactory.getLogger(ConDecEventListener.class);

@Autowired
public ConDecEventListener(EventPublisher eventPublisher){
public ConDecEventListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
LOGGER.info("ConDec event listener was added to JIRA");
LOGGER.info("ConDec event listener object was created.");
webhookEventListener = new WebhookEventListener();
decXtractEventListener = new DecXtractEventListener();
jiraIssueTextExtractionEventListener = new JiraIssueTextExtractionEventListener();
summarizationEventListener = new SummarizationEventListener();
}

Expand All @@ -43,7 +52,7 @@ public ConDecEventListener(EventPublisher eventPublisher){
@Override
public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
LOGGER.info("ConDec event listener was added to JIRA.");
LOGGER.info("ConDec event listener was registered in JIRA.");
}

/**
Expand All @@ -58,26 +67,28 @@ public void destroy() throws Exception {
}

@EventListener
public void onIssueEvent(IssueEvent issueEvent){
public void onIssueEvent(IssueEvent issueEvent) {
if (issueEvent == null) {
return;
}
webhookEventListener.onIssueEvent(issueEvent);
decXtractEventListener.onIssueEvent(issueEvent);
jiraIssueTextExtractionEventListener.onIssueEvent(issueEvent);
summarizationEventListener.onIssueEvent(issueEvent);
}

@EventListener
public void onLinkCreatedIssueEvent(IssueLinkCreatedEvent linkCreatedEvent){
DecisionKnowledgeElement element = new DecisionKnowledgeElementImpl(linkCreatedEvent.getIssueLink().getSourceObject());
public void onLinkCreatedIssueEvent(IssueLinkCreatedEvent linkCreatedEvent) {
DecisionKnowledgeElement element = new DecisionKnowledgeElementImpl(
linkCreatedEvent.getIssueLink().getSourceObject());
webhookEventListener.onLinkEvent(element);
LOGGER.info("ConDec event listener on link create issue event triggered");
LOGGER.info("ConDec event listener on link create issue event was triggered.");
}

@EventListener
public void onLinkDeletedIssueEvent(IssueLinkDeletedEvent linkDeletedEvent) {
DecisionKnowledgeElement element = new DecisionKnowledgeElementImpl(linkDeletedEvent.getIssueLink().getSourceObject());
DecisionKnowledgeElement element = new DecisionKnowledgeElementImpl(
linkDeletedEvent.getIssueLink().getSourceObject());
webhookEventListener.onLinkEvent(element);
LOGGER.info("ConDec event listener on link deleted issue event triggered");
LOGGER.info("ConDec event listener on link deleted issue event was triggered.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import java.util.List;
import java.util.Map;

import de.uhd.ifi.se.decision.management.jira.extraction.ClassificationManagerForJiraIssueComments;
import org.ofbiz.core.entity.GenericEntityException;
import org.ofbiz.core.entity.GenericValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.IssueEvent;
Expand All @@ -18,6 +16,7 @@
import com.atlassian.jira.issue.comments.MutableComment;
import com.atlassian.jira.util.collect.MapBuilder;

import de.uhd.ifi.se.decision.management.jira.extraction.ClassificationManagerForJiraIssueComments;
import de.uhd.ifi.se.decision.management.jira.model.text.TextSplitter;
import de.uhd.ifi.se.decision.management.jira.persistence.ConfigPersistenceManager;
import de.uhd.ifi.se.decision.management.jira.persistence.JiraIssuePersistenceManager;
Expand All @@ -28,11 +27,11 @@
* in the knowledge graph when the user changes either a comment or the
* description of a JIRA issue.
*/
public class DecXtractEventListener{
public class JiraIssueTextExtractionEventListener {

private String projectKey;
private IssueEvent issueEvent;
private static final Logger LOGGER = LoggerFactory.getLogger(DecXtractEventListener.class);
private static final Logger LOGGER = LoggerFactory.getLogger(JiraIssueTextExtractionEventListener.class);

/**
* Locks the edit comment event function if a REST service edits comments.
Expand Down Expand Up @@ -108,7 +107,7 @@ private void handleNewComment() {
}

private void handleEditComment() {
if (DecXtractEventListener.editCommentLock) {
if (JiraIssueTextExtractionEventListener.editCommentLock) {
// If locked, a REST service is currently manipulating the comment and should
// not be handled by this event listener.
LOGGER.debug("DecXtract event listener:\nEditing comment is still locked.");
Expand All @@ -128,7 +127,7 @@ private void handleEditComment() {
}

private void handleUpdateDescription() {
if (DecXtractEventListener.editCommentLock) {
if (JiraIssueTextExtractionEventListener.editCommentLock) {
// If locked, a REST service is currently manipulating the comment and should
// not be handled by this event listener.
LOGGER.debug("DecXtract event listener:\nEditing description is still locked.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener;

import org.ofbiz.core.entity.GenericValue;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.changehistory.ChangeHistory;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.plugin.spring.scanner.annotation.imports.JiraImport;

import de.uhd.ifi.se.decision.management.jira.extraction.impl.CodeSummarizerImpl;
import de.uhd.ifi.se.decision.management.jira.persistence.ConfigPersistenceManager;
Expand All @@ -24,11 +17,10 @@
* Triggers the code summarization when JIRA issues are closed. Then, the
* summary is written into a new comment of the JIRA issue.
*/
public class SummarizationEventListener{
public class SummarizationEventListener {

private final ChangeHistoryManager changeManager = ComponentAccessor.getChangeHistoryManager();


public void onIssueEvent(IssueEvent issueEvent) {
String projectKey = issueEvent.getProject().getKey();
String jiraIssueKey = issueEvent.getIssue().getKey();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener;

import de.uhd.ifi.se.decision.management.jira.webhook.WebhookConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -10,13 +9,13 @@
import de.uhd.ifi.se.decision.management.jira.model.DecisionKnowledgeElement;
import de.uhd.ifi.se.decision.management.jira.model.impl.DecisionKnowledgeElementImpl;
import de.uhd.ifi.se.decision.management.jira.persistence.ConfigPersistenceManager;
import de.uhd.ifi.se.decision.management.jira.webhook.WebhookConnector;

/**
* Triggers the webhook when JIRA issues are created, updated, or deleted or
* when links between JIRA issues are created or deleted
*/
public class WebhookEventListener{

public class WebhookEventListener {

protected static final Logger LOGGER = LoggerFactory.getLogger(WebhookEventListener.class);

Expand All @@ -37,8 +36,8 @@ public void onIssueEvent(IssueEvent issueEvent) {
}
}

public void onLinkEvent(DecisionKnowledgeElement decisionKnowledgeElement){
if(!ConfigPersistenceManager.isWebhookEnabled(decisionKnowledgeElement.getProject().getProjectKey())){
public void onLinkEvent(DecisionKnowledgeElement decisionKnowledgeElement) {
if (!ConfigPersistenceManager.isWebhookEnabled(decisionKnowledgeElement.getProject().getProjectKey())) {
return;
}
WebhookConnector connector = new WebhookConnector(decisionKnowledgeElement.getProject().getProjectKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.atlassian.jira.user.ApplicationUser;

import de.uhd.ifi.se.decision.management.jira.ComponentGetter;
import de.uhd.ifi.se.decision.management.jira.eventlistener.DecXtractEventListener;
import de.uhd.ifi.se.decision.management.jira.eventlistener.JiraIssueTextExtractionEventListener;
import de.uhd.ifi.se.decision.management.jira.model.DecisionKnowledgeElement;
import de.uhd.ifi.se.decision.management.jira.model.DocumentationLocation;
import de.uhd.ifi.se.decision.management.jira.model.KnowledgeType;
Expand Down Expand Up @@ -346,7 +346,7 @@ public static boolean updatePartOfJiraIssueText(PartOfJiraIssueText element, App

String newBody = firstPartOfText + changedPartOfText + lastPartOfText;

DecXtractEventListener.editCommentLock = true;
JiraIssueTextExtractionEventListener.editCommentLock = true;
if (mutableComment == null) {
MutableIssue jiraIssue = (MutableIssue) sentence.getJiraIssue();
jiraIssue.setDescription(newBody);
Expand All @@ -355,7 +355,7 @@ public static boolean updatePartOfJiraIssueText(PartOfJiraIssueText element, App
mutableComment.setBody(newBody);
ComponentAccessor.getCommentManager().update(mutableComment, true);
}
DecXtractEventListener.editCommentLock = false;
JiraIssueTextExtractionEventListener.editCommentLock = false;

int lengthDifference = changedPartOfText.length() - sentence.getLength();
updateSentenceLengthForOtherSentencesInSameComment(sentence, lengthDifference);
Expand Down Expand Up @@ -655,10 +655,10 @@ private static int removeSentenceFromComment(PartOfJiraIssueText element) {
String newBody = mutableComment.getBody();
newBody = newBody.substring(0, element.getStartPosition()) + newBody.substring(element.getEndPosition());

DecXtractEventListener.editCommentLock = true;
JiraIssueTextExtractionEventListener.editCommentLock = true;
mutableComment.setBody(newBody);
ComponentAccessor.getCommentManager().update(mutableComment, true);
DecXtractEventListener.editCommentLock = false;
JiraIssueTextExtractionEventListener.editCommentLock = false;
return element.getEndPosition() - element.getStartPosition();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private boolean postKnowledgeTree(DecisionKnowledgeElement rootElement) {
return true;
}
LOGGER.error("Could not send webhook data. The HTTP response code is: " + httpResponse);
} catch (IOException e) {
} catch (IOException | IllegalArgumentException e) {
LOGGER.error("Could not send webhook data because of " + e.getMessage());
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public void testAddIssueTypeToSchemeIssueTypeFilledProjectKeyNull() {
PluginInitializer.addIssueTypeToScheme("Decision", null);
}

@Test
@Ignore
public void testAddIssueTypeToSchemeIssueTypeFilledProjectKeyFilled() {
initialization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.HashMap;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -90,17 +89,13 @@ public void testIssueDeleted() {
listener.onIssueEvent(event);
}

// TODO Needs to be fixed
@Ignore
@Test
public void testIssueLinkCreated() {
IssueLink link = new MockIssueLink(1);
IssueLinkCreatedEvent event = new IssueLinkCreatedEvent(link, null);
listener.onLinkCreatedIssueEvent(event);
}

// TODO Needs to be fixed
@Ignore
@Test
public void testIssueLinkDeleted() {
IssueLink link = new MockIssueLink(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import static org.junit.Assert.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import static org.junit.Assert.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import static org.junit.Assert.assertNotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uhd.ifi.se.decision.management.jira.eventlistener.decxtracteventlistener;
package de.uhd.ifi.se.decision.management.jira.eventlistener.jiraissuetextextractioneventlistener;

import java.util.HashMap;
import java.util.List;
Expand Down

0 comments on commit 07a61c7

Please sign in to comment.