Class ExpressionHelper

java.lang.Object
nz.org.riskscape.wizard.ExpressionHelper

public class ExpressionHelper extends Object

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}

  • Field Details

    • TAG_LAYER_QUESTION_NAME

      public static final String TAG_LAYER_QUESTION_NAME

      Annotation whose value ought to be a Question name that will contain a Relation containing ResolvedBookmark. The helper will then use the relations type as the expression scope.

      See Also:
    • TAG_LAYER_NAME

      public static final String TAG_LAYER_NAME

      Annotation whose value is the member name that layer will be stored in.

      See Also:
    • TAG_EXPRESSION_TYPE

      public static final String TAG_EXPRESSION_TYPE

      Annotation key whose value determines the type of expression required.

      See Also:
    • TAG_EXPRESSION_TYPE_BOOLEAN

      public static final String 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

      public static final String 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

      public ExpressionHelper(Question question, nz.org.riskscape.engine.types.Struct context)

      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

      public List<ExpressionHelper.AttributeMetadata> 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 or Enumeration 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

      public Optional<String> getExpressionType()
      Returns:
      the content of the {@link #TAG<em>EXPRESSION</em>TYPE} question annotation, or empty if no annotation given
    • getQuestion

      public Question 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.