Class ExpressionAsker

java.lang.Object
nz.org.riskscape.wizard.ask.BaseAsker
nz.org.riskscape.wizard.ask.ExpressionAsker
All Implemented Interfaces:
Asker
Direct Known Subclasses:
BooleanExpressionAsker

public class ExpressionAsker extends BaseAsker

An Asker for getting an Expression answer that allows the user to either enter the expression themselves, or to build the expression interactively via askInteractively(nz.org.riskscape.wizard.CliPrompter, nz.org.riskscape.wizard.ExpressionHelper)

Intended to be extended to create more specific askers by overriding: - askInteractively(nz.org.riskscape.wizard.CliPrompter, nz.org.riskscape.wizard.ExpressionHelper) - getAllowedExpressionTypes()

  • Field Details

  • Constructor Details

    • ExpressionAsker

      public ExpressionAsker(nz.org.riskscape.engine.i18n.TranslationContext messageSource, List<String> allowedExpressionTypes)
  • Method Details

    • getAttributeChoices

      protected List<Choice<nz.org.riskscape.wizard.ExpressionHelper.AttributeMetadata>> getAttributeChoices(List<Class<? extends nz.org.riskscape.engine.types.Type>> allowedTypes, nz.org.riskscape.wizard.ExpressionHelper helper)

      Get a list of the ExpressionHelper.AttributeMetadata Choices that are available and of an allowedType.

      Parameters:
      allowedTypes - types that attributes must contain to be allowed in returned list
      helper - to obtain attributes from
      Returns:
      list of found attributes
    • getValueChoices

      protected List<Choice<String>> getValueChoices(nz.org.riskscape.wizard.ExpressionHelper.AttributeMetadata member, nz.org.riskscape.wizard.ExpressionHelper helper)
      Returns:
      a list of possible values (as Choices for the given attribute. This is only possible if the attribute's type has a predetermined set of values (i.e. enum or WithinSet), or we have the underlying relation data we can look at.
    • askInteractively

      protected String askInteractively(CliPrompter cliPrompter, nz.org.riskscape.wizard.ExpressionHelper helper)

      Build an expression interactively in the wizard, i.e. user picks what attribute to use, how to transform it, etc.

    • canAsk

      public boolean canAsk(nz.org.riskscape.wizard.bld.IncrementalBuildState buildState, nz.org.riskscape.wizard.Question question)
      Description copied from interface: Asker

      Determine whether this Asker is relevant for the given Question and IncrementalBuildState

      Returns:
      true if this Asker can and should drive the cli to answer the given Question.
    • ask

      public nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.wizard.Answer.Response> ask(AskRequest input)
      Description copied from class: BaseAsker

      Get a bound value from the user - note that the response's original input is returned from BaseAsker.askUnbound(AskRequest). This is partly here because the original API exposed this method on the interface, and keeping this method here keeps the refactoring/change noise down to a minimum while allowing the interface to change in the way we want to preserve the right amount of encapsulation

      Specified by:
      ask in class BaseAsker
    • getAllowedExpressionTypes

      protected List<String> getAllowedExpressionTypes()

      Used by canAsk(IncrementalBuildState, Question) to check if the question is for a supported type. Should be overridden if canAsk() is otherwise correct.

      Returns:
      list of TAGEXPRESSIONTYPE values that are supported by the asker