*/
final TweetPollBean tweetPollBean = new TweetPollBean();
//tweetPollBean.getHashTags().addAll();
// save create tweet poll
double randomUser = RandomUtils.nextInt(totalUsers);
UserAccount u = userAccount.get(Double.valueOf(randomUser).intValue());
SecurityUtils.authenticate(u);
tweetPollBean.setUserId(u.getAccount().getUid());
tweetPollBean.setCloseNotification(Boolean.FALSE);
tweetPollBean.setResultNotification(Boolean.FALSE);
// all published by default
tweetPollBean.setPublishPoll(Boolean.TRUE);
// publish aleatory a publish poll.
// int publish = RandomUtils.nextInt(10);
// if (publish <= 7) {
// tweetPollBean.setPublishPoll(Boolean.TRUE); // always TRUE
// }
// no scheduled tp in the demo data
tweetPollBean.setSchedule(Boolean.FALSE);
try {
//final Question qm = createQuestion(question, u, QuestionPattern.CUSTOMIZABLE_SELECTION);
final TweetPoll tweetPollDomain = getTweetPollService().createTweetPoll(tweetPollBean, question.getQuestionName(), u, null);
//force to be published
tweetPollDomain.setPublishTweetPoll(true);
getTweetPollDao().saveOrUpdate(tweetPollDomain);
double hits = getRandomNumberRange(2, EnMePlaceHolderConfigurer
.getIntegerProperty("demo.max.tweetpoll.hits"));
for (int i = 0; i < hits; i++) {
getFrontEndService().registerHit(tweetPollDomain, null, null, null, EnMeUtils.ipGenerator(), HitCategory.VISIT);
}
double votes = getRandomNumberRange(10, EnMePlaceHolderConfigurer
.getIntegerProperty("demo.max.tweetpoll.votes"));
for (int i = 0; i < votes; i++) {
getFrontEndService().registerVote(tweetPollDomain.getTweetPollId(), TypeSearchResult.TWEETPOLL, EnMeUtils.ipGenerator());
}
//TODO: make sense?
//tpx.setHits(Long.valueOf(getRandomNumberRange(6, 5000)));
//tpx.setNumbervotes(Long.valueOf(getRandomNumberRange(40, 10000)));
tweetPollDomain.setPublishTweetPoll(true);
Date tweetPollRandomDate = createRandomDate();
tweetPollDomain.setCreateDate(tweetPollRandomDate);
tweetPollDomain.setUpdatedDate(tweetPollRandomDate);
getTweetPollDao().saveOrUpdate(tweetPollDomain);
for (int i = 0; i < EnMePlaceHolderConfigurer
.getIntegerProperty("demo.max.tweetpoll.folder"); i++) {
log.debug("Creating folder name ....");
getTweetPollService().createTweetPollFolder(this.DEFAULT_FOLDER_NAME+"_"+i+"_", u.getUsername());
}
log.debug("New tweetpoll "+tweetPollDomain.getTweetPollId());
for (CommentBean commentBean2 : comments) {
log.debug("New COMMENT tweetpoll ");
final Comment comment = new Comment();
comment.setTweetPoll(tweetPollDomain);
comment.setCreatedAt(createRandomDate());
comment.setComment(commentBean2.getComment());
comment.setDislikeVote(Long.valueOf(getRandomNumberRange(EnMePlaceHolderConfigurer
.getIntegerProperty("demo.min.comments.unlikes"), EnMePlaceHolderConfigurer
.getIntegerProperty("demo.max.comments.unlikes"))));
comment.setLikeVote(Long.valueOf(getRandomNumberRange(EnMePlaceHolderConfigurer
.getIntegerProperty("demo.min.comments.likes"), EnMePlaceHolderConfigurer
.getIntegerProperty("demo.max.comments.likes"))));
comment.setUser(userAccount.get(Double.valueOf(getRandomNumberRange(0, totalUsers) - 1).intValue()));
getTweetPollDao().saveOrUpdate(comment);
log.debug("Saved COMMENT tweetpoll ");
}
log.debug("Add hashtag to tweetpoll ");
for (int i = 0; i < EnMePlaceHolderConfigurer
.getIntegerProperty("demo.hashtab.by.item"); i++) {
double htx = getRandomNumberRange(0, totalhashtagss) - 1;
final HashTagBean b = hashtags.get(Double.valueOf(htx).intValue());
log.debug("Adding Hashtag "+b.getHashTagName()+ " to tp "+tweetPollDomain.getTweetPollId());
final HashTag h = getTweetPollService().addHashtagToTweetPoll(tweetPollDomain, b);
h.setUpdatedDate(createRandomDate());
getTweetPollDao().saveOrUpdate(h);
}
List<QuestionAnswerBean> listOfAnswers = question.getListAnswers();
log.debug("Ansswers in this questions "+listOfAnswers.size());
for (QuestionAnswerBean questionAnswerBean : listOfAnswers) {
final QuestionAnswerBean answerBean = new QuestionAnswerBean(questionAnswerBean.getAnswers());
answerBean.setShortUrlType(ShortUrlProvider.NONE);
//create tweetpoll swithch
final TweetPollSwitch tweetPollSwitch = getTweetPollService().createTweetPollQuestionAnswer(answerBean, tweetPollDomain, null);
double totalVotes = getRandomNumberRange(0, EnMePlaceHolderConfigurer.getIntegerProperty("demo.votes.by.tppoll")) - 1;
log.debug(totalVotes+" Votes for this tweetpolls switch id "+tweetPollSwitch.getSwitchId());
for (int i = 0; i < totalVotes; i++) {
getTweetPollService().tweetPollVote(tweetPollSwitch, EnMeUtils.ipGenerator(), createRandomDate());
}
//social links.
//final List<SocialAccountBean> eeeee = getSecurity().getValidSocialAccounts(SocialProvider.TWITTER, true);
final List<SocialAccount>eeee = getAccountDao().getSocialVerifiedAccountByUserAccount(u.getAccount(), SocialProvider.TWITTER);
for (SocialAccount socialAccountBean : eeee) {
for (int i = 0; i < EnMePlaceHolderConfigurer
.getIntegerProperty("demo.max.tweetpoll.social.network.published"); i++) {
String tweetId = RandomStringUtils.random(6);
final TweetPollSavedPublishedStatus publishedStatus = new TweetPollSavedPublishedStatus();
//social provider.
publishedStatus.setApiType(SocialProvider.TWITTER);
publishedStatus.setSocialAccount(socialAccountBean);
//adding tweetpoll
publishedStatus.setTweetPoll(tweetPollDomain);
//store original tweet id.
publishedStatus.setTweetId(tweetId);
//store original publication date.
publishedStatus.setPublicationDateTweet(createRandomDate());
//success publish state..
publishedStatus.setStatus(Status.SUCCESS);
//store original tweet content.
publishedStatus.setTweetContent(question.getQuestionName());
getTweetPollDao().saveOrUpdate(publishedStatus);
//create notification
//createNotification(NotificationEnum.TWEETPOLL_PUBLISHED, "tweet published", socialAccount.getAccount());
createNotification(NotificationEnum.SOCIAL_MESSAGE_PUBLISHED, question.getQuestionName(), SocialUtils.getSocialTweetPublishedUrl(
tweetId, u.getUsername(), socialAccountBean.getAccounType()), Boolean.TRUE);
}
}
}
} catch (EnMeExpcetion e) {