Get Filter from Gadget & get gadgets from dashboard

JIRA Plugin Developer June 30, 2014

Hello,

is there a possibility how to get the filter of a gadget? I want to retrieve all issues in a filter. And this filter I want to access by a gadget. I know it is possible to get all issues in a filter. But my point is to get the filter via an Gadget-Object.

How can I do this programmatical?

Another question:

Can I iterate over all gadgets in a dashboard? I want to get all gadgets that are contained in a dashboard. If I got these gadgets, I could get the filter.

By the way are there any event-listener for dashboards? So when dashboard is updated an event will be triggered. I found for example listener for projects or issues but nothing for dashboards or gadgets.

Thanks in advance for any help.

4 answers

1 accepted

0 votes
Answer accepted
JIRA Plugin Developer July 7, 2014

Solution can be found on

http://goo.gl/b75kEt

0 votes
JIRA Plugin Developer July 2, 2014

Does anybody have an idea or a hint, how to get the Filter/Query of a Gadget receiving from the GadgetURI as mentioned above? Is it possible via the JIRA API 6.2.7 or do I have to consult the REST API?

Is it possible to access a gadget from java code that you have created before in a dashboard? And get its query somehow? How is a Gadget defined in the JIRA API?

Please help me.

0 votes
JIRA Plugin Developer July 1, 2014

OK, I found a solution.

You can't access all gadgets directly from the PortalPage instance. Instead you need to use the PortalPageService right from the beginning to access all PortletConfigurations like in the Code-Listing below:

List<List<PortletConfiguration>> portletConfigs = pps.getPortletConfigurations(new JiraServiceContextImpl(user), (long)10202); // pps is instance PortalPageService

And now with the List of the List of PortletConfigurations you can iterate through all GadgetURIs and you can access all Queries like:

for(int i = 0; i<portletConfigs.size(); i++)
{
 	List<PortletConfiguration> llconfigs = portletConfigs.get(i);
  	for(int j = 0; j<llconfigs.size(); j++)
    {
             PortletConfiguration pc = llconfigs.get(j);
             log.info("QUERY:" + pc.getGadgetURI().getQuery());
    }
}

It (PortalPage) no longer has a link to the PortletConfigurations (Gadgets) displayed on a dashboard. To get this information one should consult the PortalPageService directly.

Atlassian JIRA API

Unfortunately, whenever I call the method getQuery, it will return null, although a filter were defined in the corresponding gadget. What is wrong? How can I get the filter/query from every gadget?

0 votes
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2014

If I'm not mistaken, you can get the gadget's infomration if you get the gadget object.

Can I iterate over all gadgets in a dashboard?

Yes.

By the way are there any event-listener for dashboards

No.

This class DefaultPortalPageService should get you unstuck.

JIRA Plugin Developer July 1, 2014

Thanks for your answer.

The PortalPageService is the top level service for Dashboard operations. For historical reasons, Dashboards were called Portals and hence the prefix "Portal" is used consistently throughout the code.

See follwing link: http://goo.gl/qmV3Ll

When I have a PortalPage/Dashboard, how can I access all the gadgets in this dashboard?

I have following Java Code:

User user = (User)ComponentAccessor.getCrowdService().getUser("admin"); 
       PortalPage portalpage = ComponentAccessor.getComponent(PortalPageService.class).getPortalPage(new JiraServiceContextImpl(user), (long)10201);

//how to get all gadgets with portalPage

Is there a way to get all gadgets with portalpage or another way how to iterate over all gadgets? If possible a little code sample would help me further.

Suggest an answer

Log in or Sign up to answer