Search in sources :

Example 1 with Article

use of org.opennms.integration.otrs.ticketservice.Article in project opennms by OpenNMS.

the class OtrsTicketerPlugin method get.

/** {@inheritDoc} */
@Override
public Ticket get(String ticketId) throws PluginException {
    TicketWithArticles ticketWithArticles = null;
    // don't try to get ticket if it's marked as not available
    Ticket opennmsTicket = new Ticket();
    if (ticketId == null) {
        LOG.error("No OTRS ticketID available in OpenNMS Ticket");
        throw new PluginException("No OTRS ticketID available in OpenNMS Ticket");
    } else {
        TicketServicePort_PortType port = getTicketServicePort(m_endpoint);
        if (port != null) {
            long otrsTicketNumber = Long.parseLong(ticketId.trim());
            Credentials creds = new Credentials();
            creds.setUser(m_configDao.getUserName());
            creds.setPass(m_configDao.getPassword());
            try {
                ticketWithArticles = port.getByNumber(otrsTicketNumber, creds);
            } catch (RemoteException e) {
                LOG.error("Failed to retrieve OTRS ticket", e);
                throw new PluginException("Failed to retrieve OTRS ticket");
            }
        }
    }
    // add ticket basics from the OTRS ticket
    LOG.debug("Adding Ticket details from OTRS ticket # {}", ticketWithArticles.getTicket().getTicketNumber());
    opennmsTicket.setId(ticketWithArticles.getTicket().getTicketNumber().toString());
    opennmsTicket.setSummary(ticketWithArticles.getTicket().getTitle());
    // Note that we user "Owner" from the OTRS ticket here. There is nothing to ensure
    // That this is a valid OpenNMS user
    opennmsTicket.setUser(ticketWithArticles.getTicket().getOwner());
    opennmsTicket.setState(otrsToOpenNMSState(ticketWithArticles.getTicket().getStateID()));
    LOG.debug("Retrieved ticket state : {}", otrsToOpenNMSState(ticketWithArticles.getTicket().getStateID()));
    // add all the article details from the OTRS ticket
    // this is not strictly essential as we have no way of viewing this atm.
    String opennmsTicketDetails = "";
    for (Article article : ticketWithArticles.getArticles()) {
        LOG.debug("Adding Article details from OTRS article ID {}", article.getArticleID());
        opennmsTicketDetails = opennmsTicketDetails + "\n" + "From:    " + article.getFrom() + "\n" + "Subject: " + article.getSubject() + "\n" + "Body:\n" + article.getBody() + "\n";
    }
    opennmsTicket.setDetails(opennmsTicketDetails);
    return opennmsTicket;
}
Also used : Article(org.opennms.integration.otrs.ticketservice.Article) TicketServicePort_PortType(org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType) TicketWithArticles(org.opennms.integration.otrs.ticketservice.TicketWithArticles) RemoteException(java.rmi.RemoteException) Credentials(org.opennms.integration.otrs.ticketservice.Credentials)

Aggregations

RemoteException (java.rmi.RemoteException)1 Article (org.opennms.integration.otrs.ticketservice.Article)1 Credentials (org.opennms.integration.otrs.ticketservice.Credentials)1 TicketServicePort_PortType (org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType)1 TicketWithArticles (org.opennms.integration.otrs.ticketservice.TicketWithArticles)1