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

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


    return SUCCESS;
  }

  @Override
  public String retireSurvey() {
    Survey survey = null;
    try {
      if (null != this.getQuestionnaire() && null != getSurveyId()) {
        survey = getSurveyManager().loadSurvey(this.getSurveyId());
        if (null != survey) {
          survey.setActive(false);
          getSurveyManager().updateSurvey(survey);
          String surveyInfo = this.getQuestionnaire() ? this.getText("message.jpsurvey.survey.type"): this.getText("message.jpsurvey.poll.type");
          this.addActionMessage(this.getText("message.jpsurvey.surveyUnpublished", new String[] {surveyInfo, this.getLabel(survey.getTitles()) } ));
          return SUCCESS;
        } else {
          this.addActionError(this.getText("message.surveyAction.cannotProceed"));
          return INPUT;
        }
View Full Code Here


    }
  }
 
  @Override
  public String publishSurvey() {
    Survey survey = null;
    try {
      if (null != this.getSurveyId()) {
        survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
        if (null != survey ) {
          if (!survey.isPublishable()) {
            this.addActionError(this.getText("message.jpsurvey.activationNotAllowed"));
          } else {
            survey.setActive(true);
            this.getSurveyManager().updateSurvey(survey);
            String surveyInfo = this.getQuestionnaire() ? this.getText("message.jpsurvey.survey.type"): this.getText("message.jpsurvey.poll.type");
            this.addActionMessage(this.getText("message.jpsurvey.surveyPublished", new String[] {surveyInfo, this.getLabel(survey.getTitles()) } ));
          }
        } else {
          return INPUT;
        }
      } else {
View Full Code Here

  }
 
  public void testDeleteVoterBySurveyId() throws Throwable {
    Voter v1 = this.getFakeVoter();
    Voter v2 = this.getFakeVoter();
    Survey survey=null;
    List<Integer> list=null;
    try {
      survey = this.getFakeActiveSurvey();
      this.getSurveyManager().saveSurvey(survey);
      list = this.getVoterManager().searchVotersByIds(null, null, null, null, null, survey.getId(), null);
      assertNull(list);
      v1.setSurveyid(survey.getId());
      v2.setSurveyid(survey.getId());
      this.getVoterManager().saveVoter(v1);
      this.getVoterManager().saveVoter(v2);
      list = this.getVoterManager().searchVotersByIds(null, null, null, null, null, survey.getId(), null);
      assertNotNull(list);
      assertEquals(2, list.size());
      this.getVoterManager().deleteVoterBySurveyId(survey.getId());
      list = this.getVoterManager().searchVotersByIds(null, null, null, null, null, survey.getId(), null);
      assertNull(list);
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getVoterManager().deleteVoterById(v1.getId());
      this.getVoterManager().deleteVoterById(v2.getId());
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here

  private void initServices() {
    this._surveyManager = (ISurveyManager) this.getService("jpsurveySurveyManager"); // FIXME use constants
  }
 
  protected Survey getFakeActiveSurvey() throws Throwable {
    Survey survey = new Survey();
    String xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"test\">me</property><property key=\"test2\">me too</property></properties>";
    String xmlBarrali="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"en\">You should NOT see THIS in the DB!</property><property key=\"it\">NON dovresti vedere QUESTO nel database!</property></properties>";
    Question question = this.getFakeQuestion();
    Question question2 = this.getFakeQuestion();
    question2.setPos(1);
    List<Question> questions = new ArrayList<Question>();
    questions.add(question);
    questions.add(question2);
    Date date = new Date();
    ApsProperties prop = new ApsProperties();
    prop.loadFromXml(xml);
    survey.setDescriptions(prop);
    survey.setGroupName("fake");
    survey.setStartDate(date);
    survey.setEndDate(null);
    survey.setActive(true);
    survey.setPublicPartialResult(false);
    survey.setPublicResult(true);
    survey.setQuestionnaire(false);
    survey.setGatherUserInfo(true);
    survey.setRestricted(true);
    survey.setTitles(prop);
    survey.setImageId("IMGXXX");
    prop = new ApsProperties();
    prop.loadFromXml(xmlBarrali);
    survey.setImageDescriptions(prop);
    survey.setQuestions(questions);
    return survey;
  }
View Full Code Here

   * @param title the text string inserted in the XML portion for the title
   * @return the requested survey object
   * @throws Throwable
   */
  protected Survey getFakeActiveSurvey(String description, String title) throws Throwable {
    Survey survey = new Survey();
    String xmlDescription="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"en\">"+description+"_en</property><property key=\"it\">"+description+"_it</property></properties>";
    String xmlTitle="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"en\">"+title+"_en</property><property key=\"it\">"+title+"_it+</property></properties>";
    Question question = this.getFakeQuestion();
    Question question2 = this.getFakeQuestion();
    question2.setPos(1);
    List<Question> questions = new ArrayList<Question>();
    questions.add(question);
    questions.add(question2);
    Date date = new Date();
    ApsProperties prop = new ApsProperties();
    prop.loadFromXml(xmlDescription);
    survey.setDescriptions(prop);
    survey.setGroupName("fake");
    survey.setStartDate(date);
    survey.setEndDate(null);
    survey.setActive(true);
    survey.setPublicPartialResult(false);
    survey.setPublicResult(true);
    survey.setQuestionnaire(false);
    survey.setGatherUserInfo(true);
    survey.setRestricted(true);
    prop = new ApsProperties();
    prop.loadFromXml(xmlTitle);
    survey.setTitles(prop);
    survey.setImageId("IMGXXX");
    prop = new ApsProperties();
    prop.loadFromXml(xmlDescription);
    survey.setImageDescriptions(prop);
    survey.setQuestions(questions);
    return survey;
  }
View Full Code Here

   * @param isFreeText
   * @return the survey object just saved in the database
   * @throws Throwable in case of error
   */
  protected Survey createFakeSurveyForTest(boolean isQuestionnaire, boolean isActive, boolean isFreeText) throws Throwable {
    Survey survey = this.getFakeActiveSurvey("testingAction", "testingAction");
    survey.setQuestionnaire(isQuestionnaire);
    survey.setActive(isActive);
    survey.getQuestions().get(0).getChoices().get(0).setFreeText(isFreeText);
    survey.getQuestions().get(0).getChoices().get(1).setFreeText(false);
    survey.getQuestions().get(1).getChoices().get(0).setFreeText(isFreeText);
    survey.getQuestions().get(1).getChoices().get(1).setFreeText(false);
    return survey;
  }
View Full Code Here

   * Create on the fly a survey object to perform tests routines
   * @return a publishable survey object
   * @throws Throwable in case of any error
   */
  protected Survey getFakeActiveSurvey() throws Throwable {
    Survey survey = new Survey();
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"test\">me</property><property key=\"test2\">me too</property></properties>";
    String xmlImageDescr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"en\">You should NOT see THIS in the DB!</property><property key=\"it\">NON dovresti vedere QUESTO nel database!</property></properties>";
    Question question = this.getFakeQuestion();
    Question question2 = this.getFakeQuestion();
    question2.setPos(1);
    List<Question> questions = new ArrayList<Question>();
    questions.add(question);
    questions.add(question2);
    Date date = new Date();
    ApsProperties prop = new ApsProperties();
    prop.loadFromXml(xml);
    survey.setDescriptions(prop);
    survey.setGroupName("fake");
    survey.setStartDate(date);
    survey.setEndDate(null);
    survey.setActive(true);
    survey.setPublicPartialResult(false);
    survey.setPublicResult(true);
    survey.setQuestionnaire(false);
    survey.setGatherUserInfo(true);
    survey.setRestricted(true);
    survey.setTitles(prop);
    survey.setImageId("IMGXXX");
    prop = new ApsProperties();
    prop.loadFromXml(xmlImageDescr);
    survey.setImageDescriptions(prop);
    survey.setQuestions(questions);
    return survey;
  }
View Full Code Here

   * @param title the text string inserted in the XML portion for the title
   * @return the requested survey object
   * @throws Throwable
   */
  protected Survey getFakeActiveSurvey(String description, String title) throws Throwable {
    Survey survey = new Survey();
    String xmlDescription="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"en\">"+description+"_en</property><property key=\"it\">"+description+"_it</property></properties>";
    String xmlTitle="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties><property key=\"en\">"+title+"_en</property><property key=\"it\">"+title+"_it+</property></properties>";
    Question question = this.getFakeQuestion();
    question.setPos(1);
    Question question2 = this.getFakeQuestion();
    question2.setPos(2);
    List<Question> questions = new ArrayList<Question>();
    questions.add(question);
    questions.add(question2);
    Date date = new Date();
    ApsProperties prop = new ApsProperties();
    prop.loadFromXml(xmlDescription);
    survey.setDescriptions(prop);
    survey.setGroupName("fake");
    survey.setStartDate(date);
    survey.setEndDate(null);
    survey.setActive(true);
    survey.setPublicPartialResult(false);
    survey.setPublicResult(true);
    survey.setQuestionnaire(false);
    survey.setGatherUserInfo(true);
    survey.setRestricted(true);
    prop = new ApsProperties();
    prop.loadFromXml(xmlTitle);
    survey.setTitles(prop);
    survey.setImageId("IMGXXX");
    prop = new ApsProperties();
    prop.loadFromXml(xmlDescription);
    survey.setImageDescriptions(prop);
    survey.setQuestions(questions);
    return survey;
  }
View Full Code Here

    }
    return list;
  }
 
  public Survey getSurvey(Integer id) {
    Survey survey = null;
    List<Question> questions = null;
    try {
      survey = this.getSurveyManager().loadSurvey(id);
      questions = this.getSurveyManager().getSurveyQuestions(id);
      if(questions != null){
        survey.setQuestionsNumber(questions.size());
      }
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "loadSurvey");
      throw new RuntimeException("Error loading survey with id " + id, t);
    }
View Full Code Here

  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testSaveSurvey() throws Throwable {
    String result = null;
    Survey poll = this.prepareSurveyForTest(false,false);
    Survey questionnaire = this.prepareSurveyForTest(true,false);
    SurveyAction action = null;
    try {
      this.setUserOnSession("admin");
      this.getSurveyManager().saveSurvey(poll);
      this.getSurveyManager().saveSurvey(questionnaire);
      // updating wrong ID
      this.initAction("/do/jpsurvey/Survey", "saveSurvey");
      this.addParameter("surveyId", "-1");
      this.addParameter("questionnaire", true);
      this.addParameter("checkCookie", "true");
      this.addParameter("description-it", "mucca");
      this.addParameter("title-it", "lilla");
      this.addParameter("groupName", Group.FREE_GROUP_NAME);
      this.addParameter("startDate", "02/06/2008");
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.FAILURE, result);
     
      // editing existing id
      this.initAction("/do/jpsurvey/Survey", "saveSurvey");
      this.addParameter("surveyId", poll.getId());
      assertEquals(3, poll.getId());
      this.addParameter("questionnaire", false);
      this.addParameter("description-it", "mucca");
      this.addParameter("checkCookie", "true");
      this.addParameter("title-it", "lilla");
      this.addParameter("groupName", Group.FREE_GROUP_NAME);
      this.addParameter("startDate", "02/06/2008");
      this.addParameter("publicPartialResult", "1");
      this.addParameter("publicResult", "1");
      this.addParameter("profileUser", "0");
      this.addParameter("gatherUserInfo", "0");
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("imageDescription-it", "Forza Cagliari");
      result = this.executeAction();
      assertEquals("listSurveys", result);
     
      // modify existing id with missing parameter
      this.initAction("/do/jpsurvey/Survey", "saveSurvey");
      this.addParameter("surveyId", questionnaire.getId());
      assertEquals(4, questionnaire.getId());
      this.addParameter("questionnaire", true);
//      this.addParameter("description-it", "mucca"); // oops!
      this.addParameter("checkCookie", "true");
      this.addParameter("title-it", "lilla");
      this.addParameter("groupName", Group.FREE_GROUP_NAME);
      this.addParameter("startDate", "02/06/2008");
      this.addParameter("publicPartialResult", "1");
      this.addParameter("publicResult", "1");
      this.addParameter("profileUser", "0");
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      result = this.executeAction();
      assertEquals(Action.INPUT, result);
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(poll.getId());
      this.getSurveyManager().deleteSurvey(questionnaire.getId());
    }
  }
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.