Package org.intermine.template
Class TemplateQuery
- java.lang.Object
-
- org.intermine.pathquery.PathQuery
-
- org.intermine.template.TemplateQuery
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
ApiTemplate
public class TemplateQuery extends PathQuery
A template query, which consists of a PathQuery, description, category, short name.- Author:
- Mark Woodbridge, Thomas Riley, Alex Kalderimis
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
comment
The private comment for this query.protected java.util.Map<PathConstraint,java.lang.String>
constraintDescriptions
Descriptions of constraintsprotected java.util.Map<PathConstraint,SwitchOffAbility>
constraintSwitchOffAbility
Configuration for switch-off-ability of constraintsprotected java.util.List<PathConstraint>
editableConstraints
List of those Constraints that are editableprotected boolean
edited
Whether this is an edited version of another template.protected java.lang.String
name
Template query name.-
Fields inherited from class org.intermine.pathquery.PathQuery
MAX_CODE, MAX_CONSTRAINTS, MIN_CODE, SPACE_SPLITTER, USERPROFILE_VERSION
-
-
Constructor Summary
Constructors Constructor Description TemplateQuery(java.lang.String name, java.lang.String title, java.lang.String comment, PathQuery query)
Construct a new instance of TemplateQuery.TemplateQuery(TemplateQuery prototype)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearConstraints()
Clears the entire set of constraints from this query, and resets the constraint logic.TemplateQuery
clone()
Clone this TemplateQuery.TemplateQuery
cloneWithoutEditableConstraints()
Return a clone of this template query with all editable constraints removed - i.e.boolean
equals(java.lang.Object other)
java.lang.String
getComment()
Get the private comment for this template.protected java.lang.String
getCommonJsonConstraintPrefix(java.lang.String code, PathConstraint con)
Get the JSON prefix common to all constraints.java.lang.String
getConstraintDescription(PathConstraint constraint)
Returns the description attached to the given constraint.java.util.Map<PathConstraint,java.lang.String>
getConstraintDescriptions()
Returns the constraint descriptions for this query.java.lang.String
getConstraintLogicForEditableConstraints()
Return the constraint logic modified to contain only the blocks with editable constraintsjava.util.Map<PathConstraint,SwitchOffAbility>
getConstraintSwitchOffAbility()
Returns the constraint SwitchOffAbility for this query.java.util.List<PathConstraint>
getEditableConstraints()
Returns the list of all editable constraints.java.util.List<PathConstraint>
getEditableConstraints(java.lang.String path)
For a path with editable constraints, get all the editable constraints as a List, or the empty list if there are no editable constraints on that path.java.util.List<java.lang.String>
getEditablePaths()
Get the paths of all editable constraints in this template.protected java.util.Map<java.lang.String,java.lang.Object>
getHeadAttributes()
java.util.List<PathConstraint>
getModifiableEditableConstraints()
Returns the list of all editable constraints.java.lang.String
getName()
Get the query short name.PathQuery
getQueryToExecute()
Fetch the PathQuery to execute for this template.java.util.Map<PathConstraint,java.lang.String>
getRelevantConstraints()
SwitchOffAbility
getSwitchOffAbility(PathConstraint constraint)
Gets the sbitch-off-ability of a constraint.java.lang.String
getTitle()
Gets the title for this query.int
hashCode()
boolean
isEditable(PathConstraint constraint)
Returns whether a constraint is editable.boolean
isEdited()
Returns true if the TemplateQuery has been edited by the user and is therefore saved only in the query history.boolean
isOptional(PathConstraint constraint)
Returns whether a constraint is optional.boolean
isRequired(PathConstraint constraint)
Returns whether a constraint is required.void
removeConstraint(PathConstraint constraint)
Removes a constraint from this query.void
replaceConstraint(PathConstraint old, PathConstraint replacement)
Replaces a constraint in the query with a different, carrying over the constraint code, and preserving the constraint logic.void
setComment(java.lang.String comment)
Set the private comment for this template.void
setConstraintDescription(PathConstraint constraint, java.lang.String description)
Sets the description for a constraint.void
setEditable(PathConstraint constraint, boolean editable)
Sets a constraint to be editable or not.void
setEditableConstraints(java.util.List<PathConstraint> editable)
Sets the list of editable constraints to exactly that provided, in the given order.void
setEdited(boolean edited)
Set the query as being edited.void
setName(java.lang.String name)
Sets the query short name.void
setSwitchOffAbility(PathConstraint constraint, SwitchOffAbility sbitchOffAbility)
Sets the sbitch-off-ability of a constraint.java.lang.String
toJSON()
Returns a JSON string representation of the template query.java.lang.String
toString()
Converts this object into a rudimentary String format, containing all the data.java.lang.String
toXml(int version)
Convert a template query to XML.boolean
validateLookupConstraints()
Verify templates don't contain non-editable lookup constraints-
Methods inherited from class org.intermine.pathquery.PathQuery
addConstraint, addConstraint, addConstraints, addConstraints, addJsonProperty, addOrderBy, addOrderBy, addOrderBys, addOrderBys, addOrderBySpaceSeparated, addView, addViews, addViews, addViewSpaceSeparated, checkPathFormat, clearDescriptions, clearOrderBy, clearOuterJoinStatus, clearView, constraintToJson, deVerify, fixUpForJoinStyle, formatKVPair, getBagNames, getCandidateLoops, getColumnHeaders, getConstraintCodes, getConstraintForCode, getConstraintGroups, getConstraintLogic, getConstraintLogicForGroup, getConstraints, getConstraintsForPath, getDescription, getDescription, getDescriptions, getExistingLoops, getGeneratedPathDescription, getGroupedConstraintLogic, getJson, getLogicExpression, getModel, getOrderBy, getOuterJoinGroup, getOuterJoinGroups, getOuterJoinStatus, getOuterJoinStatus, getOuterMap, getRootClass, getSubclasses, getView, isEmpty, isPathCompletelyInner, isValid, makePath, removeAllIrrelevant, removeAllUnder, removeOrderBy, removeSubclassAndFixUp, removeView, setConstraintLogic, setDescription, setDescription, setOuterJoinStatus, setTitle, sortConstraints, toJson, toJson, toJson, toJson, toXml, typeConstraintToJson, valueConstraintToJson, verifyQuery
-
-
-
-
Field Detail
-
name
protected java.lang.String name
Template query name.
-
comment
protected java.lang.String comment
The private comment for this query.
-
edited
protected boolean edited
Whether this is an edited version of another template.
-
editableConstraints
protected java.util.List<PathConstraint> editableConstraints
List of those Constraints that are editable
-
constraintDescriptions
protected java.util.Map<PathConstraint,java.lang.String> constraintDescriptions
Descriptions of constraints
-
constraintSwitchOffAbility
protected java.util.Map<PathConstraint,SwitchOffAbility> constraintSwitchOffAbility
Configuration for switch-off-ability of constraints
-
-
Constructor Detail
-
TemplateQuery
public TemplateQuery(java.lang.String name, java.lang.String title, java.lang.String comment, PathQuery query)
Construct a new instance of TemplateQuery.- Parameters:
name
- the name of the templatetitle
- the short title of this template for showing in listcomment
- an optional private comment for this templatequery
- the query itself
-
TemplateQuery
public TemplateQuery(TemplateQuery prototype)
Copy constructor. Construct a new template that is the same in all respects as the one passed to the constructor.- Parameters:
prototype
- The template to copy.
-
-
Method Detail
-
clone
public TemplateQuery clone()
Clone this TemplateQuery.
-
getQueryToExecute
public PathQuery getQueryToExecute()
Fetch the PathQuery to execute for this template. The returned query excludes any optional constraints that have been sbitched off before the template is executed.- Overrides:
getQueryToExecute
in classPathQuery
- Returns:
- the PathQuery that should be executed for this query
-
setEditable
public void setEditable(PathConstraint constraint, boolean editable)
Sets a constraint to be editable or not. If setting a constraint to be editable, and it is not already editable, then the constraint will be added to the end of the editable constraints list.- Parameters:
constraint
- the PathConstraint to markeditable
- whether the constraint should be editable- Throws:
java.lang.NullPointerException
- if constraint is nulljava.util.NoSuchElementException
- if the constraint is not in the query
-
isEditable
public boolean isEditable(PathConstraint constraint)
Returns whether a constraint is editable.- Parameters:
constraint
- the PathConstraint to check- Returns:
- true if the constraint is editable
- Throws:
java.lang.NullPointerException
- if constraint is nulljava.util.NoSuchElementException
- if constraint is not in the query at all
-
isOptional
public boolean isOptional(PathConstraint constraint)
Returns whether a constraint is optional. This is the logical inverse of isRequired()- Parameters:
constraint
- the PathConstraint to check- Returns:
- true if the constraint is optional
- Throws:
java.lang.NullPointerException
- if the constraint is nulljava.util.NoSuchElementException
- if constraint is not in the query at all
-
isRequired
public boolean isRequired(PathConstraint constraint)
Returns whether a constraint is required. This is the logical inverse of isOptional()- Parameters:
constraint
- the PathConstraint to check- Returns:
- true if the constraint is required
- Throws:
java.lang.NullPointerException
- if the constraint is nulljava.util.NoSuchElementException
- if constraint is not in the query at all
-
setEditableConstraints
public void setEditableConstraints(java.util.List<PathConstraint> editable)
Sets the list of editable constraints to exactly that provided, in the given order. Previously-editable constraints are discarded.- Parameters:
editable
- a List of editable constraints to replace the existing list- Throws:
java.util.NoSuchElementException
- if the argument contains a constraint that is not in the query
-
getEditableConstraints
public java.util.List<PathConstraint> getEditableConstraints(java.lang.String path)
For a path with editable constraints, get all the editable constraints as a List, or the empty list if there are no editable constraints on that path.- Parameters:
path
- a String of a path- Returns:
- List of editable constraints for the path
-
getConstraintSwitchOffAbility
public java.util.Map<PathConstraint,SwitchOffAbility> getConstraintSwitchOffAbility()
Returns the constraint SwitchOffAbility for this query. The return value of this method is an unmodifiable copy of the data in this query, so it will not change to reflect changes in this query.- Returns:
- a Map of constraintSwitchOffAbility
-
setConstraintDescription
public void setConstraintDescription(PathConstraint constraint, java.lang.String description)
Sets the description for a constraint. To remove a description, call this method with a null description.- Parameters:
constraint
- the constraint to attach the description todescription
- a String- Throws:
java.lang.NullPointerException
- if the constraint is nulljava.util.NoSuchElementException
- if the constraint is not in the query
-
getConstraintDescription
public java.lang.String getConstraintDescription(PathConstraint constraint)
Returns the description attached to the given constraint. Returns null if no description is present.- Parameters:
constraint
- the constraint to fetch the description of- Returns:
- a String description
- Throws:
java.lang.NullPointerException
- is the constraint is nulljava.util.NoSuchElementException
- if the constraint is not in the query
-
getConstraintDescriptions
public java.util.Map<PathConstraint,java.lang.String> getConstraintDescriptions()
Returns the constraint descriptions for this query. The return value of this method is an unmodifiable copy of the data in this query, so it will not change to reflect changes in this query.- Returns:
- a Map from PathConstraint to String description
-
setSwitchOffAbility
public void setSwitchOffAbility(PathConstraint constraint, SwitchOffAbility sbitchOffAbility)
Sets the sbitch-off-ability of a constraint.- Parameters:
constraint
- the constraint to set the switch-off-ability onsbitchOffAbility
- a SwitchOffAbility instance- Throws:
java.lang.NullPointerException
- if the constraint or sbitchOffAbility is nulljava.util.NoSuchElementException
- if the constraint is not in the query
-
getSwitchOffAbility
public SwitchOffAbility getSwitchOffAbility(PathConstraint constraint)
Gets the sbitch-off-ability of a constraint.- Parameters:
constraint
- the constraint to get the sbitch-off-ability for- Returns:
- a SwitchOffAbility instance
- Throws:
java.lang.NullPointerException
- is the constraint is nulljava.util.NoSuchElementException
- if the constraint is not in the query
-
getEditableConstraints
public java.util.List<PathConstraint> getEditableConstraints()
Returns the list of all editable constraints. The return value of this method is an unmodifiable copy of the data in this query, so it will not change to reflect changes in this query.- Returns:
- a List of PathConstraint
-
getModifiableEditableConstraints
public java.util.List<PathConstraint> getModifiableEditableConstraints()
Returns the list of all editable constraints. The return value of this method is a copy of the data in this query, so it will not change to reflect changes in this query. Please only use this method if you are going to resubmit the list to the setEditableConstraints() method, as any changes made in this list will not be otherwise copied to this TemplateQuery object. For other uses, use the getEditableConstraints() method, which will prevent modification, which could catch a bug or two.- Returns:
- a List of PathConstraint
-
replaceConstraint
public void replaceConstraint(PathConstraint old, PathConstraint replacement)
Replaces a constraint in the query with a different, carrying over the constraint code, and preserving the constraint logic. The new PathConstraint will be attached to the path in the constraint, which will have already been checked for format (no colons or square brackets), but will not be verified until the verifyQuery() method is called. This method preserves the order of constraints - that is, the replacement will be swapped in where the old constraint was.- Overrides:
replaceConstraint
in classPathQuery
- Parameters:
old
- the old PathConstraint objectreplacement
- the new PathConstraint object to replace it
-
removeConstraint
public void removeConstraint(PathConstraint constraint)
Removes a constraint from this query. The PathConstraint should be a constraint that already exists in this query. The constraint will also be removed from the constraint logic.- Overrides:
removeConstraint
in classPathQuery
- Parameters:
constraint
- the PathConstraint to remove from this query
-
clearConstraints
public void clearConstraints()
Clears the entire set of constraints from this query, and resets the constraint logic.- Overrides:
clearConstraints
in classPathQuery
-
cloneWithoutEditableConstraints
public TemplateQuery cloneWithoutEditableConstraints()
Return a clone of this template query with all editable constraints removed - i.e. a query that will return all possible results of executing the template. The original template is left unaltered.- Returns:
- a clone of the original template without editable constraints.
-
getComment
public java.lang.String getComment()
Get the private comment for this template.- Returns:
- the comment
-
getTitle
public java.lang.String getTitle()
Description copied from class:PathQuery
Gets the title for this query.
-
getEditablePaths
public java.util.List<java.lang.String> getEditablePaths()
Get the paths of all editable constraints in this template.- Returns:
- the nodes
-
getName
public java.lang.String getName()
Get the query short name.- Returns:
- the query identifier string
-
setName
public void setName(java.lang.String name)
Sets the query short name.- Parameters:
name
- the template name
-
setComment
public void setComment(java.lang.String comment)
Set the private comment for this template.- Parameters:
comment
- the comment
-
toXml
public java.lang.String toXml(int version)
Convert a template query to XML.
-
toString
public java.lang.String toString()
Description copied from class:PathQuery
Converts this object into a rudimentary String format, containing all the data.
-
getRelevantConstraints
public java.util.Map<PathConstraint,java.lang.String> getRelevantConstraints()
- Overrides:
getRelevantConstraints
in classPathQuery
- Returns:
- the constraints that are relevant to the query.
-
getHeadAttributes
protected java.util.Map<java.lang.String,java.lang.Object> getHeadAttributes()
- Overrides:
getHeadAttributes
in classPathQuery
- Returns:
- the attributes that should go in the head of a JSON object.
-
getCommonJsonConstraintPrefix
protected java.lang.String getCommonJsonConstraintPrefix(java.lang.String code, PathConstraint con)
Description copied from class:PathQuery
Get the JSON prefix common to all constraints.- Overrides:
getCommonJsonConstraintPrefix
in classPathQuery
- Parameters:
code
- The constraint code.con
- the constraint to format.- Returns:
- The prefix
-
toJSON
public java.lang.String toJSON()
Returns a JSON string representation of the template query. TODO: !! fix confusion between toJson and toJSON !!- Returns:
- A string representation of the template query.
-
isEdited
public boolean isEdited()
Returns true if the TemplateQuery has been edited by the user and is therefore saved only in the query history.- Returns:
- a boolean
-
setEdited
public void setEdited(boolean edited)
Set the query as being edited.- Parameters:
edited
- whether the TemplateQuery has been modified by the user
-
validateLookupConstraints
public boolean validateLookupConstraints()
Verify templates don't contain non-editable lookup constraints- Returns:
- true id the template is valid
-
getConstraintLogicForEditableConstraints
public java.lang.String getConstraintLogicForEditableConstraints()
Return the constraint logic modified to contain only the blocks with editable constraints- Returns:
- the string representing the logic expression modified
-
-