Search in sources :

Example 1 with Issue

use of com.atlassian.jira.rest.client.api.domain.Issue in project opennms by OpenNMS.

the class JiraTicketerPlugin method getInternal.

private Ticket getInternal(String ticketId, JiraRestClient jira) throws PluginException {
    // 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;
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) PluginException(org.opennms.api.integration.ticketing.PluginException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with Issue

use of com.atlassian.jira.rest.client.api.domain.Issue in project opennms by OpenNMS.

the class JiraTicketerPlugin method saveOrUpdateInternal.

private void saveOrUpdateInternal(Ticket ticket, JiraRestClient jira) throws PluginException {
    Config config = getConfig();
    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(config.getProjectKey(), config.getIssueTypeId());
        builder.setReporterName(config.getUsername());
        builder.setSummary(ticket.getSummary());
        builder.setDescription(ticket.getDetails());
        populateFields(ticket, builder);
        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 (config.getResolveTransitionName().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(), getConfig().getResolveTransitionName());
        } else if (Ticket.State.OPEN.equals(ticket.getState())) {
            Comment comment = Comment.valueOf("Issue reopened by OpenNMS.");
            for (Transition transition : transitions) {
                if (getConfig().getReopentransitionName().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(), getConfig().getReopentransitionName());
        }
    }
}
Also used : Comment(com.atlassian.jira.rest.client.api.domain.Comment) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) PluginException(org.opennms.api.integration.ticketing.PluginException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 ExecutionException (java.util.concurrent.ExecutionException)2 PluginException (org.opennms.api.integration.ticketing.PluginException)2 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 IssueInputBuilder (com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)1 TransitionInput (com.atlassian.jira.rest.client.api.domain.input.TransitionInput)1 Ticket (org.opennms.api.integration.ticketing.Ticket)1