Package org.intermine.api.query
Class MainHelper
- java.lang.Object
-
- org.intermine.api.query.MainHelper
-
public final class MainHelper extends java.lang.Object
Helper methods for main controller and main action- Author:
- Mark Woodbridge, Thomas Riley, Matthew Wakeling
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
MainHelper.RangeConfig
protected static class
MainHelper.SummaryConfig
Controls access to configuration information on which fields should be summarised as a count of occurrences.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.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.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.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.static java.util.Set<java.lang.Class<?>>
getValidRangeTargets()
static void
loadHelpers(java.util.Properties props)
protected static Constraint
makeMultiTypeConstraint(Model model, QueryNode field, PathConstraintMultitype pcmt)
Construct a new multi-type constraint.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)
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.protected static Constraint
makeQueryDateConstraint(QueryField qf, PathConstraintAttribute c)
Make a SimpleConstraint for the given Date Constraint.static Constraint
makeRangeConstraint(Queryable q, QueryNode node, PathConstraintRange con)
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)
Generate a query from a PathQuery, to summarise a particular column of results.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)
Generate a query from a PathQuery, to summarise a particular column of results.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)
Generate a query from a PathQuery, to summarise a particular column of results.protected static LogicExpression
removeFromConstraintLogic(LogicExpression logic, java.lang.String code)
Remove a constraint code from a logic expression, e.g.
-
-
-
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 PathQuerysavedBags
- 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 QuerybagQueryRunner
- a BagQueryRunner to use to perform LOOKUPsreturnBagQueryResults
- 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 logicconstraints
- 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 thisnode
- 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 queryc
- 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 objectcs
- the ConstraintSet to put the constraints incodeToConstraint
- 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 objectcs
- the ConstraintSet to put the constraints incodeToConstraint
- 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 logiccode
- 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 logiccode
- 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 PathQuerysavedBags
- the current saved bags mappathToQueryNode
- Map, into which columns to display will be placedsummaryPath
- a String path of the column to summariseos
- an ObjectStore to do LOOKUP queries inclassKeys
- class key configbagQueryConfig
- a BagQueryConfig objectpm
- the ProfileManager to fetch the superuser profile fromoccurancesOnly
- 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 PathQuerysummaryPath
- a String path of the column to summarisesavedBags
- the current saved bags mappathToQueryNode
- Map, into which columns to display will be placedbagQueryRunner
- 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 PathQuerysummaryPath
- a String path of the column to summarisesavedBags
- the current saved bags mappathToQueryNode
- Map, into which columns to display will be placedbagQueryRunner
- a BagQueryRunner to execute bag queriesoccurancesOnly
- 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
-
makeRangeConstraint
public static Constraint makeRangeConstraint(Queryable q, QueryNode node, PathConstraintRange con)
- Parameters:
q
- fieldnode
- classcon
- contraint- Returns:
- range constraint
-
-