Exemple #1
1
 public static void toInProgress(JiraRestClient restClient, Issue issue) {
   Iterable<Transition> transitions = null;
   Transition assignToRunTransition = null, inProgressTransition = null, reRunTransition = null;
   String statusName = issue.getStatus().getName();
   System.out.println("status is " + statusName + "/" + issue.getTransitionsUri().toString());
   if (statusName.equals("Create") || statusName.equals("Open") || statusName.equals("Reopened")) {
     // do nothing
     transitions = restClient.getIssueClient().getTransitions(issue.getTransitionsUri()).claim();
     inProgressTransition = getTransitionByName(transitions, "Start Progress");
     restClient
         .getIssueClient()
         .transition(
             issue.getTransitionsUri(), new TransitionInput(4 /*inProgressTransition.getId()*/))
         .claim();
   } else if (statusName.equals("In Progress")) {
     /*只能在这里获得, 因为状态不同, transition不同*/
   } else if (statusName.equals("Resolved")) {
     transitions = restClient.getIssueClient().getTransitions(issue.getTransitionsUri()).claim();
     inProgressTransition = getTransitionByName(transitions, "Reopen Issue");
     restClient
         .getIssueClient()
         .transition(issue.getTransitionsUri(), new TransitionInput(inProgressTransition.getId()))
         .claim();
     transitions = restClient.getIssueClient().getTransitions(issue.getTransitionsUri()).claim();
     assignToRunTransition = getTransitionByName(transitions, "Start Progress");
     restClient
         .getIssueClient()
         .transition(issue.getTransitionsUri(), new TransitionInput(assignToRunTransition.getId()))
         .claim();
   } else if (statusName.equals("Closed")) {
     System.out.println(issue.getId() + ", " + statusName + ", closed, do nothing.");
   } else {
     /*状态修改过, 程序没有改动.*/
     throw new RuntimeException("status error.");
   }
 }
  /**
   * 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;
    }
  }
Exemple #3
0
 public static void toPassed(JiraRestClient restClient, Issue issue) {
   toInProgress(restClient, issue);
   /*必须在这里获得, 因为上面转换了状态*/
   final Iterable<Transition> transitions =
       restClient.getIssueClient().getTransitions(issue.getTransitionsUri()).claim();
   final Transition passTransition = getTransitionByName(transitions, "Resolve Issue");
   restClient
       .getIssueClient()
       .transition(issue.getTransitionsUri(), new TransitionInput(passTransition.getId()))
       .claim();
 }
  public SearchResult getIssues(String projectKey, int startAt, int resultsSize, String updated)
      throws ExecutionException, InterruptedException {
    String jqlQuery = "project=" + projectKey;

    if (updated != null) {
      jqlQuery += " AND updated > -" + updated;
    }

    Set<String> fields =
        new HashSet<>(
            Arrays.asList(
                "summary",
                "issuetype",
                "created",
                "updated",
                "project",
                "status",
                "reporter",
                "assignee"));
    Promise<SearchResult> result =
        restClient.getSearchClient().searchJql(jqlQuery, resultsSize, startAt, fields);

    return result.get();
  }
 public Issue getIssue(String key) throws ExecutionException, InterruptedException {
   return restClient.getIssueClient().getIssue(key).get();
 }
  public Iterable<BasicProject> getProjects() throws ExecutionException, InterruptedException {
    Promise<Iterable<BasicProject>> projects = restClient.getProjectClient().getAllProjects();

    return projects.get();
  }
  /*
   * (non-Javadoc)
   * @see org.opennms.api.integration.ticketing.Plugin#saveOrUpdate(org.opennms.api.integration.ticketing.Ticket)
   */
  @Override
  public void saveOrUpdate(Ticket ticket) throws PluginException {

    JiraRestClient jira = getConnection();

    if (ticket.getId() == null || ticket.getId().equals("")) {
      // If we can't find a ticket with the specified ID then create one.
      IssueInputBuilder builder =
          new IssueInputBuilder(
              getProperties().getProperty("jira.project"),
              Long.valueOf(getProperties().getProperty("jira.type").trim()));
      builder.setReporterName(getProperties().getProperty("jira.username"));
      builder.setSummary(ticket.getSummary());
      builder.setDescription(ticket.getDetails());
      builder.setDueDate(new DateTime(Calendar.getInstance()));

      BasicIssue createdIssue;
      try {
        createdIssue = jira.getIssueClient().createIssue(builder.build()).get();
      } catch (InterruptedException | ExecutionException e) {
        throw new PluginException("Failed to create issue.", e);
      }
      LOG.info("created ticket " + createdIssue);

      ticket.setId(createdIssue.getKey());

    } else {
      // Otherwise update the existing ticket
      LOG.info("Received ticket: {}", ticket.getId());

      Issue issue;
      try {
        issue = jira.getIssueClient().getIssue(ticket.getId()).get();
      } catch (InterruptedException | ExecutionException e) {
        throw new PluginException("Failed to get issue with id:" + ticket.getId(), e);
      }

      Iterable<Transition> transitions;
      try {
        transitions = jira.getIssueClient().getTransitions(issue).get();
      } catch (InterruptedException | ExecutionException e) {
        throw new PluginException(
            "Failed to get transitions for issue with id:" + issue.getId(), e);
      }

      if (Ticket.State.CLOSED.equals(ticket.getState())) {
        Comment comment = Comment.valueOf("Issue resolved by OpenNMS.");
        for (Transition transition : transitions) {
          if (getProperties().getProperty("jira.resolve").equals(transition.getName())) {
            LOG.info("Resolving ticket {}", ticket.getId());
            // Resolve the issue
            try {
              jira.getIssueClient()
                  .transition(issue, new TransitionInput(transition.getId(), comment))
                  .get();
            } catch (InterruptedException | ExecutionException e) {
              throw new PluginException("Failed to get resolve issue with id:" + issue.getId(), e);
            }
            return;
          }
        }
        LOG.warn(
            "Could not resolve ticket {}, no '{}' operation available.",
            ticket.getId(),
            getProperties().getProperty("jira.resolve"));
      } else if (Ticket.State.OPEN.equals(ticket.getState())) {
        Comment comment = Comment.valueOf("Issue reopened by OpenNMS.");
        for (Transition transition : transitions) {
          if (getProperties().getProperty("jira.reopen").equals(transition.getName())) {
            LOG.info("Reopening ticket {}", ticket.getId());
            // Resolve the issue
            try {
              jira.getIssueClient()
                  .transition(issue, new TransitionInput(transition.getId(), comment))
                  .get();
            } catch (InterruptedException | ExecutionException e) {
              throw new PluginException("Failed to reopen issue with id:" + issue.getId(), e);
            }
            return;
          }
        }
        LOG.warn(
            "Could not reopen ticket {}, no '{}' operation available.",
            ticket.getId(),
            getProperties().getProperty("jira.reopen"));
      }
    }
  }