Class BaseSurvey

java.lang.Object
nz.org.riskscape.wizard.survey2.BaseSurvey
All Implemented Interfaces:
nz.org.riskscape.engine.Identified, Survey
Direct Known Subclasses:
EmptySurvey, ModelSurvey2

public class BaseSurvey extends Object implements Survey

Convenient super class for a phase-based Survey.

Can also be instantiated, but that should be limited to test cases - sub classing makes it easier to organize your survey.

  • Field Details

    • id

      protected final String id
    • messageSource

      protected final nz.org.riskscape.engine.i18n.MessageSource messageSource
    • phases

      protected final List<Phase> phases
  • Constructor Details

    • BaseSurvey

      public BaseSurvey(String id, nz.org.riskscape.engine.i18n.MessageSource messageSource, Function<Survey,List<Phase>> phasesConstructor)
  • Method Details

    • getBackingData

      public BackingData getBackingData(IncrementalBuildState buildState, Question question)
      Specified by:
      getBackingData in interface Survey
      Returns:
      backing data for the ui that helps the user answer a particular question.
    • getApplicableQuestionSets

      protected List<QuestionSet> getApplicableQuestionSets(IncrementalBuildState buildState)
    • getPipelineChange

      public PipelineChange getPipelineChange(IncrementalBuildState buildState, Answer answer)
      Description copied from interface: Survey

      Returns a PipelineChange that is created by applying an answer a build state.

      Specified by:
      getPipelineChange in interface Survey
      Parameters:
      buildState - the build state to get a change to.
      answer - the answer to apply. This answer must be for a question that came back from Survey.getNextQuestion(IncrementalBuildState) using the given build state, or weird things might happen
    • getQuestionTree

      public QuestionTree getQuestionTree(IncrementalBuildState buildState)
      Specified by:
      getQuestionTree in interface Survey
      Returns:
      the set of questions that can be asked next. The controller code can use this question tree as a source of questions until it is empty - it shouldn't keep asking the survey for the tree between questions.
    • getPhaseOfType

      public <T extends Phase> Optional<T> getPhaseOfType(Class<T> clazz)

      Look up a Phase by its implementing class (Assuming they are unique). This has been added mostly so that test cases can find elements of the survey after construction.

    • isFinished

      public boolean isFinished(IncrementalBuildState buildState)
      Specified by:
      isFinished in interface Survey
      Returns:
      true if the survey is 'finished enough' to now run something (even if more optional question-sets remain).
    • getId

      public String getId()
      Specified by:
      getId in interface nz.org.riskscape.engine.Identified
    • getMessageSource

      public nz.org.riskscape.engine.i18n.MessageSource getMessageSource()
      Description copied from interface: Survey

      A MessageSource that is specific to this survey. Should contain i18n text for the various choices and text associated with this survey.

      Specified by:
      getMessageSource in interface Survey
    • getPhases

      public List<Phase> getPhases()