1
0
Fork 0

implemented retrieval of custom fields

master
Bob Carroll 2013-05-23 19:13:27 -07:00
parent 05cce72a6b
commit 29374abfd7
3 changed files with 105 additions and 1 deletions

View File

@ -0,0 +1,87 @@
/**
* 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.JSONObject;
/**
* Represents an custom field option.
*/
public final class CustomFieldOption extends Resource {
private String value = null;
/**
* Creates a custom field option from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected CustomFieldOption(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"));
value = Field.getString(map.get("value"));
}
/**
* Retrieves the given custom field option record.
*
* @param restclient REST client instance
* @param id Internal JIRA ID of the custom field option
*
* @return a custom field option instance
*
* @throws JiraException when the retrieval fails
*/
public static CustomFieldOption get(RestClient restclient, String id)
throws JiraException {
JSONObject result = null;
try {
result = restclient.get(RESOURCE_URI + "customFieldOption/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve custom field option " + id, ex);
}
return new CustomFieldOption(restclient, result);
}
@Override
public String toString() {
return getValue();
}
public String getValue() {
return value;
}
}

View File

@ -187,6 +187,8 @@ public final class Field {
result = (T)new Comment(restclient, (JSONObject)r);
else if (type == Component.class)
result = (T)new Component(restclient, (JSONObject)r);
else if (type == CustomFieldOption.class)
result = (T)new CustomFieldOption(restclient, (JSONObject)r);
else if (type == IssueType.class)
result = (T)new IssueType(restclient, (JSONObject)r);
else if (type == Priority.class)
@ -266,6 +268,8 @@ public final class Field {
results.add((T)new Comment(restclient, (JSONObject)v));
else if (type == Component.class)
results.add((T)new Component(restclient, (JSONObject)v));
else if (type == CustomFieldOption.class)
results.add((T)new CustomFieldOption(restclient, (JSONObject)v));
else if (type == IssueType.class)
results.add((T)new IssueType(restclient, (JSONObject)v));
else if (type == Priority.class)

View File

@ -188,6 +188,7 @@ public final class Issue extends Resource {
}
private String key = null;
private Map fields = null;
/* system fields */
private User assignee = null;
@ -229,7 +230,7 @@ public final class Issue extends Resource {
self = Field.getString(map.get("self"));
key = Field.getString(map.get("key"));
Map fields = (Map)map.get("fields");
fields = (Map)map.get("fields");
assignee = Field.getResource(User.class, fields.get(Field.ASSIGNEE), restclient);
attachments = Field.getResourceArray(Attachment.class, fields.get(Field.ASSIGNEE), restclient);
@ -357,6 +358,18 @@ public final class Issue extends Resource {
return new Issue(restclient, result);
}
/**
* Gets an arbitrary field by its name.
*
* @param name Name of the field to retrieve
*
* @return the field value or null if not found
*/
public Object getField(String name) {
return fields != null ? fields.get(name) : null;
}
/**
* Begins a transition field chain.
*