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

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


  public String getDefaultLangCode() {
    return this.getLangManager().getDefaultLang().getCode();
 

  public String trashChoice() throws Throwable {
    Choice choice = null;
    try {
      if (null != this.getChoiceId()) {
        choice = this.getSurveyManager().loadChoice(this.getChoiceId());
        if (null != choice) {
          if (choice.isFreeText()) {
            choice.getChoices().clear();
          }
        }
      } else {
        this.addActionError(this.getText("message.surveyAction.sysError", new String[]{"choiceId"}));
        return INPUT;
View Full Code Here


          survey.getQuestions().add(question);
          currentQuestionId = questionId;
        } else {
          question = survey.getQuestion(currentQuestionId);
        }
        Choice choice = this.buildChoiceRecordFromResultSet(res, 25);
        if (null == choice) {
          continue;
        }
        if (null == question.getChoice(choice.getId())) {
          question.getChoices().add(choice);
        }
      }
    } catch (Throwable t) {
      processDaoException(t, "Error while loading the survey ID "+id, "loadSurvey");
View Full Code Here

public class ChoiceDAO extends AbstractSurveyDAO implements IChoiceDAO {
 
  @Override
  public Choice loadChoice(int id) {
    Choice choice = null;
    Connection conn = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    try {
      conn = this.getConnection();
      stat = conn.prepareStatement(GET_CHOICE_BY_ID);
      stat.setInt(1, id);
      res = stat.executeQuery();
      if (res.next()) {
        choice = this.buildChoiceRecordFromResultSet(res, 1);
        // process get extra info
        int surveyId = res.getInt(6);
        boolean questionnaire = res.getInt(7) == 1 ? true:false;
        ApsProperties surveyTitle = new ApsProperties();
        surveyTitle.loadFromXml(res.getString(8));
        ApsProperties questionTitle = new ApsProperties();
        questionTitle.loadFromXml(res.getString(9));
        choice.setExtraInfo(surveyId, questionnaire, surveyTitle, questionTitle);
      }
    } catch (Throwable t) {
      processDaoException(t, "Error while loading the choice of ID "+id, "loadChoice");
    } finally {
      closeDaoResources(res, stat, conn);
View Full Code Here

  }
 
  @Override
  public void swapChoicePosition(Choice choiceToSwap, List<Choice> choices, boolean up) {
    Connection conn = null;
    Choice nearChoiceToSwap = null;
    try {
      for (int i = 0; i < choices.size(); i++) {
        Choice choice = choices.get(i);
        if (choice.getId() == choiceToSwap.getId()) {
          if (up && i>0) {
            nearChoiceToSwap = choices.get(i-1);
          } else if (!up && i<(choices.size()-1)) {
            nearChoiceToSwap = choices.get(i+1);
          }
View Full Code Here

      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());
      }
      // load unknown question
      question = this.getSurveyManager().loadQuestion(22);
      assertNull(question);
    } catch (Throwable t) {
View Full Code Here

      this.getSurveyManager().deleteQuestion(question2.getId());
    }
  }
 
  public void testLoadChoice() throws Throwable {
    Choice choice=null;
    try {
      choice = this.getSurveyManager().loadChoice(669);
      assertNull(choice);
      choice = this.getSurveyManager().loadChoice(6);
      assertNotNull(choice.getChoices());
      assertTrue(choice.isFreeText());
      assertEquals("Opzione TESTO LIBERO", choice.getChoices().get("it"));
      assertEquals(2, choice.getQuestionId());
      assertEquals(4, choice.getPos());
      assertEquals(1, choice.getSurveyId());
      assertEquals(true, choice.isQuestionnaire());
      assertEquals("Question 1-2", choice.getQuestions().get("en"));
      assertEquals("Titolo-1", choice.getSurveyTitles().get("it"));
    } catch (Throwable t) {
      throw t;
    }
  }
View Full Code Here

      throw t;
    }
  }
 
  public void testSaveChoice() throws Throwable {
    Choice choice = null;
    List<Choice> list = null;
    int scan;
    try {
      choice = this.getFakeChoice();
      this.getSurveyManager().saveChoice(choice);
      list = this.getSurveyManager().getQuestionChoices(2);
      assertNotNull(list);
      for (scan=0; scan < list.size() && list.get(scan).getId() != choice.getId(); scan++);
      choice = list.get(scan);
      assertNotNull(choice.getChoices());
      assertEquals(96, choice.getPos());
      assertTrue(choice.isFreeText());
      assertEquals(2, choice.getQuestionId());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteChoice(choice.getId());
    }
  }
View Full Code Here

        assertEquals(currentQuestion.isSingleChoice(), actualQuestion.isSingleChoice());
        assertEquals(currentQuestion.getMaxResponseNumber(), actualQuestion.getMaxResponseNumber());
        assertEquals(currentQuestion.getMinResponseNumber(), actualQuestion.getMinResponseNumber());
        assertEquals(currentQuestion.getQuestions(), actualQuestion.getQuestions());
        for (Choice currentChoice: currentQuestion.getChoices()) {
          Choice actualChoice = actual.getQuestion(currentQuestion.getId()).getChoice(currentChoice.getId());
          assertNotNull(actualChoice);
          assertEquals(currentChoice.isFreeText(), actualChoice.isFreeText());
          assertEquals(currentChoice.getPos(), actualChoice.getPos());
          assertEquals(currentChoice.getChoices(), actualChoice.getChoices());
//          System.out.println(" QUID "+currentQuestion.getId()+" CID "+currentChoice.getId());
        }
      }
      // test a survey with no choices
      this.getSurveyManager().deleteSurvey(survey.getId());
View Full Code Here

    }
  }
 
  public void testSaveChoiceInSortedPosition() throws Throwable {
    Survey survey = null;
    Choice choice = null;
    try {
      survey = this.getFakeActiveSurvey();
      survey.getQuestions().remove(1);
      assertEquals(1, survey.getQuestions().size());
      this.getSurveyManager().saveSurvey(survey);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(survey.getQuestions());
      choice = this.getFakeChoice();
      choice.setId(999);
      assertNotNull(survey.getQuestions());
      choice.setQuestionId(survey.getQuestions().get(0).getId());
      this.getSurveyManager().saveChoiceInSortedPosition(choice);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(survey);
      assertNotNull(survey.getQuestions());
      assertNotNull(survey.getQuestions().get(0).getChoices());
      assertEquals(3, survey.getQuestions().get(0).getChoices().size());
      choice = survey.getQuestions().get(0).getChoices().get(2);
      assertEquals(11, choice.getPos());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testUpdateChoice() throws Throwable {
    Choice choice = getFakeChoice();
    try {
      this.getSurveyManager().saveChoice(choice);
      choice = this.getSurveyManager().loadChoice(choice.getId());
      assertNotNull(choice);
      choice.setPos(2677);
      choice.setFreeText(false);
      this.getSurveyManager().updateChoice(choice);
      choice = this.getSurveyManager().loadChoice(choice.getId());
      assertNotNull(choice);
      assertEquals(2677, choice.getPos());
      assertFalse(choice.isFreeText());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteChoice(choice.getId());
    }
  }
View Full Code Here

TOP

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

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.