1
0
Fork 0

Merge pull request #1 from rcarz/master

Merging rcarz/jira-client changes to my branch.
master
Paulo Casanova 2014-05-21 14:47:38 +01:00
commit be3bfdd736
5 changed files with 45 additions and 29 deletions

View File

@ -171,7 +171,7 @@ public class Component extends Resource {
JSON result = null;
try {
result = restclient.get(getBaseUri() + "component/" + id);
result = restclient.get(getRestUri(id));
} catch (Exception ex) {
throw new JiraException("Failed to retrieve component " + id, ex);
}
@ -198,7 +198,7 @@ public class Component extends Resource {
private static String getRestUri(String id) {
return getBaseUri() + "component/" + (id != null ? id : "");
}
/**
* Creates a new JIRA component.
*
@ -211,5 +211,18 @@ public class Component extends Resource {
FluentCreate fc = new FluentCreate(restclient, project);
return fc;
}
/**
* Deletes a component from a project.
*
* @throws JiraException failed to delete the component
*/
public void delete() throws JiraException {
try {
restclient.delete(getRestUri(id));
} catch (Exception ex) {
throw new JiraException("Failed to delete component " + id, ex);
}
}
}

View File

@ -574,6 +574,12 @@ public final class Field {
} else if (m.type.equals("string")) {
if (value instanceof List)
return toJsonMap((List)value);
else if (value instanceof ValueTuple) {
JSONObject json = new JSONObject();
ValueTuple tuple = (ValueTuple)value;
json.put(tuple.type, tuple.value.toString());
return json.toString();
}
return value.toString();
} else if (m.type.equals("timetracking")) {

View File

@ -421,30 +421,6 @@ public class JiraClient {
* @throws JiraException failed to obtain the component
*/
public Component getComponent(String id) throws JiraException {
try {
URI uri = restclient.buildURI(Resource.getBaseUri() + "/component/"
+ id);
JSON response = restclient.get(uri);
return new Component(restclient, ((JSONObject) response));
} catch (Exception ex) {
throw new JiraException(ex.getMessage(), ex);
}
}
/**
* Deletes a component from a project.
*
* @param id the component ID
*
* @throws JiraException failed to delete the component
*/
public void deleteComponent(String id) throws JiraException {
try {
URI uri = restclient.buildURI(Resource.getBaseUri() + "component/"
+ id);
JSON response = restclient.delete(uri);
} catch (Exception ex) {
throw new JiraException(ex.getMessage(), ex);
}
return Component.get(restclient, id);
}
}

View File

@ -243,6 +243,22 @@ public class RestClient {
return request(new HttpGet(uri));
}
/**
* Executes an HTTP GET with the given path.
*
* @param path Path to be appended to the URI supplied in the construtor
* @param params Map of key value pairs
*
* @return JSON-encoded result or null when there's no content returned
*
* @throws RestException when an HTTP-level error occurs
* @throws IOException when an error reading the response occurs
* @throws URISyntaxException when an error occurred appending the path to the URI
*/
public JSON get(String path, Map<String, String> params) throws RestException, IOException, URISyntaxException {
return get(buildURI(path, params));
}
/**
* Executes an HTTP GET with the given path.
*
@ -255,9 +271,10 @@ public class RestClient {
* @throws URISyntaxException when an error occurred appending the path to the URI
*/
public JSON get(String path) throws RestException, IOException, URISyntaxException {
return get(buildURI(path));
return get(path, null);
}
/**
* Executes an HTTP POST with the given URI and payload.
*

View File

@ -22,6 +22,7 @@ package net.rcarz.jiraclient;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
/**
@ -61,8 +62,11 @@ public class User extends Resource {
JSON result = null;
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
try {
result = restclient.get(getBaseUri() + "user?username=" + username);
result = restclient.get(getBaseUri() + "user", params);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve user " + username, ex);
}