You can use different methods to add filtering, paging, sorting, and projections to your plug-in.

Plug-ins which want to support inventory hierarchy usually do so by either implementing the IPluginFactory interface or extending one of the factory classes such as AbstractSpringPluginFactory or AbstractModelDrivenFactory, and then providing implementation of the corresponding inventory finder methods such as find(), findAll(), or findRelation().

The Automation Orchestrator platform also provides an IQuerySupport interface, intended to be implemented by those plug-ins which want to support more advanced queries over inventory objects, including filtering and sorting of the results.

package ch.dunes.vso.sdk.api.query;

import java.util.List;

import ch.dunes.vso.sdk.api.HasChildrenResult;
import ch.dunes.vso.sdk.api.QueryResult;

/**
 * Types which implements IPluginFactory can use this interface to indicate
 * support for features like filtering, paging and sorting.
 *
 * Plug-in authors should take care of returning results conforming to the
 * constraints specified in query spec parameter.
 */
public interface IQuerySupport {

    /**
     * Finds an object by its id and type
     */
    Object find(String type, String id, QuerySpec qs);

    /**
     * Finds all objects of the requested type conforming to the given query spec
     */
    QueryResult findAll(String type, String query, QuerySpec qs);

    /**
     * Checks if there are child elements conforming to the given query spec
     */
    HasChildrenResult hasChildrenInRelation(String parentType, String parentId, String relationName, QuerySpec qs);

    /**
     * Finds are child elements from the given relation conforming to the given query spec
     */
    List<?> findRelation(String parentType, String parentId, String relationName, QuerySpec qs);
}

The methods in this interface are very similar to those in the standard plug-in factory with the same names, with an additional parameter of the type QuerySpec which carries all the information from the filtering, sorting, or paging request.

public final class QuerySpec {

    private Filter filter;
    private Paging paging;
    private Collection<Sort> sorts;
    private Collection<Projection> projections;

    /**
     * Base class for all query filters. Defines standard composite logical
     * operators and standard filter predicates. You can use your own
     * operators and predicates assuming the names do not conflict.
     */
    public abstract static class Filter {
    }

    /**
     * Filter on a single property
     */
    public static final class PropertyFilter extends Filter {
        private final String property;
        private final String operator;
        private final Object value;
    }

    /**
     * Filter on target object
     */
    public static final class ObjectIdentityFilter extends Filter {
        private final Object targetObject;
        private final String operator;
        private final Object value;
    }

    /**
     * A filter that combines several sub filters using a logical operator
     */
    public static final class CompositeFilter extends Filter {
        private final String operator;
        private final Collection<Filter> subFilters;
    }

    /**
     * Order of the sort - ascending or descending
     */
    public static enum SortDirection {
        ASC,
        DESC;
    }

    /**
     * Information about sort on single property
     */
    public static final class Sort {
        private final String property;
        private final SortDirection direction;
    }

    /**
     * Information about projection on single property
     */
    public static final class Projection {
        private final String property;
    }

    /**
     * Paging and slicing support
     * Page is specified by (page,size) pair. Page number starts from 1
     * Slice is specified by (offset,size) pair. Offset starts from 0
     */
    public static class Paging {
        private final int offset;
        private final int size;
    }
}

Filtering

Filtering can be done on either the whole inventory object or some of its properties, comparing it to some value. Many standard filter predicates are provided as static methods of the Filter class such as equal(), match(), lessThan(), and others. Also, several filters can be combined using composite logical operators such as and(), or(), and not(). Use of composite logical operators enables the construction of complex composite predicates.

Paging

Paging is specified by a simple offset/size pair.

Sorting

Sorting is specified by the name of the inventory object property to sort on in addition to the sorting direction, which can be ascending or descending.
Note: The query can contain multiple sort specs, enabling you to perform sorting on multiple object properties.

Projections

Projections allow for advanced tuning of the content and size of the inventory objects being returned. In some scenarios, the inventory objects are either very large in size (for example, vCenter virtual machines) and fully fetching them, or all their properties, can be a very expensive operation. If the caller is interested in only a small subset of inventory objects' properties, like the names of virtual machines, they can specify only the names of the desired property as a projection.
Note: The query can contain multiple projection specs so you can perform projections on multiple object properties.