Search in sources :

Example 11 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class JiraTicketerPlugin method saveOrUpdateInternal.

private void saveOrUpdateInternal(Ticket ticket, JiraRestClient jira) throws PluginException {
    Config config = getConfig();
    if (ticket.getId() == null || ticket.getId().equals("")) {
        // If we can't find a ticket with the specified ID then create one.
        IssueInputBuilder builder = new IssueInputBuilder(config.getProjectKey(), config.getIssueTypeId());
        builder.setReporterName(config.getUsername());
        builder.setSummary(ticket.getSummary());
        builder.setDescription(ticket.getDetails());
        populateFields(ticket, builder);
        BasicIssue createdIssue;
        try {
            createdIssue = jira.getIssueClient().createIssue(builder.build()).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new PluginException("Failed to create issue.", e);
        }
        LOG.info("created ticket " + createdIssue);
        ticket.setId(createdIssue.getKey());
    } else {
        // Otherwise update the existing ticket
        LOG.info("Received ticket: {}", ticket.getId());
        Issue issue;
        try {
            issue = jira.getIssueClient().getIssue(ticket.getId()).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new PluginException("Failed to get issue with id:" + ticket.getId(), e);
        }
        Iterable<Transition> transitions;
        try {
            transitions = jira.getIssueClient().getTransitions(issue).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new PluginException("Failed to get transitions for issue with id:" + issue.getId(), e);
        }
        if (Ticket.State.CLOSED.equals(ticket.getState())) {
            Comment comment = Comment.valueOf("Issue resolved by OpenNMS.");
            for (Transition transition : transitions) {
                if (config.getResolveTransitionName().equals(transition.getName())) {
                    LOG.info("Resolving ticket {}", ticket.getId());
                    // Resolve the issue
                    try {
                        jira.getIssueClient().transition(issue, new TransitionInput(transition.getId(), comment)).get();
                    } catch (InterruptedException | ExecutionException e) {
                        throw new PluginException("Failed to get resolve issue with id:" + issue.getId(), e);
                    }
                    return;
                }
            }
            LOG.warn("Could not resolve ticket {}, no '{}' operation available.", ticket.getId(), getConfig().getResolveTransitionName());
        } else if (Ticket.State.OPEN.equals(ticket.getState())) {
            Comment comment = Comment.valueOf("Issue reopened by OpenNMS.");
            for (Transition transition : transitions) {
                if (getConfig().getReopentransitionName().equals(transition.getName())) {
                    LOG.info("Reopening ticket {}", ticket.getId());
                    // Resolve the issue
                    try {
                        jira.getIssueClient().transition(issue, new TransitionInput(transition.getId(), comment)).get();
                    } catch (InterruptedException | ExecutionException e) {
                        throw new PluginException("Failed to reopen issue with id:" + issue.getId(), e);
                    }
                    return;
                }
            }
            LOG.warn("Could not reopen ticket {}, no '{}' operation available.", ticket.getId(), getConfig().getReopentransitionName());
        }
    }
}
Also used : Comment(com.atlassian.jira.rest.client.api.domain.Comment) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) PluginException(org.opennms.api.integration.ticketing.PluginException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class RemedyTicketerPluginTest method testSaveAndGet.

public void testSaveAndGet() {
    try {
        m_ticketer.saveOrUpdate(m_ticket);
        m_ticketId = m_ticket.getId();
        Ticket ticket = m_ticketer.get(m_ticketId);
        assertEquals(m_ticketId, ticket.getId());
        assertEquals(State.OPEN, ticket.getState());
    } catch (PluginException e) {
        e.printStackTrace();
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 13 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class OtrsTicketerPluginTest method testStateUpdate.

/*	
 *	This test deliberately removed.
 *	As there is no two way update, there is no need to ensure that 
 *      the OTRS ticket contents and the OpenNMS ticket contents match
 *	after the initial save.
 *
 *	public void testUpdate() {
 *		
 *		String firstArticle = new String("First Article");
 *		String secondArticle = new String("Second Article");
 *		
 *		// save with first article
 *		
 *		m_ticket.setDetails(firstArticle);
 *		
 *		m_ticketer.saveOrUpdate(m_ticket);
 *		
 *		// update with first article
 *		
 *		m_ticket.setDetails(secondArticle);
 *		
 *		m_ticketer.saveOrUpdate(m_ticket);
 *		
 *		// get a clean copy from the ID
 *		
 *		Ticket retrievedTicket = m_ticketer.get(m_ticket.getId());
 *		
 *		// compare the opennms ticket to one retrieved from OTRS
 *		
 *		assertTicketEquals(m_ticket, retrievedTicket);
 *		
 *		// should also have the first article as history
 *		
 *		// ensure that old ticket details still exist somewhere in the OTRS ticket
 *		
 *		if (retrievedTicket.getDetails().indexOf(firstArticle) <= 0 ) {
 *        		fail("could not find " + firstArticle + " in " + retrievedTicket.getDetails());
 *        	}
 *		
 *	}
 */
public void testStateUpdate() throws InterruptedException {
    try {
        m_ticketer.saveOrUpdate(m_ticket);
        // my new ticket should be open
        assertEquals(m_ticket.getState(), Ticket.State.OPEN);
        // set it cancelled
        m_ticket.setState(Ticket.State.CANCELLED);
        // and save it
        m_ticketer.saveOrUpdate(m_ticket);
        // sleep for a bit
        Thread.sleep(100);
        // get a new copy
        Ticket retrievedTicket = m_ticketer.get(m_ticket.getId());
        // my new copy should be closed
        assertEquals(retrievedTicket.getState(), Ticket.State.CANCELLED);
    } catch (PluginException e) {
        e.printStackTrace();
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 14 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class OtrsTicketerPluginTest method testSave.

public void testSave() {
    Ticket retrievedTicket = null;
    try {
        m_ticketer.saveOrUpdate(m_ticket);
        retrievedTicket = m_ticketer.get(m_ticket.getId());
    } catch (PluginException e) {
        e.printStackTrace();
    }
    assertTicketEquals(m_ticket, retrievedTicket);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 15 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class RemedyTicketerPluginTest method testClosedToCancelledStatus.

public void testClosedToCancelledStatus() {
    testSaveAndGet();
    try {
        Ticket ticket = m_ticketer.get(m_ticketId);
        assertEquals(State.OPEN, ticket.getState());
        //Close the Ticket
        m_ticket.setState(State.CLOSED);
        m_ticketer.saveOrUpdate(m_ticket);
        ticket = m_ticketer.get(m_ticketId);
        assertEquals(State.CLOSED, ticket.getState());
        //Cancel the Ticket
        m_ticket.setState(State.CANCELLED);
        m_ticketer.saveOrUpdate(m_ticket);
        ticket = m_ticketer.get(m_ticketId);
        assertEquals(State.CANCELLED, ticket.getState());
        // try to re open
        m_ticket.setState(State.OPEN);
        m_ticketer.saveOrUpdate(m_ticket);
        // but still cancelled
        ticket = m_ticketer.get(m_ticketId);
        assertEquals(State.CANCELLED, ticket.getState());
        // try to close
        m_ticket.setState(State.CLOSED);
        m_ticketer.saveOrUpdate(m_ticket);
        // but still cancelled
        ticket = m_ticketer.get(m_ticketId);
        assertEquals(State.CANCELLED, ticket.getState());
    } catch (PluginException e) {
        e.printStackTrace();
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException)

Aggregations

PluginException (org.opennms.api.integration.ticketing.PluginException)23 Ticket (org.opennms.api.integration.ticketing.Ticket)16 Test (org.junit.Test)5 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 ExecutionException (java.util.concurrent.ExecutionException)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 RTTicket (org.opennms.netmgt.rt.RTTicket)2 RequestTrackerException (org.opennms.netmgt.rt.RequestTrackerException)2 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)1 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1 ServerInfo (com.atlassian.jira.rest.client.api.domain.ServerInfo)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 IssueInputBuilder (com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)1 TransitionInput (com.atlassian.jira.rest.client.api.domain.input.TransitionInput)1 TicketIDAndNumber (org.opennms.integration.otrs.ticketservice.TicketIDAndNumber)1