r3416 - in trunk: pollen-persistence pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-persistence/src/main/java/org/chorem/pollen/entities/migration pollen-persistence/src/main/xmi pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-services/src/main/resources/i18n pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/adm
Author: tchemit Date: 2012-06-03 17:40:54 +0200 (Sun, 03 Jun 2012) New Revision: 3416 Url: http://chorem.org/repositories/revision/pollen/3416 Log: - les services sont tous disponibles au niveau de chaque action - checkup que tous les commits sont bien fait au niveau services et pas dans les actions - suppression dans le mod?\195?\168le de certaines bi-directions (il en reste encore un peu... mais j'ai plus le courage :() - fixes #579: Poll creator acts as a admin for his poll - fixes #575: Impossible de supprimer un vote pour le cr?\195?\169ateur du sondage - fixes #135: [Vote] D?\195?\169pouillement effectu?\195?\169 ?\195?\160 chaque chargement de la page des votes Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java Modified: trunk/pollen-persistence/pom.xml trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java trunk/pollen-persistence/src/main/xmi/pollen.zargo trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/GetPollImageChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Login.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/LostPassword.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp Modified: trunk/pollen-persistence/pom.xml =================================================================== --- trunk/pollen-persistence/pom.xml 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-persistence/pom.xml 2012-06-03 15:40:54 UTC (rev 3416) @@ -95,8 +95,7 @@ <defaultPackage>org.chorem.pollen.entities</defaultPackage> <templates> org.nuiton.topia.generator.TopiaMetaTransformer, - org.nuiton.topia.generator.BinderHelperTransformer, - org.nuiton.topia.generator.QueryHelperTransformer + org.nuiton.topia.generator.BinderHelperTransformer </templates> </configuration> <goals> Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -39,8 +39,9 @@ Preconditions.checkNotNull(pollId); TopiaQuery countQuery = createQuery("e"). - addWhere("e." + Comment.PROPERTY_POLL + ".pollId", - TopiaQuery.Op.EQ, pollId); + addFrom(Poll.class, "p"). + addWhere("p." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId). + addWhere("e in elements(p." + Poll.PROPERTY_COMMENT + ")"); long records = countByQuery(countQuery); pager.setRecords((int) records); @@ -56,8 +57,9 @@ Preconditions.checkNotNull(pollId); TopiaQuery query = createQuery("e"). - addWhere("e." + Comment.PROPERTY_POLL + ".pollId", - TopiaQuery.Op.EQ, pollId); + addFrom(Poll.class, "p"). + addWhere("p." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId). + addWhere("e in elements(p." + Poll.PROPERTY_COMMENT + ")"); query.addOrderDesc(Comment.PROPERTY_POST_DATE); List<E> result = findAllByQuery(query); return result; Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -106,7 +106,9 @@ VoteDAO voteDao = PollenDAOHelper.getVoteDAO(context); TopiaQuery query = voteDao.createQuery("e"). - setSelect("e." + Vote.PROPERTY_POLL, "e." + Vote.PROPERTY_POLL_ACCOUNT). + addFrom(Poll.class, "p"). + addWhere("e in elements(p." + Poll.PROPERTY_VOTE + ")"). + setSelect("p", "e." + Vote.PROPERTY_POLL_ACCOUNT). addWhere("e." + Vote.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, userToUse); Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -66,62 +66,38 @@ // Order the results by creation date (the last vote done will be // at the end of the list) TopiaQuery query = createQuery("e"). - addWhere("e.poll", TopiaQuery.Op.EQ, poll). + addFrom(Poll.class, "p"). + addWhere("p", TopiaQuery.Op.EQ, poll). + addWhere("e in elements (p." + Poll.PROPERTY_VOTE + ")"). addOrder("topiaCreateDate"); TopiaFilterPagerUtil.addPagerToQuery(query, pager); results = findAllByQuery(query); - -// -// List<E> votes = find( -// "FROM " + Vote.class.getName() + -// " WHERE poll.pollId = :pollUId" + -// " ORDER BY topiaCreateDate", -// startIndex, endIndex, -// new Object[]{"pollUId", poll.getPollId()}); - -// if (log.isDebugEnabled()) { -// log.debug("Nb votes found : " + votes.size()); -// } -// -// results = Lists.newArrayList(results); } return results; } - public boolean hasAlreadyVoted(String votingId, Poll poll) throws TopiaException { + public boolean hasAlreadyVoted(Poll poll, String votingId) throws TopiaException { // Test using a count(*) on votes TopiaQuery query = createQuery("e"). - addWhere("e.poll", TopiaQuery.Op.EQ, poll). + addFrom(Poll.class, "p"). + addWhere("p", TopiaQuery.Op.EQ, poll). + addWhere("e in elements(p." + Poll.PROPERTY_VOTE + ")"). addWhere("e.pollAccount.votingId", TopiaQuery.Op.EQ, votingId). addOrder("topiaCreateDate"); boolean result = existByQuery(query); return result; -// List<Long> tmp = transaction.find( -// "SELECT COUNT(*)" + -// " FROM " + Vote.class.getName() + -// " WHERE poll.pollId = :pollUId" + -// " AND pollAccount.votingId = :votingId", -// "pollUId", poll.getPollId(), -// "votingId", votingId); -// -// int count = tmp.get(0).intValue(); -// -// // If the count is greater than 0, there is an existing votingId -// // who has already voted for the poll -// result = count > 0; - } - + public Vote findByAccountId(String accountId) throws TopiaException { - - String accountIdProperty = + + String accountIdProperty = TopiaQuery.getProperty("e", Vote.PROPERTY_POLL_ACCOUNT, PollAccount.PROPERTY_ACCOUNT_ID); TopiaQuery query = createQuery("e").addEquals(accountIdProperty, accountId); Vote result = findByQuery(query); return result; } - - + + } //VoteDAOImpl<E extends Vote> Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -23,6 +23,7 @@ */ package org.chorem.pollen.entities.migration; +import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.business.persistence.VoteToChoiceImpl; import org.nuiton.topia.TopiaException; @@ -61,8 +62,17 @@ // see http://chorem.org/issues/574 // see http://chorem.org/issues/576 removeAllCondorcetNullVotes(tx, queries); + + // add a flag to not generate results each time (http://chorem.org/issues/135) + addResultUptodateToPoll(queries); } + private void addResultUptodateToPoll(List<String> queries) { + queries.add("ALTER TABLE poll ADD COLUMN " + + Poll.PROPERTY_RESULT_UPTODATE + " boolean default false;"); + + } + private void removeAllCondorcetNullVotes(TopiaContextImplementor tx, List<String> queries) throws TopiaException { Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -29,6 +29,7 @@ import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PreventRule; import org.chorem.pollen.services.impl.PollService; +import org.chorem.pollen.services.impl.PollUrlService; import org.chorem.pollen.services.impl.PreventRuleService; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -80,6 +81,8 @@ try { serviceContext.setTransaction(transaction); + PollUrlService pollUrlService = + serviceContext.newService(PollUrlService.class); PollService pollService = serviceContext.newService(PollService.class); PreventRuleService preventRuleService = @@ -90,7 +93,8 @@ for (Poll poll : polls) { - PollUrl pollVoteUrl = pollService.getPollVoteUrl(poll, false); + PollUrl pollVoteUrl = + pollUrlService.getPollVoteUrl(poll, false); preventRuleService.onPollToRemind(poll, pollVoteUrl); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -27,15 +27,19 @@ import com.google.common.collect.Lists; import org.chorem.pollen.bean.PollDateChoice; import org.chorem.pollen.bean.PollImageChoice; +import org.chorem.pollen.bean.PollResult; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.ChoiceImpl; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.PersonToListImpl; +import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.PollAccountImpl; +import org.chorem.pollen.business.persistence.Result; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListImpl; import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.votecounting.business.NumberMethod; import org.nuiton.topia.persistence.TopiaEntity; import java.util.Date; @@ -223,4 +227,26 @@ return result; } } + + public static Function<Result, PollResult> newResultToBeanFunction(final Poll poll) { + return new Function<Result, PollResult>() { + + @Override + public PollResult apply(Result res) { + PollResult dto = new PollResult(); + dto.setId(res.getTopiaId()); + dto.setPollId(poll.getPollId()); + String resName = res.getName(); + dto.setName(resName); + dto.setHidden(resName != null && + resName.startsWith(NumberMethod.HIDDEN_PREFIX)); + dto.setValue(res.getResultValue()); + dto.setByGroup(res.isByGroup()); + dto.setChoiceType(poll.getChoiceType()); + dto.setVoteCountingType(poll.getVoteCountingType()); + return dto; + } + }; + } + } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,8 +25,6 @@ import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.pollen.PollenTechnicalException; import org.chorem.pollen.business.persistence.PersonList; import org.chorem.pollen.business.persistence.PersonListDAO; @@ -49,9 +47,6 @@ public class FavoriteService extends PollenServiceSupport { - /** Logger. */ - private static final Log log = LogFactory.getLog(FavoriteService.class); - public List<PersonList> getFavoriteLists(UserAccount user, TopiaFilterPagerUtil.FilterPagerBean pager) { @@ -198,6 +193,8 @@ } dao.delete(favoriteListToDelete); + + commitTransaction("Could not delete favorite list"); return favoriteListToDelete; } catch (TopiaException e) { @@ -245,6 +242,7 @@ pollAccountCreated.setEmail(pollAccount.getEmail()); personListToUpdate.addPollAccount(pollAccountCreated); + commitTransaction("Could not add poll account to favorite list"); } catch (TopiaException e) { throw new PollenTechnicalException(e); } @@ -291,6 +289,7 @@ pollAccountToUpdate.setVotingId(pollAccount.getVotingId()); pollAccountToUpdate.setEmail(pollAccount.getEmail()); + commitTransaction("Could not edit poll account favorite list"); } catch (TopiaException e) { throw new PollenTechnicalException(e); @@ -333,6 +332,7 @@ personListToUpdate.removePollAccount(pollAccountToRemove); + commitTransaction("Could not remove pollaccount to favorite list"); } catch (TopiaException e) { throw new PollenTechnicalException(e); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.PollenTechnicalException; -import org.chorem.pollen.bean.PollUrl; import org.chorem.pollen.business.persistence.Comment; import org.chorem.pollen.business.persistence.CommentDAO; import org.chorem.pollen.business.persistence.Poll; @@ -47,6 +46,14 @@ */ public class PollCommentService extends PollenServiceSupport { + public Comment getExistingPollComment(String commentId) throws PollCommentNotFound { + Comment result = getEntityById(Comment.class, commentId); + if (result == null) { + throw new PollCommentNotFound(); + } + return result; + } + public Comment createComment(Poll poll, Comment comment) { Preconditions.checkNotNull(poll); @@ -61,7 +68,7 @@ // creates the poll comment Comment commentCreated = dao.create( - Comment.PROPERTY_POLL, pollToUpdate, +// Comment.PROPERTY_POLL, pollToUpdate, Comment.PROPERTY_POST_DATE, comment.getPostDate(), Comment.PROPERTY_AUTHOR, comment.getAuthor(), Comment.PROPERTY_TEXT, comment.getText() @@ -90,11 +97,8 @@ // feed notification - PollService pollService = newService(PollService.class); - PollUrl pollVoteUrl = pollService.getPollVoteUrl(poll, false); - PollFeedService pollFeedService = newService(PollFeedService.class); - pollFeedService.onAddComment(commentCreated, pollVoteUrl); + pollFeedService.onAddComment(poll, commentCreated); return commentCreated; } catch (TopiaException e) { @@ -109,27 +113,20 @@ Preconditions.checkNotNull(poll); Preconditions.checkNotNull(commentId); + Comment comment = getExistingPollComment(commentId); + CommentDAO dao = getDAO(Comment.class); try { - Comment comment = dao.findByTopiaId(commentId); - - if (comment == null) { - throw new PollCommentNotFound(); - } - dao.delete(comment); commitTransaction("Could not delete comment " + comment.getText()); // feed notification - PollService pollService = newService(PollService.class); - PollUrl pollVoteUrl = pollService.getPollVoteUrl(poll, false); - PollFeedService pollFeedService = newService(PollFeedService.class); - pollFeedService.onDeleteComment(comment, pollVoteUrl, reason); + pollFeedService.onDeleteComment(poll, comment, reason); } catch (TopiaException e) { throw new PollenTechnicalException(e); @@ -152,26 +149,31 @@ public boolean isCanDeleteComment(Comment comment, PollAccount pollAccount, - UserAccount userAccount) { + UserAccount userAccount, + boolean isPollCreator) { - boolean result; + boolean result = false; PollAccount commentAccount = comment.getPollAccount(); - // loggued - if (userAccount != null) { + if (isPollCreator) { + // poll creator has admin rights on his poll + result = true; + } else if (userAccount != null) { + + // loggued boolean isAdmin = userAccount.isAdministrator(); - boolean isCommentAccount = userAccount.equals(commentAccount.getUserAccount()); +// boolean isCommentAccount = userAccount.equals(commentAccount.getUserAccount()); - result = isAdmin || isCommentAccount; + // pollen admin or comment owner (linked by user account) + result = isAdmin || + userAccount.equals(commentAccount.getUserAccount()); } else if (pollAccount != null) { + // comment owner (linked by poll account) result = pollAccount.equals(commentAccount); - - } else { - result = false; } return result; } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -40,6 +40,7 @@ import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.Comment; import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.services.PollenServiceSupport; @@ -116,37 +117,50 @@ } } - public void onAddComment(Comment comment, PollUrl pollVoteUrl) { + public void onAddComment(Poll poll, Comment comment) { + PollUrlService pollService = newService(PollUrlService.class); + PollUrl pollVoteUrl = pollService.getPollVoteUrl(poll, false); + + String title = _("pollen.feed.addCommentTitle", comment.getAuthor()); String content = _("pollen.feed.addCommentContent", comment.getText()); - addFeedEntry(comment.getPoll(), title, content, pollVoteUrl); + addFeedEntry(poll, title, content, pollVoteUrl); } - public void onDeleteComment(Comment comment, - PollUrl pollVoteUrl, - String reason) { + public void onDeleteComment(Poll poll, Comment comment, String reason) { + PollUrlService pollService = newService(PollUrlService.class); + PollUrl pollVoteUrl = pollService.getPollVoteUrl(poll, false); + String title = _("pollen.feed.deleteCommentTitle", - comment.getAuthor()); + comment.getAuthor(), reason); - String content = _("pollen.feed.deleteCommentContent", - comment.getText(), reason); + String content = + _("pollen.feed.deleteCommentContent", comment.getText()); - addFeedEntry(comment.getPoll(), title, content, pollVoteUrl); + addFeedEntry(poll, title, content, pollVoteUrl); } - public void onAddVote(Vote vote, - boolean anonymousVote, - String pollResult, - PollUrl pollVoteUrl) { + public void onAddVote(Poll poll, Vote vote) { + PollUrlService pollUrlService = newService(PollUrlService.class); + + PollUrl pollVoteUrl = pollUrlService.getPollVoteUrl(poll, false); + + PollResultsService pollResultsService = + newService(PollResultsService.class); + + String pollResult = pollResultsService.getResultsAsString(poll); + String userId; - if (anonymousVote) { + + if (vote.isAnonymous()) { + userId = _("pollen.common.anonymous"); } else { userId = vote.getPollAccount().getVotingId(); @@ -156,9 +170,62 @@ String content = _("pollen.feed.addVoteContent", pollResult); - addFeedEntry(vote.getPoll(), title, content, pollVoteUrl); + addFeedEntry(poll, title, content, pollVoteUrl); } + public void onUpdateVote(Poll poll, + Vote vote) { + + PollUrlService pollUrlService = newService(PollUrlService.class); + + PollUrl pollVoteUrl = pollUrlService.getPollVoteUrl(poll, false); + + PollResultsService pollResultsService = + newService(PollResultsService.class); + + String pollResult = pollResultsService.getResultsAsString(poll); + + String userId; + + if (vote.isAnonymous()) { + + userId = _("pollen.common.anonymous"); + } else { + userId = vote.getPollAccount().getVotingId(); + + } + String title = _("pollen.feed.updateVoteTitle", userId); + + String content = _("pollen.feed.updateVoteContent", pollResult); + + addFeedEntry(poll, title, content, pollVoteUrl); + } + + public void onDeleteVote(Poll poll, Vote vote, PollAccount voteAccount, String reason) { + + PollUrlService pollUrlService = newService(PollUrlService.class); + + PollUrl pollVoteUrl = pollUrlService.getPollVoteUrl(poll, false); + + PollResultsService pollResultsService = + newService(PollResultsService.class); + + String pollResult = pollResultsService.getResultsAsString(poll); + + String userId; + if (vote.isAnonymous()) { + userId = _("pollen.common.anonymous"); + } else { + userId = voteAccount.getVotingId(); + + } + String title = _("pollen.feed.deleteVoteTitle", userId, reason); + + String content = _("pollen.feed.deleteVoteContent", pollResult); + + addFeedEntry(poll, title, content, pollVoteUrl); + } + public void onAddChoice(Poll poll, Choice choice, PollUrl pollVoteUrl) { String title = _("pollen.feed.addChoiceTitle", choice.getName()); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -39,6 +39,7 @@ import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; +import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.PollenServiceSupport; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.votecounting.business.NumberMethod; @@ -72,91 +73,53 @@ /** log. */ private static final Log log = LogFactory.getLog(PollResultsService.class); - public PollResultList getResults(String pollId) throws PollNotFoundException { - - PollService pollService = newService(PollService.class); - Poll poll = pollService.getPollByPollId(pollId); - - if (poll == null) { - throw new PollNotFoundException(); - } - PollResultList result; - if (poll.getPollType() == PollType.GROUP) { - result = generateResults(poll, null, true, true); - } else { - result = generateResults(poll, null, true, false); - } - return result; - } - /** - * Génère les résultats d'un sondage (= un dépouillement). + * Récurpération des résultats d'un sondage sous forme de + * {@link PollResultList}. + * <p/> + * Si les résultats ne sont pas à jour ({@link Poll#isResultUptodate()}, + * alors ils seront regénérés. * - * @param poll le sondage - * @param voteCounting type de dépouillement - * @param byGroup résultats par groupe - * @param groupOnly résultats uniquement par groupe - * @return les résultats du sondage + * @param poll le sondage à traiter + * @return les résultats du sondage. */ - private PollResultList generateResults(Poll poll, - VoteCountingType voteCounting, - boolean byGroup, - boolean groupOnly) { + public PollResultList getResults(Poll poll) { + Preconditions.checkNotNull(poll); - if (log.isDebugEnabled()) { - log.debug(poll.getPollId() + " (" + voteCounting - + ") has results: " + hasResults(poll, voteCounting)); - } - // Dépouillement du sondage. - // S'il n'existe pas de résultats ou si le sondage est encore ouvert. - //if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) { - PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); + VoteCountingResultDTO result; + if (!poll.isResultUptodate()) { - if (voteCounting != null) { - dto.setVoteCounting(voteCounting); - } + //must regenerate results - // clear result (they will be regenerated ! (a big shame)) - poll.clearResult(); + result = generateResult(poll); - VoteCountingService service = new VoteCountingService(); + commitTransaction("Could not generate poll result"); + } else { - VoteCountingResultDTO result = service.execute(dto); + result = getResultDTO(poll); - ResultDAO daoResult = getDAO(Result.class); + } - for (ChoiceDTO choice : result.getChoices()) { + boolean byGroup = poll.getPollType() == PollType.GROUP; - Result eResult = create(daoResult); + VoteCountingType voteCountingType = poll.getVoteCountingType(); - Choice eChoice = poll.getChoiceByTopiaId(choice.getIdChoice()); + // Conversion des résultats + List<PollResult> list = Lists.transform( + poll.getResult(), + PollenServiceFunctions.newResultToBeanFunction(poll)); - poll.addResult(eResult); + // Filtrage des résultats que l'on veut retourner - eResult.setName(eChoice.getName()); - eResult.setByGroup(result.isByGroup()); - eResult.setPoll(poll); - eResult.setResultValue(String.valueOf(choice.getValue())); - eResult.setVoteCountingType(result.getTypeVoteCounting()); - } - - commitTransaction("Could not generate poll result"); - - // Conversion et trie des résultats - List<PollResult> list = createPollResults(poll); - - VoteCountingType voteCountingType = poll.getVoteCountingType(); - Iterator<PollResult> it = list.iterator(); while (it.hasNext()) { PollResult currentResult = it.next(); // Cas d'un dépouillement particulier // Suppression des resultats qui ne sont pas de se dépouillement - if (voteCounting != null - && currentResult.getVoteCountingType() != voteCounting) { + if (currentResult.getVoteCountingType() != voteCountingType) { it.remove(); } @@ -164,15 +127,10 @@ if (byGroup) { // Filtre group : Suppression resultats non group - if (groupOnly && !currentResult.isByGroup()) { + if (!currentResult.isByGroup()) { it.remove(); } - // Filtre non group : Suppression resultats group - else if (!groupOnly && currentResult.isByGroup()) { - it.remove(); - } - // Suppression des autres resultats de depouillements differents if (currentResult.getVoteCountingType() != voteCountingType) { it.remove(); @@ -186,18 +144,60 @@ return resultList; } + /** + * Génère les résultats d'un sondage (= un dépouillement) et les stoque en + * base. + * <p/> + * <strong>Note importante :</strong> Le commite n'est pas effectuée dans + * cette méthode car d'autres services vont appeller cette méthode au sein + * d'une transaction et on ne veut pas faire deux commits. + * + * @param poll le sondage à dépouiller + * @since 1.4 + */ + public VoteCountingResultDTO generateResult(Poll poll) { + + Preconditions.checkNotNull(poll); + + if (log.isInfoEnabled()) { + log.info("Will regenerate results for poll " + poll.getPollId()); + } + + VoteCountingResultDTO result = getResultDTO(poll); + + // clear result + poll.clearResult(); + + ResultDAO daoResult = getDAO(Result.class); + + for (ChoiceDTO choice : result.getChoices()) { + + Result eResult = create(daoResult); + + Choice eChoice = poll.getChoiceByTopiaId(choice.getIdChoice()); + + eResult.setName(eChoice.getName()); + eResult.setByGroup(result.isByGroup()); +// eResult.setPoll(poll); + eResult.setResultValue(String.valueOf(choice.getValue())); + eResult.setVoteCountingType(result.getTypeVoteCounting()); + + poll.addResult(eResult); + } + + poll.setResultUptodate(true); + + return result; + } + public String exportPolltoXml(String pollId) throws PollNotFoundException { // Recherche du sondage PollService pollService = newService(PollService.class); - Poll poll = pollService.getPollByPollId(pollId); + Poll poll = pollService.getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); VoteCountingService service = new VoteCountingService(); @@ -216,7 +216,7 @@ // Transformation du sondage PollExportDTO pollExport = new PollExportDTO(); - pollExport.setPollId(dto.getPollId()); + pollExport.setPollId(pollId); pollExport.setPoll(dto); pollExport.setVoteCountingResults(results); @@ -227,31 +227,6 @@ return content; } - /** - * Retourne la liste des résultats d'un sondage sous forme de DTOs. - * - * @param poll le sondage (entitée Poll) - * @return la liste des DTO Result - */ - protected List<PollResult> createPollResults(Poll poll) { - List<PollResult> results = Lists.newArrayList(); - for (Result res : poll.getResult()) { - PollResult dto = new PollResult(); - dto.setId(res.getTopiaId()); - dto.setPollId(poll.getPollId()); - String resName = res.getName(); - dto.setName(resName); - dto.setHidden(resName != null && - resName.startsWith(NumberMethod.HIDDEN_PREFIX)); - dto.setValue(res.getResultValue()); - dto.setByGroup(res.isByGroup()); - dto.setChoiceType(poll.getChoiceType()); - dto.setVoteCountingType(poll.getVoteCountingType()); - results.add(dto); - } - return results; - } - public String getResultValue(Choice choice, Collection<PollResult> results) { @@ -398,7 +373,33 @@ return val; } + // /** +// * Retourne la liste des résultats d'un sondage sous forme de DTOs. +// * +// * @param poll le sondage (entitée Poll) +// * @return la liste des DTO Result +// */ +// protected List<PollResult> createPollResults(Poll poll) { +// List<PollResult> results = Lists.newArrayList(); +// for (Result res : poll.getResult()) { +// PollResult dto = new PollResult(); +// dto.setId(res.getTopiaId()); +// dto.setPollId(poll.getPollId()); +// String resName = res.getName(); +// dto.setName(resName); +// dto.setHidden(resName != null && +// resName.startsWith(NumberMethod.HIDDEN_PREFIX)); +// dto.setValue(res.getResultValue()); +// dto.setByGroup(res.isByGroup()); +// dto.setChoiceType(poll.getChoiceType()); +// dto.setVoteCountingType(poll.getVoteCountingType()); +// results.add(dto); +// } +// return results; +// } + +// /** // * Création des résultats de sondage à partir d'un dto de résultats de // * sondage. // * @@ -424,32 +425,32 @@ // } // } - /** - * Retourne vrai si le sondage a des résultats. - * - * @param poll le sondage - * @param type type de dépouillement - * @return vrai si le sondage a des résultats - */ - protected boolean hasResults(Poll poll, VoteCountingType type) { - boolean hasresult = false; +// /** +// * Retourne vrai si le sondage a des résultats. +// * +// * @param poll le sondage +// * @param type type de dépouillement +// * @return vrai si le sondage a des résultats +// */ +// protected boolean hasResults(Poll poll, VoteCountingType type) { +// boolean hasresult = false; +// +// if (!poll.isResultEmpty()) { +// +// if (type == null) { +// hasresult = true; +// } else { +// for (Result result : poll.getResult()) { +// if (type.equals(result.getVoteCountingType())) { +// hasresult = true; +// break; +// } +// } +// } +// } +// return hasresult; +// } - if (!poll.isResultEmpty()) { - - if (type == null) { - hasresult = true; - } else { - for (Result result : poll.getResult()) { - if (type.equals(result.getVoteCountingType())) { - hasresult = true; - break; - } - } - } - } - return hasresult; - } - // public String importPoll(String filePath) { // return importPoll(filePath, null); // } @@ -483,15 +484,14 @@ /** * Retourne une chaîne contenant les résultats du sondage. * - * @param poll le sondage - * @param results les résultats du sondage + * @param poll le sondage * @return les résultats sous forme de chaine de caractères */ - public String getResultsAsString(Poll poll, Collection<Result> results) { + public String getResultsAsString(Poll poll) { - DateFormat dateFormat = new SimpleDateFormat(); + DateFormat dateFormat = new SimpleDateFormat(getDateTimePattern()); StringBuilder res = new StringBuilder(""); - Iterator<Result> it = results.iterator(); + Iterator<Result> it = poll.getResult().iterator(); while (it.hasNext()) { Result result = it.next(); if (poll.getChoiceType() == ChoiceType.DATE) { @@ -507,4 +507,16 @@ } return res.toString(); } + + protected VoteCountingResultDTO getResultDTO(Poll poll) { + + PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); + + dto.setVoteCounting(poll.getVoteCountingType()); + + VoteCountingService service = new VoteCountingService(); + + VoteCountingResultDTO result = service.execute(dto); + return result; + } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -50,7 +50,6 @@ import org.chorem.pollen.business.persistence.PreventRule; import org.chorem.pollen.business.persistence.PreventRuleDAO; import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListDAO; import org.chorem.pollen.common.ChoiceType; @@ -74,7 +73,6 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.net.URL; import java.util.Date; import java.util.List; import java.util.Locale; @@ -371,10 +369,12 @@ commitTransaction("Could not create poll " + poll.getTitle()); - PollUrl pollVoteUrl = getPollVoteUrl(poll, false); - PollUrl pollModerateUrl = getPollVoteUrl(poll, true); - PollUrl pollEditUrl = getPollEditUrl(poll); + PollUrlService pollUrlService = newService(PollUrlService.class); + PollUrl pollVoteUrl = pollUrlService.getPollVoteUrl(poll, false); + PollUrl pollModerateUrl = pollUrlService.getPollVoteUrl(poll, true); + PollUrl pollEditUrl = pollUrlService.getPollEditUrl(poll); + // email notification EmailService emailService = newService(EmailService.class); emailService.onPollCreated(result, pollVoteUrl, pollModerateUrl, pollEditUrl); @@ -448,45 +448,59 @@ commitTransaction("Could not update poll [" + poll.getTopiaId() + "]"); } - public PollUrl getPollVoteUrl(Poll poll, boolean moderate) { - URL applicationUrl = serviceContext.getApplicationURL(); - String baseUrl = applicationUrl + "/poll/votefor/"; - PollUri pollUri = PollUri.newPollUri(poll.getPollId()); +// public PollUrl getPollVoteUrl(Poll poll, boolean moderate) { +// URL applicationUrl = serviceContext.getApplicationURL(); +// String baseUrl = applicationUrl + "/poll/votefor/"; +// PollUri pollUri = PollUri.newPollUri(poll.getPollId()); +// +// if (moderate) { +// String creatorId = poll.getCreator().getAccountId(); +// pollUri.setAccountId(creatorId); +// } +// +// PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); +// return result; +// } - if (moderate) { - String creatorId = poll.getCreator().getAccountId(); - pollUri.setAccountId(creatorId); - } +// public PollUrl getPollUpdateVoteUrl(Poll poll) { +// Preconditions.checkNotNull(poll); +// +// URL applicationUrl = serviceContext.getApplicationURL(); +// String baseUrl = applicationUrl + "/poll/votefor/"; +// PollUri pollUri = PollUri.newPollUri(poll.getPollId()); +// +// String creatorId = poll.getCreator().getAccountId(); +// pollUri.setAccountId(creatorId); +// +// PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); +// return result; +// } - PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); - return result; - } +// public PollUrl getPollEditUrl(Poll poll) { +// URL applicationUrl = serviceContext.getApplicationURL(); +// String baseUrl = applicationUrl + "/poll/modification/"; +// +// String creatorId = poll.getCreator().getAccountId(); +// PollUri pollUri = PollUri.newPollUri(poll.getPollId(), creatorId); +// +// PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); +// return result; +// } - public PollUrl getPollEditUrl(Poll poll) { - URL applicationUrl = serviceContext.getApplicationURL(); - String baseUrl = applicationUrl + "/poll/modification/"; +// public PollUrl getPollResultUrl(Poll poll) { +// URL applicationUrl = serviceContext.getApplicationURL(); +// String baseUrl = applicationUrl + "/poll/results/"; +// PollUri pollUri = PollUri.newPollUri(poll.getPollId()); +// +// if (!poll.isPublicResults()) { +// String creatorId = poll.getCreator().getAccountId(); +// pollUri.setAccountId(creatorId); +// } +// +// PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); +// return result; +// } - String creatorId = poll.getCreator().getAccountId(); - PollUri pollUri = PollUri.newPollUri(poll.getPollId(), creatorId); - - PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); - return result; - } - - public PollUrl getPollResultUrl(Poll poll) { - URL applicationUrl = serviceContext.getApplicationURL(); - String baseUrl = applicationUrl + "/poll/results/"; - PollUri pollUri = PollUri.newPollUri(poll.getPollId()); - - if (!poll.isPublicResults()) { - String creatorId = poll.getCreator().getAccountId(); - pollUri.setAccountId(creatorId); - } - - PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); - return result; - } - public List<Poll> getPolls(TopiaFilterPagerUtil.FilterPagerBean pager) { Preconditions.checkNotNull(pager); @@ -581,6 +595,22 @@ } } + public Poll getExistingPollByPollId(String pollId) throws PollNotFoundException { + + Preconditions.checkNotNull(pollId); + try { + PollDAO dao = getDAO(Poll.class); + Poll result = dao.findByPollId(pollId); + + if (result == null) { + throw new PollNotFoundException(); + } + return result; + } catch (TopiaException e) { + throw new PollenTechnicalException("Could not find poll with pollId '" + pollId + "'", e); + } + } + /** * Retrieve a pollAccount with {@code accountId}. This pollAccount will be * attached to the given {@code userAccount} (only if not already attached). @@ -691,12 +721,8 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(accountId); - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - if (userAccount == null || userAccount.isAdministrator()) { // must check that accountId matches the poll creator id @@ -721,12 +747,8 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(accountId); - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - if (userAccount == null || userAccount.isAdministrator()) { // must check that accountId matches the poll creator id @@ -777,12 +799,8 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(choice); - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - saveChoice(poll, choice); commitTransaction("Can't create new choice [" + @@ -839,11 +857,8 @@ public void deleteChoice(String pollId, String choiceId) throws PollNotFoundException, PollChoiceNotFoundException { - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } Choice choice = poll.getChoiceByTopiaId(choiceId); if (choice == null) { @@ -862,23 +877,15 @@ String pollId = uri.getPollId(); - Poll poll = getPollByPollId(pollId); - - if (poll == null) { - throw new PollNotFoundException(); - } + getExistingPollByPollId(pollId); } public void checkPollResult(PollUri uri) throws PollNotFoundException, UnauthorizedPollAccessException { String pollId = uri.getPollId(); - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - if (!poll.isPublicResults()) { throw new UnauthorizedPollAccessException(); } @@ -889,12 +896,8 @@ String pollId = uri.getPollId(); String accountId = uri.getAccountId(); - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - PollAccountDAO dao = getDAO(PollAccount.class); if (poll.getPollType() != PollType.FREE) { @@ -936,12 +939,8 @@ String pollId = uri.getPollId(); String accountId = uri.getAccountId(); - Poll poll = getPollByPollId(pollId); + Poll poll = getExistingPollByPollId(pollId); - if (poll == null) { - throw new PollNotFoundException(); - } - String creatorId = poll.getCreator().getAccountId(); if (!creatorId.equals(accountId)) { @@ -987,32 +986,32 @@ createThumbnail(pollChoiceImage, pollChoiceImageThumb, 100); } - public void addVoteToPoll(Poll poll, Vote vote) { +// public void addVoteToPoll(Poll poll, Vote vote) { +// +// String pollId = poll.getTopiaId(); +// String voteId = vote.getTopiaId(); +// +// Poll pollToUpdate = getEntityById(Poll.class, pollId); +// Vote voteToAdd = getEntityById(Vote.class, voteId); +// +// pollToUpdate.addVote(voteToAdd); +// +// // Update hasVoted flag for RESTRICTED/GROUP poll +// if (PollType.FREE != poll.getPollType()) { +// +// PersonToList personToList = pollToUpdate.getPersonToListByVote(voteToAdd); +// personToList.setHasVoted(true); +// } +// +// commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]"); +// +// // Send notification if necessary +// PreventRuleService preventRuleService = newService(PreventRuleService.class); +// PollUrl pollVoteUrl = getPollVoteUrl(pollToUpdate, false); +// PollUrl modifUrl = getPollEditUrl(pollToUpdate); +// preventRuleService.onVoteAdded(poll, pollVoteUrl, modifUrl); +// } - String pollId = poll.getTopiaId(); - String voteId = vote.getTopiaId(); - - Poll pollToUpdate = getEntityById(Poll.class, pollId); - Vote voteToAdd = getEntityById(Vote.class, voteId); - - pollToUpdate.addVote(voteToAdd); - - // Update hasVoted flag for RESTRICTED/GROUP poll - if (PollType.FREE != poll.getPollType()) { - - PersonToList personToList = pollToUpdate.getPersonToListByVote(voteToAdd); - personToList.setHasVoted(true); - } - - commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]"); - - // Send notification if necessary - PreventRuleService preventRuleService = newService(PreventRuleService.class); - PollUrl pollVoteUrl = getPollVoteUrl(pollToUpdate, false); - PollUrl modifUrl = getPollEditUrl(pollToUpdate); - preventRuleService.onVoteAdded(poll, pollVoteUrl, modifUrl); - } - public PersonToList getNewPersonToList(PollAccount pollAccount) { PersonToList result = newInstance(getDAO(PersonToList.class)); result.setWeight(1); @@ -1051,8 +1050,10 @@ result.setName(votingList.getName()); result.setWeight(votingList.getWeight()); - PollUrl voteURL = getPollVoteUrl(poll, false); + PollUrlService pollUrlService = newService(PollUrlService.class); + PollUrl voteURL = pollUrlService.getPollVoteUrl(poll, false); + // Merge PersonToList List<PersonToList> personToListsUpdated = Lists.newArrayList(); for (PersonToList personToList : votingList.getPollAccountPersonToList()) { Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -0,0 +1,66 @@ +package org.chorem.pollen.services.impl; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.bean.PollUri; +import org.chorem.pollen.bean.PollUrl; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.services.PollenServiceSupport; + +import java.net.URL; + +/** + * Service to deal with url used by application. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class PollUrlService extends PollenServiceSupport { + + public PollUrl getPollVoteUrl(Poll poll, boolean moderate) { + + Preconditions.checkNotNull(poll); + + URL applicationUrl = serviceContext.getApplicationURL(); + String baseUrl = applicationUrl + "/poll/votefor/"; + PollUri pollUri = PollUri.newPollUri(poll.getPollId()); + + if (moderate) { + String creatorId = poll.getCreator().getAccountId(); + pollUri.setAccountId(creatorId); + } + + PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); + return result; + } + + public PollUrl getPollEditUrl(Poll poll) { + + Preconditions.checkNotNull(poll); + + URL applicationUrl = serviceContext.getApplicationURL(); + String baseUrl = applicationUrl + "/poll/modification/"; + + String creatorId = poll.getCreator().getAccountId(); + PollUri pollUri = PollUri.newPollUri(poll.getPollId(), creatorId); + + PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); + return result; + } + + public PollUrl getPollResultUrl(Poll poll) { + + Preconditions.checkNotNull(poll); + + URL applicationUrl = serviceContext.getApplicationURL(); + String baseUrl = applicationUrl + "/poll/results/"; + PollUri pollUri = PollUri.newPollUri(poll.getPollId()); + + if (!poll.isPublicResults()) { + String creatorId = poll.getCreator().getAccountId(); + pollUri.setAccountId(creatorId); + } + + PollUrl result = PollUrl.newPollUrl(baseUrl, pollUri); + return result; + } +} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -183,6 +183,8 @@ } copyUserAccount(user, userToUpdate); + + commitTransaction("Could not update user"); return userToUpdate; } catch (TopiaException e) { @@ -250,6 +252,8 @@ throw new UserNotFoundException(); } dao.delete(user); + + commitTransaction("Could not delete user "+id); } catch (TopiaException e) { throw new PollenTechnicalException(e); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -29,7 +29,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.PollenTechnicalException; -import org.chorem.pollen.bean.PollUri; +import org.chorem.pollen.bean.PollUrl; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.PersonToListDAO; @@ -51,7 +51,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaFilterPagerUtil; -import java.net.URL; import java.util.Date; import java.util.List; import java.util.Map; @@ -140,21 +139,21 @@ return result; } - /** - * Retrieve the URL to update a vote based on {@link PollUri}. - * - * @param pollUri Uri with pollId and accountId - * @return the URL that allow the voting person to update his vote - */ - public String getUpdateVoteUrl(PollUri pollUri) { - Preconditions.checkNotNull(pollUri.getAccountId()); - URL baseUrl = serviceContext.getApplicationURL(); - String result = - String.format("%s/poll/votefor/%s", baseUrl, pollUri.getUri()); - return result; - } +// /** +// * Retrieve the URL to update a vote based on {@link PollUri}. +// * +// * @param pollUri Uri with pollId and accountId +// * @return the URL that allow the voting person to update his vote +// */ +// public String getUpdateVoteUrl(PollUri pollUri) { +// Preconditions.checkNotNull(pollUri.getAccountId()); +// URL baseUrl = serviceContext.getApplicationURL(); +// String result = +// String.format("%s/poll/votefor/%s", baseUrl, pollUri.getUri()); +// return result; +// } - public Vote createVote(Vote vote) throws PollAccountNotFound { + public Vote createVote(Poll poll, Vote vote) throws PollAccountNotFound { VoteDAO voteDAO = getDAO(Vote.class); @@ -206,12 +205,41 @@ log.debug("Entity created: " + result.getTopiaId()); } + Poll pollToUpdate = getEntityById(Poll.class, poll.getTopiaId()); + + pollToUpdate.addVote(result); + + // Update hasVoted flag for RESTRICTED/GROUP poll + if (PollType.FREE != poll.getPollType()) { + + PersonToList personToList = pollToUpdate.getPersonToListByVote(result); + personToList.setHasVoted(true); + } + + // regnenerate poll results + + generatePollResult(pollToUpdate); + commitTransaction("Could not create vote"); + PollUrlService pollUrlService = newService(PollUrlService.class); + + PollUrl pollVoteUrl = pollUrlService.getPollVoteUrl(poll, false); + + // Send notification if necessary + PreventRuleService preventRuleService = newService(PreventRuleService.class); + PollUrl modifUrl = pollUrlService.getPollEditUrl(poll); + preventRuleService.onVoteAdded(poll, pollVoteUrl, modifUrl); + + // feed notification + + PollFeedService pollFeedService = newService(PollFeedService.class); + pollFeedService.onAddVote(pollToUpdate, result); + return result; } - public Vote updateVote(Vote vote) throws VoteNotFoundException { + public Vote updateVote(Poll poll, Vote vote) throws VoteNotFoundException { Vote result = getEntityById(Vote.class, vote.getTopiaId()); @@ -234,6 +262,8 @@ } result.setAnonymous(vote.isAnonymous()); + VoteToChoiceDAO voteToChoiceDao = getDAO(VoteToChoice.class); + // -- List of VoteToChoice -- // for (VoteToChoice input : vote.getChoiceVoteToChoice()) { @@ -250,7 +280,8 @@ } } else if (voteToChoiceEntity != null) { - deleteVoteToChoice(result, voteToChoiceEntity); + result.removeChoiceVoteToChoice(voteToChoiceEntity); + delete(voteToChoiceDao, voteToChoiceEntity); } } @@ -258,35 +289,17 @@ log.debug("Entity updated: " + result.getTopiaId()); } + generatePollResult(poll); + commitTransaction("Could not update vote"); - return result; - } + // feed notification - protected VoteToChoice createVoteToChoice(Vote vote, VoteToChoice source) { - - VoteToChoiceDAO voteToChoiceDao = getDAO(VoteToChoice.class); - VoteToChoice result = create(voteToChoiceDao); - - String choiceId = source.getChoice().getTopiaId(); - Choice choiceLoaded = getEntityById(Choice.class, choiceId); - result.setChoice(choiceLoaded); - - result.setVote(vote); - result.setVoteValue(source.getVoteValue()); - - vote.addChoiceVoteToChoice(result); - + PollFeedService pollFeedService = newService(PollFeedService.class); + pollFeedService.onUpdateVote(poll, result); return result; } - protected void deleteVoteToChoice(Vote vote, VoteToChoice entity) { - - VoteToChoiceDAO voteToChoiceDao = getDAO(VoteToChoice.class); - vote.removeChoiceVoteToChoice(entity); - delete(voteToChoiceDao, entity); - } - /** * Delete vote referenced by {@code voteId}. This will also delete all * associated {@link VoteToChoice}. The {@link PollAccount} could also be @@ -295,10 +308,16 @@ * is activated. * * @param voteId TopiaId of the vote + * @param reason reason to delete this vote * @throws VoteNotFoundException if vote doesn't exist */ - public void deleteVote(String voteId) throws VoteNotFoundException { + public void deleteVote(Poll poll, + String voteId, + String reason) throws VoteNotFoundException { + Preconditions.checkNotNull(poll); + Preconditions.checkNotNull(voteId); + Vote entityToDelete = getEntityById(Vote.class, voteId); if (entityToDelete == null) { @@ -315,12 +334,12 @@ delete(voteToChoiceDao, voteToChoice); } - Poll poll = entityToDelete.getPoll(); +// Poll poll = entityToDelete.getPoll(); + PollAccount voteAccount = entityToDelete.getPollAccount(); if (PollType.FREE == poll.getPollType()) { // Delete vote PollAccount if the Poll is free and account is not the creator - PollAccount voteAccount = entityToDelete.getPollAccount(); if (!voteAccount.equals(poll.getCreator())) { PollAccountDAO accountDAO = getDAO(PollAccount.class); delete(accountDAO, voteAccount); @@ -335,13 +354,18 @@ poll.removeVote(entityToDelete); delete(dao, entityToDelete); - // TODO calculate results if continuous - if (log.isDebugEnabled()) { log.debug("Entity deleted: " + voteId); } + generatePollResult(poll); + commitTransaction("Could not delete vote"); + + // feed notification + + PollFeedService pollFeedService = newService(PollFeedService.class); + pollFeedService.onDeleteVote(poll, entityToDelete, voteAccount, reason); } public List<Vote> getVotesByPoll(Poll poll, @@ -423,10 +447,10 @@ return result; } - public boolean hasAlreadyVoted(String votingId, Poll poll) { + public boolean hasAlreadyVoted(Poll poll, String votingId) { try { VoteDAO dao = getDAO(Vote.class); - boolean result = dao.hasAlreadyVoted(votingId, poll); + boolean result = dao.hasAlreadyVoted(poll, votingId); return result; } catch (Exception e) { throw new PollenTechnicalException( @@ -464,4 +488,26 @@ } } + protected VoteToChoice createVoteToChoice(Vote vote, VoteToChoice source) { + + VoteToChoiceDAO voteToChoiceDao = getDAO(VoteToChoice.class); + VoteToChoice result = create(voteToChoiceDao); + + String choiceId = source.getChoice().getTopiaId(); + Choice choiceLoaded = getEntityById(Choice.class, choiceId); + result.setChoice(choiceLoaded); + + result.setVote(vote); + result.setVoteValue(source.getVoteValue()); + + vote.addChoiceVoteToChoice(result); + + return result; + } + + protected void generatePollResult(Poll poll) { + PollResultsService pollResultsService = newService(PollResultsService.class); + pollResultsService.generateResult(poll); + } + } //voteservice Modified: trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties =================================================================== --- trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-06-03 15:40:54 UTC (rev 3416) @@ -2,7 +2,7 @@ pollen.common.addingChoicesContent=From %s to %s pollen.common.addingChoicesFrom=From %s pollen.common.addingChoicesTo=Until %s -pollen.common.anonymous=Anonymous vote +pollen.common.anonymous=Anonymous voter pollen.common.datePattern=MM/dd/yyyy pollen.common.dateTimePattern=MM/dd/yyyy HH\:mm pollen.common.numberVote-average=Average of numbers @@ -31,12 +31,16 @@ pollen.feed.addChoiceTitle= pollen.feed.addCommentContent=%s pollen.feed.addCommentTitle=New comment of %s -pollen.feed.addVoteContent= -pollen.feed.addVoteTitle= +pollen.feed.addVoteContent=Poll result\: %s +pollen.feed.addVoteTitle=New vote from '%s' pollen.feed.createPollContent= pollen.feed.deleteCommentContent=%s -pollen.feed.deleteCommentTitle=Delete comment of %s for reason '%s' +pollen.feed.deleteCommentTitle=Delete comment of '%s' for reason '%s' +pollen.feed.deleteVoteContent=Poll result\: %s +pollen.feed.deleteVoteTitle=Delete vote of '%s' for reason '%s' pollen.feed.pollDescription=%s pollen.feed.pollTitle=Pollen \: %s +pollen.feed.updateVoteContent=Poll result\: %s +pollen.feed.updateVoteTitle=Vote modified for '%s' pollen.info.admin.created=Super admin was created with login %1$s pollen.info.admin.exists=Super admin already exists Modified: trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties =================================================================== --- trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-06-03 15:40:54 UTC (rev 3416) @@ -2,7 +2,7 @@ pollen.common.addingChoicesContent=Du %s au %s pollen.common.addingChoicesFrom=Depuis le %s pollen.common.addingChoicesTo=Jusqu'au %s -pollen.common.anonymous=Vote anonyme +pollen.common.anonymous=votant anonyme pollen.common.datePattern=dd/MM/yyyy pollen.common.dateTimePattern=dd/MM/yyyy HH\:mm pollen.common.numberVote-average=Moyenne des nombres @@ -31,12 +31,16 @@ pollen.feed.addChoiceTitle= pollen.feed.addCommentContent=%s pollen.feed.addCommentTitle=Nouveau commentaire de %s -pollen.feed.addVoteContent= -pollen.feed.addVoteTitle= +pollen.feed.addVoteContent=Résultat du sondage \: %s +pollen.feed.addVoteTitle=Nouveau vote de '%s' pollen.feed.createPollContent= pollen.feed.deleteCommentContent=%s -pollen.feed.deleteCommentTitle=Suppression du commentaire de %s pour la raison '%s' +pollen.feed.deleteCommentTitle=Suppression du commentaire de '%s' pour la raison '%s' +pollen.feed.deleteVoteContent=Résultat du sondage \: %s +pollen.feed.deleteVoteTitle=Suppression du vote de '%s' pour la raison '%s' pollen.feed.pollDescription=%s pollen.feed.pollTitle=Pollen \: %s +pollen.feed.updateVoteContent=Résultat du sondage \: %s +pollen.feed.updateVoteTitle=Vote modifié de '%s' pollen.info.admin.created=Le super admin a été créé avec l'identifiant %1$s. pollen.info.admin.exists=Le super admin existe déjà Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -35,6 +35,15 @@ import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.PollenServiceFactory; +import org.chorem.pollen.services.impl.FavoriteService; +import org.chorem.pollen.services.impl.PollCommentService; +import org.chorem.pollen.services.impl.PollFeedService; +import org.chorem.pollen.services.impl.PollResultsService; +import org.chorem.pollen.services.impl.PollService; +import org.chorem.pollen.services.impl.PollUrlService; +import org.chorem.pollen.services.impl.PreventRuleService; +import org.chorem.pollen.services.impl.UserService; +import org.chorem.pollen.services.impl.VoteService; import org.chorem.pollen.ui.PollenApplicationContext; import org.chorem.pollen.ui.PollenSession; import org.nuiton.topia.TopiaContext; @@ -88,6 +97,24 @@ protected transient TopiaContext transaction; + private transient PollService pollService; + + private transient PollUrlService pollUrlService; + + private transient PollResultsService pollResultsService; + + private transient VoteService voteService; + + private transient PollCommentService pollCommentService; + + private transient PollFeedService pollFeedService; + + private transient UserService userService; + + private transient FavoriteService favoriteService; + + private transient PreventRuleService preventRuleService; + public PageSkin getSkin() { return PageSkin.INDEX; } @@ -246,31 +273,16 @@ public Collection<String> getFlashMessages() { List<String> result = getPollenSession().consumeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); -// if (result == null) { -// result = Collections.emptyList(); -// } else { -// getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); -// } return result; } public Collection<String> getFlashErrors() { List<String> result = getPollenSession().consumeDynamicData(PollenSession.SESSION_TOKEN_ERRORS); -// if (result == null) { -// result = Collections.emptyList(); -// } else { -// getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_ERRORS); -// } return result; } public Collection<String> getFlashWarnings() { List<String> result = getPollenSession().consumeDynamicData(PollenSession.SESSION_TOKEN_WARNINGS); -// if (result == null) { -// result = Collections.emptyList(); -// } else { -// getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_ERRORS); -// } return result; } @@ -307,4 +319,67 @@ boolean result = super.hasErrors(); return result || hasFlashErrors(); } + + protected final PollService getPollService() { + if (pollService == null) { + pollService = newService(PollService.class); + } + return pollService; + } + + protected final PollUrlService getPollUrlService() { + if (pollUrlService == null) { + pollUrlService = newService(PollUrlService.class); + } + return pollUrlService; + } + + protected final PollResultsService getPollResultsService() { + if (pollResultsService == null) { + pollResultsService = newService(PollResultsService.class); + } + return pollResultsService; + } + + protected final VoteService getVoteService() { + if (voteService == null) { + voteService = newService(VoteService.class); + } + return voteService; + } + + protected final PollCommentService getPollCommentService() { + if (pollCommentService == null) { + pollCommentService = newService(PollCommentService.class); + } + return pollCommentService; + } + + protected final PollFeedService getPollFeedService() { + if (pollFeedService == null) { + pollFeedService = newService(PollFeedService.class); + } + return pollFeedService; + } + + protected final UserService getUserService() { + if (userService == null) { + userService = newService(UserService.class); + } + return userService; + } + + protected final FavoriteService getFavoriteService() { + if (favoriteService == null) { + favoriteService = newService(FavoriteService.class); + } + return favoriteService; + } + + protected final PreventRuleService getPreventRuleService() { + if (preventRuleService == null) { + preventRuleService = newService(PreventRuleService.class); + } + return preventRuleService; + } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,8 +26,6 @@ import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.services.impl.PollService; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PollenActionSupport; /** @@ -80,17 +78,13 @@ if (StringUtils.isNotEmpty(userId)) { // load user - UserService service = newService(UserService.class); - - user = service.getEntityById(UserAccount.class, userId); + user = getUserService().getEntityById(UserAccount.class, userId); } if (StringUtils.isNotEmpty(pollId)) { // load poll - PollService servcie = newService(PollService.class); - - poll = servcie.getPollByPollId(pollId); + poll = getPollService().getExistingPollByPollId(pollId); } return SUCCESS; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -59,7 +59,7 @@ Preconditions.checkNotNull(userId); - UserService service = newService(UserService.class); + UserService service = getUserService(); String result = INPUT; @@ -68,7 +68,6 @@ service.getEntityById(UserAccount.class, userId); service.deleteUser(userId); - getTransaction().commitTransaction(); addFlashMessage( _("pollen.information.user.deleted", user.getDisplayName())); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -28,7 +28,6 @@ import org.chorem.pollen.services.exceptions.UserEmailAlreadyUsedException; import org.chorem.pollen.services.exceptions.UserInvalidPasswordException; import org.chorem.pollen.services.exceptions.UserLoginAlreadyUsedException; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PollenActionSupport; /** @@ -45,8 +44,7 @@ public UserAccount getUser() { if (user == null) { - UserService service = newService(UserService.class); - user = service.getNewUser(); + user = getUserService().getNewUser(); } return user; } @@ -77,7 +75,7 @@ String result = INPUT; try { - newService(UserService.class).createUser(user, true); + getUserService().createUser(user, true); addFlashMessage( _("pollen.information.user.created", @@ -102,13 +100,10 @@ Preconditions.checkNotNull(user); - UserService service = newService(UserService.class); - String result = INPUT; try { - service.updateUser(user, null, true); - getTransaction().commitTransaction(); + getUserService().updateUser(user, null, true); addFlashMessage( _("pollen.information.user.updated", user.getDisplayName())); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/GetPollImageChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/GetPollImageChoice.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/GetPollImageChoice.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -78,10 +78,8 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(choiceId); - PollService service = newService(PollService.class); + File file = getPollService().getPollChoiceImageFile(pollId, choiceId, thumb); - File file = service.getPollChoiceImageFile(pollId, choiceId, thumb); - MimetypesFileTypeMap mimes = new MimetypesFileTypeMap(); contentType = mimes.getContentType(file); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -73,7 +73,7 @@ @Override public String execute() throws Exception { - PollService pollService = newService(PollService.class); + PollService pollService = getPollService(); List<Poll> pollList = pollService.getCreatedPolls(pager, getPollenUserAccount()); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import com.google.common.collect.Maps; import org.chorem.pollen.business.persistence.PersonList; -import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.ui.actions.PollenActionSupport; import java.util.Map; @@ -59,10 +58,8 @@ @Override public String execute() throws Exception { - FavoriteService service = newService(FavoriteService.class); - PersonList personList = - service.getEntityById(PersonList.class, favoriteListId); + getFavoriteService().getEntityById(PersonList.class, favoriteListId); favoriteList = Maps.newHashMap(); favoriteList.put("id", personList.getTopiaId()); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.entities.PollenBinderHelper; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PollenActionSupport; import org.nuiton.util.beans.Binder; @@ -60,10 +59,8 @@ @Override public String execute() throws Exception { - UserService userService = newService(UserService.class); - PollAccount userAccount = - userService.getEntityById(PollAccount.class, pollAccountId); + getUserService().getEntityById(PollAccount.class, pollAccountId); Binder<PollAccount, PollAccount> binder = PollenBinderHelper.getSimpleTopiaBinder(PollAccount.class); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -81,7 +81,7 @@ @Override public String execute() throws Exception { - FavoriteService service = newService(FavoriteService.class); + FavoriteService service = getFavoriteService(); PersonList favoriteList = service.getEntityById(PersonList.class, favoriteListId); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import com.google.common.collect.Maps; import org.chorem.pollen.business.persistence.PersonList; -import org.chorem.pollen.services.impl.FavoriteService; import java.util.List; import java.util.Map; @@ -69,9 +68,7 @@ @Override public String execute() throws Exception { - FavoriteService service = newService(FavoriteService.class); - - List<PersonList> allFavoriteLists = service.getFavoriteLists( + List<PersonList> allFavoriteLists = getFavoriteService().getFavoriteLists( getPollenUserAccount(), pager); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -75,7 +75,7 @@ @Override public String execute() throws Exception { - PollService pollService = newService(PollService.class); + PollService pollService = getPollService(); List<Pair<Poll, PollAccount>> invitedPolls = pollService.getInvitedPolls(pager, getPollenUserAccount()); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -76,7 +76,7 @@ @Override public String execute() throws Exception { - PollService pollService = newService(PollService.class); + PollService pollService = getPollService(); List<Pair<Poll, PollAccount>> participatedPolls = pollService.getParticipatedPolls(pager, getPollenUserAccount()); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -28,7 +28,6 @@ import org.chorem.pollen.business.persistence.Comment; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.entities.PollenBinderHelper; -import org.chorem.pollen.services.impl.PollCommentService; import org.nuiton.util.beans.Binder; import java.util.List; @@ -82,10 +81,9 @@ Preconditions.checkNotNull(pollId); - PollCommentService pollService = newService(PollCommentService.class); + List<Comment> commentList = getPollCommentService().getComments( + pager, pollId); - List<Comment> commentList = pollService.getComments(pager, pollId); - UserAccount userAccount = getPollenUserAccount(); comments = new Map[commentList.size()]; @@ -101,22 +99,21 @@ Comment.PROPERTY_AUTHOR ); map.put("id", comment.getTopiaId()); - Set<String> functions = getCommentFunctions(pollService, - comment, - userAccount); + Set<String> functions = getCommentFunctions( + comment, + userAccount); map.put("functions", functions); comments[index++] = map; } return SUCCESS; } - private Set<String> getCommentFunctions(PollCommentService pollService, - Comment comment, + private Set<String> getCommentFunctions(Comment comment, UserAccount userAccount) { Set<String> result = Sets.newHashSet(); - boolean canDelete = pollService.isCanDeleteComment(comment, - null, - userAccount); + //TODO-tchemit-2012-06-03 Should use also pollAccountId (if specified in url)... + boolean canDelete = getPollCommentService().isCanDeleteComment( + comment, null, userAccount, false); if (canDelete) { result.add("delete"); } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -72,7 +72,7 @@ @Override public String execute() throws Exception { - PollService pollService = newService(PollService.class); + PollService pollService = getPollService(); List<Poll> pollList = pollService.getPolls(pager); @@ -84,15 +84,6 @@ Map<String, Object> map = pollService.pollToMap(poll, binder); -// Map<String, Object> map = binder.obtainProperties( -// poll, -// Poll.PROPERTY_TITLE, -// Poll.PROPERTY_POLL_ID, -// Poll.PROPERTY_DESCRIPTION, -// Poll.PROPERTY_BEGIN_DATE, -// Poll.PROPERTY_END_DATE -// ); -// map.put("id", poll.getTopiaId()); map.put("moderateId", poll.getAdminId()); map.put("resultId", poll.getAdminId()); map.put("adminId", poll.getAdminId()); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.entities.PollenBinderHelper; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PollenActionSupport; import org.nuiton.util.beans.Binder; @@ -60,10 +59,9 @@ @Override public String execute() throws Exception { - UserService userService = newService(UserService.class); + UserAccount userAccount = getUserService().getEntityById( + UserAccount.class, userId); - UserAccount userAccount = userService.getEntityById(UserAccount.class, userId); - Binder<UserAccount, UserAccount> binder = PollenBinderHelper.getSimpleTopiaBinder(UserAccount.class); user = binder.obtainProperties( Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import com.google.common.collect.Sets; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.entities.PollenBinderHelper; -import org.chorem.pollen.services.impl.UserService; import org.nuiton.util.beans.Binder; import java.util.List; @@ -72,10 +71,8 @@ @Override public String execute() throws Exception { - UserService userService = newService(UserService.class); + List<UserAccount> allUsers = getUserService().getUsers(pager); - List<UserAccount> allUsers = userService.getUsers(pager); - UserAccount userAccount = getPollenUserAccount(); users = new Map[allUsers.size()]; Binder<UserAccount, UserAccount> binder = Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -39,7 +39,6 @@ import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.PollenServiceFunctions; -import org.chorem.pollen.services.impl.PollService; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollenActionSupport; @@ -88,8 +87,6 @@ private int reminderHourCountdown = 2; - private transient PollService pollService; - /** To create a new personToList. */ private transient Function<PersonToList, PersonToList> persontoListCreator; @@ -110,13 +107,6 @@ return PageSkin.EDITION; } - protected PollService getPollService() { - if (pollService == null) { - pollService = newService(PollService.class); - } - return pollService; - } - public Poll getPoll() { return poll; } @@ -204,15 +194,15 @@ } public String getPollVoteUrl() { - return getPollService().getPollVoteUrl(poll, false).getUrl(); + return getPollUrlService().getPollVoteUrl(poll, false).getUrl(); } public String getPollModerateUrl() { - return getPollService().getPollVoteUrl(poll, true).getUrl(); + return getPollUrlService().getPollVoteUrl(poll, true).getUrl(); } public String getPollEditUrl() { - return getPollService().getPollEditUrl(poll).getUrl(); + return getPollUrlService().getPollEditUrl(poll).getUrl(); } public int getSelectedTab() { @@ -234,18 +224,6 @@ return isEdit() && poll.sizeVote() > 0; } -// public boolean isPersonEditable(PersonToList personToList) { -// boolean result; -// // If vote is started, the person is editable if he hasn't vote yet -// if (isVoteStarted()) { -// result = !personToList.isHasVoted(); -// -// } else { -// result = true; -// } -// return result; -// } - public boolean isCreatorUserAccountDefined() { PollAccount creator = poll.getCreator(); return creator.getUserAccount() != null; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -59,8 +59,8 @@ } public final void setUriId(PollUri pollUri) { - if (log.isInfoEnabled()) { - log.info("PollUri : " + pollUri.getUri()); + if (log.isDebugEnabled()) { + log.debug("PollUri : " + pollUri.getUri()); } this.pollUri = pollUri; } @@ -70,8 +70,8 @@ } public final void setPage(int page) { - if (log.isInfoEnabled()) { - log.info("Page number : " + page); + if (log.isDebugEnabled()) { + log.debug("Page number : " + page); } this.page = page; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -42,11 +42,6 @@ import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.exceptions.PollAccountNotFound; import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.services.impl.PollCommentService; -import org.chorem.pollen.services.impl.PollFeedService; -import org.chorem.pollen.services.impl.PollResultsService; -import org.chorem.pollen.services.impl.PollService; -import org.chorem.pollen.services.impl.VoteService; import org.chorem.pollen.ui.actions.PageSkin; import java.util.Date; @@ -67,14 +62,6 @@ /** Logger. */ private static final Log log = LogFactory.getLog(AbstractVoteAction.class); - private transient PollResultsService pollResultsService; - - private transient PollService pollService; - - private transient VoteService voteService; - - private transient PollCommentService pollCommentService; - private Poll poll; private boolean feedFileExisting; @@ -106,34 +93,6 @@ return PageSkin.VOTE; } - protected PollResultsService getPollResultsService() { - if (pollResultsService == null) { - pollResultsService = newService(PollResultsService.class); - } - return pollResultsService; - } - - protected PollService getPollService() { - if (pollService == null) { - pollService = newService(PollService.class); - } - return pollService; - } - - protected VoteService getVoteService() { - if (voteService == null) { - voteService = newService(VoteService.class); - } - return voteService; - } - - protected PollCommentService getPollCommentService() { - if (pollCommentService == null) { - pollCommentService = newService(PollCommentService.class); - } - return pollCommentService; - } - @Override public void setParameters(Map<String, String[]> parameters) { this.parameters = parameters; @@ -298,8 +257,7 @@ loadPollResults(); loadPollComments(); - PollFeedService pollFeedService = newService(PollFeedService.class); - feedFileExisting = pollFeedService.isFeedExists(poll); + feedFileExisting = getPollFeedService().isFeedExists(poll); PollAccount pollCreator = poll.getCreator(); if (getPollenUserAccount() == null) { @@ -372,7 +330,11 @@ } public boolean isModifAllowed(Vote vote) { - return getVoteService().isUpdateAllowed(getPoll(), vote.getTopiaId(), getAccountId(), getPollenUserAccount()); + return getVoteService().isUpdateAllowed( + getPoll(), + vote.getTopiaId(), + getAccountId(), + getPollenUserAccount()); } public boolean isVoteAllowed() { @@ -380,11 +342,16 @@ } public boolean isDeleteCommentAllowed(Comment comment) { - return getPollCommentService().isCanDeleteComment(comment, getPollAccount(), getPollenUserAccount()); + return getPollCommentService().isCanDeleteComment( + comment, + getPollAccount(), + getPollenUserAccount(), + isCreatorUser()); } public boolean isDeleteVoteAllowed(Vote vote) { - return isUserAdmin(); + // can delete a vote if admin or poll creator + return isUserAdmin() || isCreatorUser(); } public String escapeLineBreak(String text) { @@ -398,7 +365,8 @@ protected void loadPollAccount() throws PollAccountNotFound { // Current poll account - pollAccount = getPollService().getPollAccountEditable(getAccountId(), getPollenUserAccount(), poll); + pollAccount = getPollService().getPollAccountEditable( + getAccountId(), getPollenUserAccount(), poll); } protected void loadPoll() throws PollNotFoundException { @@ -408,9 +376,10 @@ String pollId = getPollId(); if (StringUtils.isNotEmpty(pollId)) { - poll = getPollService().getPollByPollId(pollId); + poll = getPollService().getExistingPollByPollId(pollId); } - Preconditions.checkNotNull(poll, "Can't load poll with id = [" + pollId + "]"); + Preconditions.checkNotNull(poll, + "Can't load poll with id = [" + pollId + "]"); if (log.isDebugEnabled()) { log.debug("Poll TopiaId: " + poll.getTopiaId()); @@ -419,17 +388,14 @@ protected void loadPollComments() { - PollCommentService service = newService(PollCommentService.class); - - comments = service.getAllComments(poll.getPollId()); + comments = getPollCommentService().getAllComments(poll.getPollId()); } protected void loadPollResults() throws PollNotFoundException { - PollResultsService service = getPollResultsService(); + PollResultList pollResultList = + getPollResultsService().getResults(poll); - PollResultList pollResultList = service.getResults(poll.getPollId()); - results = pollResultList.getPollResults(); if (log.isDebugEnabled()) { Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -101,14 +101,16 @@ Object value = ChoiceHelper.toValue(choice, choiceType); // -- Validate value notEmpty - if (value == null || (value instanceof String && StringUtils.isBlank((String) value))) { + if (value == null || + (value instanceof String && StringUtils.isBlank((String) value))) { String typeLabel = getText(choiceType.getI18nKey()); addFieldError("choice." + propName, _("pollen.error.choice.empty", typeLabel)); } else { // Retrieve existing values to check if the new choice not already exists - Iterable<Object> pollChoiceValues = ChoiceHelper.toValues(getPoll().getChoice(), choiceType); + Iterable<Object> pollChoiceValues = ChoiceHelper.toValues( + getPoll().getChoice(), choiceType); // -- Validate value notExists if (Iterables.contains(pollChoiceValues, value)) { Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -38,6 +38,11 @@ private static final long serialVersionUID = 1L; + /** + * Text of the comment to add. + * + * @since 1.3 + */ private String commentText; public void setCommentText(String commentText) { @@ -78,6 +83,7 @@ // create the comment getPollCommentService().createComment(getPoll(), comment); + addFlashMessage(_("pollen.info.comment.added")); return SUCCESS; } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -23,8 +23,6 @@ */ package org.chorem.pollen.ui.actions.poll; -import org.chorem.pollen.services.impl.PollService; - /** * Closes an existing poll. * @@ -48,10 +46,10 @@ @Override public String execute() throws Exception { - PollService service = newService(PollService.class); + getPollService().closePoll(getPollId(), + getPollenUserAccount(), + getAccountId()); - service.closePoll(getPollId(), getPollenUserAccount(), getAccountId()); - addFlashMessage(_("pollen.information.poll.closed")); return SUCCESS; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.services.impl.PollService; /** * To confirm delete of a poll choice. @@ -57,10 +56,8 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(choiceId); - PollService service = newService(PollService.class); + Poll poll = getPollService().getExistingPollByPollId(pollId); - Poll poll = service.getPollByPollId(pollId); - choice = poll.getChoiceByTopiaId(choiceId); return SUCCESS; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,11 +25,6 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.business.persistence.Comment; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.services.exceptions.PollCommentNotFound; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.services.impl.PollCommentService; -import org.chorem.pollen.services.impl.PollService; /** * To confirm a comment delete. @@ -41,10 +36,18 @@ private static final long serialVersionUID = 1L; - /** Id of the comment. */ + /** + * Id of the comment. + * + * @since 1.3 + */ protected String commentId; - /** Comment to delete. */ + /** + * Loaded comment to delete. + * + * @since 1.3 + */ protected Comment comment; public void setCommentId(String commentId) { @@ -62,22 +65,10 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(commentId); - PollService pollService = newService(PollService.class); + getPollService().getExistingPollByPollId(pollId); - Poll poll = pollService.getPollByPollId(getPollId()); + comment = getPollCommentService().getExistingPollComment(commentId); - if (poll == null) { - throw new PollNotFoundException(); - } - - PollCommentService service = newService(PollCommentService.class); - - comment = service.getEntityById(Comment.class, commentId); - - if (comment == null) { - throw new PollCommentNotFound(); - } - return SUCCESS; } } \ No newline at end of file Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.Vote; -import org.chorem.pollen.services.impl.PollService; /** * To confirm delete of a poll vote @@ -38,8 +37,18 @@ private static final long serialVersionUID = 1L; + /** + * Id of the vote to delete. + * + * @since 1.3 + */ protected String voteId; + /** + * Loaded vote to delete. + * + * @since 1.3 + */ protected Vote vote; public void setVoteId(String voteId) { @@ -57,10 +66,8 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voteId); - PollService service = newService(PollService.class); + Poll poll = getPollService().getExistingPollByPollId(pollId); - Poll poll = service.getPollByPollId(pollId); - vote = poll.getVoteByTopiaId(voteId); return SUCCESS; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.services.impl.PollService; /** * To confirm a poll action (such as delete or close). @@ -57,7 +56,8 @@ public String execute() throws Exception { String pollId = getPollId(); Preconditions.checkNotNull(pollId); - poll = newService(PollService.class).getPollByPollId(pollId); + + poll = getPollService().getExistingPollByPollId(pollId); return SUCCESS; } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -24,7 +24,6 @@ package org.chorem.pollen.ui.actions.poll; import com.google.common.base.Preconditions; -import org.chorem.pollen.services.impl.PollService; /** * To delete a poll choice @@ -49,10 +48,9 @@ Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(choiceId); - PollService service = newService(PollService.class); + getPollService().deleteChoice(pollId, choiceId); - service.deleteChoice(pollId, choiceId); - + addFlashMessage(_("pollen.info.choice.deleted")); return SUCCESS; } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,12 +25,7 @@ import com.google.common.base.Preconditions; import com.opensymphony.xwork2.interceptor.annotations.InputConfig; -import org.chorem.pollen.business.persistence.Comment; import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.services.exceptions.PollCommentNotFound; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.services.impl.PollCommentService; -import org.chorem.pollen.services.impl.PollService; /** * To delete a poll comment. @@ -42,7 +37,11 @@ private static final long serialVersionUID = 1L; - /** Id of the comment to delete. */ + /** + * Id of the comment to delete. + * + * @since 1.3 + */ protected String commentId; /** @@ -64,26 +63,14 @@ @Override public String execute() throws Exception { - PollService pollService = newService(PollService.class); - - Poll poll = pollService.getPollByPollId(getPollId()); - - if (poll==null) { - throw new PollNotFoundException(); - } - + Preconditions.checkNotNull(getPollId()); Preconditions.checkNotNull(commentId); - PollCommentService service = newService(PollCommentService.class); + Poll poll = getPollService().getExistingPollByPollId(getPollId()); - Comment comment = service.getEntityById(Comment.class, commentId); + getPollCommentService().deleteComment(poll, commentId, reason); - if (comment == null) { - throw new PollCommentNotFound(); - } - - service.deleteComment(poll, commentId, reason); - + addFlashMessage(_("pollen.info.comment.deleted")); return SUCCESS; } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -23,8 +23,6 @@ */ package org.chorem.pollen.ui.actions.poll; -import org.chorem.pollen.services.impl.PollService; - /** * Deletes an existing poll. * @@ -48,9 +46,10 @@ @Override public String execute() throws Exception { - PollService service = newService(PollService.class); - service.deletePoll(getPollId(), getPollenUserAccount(), getAccountId()); + getPollService().deletePoll(getPollId(), + getPollenUserAccount(), + getAccountId()); return SUCCESS; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -24,7 +24,7 @@ package org.chorem.pollen.ui.actions.poll; import com.google.common.base.Preconditions; -import org.chorem.pollen.services.impl.VoteService; +import org.chorem.pollen.business.persistence.Poll; /** * To delete a poll vote. @@ -36,21 +36,39 @@ private static final long serialVersionUID = 1L; + /** + * Id of the vote to delete. + * + * @since 1.3 + */ protected String voteId; + /** + * Reason for deleting this vote (if any). + * + * @since 1.4 + */ + protected String reason; + public void setVoteId(String voteId) { this.voteId = voteId; } + public void setReason(String reason) { + this.reason = reason; + } + @Override public String execute() throws Exception { + Preconditions.checkNotNull(getPollId()); Preconditions.checkNotNull(voteId); - VoteService service = newService(VoteService.class); + Poll poll = getPollService().getExistingPollByPollId(getPollId()); - service.deleteVote(voteId); + getVoteService().deleteVote(poll, voteId, reason); + addFlashMessage(_("pollen.info.vote.deleted")); return SUCCESS; } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.persistence.PersonToList; -import org.chorem.pollen.services.impl.PollService; import org.chorem.pollen.ui.actions.PollenActionSupport; /** @@ -103,24 +102,8 @@ public String execute() throws Exception { if (personToList == null) { - personToList = newService(PollService.class).getNewPersonToList(null); + personToList = getPollService().getNewPersonToList(null); } - -// // consume personToList errors -// String token = getPersonToListErrorTokenId(tokenId, personToListNumber); -// Map<String, String> errors = getPollenSession().getDynamicData(token); -// if (MapUtils.isNotEmpty(errors)) { -// // transmit them as field errors -// for (Map.Entry<String, String> e : errors.entrySet()) { -// String fieldName = e.getKey(); -// String errorMessage = e.getValue(); -// if (log.isInfoEnabled()) { -// log.info("Transmit error on " + fieldName + " [" + errorMessage + "]"); -// } -// addFieldError(fieldName, errorMessage); -// } -// } -// getPollenSession().removeDynamicData(token); return SUCCESS; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import com.google.common.base.Preconditions; import org.apache.commons.io.IOUtils; -import org.chorem.pollen.services.impl.PollResultsService; import java.io.InputStream; @@ -63,10 +62,8 @@ String pollId = getPollId(); Preconditions.checkNotNull(pollId); - PollResultsService service = newService(PollResultsService.class); + String exportContent = getPollResultsService().exportPolltoXml(pollId); - String exportContent = service.exportPolltoXml(pollId); - filename = "exportPoll-" + pollId + ".xml"; contentLength = exportContent.length() * 2; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,9 +25,6 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.services.impl.PollFeedService; -import org.chorem.pollen.services.impl.PollService; import org.chorem.pollen.ui.actions.PollenActionSupport; import java.io.File; @@ -67,18 +64,10 @@ Preconditions.checkNotNull(pollId); - PollService service = newService(PollService.class); + Poll poll = getPollService().getExistingPollByPollId(pollId); - Poll poll = service.getPollByPollId(pollId); + File feedLocation = getPollFeedService().getFeedLocation(poll); - if (poll == null) { - throw new PollNotFoundException(); - } - - PollFeedService pollFeedService = newService(PollFeedService.class); - - File feedLocation = pollFeedService.getFeedLocation(poll); - contentLength = feedLocation.length(); inputStream = new FileInputStream(feedLocation); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -29,7 +29,6 @@ import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.services.PollenServiceFunctions; -import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.services.impl.PollService; import org.chorem.pollen.ui.actions.PollenActionSupport; @@ -91,9 +90,8 @@ @Override public String execute() throws Exception { - FavoriteService service = newService(FavoriteService.class); PersonList favoriteList = - service.getFavoriteList(getPollenUserAccount(), personListId); + getFavoriteService().getFavoriteList(getPollenUserAccount(), personListId); Function<PersonToList, PersonToList> persontoListCreator = PollenServiceFunctions.newPersonToListCreator(); @@ -103,7 +101,7 @@ votingList = votingListCreator.apply(null); - PollService pollService = newService(PollService.class); + PollService pollService = getPollService(); for (PollAccount pollAccount : favoriteList.getPollAccount()) { Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -44,7 +44,6 @@ import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.services.impl.PollResultsService; -import org.chorem.pollen.services.impl.PollService; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.converters.DateConverter; import org.nuiton.util.StringUtil; @@ -158,10 +157,8 @@ String pollId = getPollId(); Preconditions.checkNotNull(pollId); - PollService service = newService(PollService.class); + poll = getPollService().getExistingPollByPollId(pollId); - poll = service.getPollByPollId(pollId); - if (poll == null) { addFlashError(_("pollen.error.pollNotFound")); } else { @@ -252,10 +249,9 @@ protected void loadResults() throws PollNotFoundException { - PollResultsService service = newService(PollResultsService.class); + PollResultsService service = getPollResultsService(); - PollResultList resultListDTO = - service.getResults(poll.getPollId()); + PollResultList resultListDTO = service.getResults(poll); results = resultListDTO.getPollResults(); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -23,8 +23,8 @@ */ package org.chorem.pollen.ui.actions.poll; +import com.google.common.base.Preconditions; import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.services.impl.PollService; import org.chorem.pollen.ui.actions.PageSkin; /** @@ -37,19 +37,10 @@ private static final long serialVersionUID = 1L; - protected PollService pollService; - protected Poll poll; protected String pollResultUrl; - protected PollService getPollService() { - if (pollService == null) { - pollService = newService(PollService.class); - } - return pollService; - } - @Override public PageSkin getSkin() { return PageSkin.EDITION; @@ -67,10 +58,11 @@ public String execute() throws Exception { String pollUid = getPollId(); + Preconditions.checkNotNull(pollUid); - poll = getPollService().getPollByPollId(pollUid); + poll = getPollService().getExistingPollByPollId(pollUid); - pollResultUrl = getPollService().getPollResultUrl(poll).getUrl(); + pollResultUrl = getPollUrlService().getPollResultUrl(poll).getUrl(); return SUCCESS; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -243,8 +243,7 @@ poll.clearPreventRule(); - PreventRuleService preventRuleService = - newService(PreventRuleService.class); + PreventRuleService preventRuleService = getPreventRuleService(); if (isNotification()) { // add a notification rule @@ -752,7 +751,7 @@ // add personToList maps to session (but just now, since votingList // could have been reindex) for (Map.Entry<Integer, VotingList> entry : result.entrySet()) { - Integer votingListNumber = entry.getKey(); +// Integer votingListNumber = entry.getKey(); VotingList votingList = entry.getValue(); if (!votingList.isPollAccountPersonToListEmpty()) { Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -27,7 +27,6 @@ import org.chorem.pollen.PollenFunctions; import org.chorem.pollen.business.persistence.PersonList; import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.ui.actions.PollenActionSupport; import java.util.List; @@ -82,9 +81,9 @@ @Override public String execute() throws Exception { - FavoriteService service = newService(FavoriteService.class); UserAccount userAccount = getPollenUserAccount(); - List<PersonList> personLists = service.getFavoriteLists(userAccount); + List<PersonList> personLists = + getFavoriteService().getFavoriteLists(userAccount); personList = Maps.uniqueIndex(personLists, PollenFunctions.ENTITY_BY_ID); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -28,12 +28,13 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.bean.PollUri; +import org.chorem.pollen.bean.PollUrl; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.common.PollType; +import org.chorem.pollen.services.impl.VoteService; /** * Votes to a poll. @@ -75,7 +76,7 @@ // check if the new pollAccount (topiaId = null) has already voted if (pollAccount.getTopiaId() == null && - getVoteService().hasAlreadyVoted(name, poll)) { + getVoteService().hasAlreadyVoted(poll, name)) { addFieldError("pollAccount.votingId", _("pollen.error.user.alreadyVoted")); } @@ -131,25 +132,33 @@ // - pas le droit de modif si le pollAccount est rattaché a un userAccount et qu'on est pas loggé ?!? // - Ce serait plus simple que l'Admin ne puisse jamais voter, il ne peut que modérer les votes - if (getVote().getTopiaId() != null) { - getVoteService().updateVote(getVote()); + Poll poll = getPoll(); + Vote vote = getVote(); + + VoteService voteService = getVoteService(); + + if (vote.getTopiaId() == null) { + + // create a new vote + voteService.createVote(poll, vote); } else { - Vote voteCreated = getVoteService().createVote(getVote()); - getPollService().addVoteToPoll(getPoll(), voteCreated); + + // update existing vote + voteService.updateVote(poll, vote); } //TODO tchemit-2012-05-18 Why clean messages and just messages here ? clearFlashMessages(); // For free Poll, display the update Url (useless if user is logged) - if (PollType.FREE == getPoll().getPollType() && !isUserLoggued()) { + if (PollType.FREE == poll.getPollType() && !isUserLoggued()) { - String pollId = getPoll().getPollId(); + String pollId = poll.getPollId(); String accountId = getPollAccount().getAccountId(); - PollUri pollUri = PollUri.newPollUri(pollId, accountId); +// PollUri pollUri = PollUri.newPollUri(pollId, accountId); - String updateUrl = getVoteService().getUpdateVoteUrl(pollUri); + PollUrl updateUrl = getPollUrlService().getPollVoteUrl(poll, true); if (log.isDebugEnabled()) { log.debug(String.format( Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.business.persistence.PersonList; import org.chorem.pollen.business.persistence.PollAccount; -import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.ui.actions.PollenActionSupport; /** @@ -76,20 +75,18 @@ @Override public String execute() throws Exception { - FavoriteService service = newService(FavoriteService.class); - if (StringUtils.isNotEmpty(favoriteListId)) { // load favorite list - favoriteList = service.getEntityById(PersonList.class, - favoriteListId); + favoriteList = getFavoriteService().getEntityById(PersonList.class, + favoriteListId); } if (StringUtils.isNotEmpty(pollAccountId)) { // load poll account - pollAccount = service.getEntityById(PollAccount.class, - pollAccountId); + pollAccount = getFavoriteService().getEntityById(PollAccount.class, + pollAccountId); } return SUCCESS; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -62,7 +62,7 @@ String result = INPUT; try { - FavoriteService service = newService(FavoriteService.class); + FavoriteService service = getFavoriteService(); PersonList favoriteList = service.getEntityById( PersonList.class, favoriteListId); @@ -70,8 +70,6 @@ PersonList deletedFavoritedList = service.deleteFavoriteList( getPollenUserAccount(), favoriteList); - getTransaction().commitTransaction(); - addFlashMessage(_("pollen.information.favoriteList.deleted", deletedFavoritedList.getName())); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -65,7 +65,7 @@ Preconditions.checkNotNull(pollAccountId); - FavoriteService service = newService(FavoriteService.class); + FavoriteService service = getFavoriteService(); PersonList favoriteList = service.getEntityById(PersonList.class, favoriteListId); @@ -75,8 +75,6 @@ service.removePollAccountToFavoriteList(favoriteList, pollAccount); - getTransaction().commitTransaction(); - addFlashMessage( _("pollen.information.pollAccount.removedFromFavoriteList", pollAccount.getVotingId())); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.services.exceptions.UserEmailAlreadyUsedException; import org.chorem.pollen.services.exceptions.UserInvalidPasswordException; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollenActionSupport; @@ -53,8 +52,7 @@ public UserAccount getUser() { if (user == null) { - UserService service = newService(UserService.class); - user = service.getNewUser(); + user = getUserService().getNewUser(); } return user; } @@ -77,8 +75,8 @@ public String input() throws Exception { UserAccount userAccount = getPollenUserAccount(); - UserService userService = newService(UserService.class); - user = userService.getEntityById(UserAccount.class, userAccount.getTopiaId()); + user = getUserService().getEntityById(UserAccount.class, + userAccount.getTopiaId()); return INPUT; } @@ -89,13 +87,10 @@ user.setAdministrator( getPollenUserAccount().isAdministrator()); - UserService service = newService(UserService.class); - String result = INPUT; try { UserAccount updatedUser = - service.updateUser(user, newPassword, false); - getTransaction().commitTransaction(); + getUserService().updateUser(user, newPassword, false); // push back user to session getPollenSession().setUserAccount(updatedUser); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Login.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Login.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Login.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -27,7 +27,6 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.services.exceptions.UserInvalidPasswordException; import org.chorem.pollen.services.exceptions.UserNotFoundException; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PollenActionSupport; /** @@ -75,14 +74,13 @@ @Override public String execute() throws Exception { - UserService service = newService(UserService.class); - if (StringUtils.isBlank(login) || StringUtils.isBlank(password)) { addFlashError(_("pollen.error.user.bad.login.or.password")); } else { try { - UserAccount userAccount = service.connect(login, password); + UserAccount userAccount = + getUserService().connect(login, password); getPollenSession().setUserAccount(userAccount); addFlashMessage(_("pollen.information.your.are.loggued")); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/LostPassword.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/LostPassword.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/LostPassword.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.services.exceptions.UserNotFoundException; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PollenActionSupport; import org.nuiton.util.StringUtil; @@ -57,9 +56,8 @@ } else { - UserService service = newService(UserService.class); try { - service.lostPassword(email); + getUserService().lostPassword(email); addFlashMessage(_("pollen.information.lostPassword.success")); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -99,10 +99,8 @@ action = actions[0]; } - FavoriteService service = newService(FavoriteService.class); - try { - favoriteList = service.getFavoriteList( + favoriteList = getFavoriteService().getFavoriteList( getPollenUserAccount(), favoriteListId); } catch (FavoriteListNotFoundException e) { addFlashError(_("pollen.error.favoriteList.not.found")); @@ -118,12 +116,10 @@ String result = INPUT; - FavoriteService service = newService(FavoriteService.class); - try { - service.addPollAccountToFavoriteList(favoriteList, pollAccount); - getTransaction().commitTransaction(); + getFavoriteService().addPollAccountToFavoriteList( + favoriteList, pollAccount); addFlashMessage( _("pollen.information.pollAccount.addedTofavoriteList", @@ -146,12 +142,10 @@ String result = INPUT; - FavoriteService service = newService(FavoriteService.class); - try { - service.editPollAccountToFavoriteList(favoriteList, pollAccount); - getTransaction().commitTransaction(); + getFavoriteService().editPollAccountToFavoriteList( + favoriteList, pollAccount); addFlashMessage( _("pollen.information.pollAccount.updatedTofavoriteList", @@ -173,11 +167,9 @@ Preconditions.checkNotNull(pollAccount); Preconditions.checkNotNull(pollAccount.getTopiaId()); - FavoriteService service = newService(FavoriteService.class); + getFavoriteService().removePollAccountToFavoriteList( + favoriteList, pollAccount); - service.removePollAccountToFavoriteList(favoriteList, pollAccount); - getTransaction().commitTransaction(); - addFlashMessage( _("pollen.information.pollAccount.removedFromFavoriteList", pollAccount.getVotingId())); @@ -190,8 +182,7 @@ protected PollAccount getPollAccount() { if (pollAccount == null) { - FavoriteService service = newService(FavoriteService.class); - pollAccount = service.newPollAccountForFavoriteList(); + pollAccount = getFavoriteService().newPollAccountForFavoriteList(); } return pollAccount; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -34,7 +34,6 @@ import org.chorem.pollen.services.exceptions.ParticipantAlreadyFoundInListException; import org.chorem.pollen.services.impl.FavoriteListImportCSV; import org.chorem.pollen.services.impl.FavoriteListImportLDAP; -import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollenActionSupport; @@ -63,15 +62,6 @@ protected String action; - private FavoriteService favoriteService; - - public FavoriteService getFavoriteService() { - if (favoriteService == null) { - favoriteService = newService(FavoriteService.class); - } - return favoriteService; - } - public void setCsvImport(File csvImport) { this.csvImport = csvImport; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-06-03 15:40:54 UTC (rev 3416) @@ -26,7 +26,6 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.services.exceptions.UserEmailAlreadyUsedException; import org.chorem.pollen.services.exceptions.UserLoginAlreadyUsedException; -import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollenActionSupport; @@ -46,8 +45,7 @@ public UserAccount getUser() { if (user == null) { - UserService service = newService(UserService.class); - user = service.getNewUser(); + user = getUserService().getNewUser(); } return user; } @@ -70,8 +68,7 @@ String result = INPUT; try { - UserAccount createdUser = - newService(UserService.class).createUser(user, false); + UserAccount createdUser = getUserService().createUser(user, false); getPollenSession().setUserAccount(createdUser); addFlashMessage(_("pollen.information.your.are.loggued")); Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-03 15:40:54 UTC (rev 3416) @@ -25,7 +25,6 @@ pollen.action.editPollAccount=Edit selected member pollen.action.editUser=Edit selected user pollen.action.editVote=Modifier le vote -pollen.common.deleteReason=Reason for delete pollen.action.importPersonListToExistingVotingList=Add selected voting list pollen.action.importPersonListToNewVotingList=Create a new group from the selected voting list pollen.action.login=Log me In @@ -70,6 +69,7 @@ pollen.common.datePattern= pollen.common.datePickerPattern=mm/dd/yy pollen.common.dateTimePattern= +pollen.common.deleteReason=Reason for delete pollen.common.description=Description pollen.common.displayType-group=Results by groups pollen.common.displayType-normal=Results @@ -210,6 +210,10 @@ pollen.fieldset.userInformation.toDelete=User informations to delete pollen.fieldset.userInformation.toUpdate=User informations to update pollen.image.not.loaded=Image not loaded +pollen.info.choice.deleted=Choice deleted +pollen.info.comment.added=Comment added +pollen.info.comment.deleted=Comment deleted +pollen.info.vote.deleted=Vote deleted pollen.information.confirmClonePoll=Confirm clone of poll\: pollen.information.confirmClosePoll=Confirm close of poll\: pollen.information.confirmDeleteFavoriteList=Confirm delete of favorite list\: Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-03 15:40:54 UTC (rev 3416) @@ -24,7 +24,6 @@ pollen.action.editPoll=Modifier le sondage pollen.action.editPollAccount=Editer le membre sélectionné pollen.action.editUser=Editer un utilisateur sélectionné -pollen.common.deleteReason=Raison de suppression pollen.action.editVote=Modifier le vote pollen.action.importPersonListToExistingVotingList=Ajouter la liste sélectionnée de votants pollen.action.importPersonListToNewVotingList=Créer un groupe à partir de la liste sélectionnée @@ -70,6 +69,7 @@ pollen.common.datePattern= pollen.common.datePickerPattern=dd/mm/yy pollen.common.dateTimePattern= +pollen.common.deleteReason=Raison de suppression pollen.common.description=Description pollen.common.displayType-group=Résultats par groupes pollen.common.displayType-normal=Résultats @@ -210,6 +210,10 @@ pollen.fieldset.userInformation.toDelete=Informations de l'utilisateur à supprimer pollen.fieldset.userInformation.toUpdate=Informations de l'utilisateur à mettre à jour pollen.image.not.loaded=Image non chargée +pollen.info.choice.deleted=Choix supprimé +pollen.info.comment.added=Commentaire ajouté +pollen.info.comment.deleted=Commentaire supprimé +pollen.info.vote.deleted=Vote supprimé pollen.information.confirmClonePoll=Confirmer le clonage du sondage \: pollen.information.confirmClosePoll=Confirmer la fermeture du sondage \: pollen.information.confirmDeleteFavoriteList=Confirmer la suppression de la liste de votants \: Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp 2012-06-03 11:15:13 UTC (rev 3415) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp 2012-06-03 15:40:54 UTC (rev 3416) @@ -35,6 +35,9 @@ </s:param> </s:text>. + <s:textarea key='reason' rows="3" required="true" + label="%{getText('pollen.common.deleteReason')}"/> + <hr/> <div align="right">
participants (1)
-
tchemit@users.chorem.org