1
0
Fork 0

replaced the map for custom field values with a ValueTuple list

master
Bob Carroll 2013-10-14 15:51:50 -07:00
parent acda71453e
commit e0810c82d3
2 changed files with 28 additions and 19 deletions

View File

@ -45,7 +45,6 @@ Patches are welcome and appreciated. Please try to follow existing styles, and s
```java ```java
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import net.rcarz.jiraclient.BasicCredentials; import net.rcarz.jiraclient.BasicCredentials;
@ -149,10 +148,10 @@ public class Example {
/* Set two new values for customfield_5678. */ /* Set two new values for customfield_5678. */
issue.update() issue.update()
.field("customfield_5678", new HashMap() {{ .field("customfield_5678", new ArrayList() {{
put("value", "foo"); add("foo");
put("value", "bar"); add("bar");
put("id", "1234"); /* you can also update using the value ID */ add(Field.valueById("1234")); /* you can also update using the value ID */
}}) }})
.execute(); .execute();

View File

@ -73,11 +73,16 @@ public final class Field {
* Allowed value types. * Allowed value types.
*/ */
public enum ValueType { public enum ValueType {
KEY("key"), NAME("name"), ID_NUMBER("id"); KEY("key"), NAME("name"), ID_NUMBER("id"), VALUE("value");
private String value; private String typeName;
private ValueType(String value) { private ValueType(String typeName) {
this.value = value; this.typeName = typeName;
}
@Override
public String toString() {
return typeName;
} }
}; };
@ -106,7 +111,7 @@ public final class Field {
* @param value * @param value
*/ */
public ValueTuple(ValueType type, Object value) { public ValueTuple(ValueType type, Object value) {
this(type.value, value); this(type.toString(), value);
} }
} }
@ -470,7 +475,7 @@ public final class Field {
ValueTuple tuple = (ValueTuple)val; ValueTuple tuple = (ValueTuple)val;
json.put(tuple.type, tuple.value.toString()); json.put(tuple.type, tuple.value.toString());
} else } else
json.put(ValueType.NAME.value, val.toString()); json.put(ValueType.NAME.toString(), val.toString());
result.add(json.toString()); result.add(json.toString());
} else if (type.equals("string")) } else if (type.equals("string"))
@ -542,7 +547,7 @@ public final class Field {
ValueTuple tuple = (ValueTuple)value; ValueTuple tuple = (ValueTuple)value;
json.put(tuple.type, tuple.value.toString()); json.put(tuple.type, tuple.value.toString());
} else } else
json.put(ValueType.NAME.value, value.toString()); json.put(ValueType.NAME.toString(), value.toString());
return json.toString(); return json.toString();
} else if (m.type.equals("project") || m.type.equals("issuelink")) { } else if (m.type.equals("project") || m.type.equals("issuelink")) {
@ -552,12 +557,12 @@ public final class Field {
ValueTuple tuple = (ValueTuple)value; ValueTuple tuple = (ValueTuple)value;
json.put(tuple.type, tuple.value.toString()); json.put(tuple.type, tuple.value.toString());
} else } else
json.put(ValueType.KEY.value, value.toString()); json.put(ValueType.KEY.toString(), value.toString());
return json.toString(); return json.toString();
} else if (m.type.equals("string")) { } else if (m.type.equals("string")) {
if (value instanceof Map) if (value instanceof List)
return toJsonMap((Map)value); return toJsonMap((List)value);
return value.toString(); return value.toString();
} }
@ -568,15 +573,20 @@ public final class Field {
/** /**
* Converts the given map to a JSON object. * Converts the given map to a JSON object.
* *
* @param map Map to be converted * @param list List of values to be converted
* *
* @return a JSON-encoded map * @return a JSON-encoded map
*/ */
public static Object toJsonMap(Map map) { public static Object toJsonMap(List list) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
for (Object k : map.keySet()) for (Object item : list) {
json.put(k, map.get(k)); if (item instanceof ValueTuple) {
ValueTuple vt = (ValueTuple)item;
json.put(vt.type, vt.value.toString());
} else
json.put(ValueType.VALUE.toString(), item.toString());
}
return json.toString(); return json.toString();
} }