diff --git a/src/main/java/net/rcarz/jiraclient/Resource.java b/src/main/java/net/rcarz/jiraclient/Resource.java index b59ca736..9183c8c8 100644 --- a/src/main/java/net/rcarz/jiraclient/Resource.java +++ b/src/main/java/net/rcarz/jiraclient/Resource.java @@ -88,5 +88,6 @@ public String getUrl() { public String getSelf() { return self; } + } diff --git a/src/main/java/net/rcarz/jiraclient/Status.java b/src/main/java/net/rcarz/jiraclient/Status.java index 757a8ab6..7401659d 100644 --- a/src/main/java/net/rcarz/jiraclient/Status.java +++ b/src/main/java/net/rcarz/jiraclient/Status.java @@ -19,9 +19,12 @@ package net.rcarz.jiraclient; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import net.sf.json.JSON; +import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** @@ -55,6 +58,34 @@ private void deserialise(JSONObject json) { iconUrl = Field.getString(map.get("iconUrl")); name = Field.getString(map.get("name")); } + + /** + * Retrieves all boards visible to the session user. + * + * @param restclient REST client instance + * @return a list of boards + * @throws JiraException when the retrieval fails + */ + public static List getAll(RestClient restclient) throws JiraException { + JSON result = null; + + try { + result = restclient.get(getBaseUri() + "status"); + } catch (Exception ex) { + throw new JiraException("Failed to retrieve statuses ", ex); + } + + if (!(result instanceof JSONArray)) + throw new JiraException("JSON payload is malformed"); + + JSONArray array = (JSONArray) result; + List results = new ArrayList(array.size()); + for (int i = 0; i < array.size(); i++) { + JSONObject row = array.getJSONObject(i); + results.add(new Status(restclient, row)); + } + return results; + } /** * Retrieves the given status record. diff --git a/src/main/java/net/rcarz/jiraclient/agile/Board.java b/src/main/java/net/rcarz/jiraclient/agile/Board.java index 4db6aeca..e0a39a6c 100644 --- a/src/main/java/net/rcarz/jiraclient/agile/Board.java +++ b/src/main/java/net/rcarz/jiraclient/agile/Board.java @@ -89,6 +89,14 @@ public List getSprints() throws JiraException { return Sprint.getAll(getRestclient(), getId()); } + /** + * @return Configuarion the current board. + * @throws JiraException when the retrieval fails + */ + public BoardConfiguration getConfiguarion() throws JiraException { + return BoardConfiguration.get(getRestclient(), getId()); + } + /** * @return All issues in the Board backlog. * @throws JiraException when the retrieval fails diff --git a/src/main/java/net/rcarz/jiraclient/agile/BoardColumn.java b/src/main/java/net/rcarz/jiraclient/agile/BoardColumn.java new file mode 100644 index 00000000..e27edf3d --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/BoardColumn.java @@ -0,0 +1,47 @@ +package net.rcarz.jiraclient.agile; + +import java.util.ArrayList; +import java.util.List; + +import net.rcarz.jiraclient.JiraException; +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +public class BoardColumn extends AgileResource { + + private List statuses; + + public BoardColumn(RestClient restclient, JSONObject json) throws JiraException { + super(restclient, json); + } + + /** + * Deserialize the json to extract standard attributes and keep a reference of + * other attributes. + * + * @param json The JSON object to read. + */ + @Override + void deserialize(JSONObject json) throws JiraException { + super.deserialize(json); + setName(json.getString("name")); + JSONArray statusesJSON = json.getJSONArray("statuses"); + statuses = new ArrayList(statusesJSON.size()); + for (int i = 0; i < statusesJSON.size(); i++) { + JSONObject status = statusesJSON.getJSONObject(i); + Status stat = new Status(getRestclient(),status); + statuses.add(stat); + } + } + + public List getStatuses() { + return statuses; + } + + @Override + public String toString() { + return String.format("%s{name=%s, statuses='%s'}", getClass().getSimpleName(), getId(), statuses.toString()); + } + +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/BoardConfiguration.java b/src/main/java/net/rcarz/jiraclient/agile/BoardConfiguration.java new file mode 100644 index 00000000..6de1075a --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/BoardConfiguration.java @@ -0,0 +1,131 @@ +/** + * 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.agile; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import net.rcarz.jiraclient.Filter; +import net.rcarz.jiraclient.JiraClient; +import net.rcarz.jiraclient.JiraException; +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * Represents an Agile Board Configuration. + * + * @author SelAnt + */ +public class BoardConfiguration extends AgileResource { + + private String type; + private List columns; + + /** + * Retrieve all sprints related to the specified board. + * + * @param restclient REST client instance + * @param boardId The Internal JIRA board ID. + * @return The list of sprints associated to the board. + * @throws JiraException when the retrieval fails + */ + static BoardConfiguration get(RestClient restclient, long boardId) throws JiraException { + return AgileResource.get(restclient, BoardConfiguration.class, RESOURCE_URI + "board/" + boardId+"/configuration"); + } + + /** + * Creates a new Agile resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public BoardConfiguration(RestClient restclient, JSONObject json) throws JiraException { + super(restclient, json); + } + + /** + * Deserialize the json to extract standard attributes and keep a reference of + * other attributes. + * + * @param json The JSON object to read. + */ + @Override + void deserialize(JSONObject json) throws JiraException { + super.deserialize(json); + this.type = json.getString("type"); + setName(json.getString("name")); + //TODO: filter + Filter filter = new Filter(getRestclient(), json.getJSONObject("filter")); + /* + "filter": { + "id": "36869", + "self": "https://jira.pointclickcare.com/jira/rest/api/2/filter/36869" + }, + */ + JSONObject columnConfig = json.getJSONObject("columnConfig"); + //TODO: columnConfig.getString("constraintType") + columns = getResourceArray(BoardColumn.class, columnConfig , getRestclient(),"columns"); + + //Statuses in each Column do not have names - need to fetch all known statuses + List statuses = net.rcarz.jiraclient.Status.getAll(getRestclient()); + HashMap statMap = new HashMap(statuses.size()); + for (net.rcarz.jiraclient.Status status : statuses) { + statMap.put(status.getId(), status); + } + //set names to statuses in Board Columns + for (BoardColumn column : columns) { + for (Status st : column.getStatuses()) { + net.rcarz.jiraclient.Status status = statMap.get(String.valueOf(st.getId())); + if (status != null) { + st.setName(status.getName()); + } + } + } + //TODO: estimation and ranking fields + /* + "estimation": { + "type": "field", + "field": { + "fieldId": "customfield_10276", + "displayName": "Estimated Points" + } + }, + "ranking": { + "rankCustomFieldId": 18210 + } + */ + } + + @Override + public String toString() { + return String.format("%s{id=%s, name='%s'}", getClass().getSimpleName(), getId(), getName()); + } + + public String getType() { + return type; + } + + public List getColumns() { + return columns; + } + +} diff --git a/src/main/java/net/rcarz/jiraclient/greenhopper/SprintReport.java b/src/main/java/net/rcarz/jiraclient/greenhopper/SprintReport.java index 8d8d61f5..941178a8 100644 --- a/src/main/java/net/rcarz/jiraclient/greenhopper/SprintReport.java +++ b/src/main/java/net/rcarz/jiraclient/greenhopper/SprintReport.java @@ -19,16 +19,15 @@ 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.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import net.rcarz.jiraclient.Field; +import net.rcarz.jiraclient.JiraException; +import net.rcarz.jiraclient.RestClient; import net.sf.json.JSON; import net.sf.json.JSONObject; @@ -40,13 +39,15 @@ public class SprintReport { private RestClient restclient = null; private Sprint sprint = null; private List completedIssues = null; - private List incompletedIssues = null; private List puntedIssues = null; private EstimateSum completedIssuesEstimateSum = null; private EstimateSum incompletedIssuesEstimateSum = null; private EstimateSum allIssuesEstimateSum = null; private EstimateSum puntedIssuesEstimateSum = null; private List issueKeysAddedDuringSprint = null; + private EstimateSum issuesCompletedInAnotherSprintInitialEstimateSum; + private List issuesCompletedInAnotherSprint; + private List issuesNotCompletedInCurrentSprint; /** * Creates a sprint report from a JSON payload. @@ -69,10 +70,14 @@ private void deserialise(JSONObject json) { SprintIssue.class, map.get("completedIssues"), restclient); - incompletedIssues = GreenHopperField.getResourceArray( + issuesNotCompletedInCurrentSprint = GreenHopperField.getResourceArray( SprintIssue.class, - map.get("incompletedIssues"), + map.get("issuesNotCompletedInCurrentSprint"), restclient); + issuesCompletedInAnotherSprint = GreenHopperField.getResourceArray( + SprintIssue.class, + map.get("issuesCompletedInAnotherSprint"), + restclient); puntedIssues = GreenHopperField.getResourceArray( SprintIssue.class, map.get("puntedIssues"), @@ -81,12 +86,15 @@ private void deserialise(JSONObject json) { map.get("completedIssuesEstimateSum")); incompletedIssuesEstimateSum = GreenHopperField.getEstimateSum( map.get("incompletedIssuesEstimateSum")); + issuesCompletedInAnotherSprintInitialEstimateSum = GreenHopperField.getEstimateSum( + map.get("issuesCompletedInAnotherSprintInitialEstimateSum")); allIssuesEstimateSum = GreenHopperField.getEstimateSum( map.get("allIssuesEstimateSum")); puntedIssuesEstimateSum = GreenHopperField.getEstimateSum( map.get("puntedIssuesEstimateSum")); - issueKeysAddedDuringSprint = GreenHopperField.getStringArray( - map.get("issueKeysAddedDuringSprint")); + //JIRA-1234,true + Map added = Field.getMap(String.class, Boolean.class, map.get("issueKeysAddedDuringSprint")); + issueKeysAddedDuringSprint = new ArrayList(added.keySet()); } /** @@ -139,9 +147,16 @@ public List getCompletedIssues() { } public List getIncompletedIssues() { - return incompletedIssues; + return issuesNotCompletedInCurrentSprint; } + public List getIssuesCompletedInAnotherSprint() { + return issuesCompletedInAnotherSprint; + } + public EstimateSum getIssuesCompletedInAnotherSprintInitialEstimateSum() { + return issuesCompletedInAnotherSprintInitialEstimateSum; + } + public List getPuntedIssues() { return puntedIssues; } diff --git a/src/test/java/net/rcarz/jiraclient/agile/BoardConfigurationTest.java b/src/test/java/net/rcarz/jiraclient/agile/BoardConfigurationTest.java new file mode 100644 index 00000000..6b8dd9d3 --- /dev/null +++ b/src/test/java/net/rcarz/jiraclient/agile/BoardConfigurationTest.java @@ -0,0 +1,25 @@ +package net.rcarz.jiraclient.agile; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import net.rcarz.jiraclient.JiraException; + +/** + * Test cases for stuff relating to filters. + */ +public class BoardConfigurationTest { + + @Test + public void testGetBoardConfiguration() throws JiraException { +// JiraClient jira = new JiraClient("https://jira.pointclickcare.com/jira", new TokenCredentials("AAC949A2137DA8A671EF197DDCCB8857")); +// AgileClient agileClient = new AgileClient(jira); +// Board board = agileClient.getBoard(144); +// BoardConfiguration configuration = board.getConfiguarion(); +// //Filter filter = jira.getFilter(id); + + assertNotNull("q"); + } + +}