public Issue getIssue(String issueKey) throws Exception { final URI jiraServerUri = new URI("https://jira-domain"); final JiraRestClient restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(jiraServerUri, "user@domain.com", "password"); Promise issuePromise = restClient.getIssueClient().getIssue(issueKey); return Optional.ofNullable((Issue) issuePromise.claim()).orElseThrow(() -> new Exception("No such issue")); }
public List<Status> getStatuses() { try { final Iterable<Status> statuses = jiraRestClient.getMetadataClient().getStatuses() .get(timeout, TimeUnit.SECONDS); return Lists.newArrayList(statuses); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get statuses error. cause: " + e.getMessage(), e); return Collections.emptyList(); } }
private static void validateProjectKey(JiraRestClient client, String projectKey) { System.out.println("Validating project with key '" + projectKey + "'..."); try { if (client.getProjectClient().getProject(projectKey).get() == null) { throw new RuntimeException("Project with key = '" + projectKey + "' does not exist"); } } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Could not retrieve project data for project with key '" + projectKey + "' from jira", e); } System.out.println("OK"); }
updateStr + " \""; SearchResult searchResult = client.getSearchClient() .searchJql(query) .claim(); Issue jiraIssue = client.getIssueClient() .getIssue(issue.getKey(), Arrays.asList(new Expandos[] { searchResult = client.getSearchClient() .searchJql(query, maxResult, i + maxResult, null)
Project project = restClient.getProjectClient().getProject(jiraIssue.getProject().getSelf()).claim(); IssueInput update = WRAPPER.issueToFluentUpdate(issue, jiraIssue, project); IssueRestClient issueClient = restClient.getIssueClient(); issueClient.updateIssue(jiraIssue.getKey(), update).claim(); if (!JiraFields.hasSameIssueStatus(issue, jiraIssue)) {
JiraRestClient restClient; public boolean createIssue(IssueJiraDTO issueDTO) throws IOException{ final IssueInputBuilder builder = new IssueInputBuilder(PROJECT_KEY, issueDTO.getIssueType(), issueDTO.getSummary()); final ComponentRestClient componentClient = restClient.getComponentClient(); try { openClient(); //completamos los datos Component component = componentClient.getComponent(new URI(issueDTO.getComponent())).claim(); builder.setComponents(component); builder.setFieldValue(CODCESCEFIELDID, issueDTO.getCodcesce()); builder.setFieldValue(LINKCAFIELD, issueDTO.getLinkCA().trim()); builder.setFieldValue(SECURITYFIELD, ComplexIssueInputFieldValue.with("id", issueDTO.getSecurityLevel())); builder.setPriorityId(issueDTO.getPriority()); builder.setDescription(issueDTO.getDescription()); final IssueInput input = builder.build(); // create issue final IssueRestClient client = restClient.getIssueClient(); final BasicIssue issue = client.createIssue(input).claim(); logger.info("Incidencia creada correctamente: "+ issue.getId()); }catch(Exception e){ logger.error("Error al crear la Issue en Jira: " + issueDTO.getCodcesce(), e); } finally { closeClient(); } return true; }
private List<Issue> searchIssues(String jql, int maxResults) { try { Set<String> fields = new HashSet<>(); fields.add("*all"); return paginateResults(restClient.getSearchClient(), jql, fields, maxResults); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
@Override public void destroy() { try { restClient.close(); } catch (IOException e) { LOG.warn("destroyin jira issue tracker", e); } }
public List<Issue> getIssuesFromJqlSearch(String jqlSearch, Integer maxResults) throws TimeoutException { try { final SearchResult searchResult = jiraRestClient.getSearchClient() .searchJql(jqlSearch, maxResults, 0, null) .get(timeout, TimeUnit.SECONDS); return Lists.newArrayList(searchResult.getIssues()); } catch(TimeoutException e) { LOGGER.log(WARNING, "jira rest client timeout from jql search error. cause: " + e.getMessage(), e); throw e; } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get issue from jql search error. cause: " + e.getMessage(), e); return Collections.emptyList(); } }
@Override public Object execute() throws Exception { JiraRestClient jiraClient = createJiraClient(); try { doExecute(jiraClient); } finally { jiraClient.close(); } return null; }
public Issue getIssue(String issueKey) { try { return jiraRestClient.getIssueClient().getIssue(issueKey).get(timeout, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get issue error. cause: " + e.getMessage(), e); return null; } }
private static void validateProjectKey(JiraRestClient client, String projectKey) { System.out.println("Validating project with key '" + projectKey + "'..."); try { if (client.getProjectClient().getProject(projectKey).get() == null) { throw new RuntimeException("Project with key = '" + projectKey + "' does not exist"); } } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Could not retrieve project data for project with key '" + projectKey + "' from jira", e); } System.out.println("OK"); }
public List<IssueType> getIssueTypes() { try { return Lists.newArrayList(jiraRestClient.getMetadataClient().getIssueTypes().get(timeout, TimeUnit.SECONDS)); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get issue types error. cause: " + e.getMessage(), e); return Collections.emptyList(); } }
private String getJQLFromFilter(URL filterUrl) throws NotFoundException { try { // url type example https://issues.jboss.org/rest/api/latest/filter/12322199 SearchRestClient searchClient = restClient.getSearchClient(); Filter filter = searchClient.getFilter(filterUrl.toURI()).get(); return filter.getJql(); } catch (Exception e) { throw new NotFoundException("Unable to retrieve filter with url: " + filterUrl, e); } }
@Override public Object execute() throws Exception { JiraRestClient jiraClient = createJiraClient(); try { doExecute(jiraClient); } finally { jiraClient.close(); } return null; }
public List<Transition> getAvailableActions(String issueKey) { final Issue issue = getIssue(issueKey); try { final Iterable<Transition> transitions = jiraRestClient.getIssueClient() .getTransitions(issue) .get(timeout, TimeUnit.SECONDS); return Lists.newArrayList(transitions); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get available actions error. cause: " + e.getMessage(), e); return Collections.emptyList(); } }
public List<String> getProjectsKeys() { Iterable<BasicProject> projects = Collections.emptyList(); try { projects = jiraRestClient.getProjectClient().getAllProjects().get(timeout, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get project keys error. cause: " + e.getMessage(), e); } final List<String> keys = new ArrayList<>(); for (BasicProject project : projects) { keys.add(project.getKey()); } return keys; }
public List<Priority> getPriorities() { try { return Lists.newArrayList(jiraRestClient.getMetadataClient().getPriorities().get(timeout, TimeUnit.SECONDS)); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get priorities error. cause: " + e.getMessage(), e); return Collections.emptyList(); } }
@Override public Object execute() throws Exception { JiraRestClient connection = null; // Validate all settings try { System.out.println("Verifiing Jira Ticketer Plugin..."); validateConfiguration(); connection = verifyConnection(); validateProjectKey(connection, config.getProjectKey()); validateIssueType(connection); verifyCustomFields(connection); return null; } finally { if (connection != null) { connection.close(); } } }
import java.net.URI; import java.util.Optional; import com.atlassian.jira.rest.client.api.JiraRestClient; import com.atlassian.jira.rest.client.api.domain.Issue; import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory; import com.atlassian.util.concurrent.Promise; public class JRC { public Issue getIssue(String issueKey) throws Exception { final URI jiraServerUri = new URI("https://jira-domain"); final JiraRestClient restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(jiraServerUri, "user@domain.com", "password"); Promise issuePromise = restClient.getIssueClient().getIssue(issueKey); return Optional.ofNullable((Issue) issuePromise.claim()).orElseThrow(() -> new Exception("No such issue")); } }