Class ExpressionAsker
- All Implemented Interfaces:
Asker
- Direct Known Subclasses:
BooleanExpressionAsker
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()
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDetermines whether the user wants to provide a custom expression manually, or build an expression interactively in the wizard.static interface -
Field Summary
FieldsFields inherited from class nz.org.riskscape.wizard.ask.BaseAsker
enumTranslator, translationContext -
Constructor Summary
ConstructorsConstructorDescriptionExpressionAsker(nz.org.riskscape.engine.i18n.TranslationContext messageSource, List<String> allowedExpressionTypes) -
Method Summary
Modifier and TypeMethodDescriptionnz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.wizard.Answer.Response>ask(AskRequest input) Get a bound value from the user - note that the response's original input is returned fromBaseAsker.askUnbound(AskRequest).protected StringaskInteractively(CliPrompter cliPrompter, nz.org.riskscape.wizard.ExpressionHelper helper) Build an expression interactively in the wizard, i.e.booleancanAsk(nz.org.riskscape.wizard.bld.IncrementalBuildState buildState, nz.org.riskscape.wizard.Question question) Used bycanAsk(IncrementalBuildState, Question)to check if the question is for a supported type.getAttributeChoices(List<Class<? extends nz.org.riskscape.engine.types.Type>> allowedTypes, nz.org.riskscape.wizard.ExpressionHelper helper) Get a list of theExpressionHelper.AttributeMetadataCliChoices that are available and of an allowedType.getValueChoices(nz.org.riskscape.wizard.ExpressionHelper.AttributeMetadata member, nz.org.riskscape.wizard.ExpressionHelper helper) Methods inherited from class nz.org.riskscape.wizard.ask.BaseAsker
askUnbound, getChoices, getLocale, getMessage, getMessageSource, getOptionalMessage, pickChoice, toChoice
-
Field Details
-
expressionMessages
-
-
Constructor Details
-
ExpressionAsker
-
-
Method Details
-
getAttributeChoices
protected List<CliChoice<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.AttributeMetadataCliChoices that are available and of an allowedType.- Parameters:
allowedTypes- types that attributes must contain to be allowed in returned listhelper- to obtain attributes from- Returns:
- list of found attributes
-
getValueChoices
protected List<CliChoice<String>> getValueChoices(nz.org.riskscape.wizard.ExpressionHelper.AttributeMetadata member, nz.org.riskscape.wizard.ExpressionHelper helper) - Returns:
- a list of possible values (as
Choicesfor 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:AskerDetermine whether this
Askeris relevant for the givenQuestionandIncrementalBuildState- Returns:
- true if this
Askercan and should drive the cli to answer the givenQuestion.
-
ask
public nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.wizard.Answer.Response> ask(AskRequest input) Description copied from class:BaseAskerGet 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 -
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
-