/** * Create {@link TweetPollSwitch}. * * @return {@link TweetPollSwitch}. */ public TweetPollSwitch createTweetPollSwitch( final TweetPoll tweetPoll, final QuestionAnswer answer, final HttpServletRequest request) { final TweetPollSwitch tPollSwitch = new TweetPollSwitch(); tPollSwitch.setAnswers(answer); tPollSwitch.setTweetPoll(tweetPoll); // FIXME: Verfy if it these code already exist. tPollSwitch.setCodeTweet( MD5Utils.shortMD5(Calendar.getInstance().getTimeInMillis() + answer.getAnswer())); tPollSwitch.setDateUpdated(Calendar.getInstance().getTime()); // vote without domain final StringBuffer voteUrlWithoutDomain = new StringBuffer(); voteUrlWithoutDomain.append(this.TWEETPOLL_VOTE); voteUrlWithoutDomain.append(tPollSwitch.getCodeTweet()); tPollSwitch.setRelativeUrl(voteUrlWithoutDomain.toString()); final StringBuffer completeDomain = new StringBuffer(); if (request != null) { final String domain = WidgetUtil.getDomain(request); completeDomain.append(domain); } completeDomain.append(voteUrlWithoutDomain.toString()); log.debug("tweet poll answer vote :{" + voteUrlWithoutDomain.toString()); if (InternetUtils.validateUrl(completeDomain.toString())) { log.debug("createTweetPollSwitch: URL IS VALID"); // log.debug("createTweetPollSwitch: short url provider "+ answer.getProvider()); tPollSwitch.setShortUrl( WidgetUtil.createShortUrl(answer.getProvider(), completeDomain.toString())); } else { log.debug("createTweetPollSwitch: url IS NOT valid"); tPollSwitch.setShortUrl(completeDomain.toString()); log.warn("Invalid format vote url:{" + voteUrlWithoutDomain.toString()); } getTweetPollDao().saveOrUpdate(tPollSwitch); return tPollSwitch; }