Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SprintReport corrected to fetch issues not completed in current Sprint correctly #217

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/net/rcarz/jiraclient/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ public String getUrl() {
public String getSelf() {
return self;
}

}

31 changes: 31 additions & 0 deletions src/main/java/net/rcarz/jiraclient/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<Status> 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<Status> results = new ArrayList<Status>(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.
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/rcarz/jiraclient/agile/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public List<Sprint> 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
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/net/rcarz/jiraclient/agile/BoardColumn.java
Original file line number Diff line number Diff line change
@@ -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<Status> 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<Status>(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<Status> getStatuses() {
return statuses;
}

@Override
public String toString() {
return String.format("%s{name=%s, statuses='%s'}", getClass().getSimpleName(), getId(), statuses.toString());
}

}
131 changes: 131 additions & 0 deletions src/main/java/net/rcarz/jiraclient/agile/BoardConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll ([email protected])
* <p>
* 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.
* <p>
* 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.
* <p>
* 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<BoardColumn> 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<net.rcarz.jiraclient.Status> statuses = net.rcarz.jiraclient.Status.getAll(getRestclient());
HashMap<String,net.rcarz.jiraclient.Status> statMap = new HashMap<String,net.rcarz.jiraclient.Status>(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<BoardColumn> getColumns() {
return columns;
}

}
37 changes: 26 additions & 11 deletions src/main/java/net/rcarz/jiraclient/greenhopper/SprintReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,13 +39,15 @@ public 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;
private EstimateSum completedIssuesEstimateSum = null;
private EstimateSum incompletedIssuesEstimateSum = null;
private EstimateSum allIssuesEstimateSum = null;
private EstimateSum puntedIssuesEstimateSum = null;
private List<String> issueKeysAddedDuringSprint = null;
private EstimateSum issuesCompletedInAnotherSprintInitialEstimateSum;
private List<SprintIssue> issuesCompletedInAnotherSprint;
private List<SprintIssue> issuesNotCompletedInCurrentSprint;

/**
* Creates a sprint report from a JSON payload.
Expand All @@ -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"),
Expand All @@ -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<String,Boolean> added = Field.getMap(String.class, Boolean.class, map.get("issueKeysAddedDuringSprint"));
issueKeysAddedDuringSprint = new ArrayList<String>(added.keySet());
}

/**
Expand Down Expand Up @@ -139,9 +147,16 @@ public List<SprintIssue> getCompletedIssues() {
}

public List<SprintIssue> getIncompletedIssues() {
return incompletedIssues;
return issuesNotCompletedInCurrentSprint;
}

public List<SprintIssue> getIssuesCompletedInAnotherSprint() {
return issuesCompletedInAnotherSprint;
}
public EstimateSum getIssuesCompletedInAnotherSprintInitialEstimateSum() {
return issuesCompletedInAnotherSprintInitialEstimateSum;
}

public List<SprintIssue> getPuntedIssues() {
return puntedIssues;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}

}