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; }
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; }
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; }
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; }
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); }
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)); }
public List findOptions(MultipleChoicePollingQuestion pollingQuestion) { return voteDao.findOptions(pollingQuestion); }
public EntityObject findById(Class persistentClass, long id) { return voteDao.getById(persistentClass, id); }
public AbstractPollingTemplate findTemplateByName(String name) { return voteDao.findTemplateByName(name); }
public void removeVote(Vote vote) { voteDao.remove(vote); }
public void remove(EntityObject obj) throws Exception { voteDao.remove(obj); }
public EntityObject save(EntityObject obj) throws Exception { return voteDao.save(obj); }
/** * Finds all Pollings related to a polling template * * @param pollingTemplate * @return */ public List<Vote> findAllVotesByTemplate(AbstractPollingTemplate pollingTemplate) { return voteDao.findAllVotesByTemplate(pollingTemplate); }
public ResultPage findVotes( VoteReportFilter voteReportFilter, int firstResult, int maxResultSet, GridFilter gridFilter) { return voteDao.findVotes(voteReportFilter, firstResult, maxResultSet, gridFilter); }
/** * 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); }
public Vote findVote(Votable record, AbstractUser user, AbstractPollingTemplate pollingTemplate) { return voteDao.findVote(record, user, pollingTemplate); }
public ResultPage findQuestionsByReportCriteria( VoteReportFilter voteReportFilter, int firstResult, int maxResultSet, GridFilter gridFilter) { return voteDao.findQuestionsByReportCriteria( voteReportFilter, firstResult, maxResultSet, gridFilter); }
public ResultPage findRecordsByReportCriteria( VoteReportFilter voteReportFilter, int first, int size, GridFilter gridFilter) { return voteDao.findRecordsByReportCriteria(voteReportFilter, first, size, gridFilter); }
public boolean isEditableQuestion(AbstractPollingQuestion pollingQuestion) { return !voteDao.isAnsweredQuestion(pollingQuestion); }
public Boolean hasDefaultTemplate() { return voteDao.hasDefaultTemplate(); }
public boolean isEditableTemplate(AbstractPollingTemplate pollingTemplate) { return !voteDao.isUsedTemplate(pollingTemplate); }
public Votable findVotable(long id) { return voteDao.findVotable(id); }