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

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


      throw t;
    }
  }
 
  public void testSaveSurvey() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    Survey actual = null;
    try {
      DateFormat formatter=null;
      formatter = new SimpleDateFormat("yyyy-MM-dd");
      String startDateString = formatter.format(survey.getStartDate());
      Date startDate = (Date)formatter.parse(startDateString);
      // test a complete survey
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(survey.getId(), actual.getId());
      assertEquals(survey.getGroupName(), actual.getGroupName());
      assertEquals(survey.getImageId(), actual.getImageId());
      assertEquals(survey.getDescriptions(), actual.getDescriptions());
      assertEquals(survey.getEndDate(), actual.getEndDate());
      assertEquals(survey.getImageDescriptions(), actual.getImageDescriptions());
      assertEquals(startDate, actual.getStartDate());
      assertEquals(survey.getTitles(), actual.getTitles());
      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.isCheckCookie(), actual.isCheckCookie());
      assertEquals(survey.isCheckIpAddress(), actual.isCheckIpAddress());
      assertEquals(survey.getQuestions().size(), actual.getQuestions().size());
      for (Question currentQuestion: survey.getQuestions()) {
        Question actualQuestion = actual.getQuestion(currentQuestion.getId());
        assertNotNull(actualQuestion);
        assertEquals(currentQuestion.getPos(), actualQuestion.getPos());
        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());
      for (Question i: survey.getQuestions()) {
        i.setChoices(new ArrayList<Choice>());
      }
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(survey.getId(), actual.getId());
      assertEquals(survey.getGroupName(), actual.getGroupName());
      assertEquals(survey.getImageId(), actual.getImageId());
      assertEquals(survey.getDescriptions(), actual.getDescriptions());
      assertEquals(survey.getEndDate(), actual.getEndDate());
      assertEquals(survey.getImageDescriptions(), actual.getImageDescriptions());
      assertEquals(startDate, actual.getStartDate());
      assertEquals(survey.getTitles(), actual.getTitles());
      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.isCheckCookie(), actual.isCheckCookie());
      assertEquals(survey.isCheckIpAddress(), actual.isCheckIpAddress());
      assertEquals(survey.getQuestions().size(), actual.getQuestions().size());
      for (Question currentQuestion: survey.getQuestions()) {
        Question actualQuestion = actual.getQuestion(currentQuestion.getId());
        assertNotNull(actualQuestion);
        assertEquals(currentQuestion.getPos(), actualQuestion.getPos());
        assertEquals(currentQuestion.isSingleChoice(), actualQuestion.isSingleChoice());
        assertEquals(currentQuestion.getMaxResponseNumber(), actualQuestion.getMaxResponseNumber());
        assertEquals(currentQuestion.getMinResponseNumber(), actualQuestion.getMinResponseNumber());
        assertEquals(currentQuestion.getQuestions(), actualQuestion.getQuestions());
        assertNotNull(currentQuestion.getChoices());
        assertEquals(currentQuestion.getChoices().isEmpty(), actualQuestion.getChoices().isEmpty());
        // System.out.println(" QUID "+currentQuestion.getId());
      }
      // test a survey with no questions
      this.getSurveyManager().deleteSurvey(survey.getId());
      survey.getQuestions().clear();
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(survey.getId(), actual.getId());
      assertEquals(survey.getGroupName(), actual.getGroupName());
      assertEquals(survey.getImageId(), actual.getImageId());
      assertEquals(survey.getDescriptions(), actual.getDescriptions());
      assertEquals(survey.getEndDate(), actual.getEndDate());
      assertEquals(survey.getImageDescriptions(), actual.getImageDescriptions());
      assertEquals(startDate, actual.getStartDate());
      assertEquals(survey.getTitles(), actual.getTitles());
      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.isCheckCookie(), actual.isCheckCookie());
      assertEquals(survey.isCheckIpAddress(), actual.isCheckIpAddress());
      assertNotNull(actual.getQuestions());
      assertEquals(0, actual.getQuestions().size());
      assertEquals(survey.getQuestions().size(), actual.getQuestions().size());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here


      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  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().deleteChoice(choice.getId());
    }
  }
 
  public void testDeleteChoiceByQuestionid() throws Throwable {
    Survey survey = null;
    Question actualQuestion = null;
    Survey actual = null;
    try {
      survey = this.getFakeActiveSurvey();
      survey.getQuestions().remove(0);
      assertEquals(1, survey.getQuestions().size());
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertEquals(1, actual.getQuestions().size());
      assertEquals(2, actual.getQuestions().get(0).getChoices().size());
      int questionId = survey.getQuestions().get(0).getId();
      this.getSurveyManager().deleteChoiceByQuestionId(questionId);
      actualQuestion = this.getSurveyManager().loadQuestion(questionId);
      assertNotNull(actualQuestion);
      assertNotNull(actualQuestion.getChoices());
View Full Code Here

      this.getSurveyManager().deleteQuestion(question.getId());
    }
  }
 
  public void testDeleteQuestionBySurveyId() throws Throwable {
    Survey survey = getFakeActiveSurvey();
    Survey actual = null;
    try {
      this.getSurveyManager().saveSurvey(survey);
      this.getSurveyManager().deleteQuestionBySurveyId(survey.getId());
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertEquals(survey.getId(), actual.getId()); // not really needed :)
      assertEquals(survey.getImageId(), actual.getImageId());
      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.getDescriptions(), actual.getDescriptions());
      assertTrue(actual.getQuestions().isEmpty());
      for (Question question: survey.getQuestions()) {
        Question actualQuestion = this.getSurveyManager().loadQuestion(question.getId());
        assertNull(actualQuestion);
        for (Choice choice: question.getChoices()) {
          Choice actualChoice = this.getSurveyManager().loadChoice(choice.getId());
View Full Code Here

      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testUpdateSurvey() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    Survey actual = null;
    try {
      this.getSurveyManager().saveSurvey(survey);
      assertEquals(false, survey.getQuestions().get(0).isQuestionnaire());
      assertEquals(false, survey.getQuestions().get(0).getChoices().get(0).isQuestionnaire());
      assertEquals(survey.getId(), survey.getQuestions().get(0).getChoices().get(0).getSurveyId());
      // modify a complete survey with its question and choices
      survey.setActive(false);
      survey.setPublicPartialResult(true);
      survey.setPublicResult(false);
      survey.setQuestionnaire(true);
      assertEquals(survey.getId(), survey.getQuestions().get(0).getChoices().get(0).getSurveyId());
      survey.setGatherUserInfo(false);
      survey.setRestricted(true);
      survey.getQuestions().get(0).setPos(2); // this will swap position when loading from database
      survey.getQuestions().get(0).setSingleChoice(true);
      survey.getQuestions().get(0).setMinResponseNumber(789);
      survey.getQuestions().get(0).setMaxResponseNumber(1011);
      survey.getQuestions().get(0).setSingleChoice(true);
      survey.getQuestions().get(1).getChoices().get(0).setPos(11); // this will swap position when loading from database
      survey.getQuestions().get(1).getChoices().get(1).setFreeText(false);
      this.getSurveyManager().updateSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(false, actual.isActive());
      assertEquals(true, actual.isPublicPartialResult());
      assertEquals(false, actual.isPublicResult());
      assertEquals(true, actual.isQuestionnaire());
      assertEquals(false, actual.isGatherUserInfo());
      assertEquals(true, actual.isRestricted());
      assertNotNull(actual.getQuestions());
      assertEquals(2, actual.getQuestions().size());
      assertNotNull(actual.getQuestions().get(0).getChoices());
      assertNotNull(actual.getQuestions().get(1).getChoices());
      assertEquals(2, actual.getQuestions().get(0).getChoices().size());
      assertEquals(2, actual.getQuestions().get(1).getChoices().size());
      assertEquals(2, actual.getQuestions().get(1).getPos());
      assertEquals(true, actual.getQuestions().get(1).isSingleChoice());
      assertEquals(789, actual.getQuestions().get(1).getMinResponseNumber());
      assertEquals(1011, actual.getQuestions().get(1).getMaxResponseNumber());
      assertEquals(true, actual.getQuestions().get(1).isSingleChoice());
      assertEquals(1, actual.getQuestions().get(0).getPos());
      assertEquals(false, actual.getQuestions().get(0).isSingleChoice());
      assertEquals(false, actual.getQuestions().get(0).getChoices().get(0).isFreeText());
      assertEquals(11, actual.getQuestions().get(0).getChoices().get(1).getPos());
      assertEquals(10, actual.getQuestions().get(0).getChoices().get(0).getPos());
      assertTrue(survey.getQuestions().get(0).isQuestionnaire());
      assertTrue(survey.getQuestions().get(0).getChoices().get(0).isQuestionnaire());
      // check extra info
      assertTrue(survey.getQuestions().get(0).isQuestionnaire());
      assertTrue(survey.getQuestions().get(0).getChoices().get(0).isQuestionnaire());
      assertEquals(survey.getId(), survey.getQuestions().get(0).getChoices().get(0).getSurveyId());
      survey = this.getSurveyManager().loadSurvey(actual.getId());
      // update survey with no choices and one question
      assertNotNull(survey);
      survey.getQuestions().remove(1);
      survey.getQuestions().get(0).getChoices().clear();
//      survey.getQuestions().get(0).setChoices(null); // is the same of the line above
      survey.setActive(true);
      survey.setPublicPartialResult(false);
      survey.getQuestions().get(0).setSingleChoice(true);
      survey.getQuestions().get(0).setPos(11);
      this.getSurveyManager().updateSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertEquals(1, actual.getQuestions().size());
      assertEquals(true, actual.isActive());
      assertEquals(false, actual.isPublicPartialResult());
      assertEquals(true, actual.getQuestions().get(0).isSingleChoice());
      assertEquals(11, actual.getQuestions().get(0).getPos());
      // alternate question checks, load directly from the DB
      Question question = this.getSurveyManager().loadQuestion(actual.getQuestions().get(0).getId());
      assertNotNull(question);
      assertNotNull(question.getChoices());
      assertTrue(question.getChoices().isEmpty());
      // update a survey with no question
      survey = this.getSurveyManager().loadSurvey(actual.getId());
      survey.getQuestions().clear();
      survey.setActive(false);
      survey.setPublicPartialResult(false);
      survey.setPublicResult(true);
      survey.setQuestionnaire(true);
      survey.setGatherUserInfo(false);
      survey.setRestricted(true);
      this.getSurveyManager().updateSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertTrue(actual.getQuestions().isEmpty());
      assertEquals(false, actual.isActive());
      assertEquals(false, actual.isPublicPartialResult());
      assertEquals(true, actual.isPublicResult());
      assertEquals(true, actual.isQuestionnaire());
      assertEquals(false, actual.isGatherUserInfo());
      assertEquals(true, actual.isRestricted());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

   * @return the complete survey, null otherwise
   */
  @Override
  public Survey loadSurvey(int id) {
    Connection conn = null;
    Survey survey = null;
    try {
      conn = this.getConnection();
      survey = this.loadSurvey(conn, id);
    } catch (Throwable t) {
      processDaoException(t, "Error while loading the survey", "loadSurvey");
View Full Code Here

  }
 
  private Survey loadSurvey(Connection conn, int id) {
    PreparedStatement stat = null;
    ResultSet res = null;
    Survey survey = null;
    Integer currentQuestionId = null;
    try {
      stat = conn.prepareStatement(GET_COMPLETE_SURVEY_BY_ID);
      stat.setInt(1, id);
      res = stat.executeQuery();
      while (res.next()) {
        // FIXME usare le costanti per lo shift?
        if (null == survey) {
          survey = this.buildSurveyRecordFromResultSet(res);
        }
        Integer questionId = res.getInt(18);
        Question question = null;
        if (null == currentQuestionId || !questionId.equals(currentQuestionId)) {
          question = this.buildQuestionRecordFromResultSet(res, 18);
          if (null == question) continue;
          survey.getQuestions().add(question);
          currentQuestionId = questionId;
        } else {
          question = survey.getQuestion(currentQuestionId);
        }
        Choice choice = this.buildChoiceRecordFromResultSet(res, 25);
        if (null == choice) {
          continue;
        }
View Full Code Here

   * build a survey object from the record returned by the database.
   * @param res the result set containing to process
   * @param survey the resulting survey object or null if errors occur
   */
  private Survey buildSurveyRecordFromResultSet(ResultSet res) {
    Survey survey = null;
    if (null == res) {
      return null;
    }
    try {
      int id = res.getInt(1);
      if (id > 0) {
        survey = new Survey();
        survey.setQuestions(new ArrayList<Question>());
        survey.setId(id);
        ApsProperties prop = new ApsProperties();
        prop.loadFromXml(res.getString(2));
        survey.setDescriptions(prop);
        survey.setGroupName(res.getString(3).trim());
        survey.setStartDate(res.getDate(4));
        survey.setEndDate(res.getDate(5));
        survey.setActive(res.getBoolean(6));
        survey.setPublicPartialResult(res.getBoolean(7));
        survey.setPublicResult(res.getBoolean(8));
        survey.setQuestionnaire(res.getBoolean(9));
        survey.setGatherUserInfo(res.getBoolean(10));
        prop = new ApsProperties();
        prop.loadFromXml(res.getString(11));
        survey.setTitles(prop);
        survey.setRestricted(res.getBoolean(12));
        survey.setCheckCookie(res.getBoolean(13));
        survey.setCheckIpAddress(res.getBoolean(14));
        survey.setCheckUsername(res.getBoolean(15));
        survey.setImageId(res.getString(16));
        prop = new ApsProperties();
        prop.loadFromXml(res.getString(17));
        survey.setImageDescriptions(prop);
      }
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "buildSurveyRecordFromResultSet",
      "Error while building a 'survey' object from the result set");
    }
View Full Code Here

    PreparedStatement stat = null;
    Connection conn = null;
    try {
      conn = this.getConnection();
      conn.setAutoCommit(false);
      Survey survey = this.loadSurvey(id);
      if (null != survey) {
        // CANCELLA LE DOMANDE
        for (Question question: survey.getQuestions()) {
          this.deleteQuestion(conn, question.getId());
        }
        // CANCELLA IL SONDAGGIO
        stat = conn.prepareStatement(DELETE_SURVEY_BY_ID);
        stat.setInt(1, id);
View Full Code Here

      while (res.next()) {
        Integer currentId= new Integer(res.getInt(1));
        // if the search includes part of the title and / or the description we must perform extra checks
        if ((null != description && description.trim().length () > 0) ||
            (null != title && title.trim().length () > 0)) {
          Survey survey = this.loadSurvey(conn, currentId);
          if (null != description && description.trim().length() > 0) {
            if (this.searchInProperties(description, survey.getDescriptions())) {
              list.add(currentId);
              continue;
            }
          }
          if ((null != title && title.trim().length() > 0)) {
            if (this.searchInProperties(title, survey.getTitles())) {
              list.add(currentId);
            }
          }
        } else {
          // always add if no description or title description are given
View Full Code Here

TOP

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

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.