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

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


    return list;
  }
 
  @Override
  public List<Question> getSurveyQuestions(int id) {
    Survey survey = null;
    List<Question> list = new ArrayList<Question>();
    try {
      survey = this.loadSurvey(id);
      if (null != survey) {
        list = survey.getQuestions();
      }
    } catch (Throwable t) {
      this.processDaoException(t, "Error getting the questions of a survey", "searchSurveyByIds");
    }
    return list;
View Full Code Here


   *
   * @throws ApsSystemException
   */
  private void fetchLocalizedFields() {
    Iterator<Lang> itr = this.getLangManager().getLangs().iterator();
    Survey survey = null;
    try {
      while (itr.hasNext()) {
        Lang currentLang = itr.next();
        Lang defaultLanguage = this.getLangManager().getDefaultLang();
        String currentLangCode = currentLang.getCode();
        String titleKey = "title-" + currentLangCode;
        String descriptionKey = "description-" + currentLangCode;
        String imageDescriptionKey = "imageDescription-" + currentLangCode;
        String title = this.getRequest().getParameter(titleKey);
        String description = this.getRequest().getParameter(descriptionKey);
        String imageDescription = this.getRequest().getParameter(imageDescriptionKey);
        if (null != title && title.trim().length() > 0) {
          this.getTitles().put(currentLangCode, title.trim());
        } else {
          if (currentLang.getCode().equals(defaultLanguage.getCode())) {
            String[] args = { defaultLanguage.getDescr(), this.getText("title") };
            this.addFieldError(titleKey, this.getText("message.jpsurvey.defaultLangRequired", args));
          }
        }
        if (null != description && description.trim().length() > 0) {
          this.getDescriptions().put(currentLangCode,  description.trim());
        } else {
          if (currentLang.getCode().equals(defaultLanguage.getCode())) {
            String[] args = { defaultLanguage.getDescr(), this.getText("description") };
            this.addFieldError(descriptionKey, this.getText("message.jpsurvey.defaultLangRequired", args));
          }
        }
        if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
          // image description is required if and only if an image has been associated to the current editing _survey
          survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
          // there shouldn't be the need to check for the lenght of the imageId...
          if (null != survey && null != survey.getImageId()) {
            if (null != imageDescriptionKey  && null != imageDescription && imageDescription.trim().length() > 0) {
              this.getImageDescriptions().put(currentLangCode, imageDescription.trim());
            } else {
              if (currentLang.getCode().equals(defaultLanguage.getCode())) {
                String[] args = { defaultLanguage.getDescr(), this.getText("imageDescription") };
View Full Code Here

  public boolean isEditable(Integer surveyId) {
    boolean res = false;
    try {
      if (null == surveyId)
        return true;
      Survey survey = this.getSurveyManager().loadSurvey(surveyId);
      res = !survey.isElegibleForVoting(false);
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "isEditable");
      throw new RuntimeException("Errore nel valutare lo stato \"editabile\" di _survey id " + surveyId, t);
    }
    return res;
View Full Code Here

    }
  }

  @Override
  public String editSurvey() {
    Survey survey = null;
    this.setStrutsAction(ApsAdminSystemConstants.EDIT);
    try {
      survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
      if (null == survey) {
        this.addActionError(this.getText("message.surveyAction.nullSurvey", new String[] {getText("message.jpsurvey.poll.type"), String.valueOf(this.getSurveyId())}));
        return "listSurveys";
      }
      this.setSurvey(survey);
      this.setSurveyId(survey.getId());
      this.setDescriptions(survey.getDescriptions());
      this.setGroupName(survey.getGroupName());
      this.setStartDate(survey.getStartDate());
      this.setEndDate(survey.getEndDate());
      this.setActive(survey.isActive() ? 1 : 0);
      this.setPublicPartialResult(survey.isPublicPartialResult() ? 1 : 0);
      this.setPublicResult(survey.isPublicResult() ? 1 : 0);
      this.setQuestionnaire(survey.isQuestionnaire());
      this.setGatherUserInfo(survey.isGatherUserInfo() ? 1 : 0);
      this.setCheckCookie(survey.isCheckCookie());
      this.setCheckIpAddress(survey.isCheckIpAddress());
      this.setCheckUsername(survey.isCheckUsername());
      this.setTitles(survey.getTitles());
      this.setImageId(survey.getImageId());
      this.setImageDescriptions(survey.getImageDescriptions());
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "editSurvey");
      return FAILURE;
    }
    return SUCCESS;
View Full Code Here

      this.getResponseManager().deleteResponse(r3);
    }
  }
 
  public void testDeleteResponseBySurvey() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    try {
      this.getSurveyManager().saveSurvey(survey);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      for (Question question: survey.getQuestions()) {
        // WE SUPPOSE THAT ALL THE CHOICES CAN BE ANSWERED
        int choiceAnswered = 0;
        for (Choice choice: question.getChoices()) {
          SingleQuestionResponse response = this.getFakeResponse();
          if (choice.isFreeText()) response.setFreeText("Forza Cagliari!");
          response.setChoiceId(choice.getId());
          response.setQuestionId(question.getId());
          response.setVoterId(1); // ALWAYS THE SAME VOTER
          this._responseManager.submitResponse(response);
          choiceAnswered++;
        }
        List<SingleQuestionResponse> list = this._responseManager.aggregateResponseByIds(null, question.getId(), null, null);
        assertEquals(choiceAnswered, list.size());
      }
      // delete all the choices
      this._responseManager.deleteResponseBySurvey(survey);
      // VERIFY QUESTION
      for (Question question: survey.getQuestions()) {
        List<SingleQuestionResponse> questionsAnswered = this._responseManager.aggregateResponseByIds(null, question.getId(), null, null);
        assertNull(questionsAnswered);
        // VERIFY ANSWER
        for (Choice choice: question.getChoices()) {
          List<SingleQuestionResponse> choiceAnswered = this._responseManager.aggregateResponseByIds(null, null, choice.getId(), null);
          assertNull(choiceAnswered);
        }
      }
      List<SingleQuestionResponse> answered = this._responseManager.aggregateResponseByIds(null, null, null, "Cagliari");
      assertNull(answered);
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here

      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testDeleteQuestionByQuestionId() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    try {
      this.getSurveyManager().saveSurvey(survey);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      for (Question question: survey.getQuestions()) {
        // WE SUPPOSE THAT ALL THE CHOICES CAN BE ANSWERED
        int choiceAnswered = 0;
        for (Choice choice: question.getChoices()) {
          SingleQuestionResponse response = this.getFakeResponse();
          if (choice.isFreeText()) response.setFreeText("Forza Milan!");
          response.setChoiceId(choice.getId());
          response.setQuestionId(question.getId());
          response.setVoterId(1); // ALWAYS THE SAME VOTER
          this._responseManager.submitResponse(response);
          choiceAnswered++;
        }
        this._responseManager.deleteResponseByQuestionId(question.getId());
        List<SingleQuestionResponse> list = this._responseManager.aggregateResponseByIds(null, question.getId(), null, null);
        assertNull(list);
      }
      // VERIFY QUESTION
      for (Question question: survey.getQuestions()) {
        List<SingleQuestionResponse> questionsAnswered = this._responseManager.aggregateResponseByIds(null, question.getId(), null, null);
        assertNull(questionsAnswered);
        // VERIFY ANSWER
        for (Choice choice: question.getChoices()) {
          List<SingleQuestionResponse> choiceAnswered = this._responseManager.aggregateResponseByIds(null, null, choice.getId(), null);
          assertNull(choiceAnswered);
        }
      }
      List<SingleQuestionResponse> answered = this._responseManager.aggregateResponseByIds(null, null, null, "Milan");
      assertNull(answered);
    } catch (Throwable t) {
      throw t;
    } finally {
      this._responseManager.deleteResponseBySurvey(survey);
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here

    return this.getGroupManager().getGroups();
  }

  @Override
  public String saveSurvey() {
    Survey survey = null;
    try {
      if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
        survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
        if (null == survey) {
          return FAILURE;
        }
      }
      if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        survey = new Survey();
        survey.setQuestionnaire(this.getQuestionnaire());
      }
      survey.setDescriptions(this.getDescriptions());
      survey.setGroupName(this.getGroupName());
      survey.setStartDate(this.getStartDate());
      survey.setEndDate(this.getEndDate());
      if (null == this.getGatherUserInfo()) {
        this.addActionError(this.getText("message.surveyAction.cannotProceed"));
        return "listSurveys";
      }
      if (survey.isQuestionnaire()) {
        survey.setPublicPartialResult(false);
        survey.setPublicResult(false);
      } else {
        survey.setPublicPartialResult(null != this.getPublicPartialResult() && this.getPublicPartialResult() == 1);
        survey.setPublicResult(null != this.getPublicResult() && this.getPublicResult() == 1);
      }
      survey.setGatherUserInfo(this.getGatherUserInfo() == 1);
      survey.setTitles(this.getTitles());
      survey.setCheckCookie(this.getCheckCookie() == null ? false : this.getCheckCookie().booleanValue());
      survey.setCheckIpAddress(this.getCheckIpAddress() == null ? false : this.getCheckIpAddress().booleanValue());
      survey.setCheckUsername(this.getCheckUsername() == null ? false : this.getCheckUsername().booleanValue());
     
      survey.setImageId(this.getImageId());
      // refresh the image description if and only if the _survey as an image. A new _survey has no image and description by definition
      if (null != survey.getImageId()  && this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
        survey.setImageDescriptions(this.getImageDescriptions());
      } else {
        survey.setImageDescriptions(null);
      }
      this.setSurvey(survey);
      // if the we're editing update the record and return to the proper list
      if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
        this.getSurveyManager().updateSurvey(survey);
        return "listSurveys";
      }
      if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        this.setStrutsAction(ApsAdminSystemConstants.EDIT);
        this.getSurveyManager().saveSurvey(survey);
        this.setSurveyId(survey.getId());
        return "editSurvey";
      }
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "saveSurvey");
      return FAILURE;
View Full Code Here

      String result = this.saveSurvey();
      if (result.equals(FAILURE)) return FAILURE;
      if (!result.equals("listSurveys")) {
        return INPUT;
      }
      Survey survey =  this.getSurveyManager().loadSurvey(this.getSurveyId());
      if (null != survey) {
        survey.setImageId(null);
        survey.setImageDescriptions(null);
        this.getSurveyManager().updateSurvey(survey);
      }
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "removeSurveyImage");
    }
View Full Code Here

    return SUCCESS;
  }

  @Override
  public String trashSurvey() {
    Survey survey = null;
    try {
      if (null != this.getSurveyId()) {
        survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
        if (null == survey) return INPUT;
        this.setSurvey(survey);
View Full Code Here

    return SUCCESS;
  }
 
  @Override
  public String deleteSurvey() {
    Survey survey = null;
    try {
      if (null == this.getSurveyId() || null == this.getQuestionnaire()) {
        this.addActionError(this.getText("message.surveyAction.cannotProceed"));
        return INPUT;
      }
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.