Yesterday when I was going through some article, I saw lots requests and comments for JIRA REST JAVA Client!!!
I wondered and decided to provide the REST JAVA API for JIRA, and this is the one.
Connecting to JIRA using JAVA REST API is really a very easy thing like Ice Cream Sandwich ;) :) and can be written in a plain vanilla flavor.
Today I'm providing you the search operation functionality to get the tickets.
/**
* Gets all the issues based on the query and displays .... !!!!
*
* @param username the username
* @param password the password
* @param url the url
* @return the all issues
* @throws AuthenticationException the authentication exception
* @throws JSONException the jSON exception
*/
private static void getAllIssues(String username, String password, String url) throws AuthenticationException, JSONException
{
final String auth = new String(Base64.encode(username + ":" + password));
final Client client = Client.create();
final WebResource webResource = client.resource(url);
final ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json")
.accept("application/json").get(ClientResponse.class);
final int statusCode = response.getStatus();
if (statusCode == 401)
{
throw new AuthenticationException("Invalid Username or Password");
}
final String stringResponse = response.getEntity(String.class);
System.out.println("sr: " + stringResponse);
}
Usage of the above method:
1) getAllIssues("krishna", "krishna", "http://server:8080/rest/api/latest/search?jql");
fetches all the issues.. !!!
2) getAllIssues("krishna", "krishna", " http://server:8080/rest/api/latest/issue/Issue-84?expand=schema,names,transitions");
It gets all the issue whose key is Issue-84.... !!!
Have FUN...!!!!
while doing transition, how can we set assignee user in TransitionInput?
ReplyDeletehow can i convert the json string to java object ,is there any api for that?
ReplyDelete{
"expand":"schema,names",
"startAt":0,
"maxResults":50,
"total":2,
"issues":[
{},
{
"expand":"editmeta,renderedFields,transitions,changelog,operations",
"id":"10000",
"self":"http://jira.appanalytix.com/rest/api/2/issue/10000",
"key":"APPANLYTIX-1",
"fields":{
"summary":"Generate maven POM files for bundles",
"progress":{},
"issuetype":{
"self":"http://jira.appanalytix.com/rest/api/2/issuetype/1",
"id":"1",
"description":"A problem which impairs or prevents the functions of the product.",
"iconUrl":"http://jira.appanalytix.com/images/icons/issuetypes/bug.png",
"name":"Bug",
"subtask":false
},
"votes":{},
"resolution":null,
"fixVersions":[],
"resolutiondate":null,
"timespent":null,
"reporter":{},
"aggregatetimeoriginalestimate":28800,
"updated":"2013-07-16T11:29:31.000+0000",
"created":"2013-07-16T11:27:09.000+0000",
"description":"Sometimes you might want to use bundles in a Maven context. We currently have no support to generate a POM from a bundle and we want to add that so we can support various Maven repositories out there.",
"priority":{},
"duedate":null,
"issuelinks":[],
"watches":{},
"subtasks":[],
"status":{},
"labels":[],
"workratio":0,
"assignee":{},
"aggregatetimeestcurl: (6) Couldn't resolve host 'Dev' imate":28800,
"project":{},
"versions":[],
"environment":"windows",
"timeestimate":28800,
"aggregateprogress":{},
"lastViewed":"2013-07-18T04:39:52.596+0000",
"components":[],
"timeoriginalestimate":28800,
"aggregatetimespent":null
}
}
]
}