Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding check for value as instance of valueTuple in custom Fields too. #255

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>net.rcarz</groupId>
<artifactId>jira-client</artifactId>
<version>0.6-SNAPSHOT</version>
<version>0.9-SNAPSHOT</version>
<packaging>jar</packaging>

<name>jira-client</name>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/net/rcarz/jiraclient/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,14 @@ public static JSONArray toArray(Iterable iter, String type, String custom) throw
type.equals("string") && custom != null
&& (custom.equals("com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes") ||
custom.equals("com.atlassian.jira.plugin.system.customfieldtypes:multiselect")))) {

realResult = new JSONObject();
((JSONObject)realResult).put(ValueType.VALUE.toString(), realValue.toString());
if (realValue instanceof ValueTuple) {
ValueTuple tuple = (ValueTuple)realValue;
((JSONObject)realResult).put(tuple.type, tuple.value.toString());
} else {
((JSONObject)realResult).put(ValueType.VALUE.toString(), realValue.toString());
}

} else if (type.equals("string"))
realResult = realValue.toString();

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/net/rcarz/jiraclient/JiraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.util.logging.Logger;

/**
* A simple JIRA REST client.
*/
public class JiraClient {

private RestClient restclient = null;
private String username = null;
private RestClient restclient = null;
private String username = null;
private static Logger logger = Logger.getLogger("JiraClient");

/**
* Creates a JIRA client.
Expand Down Expand Up @@ -468,6 +470,7 @@ public List<Project> getProjects() throws JiraException {
try {
URI uri = restclient.buildURI(Resource.getBaseUri() + "project");
JSON response = restclient.get(uri);
logger.info("JIRA - RESPONSE " + response.toString());
JSONArray projectsArray = JSONArray.fromObject(response);

List<Project> projects = new ArrayList<Project>(projectsArray.size());
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/net/rcarz/jiraclient/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.logging.Logger;

/**
* A simple REST client that speaks JSON.
Expand All @@ -63,15 +64,17 @@ public class RestClient {
private ICredentials creds = null;
private URI uri = null;

/**
* Creates a REST client instance with a URI.
*
* @param httpclient Underlying HTTP client to use
* @param uri Base URI of the remote REST service
*/
public RestClient(HttpClient httpclient, URI uri) {
this(httpclient, null, uri);
}
private static Logger logger = Logger.getLogger("RestClient");

/**
* Creates a REST client instance with a URI.
*
* @param httpclient Underlying HTTP client to use
* @param uri Base URI of the remote REST service
*/
public RestClient(HttpClient httpclient, URI uri) {
this(httpclient, null, uri);
}

/**
* Creates an authenticated REST client instance with a URI.
Expand Down Expand Up @@ -128,6 +131,9 @@ private JSON request(HttpRequestBase req) throws RestException, IOException {
creds.authenticate(req);

HttpResponse resp = httpClient.execute(req);
logger.info("REST - RESPONSE" + resp.toString());
logger.info("RESPONSE HEADERS : " + resp.getAllHeaders());
logger.info("STATUS CODE: " + resp.getStatusLine().getStatusCode());
HttpEntity ent = resp.getEntity();
StringBuilder result = new StringBuilder();

Expand All @@ -139,6 +145,7 @@ private JSON request(HttpRequestBase req) throws RestException, IOException {

if (encoding == null) {
Header contentTypeHeader = resp.getFirstHeader("Content-Type");
logger.info("ContentTypeHeader : " + contentTypeHeader);
HeaderElement[] contentTypeElements = contentTypeHeader.getElements();
for (HeaderElement he : contentTypeElements) {
NameValuePair nvp = he.getParameterByName("charset");
Expand Down Expand Up @@ -170,6 +177,7 @@ private JSON request(HttpRequestBase req) throws RestException, IOException {
if (sl.getStatusCode() >= 300)
throw new RestException(sl.getReasonPhrase(), sl.getStatusCode(), result.toString(), resp.getAllHeaders());

logger.info("Rest Client Result: " + result );
return result.length() > 0 ? JSONSerializer.toJSON(result.toString()): null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/rcarz/jiraclient/TimeTracking.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ protected JSONObject toJsonObject() {
if (remainingEstimate != null)
object.put("remainingEstimate", remainingEstimate);

if (originalEstimateSeconds >= 0)
if (originalEstimateSeconds != null && originalEstimateSeconds >= 0)
object.put("originalEstimateSeconds", originalEstimateSeconds);

if (remainingEstimateSeconds >= 0)
if (remainingEstimateSeconds != null && remainingEstimateSeconds >= 0)
object.put("remainingEstimateSeconds", remainingEstimateSeconds);

return object;
Expand Down