/** * Implementation of TicketerPlugin API call to retrieve a Jira trouble ticket. * * @return an OpenNMS * @throws PluginException */ @Override public Ticket get(String ticketId) throws PluginException { JiraRestClient jira = getConnection(); if (jira == null) { return null; } // w00t Issue issue; try { issue = jira.getIssueClient().getIssue(ticketId).get(); } catch (InterruptedException | ExecutionException e) { throw new PluginException("Failed to get issue with id: " + ticketId, e); } if (issue != null) { Ticket ticket = new Ticket(); ticket.setId(issue.getKey()); ticket.setModificationTimestamp(String.valueOf(issue.getUpdateDate().toDate().getTime())); ticket.setSummary(issue.getSummary()); ticket.setDetails(issue.getDescription()); ticket.setState(getStateFromStatusName(issue.getStatus().getName())); return ticket; } else { return null; } }
public void testUpdate() throws Exception { String summary = "A Ticket at " + new Date(); Ticket ticket = new Ticket(); ticket.setState(Ticket.State.OPEN); ticket.setSummary(summary); ticket.setDetails("Ticket details for ticket: " + new Date()); m_ticketer.saveOrUpdate(ticket); assertNotNull(ticket.getId()); Ticket newTicket = m_ticketer.get(ticket.getId()); assertNotNull(newTicket); assertTicketEquals(ticket, newTicket); newTicket.setState(Ticket.State.CLOSED); newTicket.setDetails("These details have changed"); System.err.println("TicketId = " + newTicket.getId()); m_ticketer.saveOrUpdate(newTicket); Thread.sleep(500); Ticket newerTicket = m_ticketer.get(newTicket.getId()); assertTicketEquals(newTicket, newerTicket); }
public void testSave() { Ticket ticket = new Ticket(); ticket.setState(Ticket.State.OPEN); ticket.setSummary("This is the summary"); ticket.setDetails("These are the details"); m_ticketer.saveOrUpdate(ticket); assertNotNull(ticket.getId()); Ticket newTicket = m_ticketer.get(ticket.getId()); assertNotNull(newTicket); assertTicketEquals(ticket, newTicket); }
/* * (non-Javadoc) * @see org.opennms.api.integration.ticketing.Plugin#get(java.lang.String) */ @Override public Ticket get(String ticketId) throws PluginException { Objects.requireNonNull(ticketId, "Please provide a ticketId"); Objects.requireNonNull( m_ticketConnector, "The GenericTicketConnector was not initialized properly"); TicketGet ticketGet = new TicketGet(); ticketGet.setUserLogin(m_configDao.getUserName()); ticketGet.setPassword(m_configDao.getPassword()); ticketGet.setTicketID(new BigInteger[] {new BigInteger(ticketId)}); TicketGetResponse response = m_ticketConnector.ticketGet(ticketGet); LOG.debug("TicketGet responded with {} tickets" + response.getTicketLength()); if (response.getTicketLength() == 0) { // TODO error handling in this case } if (response.getTicketLength() > 1) { LOG.warn("Received more than 1 tickets, ignore all except the first one."); } final OTRSTicketGetResponseTicket otrsTicket = response.getTicket(0); Ticket opennmsTicket = new Ticket(); // add ticket basics from the OTRS ticket opennmsTicket.setId(otrsTicket.getTicketID().toString()); opennmsTicket.setSummary(otrsTicket.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(otrsTicket.getCustomerUserID()); opennmsTicket.setState(otrsToOpenNMSState(otrsTicket.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 (OTRSTicketGetResponseArticle article : otrsTicket.getArticle()) { LOG.debug("Adding Article details from OTRS article ID {}", article.getArticleID()); opennmsTicketDetails = new StringBuilder() .append(opennmsTicketDetails) .append("\n") .append("From: ") .append(article.getFrom()) .append("\n") .append("Subject: ") .append(article.getSubject()) .append("\n") .append("Body: ") .append(article.getBody()) .append("\n") .toString(); } opennmsTicket.setDetails(opennmsTicketDetails); return opennmsTicket; }