1
0
Fork 0

implemented retrieval of project, votes, and watchers on an issue

master
Bob Carroll 2013-05-23 18:22:37 -07:00
parent 8f465f6d34
commit 05cce72a6b
5 changed files with 320 additions and 0 deletions

View File

@ -60,11 +60,14 @@ public final class Field {
public static final String ISSUE_TYPE = "issuetype";
public static final String LABELS = "labels";
public static final String PRIORITY = "priority";
public static final String PROJECT = "project";
public static final String REPORTER = "reporter";
public static final String STATUS = "status";
public static final String SUMMARY = "summary";
public static final String TIME_TRACKING = "timetracking";
public static final String VERSIONS = "versions";
public static final String VOTES = "votes";
public static final String WATCHES = "watches";
public static final String DATE_FORMAT = "yyyy-MM-dd";
@ -188,12 +191,18 @@ public final class Field {
result = (T)new IssueType(restclient, (JSONObject)r);
else if (type == Priority.class)
result = (T)new Priority(restclient, (JSONObject)r);
else if (type == Project.class)
result = (T)new Project(restclient, (JSONObject)r);
else if (type == Status.class)
result = (T)new Status(restclient, (JSONObject)r);
else if (type == User.class)
result = (T)new User(restclient, (JSONObject)r);
else if (type == Version.class)
result = (T)new Version(restclient, (JSONObject)r);
else if (type == Votes.class)
result = (T)new Votes(restclient, (JSONObject)r);
else if (type == Watches.class)
result = (T)new Watches(restclient, (JSONObject)r);
}
return result;
@ -261,12 +270,18 @@ public final class Field {
results.add((T)new IssueType(restclient, (JSONObject)v));
else if (type == Priority.class)
results.add((T)new Priority(restclient, (JSONObject)v));
else if (type == Project.class)
results.add((T)new Project(restclient, (JSONObject)v));
else if (type == Status.class)
results.add((T)new Status(restclient, (JSONObject)v));
else if (type == User.class)
results.add((T)new User(restclient, (JSONObject)v));
else if (type == Version.class)
results.add((T)new Version(restclient, (JSONObject)v));
else if (type == Votes.class)
results.add((T)new Votes(restclient, (JSONObject)v));
else if (type == Watches.class)
results.add((T)new Watches(restclient, (JSONObject)v));
}
return results;

View File

@ -200,11 +200,14 @@ public final class Issue extends Resource {
private IssueType issueType = null;
private List<String> labels = null;
private Priority priority = null;
private Project project = null;
private User reporter = null;
private Status status = null;
private String summary = null;
private TimeTracking timeTracking = null;
private List<Version> versions = null;
private Votes votes = null;
private Watches watches = null;
/**
* Creates an issue from a JSON payload.
@ -238,11 +241,14 @@ public final class Issue extends Resource {
issueType = Field.getResource(IssueType.class, fields.get(Field.ISSUE_TYPE), restclient);
labels = Field.getStringArray(fields.get(Field.LABELS));
priority = Field.getResource(Priority.class, fields.get(Field.PRIORITY), restclient);
project = Field.getResource(Project.class, fields.get(Field.PROJECT), restclient);
reporter = Field.getResource(User.class, fields.get(Field.REPORTER), restclient);
status = Field.getResource(Status.class, fields.get(Field.STATUS), restclient);
summary = Field.getString(fields.get(Field.SUMMARY));
timeTracking = Field.getTimeTracking(fields.get(Field.TIME_TRACKING));
versions = Field.getResourceArray(Version.class, fields.get(Field.VERSIONS), restclient);
votes = Field.getResource(Votes.class, fields.get(Field.VOTES), restclient);
watches = Field.getResource(Watches.class, fields.get(Field.WATCHES), restclient);
}
private static String getRestUri(String key) {
@ -422,6 +428,10 @@ public final class Issue extends Resource {
return priority;
}
public Project getProject() {
return project;
}
public User getReporter() {
return reporter;
}
@ -441,5 +451,13 @@ public final class Issue extends Resource {
public List<Version> getVersions() {
return versions;
}
public Votes getVotes() {
return votes;
}
public Watches getWatches() {
return watches;
}
}

View File

@ -0,0 +1,99 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.util.Map;
import net.sf.json.JSONObject;
/**
* Represents a JIRA project.
*/
public final class Project extends Resource {
private Map<String, String> avatarUrls = null;
private String key = null;
private String name = null;
/**
* 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);
}
private void deserialise(JSONObject json) {
Map map = json;
self = Field.getString(map.get("self"));
id = Field.getString(map.get("id"));
avatarUrls = Field.getMap(String.class, String.class, map.get("avatarUrls"));
key = Field.getString(map.get("key"));
name = Field.getString(map.get("name"));
}
/**
* 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 {
JSONObject result = null;
try {
result = restclient.get(RESOURCE_URI + "project/" + key);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve project " + key, ex);
}
return new Project(restclient, result);
}
@Override
public String toString() {
return getName();
}
public Map<String, String> getAvatarUrls() {
return avatarUrls;
}
public String getKey() {
return key;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,94 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.util.Map;
import net.sf.json.JSONObject;
/**
* Represents issue votes.
*/
public final class Votes extends Resource {
private String name = null;
private int votes = 0;
private boolean hasVoted = false;
/**
* Creates votes from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected Votes(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
self = Field.getString(map.get("self"));
id = Field.getString(map.get("id"));
votes = Field.getInteger(map.get("votes"));
hasVoted = Field.getBoolean(map.get("hasVoted"));
}
/**
* Retrieves the given votes record.
*
* @param restclient REST client instance
* @param issue Internal JIRA ID of the issue
*
* @return a votes instance
*
* @throws JiraException when the retrieval fails
*/
public static Votes get(RestClient restclient, String issue)
throws JiraException {
JSONObject result = null;
try {
result = restclient.get(RESOURCE_URI + "issue/" + issue + "/votes");
} catch (Exception ex) {
throw new JiraException("Failed to retrieve votes for issue " + issue, ex);
}
return new Votes(restclient, result);
}
@Override
public String toString() {
return Integer.toString(getVotes());
}
public int getVotes() {
return votes;
}
public boolean hasVoted() {
return hasVoted;
}
}

View File

@ -0,0 +1,94 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.util.Map;
import net.sf.json.JSONObject;
/**
* Represents issue watches.
*/
public final class Watches extends Resource {
private String name = null;
private int watchCount = 0;
private boolean isWatching = false;
/**
* Creates watches from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected Watches(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
self = Field.getString(map.get("self"));
id = Field.getString(map.get("id"));
watchCount = Field.getInteger(map.get("watchCount"));
isWatching = Field.getBoolean(map.get("isWatching"));
}
/**
* Retrieves the given watches record.
*
* @param restclient REST client instance
* @param issue Internal JIRA ID of the issue
*
* @return a watches instance
*
* @throws JiraException when the retrieval fails
*/
public static Watches get(RestClient restclient, String issue)
throws JiraException {
JSONObject result = null;
try {
result = restclient.get(RESOURCE_URI + "issue/" + issue + "/watches");
} catch (Exception ex) {
throw new JiraException("Failed to retrieve watches for issue " + issue, ex);
}
return new Watches(restclient, result);
}
@Override
public String toString() {
return Integer.toString(getWatchCount());
}
public int getWatchCount() {
return watchCount;
}
public boolean isWatching() {
return isWatching;
}
}