It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get issues of specific type with Java api

Hi, I'm newbie to Jira plugin development. I need get all issues for specific project by specifying type.

I've tried JqlQueryBuilder, but it's very slow.

Currently I'm getting list of all issues for project and then filtering them:

Collection<Long> issuesIds = issueManager.getIssueIdsForProject(project.getId());
List<Issue> issues = issueManager.getIssueObjects(issuesIds);

However it's not best solution, since getting all issues for project taking also lots of time (less then JqlQueryBuilder, but still too much).

 

Is there any chance to specify issue type for search to cut unwanted issues?

1 answer

1 accepted

1 vote
Answer accepted

After further investigation I've figured out the way how specify issue type and sprint in JqlQueryBuilder query:

 

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObjectByName("Sprint");
SearchService searchProvider = ComponentAccessor.getComponentOfType(SearchService.class);

JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
builder.where()
.project(project.getId())
.and()
.sub()
.issueType("Story").or().issueType("Bug")
.endsub()
.and()
.customField(customField.getIdAsLong()).eq(sprint.trim());

SearchResults results = searchProvider
.searchOverrideSecurity(user, builder.buildQuery(), PagerFilter.getUnlimitedFilter());

List<Issue> issues = results.getIssues();

As result you're getting all desired issues.

In Jira 8, getIssues() method has been replaced with getResults()

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you