Search in sources :

Example 1 with Credentials

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

the class OtrsTicketerPluginTest method createTicketAndArticle.

// This is just to bootstrap a saved ticket so that we can get it back later
private TicketIDAndNumber createTicketAndArticle(String ticketSubject, String articleBody) throws InterruptedException {
    TicketIDAndNumber idAndNumber = null;
    m_configDao = new DefaultOtrsConfigDao();
    TicketCore otrsTicket = new TicketCore();
    Credentials creds = new Credentials(m_configDao.getUserName(), m_configDao.getPassword());
    otrsTicket.setLock(m_configDao.getLock());
    otrsTicket.setQueue(m_configDao.getQueue());
    otrsTicket.setPriority(m_configDao.getPriority());
    otrsTicket.setState(m_configDao.getState());
    otrsTicket.setOwnerID(m_configDao.getOwnerID());
    otrsTicket.setUser(defaultUser);
    otrsTicket.setTitle(ticketSubject);
    Integer articleId = null;
    TicketServiceLocator service = new TicketServiceLocator();
    service.setTicketServicePortEndpointAddress(m_configDao.getEndpoint());
    TicketServicePort_PortType port = null;
    try {
        port = service.getTicketServicePort();
    } catch (ServiceException e1) {
        e1.printStackTrace();
    }
    try {
        idAndNumber = port.ticketCreate(otrsTicket, creds);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    ArticleCore otrsArticle = new ArticleCore();
    otrsArticle.setArticleType(m_configDao.getArticleType());
    otrsArticle.setSenderType(m_configDao.getArticleSenderType());
    otrsArticle.setContentType(m_configDao.getArticleContentType());
    otrsArticle.setHistoryType(m_configDao.getArticleHistoryType());
    otrsArticle.setHistoryComment(m_configDao.getArticleHistoryComment());
    otrsArticle.setSenderType(m_configDao.getArticleSenderType());
    otrsArticle.setSubject(defaultArticleSubject);
    otrsArticle.setFrom(m_configDao.getArticleFrom());
    otrsArticle.setBody(defaultArticleBody);
    otrsArticle.setUser(defaultUser);
    otrsArticle.setTicketID(idAndNumber.getTicketID());
    otrsArticle.setBody(articleBody);
    try {
        articleId = port.articleCreate(otrsArticle, creds);
        assertNotNull(articleId);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return idAndNumber;
}
Also used : ArticleCore(org.opennms.integration.otrs.ticketservice.ArticleCore) ServiceException(javax.xml.rpc.ServiceException) DefaultOtrsConfigDao(org.opennms.netmgt.ticketer.otrs.common.DefaultOtrsConfigDao) TicketServicePort_PortType(org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType) RemoteException(java.rmi.RemoteException) TicketCore(org.opennms.integration.otrs.ticketservice.TicketCore) TicketServiceLocator(org.opennms.integration.otrs.ticketservice.TicketServiceLocator) Credentials(org.opennms.integration.otrs.ticketservice.Credentials) TicketIDAndNumber(org.opennms.integration.otrs.ticketservice.TicketIDAndNumber)

Example 2 with Credentials

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

the class OtrsTicketerPlugin method saveOrUpdate.

/**
 * {@inheritDoc}
 */
@Override
public void saveOrUpdate(Ticket newTicket) throws PluginException {
    TicketIDAndNumber idAndNumber = null;
    TicketServicePort_PortType port = getTicketServicePort(m_endpoint);
    Ticket currentTicket = null;
    Credentials creds = new Credentials();
    creds.setUser(m_configDao.getUserName());
    creds.setPass(m_configDao.getPassword());
    try {
        if ((newTicket.getId() == null)) {
            idAndNumber = newOTRSTicket(newTicket, port, creds);
            newTicket.setId(String.valueOf(idAndNumber.getTicketNumber()));
            LOG.debug("created new ticket: {}", newTicket.getId());
            newOTRSArticle(idAndNumber.getTicketNumber(), newTicket, port, creds);
        } else {
            currentTicket = get(newTicket.getId());
            LOG.debug("updating existing ticket : {}", currentTicket.getId());
            if (currentTicket.getState() != newTicket.getState()) {
                updateOTRSState(newTicket, port, creds);
                updateOTRSArticle(Long.parseLong(currentTicket.getId()), newTicket, port, creds);
            } else {
            // There is no else at the moment
            // Tickets are _only_ updated with new state
            }
        }
    } catch (RemoteException e) {
        LOG.error("Failed to create or update OTRS ticket", e);
        throw new PluginException("Failed to create or update OTRS ticket");
    }
}
Also used : TicketServicePort_PortType(org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType) RemoteException(java.rmi.RemoteException) Credentials(org.opennms.integration.otrs.ticketservice.Credentials) TicketIDAndNumber(org.opennms.integration.otrs.ticketservice.TicketIDAndNumber)

Example 3 with Credentials

use of org.opennms.integration.otrs.ticketservice.Credentials 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)3 Credentials (org.opennms.integration.otrs.ticketservice.Credentials)3 TicketServicePort_PortType (org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType)3 TicketIDAndNumber (org.opennms.integration.otrs.ticketservice.TicketIDAndNumber)2 ServiceException (javax.xml.rpc.ServiceException)1 Article (org.opennms.integration.otrs.ticketservice.Article)1 ArticleCore (org.opennms.integration.otrs.ticketservice.ArticleCore)1 TicketCore (org.opennms.integration.otrs.ticketservice.TicketCore)1 TicketServiceLocator (org.opennms.integration.otrs.ticketservice.TicketServiceLocator)1 TicketWithArticles (org.opennms.integration.otrs.ticketservice.TicketWithArticles)1 DefaultOtrsConfigDao (org.opennms.netmgt.ticketer.otrs.common.DefaultOtrsConfigDao)1