1
0
Fork 0

fixed rapid view id and implemented sprint retrieval

master
Bob Carroll 2013-08-24 18:54:54 -07:00
parent 1b3df7d59f
commit 6a1ada582a
5 changed files with 113 additions and 6 deletions

View File

@ -44,13 +44,13 @@ public class GreenHopperClient {
/**
* Retreives the rapid view with the given ID.
*
* @param id Rapid View ID string
* @param id Rapid View ID
*
* @return a RapidView instance
*
* @throws JiraException when something goes wrong
*/
public RapidView getRapidView(String id) throws JiraException {
public RapidView getRapidView(int id) throws JiraException {
return RapidView.get(restclient, id);
}

View File

@ -51,6 +51,8 @@ public final class GreenHopperField {
if (r instanceof JSONObject && !((JSONObject)r).isNullObject()) {
if (type == RapidView.class)
result = (T)new RapidView(restclient, (JSONObject)r);
else if (type == Sprint.class)
result = (T)new Sprint(restclient, (JSONObject)r);
}
return result;

View File

@ -29,7 +29,7 @@ public abstract class GreenHopperResource {
protected static final String RESOURCE_URI = "/rest/greenhopper/1.0/";
protected RestClient restclient = null;
protected String id = null;
protected int id = 0;
/**
* Creates a new GreenHopper resource.
@ -43,7 +43,7 @@ public abstract class GreenHopperResource {
/**
* Internal JIRA ID.
*/
public String getId() {
public int getId() {
return id;
}
}

View File

@ -55,7 +55,7 @@ public final class RapidView extends GreenHopperResource {
private void deserialise(JSONObject json) {
Map map = json;
id = Field.getString(map.get("id"));
id = Field.getInteger(map.get("id"));
name = Field.getString(map.get("name"));
canEdit = Field.getBoolean(map.get("canEdit"));
sprintSupportEnabled = Field.getBoolean(map.get("sprintSupportEnabled"));
@ -71,7 +71,7 @@ public final class RapidView extends GreenHopperResource {
*
* @throws JiraException when the retrieval fails
*/
public static RapidView get(RestClient restclient, String id)
public static RapidView get(RestClient restclient, int id)
throws JiraException {
JSON result = null;
@ -123,6 +123,38 @@ public final class RapidView extends GreenHopperResource {
);
}
/**
* Retrieves all sprints associated with this rapid view.
*
* @return a list of sprints
*
* @throws JiraException when the retrieval fails
*/
public List<Sprint> getSprints() throws JiraException {
JSON result = null;
try {
System.out.println(getId());
result = restclient.get(RESOURCE_URI + "sprints/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve sprints", ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
JSONObject jo = (JSONObject)result;
if (!jo.containsKey("sprints") || !(jo.get("sprints") instanceof JSONArray))
throw new JiraException("Sprints result is malformed");
return GreenHopperField.getResourceArray(
Sprint.class,
jo.get("sprints"),
restclient
);
}
@Override
public String toString() {
return name;

View File

@ -0,0 +1,73 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient.greenhopper;
import net.rcarz.jiraclient.Field;
import net.rcarz.jiraclient.JiraException;
import net.rcarz.jiraclient.RestClient;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
/**
* Represents a GreenHopper sprint.
*/
public final class Sprint extends GreenHopperResource {
private String name = null;
private boolean closed = false;
/**
* Creates a sprint from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected Sprint(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
id = Field.getInteger(map.get("id"));
name = Field.getString(map.get("name"));
closed = Field.getBoolean(map.get("closed"));
}
@Override
public String toString() {
return name;
}
public String getName() {
return name;
}
public Boolean isClosed() {
return closed;
}
}