1
0
Fork 0

added option to change the JIRA API revision used by the client

master
Bob Carroll 2014-01-17 13:56:46 -08:00
parent 7505aa747c
commit e6d0f04ec5
19 changed files with 47 additions and 25 deletions

View File

@ -86,7 +86,7 @@ public class Attachment extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "attachment/" + id);
result = restclient.get(getBaseUri() + "attachment/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve attachment " + id, ex);
}

View File

@ -78,7 +78,7 @@ public class Comment extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issue/" + issue + "/comment/" + id);
result = restclient.get(getBaseUri() + "issue/" + issue + "/comment/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve comment " + id + " on issue " + issue, ex);
}

View File

@ -70,7 +70,7 @@ public class Component extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "component/" + id);
result = restclient.get(getBaseUri() + "component/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve component " + id, ex);
}

View File

@ -68,7 +68,7 @@ public class CustomFieldOption extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "customFieldOption/" + id);
result = restclient.get(getBaseUri() + "customFieldOption/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve custom field option " + id, ex);
}

View File

@ -426,7 +426,7 @@ public class Issue extends Resource {
}
private static String getRestUri(String key) {
return RESOURCE_URI + "issue/" + (key != null ? key : "");
return getBaseUri() + "issue/" + (key != null ? key : "");
}
public static JSONObject getCreateMetadata(
@ -438,7 +438,7 @@ public class Issue extends Resource {
try {
URI createuri = restclient.buildURI(
RESOURCE_URI + "issue/createmeta",
getBaseUri() + "issue/createmeta",
new HashMap<String, String>() {{
put("expand", "projects.issuetypes.fields");
put("projectKeys", pval);
@ -638,7 +638,7 @@ public class Issue extends Resource {
}
try {
restclient.post(RESOURCE_URI + "issueLink", req);
restclient.post(getBaseUri() + "issueLink", req);
} catch (Exception ex) {
throw new JiraException("Failed to link issue " + key + " with issue " + issue, ex);
}
@ -686,7 +686,7 @@ public class Issue extends Resource {
JSON result = null;
try {
URI uri = restclient.buildURI(RESOURCE_URI + "issue/" + key, queryParams);
URI uri = restclient.buildURI(getBaseUri() + "issue/" + key, queryParams);
result = restclient.get(uri);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve issue " + key, ex);
@ -804,7 +804,7 @@ public class Issue extends Resource {
if (includedFields != null) {
queryParams.put("fields", includedFields);
}
URI searchUri = restclient.buildURI(RESOURCE_URI + "search", queryParams);
URI searchUri = restclient.buildURI(getBaseUri() + "search", queryParams);
result = restclient.get(searchUri);
} catch (Exception ex) {
throw new JiraException("Failed to search issues", ex);

View File

@ -64,7 +64,7 @@ public class IssueLink extends Resource {
public void delete() throws JiraException {
try {
restclient.delete(RESOURCE_URI + "issueLink/" + id);
restclient.delete(getBaseUri() + "issueLink/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to delete issue link " + id, ex);
}
@ -86,7 +86,7 @@ public class IssueLink extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issueLink/" + id);
result = restclient.get(getBaseUri() + "issueLink/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve issue link " + id, ex);
}

View File

@ -78,7 +78,7 @@ public class IssueType extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issuetype/" + id);
result = restclient.get(getBaseUri() + "issuetype/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve issue type " + id, ex);
}

View File

@ -208,7 +208,7 @@ public class JiraClient {
*/
public List<Priority> getPriorities() throws JiraException {
try {
URI uri = restclient.buildURI(Resource.RESOURCE_URI + "priority");
URI uri = restclient.buildURI(Resource.getBaseUri() + "priority");
JSON response = restclient.get(uri);
JSONArray prioritiesArray = JSONArray.fromObject(response);

View File

@ -72,7 +72,7 @@ public class LinkType extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issueLinkType/" + id);
result = restclient.get(getBaseUri() + "issueLinkType/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve issue link type " + id, ex);
}

View File

@ -70,7 +70,7 @@ public class Priority extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "priority/" + id);
result = restclient.get(getBaseUri() + "priority/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve priority " + id, ex);
}

View File

@ -91,7 +91,7 @@ public class Project extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "project/" + key);
result = restclient.get(getBaseUri() + "project/" + key);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve project " + key, ex);
}
@ -115,7 +115,7 @@ public class Project extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "project");
result = restclient.get(getBaseUri() + "project");
} catch (Exception ex) {
throw new JiraException("Failed to retrieve projects", ex);
}

View File

@ -70,7 +70,7 @@ public class Resolution extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "resolution/" + id);
result = restclient.get(getBaseUri() + "resolution/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve resolution " + id, ex);
}

View File

@ -24,7 +24,8 @@ package net.rcarz.jiraclient;
*/
public abstract class Resource {
protected static final String RESOURCE_URI = "/rest/api/2/";
public static final String DEFAULT_API_REV = "latest";
public static String apirev = DEFAULT_API_REV;
protected RestClient restclient = null;
protected String id = null;
@ -39,6 +40,27 @@ public abstract class Resource {
this.restclient = restclient;
}
/**
* Gets the JIRA REST API revision number.
*/
public static String getApiRev() {
return apirev;
}
/**
* Sets the JIRA REST API revision number.
*/
public static void setApiRev(String apirev) {
Resource.apirev = apirev;
}
/**
* Resource base URI with API revision number.
*/
public static String getBaseUri() {
return String.format("/rest/api/%s/", apirev);
}
/**
* Internal JIRA ID.
*/

View File

@ -72,7 +72,7 @@ public class Status extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "status/" + id);
result = restclient.get(getBaseUri() + "status/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve status " + id, ex);
}

View File

@ -62,7 +62,7 @@ public class User extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "user?username=" + username);
result = restclient.get(getBaseUri() + "user?username=" + username);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve user " + username, ex);
}

View File

@ -62,7 +62,7 @@ public class Version extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "version/" + id);
result = restclient.get(getBaseUri() + "version/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve version " + id, ex);
}

View File

@ -71,7 +71,7 @@ public class Votes extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issue/" + issue + "/votes");
result = restclient.get(getBaseUri() + "issue/" + issue + "/votes");
} catch (Exception ex) {
throw new JiraException("Failed to retrieve votes for issue " + issue, ex);
}

View File

@ -71,7 +71,7 @@ public class Watches extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issue/" + issue + "/watches");
result = restclient.get(getBaseUri() + "issue/" + issue + "/watches");
} catch (Exception ex) {
throw new JiraException("Failed to retrieve watches for issue " + issue, ex);
}

View File

@ -84,7 +84,7 @@ public class WorkLog extends Resource {
JSON result = null;
try {
result = restclient.get(RESOURCE_URI + "issue/" + issue + "/worklog/" + id);
result = restclient.get(getBaseUri() + "issue/" + issue + "/worklog/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve work log " + id + " on issue " + issue, ex);
}