5

I'm trying to get all issues of project and then find which are done, but I don't know how.
I connected user to Jira and than wanted to get all of his project and all of issue on him. Then I want to find, which issues from that are done. Can anybody help me, please?

I've got this:

Iterable <BasicProject> allProj;
this.yourUsername = userName;
this.yourPassword = password;

this.jiraServerUri = new URI("https://applifting.atlassian.net");
this.factory = new JerseyJiraRestClientFactory();;
this.restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, yourUsername, yourPassword);
final NullProgressMonitor pm = new NullProgressMonitor();
allProj = this.restClient.getProjectClient().getAllProjects(pm);

for(Iterator<BasicProject> i = allProj.iterator(); i.hasNext(); ) {
    BasicProject proj = i.next();
    Project ActualProject = this.restClient.getProjectClient().getProject(proj.getKey(), pm);
    ComponentRestClient cm =

}

I thought in this for cycle I should get all issues when I have all project.

dur
  • 15,689
  • 25
  • 79
  • 125
Jitka Hodná
  • 53
  • 1
  • 1
  • 4

1 Answers1

14

If you have a JQL that specifies your search criteria, you can invoke that: https://docs.atlassian.com/jira/REST/latest/#d2e2716

For a code example, please take a look here: https://answers.atlassian.com/questions/192961/answers/4049301

A working example: (also here: http://pastebin.com/WUMZ0vZa)

package com.example.jirasandbox;

import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.SearchResult;
import com.atlassian.jira.rest.client.api.domain.User;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import com.atlassian.util.concurrent.Promise;
import java.net.URI;

public class CustomJiraRestClient {

    private static final String JIRA_URL = "http://jira-dev:8080";
    private static final String JIRA_ADMIN_USERNAME = "admin";
    private static final String JIRA_ADMIN_PASSWORD = "admin";

    public static void main(String[] args) throws Exception {
        // Construct the JRJC client
        System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD));
        JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        URI uri = new URI(JIRA_URL);
        JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);

        // Invoke the JRJC Client
        Promise<User> promise = client.getUserClient().getUser("admin");
        User user = promise.claim();

        for (BasicProject project : client.getProjectClient().getAllProjects().claim()) {
            System.out.println(project.getKey() + ": " + project.getName());
        }

        Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql("project = MYPURRJECT AND status in (Closed, Completed, Resolved) ORDER BY assignee, resolutiondate");

        for (Issue issue : searchJqlPromise.claim().getIssues()) {
            System.out.println(issue.getSummary());
        }

        // Print the result
        System.out.println(String.format("Your admin user's email address is: %s\r\n", user.getEmailAddress()));

        // Done
        System.out.println("Example complete. Now exiting.");
        System.exit(0);
    }
}
Koshinae
  • 2,240
  • 2
  • 30
  • 40
  • Thanks a lot, in that working example the String URL is my jira, right? And Promise searchJqlPromise = client.getSearchClient().searchJql("project = MYPURRJECT AND status in (Closed, Completed, Resolved) ORDER BY assignee, resolutiondate"); - how should you know how to specify that? – Jitka Hodná Mar 23 '15 at 10:59
  • 1
    Your connection to jira is in `this.restClient`object . Use `restClient.getSearchClient().searchJql(JQLquery)` function with JQL query to get issues you want. To get JQL query log into Jira and in issue navigator search for issues you want, then switch to Advanced search using JQL and there is your JQL query. – ThePavolC Mar 23 '15 at 13:49
  • Yes, the JIRA_URL points to your jira. Also, @ThePavolC gets it right, you can issue JQL queries on the site there. "Issues" menu on the top, then "Search for Issues" menuitem, then click the "Advanced" link. – Koshinae Mar 23 '15 at 14:37
  • You mean to include the stuff that resides now in pastebin? – Koshinae Oct 23 '15 at 17:52
  • Hi @Koshinae - Do we definitely need REST api setup or Can I just use Jira rest java client jar and get the jira issues? We are using JIRA cloud. And Do I need to use only jira admin credentials? Please help me. I am new to this feature. – Shiva Krishna Chippa Sep 12 '18 at 07:05
  • You can use any active user (AFAIK). Also, the new approach is the REST way, so you should try both :) – Koshinae Sep 12 '18 at 07:14
  • I'm getting 'incompatible types: com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory cannot be converted to com.atlassian.jira.rest.client.JiraRestClientFactory'. – SuperHanz98 Jul 05 '19 at 13:36
  • Hey @Koshinae, Here u have provided username and password. Can we call api using only personal api token of jira? – Koushik J Mar 04 '21 at 08:05