@Nullable @Override public Task findTask(String id) throws Exception { if (myRestApiVersion == null) { myRestApiVersion = discoverRestApiVersion(); } JiraIssue issue = myRestApiVersion.findIssue(id); return issue == null ? null : new JiraTask(issue, this); }
@NotNull public JiraRestApi discoverRestApiVersion() throws Exception { String responseBody; try { responseBody = executeMethod(new GetMethod(getRestUrl("serverInfo"))); } catch (Exception e) { LOG.warn("Can't find out JIRA REST API version"); throw e; } JsonObject object = GSON.fromJson(responseBody, JsonObject.class); // when JIRA 4.x support will be dropped 'versionNumber' array in response // may be used instead version string parsing JiraRestApi version = JiraRestApi.fromJiraVersion(object.get("version").getAsString(), this); if (version == null) { throw new Exception("JIRA below 4.0.0 doesn't have REST API and is no longer supported."); } return version; }
public Task[] getIssues(@Nullable String query, int max, long since) throws Exception { if (myRestApiVersion == null) { myRestApiVersion = discoverRestApiVersion(); } String jqlQuery = mySearchQuery; if (!StringUtil.isEmpty(query)) { jqlQuery = String.format("summary ~ '%s'", query); if (!StringUtil.isEmpty(mySearchQuery)) { jqlQuery += String.format(" and %s", mySearchQuery); } } List<JiraIssue> issues = myRestApiVersion.findIssues(jqlQuery, max); return ContainerUtil.map2Array( issues, Task.class, new Function<JiraIssue, Task>() { @Override public JiraTask fun(JiraIssue issue) { return new JiraTask(issue, JiraRepository.this); } }); }
@Override public void updateTimeSpent( @NotNull LocalTask task, @NotNull String timeSpent, @NotNull String comment) throws Exception { myRestApiVersion.updateTimeSpend(task, timeSpent, comment); }
@Override public void setTaskState(Task task, TaskState state) throws Exception { myRestApiVersion.setTaskState(task, state); }