1
0
Fork 0

implemented retrieval of rapid boards

master
Bob Carroll 2013-08-24 18:16:53 -07:00
parent 07ecf44a39
commit 1b3df7d59f
6 changed files with 350 additions and 43 deletions

View File

@ -293,41 +293,11 @@ public final class Field {
List<T> results = new ArrayList<T>();
if (ra instanceof JSONArray) {
for (Object v : (JSONArray)ra)
if (type == Attachment.class)
results.add((T)new Attachment(restclient, (JSONObject)v));
else if (type == Comment.class)
results.add((T)new Comment(restclient, (JSONObject)v));
else if (type == Component.class)
results.add((T)new Component(restclient, (JSONObject)v));
else if (type == CustomFieldOption.class)
results.add((T)new CustomFieldOption(restclient, (JSONObject)v));
else if (type == Issue.class)
results.add((T)new Issue(restclient, (JSONObject)v));
else if (type == IssueLink.class)
results.add((T)new IssueLink(restclient, (JSONObject)v));
else if (type == IssueType.class)
results.add((T)new IssueType(restclient, (JSONObject)v));
else if (type == LinkType.class)
results.add((T)new LinkType(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 == Resolution.class)
results.add((T)new Resolution(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));
else if (type == WorkLog.class)
results.add((T)new WorkLog(restclient, (JSONObject)v));
for (Object v : (JSONArray)ra) {
T item = getResource(type, v, restclient);
if (item != null)
results.add(item);
}
}
return results;

View File

@ -19,13 +19,6 @@
package net.rcarz.jiraclient;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
/**
* A base class for JIRA resources.
*/
@ -34,7 +27,6 @@ public abstract class Resource {
protected static final String RESOURCE_URI = "/rest/api/2/";
protected RestClient restclient = null;
protected String id = null;
protected String self = null;

View File

@ -0,0 +1,68 @@
/**
* 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.JiraClient;
import net.rcarz.jiraclient.JiraException;
import net.rcarz.jiraclient.RestClient;
import java.util.List;
/**
* A GreenHopper extension to the JIRA client.
*/
public class GreenHopperClient {
private RestClient restclient = null;
/**
* Creates a GreenHopper client.
*
* @param jira JIRA client
*/
public GreenHopperClient(JiraClient jira) {
restclient = jira.getRestClient();
}
/**
* Retreives the rapid view with the given ID.
*
* @param id Rapid View ID string
*
* @return a RapidView instance
*
* @throws JiraException when something goes wrong
*/
public RapidView getRapidView(String id) throws JiraException {
return RapidView.get(restclient, id);
}
/**
* Retreives all rapid views visible to the session user.
*
* @return a list of rapid views
*
* @throws JiraException when something goes wrong
*/
public List<RapidView> getRapidViews() throws JiraException {
return RapidView.getAll(restclient);
}
}

View File

@ -0,0 +1,84 @@
/**
* 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.RestClient;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* Utility functions for translating between JSON and fields.
*/
public final class GreenHopperField {
private GreenHopperField() { }
/**
* Gets a GreenHopper resource from the given object.
*
* @param type Resource data type
* @param r a JSONObject instance
* @param restclient REST client instance
*
* @return a Resource instance or null if r isn't a JSONObject instance
*/
public static <T extends GreenHopperResource> T getResource(
Class<T> type, Object r, RestClient restclient) {
T result = null;
if (r instanceof JSONObject && !((JSONObject)r).isNullObject()) {
if (type == RapidView.class)
result = (T)new RapidView(restclient, (JSONObject)r);
}
return result;
}
/**
* Gets a list of GreenHopper resources from the given object.
*
* @param type Resource data type
* @param ra a JSONArray instance
* @param restclient REST client instance
*
* @return a list of Resources found in ra
*/
public static <T extends GreenHopperResource> List<T> getResourceArray(
Class<T> type, Object ra, RestClient restclient) {
List<T> results = new ArrayList<T>();
if (ra instanceof JSONArray) {
for (Object v : (JSONArray)ra) {
T item = getResource(type, v, restclient);
if (item != null)
results.add(item);
}
}
return results;
}
}

View File

@ -0,0 +1,50 @@
/**
* 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.RestClient;
/**
* A base class for GreenHopper resources.
*/
public abstract class GreenHopperResource {
protected static final String RESOURCE_URI = "/rest/greenhopper/1.0/";
protected RestClient restclient = null;
protected String id = null;
/**
* Creates a new GreenHopper resource.
*
* @param restclient REST client instance
*/
public GreenHopperResource(RestClient restclient) {
this.restclient = restclient;
}
/**
* Internal JIRA ID.
*/
public String getId() {
return id;
}
}

View File

@ -0,0 +1,143 @@
/**
* 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.List;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* Represents a GreenHopper Rapid Board.
*/
public final class RapidView extends GreenHopperResource {
private String name = null;
private boolean canEdit = false;
private boolean sprintSupportEnabled = false;
/**
* Creates a rapid view from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected RapidView(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
id = Field.getString(map.get("id"));
name = Field.getString(map.get("name"));
canEdit = Field.getBoolean(map.get("canEdit"));
sprintSupportEnabled = Field.getBoolean(map.get("sprintSupportEnabled"));
}
/**
* Retrieves the given rapid view.
*
* @param restclient REST client instance
* @param id Internal JIRA ID of the rapid view
*
* @return a rapid view instance
*
* @throws JiraException when the retrieval fails
*/
public static RapidView get(RestClient restclient, String id)
throws JiraException {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "rapidview/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve rapid view " + id, ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
return new RapidView(restclient, (JSONObject)result);
}
/**
* Retrieves all rapid views visible to the session user.
*
* @param restclient REST client instance
*
* @return a list of rapid views
*
* @throws JiraException when the retrieval fails
*/
public static List<RapidView> getAll(RestClient restclient)
throws JiraException {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "rapidview");
} catch (Exception ex) {
throw new JiraException("Failed to retrieve rapid views", ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
JSONObject jo = (JSONObject)result;
if (!jo.containsKey("views") || !(jo.get("views") instanceof JSONArray))
throw new JiraException("Rapid View result is malformed");
return GreenHopperField.getResourceArray(
RapidView.class,
jo.get("views"),
restclient
);
}
@Override
public String toString() {
return name;
}
public String getName() {
return name;
}
public Boolean canEdit() {
return canEdit;
}
public Boolean sprintSupportEnabled() {
return sprintSupportEnabled;
}
}