From 0c18c3bcd7090d1f7e5fc8b9083c177999b81d82 Mon Sep 17 00:00:00 2001 From: Philip Stehlik Date: Sun, 24 Nov 2013 20:09:57 -0800 Subject: [PATCH] Making getDateTime safer to deal with 'None' date strings returned from JIRA API Changing the backlog to allow seeing sprints (not 'openSprints') and also adding the issues to the actual Sprint objects. In addition also adding 'backlogIssues' List to Backlog class for easy access to the issues in a given Backlog --- .../rcarz/jiraclient/greenhopper/Backlog.java | 34 ++++++++++++++++--- .../greenhopper/GreenHopperField.java | 9 +++-- .../rcarz/jiraclient/greenhopper/Sprint.java | 20 +++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/rcarz/jiraclient/greenhopper/Backlog.java b/src/main/java/net/rcarz/jiraclient/greenhopper/Backlog.java index a690c59..7641e25 100644 --- a/src/main/java/net/rcarz/jiraclient/greenhopper/Backlog.java +++ b/src/main/java/net/rcarz/jiraclient/greenhopper/Backlog.java @@ -40,8 +40,9 @@ public class Backlog { private RestClient restclient = null; private List issues = null; + private List backlogIssues = null; private int rankCustomFieldId = 0; - private List openSprints = null; + private List sprints = null; private List projects = null; private List markers = null; private List epics = null; @@ -72,9 +73,9 @@ public class Backlog { map.get("issues"), restclient); rankCustomFieldId = Field.getInteger(map.get("rankCustomFieldId")); - openSprints = GreenHopperField.getResourceArray( + sprints = GreenHopperField.getResourceArray( Sprint.class, - map.get("openSprints"), + map.get("sprints"), restclient); projects = GreenHopperField.getResourceArray( RapidViewProject.class, @@ -124,6 +125,25 @@ public class Backlog { } } } + + //determining which issues are actually in the backlog vs the sprints + //fill in the issues into the single sprints and the backlog issue list respectively + for(SprintIssue issue : issues){ + boolean addedToSprint = false; + for(Sprint sprint : sprints){ + if(sprint.getIssuesIds().contains(issue.getId())){ + sprint.getIssues().add(issue); + addedToSprint = true; + } + } + if(!addedToSprint){ + if(backlogIssues == null){ + backlogIssues = new ArrayList(); + } + backlogIssues.add(issue); + } + } + } /** @@ -163,12 +183,16 @@ public class Backlog { return issues; } + public List getBacklogIssues() { + return backlogIssues; + } + public int getRankCustomFieldId() { return rankCustomFieldId; } - public List getOpenSprints() { - return openSprints; + public List getSprints() { + return sprints; } public List getProjects() { diff --git a/src/main/java/net/rcarz/jiraclient/greenhopper/GreenHopperField.java b/src/main/java/net/rcarz/jiraclient/greenhopper/GreenHopperField.java index f6862d6..e3e8b7e 100644 --- a/src/main/java/net/rcarz/jiraclient/greenhopper/GreenHopperField.java +++ b/src/main/java/net/rcarz/jiraclient/greenhopper/GreenHopperField.java @@ -37,6 +37,8 @@ public final class GreenHopperField { public static final String DATE_TIME_FORMAT = "d/MMM/yy h:m a"; + public static final String NO_DATE = "None"; + private GreenHopperField() { } /** @@ -47,9 +49,10 @@ public final class GreenHopperField { * @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; + if(dt == null || ((String)dt).equals(NO_DATE)){ + return null; + } + return DateTime.parse((String)dt, DateTimeFormat.forPattern(DATE_TIME_FORMAT)); } /** diff --git a/src/main/java/net/rcarz/jiraclient/greenhopper/Sprint.java b/src/main/java/net/rcarz/jiraclient/greenhopper/Sprint.java index e2274a3..374000d 100644 --- a/src/main/java/net/rcarz/jiraclient/greenhopper/Sprint.java +++ b/src/main/java/net/rcarz/jiraclient/greenhopper/Sprint.java @@ -22,6 +22,8 @@ package net.rcarz.jiraclient.greenhopper; import net.rcarz.jiraclient.Field; import net.rcarz.jiraclient.RestClient; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import net.sf.json.JSONObject; @@ -38,6 +40,8 @@ public class Sprint extends GreenHopperResource { private DateTime startDate = null; private DateTime endDate = null; private DateTime completeDate = null; + private List issuesIds = null; + private List issues = null; /** * Creates a sprint from a JSON payload. @@ -61,6 +65,7 @@ public class Sprint extends GreenHopperResource { startDate = GreenHopperField.getDateTime(map.get("startDate")); endDate = GreenHopperField.getDateTime(map.get("endDate")); completeDate = GreenHopperField.getDateTime(map.get("completeDate")); + issuesIds = GreenHopperField.getIntegerArray(map.get("issuesIds")); } @Override @@ -87,5 +92,20 @@ public class Sprint extends GreenHopperResource { public DateTime getCompleteDate() { return completeDate; } + + public void setIssues(List _issues){ + issues = _issues; + } + + public List getIssues(){ + if(issues == null){ + issues = new ArrayList(); + } + return issues; + } + + public List getIssuesIds() { + return issuesIds; + } }