1
0
Fork 0

implemented reading issue links

master
Bob Carroll 2013-05-28 15:46:21 -07:00
parent c3e00d4304
commit b91162e722
5 changed files with 219 additions and 2 deletions

View File

@ -57,6 +57,7 @@ public final class Field {
public static final String DESCRIPTION = "description";
public static final String DUE_DATE = "duedate";
public static final String FIX_VERSIONS = "fixVersions";
public static final String ISSUE_LINKS = "issuelinks";
public static final String ISSUE_TYPE = "issuetype";
public static final String LABELS = "labels";
public static final String PRIORITY = "priority";
@ -191,8 +192,14 @@ public final class Field {
result = (T)new Component(restclient, (JSONObject)r);
else if (type == CustomFieldOption.class)
result = (T)new CustomFieldOption(restclient, (JSONObject)r);
else if (type == Issue.class)
result = (T)new Issue(restclient, (JSONObject)r);
else if (type == IssueLink.class)
result = (T)new IssueLink(restclient, (JSONObject)r);
else if (type == IssueType.class)
result = (T)new IssueType(restclient, (JSONObject)r);
else if (type == LinkType.class)
result = (T)new LinkType(restclient, (JSONObject)r);
else if (type == Priority.class)
result = (T)new Priority(restclient, (JSONObject)r);
else if (type == Project.class)
@ -274,8 +281,14 @@ public final class Field {
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)

View File

@ -261,6 +261,7 @@ public final class Issue extends Resource {
private String description = null;
private Date dueDate = null;
private List<Version> fixVersions = null;
private List<IssueLink> issueLinks = null;
private IssueType issueType = null;
private List<String> labels = null;
private Priority priority = null;
@ -304,6 +305,7 @@ public final class Issue extends Resource {
description = Field.getString(fields.get(Field.DESCRIPTION));
dueDate = Field.getDate(fields.get(Field.DUE_DATE));
fixVersions = Field.getResourceArray(Version.class, fields.get(Field.FIX_VERSIONS), restclient);
issueLinks = Field.getResourceArray(IssueLink.class, fields.get(Field.ISSUE_LINKS), restclient);
issueType = Field.getResource(IssueType.class, fields.get(Field.ISSUE_TYPE), restclient);
labels = Field.getStringArray(fields.get(Field.LABELS));
priority = Field.getResource(Priority.class, fields.get(Field.PRIORITY), restclient);
@ -656,6 +658,10 @@ public final class Issue extends Resource {
return fixVersions;
}
public List<IssueLink> getIssueLinks() {
return issueLinks;
}
public IssueType getIssueType() {
return issueType;
}

View File

@ -0,0 +1,97 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
/**
* Represents an issue link.
*/
public final class IssueLink extends Resource {
private LinkType type = null;
private Issue inwardIssue = null;
/**
* Creates a issue link from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected IssueLink(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
self = Field.getString(map.get("self"));
id = Field.getString(map.get("id"));
type = Field.getResource(LinkType.class, map.get("type"), restclient);
inwardIssue = Field.getResource(Issue.class, map.get("inwardIssue"), restclient);
}
/**
* Retrieves the given issue link record.
*
* @param restclient REST client instance
* @param id Internal JIRA ID of the issue link
*
* @return a issue link instance
*
* @throws JiraException when the retrieval fails
*/
public static IssueLink get(RestClient restclient, String id)
throws JiraException {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issueLink/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve issue link " + id, ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
return new IssueLink(restclient, (JSONObject)result);
}
@Override
public String toString() {
return String.format("%s %s", getType().getInward(), getInwardIssue());
}
public LinkType getType() {
return type;
}
public Issue getInwardIssue() {
return inwardIssue;
}
}

View File

@ -26,8 +26,6 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import net.sf.json.JSONObject;
/**
* A simple JIRA REST client.
*/

View File

@ -0,0 +1,103 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
/**
* Represents an issue link type.
*/
public final class LinkType extends Resource {
private String name = null;
private String inward = null;
private String outward = null;
/**
* Creates a issue link type from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected LinkType(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
self = Field.getString(map.get("self"));
id = Field.getString(map.get("id"));
name = Field.getString(map.get("name"));
inward = Field.getString(map.get("inward"));
outward = Field.getString(map.get("outward"));
}
/**
* Retrieves the given issue link type record.
*
* @param restclient REST client instance
* @param id Internal JIRA ID of the issue link type
*
* @return a issue link type instance
*
* @throws JiraException when the retrieval fails
*/
public static LinkType get(RestClient restclient, String id)
throws JiraException {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issueLinkType/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve issue link type " + id, ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
return new LinkType(restclient, (JSONObject)result);
}
@Override
public String toString() {
return getName();
}
public String getName() {
return name;
}
public String getInward() {
return inward;
}
public String getOutward() {
return outward;
}
}