Package org.encuestame.persistence.domain.survey

Examples of org.encuestame.persistence.domain.survey.Poll


      * @return
      * @throws EnMeNoResultsFoundException
      */
    public Poll getPollById(final Long pollId)
            throws EnMeNoResultsFoundException {
        final Poll poll = this.getPollDao().getPollById(pollId);
        if (poll == null) {
            throw new EnMePollNotFoundException("poll invalid with this id "
                    + pollId);
        }
        return poll;
View Full Code Here


    public String pollController(final ModelMap model, @PathVariable Long id,
            @PathVariable String slug) {
        log.trace("poll Id -->" + id);
        log.trace("poll slug -->" + slug);
        try {
            final Poll poll = getPollService().getPollSlugById(id, slug);
            // final List<QuestionAnswerBean> answer =
            // getPollService().retrieveAnswerByQuestionId(poll.getQuestion().getQid());
            final List<PollBeanResult> results = getPollService()
                    .getResultVotes(poll);
            log.trace("Poll Detail Answers " + results.size());
View Full Code Here

        // default path
        final RequestSourceType requestSourceType = RequestSourceType.getSource(type_form);
        final String isEmbedded = !requestSourceType.equals(RequestSourceType.EMBEDDED) ? "" : "embedded/";
        log.debug("isEmbedded   * " + isEmbedded);
        String pathVote = "poll/" + isEmbedded + "voted";
        Poll poll = new Poll();
        // Check IP in BlackListFile - Validation
        final String IP = getIpClient(req);
        final Boolean checkBannedIp = checkIPinBlackList(IP);
        if (checkBannedIp) {
            // if banned send to banned view.
            pathVote = "poll/ " + isEmbedded + "banned";
        } else {
            // Item id is poll id
            if (itemId == null) {
                // Exception musst be removed.
                throw new EnMePollNotFoundException("poll id has not been found");
                // if answer id is null return the request
            } else if (responseId == null) {
                //poll = getPollService().getPollById(itemId);
                poll = getPollService().getPollByAnswerId(itemId, responseId, null);
                model.addAttribute("poll", ConvertDomainBean.convertPollDomainToBean(poll));
                RequestSessionMap.getCurrent(req).put("votePollError", Boolean.TRUE);
                pathVote = "redirect:/poll/vote/" + itemId + "/" + slugName;
            } else {
                type = filterValue(type);
                type_form = filterValue(type_form);
                slugName = filterValue(slugName);
                poll = getPollService().getPollByAnswerId(itemId, responseId, null);
                // restrictions by date
                final Boolean restrictVotesByDate = getPollService().restrictVotesByDate(poll);
                // restrictions by quota
                final Boolean restrictVotesByQuota = getPollService().restrictVotesByQuota(poll);
                if (poll == null || !poll.getPublish()) {
                    log.warn("pll answer not found");
                    model.put("message", getMessage("poll.votes.bad"));
                }
                // Validate properties or options
                else if (poll.getPollCompleted()) {
                    model.put("message", getMessage("poll.completed"));
                    pathVote = "poll/" + isEmbedded + "completed";
                } else if (restrictVotesByQuota) {
                    model.put("message", getMessage("tweetpoll.votes.limited"));
                    pathVote = "poll/" + isEmbedded + "bad";
                } else if (restrictVotesByDate) {
                    model.put("message", getMessage("poll.closed"));
                    pathVote = "poll/" + isEmbedded + "bad";
                } else {
                    try {
                        model.put("pollAnswer", poll);
                        final PollResult result = getPollService().validatePollIP(IP, poll);
                        if (result == null) {
                            if (poll.getMultipleResponse().equals(AbstractSurvey.MultipleResponse.MULTIPLE)) {
                                for (int i = 0; i < multiplesVotes.length; i++) {
                                    try {
                                        final Long responseIdMultiple = Long.valueOf(multiplesVotes[i]);
                                        getPollService().vote(poll, slugName, IP, responseIdMultiple);
                                    } catch(Exception error) {
                                        log.error("error on multivote " + error.getMessage());
                                        error.printStackTrace();
                                    }
                                    model.put("message", getMessage("poll.votes.thanks"));
                                    pathVote = "poll/" + isEmbedded + "voted";
                                }
                            } else if(poll.getMultipleResponse().equals(AbstractSurvey.MultipleResponse.SINGLE)) {
                                    getPollService().vote(poll, slugName, IP,responseId);
                                    model.put("message", getMessage("poll.votes.thanks"));
                                    pathVote = "poll/" + isEmbedded + "voted";
                            }
                        } else {
View Full Code Here

    @RequestMapping(value = "/poll/vote/{id}/{slug}", method = RequestMethod.GET)
    public String pollVoteController(ModelMap model,
            HttpServletRequest request, @PathVariable Long id,
            @PathVariable String slug) {
        try {
            final Poll poll = getPollService().getPollSlugById(id, slug);
            final List<QuestionAnswerBean> answer = getPollService()
                    .retrieveAnswerByQuestionId(poll.getQuestion().getQid());
            log.debug("Poll Detail Answers " + answer.size());
            model.addAttribute("poll",
                    ConvertDomainBean.convertPollDomainToBean(poll));
            model.addAttribute("answers", answer);
        } catch (EnMeNoResultsFoundException e) {
View Full Code Here

        /* TweetPoll **/
        final TweetPoll myTweetPoll = createPublishedTweetPoll(question, userAcc);

        /* Poll **/
        final Poll myPoll = createPoll(creationDate, question, userAcc, Boolean.TRUE, Boolean.TRUE);

        /* Survey **/
        final Survey mySurvey = createDefaultSurvey(userAcc.getAccount(), "My First Encuestame Survey", creationDate);

        // 2- Add HashTag to TweetPoll, Poll or Survey
        myTweetPoll.getHashTags().add(hashtag1);
        getTweetPoll().saveOrUpdate(myTweetPoll);

        myPoll.getHashTags().add(hashtag1);
        getPollDao().saveOrUpdate(myPoll);

        mySurvey.getHashTags().add(hashtag1);
        getSurveyDaoImp().saveOrUpdate(mySurvey);

View Full Code Here

         * Test {@link SignInController}.
         * @throws Exception exception.
         */
        @Test
        public void testPollController() throws Exception {
            final Poll poll = createPoll(new Date(), createQuestion("question 1", "Si"),
                    createUserAccount("diana", createAccount()), true, true);
            //"/user/signin
            request = new MockHttpServletRequest(MethodJson.GET.toString(), "/poll/"+poll.getPollId()+"/"+poll.getQuestion().getSlugQuestion());
            final ModelAndView mav = handlerAdapter.handle(request, response,
                pollController2);
            assertViewName(mav, "poll/detail");
        }
View Full Code Here

     * (non-Javadoc)
     * @see org.encuestame.core.service.imp.IPollService#createPoll(java.lang.String, java.lang.String[], java.lang.Boolean, java.lang.String, java.lang.Boolean, java.util.List)
     */
    public Poll createPoll(final CreatePollBean createPollBean ) throws EnMeExpcetion {
        final UserAccount user = getUserAccount(getUserPrincipalUsername());
        final Poll pollDomain = new Poll();
        try {
            final QuestionBean questionBean = new QuestionBean();
            questionBean.setQuestionName(createPollBean.getQuestionName());
            final Question question = createQuestion(questionBean, user, QuestionPattern.CUSTOMIZABLE_SELECTION);
            if (question == null) {
                throw new EnMeNoResultsFoundException("Question not valid");
            } else if (createPollBean.getAnswers().length  == 0 ) {
                  throw new EnMeNoResultsFoundException("answers are required to create Poll");
            }
            else{
            final String hashPoll = MD5Utils.md5(RandomStringUtils.randomAlphanumeric(500));
            final CommentOptions commentOpt = CommentOptions.getCommentOption(createPollBean.getShowComments());
            final ShowResultsOptions showResultsOptions = ShowResultsOptions.getShowResults(createPollBean.getShowComments());
            pollDomain.setEditorOwner(user);
            pollDomain.setCreateDate(Calendar.getInstance().getTime());
            pollDomain.setPollHash(hashPoll);
            pollDomain.setQuestion(question);
            pollDomain.setPollCompleted(Boolean.FALSE);
            pollDomain.setHits(EnMeUtils.HIT_DEFAULT);
            pollDomain.setRelevance(EnMeUtils.RATE_DEFAULT);
            pollDomain.setLikeVote(EnMeUtils.LIKE_DEFAULT);
            pollDomain.setDislikeVote(EnMeUtils.DISLIKE_DEFAULT);
            pollDomain.setNumbervotes(EnMeUtils.VOTE_MIN);
            pollDomain.setEditorOwner(user);
            pollDomain.setOwner(user.getAccount());
            // Type of results display
            pollDomain.setShowResults(showResultsOptions);
            // Comments restrictions
            pollDomain.setShowComments(commentOpt);
            pollDomain.setPublish(Boolean.TRUE);
            // multiple votes enabled or not
            if (createPollBean.getMultiple()) {
              pollDomain.setMultipleResponse(org.encuestame.persistence.domain.AbstractSurvey.MultipleResponse.MULTIPLE);
            } else {
              pollDomain.setMultipleResponse(org.encuestame.persistence.domain.AbstractSurvey.MultipleResponse.SINGLE);
            }
            // set limit of votes by user
            if (createPollBean.getLimitVote() != null) {
              pollDomain.setNumbervotes(createPollBean.getLimitVote());
            }
            // define the closed date
            if (createPollBean.getCloseDate() != null) {
              final Date closedDate = new Date(createPollBean.getCloseDate());
              pollDomain.setClosedDate(closedDate);
            }
            // notifications enabled by default
            pollDomain.setNotifications(Boolean.TRUE);
            // published on create the poll
            pollDomain.setPublish(Boolean.TRUE);
            final List<HashTagBean> hashtags = EnMeUtils.createHashTagBeansList(createPollBean.hashtags);
            if (hashtags.size() > 0) {
                //http://issues.encuestame.org/browse/ENCUESTAME-504
                pollDomain.getHashTags().addAll(retrieveListOfHashTags(hashtags));
            }
            // Add answers
            this.createQuestionAnswers(createPollBean.getAnswers(), question);
            this.getPollDao().saveOrUpdate(pollDomain);

View Full Code Here

        if (searchResult.equals(TypeSearchResult.TWEETPOLL)) {
            final TweetPoll tweetPoll = getTweetPollService().getTweetPollPublishedById(
                    itemId);
             comments.addAll(this.getCommentsbyTweetPoll(tweetPoll, max, start));
        } else if (searchResult.equals(TypeSearchResult.POLL)) {
            final Poll poll = getPollService().getPollById(itemId);
            comments.addAll(getCommentsOperations().getCommentsbPoll(poll, max, start));
        } else if (searchResult.equals(TypeSearchResult.SURVEY)) {
            final Survey survey = null;
            //TODO:
        } else {
View Full Code Here

        if (TypeSearchResult.TWEETPOLL.equals(commentBean.getType())) {
            final TweetPoll tweetPoll = getTweetPollById(commentBean.getId());
            comment.setTweetPoll(tweetPoll);
            comment.setCommentOptions(tweetPoll.getShowComments() == null ? CommentOptions.PUBLISHED : tweetPoll.getShowComments());
        } else if (TypeSearchResult.POLL.equals(commentBean.getType())) {
            final Poll poll = getPollById(commentBean.getId());
            comment.setPoll(poll);
            comment.setCommentOptions(poll.getShowComments()  == null ? CommentOptions.PUBLISHED : poll.getShowComments());
        } else if (TypeSearchResult.SURVEY.equals(commentBean.getType())) {
            //TODO: survey get imp
          //comment.setPoll(poll);
            //comment.setCommentOptions(poll.getShowComments());
        } else {
View Full Code Here

    if(itemType.equals(TypeSearchResult.TWEETPOLL)){
      final TweetPoll tpoll = this.getTweetPollById(id);
      totalComments = getCommentsOperations().getTotalCommentsbyItem(tpoll.getTweetPollId(), itemType, commentOptions, period);
    }
    else if(itemType.equals(TypeSearchResult.POLL)){
      final Poll poll = this.getPollById(id);
      totalComments = getCommentsOperations().getTotalCommentsbyItem(poll.getPollId(), itemType, commentOptions, period);

    }
    else if(itemType.equals(TypeSearchResult.SURVEY)){
      //
    }
View Full Code Here

TOP

Related Classes of org.encuestame.persistence.domain.survey.Poll

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.