public void removePollingQuestion(AbstractPollingQuestion pollingQuestion)
     throws UsedQuestionException {
   if (!voteDao.isUsedQuestion(pollingQuestion)) {
     voteDao.remove(pollingQuestion);
   } else {
     throw new UsedQuestionException("question_is_used");
   }
 }
 public RatingPollingQuestion saveQuestion(RatingPollingQuestion pollingQuestion)
     throws Exception {
   if (voteDao.isRepeatedQuestion(pollingQuestion))
     throw new RepeatedQuestionException("question_is_repeated");
   else if (voteDao.isAnsweredQuestion(pollingQuestion))
     throw new UsedQuestionException("edit_used_question_message");
   else return (RatingPollingQuestion) voteDao.save(pollingQuestion);
 }
 public MultipleChoicePollingQuestion saveQuestion(MultipleChoicePollingQuestion pollingQuestion)
     throws Exception {
   if (isRepeatedMultipleChoiceQuestion(pollingQuestion))
     throw new RepeatedQuestionException("question_is_repeated");
   else if (voteDao.isAnsweredQuestion(pollingQuestion))
     throw new UsedQuestionException("edit_used_question_message");
   else {
     return (MultipleChoicePollingQuestion) voteDao.save(pollingQuestion);
   }
 }
  public void removePollingTemplate(AbstractPollingTemplate pollingTemplate)
      throws UsedTemplateException {
    if (!voteDao.isUsedTemplate(pollingTemplate)) {
      voteDao.remove(pollingTemplate);
    } else {
      throw new UsedTemplateException("template_is_used");
    }

    //        pollingTemplate = findTemplateByName(pollingTemplate.getName());
    //        List<AbstractVomte> relatedPollingList = findAllVotesByTemplate(pollingTemplate);
    //        if (!relatedPollingList.isEmpty()){
    //            //throws exception
    //            return;
    //        }
  }
 public RecordReport getAverageTotalRateOnRecord(
     VoteReportFilter voteReportFilter, long recordId) {
   RecordReport recordReport = new RecordReport();
   try {
     recordReport.setCount(voteDao.countVotesByVotable(voteReportFilter, recordId));
   } catch (Exception e) {
     recordReport.setCount(0);
   }
   try {
     recordReport.setTotalRate(voteDao.getAverageTotalRateOnRecord(voteReportFilter, recordId));
   } catch (Exception e) {
     recordReport.setTotalRate(0);
   }
   return recordReport;
 }
 public ResultPage findTemplates(
     BibliographicPollingTemplateFilter pollingTemplateFilter,
     int firstResult,
     int maxResultSet,
     GridFilter gridFilter) {
   return voteDao.findTemplates(pollingTemplateFilter, firstResult, maxResultSet, gridFilter);
 }
 public RatingQuestionReport getRatingQuestionTotalRateOnRecord(
     VoteReportFilter voteReportFilter, RatingPollingQuestion question) {
   RatingQuestionReport ratingQuestionReport = new RatingQuestionReport();
   ratingQuestionReport.setQuestion(question);
   List<AbstractQuestionAnswer> questionAnswers =
       voteDao.findVoteQuestionAnswers(voteReportFilter, question);
   ratingQuestionReport.setCount(questionAnswers.size());
   float sumOfRates = 0;
   float sumOfMaxRates = 0;
   for (int i = 0; i < questionAnswers.size(); i++) {
     sumOfRates += ((RatingQuestionAnswer) questionAnswers.get(i)).getValue();
     RatingQuestionAnswer ratingQuestionAnswer = (RatingQuestionAnswer) questionAnswers.get(i);
     List<AbstractTemplateQuestion> templateQuestions =
         ratingQuestionAnswer.getVote().getPollingTemplate().getQuestionList();
     for (int j = 0; j < templateQuestions.size(); j++) {
       if (templateQuestions.get(j) instanceof MultipleChoiceTemplateQuestion) continue;
       if (templateQuestions.get(j).getQuestion().equals(question)) {
         sumOfMaxRates += ((RatingTemplateQuestion) templateQuestions.get(j)).getMaxValue();
         continue;
       }
     }
   }
   if (sumOfMaxRates != 0) {
     ratingQuestionReport.setTotalRate((sumOfRates / sumOfMaxRates));
   }
   return ratingQuestionReport;
 }
 public Vote saveVote(Vote vote) throws Exception {
   // totalRate = (((answer1 calculated rate)/q1 total rate)+(((answer2 calculated rate)/q2 total
   // rate)+...)/(sum of all template question's wight)
   // MultipleChoice answer rate and "total rate" will be evaluated according to selected options
   // Rating answer rate is "value/maxRate"
   vote.setTotalRate(calculateVoteTotalRate(vote));
   return (Vote) voteDao.save(vote);
 }
 private int calculateOptionsTotalRate(MultipleChoicePollingQuestion question) {
   int totalWeight = 0;
   List<PollingOption> options = voteDao.findOptions(question);
   for (int i = 0; i < options.size(); i++) {
     totalWeight += options.get(i).getWeight();
   }
   return totalWeight;
 }
