Class ExpressionHelper
Helper to access attribute information that's helpful when answering questions that require an
Expression
answer. Such as the scope (input struct) that the expression has available to it.
This helper has distinct modes of operation which are:
1) context is the Struct produced by the last pipeline step
2) context is the type produced by the step named by {@link #TAG<em>STEP</em>NAME}
3) context is based on a bookmark, which was the answer to a previous question whose name is in {@link #TAG<em>LAYER</em>QUESTION_NAME}
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents an attribute (member) of the context struct that could be referenced in an expression.static class
Represents the value that an attribute may contain. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Annotation key whose value determines the type of expression required.static final String
Value for {@link #TAG<em>EXPRESSION</em>TYPE} to require an expression that should return a boolean when evaluated.static final String
Value for {@link #TAG<em>EXPRESSION</em>TYPE} to require an expression that should return a numeric value when evaluated.static final String
Annotation whose value is the member name that layer will be stored in.static final String
Annotation whose value ought to be aQuestion
name that will contain aRelation
containingResolvedBookmark
. -
Constructor Summary
ConstructorDescriptionExpressionHelper
(Question question, nz.org.riskscape.engine.types.Struct context) Creates a helper for the given struct context. -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<ExpressionHelper>
create
(IncrementalBuildState buildState, Question question) Creates an attribute helper based on the context struct deduced from the given question/answers.Returns a complete list of attributes (included those nested within structs) that contained in the context struct.getAttributeMetadata
(List<Class<? extends nz.org.riskscape.engine.types.Type>> allowedTypes) Obtains a list of attributes that are found by re-cursing into the context struct.nz.org.riskscape.engine.types.Struct
The fully qualified context that expressions would have available when they are executed.TheQuestion
that this helper is to help answer.getValues
(@NonNull ExpressionHelper.AttributeMetadata attribute) Attempt to get a list of possible values of the desired attribute.
-
Field Details
-
TAG_LAYER_QUESTION_NAME
Annotation whose value ought to be a
Question
name that will contain aRelation
containingResolvedBookmark
. The helper will then use the relations type as the expression scope.- See Also:
-
TAG_LAYER_NAME
Annotation whose value is the member name that layer will be stored in.
- See Also:
-
TAG_EXPRESSION_TYPE
Annotation key whose value determines the type of expression required.
- See Also:
-
TAG_EXPRESSION_TYPE_BOOLEAN
Value for {@link #TAG<em>EXPRESSION</em>TYPE} to require an expression that should return a boolean when evaluated.
- See Also:
-
TAG_EXPRESSION_TYPE_NUMERIC
Value for {@link #TAG<em>EXPRESSION</em>TYPE} to require an expression that should return a numeric value when evaluated.
- See Also:
-
-
Constructor Details
-
ExpressionHelper
Creates a helper for the given struct context. In this case there is no underlying relation associated with the struct.
-
-
Method Details
-
create
public static Optional<ExpressionHelper> create(IncrementalBuildState buildState, Question question) Creates an attribute helper based on the context struct deduced from the given question/answers.
- Returns:
- an optional expression helper if question/answers contains required metadata, empty otherwise
-
getAttributeMetadata
public List<ExpressionHelper.AttributeMetadata> getAttributeMetadata(List<Class<? extends nz.org.riskscape.engine.types.Type>> allowedTypes) Obtains a list of attributes that are found by re-cursing into the context struct.
- Parameters:
allowedTypes
- that attributes must be to be included in returned list. If empty all types are allowed.- Returns:
- list of found attributes that are of an allowed type
-
getAttributeMetadata
Returns a complete list of attributes (included those nested within structs) that contained in the context struct.
-
getValues
public List<ExpressionHelper.AttributeValue> getValues(@NonNull @NonNull ExpressionHelper.AttributeMetadata attribute) Attempt to get a list of possible values of the desired attribute.
In the case of types with a restricted set of allowed values such as
WithinSet
orEnumeration
then the values are those allowed by the type system.Otherwise the relation (if present) will be scanned, for the values that are actually present in the data.
- Parameters:
attribute
- attribute to get possible values of- Returns:
- list of possible values, or empty if no list could be generated
-
getExpressionType
- Returns:
- the content of the {@link #TAG<em>EXPRESSION</em>TYPE} question annotation, or empty if no annotation given
-
getAttributeChoices
-
getQuestion
The
Question
that this helper is to help answer. -
getContext
public nz.org.riskscape.engine.types.Struct getContext()The fully qualified context that expressions would have available when they are executed.
-