Does JIRA-API-Model support following object constellation (Dashboard -> Gadget -> Filter -> Query)?

I want to get all gadgets in a particular dashboard and the filter in all gadgets and the query in the filter.

Does JIRA-API-Model support that way of accessing a query like shown below?

Dashboard -> Gadget -> Filter -> Query

Via PortletConfigurationManager I've already tried to get from my dashboard to its gadgets and from the gadgets to their filter.

But the only method when I get a particular PortletConfiguration is getGadgetUri() to get somehow to a gadget. It always leads me like the method's name already says to

rest/gadgets/1.0/g/com.atlassian.jira.gadgets:filter-results-gadget/gadgets/filter-results-gadget.xml

From this point I don't know how to go on in order to get to that filter that is saved in the gadget.

1 answer

1 accepted

This widget could not be displayed.

Ok, finally I found a solution how to resolve that Problem.

With the PortletPageService you can get the PortletConfigurations. Every PortletConfiguration in the PortletConfiguerartions allocates a Map with UserPrefs. And profoundly hidden in this Map, you can find the filterId as a String. With SearchRequestService you are able to find a filter by id.

Unfortunatley, there were no further detailed infos on the JIRA API when it comes to the getUserPrefs()-Method

http://goo.gl/e6dz4u

Here is the method how you get all Queries from a Dashboard:

public List<Query> getAllQueriesFromDashboard(PortalPage dashboard)
   {
      PortalPageService pps = ComponentAccessor.getComponent(PortalPageService.class);
      SearchRequestService srs = ComponentAccessor.getComponent(SearchRequestService.class);
      Set<String> filterIds = new HashSet<String>();
      List<Query> queries = new ArrayList<Query>();
      
      // get dashboard by id
      List<List<PortletConfiguration>> portletConfigurations = pps.getPortletConfigurations(getJiraServiceContext(), dashboard.getId());        
      
      //get all gadgets
      for(int i = 0; i<portletConfigurations.size(); i++)
      {
         List<PortletConfiguration> lpc = portletConfigurations.get(i);
         for(int j = 0; j<lpc.size(); j++)
         {
            PortletConfiguration pc = lpc.get(j);
            
            Map<String, String> userPrefs = pc.getUserPrefs();

            for(Entry<String, String> x : userPrefs.entrySet())
            {            
               if(x.getKey().equalsIgnoreCase("filterId"))
               {
                  filterIds.add(x.getValue().replace("filter-", ""));     
               }
            }
         }
      }
      
      // get all filters by Id --> get all Queries
      Iterator<String> it = filterIds.iterator();
      while(it.hasNext())
      {
         Long id = Long.parseLong(it.next());
         SearchRequest sr = srs.getFilter(getJiraServiceContext(), id);
         Query q = sr.getQuery();
         queries.add(q);
      }
      
      return queries;
   }

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

223 views 3 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you