@Override public List<T> get() throws InterruptedException, ExecutionException { waitAllLock.await(); List<T> r = new ArrayList<>(); for (Promise<T> f : promises) { r.add(f.get()); } return r; }
@Override public void invoke(Promise<T> completed) { waitAllLock.countDown(); if (waitAllLock.getCount() == 0) { try { result.invoke(result.get()); } catch (Exception e) { result.invokeWithException(e); } } } };
@Override public void setHerculesMatches(String userId, AcHost acHost, Issue issue, final List<Pattern> patterns) { LOGGER.trace("Setting hercules property on issue {} to {} matches", issue.getKey(), patterns.size()); final ObjectNode herculesProperty = Json.newObject(); herculesProperty.put("matches", patterns.size()); herculesProperty.put("articles", patterns.stream().map(Pattern::getPageName).collect(Collectors.joining("|"))); final WS.WSRequestHolder url = AC.url("/rest/api/2/issue/" + issue.getKey() + "/properties/hercules", acHost, Option.none()).setContentType("application/json"); final WS.Response response = url.put(herculesProperty).get(30, TimeUnit.SECONDS); // HTTP 201 created if (response.getStatus() >= 400) { LOGGER.error("Error setting 'hercules' property on issue {}, response [{}] {}", issue.getKey(), response.getStatus(), response.getStatusText()); } else { LOGGER.trace("Property 'hercules' set on issue {}", issue.getKey()); } } }
final WS.Response response = AC.url(relativeUri, acHost, Option.none()).setTimeout(requestTimeoutMillis).get().get(requestTimeoutMillis, TimeUnit.MILLISECONDS); if (response.getStatus() == 200)
@Override public Issue fetchRenderedIssue(final String userId, final AcHost tenant, final Long issueId) { final WS.WSRequestHolder requestHolder = getRequestHolder(tenant, issueId); requestHolder.setQueryParameter("expand", "renderedFields"); final WS.Response response; try { response = requestHolder.get().get(30, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.warn("Unknown error retrieving issue: " + e.getMessage()); return null; } return handleResponse(tenant, issueId, response); }
private void addComment(final AcHost acHost, final Issue issue, final String commentBody) { LOGGER.debug("Adding comment to the issue {}", issue.getKey()); final ObjectNode commentJson = Json.newObject(); commentJson.put("body", commentBody); final WS.WSRequestHolder url = AC.url("/rest/api/2/issue/" + issue.getKey() + "/comment", acHost, Option.none()).setContentType("application/json"); final WS.Response response = url.post(commentJson).get(30, TimeUnit.SECONDS); // HTTP 201 created if (response.getStatus() != 201) { LOGGER.error("Error adding comment to the issue {}, [{}] {}", issue.getKey(), response.getStatus(), response.getStatusText()); } else { LOGGER.debug("Successfully added comment to the issue {}", issue.getKey()); } } }
@Override public Issue fetchIssue(final String userId, final AcHost tenant, final Long issueId) { final WS.WSRequestHolder requestHolder = getRequestHolder(tenant, issueId); final WS.Response response; try { response = requestHolder.get().get(30, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.warn("Unknown error retrieving issue: " + e.getMessage()); return null; } return handleResponse(tenant, issueId, response); }
@Override public Iterable<JiraProject> getAllProjects(final AcHost tenant) { final WS.Response response; try { response = AC.url("/rest/api/2/project", tenant).get().get(30, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.warn("Unknown error retrieving projects: " + e.getMessage()); return Collections.emptyList(); } return JsonParser.parse(response.getBodyAsStream(), new TypeReference<List<JiraProject>>() {}); }
@Override public void doJob() throws Exception { ISObject sobj = p.get(); if (null != sobj) { me.sobj = sobj; } } }.now();
private List<Comment> getExistingComments(AcHost acHost, Issue issue) throws IOException { LOGGER.debug("Getting comments for the issue {}", issue.getKey()); final WS.WSRequestHolder url = AC.url("/rest/api/2/issue/" + issue.getKey() + "/comment", acHost, Option.none()).setContentType("application/json"); final WS.Response response = url.get().get(30, TimeUnit.SECONDS); if (response.getStatus() != 200) { LOGGER.error("Comments by issue {} are not available, [{}] {}", issue.getKey(), response.getStatus(), response.getStatusText()); throw new HttpResponseException(response.getStatus(), response.getStatusText()); } return JsonCommentFactory.toComments(response.asJson()); }
private static Result wrapScalaResult(scala.concurrent.Future<play.api.mvc.Result> result, long timeout) { if (result == null) { return null; } else { final play.api.mvc.Result scalaResult = Promise.wrap(result).get(timeout); return () -> scalaResult; } }