Beispiel #10
0
  public boolean isRepeatedMultipleChoiceQuestion(MultipleChoicePollingQuestion pollingQuestion) {
    List l = voteDao.findCandidateSimilarQuestions(pollingQuestion);

    for (int i = 0; i < l.size(); i++) {
      List<PollingOption> optionList = ((MultipleChoicePollingQuestion) l.get(i)).getOptionList();
      if (isEqualOptionList(optionList, pollingQuestion.getOptionList())) {
        return true;
      }
    }
    return false;
  }
Beispiel #11
0
  public MultipleChoiceQuestionReport getMultipleChoiceQuestionTotalRateOnRecord(
      VoteReportFilter voteReportFilter, MultipleChoicePollingQuestion question) {
    MultipleChoiceQuestionReport multipleChoiceQuestionReport =
        new MultipleChoiceQuestionReport(voteDao.findOptions(question));
    multipleChoiceQuestionReport.setQuestion(question);

    List<AbstractQuestionAnswer> questionAnswers =
        voteDao.findVoteQuestionAnswers(voteReportFilter, question);
    multipleChoiceQuestionReport.setCount(questionAnswers.size());
    float questionTotalWeight = calculateOptionsTotalRate(question);
    float sumOfTotalRates = questionAnswers.size() * questionTotalWeight;

    float sumOfRates = 0;

    for (int i = 0; i < questionAnswers.size(); i++) {
      MultipleChoiceQuestionAnswer multipleChoiceQuestionAnswer =
          (MultipleChoiceQuestionAnswer) questionAnswers.get(i);
      List<PollingAnswerOption> optionList = multipleChoiceQuestionAnswer.getOptionList();
      for (int j = 0; j < optionList.size(); j++) {
        PollingAnswerOption pollingAnswerOption = optionList.get(j);
        MultipleChoiceQuestionReport.OptionInfo optionInfo =
            findOptionCount(
                multipleChoiceQuestionReport.getOptionCounts(),
                pollingAnswerOption.getPollingOption());
        optionInfo.setCount(optionInfo.getCount() + 1);
        float percent =
            (new Float(optionInfo.getCount()) / new Float(multipleChoiceQuestionReport.getCount()));
        optionInfo.setPercent(Math.round(percent * 10000) / 100);
        sumOfRates += pollingAnswerOption.getPollingOption().getWeight();
      }
    }
    //        multipleChoiceQuestionReport.setOp tionCounts(optionCounts);
    if (sumOfTotalRates != 0) {
      multipleChoiceQuestionReport.setTotalRate(sumOfRates / sumOfTotalRates);
    }
    return multipleChoiceQuestionReport;
  }
