Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
February 2012
- 1 participants
- 27 discussions
r3143 - branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui
by tchemit@users.chorem.org 22 Feb '12
by tchemit@users.chorem.org 22 Feb '12
22 Feb '12
Author: tchemit
Date: 2012-02-22 23:54:14 +0100 (Wed, 22 Feb 2012)
New Revision: 3143
Url: http://chorem.org/repositories/revision/pollen/3143
Log:
build fix2
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-02-22 22:40:53 UTC (rev 3142)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-02-22 22:54:14 UTC (rev 3143)
@@ -25,7 +25,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.ServletActionContext;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.PollenTechnicalException;
import org.chorem.pollen.PollenTopiaRootContextFactory;
@@ -43,7 +42,6 @@
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-import java.net.URL;
import java.util.Date;
import java.util.Locale;
@@ -80,13 +78,6 @@
I18n.init(i18nInitializer, Locale.getDefault());
PollenApplicationContext applicationContext = new PollenApplicationContext();
-
- URL url = PollenUIUtils.getApplicationBase(ServletActionContext.getRequest());
- if (log.isInfoEnabled()) {
- log.info("Pollen application url : " + url);
- }
- applicationContext.setApplicationUrl(url);
-
sce.getServletContext().setAttribute(PollenActionSupport.APPLICATION_CONTEXT_PARAMETER, applicationContext);
// initialize configuration
1
0
r3142 - branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui
by tchemit@users.chorem.org 22 Feb '12
by tchemit@users.chorem.org 22 Feb '12
22 Feb '12
Author: tchemit
Date: 2012-02-22 23:40:53 +0100 (Wed, 22 Feb 2012)
New Revision: 3142
Url: http://chorem.org/repositories/revision/pollen/3142
Log:
fix build
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-02-22 22:25:51 UTC (rev 3141)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-02-22 22:40:53 UTC (rev 3142)
@@ -156,7 +156,8 @@
Locale.getDefault(),
transaction,
configuration,
- serviceFactory
+ serviceFactory,
+ null
);
UserService service =
1
0
22 Feb '12
Author: tchemit
Date: 2012-02-22 23:25:51 +0100 (Wed, 22 Feb 2012)
New Revision: 3141
Url: http://chorem.org/repositories/revision/pollen/3141
Log:
- add application url in service context
- vote comment is ok
- Anomalie #119: [Comment] Pas de message de confirmation lors de la suppression d'un commentaire
- Anomalie #175: [Comment] Impossible de supprimer des commentaires (ou alors c'est tr?\195?\168s long)
- Anomalie #172: [Comment] Pagination des commentaires
- Anomalie #171: [Comment] Ordre des commentaires bizarre
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollcomment.jsp
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Vote.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -25,6 +25,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.ServletActionContext;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.PollenTechnicalException;
import org.chorem.pollen.PollenTopiaRootContextFactory;
@@ -42,6 +43,7 @@
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import java.net.URL;
import java.util.Date;
import java.util.Locale;
@@ -78,6 +80,13 @@
I18n.init(i18nInitializer, Locale.getDefault());
PollenApplicationContext applicationContext = new PollenApplicationContext();
+
+ URL url = PollenUIUtils.getApplicationBase(ServletActionContext.getRequest());
+ if (log.isInfoEnabled()) {
+ log.info("Pollen application url : " + url);
+ }
+ applicationContext.setApplicationUrl(url);
+
sce.getServletContext().setAttribute(PollenActionSupport.APPLICATION_CONTEXT_PARAMETER, applicationContext);
// initialize configuration
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -160,7 +160,8 @@
getLocale(),
getTransaction(),
getConfiguration(),
- getServiceFactory()
+ getServiceFactory(),
+ getApplicationUrl()
);
}
return serviceContext;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -80,7 +80,7 @@
String result = INPUT;
try {
- service.createUser(user, true, getApplicationUrl());
+ service.createUser(user, true);
getTransaction().commitTransaction();
addActionMessage(
_("pollen.information.user.created",
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -24,7 +24,9 @@
package org.chorem.pollen.ui.actions.json;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
import org.chorem.pollen.business.persistence.Comment;
+import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.entities.PollenBinderHelper;
import org.chorem.pollen.services.impl.PollCommentService;
@@ -32,6 +34,7 @@
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Get paginated list of poll comments.
@@ -97,15 +100,29 @@
Comment.PROPERTY_TEXT,
Comment.PROPERTY_POST_DATE
);
- map.put("name", comment.getPollAccount().getVotingId());
+ map.put(Comment.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_VOTING_ID,
+ comment.getPollAccount().getVotingId());
map.put("id", comment.getTopiaId());
- boolean canDelete = pollService.isCanDeleteComment(comment,
- userAccount);
- map.put("canDelete", canDelete);
+ Set<String> functions = getCommentFunctions(pollService,
+ comment,
+ userAccount);
+ map.put("functions", functions);
comments[index++] = map;
}
return SUCCESS;
}
+ private Set<String> getCommentFunctions(PollCommentService pollService,
+ Comment comment,
+ UserAccount userAccount) {
+ Set<String> result = Sets.newHashSet();
+ boolean canDelete = pollService.isCanDeleteComment(comment,
+ userAccount);
+ if (canDelete) {
+ result.add("delete");
+ }
+ return result;
+ }
+
}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -0,0 +1,142 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.common.VoteCountingType;
+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;
+
+/**
+ * Abstract action for actions on the vote poll page.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public abstract class AbstractVoteAction extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String pollId;
+
+ protected Poll poll;
+
+ protected boolean feedFileExisting;
+
+ protected String voteCountingTypeHelp;
+
+ protected String defaultCommentName;
+
+ protected String creatorName;
+
+ protected String commentName;
+
+ @Override
+ public final String getPageLogo() {
+ return "Vote";
+ }
+
+ public final String getPollId() {
+ return pollId;
+ }
+
+ public final void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public final Poll getPoll() {
+ return poll;
+ }
+
+ public final boolean isFeedFileExisting() {
+ return feedFileExisting;
+ }
+
+ public final String getVoteCountingTypeHelp() {
+ return voteCountingTypeHelp;
+ }
+
+ public final String getDefaultCommentName() {
+ return defaultCommentName;
+ }
+
+ public final String getCommentName() {
+ return commentName;
+ }
+
+ public void prepareVotePage() throws Exception {
+
+ loadPoll();
+
+ PollFeedService pollFeedService = newService(PollFeedService.class);
+
+ feedFileExisting = pollFeedService.isFeedExists(poll);
+
+ VoteCountingType voteCountingType = poll.getVoteCountingType();
+ switch (voteCountingType) {
+
+ case NORMAL:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.normal");
+ break;
+ case PERCENTAGE:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.percentage");
+ break;
+ case CONDORCET:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.condorcet");
+ break;
+ case NUMBER:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.number");
+ break;
+ }
+
+ // set default comment name
+ UserAccount userAccount = getPollenSession().getUserAccount();
+ if (userAccount == null) {
+ defaultCommentName = "";
+ } else {
+ defaultCommentName = userAccount.getDisplayName();
+ }
+ }
+
+ protected void loadPoll() throws PollNotFoundException {
+
+ Preconditions.checkNotNull(pollId);
+
+ PollService service = newService(PollService.class);
+
+ poll = service.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -24,11 +24,10 @@
package org.chorem.pollen.ui.actions.poll;
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.business.persistence.PollAccount;
import org.chorem.pollen.services.impl.PollCommentService;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
/**
* To add a poll comment.
@@ -36,63 +35,51 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class AddComment extends PollenActionSupport {
+public class AddComment extends AbstractVoteAction {
private static final long serialVersionUID = 1L;
- protected String pollId;
+ /** Text of the comment. */
+ protected String commentText;
- protected String name;
-
- protected String text;
-
- public String getPollId() {
- return pollId;
+ public void setCommentName(String commentName) {
+ this.commentName = commentName;
}
- public void setPollId(String pollId) {
- this.pollId = pollId;
+ public String getCommentText() {
+ return commentText;
}
- public String getName() {
- return name;
+ public void setCommentText(String commentText) {
+ this.commentText = commentText;
}
- public void setName(String name) {
- this.name = name;
- }
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
+ @InputConfig(methodName = "prepareVotePage")
@Override
public String execute() throws Exception {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(text);
- Preconditions.checkNotNull(name);
+ loadPoll();
+ Preconditions.checkNotNull(commentName);
+ Preconditions.checkNotNull(commentText);
+
PollCommentService service = newService(PollCommentService.class);
- Poll poll = service.getEntityById(Poll.class, pollId);
-
// prepare a new poll account for the comment
PollAccount pollAccount = service.getNewPollAccount(
- getPollenSession().getUserAccount(), name);
+ getPollenSession().getUserAccount(), commentName);
// prepare a new comment
- Comment comment = service.getNewComment(pollAccount, text);
+ Comment comment = service.getNewComment(pollAccount, commentText);
// create the comment
service.createComment(poll, comment);
getTransaction().commitTransaction();
+ // let's use back default comment name
+ commentName = getDefaultCommentName();
return SUCCESS;
}
+
}
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -0,0 +1,71 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.business.persistence.Comment;
+import org.chorem.pollen.services.exceptions.PollCommentNotFound;
+import org.chorem.pollen.services.impl.PollCommentService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * To confirm a comment delete.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ConfirmDeleteComment extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Id of the comment. */
+ protected String commentId;
+
+ /** Comment to delete. */
+ protected Comment comment;
+
+ public void setCommentId(String commentId) {
+ this.commentId = commentId;
+ }
+
+ public Comment getComment() {
+ return comment;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(commentId);
+
+ 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
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -24,8 +24,10 @@
package org.chorem.pollen.ui.actions.poll;
import com.google.common.base.Preconditions;
+import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
+import org.chorem.pollen.business.persistence.Comment;
+import org.chorem.pollen.services.exceptions.PollCommentNotFound;
import org.chorem.pollen.services.impl.PollCommentService;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
/**
* To delete a poll comment.
@@ -33,27 +35,39 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class DeleteComment extends PollenActionSupport {
+public class DeleteComment extends AbstractVoteAction {
private static final long serialVersionUID = 1L;
- protected String pollId;
-
+ /** Id of the comment to delete. */
protected String commentId;
+ public void setCommentId(String commentId) {
+ this.commentId = commentId;
+ }
+ @InputConfig(methodName = "prepareVotePage")
@Override
public String execute() throws Exception {
- Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(commentId);
PollCommentService service = newService(PollCommentService.class);
+ Comment comment = service.getEntityById(Comment.class, commentId);
+
+ if (comment == null) {
+ throw new PollCommentNotFound();
+ }
+
+ setPollId(comment.getPoll().getPollId());
+
service.deleteComment(commentId);
getTransaction().commitTransaction();
+ commentName = getDefaultCommentName();
+
return SUCCESS;
}
}
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+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;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * Obtain the feed of a given poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class GetFeed extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String pollId;
+
+ protected long contentLength;
+
+ protected transient InputStream stream;
+
+ public String getPollId() {
+ return pollId;
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public InputStream getStream() {
+ return stream;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollId);
+
+ PollService service = newService(PollService.class);
+
+ Poll poll = service.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+
+ PollFeedService pollFeedService = newService(PollFeedService.class);
+
+ File feedLocation = pollFeedService.getFeedLocation(poll);
+
+ contentLength = feedLocation.length();
+
+ stream = new FileInputStream(feedLocation);
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Vote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Vote.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Vote.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -23,7 +23,7 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
+import com.opensymphony.xwork2.Preparable;
/**
* Votes to a poll.
@@ -31,7 +31,29 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class Vote extends PollenActionSupport {
+public class Vote extends AbstractVoteAction implements Preparable {
private static final long serialVersionUID = 1L;
+
+ @Override
+ public String input() throws Exception {
+
+ //TODO DO me!
+ return INPUT;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ //TODO Do me!
+
+ return SUCCESS;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ prepareVotePage();
+ commentName = getDefaultCommentName();
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-02-22 22:25:51 UTC (rev 3141)
@@ -70,7 +70,7 @@
String result = INPUT;
try {
- UserAccount createdUser = service.createUser(user, false, getApplicationUrl());
+ UserAccount createdUser = service.createUser(user, false);
getTransaction().commitTransaction();
getPollenSession().setUserAccount(createdUser);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml 2012-02-22 22:25:51 UTC (rev 3141)
@@ -101,6 +101,13 @@
<result type="json"/>
</action>
+ <!-- get pagined poll comments -->
+ <action name="getPollComments"
+ class="org.chorem.pollen.ui.actions.json.GetPollComments">
+ <interceptor-ref name="pollenBasicStack"/>
+ <result type="json"/>
+ </action>
+
</package>
</struts>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-02-22 22:25:51 UTC (rev 3141)
@@ -32,6 +32,16 @@
<package name="poll" extends="default" namespace="/poll">
+ <result-types>
+ <result-type name="redirectToVote"
+ class="org.apache.struts2.dispatcher.ServletActionRedirectResult">
+ <param name="namespace">/poll</param>
+ <param name="actionName">vote</param>
+ <param name="method">input</param>
+ <param name="pollId">${pollId}</param>
+ </result-type>
+ </result-types>
+
<!-- create poll -->
<action name="create"
class="org.chorem.pollen.ui.actions.poll.Create">
@@ -104,20 +114,35 @@
<result>/WEB-INF/jsp/home.jsp</result>
</action>
+ <!-- confirm delete comment -->
+ <action name="confirmDeleteComment"
+ class="org.chorem.pollen.ui.actions.poll.ConfirmDeleteComment">
+ <result>/WEB-INF/jsp/poll/confirmDeletePollcomment.jsp</result>
+ </action>
+
<!-- add a poll comment -->
<action name="addComment"
class="org.chorem.pollen.ui.actions.poll.AddComment">
<result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
- <result>/WEB-INF/jsp/poll/vote.jsp</result>
+ <result type="redirectToVote"/>
</action>
<!-- delete a poll comment -->
<action name="deleteComment"
class="org.chorem.pollen.ui.actions.poll.DeleteComment">
- <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
- <result>/WEB-INF/jsp/poll/vote.jsp</result>
+ <result type="redirectToVote"/>
</action>
+ <!-- get the feed of a given poll -->
+ <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetFeed">
+ <result type="stream">
+ <param name="contentCharSet">UTF-8</param>
+ <param name="contentType">application/atom+xml</param>
+ <param name="encode">true</param>
+ <param name="bufferSize">4096</param>
+ </result>
+ </action>
+
</package>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-02-22 22:25:51 UTC (rev 3141)
@@ -1,5 +1,11 @@
+poll.common.aboutPoll=About the poll
+poll.common.comments=Comments about this poll
poll.common.select.choiceType=Select the type of choice
poll.common.select.userFavoriteList=List
+poll.common.vote.results=Results
+poll.common.vote.results-help=Display results
+poll.legend.addNewComment=Add a comment
+pollen.action.addComment=Add
pollen.action.backToFavoriteLists=Back to favorite lists
pollen.action.create=Create
pollen.action.createFavoriteList=Create a new list
@@ -17,6 +23,7 @@
pollen.action.modify=Modify
pollen.action.pollClone=Copy the poll to create a new one
pollen.action.pollClose=Close the poll
+pollen.action.pollCommentDelete=Supprimer le commentaire
pollen.action.pollDelete=Delete the poll
pollen.action.pollEdit=Edit poll
pollen.action.pollExport=Export poll
@@ -29,6 +36,8 @@
pollen.common.beginChoiceDate=Begin choice date
pollen.common.beginDate=Begin date
pollen.common.bugReport=Bug report
+pollen.common.commentName=Name
+pollen.common.commentText=Comment
pollen.common.csvImport=CSV import
pollen.common.description=Description
pollen.common.email=Em@il
@@ -47,6 +56,7 @@
pollen.common.or=or
pollen.common.password=Password
pollen.common.password2=Renter your password
+pollen.common.pollCreator=Creator
pollen.common.pollOption.anonymous=Anonymous
pollen.common.pollOption.anonymousVoteAllowed=Anonymous vote allowed
pollen.common.pollOption.choiceAddAllowed=Allow adding choices
@@ -59,9 +69,14 @@
pollen.common.pollOption.reminder=Send reminder emails
pollen.common.pollOption.reminderHourCountdown=Hours before end
pollen.common.pollType=Poll type
+pollen.common.postDate=Comment date
pollen.common.title=Title
pollen.common.userSupport=User support
pollen.common.voteCountingType=Counting type
+pollen.common.voteCountingTypeHelp.condorcet=Condorcet vote\: rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
+pollen.common.voteCountingTypeHelp.normal=Normal vote\: vote for your favorite choice.
+pollen.common.voteCountingTypeHelp.number=Voting by number\: The answer is free, leave blank or enter a integer.
+pollen.common.voteCountingTypeHelp.percentage=Percentage vote\: allocate choices to get a 100%% total.
pollen.error.comment.name.empty=Comment name mandatory
pollen.error.comment.text.empty=Comment text mandatory
pollen.error.email.required=You must provide an email
@@ -72,6 +87,7 @@
pollen.error.favoriteList.participant.not.found.in.list=Member not found in favorite list
pollen.error.favoriteListName.required=List name mandatory
pollen.error.login.required=You must provide a login
+pollen.error.no.poll.found=Poll not found with id %s
pollen.error.password.required=Your must provide a password
pollen.error.password2.required=You must repeat your password for confirmation
pollen.error.passwords.not.equals=Les deux mots de passe saisis non identiques
@@ -124,6 +140,7 @@
pollen.menu.register=Register
pollen.menu.userFavoriteLists=Voting lists
pollen.title.createPoll=New poll
+pollen.title.delete.comment=Confirm to delete a poll comment
pollen.title.editFavoriteList=Edition de la liste des favoris
pollen.title.favoriteLists=Vos listes de votants
pollen.title.myAccount=My account
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-02-22 22:25:51 UTC (rev 3141)
@@ -1,5 +1,11 @@
+poll.common.aboutPoll=A propos du sondage
+poll.common.comments=Commentaire à propos du sondage
poll.common.select.choiceType=Sélectionner le type de choix
poll.common.select.userFavoriteList=Liste
+poll.common.vote.results=Résultats
+poll.common.vote.results-help=Voir les résultats
+poll.legend.addNewComment=Ajouter un commentaire
+pollen.action.addComment=Ajouter
pollen.action.backToFavoriteLists=Retour à la liste des favoris
pollen.action.create=Créer
pollen.action.createFavoriteList=Créer une ouvelle liste
@@ -17,6 +23,7 @@
pollen.action.modify=Modifier
pollen.action.pollClone=Créer un nouveau sondage à partir de celui-ci
pollen.action.pollClose=Fermer le sondage
+pollen.action.pollCommentDelete=Supprimer le commentaire
pollen.action.pollDelete=Supprimer le sondage
pollen.action.pollEdit=Editer le sondage
pollen.action.pollExport=Exporter le sondage
@@ -29,6 +36,8 @@
pollen.common.beginChoiceDate=Date de début des choix
pollen.common.beginDate=Date de début
pollen.common.bugReport=Rapport de bug
+pollen.common.commentName=Nom
+pollen.common.commentText=Commentaire
pollen.common.csvImport=Import CSV
pollen.common.description=Description
pollen.common.email=Em@il
@@ -47,6 +56,7 @@
pollen.common.or=ou
pollen.common.password=Mot de passe
pollen.common.password2=Répétez votre mot de passe
+pollen.common.pollCreator=Créateur
pollen.common.pollOption.anonymous=Sondage anonyme
pollen.common.pollOption.anonymousVoteAllowed=Autoriser le vote anonyme
pollen.common.pollOption.choiceAddAllowed=Autoriser l'ajout de choix
@@ -59,9 +69,14 @@
pollen.common.pollOption.reminder=Envoyer des emails de rappel
pollen.common.pollOption.reminderHourCountdown=heures avant la fin du sondage
pollen.common.pollType=Type de sondage
+pollen.common.postDate=Date du commentaire
pollen.common.title=Titre
pollen.common.userSupport=Support utilisateur
pollen.common.voteCountingType=Type de dépouillement
+pollen.common.voteCountingTypeHelp.condorcet=Vote Condorcet \: classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
+pollen.common.voteCountingTypeHelp.normal=Vote normal \: voter pour le ou les choix préférés.
+pollen.common.voteCountingTypeHelp.number=Vote par nombre \: La réponse est libre, laissez vide ou entrez un nombre entier
+pollen.common.voteCountingTypeHelp.percentage=Vote par pourcentage \: répartir les choix de manière à obtenir 100%% au total.
pollen.common.x=Dépouillement
pollen.error.comment.name.empty=Nom du commentaire obligatoire
pollen.error.comment.text.empty=Texte du commentaire obligatoire
@@ -73,6 +88,7 @@
pollen.error.favoriteList.participant.not.found.in.list=Membre non trouvé dans la liste
pollen.error.favoriteListName.required=Nom de liste obligatoire
pollen.error.login.required=Login obligatoire
+pollen.error.no.poll.found=Sondage non trouvé avec l'id %s
pollen.error.password.required=Mot de passe obligatoire
pollen.error.password2.required=Mot de passe répété obligatoire
pollen.error.passwords.not.equals=Les deux mots de passe saisis non identiques
@@ -125,6 +141,7 @@
pollen.menu.register=Inscrivez-vous
pollen.menu.userFavoriteLists=Listes de votants
pollen.title.createPoll=Nouveau sondage
+pollen.title.delete.comment=Confirmer la suppresion d'un commentaire
pollen.title.editFavoriteList=Edition de la liste des favoris
pollen.title.favoriteLists=Vos listes de votants
pollen.title.myAccount=Mon compte
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml 2012-02-22 22:25:51 UTC (rev 3141)
@@ -30,14 +30,14 @@
<validators>
- <field name="name">
+ <field name="commentName">
<field-validator type="requiredstring">
<message key="pollen.error.comment.name.empty"/>
</field-validator>
</field>
- <field name="text">
+ <field name="commentText">
<field-validator type="requiredstring">
<message key="pollen.error.comment.text.empty"/>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-02-22 22:25:51 UTC (rev 3141)
@@ -259,7 +259,7 @@
<a href="http://www.gnu.org/licenses/gpl.html">
<s:text name="pollen.common.license"/>
</a> -
- <span title="Copyright">©2009-${currentYear}</span>
+ <span title="Copyright">©2009-2012</span>
<a href="http://www.codelutin.com">Code Lutin</a> -
<a href="http://www.chorem.org/projects/pollen/issues">
<s:text name="pollen.common.bugReport"/>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-02-22 22:25:51 UTC (rev 3141)
@@ -29,6 +29,7 @@
<pattern>/images/*</pattern>
<pattern>/config-browser/*</pattern>
<pattern>/json/*</pattern>
+ <pattern>/poll/confirmDelete*</pattern>
</excludes>
<decorator name="layout-default" page="layout-default.jsp">
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollcomment.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollcomment.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollcomment.jsp 2012-02-22 22:25:51 UTC (rev 3141)
@@ -0,0 +1,45 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<s:form method="POST" namespace="/poll" action="deleteComment">
+
+ <s:hidden name="pollId" value='%{comment.poll.pollId}'/>
+
+ <s:hidden name="commentId" value='%{comment.topiaId}'/>
+
+ <s:textfield key='comment.postDate' readonly="true" size="50"
+ label="%{getText('pollen.common.postDate')}"/>
+
+ <s:textfield key='comment.pollAccount.votingId' readonly="true" size="50"
+ label="%{getText('pollen.common.commentName')}"/>
+
+ <s:textarea key='comment.text' readonly="true" rows="3"
+ label="%{getText('pollen.common.commentText')}"/>
+
+ <div class="cleanBoth">
+ <s:submit key="pollen.action.delete" align="center"/>
+ </div>
+</s:form>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollcomment.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-02-22 22:23:54 UTC (rev 3140)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-02-22 22:25:51 UTC (rev 3141)
@@ -21,5 +21,142 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
#L%
--%>
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-<h2>vote poll TODO</h2>
\ No newline at end of file
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
+
+<script type="text/javascript"
+ src="<s:url value='/js/gridHelper.js' />"></script>
+
+<s:url id="deleteUrl" action="confirmDeleteComment" namespace="/poll"/>
+
+<s:url id='deleteImg' value='/img/delete.png'/>
+<s:set id='deleteTitle'><s:text name="pollen.action.pollCommentDelete"/></s:set>
+
+<script type="text/javascript">
+
+ function commentFunctions(cellvalue, options, rowObject) {
+
+ var id = rowObject.id;
+
+ var result = "";
+
+ if (cellvalue.indexOf('delete') > -1) {
+ var url = "openDialog(\""+ id + "\"); return false;";
+ result += formatLink(id, url, "${deleteImg}", "Delete", "${deleteTitle}")
+ }
+ return result;
+ }
+ function formatLink(id, baseUrl, image, imageAlt, imageTitle) {
+ //var url = $.prepareUrl(baseUrl, {commentId:id});
+ return "<a href='#' onclick='" + baseUrl + "'><image alt='" + imageAlt + "' title='" + imageTitle + "' src='" + image + "'> </a>";
+// return "<a href='" + url + "'><image alt='" + imageAlt + "' title='" + imageTitle + "' src='" + image + "'> </a>";
+ }
+
+ function openDialog(commentId) {
+ var dialog = $("#deleteCommentDialog");
+ var url = $.prepareUrl("${deleteUrl}", {commentId:commentId});
+ dialog.load(url);
+ dialog.dialog('open');
+ }
+</script>
+
+<h1 class="titleVote"><s:property value="poll.title"/></h1>
+
+<!-- Informations sur le sondage -->
+
+<div id="pollTop">
+ <div style="white-space:pre-wrap; text-align: start;">
+ <s:property value="poll.description"/>
+ </div>
+ <fieldset>
+ <legend><s:text name="poll.common.aboutPoll"/></legend>
+ <div style="float: right">
+ <s:if test="poll.publicResults">
+
+ <s:a namespace="/poll" action="result" method="input">
+ <s:param name="pollId" value="poll.pollId"/>
+ <img src="<s:url value='/img/count.png'/>"
+ title="<s:text name="poll.common.vote.results-help"/>"
+ alt="<s:text name="poll.common.vote.results"/>"/>
+ </s:a>
+ </s:if>
+ <t:FeedContextLink t:id="feedContext"/>
+ <s:if test="feedFileExisting">
+ <s:a namespace="/poll" action="getFeed" method="input">
+ <s:param name="pollId" value="poll.pollId"/>
+ <img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>
+ </s:a>
+ </s:if>
+ </div>
+ <s:label value="%{poll.creator.votingId}" key='pollen.common.pollCreator'/>
+ <s:label value="%{poll.beginDate}" key='pollen.common.beginDate'/>
+ <s:label value="%{poll.endDate}"
+ label='%{getText("pollen.common.endDate")}'/>
+ <s:label value="%{poll.voteCountingType}"
+ label='%{getText("pollen.common.voteCountingType")}'
+ tooltip="%{voteCountingTypeHelp}" tooltipIconPath="/img/help.png"/>
+ </fieldset>
+</div>
+
+
+<!-- Ajout de commentaires -->
+
+<h3><s:text name="poll.common.comments"/></h3>
+
+<div id="commentsDiv">
+
+ <s:url id="loadPollComments" action="getPollComments" namespace="/json"
+ escapeAmp="false">
+ <s:param name="pollId" value="%{poll.pollId}"/>
+ </s:url>
+
+ <sjg:grid id="comments" dataType="json" href="%{loadPollComments}"
+ gridModel="comments" sortable="true" pager="true"
+ pagerButtons="true" pagerInput="true" navigator="true"
+ rownumbers="false" autowidth="true" editinline="false"
+ navigatorEdit="false" navigatorDelete="false"
+ navigatorSearch="false" navigatorRefresh="false"
+ navigatorAdd="false" viewrecords="true" sortorder="desc"
+ sortname="postDate" rowList="10,15,20,50,100" rowNum="10">
+
+ <sjg:gridColumn name="id" title="id" hidden="true"/>
+ <sjg:gridColumn name="postDate" title='%{getText("pollen.common.postDate")}'
+ sortable="true" formatter="date" width="50"
+ formatoptions="{newformat : 'd.m.Y H:i', srcformat : 'Y-m-d H:i:s'}"/>
+ <sjg:gridColumn name="pollAccount.votingId"
+ title='%{getText("pollen.common.commentName")}'
+ sortable="true"/>
+ <sjg:gridColumn name="text" title='%{getText("pollen.common.commentText")}'
+ sortable="true"/>
+ <sjg:gridColumn name="functions" sortable="false" title='' width="10"
+ formatter="commentFunctions"/>
+ </sjg:grid>
+</div>
+
+<br/>
+
+<%--<div id="commentFormDiv">--%>
+
+<fieldset>
+ <legend><s:text name="poll.legend.addNewComment"/></legend>
+ <s:form id='addCommentForm' method="POST" namespace="/poll">
+ <s:hidden key="pollId" label=''/>
+ <s:textfield key="commentName" required="true"
+ label="%{getText('pollen.common.commentName')}"/>
+ <s:textarea key="commentText" required="true" value=''
+ label="%{getText('pollen.common.commentText')}"/>
+
+ <div class="cleanBoth">
+ <s:submit action="addComment" key="pollen.action.addComment"
+ align="left"/>
+ </div>
+ </s:form>
+</fieldset>
+<%--</div>--%>
+
+<sj:dialog id="deleteCommentDialog"
+ title="%{getText('pollen.title.delete.comment')}"
+ autoOpen="false" modal="true" width="800"/>
+
1
0
r3140 - in branches/pollen-1.2.6-struts2/pollen-services: . src/main/java/org/chorem/pollen/services src/main/java/org/chorem/pollen/services/exceptions src/main/java/org/chorem/pollen/services/impl src/main/resources/i18n src/test/java/org/chorem/pollen/services
by tchemit@users.chorem.org 22 Feb '12
by tchemit@users.chorem.org 22 Feb '12
22 Feb '12
Author: tchemit
Date: 2012-02-22 23:23:54 +0100 (Wed, 22 Feb 2012)
New Revision: 3140
Url: http://chorem.org/repositories/revision/pollen/3140
Log:
add PollFeedService
add application url in service context
Added:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/PollCommentNotFound.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
Modified:
branches/pollen-1.2.6-struts2/pollen-services/pom.xml
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
Modified: branches/pollen-1.2.6-struts2/pollen-services/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/pom.xml 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/pom.xml 2012-02-22 22:23:54 UTC (rev 3140)
@@ -62,6 +62,10 @@
<artifactId>mail</artifactId>
</dependency>
<dependency>
+ <groupId>rome</groupId>
+ <artifactId>rome</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.nuiton.web</groupId>
<artifactId>nuiton-struts2</artifactId>
</dependency>
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -27,6 +27,7 @@
import org.chorem.pollen.PollenConfiguration;
import org.nuiton.topia.TopiaContext;
+import java.net.URL;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
@@ -47,13 +48,17 @@
protected Locale locale;
+ private final URL applicationURL;
+
public static PollenServiceContext newContext(
PollenServiceContext serviceContext,
TopiaContext transaction) {
return newContext(serviceContext.getLocale(),
transaction,
serviceContext.getConfiguration(),
- serviceContext.getServiceFactory()
+ serviceContext.getServiceFactory(),
+ serviceContext.getApplicationURL()
+
);
}
@@ -61,21 +66,25 @@
Locale locale,
TopiaContext transaction,
PollenConfiguration configuration,
- PollenServiceFactory serviceFactory) {
+ PollenServiceFactory serviceFactory,
+ URL applicationURL) {
return new DefaultPollenServiceContext(locale,
transaction,
configuration,
- serviceFactory);
+ serviceFactory,
+ applicationURL);
}
protected DefaultPollenServiceContext(Locale locale,
TopiaContext transaction,
PollenConfiguration configuration,
- PollenServiceFactory serviceFactory) {
+ PollenServiceFactory serviceFactory,
+ URL applicationURL) {
this.locale = locale;
this.transaction = transaction;
this.configuration = configuration;
this.serviceFactory = serviceFactory;
+ this.applicationURL = applicationURL;
}
@Override
@@ -95,6 +104,11 @@
}
@Override
+ public URL getApplicationURL() {
+ return applicationURL;
+ }
+
+ @Override
public <E extends PollenService> E newService(Class<E> clazz) {
return serviceFactory.newService(clazz, this);
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -27,6 +27,7 @@
import org.chorem.pollen.PollenConfiguration;
import org.nuiton.topia.TopiaContext;
+import java.net.URL;
import java.util.Date;
import java.util.Locale;
@@ -46,6 +47,8 @@
Locale getLocale();
+ URL getApplicationURL();
+
PollenConfiguration getConfiguration();
PollenServiceFactory getServiceFactory();
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/PollCommentNotFound.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/PollCommentNotFound.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/PollCommentNotFound.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -0,0 +1,35 @@
+/*
+ * #%L
+ * Pollen :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.services.exceptions;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollCommentNotFound extends Exception {
+
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/PollCommentNotFound.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -33,6 +33,7 @@
import org.chorem.pollen.business.persistence.PollDAO;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exceptions.PollCommentNotFound;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.web.struts2.FilterPagerUtil;
@@ -75,13 +76,17 @@
// add it to poll
pollToUpdate.addComment(commentCreated);
+ // add a feed entry
+ PollFeedService pollFeedService = newService(PollFeedService.class);
+ pollFeedService.addFeedEntryWhenCreateComment(commentCreated);
+
return commentCreated;
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
}
- public void deleteComment(String commentId) {
+ public void deleteComment(String commentId) throws PollCommentNotFound {
Preconditions.checkNotNull(commentId);
@@ -92,8 +97,7 @@
Comment comment = dao.findByTopiaId(commentId);
if (comment == null) {
- throw new PollenTechnicalException(
- "Poll comment with id [" + commentId + "] not found ");
+ throw new PollCommentNotFound();
}
//FIXME Should we also delete the associated pollAccount ?
@@ -168,7 +172,7 @@
try {
TopiaQuery countQuery = dao.createQuery("e").
- addWhere("e." + Comment.PROPERTY_POLL + ".id",
+ addWhere("e." + Comment.PROPERTY_POLL + ".pollId",
TopiaQuery.Op.EQ, pollId);
long records = dao.countByQuery(countQuery);
pager.setRecords((int) records);
@@ -181,4 +185,5 @@
throw new PollenTechnicalException(e);
}
}
+
}
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -0,0 +1,242 @@
+/*
+ * #%L
+ * Pollen :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.services.impl;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndContentImpl;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndEntryImpl;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.SyndFeedOutput;
+import com.sun.syndication.io.XmlReader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenTechnicalException;
+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.Vote;
+import org.chorem.pollen.services.PollenServiceSupport;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.l_;
+
+/**
+ * Service to manage feed of a poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollFeedService extends PollenServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(PollFeedService.class);
+
+ public boolean isFeedExists(Poll poll) {
+ File file = getFeedLocation(poll);
+ return file.exists();
+ }
+
+ /**
+ * Obtain the feed file of the given poll.
+ *
+ * @param poll poll
+ * @return the location of the feed of the given poll
+ */
+ public File getFeedLocation(Poll poll) {
+
+ File feedDirectory = getConfiguration().getFeedDirectory();
+ String filename = poll.getPollId() + ".xml";
+ File result = new File(feedDirectory, filename);
+ return result;
+ }
+
+ /**
+ * Création d'un flux.
+ *
+ * @param poll poll
+ * @param type type de flux (rss_2.0, atom_1.0)
+ */
+ public void createFeed(Poll poll, String type) {
+
+ File file = getFeedLocation(poll);
+
+ String title = l_(getLocale(), "pollen.feed.pollTitle", poll.getTitle());
+ String description = l_(getLocale(), "pollen.feed.pollDescription", poll.getDescription());
+ String link = getPollFeedLink(poll);
+ try {
+
+ SyndFeed feed = new SyndFeedImpl();
+ feed.setFeedType(type);
+ feed.setTitle(title);
+ feed.setLink(link);
+ feed.setDescription(description);
+
+ Writer writer = new FileWriter(file);
+ SyndFeedOutput output = new SyndFeedOutput();
+ output.output(feed, writer);
+ writer.close();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Feed created: " + file.getAbsolutePath());
+ }
+ } catch (Exception e) {
+ throw new PollenTechnicalException("Could not create feed", e);
+ }
+ }
+
+ /**
+ * Ajout d'une entrée dans un flux.
+ *
+ * @param poll poll
+ * @param title titre de l'entrée
+ * @param content contenu de l'entrée
+ */
+ public void feedFeed(Poll poll, String title,
+ String content) {
+
+ if (!isFeedExists(poll)) {
+ createFeed(poll, "atom_1.0");
+ }
+
+ File file = getFeedLocation(poll);
+ String link = getPollFeedLink(poll);
+
+ try {
+ List entries = new ArrayList();
+ SyndFeedInput input = new SyndFeedInput();
+ SyndFeed feed = input.build(new XmlReader(file));
+ entries.addAll(feed.getEntries());
+
+ SyndEntry entry;
+ SyndContent description;
+ entry = new SyndEntryImpl();
+ entry.setTitle(title);
+ entry.setLink(link);
+ entry.setPublishedDate(new Date());
+ description = new SyndContentImpl();
+ description.setType("text/plain");
+ description.setValue(content);
+ entry.setDescription(description);
+ entries.add(entry);
+
+ feed.setEntries(entries);
+
+ Writer writer = new FileWriter(file);
+ try {
+ SyndFeedOutput output = new SyndFeedOutput();
+ output.output(feed, writer);
+ } finally {
+ writer.close();
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Feed updated: " + file.getAbsolutePath());
+ }
+ } catch (Exception e) {
+ throw new PollenTechnicalException("Could not feed feed", e);
+ }
+ }
+
+ /**
+ * Delete the poll feed file.
+ *
+ * @param poll poll
+ */
+ public void deleteFeed(Poll poll) {
+
+ File feedLocation = getFeedLocation(poll);
+ if (feedLocation.exists()) {
+ boolean wasDeleted = feedLocation.delete();
+ if (!wasDeleted) {
+ throw new PollenTechnicalException("Could not delete feed");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Feed deleted: " + feedLocation.getAbsolutePath());
+ }
+ }
+ }
+
+ public void addFeedEntryWhenCreatePoll(Poll poll) {
+
+
+ String title = _("pollen.feed.createPollContent",
+ poll.getCreator().getVotingId());
+
+ String content = _("pollen.feed.createPollContent", poll.getDescription());
+
+ feedFeed(poll, title, content);
+ }
+
+
+ public void addFeedEntryWhenCreateComment(Comment comment) {
+
+ //TODO Validate this is ok
+ String title = _("pollen.feed.addCommentTitle",
+ comment.getPollAccount().getVotingId());
+
+ String content = _("pollen.feed.addCommentContent",
+ comment.getText());
+
+ feedFeed(comment.getPoll(), title, content);
+ }
+
+ public void addFeedEntryWhenAddVote(Vote vote) {
+
+
+ String title = _("pollen.feed.addVoteTitle",
+ vote.getPollAccount().getVotingId());
+
+ // TODO Add result of poll ? And if poll is not public ?
+ String content = _("pollen.feed.addVoteContent", "TODO");
+
+ feedFeed(vote.getPoll(), title, content);
+ }
+
+ public void addFeedEntryWhenAddChoice(Choice choice) {
+
+ String title = _("pollen.feed.addChoiceTitle", choice.getName());
+
+ String content = _("pollen.feed.addChoiceContent",
+ choice.getDescription());
+
+ feedFeed(choice.getPoll(), title, content);
+ }
+
+ protected String getPollFeedLink(Poll poll) {
+ String link =
+ serviceContext.getApplicationURL() +
+ "/poll/vote?pollId=" + poll.getPollId();
+ return link;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -45,6 +45,8 @@
import java.util.List;
+import static org.nuiton.i18n.I18n._;
+
public class PollService extends PollenServiceSupport {
/** Logger. */
@@ -85,6 +87,21 @@
return result;
}
+ /*
+ private void addFeedEntry() {
+ PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId());
+ String voteURL = siteURL + "poll/votefor/" + poll.getPollId();
+ File feedFile = feedContext.getFile(poll.getPollId());
+
+ FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
+ "pollFeed_title", poll.getTitle()), siteURL, messages.format(
+ "pollFeed_desc", poll.getDescription()));
+ FeedUtil.feedFeed(feedFile, messages.format("pollFeed_createTitle",
+ creator.getVotingId()), voteURL, messages
+ .get("pollFeed_createContent"));
+ }
+ */
+
public List<Poll> getPolls(FilterPagerUtil.FilterPagerBean pager) {
Preconditions.checkNotNull(pager);
@@ -894,4 +911,16 @@
//
// return results;
// }
+
+ public Poll getPollByPollId(String pollId) {
+
+ Preconditions.checkNotNull(pollId);
+ PollDAO dao = getDAO(Poll.class);
+ try {
+ Poll result = dao.findByPollId(pollId);
+ return result;
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException("Could not find poll with pollId " + pollId);
+ }
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -83,8 +83,7 @@
}
public UserAccount createUser(UserAccount user,
- boolean byAdmin,
- URL url) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException {
+ boolean byAdmin) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException {
Preconditions.checkNotNull(user);
@@ -121,6 +120,8 @@
throw new PollenTechnicalException(e);
}
+ URL url = serviceContext.getApplicationURL();
+
if (url != null && StringUtil.isEmail(user.getEmail())) {
Locale locale = getLocale();
@@ -259,7 +260,7 @@
user.setEmail(getConfiguration().getAdminEmail());
user.setPassword(getConfiguration().getAdminPassword());
try {
- createUser(user, false, null);
+ createUser(user, false);
if (log.isInfoEnabled()) {
log.info(_("pollen.info.admin.created", login));
}
@@ -283,7 +284,8 @@
* @param destination which receive the copy
* @see Binder#copy(Object, Object, String...)
*/
- protected void copyUserAccount(UserAccount source, UserAccount destination) {
+ protected void copyUserAccount(UserAccount source,
+ UserAccount destination) {
TopiaEntityBinder<UserAccount> binder =
PollenBinderHelper.getSimpleTopiaBinder(UserAccount.class);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -32,6 +32,40 @@
/** Logger. */
private static final Log log = LogFactory.getLog(VoteService.class);
+ /*
+ private void addFeedEntry(PollAction pollAction, String titleStr,
+ String contentStr) {
+ String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId();
+ File feedFile = getFeedContext().getFile(poll.getPollId());
+ String title = null;
+ String content = null;
+
+ switch (pollAction) {
+ case ADDVOTE:
+ if (isVoteAnonymous()) {
+ titleStr = messages.get("anonymous");
+ }
+ title = messages.format("pollFeed_voteTitle", titleStr);
+ content = messages.format("pollFeed_voteContent", contentStr);
+ break;
+ case ADDCHOICE:
+ title = messages.format("pollFeed_choiceTitle", titleStr);
+ content = messages.format("pollFeed_choiceContent", contentStr);
+ break;
+ case ADDCOMMENT:
+ title = messages.format("pollFeed_commentTitle", titleStr);
+ content = messages.format("pollFeed_commentContent", contentStr);
+ break;
+ }
+
+ if (!feedFile.exists()) {
+ FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
+ "pollFeed_title", poll.getTitle()), siteURL, messages
+ .format("pollFeed_desc", poll.getDescription()));
+ }
+ FeedUtil.feedFeed(feedFile, title, voteURL, content);
+ }
+ */
// public boolean canVote(Poll poll, PollAccount participant) {
// try {
// if (log.isDebugEnabled()) {
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-02-22 22:23:54 UTC (rev 3140)
@@ -148,6 +148,15 @@
pollen.exception.user_wrong_password=
pollen.exception.vote_doubloon=
pollen.exception.vote_not_allowed=
+pollen.feed.addChoiceContent=
+pollen.feed.addChoiceTitle=
+pollen.feed.addCommentContent=%s
+pollen.feed.addCommentTitle=New comment of %s
+pollen.feed.addVoteContent=
+pollen.feed.addVoteTitle=
+pollen.feed.createPollContent=
+pollen.feed.pollDescription=%s
+pollen.feed.pollTitle=Pollen \: %s
pollen.info.admin.created=Super admin was created with login %1$s
pollen.info.admin.exists=Super admin already exists
pollen.info.start=Start Pollen
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-02-22 22:23:54 UTC (rev 3140)
@@ -152,6 +152,15 @@
pollen.exception.user_wrong_password=Le mot de passe renseigné est incorrect pour l'utilisateur '%1$s'.
pollen.exception.vote_doubloon=
pollen.exception.vote_not_allowed=
+pollen.feed.addChoiceContent=
+pollen.feed.addChoiceTitle=
+pollen.feed.addCommentContent=%s
+pollen.feed.addCommentTitle=Nouveau commentaire de %s
+pollen.feed.addVoteContent=
+pollen.feed.addVoteTitle=
+pollen.feed.createPollContent=
+pollen.feed.pollDescription=%s
+pollen.feed.pollTitle=Pollen \: %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à
pollen.info.start=Démarrage de Pollen...
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-02-22 22:21:35 UTC (rev 3139)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-02-22 22:23:54 UTC (rev 3140)
@@ -37,6 +37,7 @@
import org.nuiton.util.DateUtil;
import java.io.File;
+import java.net.URL;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
@@ -163,6 +164,11 @@
return Locale.getDefault();
}
+ @Override
+ public URL getApplicationURL() {
+ return null;
+ }
+
/**
* Create an id to easily managed polls using urls.
*
1
0
r3139 - in branches/pollen-1.2.6-struts2/pollen-ui/src/main: java/org/chorem/pollen/ui resources webapp
by tchemit@users.chorem.org 22 Feb '12
by tchemit@users.chorem.org 22 Feb '12
22 Feb '12
Author: tchemit
Date: 2012-02-22 23:21:35 +0100 (Wed, 22 Feb 2012)
New Revision: 3139
Url: http://chorem.org/repositories/revision/pollen/3139
Log:
remove all struts parts of the tapestry module
Removed:
branches/pollen-1.2.6-struts2/pollen-ui/src/main/java/org/chorem/pollen/ui/PollenSession.java
branches/pollen-1.2.6-struts2/pollen-ui/src/main/java/org/chorem/pollen/ui/actions/
branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.properties
branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui/src/main/webapp/jsp/
branches/pollen-1.2.6-struts2/pollen-ui/src/main/webapp/template/
Deleted: branches/pollen-1.2.6-struts2/pollen-ui/src/main/java/org/chorem/pollen/ui/PollenSession.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-02-22 14:25:23 UTC (rev 3138)
+++ branches/pollen-1.2.6-struts2/pollen-ui/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-02-22 22:21:35 UTC (rev 3139)
@@ -1,31 +0,0 @@
-package org.chorem.pollen.ui;
-
-import java.util.Map;
-
-import com.opensymphony.xwork2.ActionContext;
-
-/**
- * Class used to manage the session
- */
-public class PollenSession {
-
- static final private String POLLEN_SESSION_KEY = PollenSession.class.getSimpleName();
-
- static public Map<String, Object> getSession() {
- return ActionContext.getContext().getSession();
- }
-
- static public PollenSession getPollenSession() {
- PollenSession session = (PollenSession) getSession().get(POLLEN_SESSION_KEY);
-
- if (session == null) {
- session = new PollenSession();
- getSession().put(POLLEN_SESSION_KEY, session);
- }
- return session;
- }
-
- static public void invalidate() {
- getSession().remove(POLLEN_SESSION_KEY);
- }
-}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.properties 2012-02-22 14:25:23 UTC (rev 3138)
+++ branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.properties 2012-02-22 22:21:35 UTC (rev 3139)
@@ -1,51 +0,0 @@
-struts.locale=fr_FR
-struts.i18n.encoding=UTF-8
-
-struts.objectFactory = spring
-
-struts.objectFactory.spring.autoWire = name
-
-struts.objectFactory.spring.useClassCache = true
-
-# struts.multipart.parser=cos
-# struts.multipart.parser=pell
-struts.multipart.parser=jakarta
-# uses javax.servlet.context.tempdir by default
-struts.multipart.saveDir=
-struts.multipart.maxSize=2097152
-
-# struts.custom.properties=application,com/webwork/extension/custom
-
-struts.mapper.class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper
-
-struts.action.extension=action
-
-struts.serve.static=true
-
-struts.serve.static.browserCache=true
-
-struts.tag.altSyntax=true
-
-struts.devMode=true
-
-struts.i18n.reload=true
-
-struts.ui.theme=xhtml
-struts.ui.templateDir=template
-#sets the default template type. Either ftl, vm, or jsp
-struts.ui.templateSuffix=ftl
-
-struts.configuration.xml.reload=false
-
-struts.url.http.port = 80
-struts.url.https.port = 443
-
-struts.custom.i18n.resources=bow-i18n
-
-struts.dispatcher.parametersWorkaround = false
-
-#struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.FreemarkerManager
-
-struts.freemarker.wrapper.altMap=true
-
-struts.xslt.nocache=false
Deleted: branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.xml 2012-02-22 14:25:23 UTC (rev 3138)
+++ branches/pollen-1.2.6-struts2/pollen-ui/src/main/resources/struts.xml 2012-02-22 22:21:35 UTC (rev 3139)
@@ -1,90 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
-<struts>
- <constant name="struts.devMode" value="true" />
- <constant name="struts.ognl.allowStaticMethodAccess" value="true" />
-
- <package name="default" extends="struts-default">
- <interceptors>
- <interceptor name="login"
- class="org.chorem.pollen.ui.interceptor.LoginInterceptor">
- <param name="redirect">login_input.action</param>
- </interceptor>
- <interceptor-stack name="loginStack">
- <interceptor-ref name="login" />
- <interceptor-ref name="defaultStack" />
- </interceptor-stack>
- </interceptors>
- <action name="login"
- class="org.chorem.pollen.ui.action.user.LoginUserAction"
- method="login">
- </action>
- <action name="logout"
- class="org.chorem.pollen.ui.action.user.LoginUserAction"
- method="logout">
- <result type="redirect">/jsp/index.jsp</result>
- </action>
- <action name="register"
- class="org.chorem.pollen.ui.action.user.RegisterAction">
- <result type="redirect">/jsp/index.jsp</result>
- </action>
- <action name="pollsParticipated"
- class="org.chorem.pollen.ui.action.poll.PollsListAction"
- method="listPollsParticipated">
- <interceptor-ref name="loginStack" />
- </action>
- <action name="pollsCreated"
- class="org.chorem.pollen.ui.action.poll.PollsListAction"
- method="listPollsCreated">
- <interceptor-ref name="loginStack" />
- </action>
- <action name="userProfile"
- class="org.chorem.pollen.ui.action.user.UserProfileAction">
- <interceptor-ref name="loginStack" />
- </action>
- <action name="createVotersList"
- class="org.chorem.pollen.ui.action.poll.VotersListAction"
- method="create">
- <interceptor-ref name="loginStack" />
- </action>
- <action name="modifyVotersList"
- class="org.chorem.pollen.ui.action.poll.VotersListAction"
- method="modify">
- <interceptor-ref name="loginStack" />
- </action>
- <action name="deleteVotersList"
- class="org.chorem.pollen.ui.action.poll.VotersListAction"
- method="delete">
- <interceptor-ref name="loginStack" />
- </action>
- <action name="voteFor"
- class="org.chorem.pollen.ui.action.poll.VoteForAction">
- </action>
- <action name="createPoll"
- class="org.chorem.pollen.ui.action.poll.PollAction"
- method="create">
- </action>
- <action name="modifyPoll"
- class="org.chorem.pollen.ui.action.poll.PollAction"
- method="modify">
- </action>
- <action name="copyPoll"
- class="org.chorem.pollen.ui.action.poll.PollAction"
- method="copy">
- </action>
- <action name="closePoll"
- class="org.chorem.pollen.ui.action.poll.PollAction"
- method="close">
- </action>
- <action name="deletePoll"
- class="org.chorem.pollen.ui.action.poll.PollAction"
- method="delete">
- </action>
- <action name="exportPollXML"
- class="org.chorem.pollen.ui.action.poll.PollAction"
- method="exportXML">
- </action>
- </package>
-</struts>
1
0
Author: tchemit
Date: 2012-02-22 15:25:23 +0100 (Wed, 22 Feb 2012)
New Revision: 3138
Url: http://chorem.org/repositories/revision/pollen/3138
Log:
add poll comment actions + service
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-02-22 14:20:18 UTC (rev 3137)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-02-22 14:25:23 UTC (rev 3138)
@@ -58,9 +58,8 @@
public <E extends TopiaEntity> List<E> getEntities(Class<E> entityType) {
Preconditions.checkNotNull(entityType);
try {
- List<E> result = PollenDAOHelper.<E, TopiaDAO<E>>getDAO(
- getTransaction(),
- entityType).findAll();
+ TopiaDAO<E> dao = getDAO(entityType);
+ List<E> result = dao.findAll();
return result;
} catch (TopiaException eee) {
throw new PollenTechnicalException(
@@ -72,9 +71,8 @@
Preconditions.checkNotNull(entityType);
Preconditions.checkArgument(StringUtils.isNotEmpty(id));
try {
- E result = PollenDAOHelper.<E, TopiaDAO<E>>getDAO(
- getTransaction(),
- entityType).findByTopiaId(id);
+ TopiaDAO<E> dao = getDAO(entityType);
+ E result = dao.findByTopiaId(id);
return result;
} catch (TopiaException eee) {
throw new PollenTechnicalException(
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-02-22 14:20:18 UTC (rev 3137)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-02-22 14:25:23 UTC (rev 3138)
@@ -23,17 +23,22 @@
*/
package org.chorem.pollen.services.impl;
+import com.google.common.base.Preconditions;
import org.chorem.pollen.PollenTechnicalException;
import org.chorem.pollen.business.persistence.Comment;
import org.chorem.pollen.business.persistence.CommentDAO;
-import org.chorem.pollen.business.persistence.CommentImpl;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollAccountDAO;
import org.chorem.pollen.business.persistence.PollDAO;
-import org.chorem.pollen.entities.PollenDAOHelper;
+import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.services.PollenServiceSupport;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.web.struts2.FilterPagerUtil;
+import java.util.List;
+
/**
* Manage comments on a poll.
*
@@ -42,56 +47,138 @@
*/
public class PollCommentService extends PollenServiceSupport {
- public int getNbComments(Poll poll) {
- try {
- PollDAO dao = PollenDAOHelper.getPollDAO(getTransaction());
+ public Comment createComment(Poll poll, Comment comment) {
- Poll pollFound = dao.findByTopiaId(poll.getTopiaId());
+ Preconditions.checkNotNull(poll);
- int result = pollFound.sizeComment();
- return result;
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
+ PollDAO pollDAO = getDAO(Poll.class);
+ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
+ CommentDAO dao = getDAO(Comment.class);
- public Comment createComment(Poll poll, Comment comment) {
try {
- CommentDAO dao = PollenDAOHelper.getCommentDAO(getTransaction());
+ // creates poll account
+ PollAccount pollAccountCreated =
+ pollAccountDAO.create(comment.getPollAccount());
+
+ // get last version of the poll
+ Poll pollToUpdate = pollDAO.findByTopiaId(poll.getTopiaId());
+
+ // creates the poll comment
Comment commentCreated = dao.create(
- Comment.PROPERTY_POLL, poll,
- Comment.PROPERTY_POST_DATE, serviceContext.getCurrentTime(),
+ Comment.PROPERTY_POLL_ACCOUNT, pollAccountCreated,
+ Comment.PROPERTY_POLL, pollToUpdate,
+ Comment.PROPERTY_POST_DATE, comment.getPostDate(),
Comment.PROPERTY_TEXT, comment.getText()
);
- PollDAO pollDAO = PollenDAOHelper.getPollDAO(getTransaction());
-
- Poll pollToUpdate = pollDAO.findByTopiaId(poll.getTopiaId());
-
+ // add it to poll
pollToUpdate.addComment(commentCreated);
- pollDAO.update(pollToUpdate);
return commentCreated;
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
}
- public void deleteComment(Comment comment) {
+ public void deleteComment(String commentId) {
+
+ Preconditions.checkNotNull(commentId);
+
+ CommentDAO dao = getDAO(Comment.class);
+
try {
- CommentDAO dao = PollenDAOHelper.getCommentDAO(getTransaction());
+
+ Comment comment = dao.findByTopiaId(commentId);
+
+ if (comment == null) {
+ throw new PollenTechnicalException(
+ "Poll comment with id [" + commentId + "] not found ");
+ }
+
+ //FIXME Should we also delete the associated pollAccount ?
dao.delete(comment);
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
}
- public Comment getNewComment(PollAccount account) {
- Comment result = new CommentImpl();
+ public Comment getNewComment(PollAccount account, String text) {
+
+ CommentDAO dao = getDAO(Comment.class);
+ Comment result = newInstance(dao);
+
if (account != null) {
result.setPollAccount(account);
}
+ result.setText(text);
+ result.setPostDate(serviceContext.getCurrentTime());
return result;
}
+
+ public PollAccount getNewPollAccount(UserAccount user, String votingId) {
+ PollAccountDAO dao = getDAO(PollAccount.class);
+ PollAccount result = newInstance(dao);
+ if (user != null) {
+ result.setVotingId(user.getDisplayName());
+ result.setAccountId(serviceContext.createPollenUrlId());
+ result.setEmail(user.getEmail());
+ result.setUserAccount(user);
+ }
+ if (votingId != null) {
+ result.setVotingId(votingId);
+ }
+ return result;
+ }
+
+ public boolean isCanDeleteComment(Comment comment,
+ UserAccount userAccount) {
+
+ boolean result = false;
+
+ if (userAccount != null) {
+
+ // loggued
+
+ if (userAccount.isAdministrator()) {
+
+ // administrator can always delete everything
+ result = true;
+
+ } else {
+
+ PollAccount pollAccount = comment.getPollAccount();
+ if (userAccount.equals(pollAccount.getUserAccount())) {
+ result = true;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public List<Comment> getComments(FilterPagerUtil.FilterPagerBean pager,
+ String pollId) {
+
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(pollId);
+
+ CommentDAO dao = getDAO(Comment.class);
+
+ try {
+
+ TopiaQuery countQuery = dao.createQuery("e").
+ addWhere("e." + Comment.PROPERTY_POLL + ".id",
+ TopiaQuery.Op.EQ, pollId);
+ long records = dao.countByQuery(countQuery);
+ pager.setRecords((int) records);
+
+ TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery,
+ pager);
+ List<Comment> result = dao.findAllByQuery(query);
+ return result;
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
}
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-02-22 14:25:23 UTC (rev 3138)
@@ -0,0 +1,111 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.json;
+
+import com.google.common.base.Preconditions;
+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;
+import java.util.Map;
+
+/**
+ * Get paginated list of poll comments.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class GetPollComments extends AbstractJSONPaginedAction {
+
+ private static final long serialVersionUID = 1L;
+
+ protected transient Map<String, Object>[] comments;
+
+ protected String pollId;
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public Map<String, Object>[] getComments() {
+ return comments;
+ }
+
+ @Override
+ public Integer getRows() {
+ return pager.getPageSize();
+ }
+
+ @Override
+ public Integer getPage() {
+ return pager.getPageIndex();
+ }
+
+ @Override
+ public Integer getTotal() {
+ return pager.getPagesNumber();
+ }
+
+ @Override
+ public Integer getRecords() {
+ return pager.getRecords();
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollId);
+
+ PollCommentService pollService = newService(PollCommentService.class);
+
+ List<Comment> commentList = pollService.getComments(pager, pollId);
+
+ UserAccount userAccount = getPollenSession().getUserAccount();
+
+ comments = new Map[commentList.size()];
+ Binder<Comment, Comment> binder =
+ PollenBinderHelper.getSimpleTopiaBinder(Comment.class);
+ int index = 0;
+ for (Comment comment : commentList) {
+
+ Map<String, Object> map = binder.obtainProperties(
+ comment,
+ Comment.PROPERTY_TEXT,
+ Comment.PROPERTY_POST_DATE
+ );
+ map.put("name", comment.getPollAccount().getVotingId());
+ map.put("id", comment.getTopiaId());
+ boolean canDelete = pollService.isCanDeleteComment(comment,
+ userAccount);
+ map.put("canDelete", canDelete);
+ comments[index++] = map;
+ }
+ return SUCCESS;
+ }
+
+
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-02-22 14:25:23 UTC (rev 3138)
@@ -0,0 +1,98 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+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.services.impl.PollCommentService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * To add a poll comment.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class AddComment extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String pollId;
+
+ protected String name;
+
+ protected String text;
+
+ public String getPollId() {
+ return pollId;
+ }
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(text);
+ Preconditions.checkNotNull(name);
+
+ PollCommentService service = newService(PollCommentService.class);
+
+ Poll poll = service.getEntityById(Poll.class, pollId);
+
+ // prepare a new poll account for the comment
+ PollAccount pollAccount = service.getNewPollAccount(
+ getPollenSession().getUserAccount(), name);
+
+ // prepare a new comment
+ Comment comment = service.getNewComment(pollAccount, text);
+
+ // create the comment
+ service.createComment(poll, comment);
+
+ getTransaction().commitTransaction();
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-02-22 14:25:23 UTC (rev 3138)
@@ -0,0 +1,59 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.services.impl.PollCommentService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * To delete a poll comment.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class DeleteComment extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String pollId;
+
+ protected String commentId;
+
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(commentId);
+
+ PollCommentService service = newService(PollCommentService.class);
+
+ service.deleteComment(commentId);
+
+ getTransaction().commitTransaction();
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-02-22 14:20:18 UTC (rev 3137)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-02-22 14:25:23 UTC (rev 3138)
@@ -50,7 +50,7 @@
<action name="vote"
class="org.chorem.pollen.ui.actions.poll.Vote">
<result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
- <result>/WEB-INF/jsp/home.jsp</result>
+ <result>/WEB-INF/jsp/poll/vote.jsp</result>
</action>
<!-- clone poll -->
@@ -104,7 +104,20 @@
<result>/WEB-INF/jsp/home.jsp</result>
</action>
+ <!-- add a poll comment -->
+ <action name="addComment"
+ class="org.chorem.pollen.ui.actions.poll.AddComment">
+ <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
+ <result>/WEB-INF/jsp/poll/vote.jsp</result>
+ </action>
+ <!-- delete a poll comment -->
+ <action name="deleteComment"
+ class="org.chorem.pollen.ui.actions.poll.DeleteComment">
+ <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
+ <result>/WEB-INF/jsp/poll/vote.jsp</result>
+ </action>
+
</package>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-02-22 14:20:18 UTC (rev 3137)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-02-22 14:25:23 UTC (rev 3138)
@@ -62,6 +62,8 @@
pollen.common.title=Title
pollen.common.userSupport=User support
pollen.common.voteCountingType=Counting type
+pollen.error.comment.name.empty=Comment name mandatory
+pollen.error.comment.text.empty=Comment text mandatory
pollen.error.email.required=You must provide an email
pollen.error.favoriteList.already.used=List name already used
pollen.error.favoriteList.not.found=Favorite list not found
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-02-22 14:20:18 UTC (rev 3137)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-02-22 14:25:23 UTC (rev 3138)
@@ -63,6 +63,8 @@
pollen.common.userSupport=Support utilisateur
pollen.common.voteCountingType=Type de dépouillement
pollen.common.x=Dépouillement
+pollen.error.comment.name.empty=Nom du commentaire obligatoire
+pollen.error.comment.text.empty=Texte du commentaire obligatoire
pollen.error.email.required=Courriel obligatoire
pollen.error.favoriteList.already.used=Nom de liste déjà utilisé
pollen.error.favoriteList.not.found=Liste non trouvée
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml 2012-02-22 14:25:23 UTC (rev 3138)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ -->
+
+
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+
+ <field name="name">
+
+ <field-validator type="requiredstring">
+ <message key="pollen.error.comment.name.empty"/>
+ </field-validator>
+ </field>
+
+ <field name="text">
+
+ <field-validator type="requiredstring">
+ <message key="pollen.error.comment.text.empty"/>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2012-02-22 15:20:18 +0100 (Wed, 22 Feb 2012)
New Revision: 3137
Url: http://chorem.org/repositories/revision/pollen/3137
Log:
update to last stable of topia
Modified:
branches/pollen-1.2.6-struts2/pom.xml
Modified: branches/pollen-1.2.6-struts2/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pom.xml 2012-02-22 12:08:44 UTC (rev 3136)
+++ branches/pollen-1.2.6-struts2/pom.xml 2012-02-22 14:20:18 UTC (rev 3137)
@@ -429,7 +429,7 @@
<projectId>pollen</projectId>
<!-- customized versions -->
- <topiaVersion>2.6.7-SNAPSHOT</topiaVersion>
+ <topiaVersion>2.6.7</topiaVersion>
<eugenePluginVersion>2.4.2</eugenePluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<tapestryVersion>5.1.0.5</tapestryVersion>
1
0
r3136 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui: . actions actions/admin actions/json actions/user
by tchemit@users.chorem.org 22 Feb '12
by tchemit@users.chorem.org 22 Feb '12
22 Feb '12
Author: tchemit
Date: 2012-02-22 13:08:44 +0100 (Wed, 22 Feb 2012)
New Revision: 3136
Url: http://chorem.org/repositories/revision/pollen/3136
Log:
reformat
use favoritService instead of Userservice when possible
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManagePolls.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -37,7 +37,7 @@
protected PollenConfiguration configuration;
protected TopiaContext rootContext;
-
+
protected URL applicationUrl;
public PollenConfiguration getConfiguration() {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -56,14 +56,14 @@
// get port
String port;
if ("http".equalsIgnoreCase(request.getScheme()) && request.getServerPort() != 80 ||
- "https".equalsIgnoreCase(request.getScheme()) && request.getServerPort() != 443) {
+ "https".equalsIgnoreCase(request.getScheme()) && request.getServerPort() != 443) {
port = ":" + request.getServerPort();
} else {
port = "";
}
String applicationBase = request.getScheme() + "://" + request.getServerName() +
- port + request.getContextPath();
+ port + request.getContextPath();
try {
return new URL(applicationBase);
} catch (MalformedURLException e) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -30,9 +30,9 @@
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
import org.chorem.pollen.PollenConfiguration;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
import org.chorem.pollen.services.PollenService;
import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.DefaultPollenServiceContext;
import org.chorem.pollen.services.PollenServiceFactory;
import org.chorem.pollen.ui.PollenApplicationContext;
import org.chorem.pollen.ui.PollenSession;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManagePolls.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManagePolls.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManagePolls.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -26,7 +26,6 @@
import org.chorem.pollen.ui.actions.PollenActionSupport;
/**
- *
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -26,8 +26,8 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.json.JSONException;
import org.apache.struts2.json.JSONUtil;
-import org.chorem.pollen.services.PollenPagerBean;
import org.chorem.pollen.ui.actions.PollenActionSupport;
+import org.nuiton.web.struts2.FilterPagerUtil;
/**
* Abstract JSON action with pagination support.
@@ -47,7 +47,8 @@
public abstract Integer getRecords();
- protected PollenPagerBean pager = new PollenPagerBean();
+ protected FilterPagerUtil.FilterPagerBean pager =
+ FilterPagerUtil.newFilterPagerBean();
protected String filters;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -25,7 +25,7 @@
import com.google.common.collect.Maps;
import org.chorem.pollen.business.persistence.PersonList;
-import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.services.impl.FavoriteService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
import java.util.Map;
@@ -59,10 +59,10 @@
@Override
public String execute() throws Exception {
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
PersonList personList =
- userService.getEntityById(PersonList.class, favoriteListId);
+ service.getEntityById(PersonList.class, favoriteListId);
favoriteList = Maps.newHashMap();
favoriteList.put("id", personList.getTopiaId());
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -26,7 +26,7 @@
import org.chorem.pollen.business.persistence.PersonList;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.entities.PollenBinderHelper;
-import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.services.impl.FavoriteService;
import org.nuiton.util.beans.Binder;
import java.util.List;
@@ -81,12 +81,12 @@
@Override
public String execute() throws Exception {
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
PersonList favoriteList =
- userService.getEntityById(PersonList.class, favoriteListId);
+ service.getEntityById(PersonList.class, favoriteListId);
- List<PollAccount> allPollAccounts = userService.getFavoriteListUsers(
+ List<PollAccount> allPollAccounts = service.getFavoriteListUsers(
favoriteList,
pager);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -25,7 +25,7 @@
import com.google.common.collect.Maps;
import org.chorem.pollen.business.persistence.PersonList;
-import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.services.impl.FavoriteService;
import java.util.List;
import java.util.Map;
@@ -69,9 +69,9 @@
@Override
public String execute() throws Exception {
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
- List<PersonList> allFavoriteLists = userService.getFavoriteLists(
+ List<PersonList> allFavoriteLists = service.getFavoriteLists(
getPollenSession().getUserAccount(),
pager);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -30,7 +30,7 @@
import org.chorem.pollen.services.exceptions.FavoriteListNotFoundException;
import org.chorem.pollen.services.exceptions.FavoriteListNotOwnedByUserException;
import org.chorem.pollen.services.exceptions.ParticipantAlreadyFoundInListException;
-import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.services.impl.FavoriteService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
/**
@@ -93,10 +93,10 @@
Preconditions.checkNotNull(favoriteListId);
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
try {
- favoriteList = userService.getFavoriteList(
+ favoriteList = service.getFavoriteList(
getPollenSession().getUserAccount(), favoriteListId);
} catch (FavoriteListNotFoundException e) {
addActionError(_("pollen.error.favoriteList.not.found"));
@@ -112,12 +112,11 @@
String result = INPUT;
+ FavoriteService service = newService(FavoriteService.class);
- UserService userService = newService(UserService.class);
-
try {
- userService.addPollAccountToFavoriteList(favoriteList, pollAccount);
+ service.addPollAccountToFavoriteList(favoriteList, pollAccount);
getTransaction().commitTransaction();
addActionMessage(
@@ -141,12 +140,11 @@
String result = INPUT;
+ FavoriteService service = newService(FavoriteService.class);
- UserService userService = newService(UserService.class);
-
try {
- userService.editPollAccountToFavoriteList(favoriteList, pollAccount);
+ service.editPollAccountToFavoriteList(favoriteList, pollAccount);
getTransaction().commitTransaction();
addActionMessage(
@@ -169,9 +167,9 @@
Preconditions.checkNotNull(pollAccount);
Preconditions.checkNotNull(pollAccount.getTopiaId());
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
- userService.removePollAccountToFavoriteList(favoriteList, pollAccount);
+ service.removePollAccountToFavoriteList(favoriteList, pollAccount);
getTransaction().commitTransaction();
addActionMessage(
@@ -186,8 +184,8 @@
protected PollAccount getPollAccount() {
if (pollAccount == null) {
- UserService userService = newService(UserService.class);
- pollAccount = userService.newPollAccountForFavoriteList();
+ FavoriteService service = newService(FavoriteService.class);
+ pollAccount = service.newPollAccountForFavoriteList();
}
return pollAccount;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java 2012-02-22 12:07:31 UTC (rev 3135)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java 2012-02-22 12:08:44 UTC (rev 3136)
@@ -26,7 +26,7 @@
import com.google.common.base.Preconditions;
import org.chorem.pollen.business.persistence.PersonList;
import org.chorem.pollen.services.exceptions.FavoriteListAlreadyExistException;
-import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.services.impl.FavoriteService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
import java.io.File;
@@ -100,10 +100,10 @@
Preconditions.checkNotNull(favoriteList.getName());
String result = INPUT;
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
try {
- userService.createFavoriteList(getPollenSession().getUserAccount(),
- favoriteList.getName());
+ service.createFavoriteList(getPollenSession().getUserAccount(),
+ favoriteList.getName());
getTransaction().commitTransaction();
addActionMessage(_("pollen.information.favoriteList.created",
@@ -122,10 +122,10 @@
Preconditions.checkNotNull(favoriteList);
- UserService userService = newService(UserService.class);
+ FavoriteService service = newService(FavoriteService.class);
- PersonList deletedFavoritedList = userService.deleteFavoriteList(getPollenSession().getUserAccount(),
- favoriteList);
+ PersonList deletedFavoritedList = service.deleteFavoriteList(getPollenSession().getUserAccount(),
+ favoriteList);
getTransaction().commitTransaction();
addActionMessage(_("pollen.information.favoriteList.deleted",
@@ -137,7 +137,7 @@
protected PersonList getFavoriteList() {
if (favoriteList == null) {
- favoriteList = newService(UserService.class).newFavoriteList();
+ favoriteList = newService(FavoriteService.class).newFavoriteList();
}
return favoriteList;
}
1
0
r3135 - in branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services: . impl
by tchemit@users.chorem.org 22 Feb '12
by tchemit@users.chorem.org 22 Feb '12
22 Feb '12
Author: tchemit
Date: 2012-02-22 13:07:31 +0100 (Wed, 22 Feb 2012)
New Revision: 3135
Url: http://chorem.org/repositories/revision/pollen/3135
Log:
use nuiton-struts2 filter pager bean + improve some code
Removed:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenPagerBean.java
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
Deleted: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenPagerBean.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenPagerBean.java 2012-02-22 12:06:41 UTC (rev 3134)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenPagerBean.java 2012-02-22 12:07:31 UTC (rev 3135)
@@ -1,94 +0,0 @@
-/*
- * #%L
- * Pollen :: Services
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.services;
-
-import org.apache.commons.lang3.StringUtils;
-import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.util.PagerUtil;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Override nuiton pager while adding sort informations.
- * <p/>
- * Maybe this should be push back to nuiton ?
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class PollenPagerBean extends PagerUtil.PagerBean {
-
- private static final long serialVersionUID = 1L;
-
- // sorting order - asc or desc
- protected boolean sortAscendant;
-
- // get index row - i.e. user click to sort.
- protected String sortColumn;
-
- public boolean isSortAscendant() {
- return sortAscendant;
- }
-
- public void setSortAscendant(boolean sortAscendant) {
- this.sortAscendant = sortAscendant;
- }
-
- public String getSortColumn() {
- return sortColumn;
- }
-
- public void setSortColumn(String sortColumn) {
- this.sortColumn = sortColumn;
- }
-
- public static TopiaQuery addPagerToQuery(TopiaQuery query,
- PollenPagerBean pager) {
- PagerUtil.computeRecordIndexesAndPagesNumber(pager);
- query.setLimit(pager.getRecordStartIndex(),
- pager.getRecordEndIndex() - 1);
-
- if (StringUtils.isNotEmpty(pager.getSortColumn())) {
- if (pager.isSortAscendant()) {
- query.addOrder(pager.getSortColumn());
- } else {
- query.addOrderDesc(pager.getSortColumn());
- }
- }
- return query;
- }
-
- public static <E> List<E> getPageFromList(List<E> elements,
- PollenPagerBean pager) {
-
- PagerUtil.computeRecordIndexesAndPagesNumber(pager);
- List<E> subList = elements.subList(pager.getRecordStartIndex(),
- pager.getRecordEndIndex());
- List<E> result = new ArrayList<E>(subList);
-
- return result;
- }
-
-}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-02-22 12:06:41 UTC (rev 3134)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-02-22 12:07:31 UTC (rev 3135)
@@ -83,6 +83,24 @@
}
}
+ public <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(Class<T> entityType) {
+ Preconditions.checkNotNull(entityType);
+ try {
+ D dao = PollenDAOHelper.getDAO(getTransaction(), entityType);
+ return dao;
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException("Could not obtain dao of type " + entityType.getName(), e);
+ }
+ }
+
+ protected <T extends TopiaEntity, D extends TopiaDAO<? super T>> T newInstance(D dao) {
+ try {
+ return (T) dao.newInstance();
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException("Could not obtain new instance from dao " + dao, e);
+ }
+ }
+
protected TopiaContext getTransaction() {
return serviceContext.getTransaction();
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java 2012-02-22 12:06:41 UTC (rev 3134)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java 2012-02-22 12:07:31 UTC (rev 3135)
@@ -23,6 +23,7 @@
*/
package org.chorem.pollen.services.impl;
+import com.google.common.base.Preconditions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.mail.EmailException;
@@ -39,6 +40,11 @@
public void sendEmail(String to,
String subject,
String content) {
+
+ Preconditions.checkNotNull(to);
+ Preconditions.checkNotNull(subject);
+ Preconditions.checkNotNull(content);
+
try {
// Create the SimpleEmail to send
SimpleEmail email = createSimpleEmail(to, subject, content);
@@ -65,6 +71,11 @@
String to,
String subject,
String content) throws EmailException {
+
+ Preconditions.checkNotNull(to);
+ Preconditions.checkNotNull(subject);
+ Preconditions.checkNotNull(content);
+
PollenConfiguration configuration = getConfiguration();
SimpleEmail result = new SimpleEmail();
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-02-22 12:06:41 UTC (rev 3134)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-02-22 12:07:31 UTC (rev 3135)
@@ -23,15 +23,368 @@
*/
package org.chorem.pollen.services.impl;
+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;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollAccountDAO;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.UserAccountDAO;
import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exceptions.FavoriteListAlreadyExistException;
+import org.chorem.pollen.services.exceptions.FavoriteListNotFoundException;
+import org.chorem.pollen.services.exceptions.FavoriteListNotOwnedByUserException;
+import org.chorem.pollen.services.exceptions.ParticipantAlreadyFoundInListException;
+import org.chorem.pollen.services.exceptions.ParticipantNotFoundException;
+import org.chorem.pollen.services.exceptions.ParticipantNotFoundInListException;
+import org.chorem.pollen.services.exceptions.UserNotFoundException;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.web.struts2.FilterPagerUtil;
+import java.util.List;
+
public class FavoriteService extends PollenServiceSupport {
/** Logger. */
private static final Log log = LogFactory.getLog(FavoriteService.class);
+ public List<PersonList> getFavoriteLists(UserAccount user,
+ FilterPagerUtil.FilterPagerBean pager) {
+
+ Preconditions.checkNotNull(user);
+
+ PersonListDAO dao = getDAO(PersonList.class);
+
+ try {
+
+ TopiaQuery countQuery = dao.createQuery("e");
+ countQuery.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
+ long records = dao.countByQuery(countQuery);
+
+ pager.setRecords((int) records);
+
+ TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery, pager);
+
+ List<PersonList> result = dao.findAllByQuery(query);
+ return result;
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public List<PersonList> getFavoriteLists(UserAccount user) {
+
+ Preconditions.checkNotNull(user);
+
+ PersonListDAO dao = getDAO(PersonList.class);
+
+ try {
+
+ TopiaQuery query = dao.createQuery("e");
+ query.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
+ List<PersonList> result = dao.findAllByQuery(query);
+ return result;
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public PersonList getFavoriteList(UserAccount user,
+ String favoriteListId) throws FavoriteListNotFoundException, FavoriteListNotOwnedByUserException {
+
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(favoriteListId);
+
+ PersonListDAO dao = getDAO(PersonList.class);
+
+ try {
+
+ PersonList favoriteList = dao.findByTopiaId(favoriteListId);
+
+ if (favoriteList == null) {
+ throw new FavoriteListNotFoundException();
+ }
+
+ // check this favorite belongs to the given user
+ UserAccount favoriteListOwner = favoriteList.getOwner();
+ if (!favoriteListOwner.equals(user)) {
+ throw new FavoriteListNotOwnedByUserException();
+ }
+
+ return favoriteList;
+
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public List<PollAccount> getFavoriteListUsers(PersonList favoriteList,
+ FilterPagerUtil.FilterPagerBean pager) {
+
+ Preconditions.checkNotNull(favoriteList);
+ Preconditions.checkNotNull(pager);
+
+ PollAccountDAO dao = getDAO(PollAccount.class);
+
+ try {
+
+ int records = favoriteList.sizePollAccount();
+ pager.setRecords(records);
+
+ TopiaQuery query = dao.createQuery("e");
+ FilterPagerUtil.addPagerToQuery(query, pager);
+ query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, favoriteList);
+
+ List<PollAccount> result = dao.findAllByQuery(query);
+ return result;
+
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public void createFavoriteList(UserAccount user,
+ String name) throws FavoriteListAlreadyExistException, UserNotFoundException {
+
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(name);
+
+ // can't accept favorite list without name
+ Preconditions.checkArgument(StringUtils.isNotEmpty(name));
+
+ UserAccountDAO userDAO = getDAO(UserAccount.class);
+ PersonListDAO dao = getDAO(PersonList.class);
+
+ try {
+
+ UserAccount userToUse =
+ userDAO.findByTopiaId(user.getTopiaId());
+
+ if (userToUse == null) {
+ throw new UserNotFoundException();
+ }
+
+ // check list does not already exists
+
+ TopiaQuery query = dao.createQuery("e");
+
+ query.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
+ query.addWhere("e." + PersonList.PROPERTY_NAME, TopiaQuery.Op.EQ, name);
+
+ boolean exist = dao.existByQuery(query);
+
+ if (exist) {
+
+ throw new FavoriteListAlreadyExistException();
+ }
+
+ PersonList favoriteListCreated = dao.create(
+ PersonList.PROPERTY_OWNER, userToUse
+ );
+ favoriteListCreated.setName(name);
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public PersonList deleteFavoriteList(UserAccount user,
+ PersonList favoriteList) throws FavoriteListNotFoundException, FavoriteListNotOwnedByUserException, UserNotFoundException {
+
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(favoriteList);
+
+ UserAccountDAO userDAO = getDAO(UserAccount.class);
+ PersonListDAO dao = getDAO(PersonList.class);
+
+ try {
+
+ UserAccount userToUse =
+ userDAO.findByTopiaId(user.getTopiaId());
+
+ if (userToUse == null) {
+ throw new UserNotFoundException();
+ }
+
+ PersonList favoriteListToDelete =
+ dao.findByTopiaId(favoriteList.getTopiaId());
+
+ if (favoriteListToDelete == null) {
+ throw new FavoriteListNotFoundException();
+ }
+
+ // check this favorite belongs to the given user
+ UserAccount favoriteListOwner = favoriteListToDelete.getOwner();
+ if (!favoriteListOwner.equals(user)) {
+ throw new FavoriteListNotOwnedByUserException();
+ }
+
+ dao.delete(favoriteListToDelete);
+ return favoriteListToDelete;
+
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public void addPollAccountToFavoriteList(PersonList favoriteList,
+ PollAccount pollAccount) throws ParticipantAlreadyFoundInListException, FavoriteListNotFoundException {
+
+ Preconditions.checkNotNull(favoriteList);
+ Preconditions.checkNotNull(pollAccount);
+
+ // can't accept poll account without name
+ Preconditions.checkArgument(
+ StringUtils.isNotEmpty(pollAccount.getVotingId()));
+
+ // can't accept poll account without email
+ Preconditions.checkArgument(
+ StringUtils.isNotEmpty(pollAccount.getEmail()));
+
+ PollAccountDAO dao = getDAO(PollAccount.class);
+ PersonListDAO personListDAO = getDAO(PersonList.class);
+
+ try {
+
+ PersonList personListToUpdate =
+ personListDAO.findByTopiaId(favoriteList.getTopiaId());
+
+ if (personListToUpdate == null) {
+ throw new FavoriteListNotFoundException();
+ }
+
+ // check there is other poll account in this list with same id
+ TopiaQuery query = dao.createQuery("e");
+ query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
+ query.addWhere("e." + PollAccount.PROPERTY_VOTING_ID, TopiaQuery.Op.EQ, pollAccount.getVotingId());
+ boolean pollAccountExists = dao.existByQuery(query);
+ if (pollAccountExists) {
+
+ throw new ParticipantAlreadyFoundInListException();
+ }
+
+ PollAccount pollAccountCreated =
+ dao.create(PollAccount.PROPERTY_PERSON_LIST,
+ personListToUpdate);
+
+ pollAccountCreated.setVotingId(pollAccount.getVotingId());
+ pollAccountCreated.setEmail(pollAccount.getEmail());
+ personListToUpdate.addPollAccount(pollAccountCreated);
+
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public void editPollAccountToFavoriteList(PersonList favoriteList,
+ PollAccount pollAccount) throws ParticipantAlreadyFoundInListException, FavoriteListNotFoundException, ParticipantNotFoundException {
+
+ Preconditions.checkNotNull(favoriteList);
+ Preconditions.checkNotNull(pollAccount);
+
+ // can't accept poll account without name
+ Preconditions.checkArgument(
+ StringUtils.isNotEmpty(pollAccount.getVotingId()));
+
+ // can't accept poll account without email
+ Preconditions.checkArgument(
+ StringUtils.isNotEmpty(pollAccount.getEmail()));
+
+ PollAccountDAO dao = getDAO(PollAccount.class);
+ PersonListDAO personListDAO = getDAO(PersonList.class);
+
+ try {
+
+ PersonList personListToUpdate =
+ personListDAO.findByTopiaId(favoriteList.getTopiaId());
+
+ if (personListToUpdate == null) {
+ throw new FavoriteListNotFoundException();
+ }
+
+ PollAccount pollAccountToUpdate =
+ dao.findByTopiaId(pollAccount.getTopiaId());
+
+ if (pollAccountToUpdate == null) {
+ throw new ParticipantNotFoundException();
+ }
+
+ // check there is another poll account in this list with same id
+ TopiaQuery query = dao.createQuery("e");
+ query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
+ query.addWhere("e." + PollAccount.PROPERTY_VOTING_ID, TopiaQuery.Op.EQ, pollAccount.getVotingId());
+ query.addWhere("e." + PollAccount.TOPIA_ID, TopiaQuery.Op.NEQ, pollAccount.getTopiaId());
+ boolean pollAccountExists = dao.existByQuery(query);
+ if (pollAccountExists) {
+
+ throw new ParticipantAlreadyFoundInListException();
+ }
+
+ pollAccountToUpdate.setVotingId(pollAccount.getVotingId());
+ pollAccountToUpdate.setEmail(pollAccount.getEmail());
+
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public void removePollAccountToFavoriteList(PersonList favoriteList,
+ PollAccount pollAccount) throws ParticipantNotFoundException, FavoriteListNotFoundException, ParticipantNotFoundInListException {
+
+ Preconditions.checkNotNull(favoriteList);
+ Preconditions.checkNotNull(pollAccount);
+
+ PollAccountDAO dao = getDAO(PollAccount.class);
+ PersonListDAO personListDAO = getDAO(PersonList.class);
+
+ try {
+
+ PersonList personListToUpdate =
+ personListDAO.findByTopiaId(favoriteList.getTopiaId());
+
+ if (personListToUpdate == null) {
+ throw new FavoriteListNotFoundException();
+ }
+
+ PollAccount pollAccountToRemove =
+ dao.findByTopiaId(pollAccount.getTopiaId());
+
+ if (pollAccountToRemove == null) {
+
+ throw new ParticipantNotFoundException();
+ }
+
+ PollAccount pollAccountInList =
+ personListToUpdate.getPollAccountByTopiaId(pollAccount.getTopiaId());
+
+ if (pollAccountInList == null) {
+
+ throw new ParticipantNotFoundInListException();
+ }
+
+ personListToUpdate.removePollAccount(pollAccountToRemove);
+
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(e);
+ }
+ }
+
+ public PersonList newFavoriteList() {
+ PersonListDAO dao = getDAO(PersonList.class);
+ PersonList personList = newInstance(dao);
+ return personList;
+ }
+
+ public PollAccount newPollAccountForFavoriteList() {
+ PollAccountDAO dao = getDAO(PollAccount.class);
+ PollAccount pollAccount = newInstance(dao);
+ return pollAccount;
+ }
+
// public void createFavoriteParticipant(FavoriteParticipant participant) throws ParticipantExistWithoutMailException, ParticipantAlreadyFoundInListException {
// try {
// FavoriteParticipantDAO dao =
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-02-22 12:06:41 UTC (rev 3134)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-02-22 12:07:31 UTC (rev 3135)
@@ -23,6 +23,7 @@
*/
package org.chorem.pollen.services.impl;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -31,18 +32,16 @@
import org.chorem.pollen.business.persistence.PersonToList;
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.PollAccountDAO;
import org.chorem.pollen.business.persistence.PollDAO;
-import org.chorem.pollen.business.persistence.PollImpl;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteDAO;
import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.entities.PollenDAOHelper;
-import org.chorem.pollen.services.PollenPagerBean;
import org.chorem.pollen.services.PollenServiceSupport;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.web.struts2.FilterPagerUtil;
import java.util.List;
@@ -58,8 +57,10 @@
* @return Build a new Poll instance with given {@code user} as administrator
*/
public Poll getNewPoll(UserAccount user) {
- Poll result = new PollImpl();
+ PollDAO pollDAO = getDAO(Poll.class);
+ Poll result = newInstance(pollDAO);
+
PollenConfiguration configuration = getConfiguration();
// default values from configuration
@@ -68,7 +69,8 @@
result.setPollType(configuration.getDefaultPollType());
// Initialize creator as an admin for the poll
- PollAccount creator = new PollAccountImpl();
+ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
+ PollAccount creator = newInstance(pollAccountDAO);
// creator.setAdmin(true);
if (user != null) {
// Link the creator with the user
@@ -83,16 +85,19 @@
return result;
}
- public List<Poll> getPolls(PollenPagerBean pager) {
+ public List<Poll> getPolls(FilterPagerUtil.FilterPagerBean pager) {
+ Preconditions.checkNotNull(pager);
+
+ PollDAO dao = getDAO(Poll.class);
+
try {
- PollDAO dao = PollenDAOHelper.getPollDAO(getTransaction());
long records = dao.count();
pager.setRecords((int) records);
TopiaQuery query = dao.createQuery("e");
- PollenPagerBean.addPagerToQuery(query, pager);
+ FilterPagerUtil.addPagerToQuery(query, pager);
List<Poll> result = dao.findAllByQuery(query);
return result;
@@ -101,17 +106,21 @@
}
}
- public List<Poll> getCreatedPolls(PollenPagerBean pager, UserAccount user) {
+ public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) {
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(user);
+
+ PollDAO dao = getDAO(Poll.class);
+
try {
- PollDAO dao = PollenDAOHelper.getPollDAO(getTransaction());
TopiaQuery countQuery = dao.createQuery("e");
countQuery.addWhere("e." + Poll.PROPERTY_CREATOR + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, user);
long records = dao.countByQuery(countQuery);
pager.setRecords((int) records);
- TopiaQuery query = PollenPagerBean.addPagerToQuery(countQuery, pager);
+ TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery, pager);
List<Poll> result = dao.findAllByQuery(query);
return result;
@@ -120,8 +129,11 @@
}
}
- public List<Poll> getInvitedPolls(PollenPagerBean pager, UserAccount user) {
+ public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) {
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(user);
+
UserService userService = newService(UserService.class);
UserAccount userToUse = userService.getEntityById(UserAccount.class, user.getTopiaId());
@@ -152,7 +164,7 @@
int records = allPolls.size();
pager.setRecords(records);
- List<Poll> result = PollenPagerBean.getPageFromList(allPolls, pager);
+ List<Poll> result = FilterPagerUtil.getPageFromList(allPolls, pager);
return result;
// try {
@@ -164,7 +176,7 @@
//
// PagerUtil.computeRecordIndexesAndPagesNumber(pager);
// TopiaQuery query = dao.createQuery("e");
-// PollenPagerBean.addPagerToQuery(pager, query);
+// FilterPagerUtil.addPagerToQuery(pager, query);
// query.addWhere("e." + Poll.PROPERTY_CREATOR + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, user);
//
// List<Poll> result = dao.findAllByQuery(query);
@@ -174,9 +186,12 @@
// }
}
- public List<Poll> getParticipatedPolls(PollenPagerBean pager,
+ public List<Poll> getParticipatedPolls(FilterPagerUtil.FilterPagerBean pager,
UserAccount user) {
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(user);
+
//FIXME Use a query to do this to avoid in memory pagination
UserService userService = newService(UserService.class);
@@ -195,13 +210,14 @@
// int records = allPolls.size();
// pager.setRecords(records);
// PagerUtil.computeRecordIndexesAndPagesNumber(pager);
-// List<Poll> result = PollenPagerBean.getPageFromList(allPolls, pager);
+// List<Poll> result = FilterPagerUtil.getPageFromList(allPolls, pager);
// return result;
+ PollDAO pollDao = getDAO(Poll.class);
+ VoteDAO voteDao = getDAO(Vote.class);
+
try {
- PollDAO pollDao = PollenDAOHelper.getPollDAO(getTransaction());
- VoteDAO voteDao = PollenDAOHelper.getVoteDAO(getTransaction());
TopiaQuery countQuery = voteDao.createQuery("e").
addDistinct().
@@ -211,7 +227,7 @@
long records = pollDao.countByQuery(countQuery);
pager.setRecords((int) records);
- TopiaQuery query = PollenPagerBean.addPagerToQuery(countQuery, pager);
+ TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery, pager);
// query.addDistinct();
// query.setSelect("e." + Vote.PROPERTY_POLL);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-02-22 12:06:41 UTC (rev 3134)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-02-22 12:07:31 UTC (rev 3135)
@@ -29,25 +29,10 @@
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;
-import org.chorem.pollen.business.persistence.PersonListImpl;
-import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.PollAccountDAO;
-import org.chorem.pollen.business.persistence.PollAccountImpl;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.UserAccountDAO;
-import org.chorem.pollen.business.persistence.UserAccountImpl;
import org.chorem.pollen.entities.PollenBinderHelper;
-import org.chorem.pollen.entities.PollenDAOHelper;
-import org.chorem.pollen.services.PollenPagerBean;
import org.chorem.pollen.services.PollenServiceSupport;
-import org.chorem.pollen.services.exceptions.FavoriteListAlreadyExistException;
-import org.chorem.pollen.services.exceptions.FavoriteListNotFoundException;
-import org.chorem.pollen.services.exceptions.FavoriteListNotOwnedByUserException;
-import org.chorem.pollen.services.exceptions.ParticipantAlreadyFoundInListException;
-import org.chorem.pollen.services.exceptions.ParticipantNotFoundException;
-import org.chorem.pollen.services.exceptions.ParticipantNotFoundInListException;
import org.chorem.pollen.services.exceptions.UserEmailAlreadyUsedException;
import org.chorem.pollen.services.exceptions.UserInvalidPasswordException;
import org.chorem.pollen.services.exceptions.UserLoginAlreadyUsedException;
@@ -57,6 +42,7 @@
import org.nuiton.topia.persistence.util.TopiaEntityBinder;
import org.nuiton.util.StringUtil;
import org.nuiton.util.beans.Binder;
+import org.nuiton.web.struts2.FilterPagerUtil;
import java.net.URL;
import java.util.List;
@@ -71,9 +57,13 @@
private static final Log log = LogFactory.getLog(UserService.class);
public UserAccount connect(String login, String password) throws UserNotFoundException, UserInvalidPasswordException {
+
+ Preconditions.checkNotNull(login);
+ Preconditions.checkNotNull(password);
+
+ UserAccountDAO dao = getDAO(UserAccount.class);
+
try {
- UserAccountDAO dao =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
UserAccount user = dao.findByLogin(login);
@@ -96,12 +86,14 @@
boolean byAdmin,
URL url) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException {
+ Preconditions.checkNotNull(user);
+
String password = user.getPassword(); // le mot de passe en clair
+ UserAccountDAO dao = getDAO(UserAccount.class);
+
UserAccount userAccount;
try {
- UserAccountDAO dao =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
UserAccount userByLogin = dao.findByLogin(user.getLogin());
if (userByLogin != null) {
@@ -153,11 +145,12 @@
String newPassword,
boolean byAdmin) throws UserEmailAlreadyUsedException, UserInvalidPasswordException {
- try {
+ Preconditions.checkNotNull(user);
- UserAccountDAO dao =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
+ UserAccountDAO dao = getDAO(UserAccount.class);
+ try {
+
UserAccount userToUpdate = dao.findByTopiaId(user.getTopiaId());
// Do not manage password for an admin update
@@ -200,14 +193,18 @@
}
public UserAccount getNewUser() {
- UserAccount result = new UserAccountImpl();
+ UserAccountDAO dao = getDAO(UserAccount.class);
+ UserAccount result = newInstance(dao);
return result;
}
public void deleteUser(String id) throws UserNotFoundException {
+
+ Preconditions.checkNotNull(id);
+
+ UserAccountDAO dao = getDAO(UserAccount.class);
+
try {
- UserAccountDAO dao =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
UserAccount user = dao.findByTopiaId(id);
if (user == null) {
@@ -219,17 +216,19 @@
}
}
- public List<UserAccount> getUsers(PollenPagerBean pager) {
+ public List<UserAccount> getUsers(FilterPagerUtil.FilterPagerBean pager) {
+ Preconditions.checkNotNull(pager);
+
+ UserAccountDAO dao = getDAO(UserAccount.class);
+
try {
- UserAccountDAO dao =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
long records = dao.count();
pager.setRecords((int) records);
TopiaQuery query = dao.createQuery("e");
- PollenPagerBean.addPagerToQuery(query, pager);
+ FilterPagerUtil.addPagerToQuery(query, pager);
List<UserAccount> result = dao.findAllByQuery(query);
return result;
@@ -238,336 +237,11 @@
}
}
- public List<PersonList> getFavoriteLists(UserAccount user,
- PollenPagerBean pager) {
+ public int getNbUsers() {
- try {
+ UserAccountDAO dao = getDAO(UserAccount.class);
- PersonListDAO dao =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- TopiaQuery countQuery = dao.createQuery("e");
- countQuery.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
- long records = dao.countByQuery(countQuery);
-
- pager.setRecords((int) records);
-
- TopiaQuery query = PollenPagerBean.addPagerToQuery(countQuery, pager);
-
- List<PersonList> result = dao.findAllByQuery(query);
- return result;
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public List<PersonList> getFavoriteLists(UserAccount user) {
try {
-
- PersonListDAO dao =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- TopiaQuery query = dao.createQuery("e");
- query.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
- List<PersonList> result = dao.findAllByQuery(query);
- return result;
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public PersonList getFavoriteList(UserAccount user,
- String favoriteListId) throws FavoriteListNotFoundException, FavoriteListNotOwnedByUserException {
- try {
-
- PersonListDAO dao =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- PersonList favoriteList = dao.findByTopiaId(favoriteListId);
-
- if (favoriteList == null) {
- throw new FavoriteListNotFoundException();
- }
-
- // check this favorite belongs to the given user
- UserAccount favoriteListOwner = favoriteList.getOwner();
- if (!favoriteListOwner.equals(user)) {
- throw new FavoriteListNotOwnedByUserException();
- }
-
- return favoriteList;
-
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public List<PollAccount> getFavoriteListUsers(PersonList favoriteList,
- PollenPagerBean pager) {
-
- Preconditions.checkNotNull(favoriteList);
- Preconditions.checkNotNull(pager);
- try {
-
- int records = favoriteList.sizePollAccount();
- pager.setRecords(records);
-
- PollAccountDAO dao =
- PollenDAOHelper.getPollAccountDAO(getTransaction());
-
- TopiaQuery query = dao.createQuery("e");
- PollenPagerBean.addPagerToQuery(query, pager);
- query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, favoriteList);
-
- List<PollAccount> result = dao.findAllByQuery(query);
- return result;
-
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public void createFavoriteList(UserAccount user,
- String name) throws FavoriteListAlreadyExistException, UserNotFoundException {
-
- Preconditions.checkNotNull(user);
- Preconditions.checkNotNull(name);
-
- // can't accept favorite list without name
- Preconditions.checkArgument(StringUtils.isNotEmpty(name));
- try {
-
- UserAccountDAO userDAO =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
-
- UserAccount userToUse =
- userDAO.findByTopiaId(user.getTopiaId());
-
- if (userToUse == null) {
- throw new UserNotFoundException();
- }
-
- PersonListDAO dao =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- // check list does not already exists
-
- TopiaQuery query = dao.createQuery("e");
-
- query.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
- query.addWhere("e." + PersonList.PROPERTY_NAME, TopiaQuery.Op.EQ, name);
-
- boolean exist = dao.existByQuery(query);
-
- if (exist) {
-
- throw new FavoriteListAlreadyExistException();
- }
-
- PersonList favoriteListCreated = dao.create(
- PersonList.PROPERTY_OWNER, userToUse
- );
- favoriteListCreated.setName(name);
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public PersonList deleteFavoriteList(UserAccount user,
- PersonList favoriteList) throws FavoriteListNotFoundException, FavoriteListNotOwnedByUserException, UserNotFoundException {
- try {
-
- Preconditions.checkNotNull(user);
- Preconditions.checkNotNull(favoriteList);
-
- UserAccountDAO userDAO =
- PollenDAOHelper.getUserAccountDAO(getTransaction());
-
- UserAccount userToUse =
- userDAO.findByTopiaId(user.getTopiaId());
-
- if (userToUse == null) {
- throw new UserNotFoundException();
- }
-
- PersonListDAO dao =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- PersonList favoriteListToDelete =
- dao.findByTopiaId(favoriteList.getTopiaId());
-
- if (favoriteListToDelete == null) {
- throw new FavoriteListNotFoundException();
- }
-
- // check this favorite belongs to the given user
- UserAccount favoriteListOwner = favoriteListToDelete.getOwner();
- if (!favoriteListOwner.equals(user)) {
- throw new FavoriteListNotOwnedByUserException();
- }
-
- dao.delete(favoriteListToDelete);
- return favoriteListToDelete;
-
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public void addPollAccountToFavoriteList(PersonList favoriteList,
- PollAccount pollAccount) throws ParticipantAlreadyFoundInListException, FavoriteListNotFoundException {
-
- Preconditions.checkNotNull(favoriteList);
- Preconditions.checkNotNull(pollAccount);
-
- // can't accept poll account without name
- Preconditions.checkArgument(
- StringUtils.isNotEmpty(pollAccount.getVotingId()));
-
- // can't accept poll account without email
- Preconditions.checkArgument(
- StringUtils.isNotEmpty(pollAccount.getEmail()));
-
- try {
-
- PersonListDAO personListDAO =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- PersonList personListToUpdate =
- personListDAO.findByTopiaId(favoriteList.getTopiaId());
-
- if (personListToUpdate == null) {
- throw new FavoriteListNotFoundException();
- }
-
- PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(getTransaction());
-
- // check there is other poll account in this list with same id
- TopiaQuery query = dao.createQuery("e");
- query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
- query.addWhere("e." + PollAccount.PROPERTY_VOTING_ID, TopiaQuery.Op.EQ, pollAccount.getVotingId());
- boolean pollAccountExists = dao.existByQuery(query);
- if (pollAccountExists) {
-
- throw new ParticipantAlreadyFoundInListException();
- }
-
- PollAccount pollAccountCreated =
- dao.create(PollAccount.PROPERTY_PERSON_LIST,
- personListToUpdate);
-
- pollAccountCreated.setVotingId(pollAccount.getVotingId());
- pollAccountCreated.setEmail(pollAccount.getEmail());
- personListToUpdate.addPollAccount(pollAccountCreated);
-
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public void editPollAccountToFavoriteList(PersonList favoriteList,
- PollAccount pollAccount) throws ParticipantAlreadyFoundInListException, FavoriteListNotFoundException, ParticipantNotFoundException {
-
- Preconditions.checkNotNull(favoriteList);
- Preconditions.checkNotNull(pollAccount);
-
- // can't accept poll account without name
- Preconditions.checkArgument(
- StringUtils.isNotEmpty(pollAccount.getVotingId()));
-
- // can't accept poll account without email
- Preconditions.checkArgument(
- StringUtils.isNotEmpty(pollAccount.getEmail()));
-
- try {
-
- PersonListDAO personListDAO =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- PersonList personListToUpdate =
- personListDAO.findByTopiaId(favoriteList.getTopiaId());
-
- if (personListToUpdate == null) {
- throw new FavoriteListNotFoundException();
- }
-
- PollAccountDAO dao =
- PollenDAOHelper.getPollAccountDAO(getTransaction());
-
-
- PollAccount pollAccountToUpdate =
- dao.findByTopiaId(pollAccount.getTopiaId());
-
- if (pollAccountToUpdate == null) {
- throw new ParticipantNotFoundException();
- }
-
- // check there is another poll account in this list with same id
- TopiaQuery query = dao.createQuery("e");
- query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
- query.addWhere("e." + PollAccount.PROPERTY_VOTING_ID, TopiaQuery.Op.EQ, pollAccount.getVotingId());
- query.addWhere("e." + PollAccount.TOPIA_ID, TopiaQuery.Op.NEQ, pollAccount.getTopiaId());
- boolean pollAccountExists = dao.existByQuery(query);
- if (pollAccountExists) {
-
- throw new ParticipantAlreadyFoundInListException();
- }
-
- pollAccountToUpdate.setVotingId(pollAccount.getVotingId());
- pollAccountToUpdate.setEmail(pollAccount.getEmail());
-
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public void removePollAccountToFavoriteList(PersonList favoriteList,
- PollAccount pollAccount) throws ParticipantNotFoundException, FavoriteListNotFoundException, ParticipantNotFoundInListException {
-
- Preconditions.checkNotNull(favoriteList);
- Preconditions.checkNotNull(pollAccount);
-
- try {
-
- PersonListDAO personListDAO =
- PollenDAOHelper.getPersonListDAO(getTransaction());
-
- PersonList personListToUpdate =
- personListDAO.findByTopiaId(favoriteList.getTopiaId());
-
- if (personListToUpdate == null) {
- throw new FavoriteListNotFoundException();
- }
-
- PollAccountDAO dao =
- PollenDAOHelper.getPollAccountDAO(getTransaction());
-
- PollAccount pollAccountToRemove =
- dao.findByTopiaId(pollAccount.getTopiaId());
-
- if (pollAccountToRemove == null) {
-
- throw new ParticipantNotFoundException();
- }
-
- PollAccount pollAccountInList =
- personListToUpdate.getPollAccountByTopiaId(pollAccount.getTopiaId());
-
- if (pollAccountInList == null) {
-
- throw new ParticipantNotFoundInListException();
- }
-
- personListToUpdate.removePollAccount(pollAccountToRemove);
-
- } catch (TopiaException e) {
- throw new PollenTechnicalException(e);
- }
- }
-
- public int getNbUsers() {
- try {
- UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(getTransaction());
Long result = dao.count();
return result.intValue();
} catch (TopiaException e) {
@@ -576,7 +250,9 @@
}
public void createDefaultUsers() {
+
UserAccount user = getNewUser();
+
user.setAdministrator(true);
String login = getConfiguration().getAdminLogin();
user.setLogin(login);
@@ -621,12 +297,4 @@
destination.setEmail(StringUtils.lowerCase(source.getEmail()));
}
- public PersonList newFavoriteList() {
- PersonListImpl personList = new PersonListImpl();
- return personList;
- }
-
- public PollAccount newPollAccountForFavoriteList() {
- return new PollAccountImpl();
- }
}
1
0
22 Feb '12
Author: tchemit
Date: 2012-02-22 13:06:41 +0100 (Wed, 22 Feb 2012)
New Revision: 3134
Url: http://chorem.org/repositories/revision/pollen/3134
Log:
use nuiton-struts2 in service module to have the pager
Modified:
branches/pollen-1.2.6-struts2/pollen-services/pom.xml
Modified: branches/pollen-1.2.6-struts2/pollen-services/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/pom.xml 2012-02-22 12:06:04 UTC (rev 3133)
+++ branches/pollen-1.2.6-struts2/pollen-services/pom.xml 2012-02-22 12:06:41 UTC (rev 3134)
@@ -62,6 +62,10 @@
<artifactId>mail</artifactId>
</dependency>
<dependency>
+ <groupId>org.nuiton.web</groupId>
+ <artifactId>nuiton-struts2</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
</dependency>
1
0