Class Filter


  • public abstract class Filter
    extends Object
    A filter is a query that, given a set of input parameters, returns a list of inventory assets. Queries are usually complex and can not be done using the Query Manager alone. These queries can be embedded in multiple modules, so they can be used to filter what information is displayed. A typical use case is the navigation module: Filters applicable per class are created and, when a user selects an object, it is possible to expand de navigation tree showing its direct children or apply a filter to display only a predefined set (for example, in a network device show only the ports and skip cards and slots). A FilterDefinition instance contains the metadata of a Filter (name, if it's enabled, the corresponding script), while a filter instance can execute code. Filters are Groovy scripts containing subclasses of Filter. These classes are compiled on-the-fly and the instances cached to be executed on demand.
    Author:
    Charles Edward Bedon Cortazar <charles.bedon@kuwaiba.org>
    • Constructor Detail

      • Filter

        public Filter​(MetadataEntityManager mem,
                      ApplicationEntityManager aem,
                      BusinessEntityManager bem,
                      ConnectionManager cm)
        Default mandatory constructor.
        Parameters:
        mem - Reference to the Metadata Entity Manager.
        aem - Reference to the Application Entity Manager.
        bem - Reference to the Business Entity Manager.
        cm - Reference to the Connection Manager. Useful to access directly the database, bypassing the Persistence API.
    • Method Detail

      • run

        public abstract List<BusinessObjectLight> run​(String objectId,
                                                      String objectClass,
                                                      HashMap<String,​String> parameters,
                                                      int page,
                                                      int limit)
                                               throws InvalidArgumentException
        This method should be implemented by all filter definition scripts (which must define a subclass of Filter), and contains the logic to evaluate the condition.
        Parameters:
        objectId - The id of the object from which the filter is ran.
        objectClass - The class of the object from which the filter is ran.
        parameters - Extra parameters useful for the filter to complete its task. For example, a consumer would like to retrieve all the ports in a network device recursively, but only those containing a given string. That could be provided as a parameter. The parameters are handed as String and it's expected that the filter script perform the respective validations. This might be null or an empty hash, depending on the filter.
        page - -1 to avoid pagination, the page of the results.
        limit - -1 to no limit, the limit of results per page.
        Returns:
        The list of objects product of running the filter.
        Throws:
        InvalidArgumentException - If the script had a problem (managed or not) in its execution.