1
0
Fork 0

implemented reading rapid view sprints and sprint report

master
Bob Carroll 2013-08-24 23:53:46 -07:00
parent 6a1ada582a
commit aef458bb52
7 changed files with 500 additions and 11 deletions

23
pom.xml
View File

@ -38,20 +38,20 @@
</parent>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
@ -60,5 +60,12 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,80 @@
/**
* 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.RestClient;
import java.util.Map;
import net.sf.json.JSONObject;
import org.joda.time.DateTime;
/**
* GreenHopper estimate statistics for rapid views.
*/
public final class EstimateStatistic extends GreenHopperResource {
private String statFieldId = null;
private int statFieldValue = 0;
private String statFieldText = null;
/**
* Creates an estimate statistic from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected EstimateStatistic(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
statFieldId = Field.getString(map.get("statFieldId"));
if (map.containsKey("statFieldValue") &&
map.get("statFieldValue") instanceof JSONObject) {
Map val = (Map)json.get("statFieldValue");
statFieldValue = Field.getInteger(map.get("value"));
statFieldText = Field.getString(map.get("text"));
}
}
public String getFieldId() {
return statFieldId;
}
public int getFieldValue() {
return statFieldValue;
}
public String getFieldText() {
return statFieldText;
}
}

View File

@ -27,13 +27,49 @@ import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
/**
* Utility functions for translating between JSON and fields.
*/
public final class GreenHopperField {
public static final String DATE_TIME_FORMAT = "d/MMM/yy h:m a";
private GreenHopperField() { }
/**
* Gets a date-time from the given object.
*
* @param dt Date-Time as a string
*
* @return the date-time or null
*/
public static DateTime getDateTime(Object dt) {
return dt != null ?
DateTime.parse((String)dt, DateTimeFormat.forPattern(DATE_TIME_FORMAT)) :
null;
}
/**
* Gets a list of integers from the given object.
*
* @param ia a JSONArray instance
*
* @return a list of integers
*/
public static List<Integer> getIntegerArray(Object ia) {
List<Integer> results = new ArrayList<Integer>();
if (ia instanceof JSONArray) {
for (Object v : (JSONArray)ia)
results.add((Integer)v);
}
return results;
}
/**
* Gets a GreenHopper resource from the given object.
*
@ -49,10 +85,14 @@ public final class GreenHopperField {
T result = null;
if (r instanceof JSONObject && !((JSONObject)r).isNullObject()) {
if (type == RapidView.class)
if (type == EstimateStatistic.class)
result = (T)new EstimateStatistic(restclient, (JSONObject)r);
else if (type == RapidView.class)
result = (T)new RapidView(restclient, (JSONObject)r);
else if (type == Sprint.class)
result = (T)new Sprint(restclient, (JSONObject)r);
else if (type == SprintIssue.class)
result = (T)new SprintIssue(restclient, (JSONObject)r);
}
return result;

View File

@ -155,6 +155,19 @@ public final class RapidView extends GreenHopperResource {
);
}
/**
* Retrieves the sprint report for the given sprint.
*
* @param sprint Sprint to lookup
*
* @return the sprint report
*
* @throws JiraException when the retrieval fails
*/
public SprintReport getSprintReport(Sprint sprint) throws JiraException {
return SprintReport.get(restclient, this, sprint);
}
@Override
public String toString() {
return name;

View File

@ -20,14 +20,14 @@
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;
import org.joda.time.DateTime;
/**
* Represents a GreenHopper sprint.
*/
@ -35,6 +35,9 @@ public final class Sprint extends GreenHopperResource {
private String name = null;
private boolean closed = false;
private DateTime startDate = null;
private DateTime endDate = null;
private DateTime completeDate = null;
/**
* Creates a sprint from a JSON payload.
@ -55,6 +58,9 @@ public final class Sprint extends GreenHopperResource {
id = Field.getInteger(map.get("id"));
name = Field.getString(map.get("name"));
closed = Field.getBoolean(map.get("closed"));
startDate = GreenHopperField.getDateTime(map.get("startDate"));
endDate = GreenHopperField.getDateTime(map.get("endDate"));
completeDate = GreenHopperField.getDateTime(map.get("completeDate"));
}
@Override
@ -69,5 +75,17 @@ public final class Sprint extends GreenHopperResource {
public Boolean isClosed() {
return closed;
}
public DateTime getStartDate() {
return startDate;
}
public DateTime getEndDate() {
return endDate;
}
public DateTime getCompleteDate() {
return completeDate;
}
}

View File

@ -0,0 +1,196 @@
/**
* 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.Issue;
import net.rcarz.jiraclient.JiraException;
import net.rcarz.jiraclient.RestClient;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
/**
* Represents a GreenHopper sprint issue.
*/
public final class SprintIssue extends GreenHopperResource {
private String key = null;
private boolean hidden = false;
private String typeName = null;
private String typeId = null;
private String summary = null;
private String typeUrl = null;
private String priorityUrl = null;
private String priorityName = null;
private boolean done = false;
private String assignee = null;
private String assigneeName = null;
private String avatarUrl = null;
private String colour = null;
private String epic = null;
private EstimateStatistic estimateStatistic = null;
private String statusId = null;
private String statusName = null;
private String statusUrl = null;
private List<Integer> fixVersions = null;
private int projectId = 0;
/**
* Creates a sprint from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected SprintIssue(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"));
key = Field.getString(map.get("key"));
hidden = Field.getBoolean(map.get("hidden"));
summary = Field.getString(map.get("summary"));
typeName = Field.getString(map.get("key"));
typeId = Field.getString(map.get("typeId"));
typeUrl = Field.getString(map.get("typeUrl"));
priorityUrl = Field.getString(map.get("priorityUrl"));
priorityName = Field.getString(map.get("priorityName"));
done = Field.getBoolean(map.get("done"));
assignee = Field.getString(map.get("assignee"));
assigneeName = Field.getString(map.get("assigneeName"));
avatarUrl = Field.getString(map.get("avatarUrl"));
colour = Field.getString(map.get("color"));
epic = Field.getString(map.get("epic"));
estimateStatistic = GreenHopperField.getResource(
EstimateStatistic.class,
map.get("estimateStatistic"),
restclient);
statusId = Field.getString(map.get("statusId"));
statusName = Field.getString(map.get("statusName"));
statusUrl = Field.getString(map.get("statusUrl"));
fixVersions = GreenHopperField.getIntegerArray(map.get("fixVersions"));
projectId = Field.getInteger(map.get("projectId"));
}
/**
* Retrieves the full JIRA issue.
*
* @return an Issue
*
* @throws JiraException when the retrieval fails
*/
public Issue getJiraIssue() throws JiraException {
return Issue.get(restclient, key);
}
@Override
public String toString() {
return key;
}
public String getKey() {
return key;
}
public Boolean isHidden() {
return hidden;
}
public String getSummary() {
return summary;
}
public String getTypeName() {
return typeName;
}
public String getTypeId() {
return typeId;
}
public String getTypeUrl() {
return typeUrl;
}
public String getPriorityUrl() {
return priorityUrl;
}
public String getPriorityName() {
return priorityName;
}
public Boolean isDone() {
return done;
}
public String getAssignee() {
return assignee;
}
public String getAssigneeName() {
return assigneeName;
}
public String getAvatarUrl() {
return avatarUrl;
}
public String getColour() {
return colour;
}
public String getEpic() {
return epic;
}
public EstimateStatistic getEstimateStatistic() {
return estimateStatistic;
}
public String getStatusId() {
return statusId;
}
public String getStatusName() {
return statusName;
}
public String getStatusUrl() {
return statusUrl;
}
public List<Integer> getFixVersions() {
return fixVersions;
}
public int getProjectId() {
return projectId;
}
}

View File

@ -0,0 +1,135 @@
/**
* 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.Issue;
import net.rcarz.jiraclient.JiraException;
import net.rcarz.jiraclient.RestClient;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
/**
* GreenHopper sprint statistics.
*/
public final class SprintReport {
private RestClient restclient = null;
private Sprint sprint = null;
private List<SprintIssue> completedIssues = null;
private List<SprintIssue> incompletedIssues = null;
private List<SprintIssue> puntedIssues = null;
/**
* Creates a sprint report from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected SprintReport(RestClient restclient, JSONObject json) {
this.restclient = restclient;
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
sprint = GreenHopperField.getResource(Sprint.class, map.get("sprint"), restclient);
completedIssues = GreenHopperField.getResourceArray(
SprintIssue.class,
map.get("completedIssues"),
restclient);
incompletedIssues = GreenHopperField.getResourceArray(
SprintIssue.class,
map.get("incompletedIssues"),
restclient);
puntedIssues = GreenHopperField.getResourceArray(
SprintIssue.class,
map.get("puntedIssues"),
restclient);
}
/**
* Retrieves the sprint report for the given rapid view and sprint.
*
* @param restclient REST client instance
* @param rv Rapid View instance
* @param sprint Sprint instance
*
* @return the sprint report
*
* @throws JiraException when the retrieval fails
*/
public static SprintReport get(RestClient restclient, RapidView rv, Sprint sprint)
throws JiraException {
final int rvId = rv.getId();
final int sprintId = sprint.getId();
JSON result = null;
try {
URI reporturi = restclient.buildURI(
GreenHopperResource.RESOURCE_URI + "rapid/charts/sprintreport",
new HashMap<String, String>() {{
put("rapidViewId", Integer.toString(rvId));
put("sprintId", Integer.toString(sprintId));
}});
result = restclient.get(reporturi);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve sprint report", ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
JSONObject jo = (JSONObject)result;
if (!jo.containsKey("contents") || !(jo.get("contents") instanceof JSONObject))
throw new JiraException("Sprint report content is malformed");
return new SprintReport(restclient, (JSONObject)jo.get("contents"));
}
public Sprint getSprint() {
return sprint;
}
public List<SprintIssue> getCompletedIssues() {
return completedIssues;
}
public List<SprintIssue> getIncompletedIssues() {
return incompletedIssues;
}
public List<SprintIssue> getPuntedIssues() {
return puntedIssues;
}
}