How to get filters share with specific project?


#1

I want to get the filters which are shared for specific project?
For example:
Get all filters: Due this week (ATD), Open and unassigned (ATD) and Overdue (ATD) For project ATD

How can I do it?

It could be nice if I can get via REST.
I can get all filters via this script

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
searchRequestList = new ArrayList<>(searchRequestService.getOwnedFilters(user));

Thanks,


#2

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/bc/filter/ProjectSearchRequestService.html#getSearchRequestsForProject-com.atlassian.jira.user.ApplicationUser-com.atlassian.jira.project.Project-

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey('ZZZBLANK');
ProjectSearchRequestService projectSearchRequestService = ComponentAccessor.getComponent(ProjectSearchRequestService);

List<SearchRequest> searchRequests = projectSearchRequestService.getSearchRequestsForProject(loggedInUser, project);

log..warn (searchRequests);
[Search Request: name: Open and unassigned (ZZZBLANK) query = {project = 19202} AND {statusCategory != "Done"} AND {assignee = EMPTY} order by priority DESC, Search Request: name: Due this week (ZZZBLANK) query = {project = 19202} AND {duedate >= startOfWeek()} AND {duedate <= endOfWeek()} order by priority DESC, Search Request: name: Overdue (ZZZBLANK) query = {project = 19202} AND {statusCategory != "Done"} AND {duedate < now()} order by duedate DESC]

#3

Thank you so much @sfbehnke
And how about get all popular filters?

For your script if I apply for this case. It’s only get 3 searchRequest Due this week (DP), Open and unassigned (DP) and Overdue (DP) For project DP . But It’s doesn’t get filter “all issue DP”


Cheers


#4

I see. The API I provided you is only useful for capturing the Filters that are present on a Project > Issues tab – There’s a dropdown that allows selecting a few pre-defined filters. That’s all that the ProjectSearchRequestService is responsible for.

For your usecases, I would probably use SearchRequestManager::visitAll method – https://docs.atlassian.com/software/jira/docs/api/7.2.0/com/atlassian/jira/issue/search/SearchRequestManager.html

The visitAll method would all you to iterate over all filters and grab the ones you care about while comparing properties.


#5

Thank you @sfbehnke, I did it :smiley:
I use the same method like you recommend
https://docs.atlassian.com/software/jira/docs/api/7.2.0/com/atlassian/jira/issue/search/DefaultSearchRequestManager.html : method getAll()


#6

Woo hoo! :slight_smile: Glad to hear.

Please note this comment on the getAll() method:
WARNING: This method will run horribly slow on systems with a lot of saved filters.

Please keep in mind that the visitAll(Visitor<SearchRequest>) pattern will save you if performance is a problem. I’d recommend using the visitor pattern.


#7

Thank for your suggestion @sfbehnke,

SearchRequestManager searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager.class);
    searchRequestManager.visitAll(new Visitor<SearchRequestEntity>() {
      @Override
      public void visit(SearchRequestEntity searchRequestEntity) {
         // do some thing
      }
    });

But I can’t get SharePermission to filter which one I want to show :frowning:
I just want to get all SearchRequest which shared with project.