/*
* (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);