Beispiel #12
0
  public AbstractPollingTemplate findDefaultTemplateByCriteria(
      ConstantTableItem docType, ConstantTableItem gmdType, String language, boolean isDefault) {
    AbstractPollingTemplate template = null;

    if (template == null && docType != null && gmdType != null && language != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(
              docType, gmdType, language, isDefault);
    }

    if (template == null && docType != null && gmdType != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(docType, gmdType, null, isDefault);
    }

    if (template == null && docType != null && language != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(docType, null, language, isDefault);
    }

    if (template == null && docType != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(docType, null, null, isDefault);
    }

    if (template == null && gmdType != null && language != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(null, gmdType, language, isDefault);
    }

    if (template == null && gmdType != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(null, gmdType, null, isDefault);
    }

    if (template == null && language != null) {
      template =
          voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(null, null, language, isDefault);
    }

    if (template == null) {
      template = voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(null, null, null, isDefault);
    }

    return template;
  }
Beispiel #13
0
 public AbstractPollingTemplate savePollingTemplate(AbstractPollingTemplate pollingTemplate)
     throws UsedTemplateException {
   //        if (voteDao.isUsedTemplate(pollingTemplate)) {
   //            throw new UsedTemplateException("template_is_used");
   //
   //        }
   if (pollingTemplate instanceof BibliographicPollingTemplate) {
     ConstantTableItem docType = ((BibliographicPollingTemplate) pollingTemplate).getDocType();
     ConstantTableItem gmdType = ((BibliographicPollingTemplate) pollingTemplate).getGmdType();
     String language = pollingTemplate.getLanguage();
     if (pollingTemplate.isDefaultTemplate()) {
       AbstractPollingTemplate defaultTemplate =
           voteDao.findDefaultTemplateByDocTypeGmdTypeLanguage(docType, gmdType, language, true);
       if (defaultTemplate != null && !defaultTemplate.equals(pollingTemplate)) {
         defaultTemplate.setDefaultTemplate(false);
         voteDao.save(defaultTemplate);
       }
     }
   }
   if (pollingTemplate.getCreationDate() == null) {
     pollingTemplate.setCreationDate(new Date());
   }
   return (AbstractPollingTemplate) voteDao.saveByMerge(pollingTemplate);
 }
Beispiel #14
0
  private int calculateVoteTotalRate(Vote vote) {
    BibliographicPollingTemplate template =
        (BibliographicPollingTemplate) vote.getPollingTemplate();
    template =
        (BibliographicPollingTemplate)
            voteDao.getById(AbstractPollingTemplate.class, template.getId());
    List<AbstractTemplateQuestion> templateQuestions = template.getQuestionList();
    int totalWeight = 0;
    for (int i = 0; i < templateQuestions.size(); i++) {
      totalWeight += templateQuestions.get(i).getWeight();
    }
    float totalRate = 0;
    List<AbstractQuestionAnswer> questionAnswers = vote.getQuestionAnswer();
    for (int i = 0; i < questionAnswers.size(); i++) {
      int questionWeight = 0;
      int questionTotalRate = 0;
      int answerTotalRate = 0;
      AbstractQuestionAnswer questionAnswer = questionAnswers.get(i);
      questionWeight = questionAnswer.getQuestion().getWeight();
      if (questionAnswer instanceof MultipleChoiceQuestionAnswer) {
        questionTotalRate =
            calculateOptionsTotalRate(
                (MultipleChoicePollingQuestion) questionAnswer.getQuestion().getQuestion());
        answerTotalRate = 0;
        List<PollingAnswerOption> optionList =
            ((MultipleChoiceQuestionAnswer) questionAnswers.get(i)).getOptionList();
        for (int j = 0; j < optionList.size(); j++) {
          PollingAnswerOption pollingAnswerOption = optionList.get(j);
          answerTotalRate += pollingAnswerOption.getPollingOption().getWeight();
        }

      } else if (questionAnswer instanceof RatingQuestionAnswer) {
        questionTotalRate =
            ((RatingTemplateQuestion) ((RatingQuestionAnswer) questionAnswer).getQuestion())
                .getMaxValue();
        answerTotalRate = ((RatingQuestionAnswer) questionAnswer).getValue();
      }
      totalRate +=
          ((new Integer(answerTotalRate)).floatValue()
                  / (new Integer(questionTotalRate)).floatValue())
              * questionWeight;
    }
    return Math.round(((totalRate / totalWeight) * 100));
  }
