final int max_results = 1;
try {
@SuppressWarnings("rawtypes")
final Map model = new HashMap();
final TypeSearchResult typeItem = TypeSearchResult.getTypeSearchResult(type);
final JavascriptEmbebedBody embebedBody = new JavascriptEmbebedBody();
final ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
final String domain = WidgetUtil.getDomain(request, true);
final String logo = EnMePlaceHolderConfigurer.getProperty("application.logo.icon");
model.put("logo_enme", domain + "/resources/" + logo);
model.put("domain", domain);
model.put("typeItem", typeItem.toString().toLowerCase());
model.put("itemId", pollId);
model.put("domain_config", domain);
response.setContentType("text/javascript; charset=UTF-8");
if (TypeSearchResult.TWEETPOLL.equals(typeItem)) {
// generate tweetpoll body
// generate tweetpoll body
final TweetPoll tweetPoll = getTweetPollService().getTweetPollById(pollId);
model.put("tp", tweetPoll);
model.put("editorOwner", tweetPoll.getEditorOwner());
model.put("votes", tweetPoll.getLikeVote());
model.put("hits", tweetPoll.getHits());
model.put("date_published", EnMeUtils.formatDate(tweetPoll.getCreateDate(), "HH:mm - d MMMM yyyy"));
model.put("owner_picture", domain + "/picture/profile/" + tweetPoll.getEditorOwner().getUsername() + "/thumbnail");
model.put("owner_profile_url", domain + "/profile/" + tweetPoll.getEditorOwner().getUsername());
StringBuffer buffer = new StringBuffer();
String q = tweetPoll.getQuestion().getQuestion();
final List<TweetPollSwitch> answers = getTweetPollService().getTweetPollSwitch(tweetPoll);
final Set<HashTag> hashTags = tweetPoll.getHashTags();
buffer.append(EnMeUtils.generateBodyTweetPollasHtml(domain, tweetPoll, q,answers, hashTags));
model.put("body_text", buffer.toString());
model.put("url_tpoll", domain +
"/tweetpoll/" + tweetPoll.getTweetPollId() + "/" + tweetPoll.getQuestion().getSlugQuestion());
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, HTML_TEMPLATES + "/tweetpoll_form.vm", "utf-8", model);
} else if (TypeSearchResult.TWEETPOLLRESULT.equals(typeItem)) {
final TweetPoll tpoll = getTweetPollService().getTweetPollById(pollId);
final TweetPollDetailBean tpollDetail = getTweetPollService().getTweetPollDetailInfo(pollId);
model.put("owner_picture", domain + "/picture/profile/" + tpoll.getEditorOwner().getUsername() + "/thumbnail");
model.put("editorOwner", tpoll.getEditorOwner());
model.put("question", tpoll.getQuestion());
model.put("url", EnMeUtils.createTweetPollUrlAccess(domain, tpoll));
model.put("answersList", tpollDetail.getResults());
model.put("date_published", EnMeUtils.formatDate(tpoll.getCreateDate(), "HH:mm - d MMMM yyyy"));
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, HTML_TEMPLATES + "/tweetpoll_votes.vm", "utf-8", model);
embebedBody.setAditionalInfo(tpollDetail.getResults());
} else if (TypeSearchResult.POLL.equals(typeItem)) {
// generate poll body
final Poll poll = getPollService().getPollById(pollId);
final PollDetailBean detailBean = getPollService().getPollDetailInfo(poll.getPollId());
model.put("owner_picture", domain + "/picture/profile/" + poll.getEditorOwner().getUsername() + "/thumbnail");
model.put("editorOwner", poll.getEditorOwner());
model.put("title", poll.getQuestion().getQuestion());
model.put("date_published", EnMeUtils.formatDate(poll.getCreateDate(), "HH:mm - d MMMM yyyy"));
model.put("poll", poll);
model.put("action", WidgetUtil.getDomain(request) + "/poll/vote/post");
model.put("detailBean", detailBean);
model.put("vote_title", "Vote");
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, HTML_TEMPLATES + "/poll_form.vm", "utf-8", model);
} else if (TypeSearchResult.POLLRESULT.equals(typeItem)) {
// generate poll body
final Poll poll = getPollService().getPollById(pollId);
final PollDetailBean detailBean = getPollService().getPollDetailInfo(poll.getPollId());
model.put("owner_picture", domain + "/picture/profile/" + poll.getEditorOwner().getUsername() + "/thumbnail");
model.put("editorOwner", poll.getEditorOwner());
model.put("question", poll.getQuestion());
model.put("url", EnMeUtils.createUrlPollAccess(domain, poll));
model.put("answersList", detailBean.getResults());
model.put("date_published", EnMeUtils.formatDate(poll.getCreateDate(), "HH:mm - d MMMM yyyy"));
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, HTML_TEMPLATES + "/tweetpoll_votes.vm", "utf-8", model);
embebedBody.setAditionalInfo(detailBean.getResults());
} else if (TypeSearchResult.HASHTAG.equals(typeItem)) {
// generate hashtag body
model.put("hellow", "world");
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, HTML_TEMPLATES + "/hashtag.vm", "utf-8", model);
} else if (TypeSearchResult.PROFILE.equals(typeItem)) {
final UserAccount user = getSecurityService().getUserbyId(pollId);
model.put("owner_picture", domain + "/picture/profile/" + user.getUsername() + "/thumbnail");
model.put("editorOwner", user);
model.put("profile", user.getUsername());
model.put("owner_profile_url", domain + "/profile/" + user.getUsername());
model.put("picture", getPictureService().getProfilePicture(user.getUsername(), PictureType.DEFAULT));
model.put("total_tweets", getFrontService().getTotalItemsPublishedByType(user, Boolean.TRUE, TypeSearchResult.TWEETPOLL));
model.put("total_poll", getFrontService().getTotalItemsPublishedByType(user, Boolean.TRUE, TypeSearchResult.POLL));
model.put("total_survey", getFrontService().getTotalItemsPublishedByType(user, Boolean.TRUE, TypeSearchResult.SURVEY));
final List<HomeBean> lastPublication = getFrontService().getLastItemsPublishedFromUserAccount(
user.getUsername(),
max_results,
Boolean.FALSE,
request);
if (lastPublication.size() >= 1) {
model.put("last_publication", lastPublication.get(0));
}
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, HTML_TEMPLATES + "/profile.vm", "utf-8", model);
}
final String string = new String(text.getBytes("UTF-8"));
embebedBody.setBody(string);
final String json = ow.writeValueAsString(embebedBody);
out.print(callback + "(" + json + ")");
} catch (Exception e) {
e.printStackTrace();
out.print(callback + "(" + Boolean.FALSE + ")");