Search in sources :

Example 1 with TicketUpdate

use of org.otrs.ticketconnector.TicketUpdate 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)

Aggregations

BigInteger (java.math.BigInteger)1 Ticket (org.opennms.api.integration.ticketing.Ticket)1 OTRSArticle (org.otrs.ticketconnector.OTRSArticle)1 OTRSTicketCreateTicket (org.otrs.ticketconnector.OTRSTicketCreateTicket)1 OTRSTicketGetResponseTicket (org.otrs.ticketconnector.OTRSTicketGetResponseTicket)1 OTRSTicketUpdateTicket (org.otrs.ticketconnector.OTRSTicketUpdateTicket)1 TicketUpdate (org.otrs.ticketconnector.TicketUpdate)1