Search in sources :

Example 36 with Ticket

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

the class Otrs31TicketerPlugin method update.

private void update(Ticket ticketToUpdate) throws PluginException {
    Ticket currentTicket = get(ticketToUpdate.getId());
    LOG.debug("updating existing ticket : {}", currentTicket.getId());
    if (currentTicket.getState() != ticketToUpdate.getState()) {
        OTRSTicketUpdateTicket ticketUpdate = new OTRSTicketUpdateTicket();
        ticketUpdate.setStateID(openNMSToOTRSState(ticketToUpdate.getState()));
        OTRSArticle articleUpdate = new OTRSArticle();
        // TODO Figure out why we can't set ArticleFrom without an error from OTRS
        // otrsArticle.setFrom(m_configDao.getArticleFrom());
        articleUpdate.setSubject(m_configDao.getArticleUpdateSubject());
        // All OTRS article fields from defaults
        articleUpdate.setArticleType(m_configDao.getArticleType());
        articleUpdate.setSenderType(m_configDao.getArticleSenderType());
        articleUpdate.setContentType(m_configDao.getArticleContentType());
        articleUpdate.setHistoryType(m_configDao.getArticleHistoryType());
        articleUpdate.setHistoryComment(m_configDao.getArticleHistoryComment());
        switch(ticketToUpdate.getState()) {
            case OPEN:
                // ticket is new
                articleUpdate.setBody(m_configDao.getTicketOpenedMessage());
                break;
            case CANCELLED:
                // not sure how often we see this
                articleUpdate.setBody(m_configDao.getTicketCancelledMessage());
                break;
            case CLOSED:
                // closed successful
                articleUpdate.setBody(m_configDao.getTicketClosedMessage());
                break;
            default:
                LOG.debug("No valid OpenNMS state on ticket");
                articleUpdate.setBody(m_configDao.getTicketUpdatedMessage());
        }
        TicketUpdate update = new TicketUpdate();
        update.setUserLogin(m_configDao.getUserName());
        update.setPassword(m_configDao.getPassword());
        update.setTicketID(new BigInteger(currentTicket.getId()));
        update.setTicket(ticketUpdate);
        update.setArticle(articleUpdate);
        m_ticketConnector.ticketUpdate(update);
    } else {
    // There is no else at the moment
    // Tickets are _only_ updated with new state
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) OTRSTicketGetResponseTicket(org.otrs.ticketconnector.OTRSTicketGetResponseTicket) OTRSTicketUpdateTicket(org.otrs.ticketconnector.OTRSTicketUpdateTicket) OTRSTicketCreateTicket(org.otrs.ticketconnector.OTRSTicketCreateTicket) TicketUpdate(org.otrs.ticketconnector.TicketUpdate) OTRSTicketUpdateTicket(org.otrs.ticketconnector.OTRSTicketUpdateTicket) BigInteger(java.math.BigInteger) OTRSArticle(org.otrs.ticketconnector.OTRSArticle)

Example 37 with Ticket

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

the class OtrsTicketerPluginTest method setUp.

@Override
protected void setUp() throws Exception {
    System.setProperty("opennms.home", "src" + File.separatorChar + "test" + File.separatorChar + "opennms-home");
    System.out.println("src" + File.separatorChar + "test" + File.separatorChar + "opennms-home");
    m_ticketer = new OtrsTicketerPlugin();
    m_configDao = new DefaultOtrsConfigDao();
    m_ticket = new Ticket();
    m_ticket.setState(Ticket.State.OPEN);
    m_ticket.setSummary("Ticket Summary for ticket: " + new Date());
    m_ticket.setDetails("First Article for ticket: " + new Date());
    m_ticket.setUser("root@localhost");
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) DefaultOtrsConfigDao(org.opennms.netmgt.ticketer.otrs.common.DefaultOtrsConfigDao) Date(java.util.Date)

Example 38 with Ticket

use of org.opennms.api.integration.ticketing.Ticket 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 39 with Ticket

use of org.opennms.api.integration.ticketing.Ticket 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 40 with Ticket

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

the class TsrmMockTest method testSaveWithMock.

@Test
public void testSaveWithMock() throws PluginException {
    CreateSHSIMPINCType createIncidentType = new CreateSHSIMPINCType();
    CreateSHSIMPINCResponseType incidentResponse = new CreateSHSIMPINCResponseType();
    INCIDENTMboKeySetType incidentMboKeyType = new INCIDENTMboKeySetType();
    INCIDENTKeyType incidentKey = new INCIDENTKeyType();
    MXStringType incidentId = new MXStringType();
    incidentId.setValue(INCIDENT_ID);
    incidentKey.setTICKETID(incidentId);
    incidentResponse.setINCIDENTMboKeySet(incidentMboKeyType);
    incidentMboKeyType.getINCIDENT().add(incidentKey);
    when(port.createSHSIMPINC(argThat(new CreateIncidentArg()))).thenReturn(incidentResponse);
    port.createSHSIMPINC(createIncidentType);
    Ticket ticket = new Ticket();
    m_ticketer.saveOrUpdate(ticket);
    verify(port).createSHSIMPINC(createIncidentType);
    assertEquals(ticket.getId(), INCIDENT_ID);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) CreateSHSIMPINCType(com.ibm.maximo.CreateSHSIMPINCType) INCIDENTMboKeySetType(com.ibm.maximo.INCIDENTMboKeySetType) INCIDENTKeyType(com.ibm.maximo.INCIDENTKeyType) CreateSHSIMPINCResponseType(com.ibm.maximo.CreateSHSIMPINCResponseType) MXStringType(com.ibm.maximo.MXStringType) Test(org.junit.Test)

Aggregations

Ticket (org.opennms.api.integration.ticketing.Ticket)46 PluginException (org.opennms.api.integration.ticketing.PluginException)15 Date (java.util.Date)9 Test (org.junit.Test)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 MXStringType (com.ibm.maximo.MXStringType)3 Properties (java.util.Properties)3 Plugin (org.opennms.api.integration.ticketing.Plugin)3 DataRetrievalFailureException (org.springframework.dao.DataRetrievalFailureException)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 QuerySHSIMPINCResponseType (com.ibm.maximo.QuerySHSIMPINCResponseType)2 QuerySHSIMPINCType (com.ibm.maximo.QuerySHSIMPINCType)2 SHSIMPINCINCIDENTType (com.ibm.maximo.SHSIMPINCINCIDENTType)2 File (java.io.File)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2