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<BasePhase> phases
  • Constructor Details

  • Method Details

    • getApplicableQuestionSets

      public List<QuestionSet> getApplicableQuestionSets(IncrementalBuildState buildState)
      Specified by:
      getApplicableQuestionSets in interface Survey
      Returns:
      a list of the currently applicable QuestionSets, i.e. the sets of questions that are able to be answered next
    • 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).
    • getDefinedPhases

      public List<Phase> getDefinedPhases()
      Specified by:
      getDefinedPhases in interface Survey
      Returns:
      a list of the phases this survey goes through, in sequence order.
    • getId

      public String getId()
      Description copied from interface: Survey

      A unique identifier for this survey.

      Specified by:
      getId in interface nz.org.riskscape.engine.Identified
      Specified by:
      getId in interface Survey
    • 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<BasePhase> getPhases()