/** * Creates a project from a JSON payload. * * @param restclient REST client instance * @param json JSON payload */ protected Project(RestClient restclient, JSONObject json) { super(restclient); if (json != null) deserialise(json); }
/** * Retrieves the full JIRA project. * * @return a Project * * @throws JiraException when the retrieval fails */ public Project getJiraProject() throws JiraException { return Project.get(restclient, key); }
@Override public String toString() { return getName(); }
/** * 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); } }
/** * Retrieves the given project record. * * @param restclient REST client instance * @param key Project key * * @return a project instance * * @throws JiraException when the retrieval fails */ public static Project get(RestClient restclient, String key) throws JiraException { JSON result = null; try { result = restclient.get(getBaseUri() + "project/" + key); } catch (Exception ex) { throw new JiraException("Failed to retrieve project " + key, ex); } if (!(result instanceof JSONObject)) throw new JiraException("JSON payload is malformed"); return new Project(restclient, (JSONObject)result); }
/** * Obtains information about a project, given its project key. * @param key the project key * @return the project * @throws JiraException failed to obtain the project */ public Project getProject(String key) throws JiraException { try { URI uri = restclient.buildURI(Resource.getBaseUri() + "project/" + key); JSON response = restclient.get(uri); return new Project(restclient, (JSONObject) response); } catch (Exception ex) { throw new JiraException(ex.getMessage(), ex); } }
public List<User> getAssignableUsers() throws JiraException { JSON result = null; try { Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("project", this.key); URI searchUri = restclient.buildURI(getBaseUri() + "user/assignable/search", queryParams); result = restclient.get(searchUri); } catch (Exception ex) { throw new JiraException("Failed to retrieve assignable users", ex); } if (!(result instanceof JSONArray)) throw new JiraException("JSON payload is malformed"); return Field.getResourceArray(User.class, result, restclient); }
/** * Creates a new sub-task. * * @return a fluent create instance * * @throws JiraException when the client fails to retrieve issue metadata */ public FluentCreate createSubtask() throws JiraException { return Issue.create(restclient, getProject().getKey(), "Sub-task") .field(Field.PARENT, getKey()); }
restclient); if (projects.isEmpty() || projects.get(0).getIssueTypes().isEmpty()) throw new JiraException("Project '"+ project + "' or issue type '" + issueType + "' missing from create metadata. Do you have enough permissions?"); return projects.get(0).getIssueTypes().get(0).getFields();
/** * 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); } }
/** * Retrieves the given project record. * * @param restclient REST client instance * @param key Project key * * @return a project instance * * @throws JiraException when the retrieval fails */ public static Project get(RestClient restclient, String key) throws JiraException { JSON result = null; try { result = restclient.get(getBaseUri() + "project/" + key); } catch (Exception ex) { throw new JiraException("Failed to retrieve project " + key, ex); } if (!(result instanceof JSONObject)) throw new JiraException("JSON payload is malformed"); return new Project(restclient, (JSONObject)result); }
/** * Obtains information about a project, given its project key. * @param key the project key * @return the project * @throws JiraException failed to obtain the project */ public Project getProject(String key) throws JiraException { try { URI uri = restclient.buildURI(Resource.getBaseUri() + "project/" + key); JSON response = restclient.get(uri); return new Project(restclient, (JSONObject) response); } catch (Exception ex) { throw new JiraException(ex.getMessage(), ex); } }
/** * Retrieves all project records visible to the session user. * * @param restclient REST client instance * * @return a list of projects * * @throws JiraException when the retrieval fails */ public static List<Project> getAll(RestClient restclient) throws JiraException { JSON result = null; try { result = restclient.get(getBaseUri() + "project"); } catch (Exception ex) { throw new JiraException("Failed to retrieve projects", ex); } if (!(result instanceof JSONArray)) throw new JiraException("JSON payload is malformed"); return Field.getResourceArray(Project.class, result, restclient); }
/** * Creates a new sub-task. * * @return a fluent create instance * * @throws JiraException when the client fails to retrieve issue metadata */ public FluentCreate createSubtask() throws JiraException { return Issue.create(restclient, getProject().getKey(), "Sub-task") .field(Field.PARENT, getKey()); }
restclient); if (projects.isEmpty() || projects.get(0).getIssueTypes().isEmpty()) throw new JiraException("Project '"+ project + "' or issue type '" + issueType + "' missing from create metadata. Do you have enough permissions?"); return projects.get(0).getIssueTypes().get(0).getFields();
/** * Obtains the list of all projects in Jira. * @return all projects; not all data is returned for each project; to get * the extra data use {@link #getProject(String)} * @throws JiraException failed to obtain the project list. */ public List<Project> getProjects() throws JiraException { try { URI uri = restclient.buildURI(Resource.getBaseUri() + "project"); JSON response = restclient.get(uri); JSONArray projectsArray = JSONArray.fromObject(response); List<Project> projects = new ArrayList<Project>(projectsArray.size()); for (int i = 0; i < projectsArray.size(); i++) { JSONObject p = projectsArray.getJSONObject(i); projects.add(new Project(restclient, p)); } return projects; } catch (Exception ex) { throw new JiraException(ex.getMessage(), ex); } }
/** * Retrieves all project records visible to the session user. * * @param restclient REST client instance * * @return a list of projects * * @throws JiraException when the retrieval fails */ public static List<Project> getAll(RestClient restclient) throws JiraException { JSON result = null; try { result = restclient.get(getBaseUri() + "project"); } catch (Exception ex) { throw new JiraException("Failed to retrieve projects", ex); } if (!(result instanceof JSONArray)) throw new JiraException("JSON payload is malformed"); return Field.getResourceArray(Project.class, result, restclient); }
/** * Retrieves the full JIRA project. * * @return a Project * * @throws JiraException when the retrieval fails */ public Project getJiraProject() throws JiraException { return Project.get(restclient, key); }
/** * Creates a project from a JSON payload. * * @param restclient REST client instance * @param json JSON payload */ protected Project(RestClient restclient, JSONObject json) { super(restclient); if (json != null) deserialise(json); }
@Override public String toString() { return getName(); }