* @param commentDomain
* @return
*/
public static final CommentBean convertCommentDomainToBean(
final Comment commentDomain) {
final CommentBean commentBean = new CommentBean();
Assert.assertNotNull(commentDomain);
commentBean.setCommentId(commentDomain.getCommentId());
commentBean.setComment(commentDomain.getComment());
commentBean.setCreatedAt(commentDomain.getCreatedAt());
commentBean
.setDislikeVote(commentDomain.getDislikeVote() == null ? EnMeUtils.VOTE_MIN
: commentDomain.getDislikeVote());
commentBean
.setLikeVote(commentDomain.getLikeVote() == null ? EnMeUtils.VOTE_MIN
: commentDomain.getLikeVote());
long id = 0;
boolean set = false;
String slug = "";
/*
* is possible refactor this part? ..
*/
TypeSearchResult type = null;
if (commentDomain.getPoll() != null && !set) {
type = TypeSearchResult.POLL;
id = commentDomain.getPoll().getPollId();
commentBean.setType(TypeSearchResult.POLL);
set = true;
slug = commentDomain.getPoll().getQuestion().getSlugQuestion();
}
if (commentDomain.getTweetPoll() != null && !set) {
type = TypeSearchResult.TWEETPOLL;
id = commentDomain.getTweetPoll().getTweetPollId();
commentBean.setType(TypeSearchResult.TWEETPOLL);
set = true;
slug = commentDomain.getTweetPoll().getQuestion().getSlugQuestion();
}
if (commentDomain.getSurvey() != null && !set) {
type = TypeSearchResult.SURVEY;
id = commentDomain.getSurvey().getSid();
commentBean.setType(TypeSearchResult.SURVEY);
set = true;
// slug =
// commentDomain.getTweetPoll().getQuestion().getSlugQuestion();
}
commentBean.setId(id);
commentBean.setParentId(commentDomain.getParentId() == null ? null
: commentDomain.getParentId());
commentBean.setUserAccountId(commentDomain.getUser() == null ? null
: commentDomain.getUser().getUid());
commentBean.setCommentedBy(commentDomain.getUser().getCompleteName());
commentBean.setCommentedByUsername(commentDomain.getUser()
.getUsername());
commentBean.setStatus(commentDomain.getCommentOptions());
// url
// tweetpoll/4/do-you-like-summer-season%3F
if (type != null) {
final StringBuffer url = new StringBuffer("/");
url.append(TypeSearchResult.getUrlPrefix(type));
url.append("/");
url.append(id);
url.append("/");
url.append(slug);
url.append("/#comment");
url.append(commentDomain.getCommentId());
commentBean.setCommentUrl(url.toString());
}
return commentBean;
}