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
Modifier and TypeClassDescriptionstatic enum
Determines whether the user wants to provide a custom expression manually, or build an expression interactively in the wizard.static interface
-
Field Summary
Fields inherited from class nz.org.riskscape.wizard.ask.BaseAsker
enumTranslator, translationContext
-
Constructor Summary
ConstructorDescriptionExpressionAsker
(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 String
askInteractively
(CliPrompter cliPrompter, nz.org.riskscape.wizard.ExpressionHelper helper) Build an expression interactively in the wizard, i.e.boolean
canAsk
(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.AttributeMetadata
CliChoice
s 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.AttributeMetadata
CliChoice
s 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
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 givenQuestion
andIncrementalBuildState
- Returns:
- true if this
Asker
can 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: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 -
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
-