/** * Executes an HTTP POST with the given path and payload. * * @param path Path to be appended to the URI supplied in the construtor * @param payload JSON-encoded data to send to the remote service * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON post(String path, JSON payload) throws RestException, IOException, URISyntaxException { return post(buildURI(path), payload); }
/** * Executes an HTTP POST with the given path and payload. * * @param path Path to be appended to the URI supplied in the construtor * @param payload JSON-encoded data to send to the remote service * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON post(String path, JSON payload) throws RestException, IOException, URISyntaxException { return post(buildURI(path), payload); }
/** * Casts a vote in favour of an issue. * * @throws JiraException when the voting fails */ public void vote() throws JiraException { try { restclient.post(getRestUri(key) + "/votes"); } catch (Exception ex) { throw new JiraException("Failed to vote on issue " + key, ex); } }
/** * Casts a vote in favour of an issue. * * @throws JiraException when the voting fails */ public void vote() throws JiraException { try { restclient.post(getRestUri(key) + "/votes"); } catch (Exception ex) { throw new JiraException("Failed to vote on issue " + key, ex); } }
/** * Creates or updates the remote link if a {@link #globalId(String) global id} is given and there is already * a remote link for the specified global id. * @throws JiraException when the remote link creation fails */ public void create() throws JiraException { try { request.put("object", object); restclient.post(getRestUri(key) + "/remotelink", request); } catch (Exception ex) { throw new JiraException("Failed add remote link to issue " + key, ex); } }
/** * Adds an attachment to this issue. * * @param file java.io.File * * @throws JiraException when the attachment creation fails */ public void addAttachment(File file) throws JiraException { try { restclient.post(getRestUri(key) + "/attachments", file); } catch (Exception ex) { throw new JiraException("Failed add attachment to issue " + key, ex); } }
/** * Adds an attachment to this issue. * * @param file java.io.File * * @throws JiraException when the comment creation fails */ public void addAttachment(File file) throws JiraException { try { restclient.post(getRestUri(key) + "/attachments", file); } catch (Exception ex) { throw new JiraException("Failed add attachment to issue " + key, ex); } }
/** * Executes an HTTP POST with the given path. * * @param path Path to be appended to the URI supplied in the construtor * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON post(String path) throws RestException, IOException, URISyntaxException { return post(buildURI(path), new JSONObject()); }
/** * Executes an HTTP POST with the given path. * * @param path Path to be appended to the URI supplied in the construtor * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON post(String path) throws RestException, IOException, URISyntaxException { return post(buildURI(path), new JSONObject()); }
/** * Adds an attachments to this issue. * * @param attachments the attachments to add * * @throws JiraException when the attachments creation fails */ public void addAttachments(NewAttachment... attachments) throws JiraException { if (attachments == null) { throw new NullPointerException("attachments may not be null"); } if (attachments.length == 0) { return; } try { restclient.post(getRestUri(key) + "/attachments", attachments); } catch (Exception ex) { throw new JiraException("Failed add attachment to issue " + key, ex); } }
/** * Adds a watcher to the issue. * * @param username Username of the watcher to add * * @throws JiraException when the operation fails */ public void addWatcher(String username) throws JiraException { try { URI uri = restclient.buildURI(getRestUri(key) + "/watchers"); restclient.post(uri, username); } catch (Exception ex) { throw new JiraException( "Failed to add watcher (" + username + ") to issue " + key, ex ); } }
/** * Adds a watcher to the issue. * * @param username Username of the watcher to add * * @throws JiraException when the operation fails */ public void addWatcher(String username) throws JiraException { try { URI uri = restclient.buildURI(getRestUri(key) + "/watchers"); restclient.post(uri, username); } catch (Exception ex) { throw new JiraException( "Failed to add watcher (" + username + ") to issue " + key, ex ); } }
/** * Executes the create action. * @return the created component * * @throws JiraException when the create fails */ public Component execute() throws JiraException { JSON result = null; try { result = restclient.post(getRestUri(null), req); } catch (Exception ex) { throw new JiraException("Failed to create issue", ex); } if (!(result instanceof JSONObject) || !((JSONObject) result).containsKey("id") || !(((JSONObject) result).get("id") instanceof String)) { throw new JiraException("Unexpected result on create component"); } return new Component(restclient, (JSONObject) result); } }
/** * Executes the create action. * @return the created component * * @throws JiraException when the create fails */ public Component execute() throws JiraException { JSON result = null; try { result = restclient.post(getRestUri(null), req); } catch (Exception ex) { throw new JiraException("Failed to create issue", ex); } if (!(result instanceof JSONObject) || !((JSONObject) result).containsKey("id") || !(((JSONObject) result).get("id") instanceof String)) { throw new JiraException("Unexpected result on create component"); } return new Component(restclient, (JSONObject) result); } }
/** * Executes the create action. * @return the created Version * * @throws JiraException when the create fails */ public Version execute() throws JiraException { JSON result = null; try { result = restclient.post(getRestUri(null), req); } catch (Exception ex) { throw new JiraException("Failed to create version", ex); } if (!(result instanceof JSONObject) || !((JSONObject) result).containsKey("id") || !(((JSONObject) result).get("id") instanceof String)) { throw new JiraException("Unexpected result on create version"); } return new Version(restclient, (JSONObject) result); } }
private void realExecute(Transition trans) throws JiraException { if (trans == null || trans.getFields() == null) throw new JiraException("Transition is missing fields"); JSONObject fieldmap = new JSONObject(); for (Map.Entry<String, Object> ent : fields.entrySet()) { fieldmap.put(ent.getKey(), ent.getValue()); } JSONObject req = new JSONObject(); if (fieldmap.size() > 0) req.put("fields", fieldmap); JSONObject t = new JSONObject(); t.put("id", Field.getString(trans.getId())); req.put("transition", t); try { restclient.post(getRestUri(key) + "/transitions", req); } catch (Exception ex) { throw new JiraException("Failed to transition issue " + key, ex); } }
private void realExecute(JSONObject trans) throws JiraException { if (trans.isNullObject() || !trans.containsKey("fields") || !(trans.get("fields") instanceof JSONObject)) throw new JiraException("Transition metadata is missing fields"); JSONObject editmeta = (JSONObject)trans.get("fields"); JSONObject fieldmap = new JSONObject(); for (Map.Entry<String, Object> ent : fields.entrySet()) { Object newval = Field.toJson(ent.getKey(), ent.getValue(), editmeta); fieldmap.put(ent.getKey(), newval); } JSONObject req = new JSONObject(); if (fieldmap.size() > 0) req.put("fields", fieldmap); JSONObject t = new JSONObject(); t.put("id", Field.getString(trans.get("id"))); req.put("transition", t); try { restclient.post(getRestUri(key) + "/transitions", req); } catch (Exception ex) { throw new JiraException("Failed to transition issue " + key, ex); } }
public void initialize(RestClient client) throws JiraException { if (token==null) { try { JSONObject req = new JSONObject(); req.put("username", username); req.put("password", password); JSON json = client.post(Resource.getAuthUri() + "session", req); if (json instanceof JSONObject) { JSONObject jso = (JSONObject) json; jso = (JSONObject) jso.get("session"); cookieName = (String)jso.get("name"); token = (String)jso.get("value"); } } catch (Exception ex) { throw new JiraException("Failed to login", ex); } } }
/** * Copies the version to the given project * * @param project * The project the version will be copied to */ public void copyTo(Project project) { JSONObject req = new JSONObject(); req.put("description", getDescription()); req.put("name", getName()); req.put("archived", isArchived()); req.put("released", isReleased()); req.put("releaseDate", getReleaseDate()); req.put("project", project.getKey()); req.put("projectId", project.getId()); try { restclient.post(Resource.getBaseUri() + "version/", req); } catch (Exception ex) { throw new RuntimeException("Failed to copy to project '" + project.getKey() + "'", ex); } }
/** * Copies the version to the given project * * @param project * The project the version will be copied to */ public void copyTo(Project project) throws JiraException { JSONObject req = new JSONObject(); req.put("description", getDescription()); req.put("name", getName()); req.put("archived", isArchived()); req.put("released", isReleased()); req.put("releaseDate", getReleaseDate()); req.put("project", project.getKey()); req.put("projectId", project.getId()); try { restclient.post(Resource.getBaseUri() + "version/", req); } catch (Exception ex) { throw new JiraException("Failed to copy to project '" + project.getKey() + "'", ex); } }