Class TemplatePopulator


  • public final class TemplatePopulator
    extends java.lang.Object
    Configures original template. Old constraints are replaced with the similar new constraints, that have different values.
    Author:
    Richard Smith
    • Method Detail

      • getPopulatedTemplate

        public static TemplateQuery getPopulatedTemplate​(TemplateQuery origTemplate,
                                                         java.util.Map<java.lang.String,​java.util.List<TemplateValue>> newConstraints)
        Given a template and a map of values for editable constraints on each editable node create a copy of the template query with the values filled in. This may alter the query when e.g. bag constraints are applied to a class rather than an attribute.
        Parameters:
        origTemplate - the template to populate with values
        newConstraints - a map from editable node to a list of values for each editable constraint
        Returns:
        a copy of the template with values filled in
        Throws:
        TemplatePopulatorException - if something goes wrong
      • populateTemplateWithObject

        public static TemplateQuery populateTemplateWithObject​(TemplateQuery template,
                                                               InterMineObject obj)
                                                        throws PathException
        Constrain a template query with a single editable constraint to be the given object. This returns a copy of the template with the value filled in, if the existing constraint will be replaced by a constraint on the id field of the editable node.
        Parameters:
        template - the template to constrain
        obj - the object to constrain to
        Returns:
        a copy of the template with values filled in
        Throws:
        PathException - if the template is invalid
      • populateTemplateWithBag

        public static TemplateQuery populateTemplateWithBag​(TemplateQuery template,
                                                            InterMineBag bag)
                                                     throws PathException
        Constrain a template query with a single editable constraint to be in the given bag. This returns a copy of the template with the value filled in, if the constraint is on an attribute it will be replaced by a constrain on the parent class.
        Parameters:
        template - the template to constrain
        bag - the bag to constrain to
        Returns:
        a copy of the template with values filled in
        Throws:
        PathException - if the template is invalid
      • populateTemplateOneConstraint

        public static TemplateQuery populateTemplateOneConstraint​(TemplateQuery template,
                                                                  ConstraintOp op,
                                                                  java.lang.String value)
                                                           throws PathException
        Populate a TemplateQuery that has a single editable constraint with the given value. This returns a copy of the template with the value filled in.
        Parameters:
        template - the template query to populate
        op - operation of the constraint
        value - value to be constrained to
        Returns:
        a copy of the template with the value filled in
        Throws:
        PathException - if the template is invalid
      • setConstraint

        protected static void setConstraint​(TemplateQuery template,
                                            TemplateValue templateValue)
                                     throws PathException
        Set the value for a constraint in the template query with the given TemplateValue. This may move a constraint from an attribute to the parent class if the constraint is object or bag.
        Parameters:
        template - the template to constrain
        templateValue - container for the value to set constraint to
        Throws:
        PathException - if a TemplateValue contains an invalid path