Class MainHelper


  • public final class MainHelper
    extends java.lang.Object
    Helper methods for main controller and main action
    Author:
    Mark Woodbridge, Thomas Riley, Matthew Wakeling
    • Method Detail

      • makeQuery

        public static Query makeQuery​(PathQuery pathQuery,
                                      java.util.Map<java.lang.String,​InterMineBag> savedBags,
                                      java.util.Map<java.lang.String,​QuerySelectable> pathToQueryNode,
                                      BagQueryRunner bagQueryRunner,
                                      java.util.Map<java.lang.String,​BagQueryResult> returnBagQueryResults)
                               throws ObjectStoreException
        Converts a PathQuery object into an ObjectStore Query object, and optionally populates a Map from String path in the PathQuery to the object in the Query that represents it.
        Parameters:
        pathQuery - the PathQuery
        savedBags - the current saved bags map (a Map from bag name to InterMineBag)
        pathToQueryNode - optional parameter which will be populated with entries, mapping from String path in the pathQuery to objects in the result Query
        bagQueryRunner - a BagQueryRunner to use to perform LOOKUPs
        returnBagQueryResults - optional parameter in which any BagQueryResult objects can be returned
        Returns:
        an ObjectStore Query object
        Throws:
        ObjectStoreException - if something goes wrong
      • makeMultiTypeConstraint

        protected static Constraint makeMultiTypeConstraint​(Model model,
                                                            QueryNode field,
                                                            PathConstraintMultitype pcmt)
                                                     throws ObjectStoreException
        Construct a new multi-type constraint.
        Parameters:
        model - The model to look for types within.
        field - The subject of the constraint.
        pcmt - The constraint itself.
        Returns:
        A constraint.
        Throws:
        ObjectStoreException - if the constraint names types that are not in the model.
      • findParticipatingLoops

        protected static java.util.Set<PathConstraintLoop> findParticipatingLoops​(LogicExpression logic,
                                                                                  java.util.Map<PathConstraint,​java.lang.String> constraints)
        Returns the Set of PathConstraintLoop objects that will participate in the QueryClass collapsing mechanism.
        Parameters:
        logic - the constraint logic
        constraints - a Map from PathConstraint to code
        Returns:
        a Set of PathConstraintLoop objects
      • findAndCodes

        protected static void findAndCodes​(java.util.Set<java.lang.String> codes,
                                           LogicExpression.Node node)
        Finds all the codes in a constraint logic that are ANDed in the given constraint logic.
        Parameters:
        codes - codes are added to this
        node - a node to traverse
      • makeQueryDateConstraint

        protected static Constraint makeQueryDateConstraint​(QueryField qf,
                                                            PathConstraintAttribute c)
        Make a SimpleConstraint for the given Date Constraint. The time stored in the Date will be ignored. Example webapp constraints and the corresponding object store constraints:
        Webapp Version ObjectStore Version
        <= 2008-01-02 >= 2008-01-02 23:59:59
        > 2008-01-02 < 2008-01-02 00:00:00
        > 2008-01-02 > 2008-01-02 23:59:59
        >= 2008-01-02 > 2008-01-02 00:00:00
        Parameters:
        qf - the QueryNode in the new query
        c - the webapp constraint
        Returns:
        a new object store constraint
      • createConstraintStructure

        protected static void createConstraintStructure​(LogicExpression logic,
                                                        ConstraintSet cs,
                                                        java.util.Map<java.lang.String,​Constraint> codeToConstraint)
        Given a LogicExpression, a Map from codes to Constraint objects, and a ConstraintSet to put it all in, construct a tree of ConstraintSets that reflects the expression.
        Parameters:
        logic - the LogicExpression object
        cs - the ConstraintSet to put the constraints in
        codeToConstraint - a Map from constraint code to Constraint object
      • createConstraintStructure

        protected static void createConstraintStructure​(LogicExpression.Node node,
                                                        ConstraintSet cs,
                                                        java.util.Map<java.lang.String,​Constraint> codeToConstraint)
        Given a LogicExpression.Node, a Map from codes to Constraint objects, and a ConstraintSet to put it all in, construct a tree of ConstraintSets that reflects the expression.
        Parameters:
        node - the LogicExpression.Node object
        cs - the ConstraintSet to put the constraints in
        codeToConstraint - a Map from constraint code to Constraint object
      • addToConstraintLogic

        protected static LogicExpression addToConstraintLogic​(LogicExpression logic,
                                                              java.lang.String code)
        Add a constraint code to a logic expression, ANDed with any constraints already in the expression, e.g. 'A OR B' + code C -> '(A OR B) AND C'. If the expression is null a new expression is created.
        Parameters:
        logic - an existing constraint logic
        code - the code to add
        Returns:
        a new logic expression including the new code
      • removeFromConstraintLogic

        protected static LogicExpression removeFromConstraintLogic​(LogicExpression logic,
                                                                   java.lang.String code)
        Remove a constraint code from a logic expression, e.g. '(A OR B) AND C' -> 'B AND C'. If there is only one code in the expression return null.
        Parameters:
        logic - an existing constraint logic
        code - the code to remove
        Returns:
        a new logic expression or null if the expression is now empty
      • makeSummaryQuery

        public static Query makeSummaryQuery​(PathQuery pathQuery,
                                             java.util.Map<java.lang.String,​InterMineBag> savedBags,
                                             java.util.Map<java.lang.String,​QuerySelectable> pathToQueryNode,
                                             java.lang.String summaryPath,
                                             ObjectStore os,
                                             java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys,
                                             BagQueryConfig bagQueryConfig,
                                             ProfileManager pm,
                                             boolean occurancesOnly)
                                      throws ObjectStoreException
        Generate a query from a PathQuery, to summarise a particular column of results.
        Parameters:
        pathQuery - the PathQuery
        savedBags - the current saved bags map
        pathToQueryNode - Map, into which columns to display will be placed
        summaryPath - a String path of the column to summarise
        os - an ObjectStore to do LOOKUP queries in
        classKeys - class key config
        bagQueryConfig - a BagQueryConfig object
        pm - the ProfileManager to fetch the superuser profile from
        occurancesOnly - Force summary to take form of item summary if true.
        Returns:
        the generated summary query
        Throws:
        ObjectStoreException - if there is a problem creating the query
      • makeSummaryQuery

        public static Query makeSummaryQuery​(PathQuery pathQuery,
                                             java.lang.String summaryPath,
                                             java.util.Map<java.lang.String,​InterMineBag> savedBags,
                                             java.util.Map<java.lang.String,​QuerySelectable> pathToQueryNode,
                                             BagQueryRunner bagQueryRunner)
                                      throws ObjectStoreException
        Generate a query from a PathQuery, to summarise a particular column of results.
        Parameters:
        pathQuery - the PathQuery
        summaryPath - a String path of the column to summarise
        savedBags - the current saved bags map
        pathToQueryNode - Map, into which columns to display will be placed
        bagQueryRunner - a BagQueryRunner to execute bag queries
        Returns:
        the generated summary query
        Throws:
        ObjectStoreException - if there is a problem creating the query
      • makeSummaryQuery

        public static Query makeSummaryQuery​(PathQuery pathQuery,
                                             java.lang.String summaryPath,
                                             java.util.Map<java.lang.String,​InterMineBag> savedBags,
                                             java.util.Map<java.lang.String,​QuerySelectable> pathToQueryNode,
                                             BagQueryRunner bagQueryRunner,
                                             boolean occurancesOnly)
                                      throws ObjectStoreException
        Generate a query from a PathQuery, to summarise a particular column of results.
        Parameters:
        pathQuery - the PathQuery
        summaryPath - a String path of the column to summarise
        savedBags - the current saved bags map
        pathToQueryNode - Map, into which columns to display will be placed
        bagQueryRunner - a BagQueryRunner to execute bag queries
        occurancesOnly - Force summary to take form of item summary if true.
        Returns:
        the generated summary query
        Throws:
        ObjectStoreException - if there is a problem creating the query
      • loadHelpers

        public static void loadHelpers​(java.util.Properties props)
        Parameters:
        props - properties to configure the range queries
      • getValidRangeTargets

        public static java.util.Set<java.lang.Class<?>> getValidRangeTargets()
        Returns:
        set of classes that are legal to use with range constraints