Beispiel #15
0
 public List findOptions(MultipleChoicePollingQuestion pollingQuestion) {
   return voteDao.findOptions(pollingQuestion);
 }
Beispiel #16
0
 public EntityObject findById(Class persistentClass, long id) {
   return voteDao.getById(persistentClass, id);
 }
Beispiel #17
0
 public AbstractPollingTemplate findTemplateByName(String name) {
   return voteDao.findTemplateByName(name);
 }
Beispiel #18
0
 public void removeVote(Vote vote) {
   voteDao.remove(vote);
 }
Beispiel #19
0
 public void remove(EntityObject obj) throws Exception {
   voteDao.remove(obj);
 }
Beispiel #20
0
 public EntityObject save(EntityObject obj) throws Exception {
   return voteDao.save(obj);
 }
Beispiel #21
0
 /**
  * Finds all Pollings related to a polling template
  *
  * @param pollingTemplate
  * @return
  */
 public List<Vote> findAllVotesByTemplate(AbstractPollingTemplate pollingTemplate) {
   return voteDao.findAllVotesByTemplate(pollingTemplate);
 }
Beispiel #22
0
 public ResultPage findVotes(
     VoteReportFilter voteReportFilter, int firstResult, int maxResultSet, GridFilter gridFilter) {
   return voteDao.findVotes(voteReportFilter, firstResult, maxResultSet, gridFilter);
 }
Beispiel #23
0
 /**
  * persistentClass should be AbstractPollingQuestion or MultipleChoicePollingQuestion or
  * RatingPollingQuestion
  *
  * @param persistentClass
  * @param type
  * @param firstResult
  * @param maxResultSet
  * @param gridFilter
  * @return
  */
 public ResultPage findQuestionsByReportCriteria(
     PollingQuestionFilter filter, int firstResult, int maxResultSet, GridFilter gridFilter) {
   return voteDao.findQuestionsByReportCriteria(filter, firstResult, maxResultSet, gridFilter);
 }
Beispiel #24
0
 public Vote findVote(Votable record, AbstractUser user, AbstractPollingTemplate pollingTemplate) {
   return voteDao.findVote(record, user, pollingTemplate);
 }
Beispiel #25
0
 public ResultPage findQuestionsByReportCriteria(
     VoteReportFilter voteReportFilter, int firstResult, int maxResultSet, GridFilter gridFilter) {
   return voteDao.findQuestionsByReportCriteria(
       voteReportFilter, firstResult, maxResultSet, gridFilter);
 }
Beispiel #26
0
 public ResultPage findRecordsByReportCriteria(
     VoteReportFilter voteReportFilter, int first, int size, GridFilter gridFilter) {
   return voteDao.findRecordsByReportCriteria(voteReportFilter, first, size, gridFilter);
 }
Beispiel #27
0
 public boolean isEditableQuestion(AbstractPollingQuestion pollingQuestion) {
   return !voteDao.isAnsweredQuestion(pollingQuestion);
 }
Beispiel #28
0
 public Boolean hasDefaultTemplate() {
   return voteDao.hasDefaultTemplate();
 }
Beispiel #29
0
 public boolean isEditableTemplate(AbstractPollingTemplate pollingTemplate) {
   return !voteDao.isUsedTemplate(pollingTemplate);
 }
Beispiel #30
0
 public Votable findVotable(long id) {
   return voteDao.findVotable(id);
 }