r3117 - branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services
Author: tchemit Date: 2012-01-24 15:15:29 +0100 (Tue, 24 Jan 2012) New Revision: 3117 Url: http://chorem.org/repositories/revision/pollen/3117 Log: split PolleService into PollCommentService Added: branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollCommentService.java Modified: branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollService.java Added: branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollCommentService.java =================================================================== --- branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollCommentService.java (rev 0) +++ branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollCommentService.java 2012-01-24 14:15:29 UTC (rev 3117) @@ -0,0 +1,96 @@ +/* + * #%L + * Pollen :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.services; + +import org.chorem.pollen.PollenDAOHelper; +import org.chorem.pollen.PollenTechnicalException; +import org.chorem.pollen.entity.Comment; +import org.chorem.pollen.entity.CommentDAO; +import org.chorem.pollen.entity.CommentImpl; +import org.chorem.pollen.entity.Poll; +import org.chorem.pollen.entity.PollAccount; +import org.chorem.pollen.entity.PollDAO; +import org.nuiton.topia.TopiaException; + +/** + * Manage comments on a poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollCommentService extends PollenServiceSupport { + + public int getNbComments(Poll poll) { + try { + PollDAO dao = PollenDAOHelper.getPollDAO(getTransaction()); + + Poll pollFound = dao.findByTopiaId(poll.getTopiaId()); + + int result = pollFound.sizeComment(); + return result; + } catch (TopiaException e) { + throw new PollenTechnicalException(e); + } + } + + public Comment createComment(Poll poll, Comment comment) { + try { + CommentDAO dao = PollenDAOHelper.getCommentDAO(getTransaction()); + + Comment commentCreated = dao.create( + Comment.PROPERTY_AUTHOR, comment.getAuthor(), + Comment.PROPERTY_COMMENT_DATE, serviceContext.getCurrentTime(), + Comment.PROPERTY_TEXT, comment.getText() + ); + + PollDAO pollDAO = PollenDAOHelper.getPollDAO(getTransaction()); + + Poll pollToUpdate = pollDAO.findByTopiaId(poll.getTopiaId()); + + pollToUpdate.addComment(commentCreated); + + pollDAO.update(pollToUpdate); + return commentCreated; + } catch (TopiaException e) { + throw new PollenTechnicalException(e); + } + } + + public void deleteComment(Comment comment) { + try { + CommentDAO dao = PollenDAOHelper.getCommentDAO(getTransaction()); + dao.delete(comment); + } catch (TopiaException e) { + throw new PollenTechnicalException(e); + } + } + + public Comment getNewComment(PollAccount account) { + Comment result = new CommentImpl(); + if (account != null) { + result.setAuthor(account.getName()); + } + return result; + } +} Property changes on: branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollCommentService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollService.java =================================================================== --- branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollService.java 2012-01-24 14:15:07 UTC (rev 3116) +++ branches/pollen-2.0-beta-1/pollen-services/src/main/java/org/chorem/pollen/services/PollService.java 2012-01-24 14:15:29 UTC (rev 3117) @@ -40,7 +40,6 @@ import org.chorem.pollen.entity.ChoiceImpl; import org.chorem.pollen.entity.Comment; import org.chorem.pollen.entity.CommentDAO; -import org.chorem.pollen.entity.CommentImpl; import org.chorem.pollen.entity.Participant; import org.chorem.pollen.entity.ParticipantList; import org.chorem.pollen.entity.Poll; @@ -71,11 +70,6 @@ /** Logger. */ private static final Log log = LogFactory.getLog(PollService.class); - public Poll getNewPoll() { - Poll result = new PollImpl(); - return result; - } - /** * Build a new Poll instance with given {@code user} as administrator * @@ -83,7 +77,7 @@ * @return Build a new Poll instance with given {@code user} as administrator */ public Poll getNewPoll(UserAccount user) { - Poll result = getNewPoll(); + Poll result = new PollImpl(); result.setChoiceType(ChoiceType.TEXT); result.setVoteCounting(VoteCountingType.NORMAL); result.setType(PollType.FREE); @@ -110,7 +104,7 @@ * @return Build a new Poll instance based on existing {@code poll} (copy) */ public Poll getNewPoll(Poll poll) { - Poll result = getNewPoll(); + Poll result = new PollImpl(); TopiaEntityBinder<Poll> binder = PollenBinderHelper.getSimpleTopiaBinder(Poll.class); //TODO-fdesbois-2010-07-13 : add test and check if exluding only those properties is realistic binder.copyExcluding(poll, result, @@ -433,61 +427,6 @@ } } - public int getNbComments(Poll poll) { - try { - PollDAO dao = PollenDAOHelper.getPollDAO(getTransaction()); - - Poll pollFound = dao.findByTopiaId(poll.getTopiaId()); - - int result = pollFound.sizeComment(); - return result; - } catch (TopiaException e) { - throw new PollenTechnicalException(e); - } - } - - public Comment createComment(Poll poll, Comment comment) { - try { - CommentDAO dao = PollenDAOHelper.getCommentDAO(getTransaction()); - - Comment commentCreated = dao.create( - Comment.PROPERTY_AUTHOR, comment.getAuthor(), - Comment.PROPERTY_COMMENT_DATE, serviceContext.getCurrentTime(), - Comment.PROPERTY_TEXT, comment.getText() - ); - - PollDAO pollDAO = PollenDAOHelper.getPollDAO(getTransaction()); - - Poll pollToUpdate = pollDAO.findByTopiaId(poll.getTopiaId()); - - pollToUpdate.addComment(commentCreated); - - pollDAO.update(pollToUpdate); - return commentCreated; - } catch (TopiaException e) { - throw new PollenTechnicalException(e); - } - } - - //FIXME tchemit-20120123 Why returning true ? - public boolean deleteComment(Comment comment) { - try { - CommentDAO dao = PollenDAOHelper.getCommentDAO(getTransaction()); - dao.delete(comment); - return true; - } catch (TopiaException e) { - throw new PollenTechnicalException(e); - } - } - - public Comment getNewComment(PollAccount account) { - Comment result = new CommentImpl(); - if (account != null) { - result.setAuthor(account.getName()); - } - return result; - } - public Choice createChoice(Poll poll, Choice choice) { try { ChoiceDAO dao = PollenDAOHelper.getChoiceDAO(getTransaction());
participants (1)
-
tchemit@users.chorem.org