public void beforeRenderComponent() { super.beforeRenderComponent(); // Initialize the dashboard (loads all its kpi panels) DashboardHandler.lookup().getCurrentDashboard(); // Get the filter. DashboardFilter filter = getFilter(); // Check all visible properties exist. Iterator props = properties.iterator(); while (props.hasNext()) { DashboardFilterProperty dashboardFilterProperty = (DashboardFilterProperty) props.next(); if (!dashboardFilterProperty.isPropertyAlive()) props.remove(); } // Check if filtered properties for this filter component are already in dashboard filter. DashboardFilterProperty[] beingFilteredProps = getBeingFilteredProperties(); for (int i = 0; i < beingFilteredProps.length; i++) { List dfProperties = Arrays.asList(filter.getPropertyIds()); DashboardFilterProperty beignFilteredProp = beingFilteredProps[i]; if (!dfProperties.contains(beignFilteredProp.getPropertyId())) beignFilteredProp.setBeignFiltered(false); } // Check filtered properties and hide from available filter properties (set property not // visible) String[] propIds = filter.getPropertyIds(); for (int i = 0; i < propIds.length; i++) { String propId = propIds[i]; DashboardFilterProperty prop = getDashboardFilterProperty(propId); if (prop == null) { DashboardFilterProperty parentProperty = filter.getPropertyInParentDashboards(propId); if (parentProperty != null) { prop = new DashboardFilterProperty( parentProperty.getDataProviderCode(), propId, getFilter(), null, true); properties.add(prop); } } else { prop.setBeignFiltered(true); } } }
public CommandResponse actionFilter(CommandRequest request) { try { // Init attributes for start applying the filter. filterPropertyErrors.clear(); // Parse parameters and set the filter. Iterator visiblePropertiesIt = properties.iterator(); while (visiblePropertiesIt.hasNext()) { DashboardFilterProperty dashboardFilterProperty = (DashboardFilterProperty) visiblePropertiesIt.next(); // Is property already in the dashboard filter?. Then is not possible to filter by this // property, it's already added to dashboard filter. if (dashboardFilterProperty.isBeingFiltered()) continue; if (!dashboardFilterProperty.isPropertyAlive()) { log.warn( "Trying to filter by " + dashboardFilterProperty.getPropertyId() + ". This property is not in any dataset."); continue; } if (!dashboardFilterProperty.isVisible()) continue; Object[] result; try { result = requestProcessor.parseDashboardProperty( request.getRequestObject(), dashboardFilterProperty); } catch (Exception e) { log.error("Error parsing property " + dashboardFilterProperty.getPropertyId() + ".", e); continue; } if (result.length != 3) { log.error( "Error parsing property: '" + dashboardFilterProperty.getPropertyId() + "' for dataProvider: '" + dashboardFilterProperty.getDataProviderCode() + "'"); continue; } Collection allowedValues = (Collection) result[0]; Object minValue = result[1]; Object maxValue = result[2]; if (allowedValues == null && minValue == null && maxValue == null) continue; // Set the filter with this property. Dashboard currentDashboard = DashboardHandler.lookup().getCurrentDashboard(); if (currentDashboard.filter( dashboardFilterProperty.getPropertyId(), minValue, true, maxValue, true, allowedValues, FilterByCriteria.ALLOW_ANY)) { return new ShowCurrentScreenResponse(); } } } catch (Exception e) { log.error("Error trying to filter properties for dashboard", e); } return null; }