Friday, 29 June 2012

How to add a Listner in Jira platform

Though I have started blogging some time back in feb'12, I was not consistent in my posts. But, now onwards, I will try to post about jira platform consistently. Today, I will share about how listener can be configured in jira platform.

As literally speaking, LISTENER is some body/thing who listens and does the job based on what has happened on a particular event. It's the same on jira platform as well.

Jira has given one abstraction for the listener, AbstractIssueEventListener.java So, if you want to create a listener for your jira platform, you need to extend this class and implement the required events. Once you deploy your plug-in on the jira platform, by default this listener will be configured to your jira platform. You may see this on the administration section of jira application.


Ex: ApplicationListene.java

import com.atlassian.jira.event.issue.AbstractIssueEventListener;

public class ApplicationListener extends AbstractIssueEventListener {

   
    Logger logger = Logger.getLogger(ApplicationListener.class);
   
    @Override
    public void issueCreated(IssueEvent event) {
                   // do what ever you want do on create issue event
        } catch (Exception e) {
            logger.error("Exception Caught while listening the event of issue creation: ", e);
        }
    }
   
    @Override
    public void issueUpdated(IssueEvent event) {
        try {
              // what ever you want to do on the issue update         
        } catch (Exception e) {
            logger.error("Exception Caught while listening the event of issue update: ", e);
        }
    }
   
    @Override
    public void issueDeleted(IssueEvent event) {
        super.issueDeleted(event);
        try {
           // do some thing
           
        } catch (Exception e) {
            this.logger.error("Exception Caught while listening the event of issue delete", e);
        }
    }

    @Override
    public void issueMoved(IssueEvent event) {
        try {
            // what ever you want to do on moving issue event
        } catch (Exception e) {
            this.logger.error("Exception Caught while listening the event of issue move: ", e);
        }
    }

    @Override
    public void issueResolved(IssueEvent event) {
        try {
              // do some thing on issue resolution
        } catch (Exception e) {
            logger.error("Exception Caught while listening the event of issue resolve :", e);
        }
    }

    @Override
    public void issueClosed(IssueEvent event) {
        try {
             // do some thing on close event of the issue
        } catch (Exception e) {
            logger.error("Exception Caught while listening the event of issue close :", e);
        }
    }
   
    @Override
    public void issueReopened(IssueEvent event) {
        try {
             // do some thing on when issue is re-opened
        } catch (Exception e) {
            logger.error("Exception Caught while listening the event of issue reopen :", e);
        }
    }
   
    @Override
    public void issueWorklogDeleted(IssueEvent event) {
        try {
              // do some thing on when work log is deleted on the issue          
        } catch (Exception e) {
            logger.error("Exception Caught while listening the event of worklog deletion on issue :", e);
        }
    }

    @Override
    public void issueWorkLogged(IssueEvent event) {
        // Implement this to do some action on when work is logged on issue
    }

    @Override
    public void issueWorklogUpdated(IssueEvent event) {
        // Implement this to do some action on when worklog is updated on issue
    }
   
    @Override
    public void issueGenericEvent(IssueEvent event) {
        // Implement this to do some action on Issue Generic Event
    }
   
    @Override
    public void issueAssigned(IssueEvent event) {
        // Implement this to do some action on Issue Assigned Event
    }

    @Override
    public void issueCommented(IssueEvent event) {
        // Implement this to do some action on Issue Commented Event
    }

    @Override
    public void issueCommentEdited(IssueEvent event) {
        // Implement this to do some action on Issue Comment Edit event
    }
   
 }


No comments:

Post a Comment