示例#1
0
  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

    }
  }
示例#2
0
  private void create(Ticket newTicket) throws Otrs31PluginException {
    final String summary = newTicket.getSummary().replaceAll("\\<.*?\\>", "");

    // TODO Check whether we should use the OpenNMS ticket for this
    // The original OTRS plugin checks this and sets if there is a user
    // in the OpenNMS ticket. Suspect this may just cause pain as the
    // OpenNMS user is unlikely to be a valid OTRS customer user.

    final OTRSTicketCreateTicket otrsTicket = new OTRSTicketCreateTicket();
    otrsTicket.setCustomerUser(m_configDao.getDefaultUser());
    otrsTicket.setTitle(summary);
    otrsTicket.setQueue(m_configDao.getQueue());
    otrsTicket.setStateID(openNMSToOTRSState(newTicket.getState()));
    otrsTicket.setPriority(m_configDao.getPriority());
    otrsTicket.setType(m_configDao.getType());

    OTRSArticle otrsArticle = new OTRSArticle();
    // TODO Figure out why we can't set ArticleFrom without an error from OTRS
    // otrsArticle.setFrom(m_configDao.getArticleFrom());
    otrsArticle.setSubject(summary);
    otrsArticle.setBody(newTicket.getDetails());
    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());

    TicketCreate createRequest = new TicketCreate();
    createRequest.setUserLogin(m_configDao.getUserName());
    createRequest.setPassword(m_configDao.getPassword());
    createRequest.setTicket(otrsTicket);
    createRequest.setArticle(otrsArticle);

    TicketCreateResponse response = m_ticketConnector.ticketCreate(createRequest);
    if (response.getError() != null) {
      throw new Otrs31PluginException(response.getError());
    }
    LOG.debug("Created new ticket with ID {}", response.getTicketID().toString());
    newTicket.setId(response.getTicketID().toString());
  }