Package com.agiletec.plugins.jpsurvey.aps.system.services.survey.model

Examples of com.agiletec.plugins.jpsurvey.aps.system.services.survey.model.Question


  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testDeleteQuestion() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(false, true, false);
    Question question = null;
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
View Full Code Here


  /* (non-Javadoc)
   * @see com.agiletec.plugins.jpsurvey.apsadmin.survey.IQuestionAction#addNewQuestion()
   */
  public String addNewQuestion() {
    SurveyRecord survey = null;
    Question fakeQuestion = new Question();
    try {
      if (this.getQuestionId() == null ) {
        setStrutsAction(ApsAdminSystemConstants.ADD);
        // we have no choice but to load the titles from the survey
        survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
        if (null != survey) {
          fakeQuestion.setId(-1);
          fakeQuestion.setSurveyId(this.getSurveyId());
          fakeQuestion.setExtraInfo(survey.isQuestionnaire(), survey.getTitles());
          this.setQuestion(fakeQuestion);
        }
      } else {
        if (this.getActionErrors().isEmpty()) return this.editSingleQuestion();
      }
View Full Code Here

    return SUCCESS;
  }
 
  @Override
  public String editSingleQuestion() {
    Question question = null;
    this.setStrutsAction(ApsAdminSystemConstants.EDIT);
    try {
      if (null != this.getQuestionId()) {
        question = this.getSurveyManager().loadQuestion(this.getQuestionId());
        if (null == question) {
          this.addActionError(this.getText("message.questionAction.nullquestion", new String[]{String.valueOf(this.getQuestionId())}));
          return INPUT;
        } else {
          this.setQuestion(question);
          this.setTitles(question.getSurveyTitles());
          this.setQuestionId(question.getId());
          this.setSurveyId(question.getSurveyId());
          this.setQuestions(question.getQuestions());
          this.setPos(question.getPos());
          this.setSingleChoice(question.isSingleChoice() ? SINGLE_CHOICE_ID : MULTIPLE_CHOICE_ID);
          if (!question.isSingleChoice()) {
            this.setMinResponseNumber(question.getMinResponseNumber());
            this.setMaxResponseNumber(question.getMaxResponseNumber());
          }
          Map<Integer, Integer> stats = getResponseManager().loadQuestionStatistics(this.getQuestionId());
          // load statistics for the current question
          this.setChoiceStats(stats);
        }
View Full Code Here

 
  /* (non-Javadoc)
   * @see com.agiletec.plugins.jpsurvey.apsadmin.survey.IQuestionAction#saveQuestion()
   */
  public String saveQuestion() {
    Question question = null;
    try {
      if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        question = new Question();
        question.setSurveyId(this.getSurveyId());
        question.setSingleChoice(true);
      }
      if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
        question = this.getSurveyManager().loadQuestion(this.getQuestionId());
        question.setSingleChoice(this.getSingleChoice() == SINGLE_CHOICE_ID);
        if (!question.isSingleChoice()) {
          question.setMaxResponseNumber(this.getMaxResponseNumber());
          question.setMinResponseNumber(this.getMinResponseNumber());
          // THIS WILL NOT PRESERVE THE SINGLE/MULTIPLE CHOICE OPTION
          // check if the min and max answer are present
          if (question.getChoices().size() < this.getMinResponseNumber()) {
            // the choices are fewer than those mandatory
            this.addActionError(this.getText("message.question.tooFewChoices",
                new String[]{String.valueOf(question.getChoices().size()), String.valueOf(this.getMinResponseNumber())}));
            return "wrongAnswerNumber";
          }
          if (this.getMinResponseNumber() > this.getMaxResponseNumber()) {
            // the number of mandatory choices is smaller than the number of the allowed ones.
            this.addActionError(this.getText("message.question.incorrectChoicesRange",
                new String[]{String.valueOf(this.getMinResponseNumber()), String.valueOf(this.getMaxResponseNumber())}));
            return "wrongAnswerNumber";
          }
          if (question.getChoices().size() < this.getMaxResponseNumber()) {
            // the number of choices is smaller than the one a user can pick
            this.addActionError(this.getText("message.question.fewChoices",
                new String[]{String.valueOf(question.getChoices().size()), String.valueOf(this.getMaxResponseNumber())}));
            return "wrongAnswerNumber";
          }
        } else {
          question.setMaxResponseNumber(0);
          question.setMinResponseNumber(0);
        }
      }
      question.setQuestions(this.getQuestions());
      if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        this.getSurveyManager().saveQuestionInSortedPosition(question);
        this.setQuestionId(question.getId());
        this.setStrutsAction(ApsAdminSystemConstants.EDIT);
        return "editSingleQuestion";
      }
      if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
        this.getSurveyManager().updateQuestion(question);
View Full Code Here

public class SurveyQuestionAction extends AbstractSurveyAction implements ISurveyQuestionAction, ServletResponseAware {
 
  @Override
  public void validate() {
    super.validate();
    Question question = this.getCurrentQuestion();
    if (question.isSingleChoice()) {
      this.checkSingleChoiseQuestion(question);
    } else {
      if (this.getChoiceIds().size() < question.getMinResponseNumber()) {
          String[] args = {String.valueOf(question.getMinResponseNumber())};
          this.addActionError(this.getText("jpsurvey.front.wrongMinResponseNumber", args))
      }
      if (this.getChoiceIds().size() > question.getMaxResponseNumber()) {
        String[] args = {String.valueOf(question.getMaxResponseNumber())};
        this.addActionError(this.getText("jpsurvey.front.wrongMaxResponseNumber", args));
      }
      for (int i=0; i<this.getChoiceIds().size(); i++) {
        Integer choiseId = this.getChoiceIds().get(i);
        this.checkSingleResponse(question, choiseId);
View Full Code Here

      int currentIndexInt = this.getCurrentQuestionIndex().intValue();
      if (currentIndexInt != currentVotingInfoBean.getCurrentQuestionIndex()) {
        //Check REFRESH
        return SUCCESS;
      }
      Question question = this.getCurrentQuestion();
      for (int i=0; i<this.getChoiceIds().size(); i++) {
        Integer choiceId = this.getChoiceIds().get(i);
        SingleQuestionResponse singleResponse = new SingleQuestionResponse();
        singleResponse.setChoiceId(choiceId);
        singleResponse.setQuestionId(question.getId());
        Choice choice = question.getChoice(choiceId);
        if (choice.isFreeText()) {
          singleResponse.setFreeText(this.getInsertedFreeText().trim());
        }
        currentVotingInfoBean.getVoterResponse().getResponses().add(singleResponse);
      }
View Full Code Here

 
  /* (non-Javadoc)
   * @see com.agiletec.plugins.jpsurvey.apsadmin.survey.IQuestionAction#trashQuestion()
   */
  public String trashQuestion() {
    Question question = null;
    try {
      if (null != this.getQuestionId()) {
        question = this.getSurveyManager().loadQuestion(this.getQuestionId());
      } else {
        this.addActionError(this.getText("message.surveyAction.sysError", new String[]{"questionId"}));
View Full Code Here

      throw t;
    }
  }
 
  public void testLoadQuestion() throws Throwable {
    Question question = null;
    int[] choiceOrder = {5, 4, 7, 6};
    try {
      question = this.getSurveyManager().loadQuestion(2);
      assertNotNull(question);
      assertEquals(2, question.getId());
      assertNotNull(question.getQuestions());
      assertEquals(1, question.getPos());
      assertFalse(question.isSingleChoice());
      assertEquals(1, question.getMinResponseNumber());
      assertEquals(2, question.getMaxResponseNumber());
      List<Choice> choices = question.getChoices();
      assertNotNull(choices);
      assertEquals(4, choices.size());
      assertEquals(true, question.isQuestionnaire());
      assertEquals(true, choices.get(0).isQuestionnaire());
      assertEquals("Titolo-1", question.getSurveyTitles().get("it"));
      for (int i = 0; i < choices.size(); i++) {
        Choice choice = choices.get(i);
        assertEquals(choiceOrder[i], choice.getId());
        assertEquals(i + 1, choice.getPos());
      }
View Full Code Here

      throw t;
    }
  }
 
  public void testSaveQuestion() throws Throwable {
    Question question = this.getFakeQuestion();
    Question question2 = this.getFakeQuestion();
    Question actual = null;
    try {
      assertEquals(1, question.getSurveyId());
      // save a complete question
      this.getSurveyManager().saveQuestion(question);
      // save question with no choices
      question2.setChoices(null);
      this.getSurveyManager().saveQuestion(question2);
      // save a standard question
      actual = this.getSurveyManager().loadQuestion(question.getId());
      assertNotNull(actual);
      assertEquals(question.getSurveyId(), actual.getSurveyId());
      assertEquals(question.getPos(), actual.getPos());
      assertEquals(question.getMinResponseNumber(), actual.getMinResponseNumber());
      assertEquals(question.getMaxResponseNumber(), actual.getMaxResponseNumber());
      assertTrue(!actual.getChoices().isEmpty());
      assertEquals(question.getChoices().size(), actual.getChoices().size());
      // save a question with no choices
      actual = this.getSurveyManager().loadQuestion(question2.getId());
      assertNotNull(actual);
      assertEquals(question2.getId(), actual.getId());
      assertEquals(question2.getSurveyId(), actual.getSurveyId());
      assertEquals(question2.getPos(), actual.getPos());
      assertEquals(question2.getMinResponseNumber(), actual.getMinResponseNumber());
      assertEquals(question2.getMaxResponseNumber(), actual.getMaxResponseNumber());
      assertTrue(actual.getChoices().isEmpty());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteQuestion(question.getId());
      this.getSurveyManager().deleteQuestion(question2.getId());
View Full Code Here

  }
 
  @Override
  public void swapQuestionPosition(int id, boolean isUp) throws ApsSystemException {
    try {
      Question targetQuestion = this.getQuestionDAO().loadQuestion(id);
      if (null == targetQuestion) {
        return;
      }
      Survey survey = this.getSurveyDAO().loadSurvey(targetQuestion.getSurveyId());
      if (null == survey) {
        return;
      }
      List<Question> questions = survey.getQuestions();
      this.getQuestionDAO().swapQuestionPosition(targetQuestion, questions, isUp);
View Full Code Here

TOP

Related Classes of com.agiletec.plugins.jpsurvey.aps.system.services.survey.model.Question

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.