Author: tchemit Date: 2012-03-07 17:56:43 +0100 (Wed, 07 Mar 2012) New Revision: 3167 Url: http://chorem.org/repositories/revision/pollen/3167 Log: reuse the siteUrl applicationUrl, safer than using url from request... rename poll actions (to be uniform with other actions of the package) prefer commit in service instead of action continue create action add PollenNotifierWorker Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java Removed: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.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/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/poll/AddComment.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.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/DeleteVote.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.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-poll.xml branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.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/PollenApplicationContext.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -24,10 +24,9 @@ package org.chorem.pollen.ui; import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.services.PollenNotifierWorker; import org.nuiton.topia.TopiaContext; -import java.net.URL; - /** * @author tchemit <chemit@codelutin.com> * @since 1.2.6 @@ -38,7 +37,7 @@ protected TopiaContext rootContext; - protected URL applicationUrl; + protected PollenNotifierWorker pollenNotifierWorker; public PollenConfiguration getConfiguration() { return configuration; @@ -56,11 +55,11 @@ this.rootContext = rootContext; } - public URL getApplicationUrl() { - return applicationUrl; + public PollenNotifierWorker getPollenNotifierWorker() { + return pollenNotifierWorker; } - public void setApplicationUrl(URL applicationUrl) { - this.applicationUrl = applicationUrl; + public void setPollenNotifierWorker(PollenNotifierWorker pollenNotifierWorker) { + this.pollenNotifierWorker = pollenNotifierWorker; } } 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -30,6 +30,7 @@ import org.chorem.pollen.PollenTopiaRootContextFactory; import org.chorem.pollen.entities.PollenDAOHelper; import org.chorem.pollen.services.DefaultPollenServiceContext; +import org.chorem.pollen.services.PollenNotifierWorker; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.PollenServiceFactory; import org.chorem.pollen.services.impl.UserService; @@ -42,6 +43,7 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import java.io.IOException; import java.util.Date; import java.util.Locale; @@ -62,8 +64,6 @@ protected static final Log log = LogFactory.getLog(PollenApplicationListener.class); - private TopiaContext rootContext; - @Override public void contextInitialized(ServletContextEvent sce) { @@ -85,11 +85,12 @@ applicationContext.setConfiguration(configuration); if (log.isInfoEnabled()) { - log.info("Initializing RootContextSupplier..."); + log.info("Initializing RootContext..."); } PollenTopiaRootContextFactory factory = new PollenTopiaRootContextFactory(); - rootContext = factory.newDatabaseFromConfig(configuration); + TopiaContext rootContext + = factory.newDatabaseFromConfig(configuration); applicationContext.setRootContext(rootContext); // init db @@ -99,6 +100,9 @@ } catch (TopiaException e) { throw new PollenTechnicalException("Could not init db", e); } + + // int pollen notifier worker + initPollenNotifierworker(applicationContext); } @Override @@ -107,9 +111,60 @@ if (log.isInfoEnabled()) { log.info("Application is ending at " + new Date() + "..."); } + + PollenApplicationContext applicationContext = + (PollenApplicationContext) sce.getServletContext().getAttribute(PollenActionSupport.APPLICATION_CONTEXT_PARAMETER); + + if (applicationContext != null) { + + // close pollen notifier worker + closePollenNotifierWorker(applicationContext.getPollenNotifierWorker()); + + // close topia root context to pollen db + closeRootcontext(applicationContext.getRootContext()); + + + } + } + + private void initPollenNotifierworker(PollenApplicationContext applicationContext) { + PollenServiceContext serviceContext = DefaultPollenServiceContext.newContext( + Locale.getDefault(), + null, + applicationContext.getConfiguration(), + new PollenServiceFactory() + ); + PollenNotifierWorker pollenNotifierWorker = new PollenNotifierWorker( + serviceContext, + applicationContext.getRootContext() + ); + applicationContext.setPollenNotifierWorker(pollenNotifierWorker); + + pollenNotifierWorker.run(); + } + + private void closePollenNotifierWorker(PollenNotifierWorker pollenNotifierWorker) { + + if (pollenNotifierWorker != null) { + if (log.isInfoEnabled()) { + log.info("Shuting down pollenNotifierWorker... " + + pollenNotifierWorker); + } + try { + pollenNotifierWorker.close(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not close pollenNotifierWorker", e); + } + } + } + } + + private void closeRootcontext(TopiaContext rootContext) { + if (rootContext != null) { if (log.isInfoEnabled()) { - log.info("Shuting down RootContextSupplier..."); + log.info("Shuting down RootContext... " + rootContext); } if (!rootContext.isClosed()) { try { @@ -125,6 +180,8 @@ protected void initDB(PollenApplicationContext applicationContext) throws TopiaException { + TopiaContext rootContext = applicationContext.getRootContext(); + boolean schemaFound = TopiaUtil.isSchemaExist( rootContext, PollenDAOHelper.PollenEntityEnum.UserAccount.getImplementation().getName() @@ -147,8 +204,7 @@ Locale.getDefault(), transaction, configuration, - serviceFactory, - null + serviceFactory ); UserService service = @@ -165,7 +221,6 @@ } finally { closeTransaction(transaction); } - } /** 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -27,7 +27,6 @@ import com.opensymphony.xwork2.ActionContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsStatics; import org.chorem.pollen.PollenConfiguration; import org.chorem.pollen.services.DefaultPollenServiceContext; @@ -36,7 +35,6 @@ import org.chorem.pollen.services.PollenServiceFactory; import org.chorem.pollen.ui.PollenApplicationContext; import org.chorem.pollen.ui.PollenSession; -import org.chorem.pollen.ui.PollenUIUtils; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.framework.TopiaTransactionAware; import org.nuiton.web.filter.TopiaTransactionFilter; @@ -136,16 +134,7 @@ } public URL getApplicationUrl() { - URL url = getPollenApplicationContext().getApplicationUrl(); - if (url == null) { - - // first time asking this, let's compute it - url = PollenUIUtils.getApplicationBase(ServletActionContext.getRequest()); - if (log.isInfoEnabled()) { - log.info("Pollen application url : " + url); - } - getPollenApplicationContext().setApplicationUrl(url); - } + URL url = getServiceContext().getApplicationURL(); return url; } @@ -161,8 +150,7 @@ getLocale(), getTransaction(), getConfiguration(), - getServiceFactory(), - getApplicationUrl() + getServiceFactory() ); } 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -76,12 +76,10 @@ Preconditions.checkNotNull(user); - UserService service = newService(UserService.class); - String result = INPUT; try { - service.createUser(user, true); - getTransaction().commitTransaction(); + newService(UserService.class).createUser(user, true); + addActionMessage( _("pollen.information.user.created", user.getDisplayName())); 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -75,8 +75,6 @@ // create the comment service.createComment(poll, comment); - getTransaction().commitTransaction(); - // let's use back default comment name commentName = getDefaultCommentName(); return SUCCESS; Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,38 +0,0 @@ -/* - * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Creates a new poll by cloning an existing one. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Clone extends PollenActionSupport { - - private static final long serialVersionUID = 1L; - -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -0,0 +1,38 @@ +/* + * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Creates a new poll by cloning an existing one. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class ClonePoll extends AbstractPollUriIdAction { + + private static final long serialVersionUID = 1L; + +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,37 +0,0 @@ -/* - * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Closes an existing poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Close extends PollenActionSupport { - - private static final long serialVersionUID = 1L; -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -0,0 +1,37 @@ +/* + * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Closes an existing poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class ClosePoll extends AbstractPollUriIdAction { + + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,620 +0,0 @@ -/* - * #%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 com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.opensymphony.xwork2.Preparable; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.interceptor.ParameterAware; -import org.chorem.pollen.bean.PollImageChoice; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.business.persistence.ChoiceImpl; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.I18nAble; -import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; -import org.chorem.pollen.services.impl.PollService; -import org.chorem.pollen.ui.actions.PollenActionSupport; - -import java.io.File; -import java.net.URL; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Creates a new poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Create extends PollenActionSupport implements Preparable, ParameterAware { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(Create.class); - - public static final Pattern TEXT_CHOICE_NAME_PATTERN = - Pattern.compile("textChoice_(\\d+).name"); - - public static final Pattern DATE_CHOICE_NAME_PATTERN = - Pattern.compile("dateChoice_(\\d+).name"); - - public static final Pattern IMAGE_CHOICE_NAME_PATTERN = - Pattern.compile("imageChoice_(\\d+).name"); - - protected Poll poll; - - protected Map<String, String> pollTypes; - - protected Map<String, String> voteCountingTypes; - - protected Map<String, String> choiceTypes; - - protected boolean notification; - - protected boolean reminder; - - protected boolean limitChoice; - - protected int reminderHourCountdown; - - protected int notificationNumber; - - private String textChoiceTokenId; - - private String dateChoiceTokenId; - - private String imageChoiceTokenId; - - private int nbTextChoices; - - private int nbDateChoices; - - private int nbImageChoices; - - /** Uploaded images (for choice type poll). */ - private List<File> imageChoice; - - /** Uploaded images content type (for choice type poll). */ - private List<String> imageChoiceContentType; - - /** Uploaded images name (from use desktop) (for choice type poll). */ - private List<String> imageChoiceFileName; - - /** - * All the parameters send by request used to build back choices of the - * poll. - */ - private Map<String, String[]> parameters; - - @Override - public String getPageLogo() { - return "Creation"; - } - - public Poll getPoll() { - if (poll == null) { - UserAccount userAccount = getPollenSession().getUserAccount(); - poll = newService(PollService.class).getNewPoll(userAccount); - } - return poll; - } - - public int getNbTextChoices() { - return nbTextChoices; - } - - public String getTextChoiceTokenId() { - return textChoiceTokenId; - } - - public int getNbDateChoices() { - return nbDateChoices; - } - - public String getDateChoiceTokenId() { - return dateChoiceTokenId; - } - - public int getNbImageChoices() { - return nbImageChoices; - } - - public String getImageChoiceTokenId() { - return imageChoiceTokenId; - } - - public Map<String, String> getPollTypes() { - return pollTypes; - } - - public Map<String, String> getVoteCountingTypes() { - return voteCountingTypes; - } - - public Map<String, String> getChoiceTypes() { - return choiceTypes; - } - - public boolean isNotification() { - return notification; - } - - public void setNotification(boolean notification) { - this.notification = notification; - } - - public boolean isReminder() { - return reminder; - } - - public void setReminder(boolean reminder) { - this.reminder = reminder; - } - - public boolean isLimitChoice() { - return limitChoice; - } - - public void setLimitChoice(boolean limitChoice) { - this.limitChoice = limitChoice; - } - - public int getReminderHourCountdown() { - return reminderHourCountdown; - } - - public void setReminderHourCountdown(int reminderHourCountdown) { - this.reminderHourCountdown = reminderHourCountdown; - } - - public int getNotificationNumber() { - return notificationNumber; - } - - public void setNotificationNumber(int notificationNumber) { - this.notificationNumber = notificationNumber; - } - - public List<File> getImageChoice() { - if (imageChoice == null) { - imageChoice = Lists.newArrayList(); - } - return imageChoice; - } - - public void setImageChoice(int index, File imageChoice) { - addtoList(getImageChoice(), index, imageChoice); - } - - public List<String> getImageChoiceContentType() { - if (imageChoiceContentType == null) { - imageChoiceContentType = Lists.newArrayList(); - } - return imageChoiceContentType; - } - - public List<String> getImageChoiceFileName() { - if (imageChoiceFileName == null) { - imageChoiceFileName = Lists.newArrayList(); - } - return imageChoiceFileName; - } - - public void setImageChoiceContentType(int index, String imageChoiceContentType) { - addtoList(getImageChoiceContentType(), index, imageChoiceContentType); - } - - public void setImageChoiceFileName(int index, String imageChoiceFileName) { - addtoList(getImageChoiceFileName(), index, imageChoiceFileName); - } - - @Override - public void prepare() throws Exception { - - pollTypes = decorateToName(PollType.values()); - choiceTypes = decorateToName(ChoiceType.values()); - voteCountingTypes = decorateToName(VoteCountingType.values()); - - //TODO tchemit-2012-03-05 use a default value from configuration - nbTextChoices = nbDateChoices = nbImageChoices = 5; - - String tokenSuffix = getServiceContext().createPollenUrlId(); - - textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" + - tokenSuffix; - - dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" + - tokenSuffix; - - imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" + - tokenSuffix; - - ChoiceType pollChoiceType = getPoll().getChoiceType(); - - if (log.isInfoEnabled()) { - log.info("choice type " + pollChoiceType); - } - - Map<Integer, Choice> choices = null; - String tokenId = null; - - switch (pollChoiceType) { - case TEXT: - choices = buildTextChoices(5); - tokenId = textChoiceTokenId; - break; - case DATE: - choices = buildDateChoices(5); - tokenId = dateChoiceTokenId; - break; - case IMAGE: - choices = buildImageChoices(5); - tokenId = imageChoiceTokenId; - break; - } - getPollenSession().putDynamicData(tokenId, choices); - } - - @Override - public void validate() { - - Preconditions.checkNotNull(poll); - - // poll must have a title - if (StringUtils.isEmpty(poll.getTitle())) { - addFieldError("poll.title", _("poll.error.poll.required.title")); - } - - // validate choices - Map<Integer, Choice> orderedChoices = getOrderedChoices(); - - if (MapUtils.isEmpty(orderedChoices)) { - - // poll must have at least one choice - addFieldError("poll.choices", - _("poll.error.poll.required.one.choice")); - } else { - - // check there is no choice with same name - boolean duplicateNameDetected = false; - Set<String> names = Sets.newHashSet(); - for (Choice choice : orderedChoices.values()) { - String choiceName = choice.getName(); - if (!names.add(choiceName)) { - duplicateNameDetected = true; - break; - } - } - if (duplicateNameDetected) { - addFieldError("poll.choices", - _("poll.error.poll.detected.duplicate.choice.name")); - } - } - - // validate security stuff - - } - - @Override - public String execute() throws Exception { - - Map<Integer, Choice> orderedChoices = getOrderedChoices(); - - List<Choice> choices = Lists.newLinkedList(); - - for (Integer index : orderedChoices.keySet()) { - Choice choice = orderedChoices.get(index); - poll.addChoice(choice); - } - - PollService service = newService(PollService.class); - - poll = service.createPoll(poll); - - getTransaction().commitTransaction(); - - // remove all stuff from session - getPollenSession().removeDynamicData(textChoiceTokenId); - getPollenSession().removeDynamicData(dateChoiceTokenId); - getPollenSession().removeDynamicData(imageChoiceTokenId); - - addActionMessage(_("poll.info.poll.created")); - return SUCCESS; - } - - public String getPollVoteUrl() { - URL applicationUrl = getApplicationUrl(); - StringBuilder url = new StringBuilder(applicationUrl.toString()); - - url.append("/poll/votefor/").append(poll.getPollId()); - - if (poll.getPollType() != PollType.FREE) { - url.append(':').append(poll.getCreator().getAccountId()); - } - return url.toString(); - } - - public String getPollEditUrl() { - URL applicationUrl = getApplicationUrl(); - StringBuilder url = new StringBuilder(applicationUrl.toString()); - - url.append("/poll/modification/").append(poll.getPollId()); - url.append(':').append(poll.getCreator().getAccountId()); - return url.toString(); - } - - @Override - public void setParameters(Map<String, String[]> parameters) { - this.parameters = parameters; - } - - private Map<Integer, Choice> getOrderedChoices() { - - Map<Integer, Choice> orderedChoices = null; - switch (poll.getChoiceType()) { - - case TEXT: - orderedChoices = getPollenSession().getDynamicData( - textChoiceTokenId); - - break; - case DATE: - orderedChoices = getPollenSession().getDynamicData( - dateChoiceTokenId); - break; - case IMAGE: - orderedChoices = getPollenSession().getDynamicData( - imageChoiceTokenId); - break; - } - return orderedChoices; - } - - private Map<Integer, Choice> buildTextChoices(int nbDefault) { - Map<Integer, Choice> result = Maps.newTreeMap(); - - int maxNumber = 0; - - for (String paramName : parameters.keySet()) { - - Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName); - if (matcher.matches()) { - - // found a text choice name - - String paramValue = getNonEmptyParameterValue(paramName); - if (paramValue != null) { - - // can keep this none empty text choice name - - Integer choiceNumber = Integer.valueOf(matcher.group(1)); - if (choiceNumber > maxNumber) { - maxNumber = choiceNumber; - } - Choice choice = new ChoiceImpl(); - createChoice(choice, "textChoice_" + choiceNumber, - paramValue); - result.put(choiceNumber, choice); - } - } - } - result = reindexChoices(result, maxNumber); - - int size = result.size(); - nbTextChoices = Math.max(nbDefault, size); - log.info("nbTextChoices (from request) = " + size); - logChoice(result); - return result; - } - - private Map<Integer, Choice> buildDateChoices(int nbDefault) { - Map<Integer, Choice> result = Maps.newTreeMap(); - - int maxNumber = 0; - for (String paramName : parameters.keySet()) { - - Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName); - if (matcher.matches()) { - - // found a text choice name - - String paramValue = getNonEmptyParameterValue(paramName); - if (paramValue != null) { - - // can keep this none empty text choice name - - Integer choiceNumber = Integer.valueOf(matcher.group(1)); - if (choiceNumber > maxNumber) { - maxNumber = choiceNumber; - } - Choice choice = new ChoiceImpl(); - createChoice(choice, - "dateChoice_" + choiceNumber, - paramValue); - result.put(choiceNumber, choice); - } - } - } - result = reindexChoices(result, maxNumber); - - int size = result.size(); - nbDateChoices = Math.max(nbDefault, size); - log.info("nbDateChoices (from request) = " + size); - logChoice(result); - return result; - } - - private Map<Integer, Choice> buildImageChoices(int nbDefault) { - Map<Integer, Choice> result = Maps.newTreeMap(); - - // push back in parameters stuff from uploaded files - int index = 0; - - for (String fileName : getImageChoiceFileName()) { - if (fileName != null) { - parameters.put("imageChoice_" + index + ".name", new String[]{fileName}); - parameters.put("imageChoice_" + index + ".location", new String[]{getImageChoice().get(index).getAbsolutePath()}); - } - index++; - } - - int maxNumber = 0; - for (String paramName : parameters.keySet()) { - - Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName); - if (matcher.matches()) { - - // found a text choice name - - String paramValue = getNonEmptyParameterValue(paramName); - if (paramValue != null) { - - // can keep this none empty text choice name - - Integer choiceNumber = Integer.valueOf(matcher.group(1)); - if (choiceNumber > maxNumber) { - maxNumber = choiceNumber; - } - PollImageChoice choice = new PollImageChoice(); - createImageChoice(choice, - "imageChoice_" + choiceNumber, - paramValue); - - result.put(choiceNumber, choice); - } - } - } - result = reindexChoices(result, maxNumber); - int size = result.size(); - nbImageChoices = Math.max(nbDefault, size); - log.info("nbImageChoices (from request) = " + size); - logChoice(result); - return result; - } - - private void logChoice(Map<Integer, Choice> result) { - for (Map.Entry<Integer, Choice> e : result.entrySet()) { - Integer choiceId = e.getKey(); - Choice choice = e.getValue(); - if (log.isInfoEnabled()) { - log.info("Choice [" + choiceId + "] = " + - choice.getName() + " -- " + - choice.getDescription()); - } - } - } - - private Choice createImageChoice(PollImageChoice choice, - String prefix, String name) { - createChoice(choice, prefix, name); - String locationName = prefix + ".location"; - String location = getNonEmptyParameterValue(locationName); - choice.setLocation(location); - if (log.isInfoEnabled()) { - log.info("image location [" + name + "] =" + location); - } - return choice; - } - - private Choice createChoice(Choice choice, String prefix, String name) { - String descriptionName = prefix + ".description"; - String topiaIdName = prefix + ".topiaId"; - String description = getNonEmptyParameterValue(descriptionName); - String topiaId = getNonEmptyParameterValue(topiaIdName); - choice.setName(name); - choice.setDescription(description); - choice.setTopiaId(topiaId); - return choice; - } - - - private Map<Integer, Choice> reindexChoices(Map<Integer, Choice> result, - int maxNumber) { - Map<Integer, Choice> result2; - - if (maxNumber != result.size() - 1) { - - // means there is a hole inside the result (a empty choice was - // submitted) - - // le'ts remove this - List<Integer> numbers = Lists.newArrayList(result.keySet()); - - Collections.sort(numbers); - - result2 = Maps.newTreeMap(); - int i = 0; - for (Integer number : numbers) { - Choice choice = result.get(number); - result2.put(i++, choice); - } - } else { - result2 = result; - } - return result2; - } - - private <O> void addtoList(List<O> list, int index, O object) { - - while (list.size() < index) { - list.add(null); - } - list.add(index, object); - } - - - private String getNonEmptyParameterValue(String paramName) { - String[] paramValues = parameters.get(paramName); - String result = null; - if (paramValues.length == 1) { - String paramValue = paramValues[0]; - if (StringUtils.isNotEmpty(paramValue)) { - result = paramValue; - } - } - return result; - } - - private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) { - Map<String, String> result = Maps.newLinkedHashMap(); - for (E value : values) { - result.put(value.name(), getText(value.getI18nKey())); - } - return result; - } -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -0,0 +1,638 @@ +/* + * #%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 com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.opensymphony.xwork2.Preparable; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.interceptor.ParameterAware; +import org.chorem.pollen.bean.PollDateChoice; +import org.chorem.pollen.bean.PollImageChoice; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.ChoiceImpl; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PreventRule; +import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.common.I18nAble; +import org.chorem.pollen.common.PollType; +import org.chorem.pollen.common.VoteCountingType; +import org.chorem.pollen.services.impl.PollService; +import org.chorem.pollen.services.impl.PreventRuleService; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +import java.io.File; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Creates a new poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class CreatePoll extends PollenActionSupport implements Preparable, ParameterAware { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(CreatePoll.class); + + public static final Pattern TEXT_CHOICE_NAME_PATTERN = + Pattern.compile("textChoice_(\\d+).name"); + + public static final Pattern DATE_CHOICE_NAME_PATTERN = + Pattern.compile("dateChoice_(\\d+).name"); + + public static final Pattern IMAGE_CHOICE_NAME_PATTERN = + Pattern.compile("imageChoice_(\\d+).name"); + + protected Poll poll; + + protected Map<String, String> pollTypes; + + protected Map<String, String> voteCountingTypes; + + protected Map<String, String> choiceTypes; + + protected boolean notification; + + protected boolean reminder; + + protected boolean limitChoice; + + protected int reminderHourCountdown = 2; + + private String textChoiceTokenId; + + private String dateChoiceTokenId; + + private String imageChoiceTokenId; + + private int nbTextChoices; + + private int nbDateChoices; + + private int nbImageChoices; + + /** Uploaded images (for choice type poll). */ + private List<File> imageChoice; + + /** Uploaded images content type (for choice type poll). */ + private List<String> imageChoiceContentType; + + /** Uploaded images name (from use desktop) (for choice type poll). */ + private List<String> imageChoiceFileName; + + /** + * All the parameters send by request used to build back choices of the + * poll. + */ + private Map<String, String[]> parameters; + + protected transient PollService pollService; + + @Override + public String getPageLogo() { + return "Creation"; + } + + public Poll getPoll() { + return poll; + } + + public int getNbTextChoices() { + return nbTextChoices; + } + + public String getTextChoiceTokenId() { + return textChoiceTokenId; + } + + public int getNbDateChoices() { + return nbDateChoices; + } + + public String getDateChoiceTokenId() { + return dateChoiceTokenId; + } + + public int getNbImageChoices() { + return nbImageChoices; + } + + public String getImageChoiceTokenId() { + return imageChoiceTokenId; + } + + public Map<String, String> getPollTypes() { + return pollTypes; + } + + public Map<String, String> getVoteCountingTypes() { + return voteCountingTypes; + } + + public Map<String, String> getChoiceTypes() { + return choiceTypes; + } + + public boolean isNotification() { + return notification; + } + + public void setNotification(boolean notification) { + this.notification = notification; + } + + public boolean isReminder() { + return reminder; + } + + public void setReminder(boolean reminder) { + this.reminder = reminder; + } + + public boolean isLimitChoice() { + return limitChoice; + } + + public void setLimitChoice(boolean limitChoice) { + this.limitChoice = limitChoice; + } + + public int getReminderHourCountdown() { + return reminderHourCountdown; + } + + public void setReminderHourCountdown(int reminderHourCountdown) { + this.reminderHourCountdown = reminderHourCountdown; + } + + public List<File> getImageChoice() { + if (imageChoice == null) { + imageChoice = Lists.newArrayList(); + } + return imageChoice; + } + + public void setImageChoice(int index, File imageChoice) { + addtoList(getImageChoice(), index, imageChoice); + } + + public List<String> getImageChoiceContentType() { + if (imageChoiceContentType == null) { + imageChoiceContentType = Lists.newArrayList(); + } + return imageChoiceContentType; + } + + public List<String> getImageChoiceFileName() { + if (imageChoiceFileName == null) { + imageChoiceFileName = Lists.newArrayList(); + } + return imageChoiceFileName; + } + + public void setImageChoiceContentType(int index, String imageChoiceContentType) { + addtoList(getImageChoiceContentType(), index, imageChoiceContentType); + } + + public void setImageChoiceFileName(int index, String imageChoiceFileName) { + addtoList(getImageChoiceFileName(), index, imageChoiceFileName); + } + + @Override + public void prepare() throws Exception { + + // create poll + UserAccount userAccount = getPollenSession().getUserAccount(); + poll = getPollService().getNewPoll(userAccount); + + pollTypes = decorateToName(PollType.values()); + choiceTypes = decorateToName(ChoiceType.values()); + voteCountingTypes = decorateToName(VoteCountingType.values()); + + //TODO tchemit-2012-03-05 use a default value from configuration + nbTextChoices = nbDateChoices = nbImageChoices = 5; + + String tokenSuffix = getServiceContext().createPollenUrlId(); + + textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" + + tokenSuffix; + + dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" + + tokenSuffix; + + imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" + + tokenSuffix; + + ChoiceType pollChoiceType = getPoll().getChoiceType(); + + if (log.isInfoEnabled()) { + log.info("choice type " + pollChoiceType); + } + + Map<Integer, Choice> choices = null; + String tokenId = null; + + switch (pollChoiceType) { + case TEXT: + choices = buildTextChoices(5); + tokenId = textChoiceTokenId; + break; + case DATE: + choices = buildDateChoices(5); + tokenId = dateChoiceTokenId; + break; + case IMAGE: + choices = buildImageChoices(5); + tokenId = imageChoiceTokenId; + break; + } + getPollenSession().putDynamicData(tokenId, choices); + } + + @Override + public void validate() { + + Preconditions.checkNotNull(poll); + + // poll must have a title + if (StringUtils.isEmpty(poll.getTitle())) { + addFieldError("poll.title", _("poll.error.poll.required.title")); + } + + // validate choices + Map<Integer, Choice> orderedChoices = getOrderedChoices(); + + if (MapUtils.isEmpty(orderedChoices)) { + + // poll must have at least one choice + addFieldError("poll.choices", + _("poll.error.poll.required.one.choice")); + } else { + + //TODO tchemit improve this (from different cases text-date-image) + // check there is no choice with same name + boolean duplicateNameDetected = false; + Set<String> names = Sets.newHashSet(); + for (Choice choice : orderedChoices.values()) { + String choiceName = choice.getName(); + if (!names.add(choiceName)) { + duplicateNameDetected = true; + break; + } + } + if (duplicateNameDetected) { + addFieldError("poll.choices", + _("poll.error.poll.detected.duplicate.choice.name")); + } + } + + // validate security stuff + + } + + @Override + public String execute() throws Exception { + + Map<Integer, Choice> orderedChoices = getOrderedChoices(); + + for (Integer index : orderedChoices.keySet()) { + Choice choice = orderedChoices.get(index); + poll.addChoice(choice); + } + + PollService service = getPollService(); + + PreventRuleService preventRuleService = + newService(PreventRuleService.class); + if (isNotification()) { + + // add a notification rule + + PreventRule rule = preventRuleService.createAddVotePreventRule(); + poll.addPreventRule(rule); + } + + if (isReminder()) { + + // add a reminder rule + + PreventRule rule = preventRuleService.createRemindPreventRule( + getReminderHourCountdown() + ); + + poll.addPreventRule(rule); + } + + poll = service.createPoll(poll); + + // remove all stuff from session + getPollenSession().removeDynamicData(textChoiceTokenId); + getPollenSession().removeDynamicData(dateChoiceTokenId); + getPollenSession().removeDynamicData(imageChoiceTokenId); + + addActionMessage(_("poll.info.poll.created")); + return SUCCESS; + } + + public String getPollVoteUrl() { + return getPollService().getPollVoteUrl(poll); + } + + public String getPollEditUrl() { + return getPollService().getPollEditUrl(poll); + } + + @Override + public void setParameters(Map<String, String[]> parameters) { + this.parameters = parameters; + } + + protected PollService getPollService() { + if (pollService == null) { + pollService = newService(PollService.class); + } + return pollService; + } + + protected Map<Integer, Choice> getOrderedChoices() { + + Map<Integer, Choice> orderedChoices = null; + switch (poll.getChoiceType()) { + + case TEXT: + orderedChoices = getPollenSession().getDynamicData( + textChoiceTokenId); + + break; + case DATE: + orderedChoices = getPollenSession().getDynamicData( + dateChoiceTokenId); + break; + case IMAGE: + orderedChoices = getPollenSession().getDynamicData( + imageChoiceTokenId); + break; + } + return orderedChoices; + } + + protected Map<Integer, Choice> buildTextChoices(int nbDefault) { + Map<Integer, Choice> result = Maps.newTreeMap(); + + int maxNumber = 0; + + for (String paramName : parameters.keySet()) { + + Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName); + if (matcher.matches()) { + + // found a text choice name + + String paramValue = getNonEmptyParameterValue(paramName); + if (paramValue != null) { + + // can keep this none empty text choice name + + Integer choiceNumber = Integer.valueOf(matcher.group(1)); + if (choiceNumber > maxNumber) { + maxNumber = choiceNumber; + } + Choice choice = new ChoiceImpl(); + createChoice(choice, "textChoice_" + choiceNumber, + paramValue); + result.put(choiceNumber, choice); + } + } + } + result = reindexChoices(result, maxNumber); + + int size = result.size(); + nbTextChoices = Math.max(nbDefault, size); + log.info("nbTextChoices (from request) = " + size); + logChoice(result); + return result; + } + + protected Map<Integer, Choice> buildDateChoices(int nbDefault) { + Map<Integer, Choice> result = Maps.newTreeMap(); + + int maxNumber = 0; + for (String paramName : parameters.keySet()) { + + Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName); + if (matcher.matches()) { + + // found a text choice name + + String paramValue = getNonEmptyParameterValue(paramName); + if (paramValue != null) { + + // can keep this none empty text choice name + + Integer choiceNumber = Integer.valueOf(matcher.group(1)); + if (choiceNumber > maxNumber) { + maxNumber = choiceNumber; + } + PollDateChoice choice = new PollDateChoice(); + createDateChoice(choice, + "dateChoice_" + choiceNumber, + paramValue); + result.put(choiceNumber, choice); + } + } + } + result = reindexChoices(result, maxNumber); + + int size = result.size(); + nbDateChoices = Math.max(nbDefault, size); + log.info("nbDateChoices (from request) = " + size); + logChoice(result); + return result; + } + + protected Map<Integer, Choice> buildImageChoices(int nbDefault) { + Map<Integer, Choice> result = Maps.newTreeMap(); + + // push back in parameters stuff from uploaded files + int index = 0; + + for (String fileName : getImageChoiceFileName()) { + if (fileName != null) { + parameters.put("imageChoice_" + index + ".name", new String[]{fileName}); + parameters.put("imageChoice_" + index + ".location", new String[]{getImageChoice().get(index).getAbsolutePath()}); + } + index++; + } + + int maxNumber = 0; + for (String paramName : parameters.keySet()) { + + Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName); + if (matcher.matches()) { + + // found a text choice name + + String paramValue = getNonEmptyParameterValue(paramName); + if (paramValue != null) { + + // can keep this none empty text choice name + + Integer choiceNumber = Integer.valueOf(matcher.group(1)); + if (choiceNumber > maxNumber) { + maxNumber = choiceNumber; + } + PollImageChoice choice = new PollImageChoice(); + createImageChoice(choice, + "imageChoice_" + choiceNumber, + paramValue); + + result.put(choiceNumber, choice); + } + } + } + result = reindexChoices(result, maxNumber); + int size = result.size(); + nbImageChoices = Math.max(nbDefault, size); + log.info("nbImageChoices (from request) = " + size); + logChoice(result); + return result; + } + + private void logChoice(Map<Integer, Choice> result) { + for (Map.Entry<Integer, Choice> e : result.entrySet()) { + Integer choiceId = e.getKey(); + Choice choice = e.getValue(); + if (log.isInfoEnabled()) { + log.info("Choice [" + choiceId + "] = " + + choice.getName() + " -- " + + choice.getDescription()); + } + } + } + + private Choice createImageChoice(PollImageChoice choice, + String prefix, + String name) { + createChoice(choice, prefix, name); + String locationName = prefix + ".location"; + String location = getNonEmptyParameterValue(locationName); + choice.setLocation(location); + if (log.isInfoEnabled()) { + log.info("image location [" + name + "] =" + location); + } + return choice; + } + + private Choice createDateChoice(PollDateChoice choice, + String prefix, + String name) { + createChoice(choice, prefix, name); + if (StringUtils.isNotEmpty(name)) { + choice.setDate(new Date(Long.valueOf(name))); + } + return choice; + } + + private Choice createChoice(Choice choice, String prefix, String name) { + String descriptionName = prefix + ".description"; + String topiaIdName = prefix + ".topiaId"; + String description = getNonEmptyParameterValue(descriptionName); + String topiaId = getNonEmptyParameterValue(topiaIdName); + choice.setName(name); + choice.setDescription(description); + choice.setTopiaId(topiaId); + return choice; + } + + + private Map<Integer, Choice> reindexChoices(Map<Integer, Choice> result, + int maxNumber) { + Map<Integer, Choice> result2; + + if (maxNumber != result.size() - 1) { + + // means there is a hole inside the result (a empty choice was + // submitted) + + // le'ts remove this + List<Integer> numbers = Lists.newArrayList(result.keySet()); + + Collections.sort(numbers); + + result2 = Maps.newTreeMap(); + int i = 0; + for (Integer number : numbers) { + Choice choice = result.get(number); + result2.put(i++, choice); + } + } else { + result2 = result; + } + return result2; + } + + private <O> void addtoList(List<O> list, int index, O object) { + + while (list.size() < index) { + list.add(null); + } + list.add(index, object); + } + + + private String getNonEmptyParameterValue(String paramName) { + String[] paramValues = parameters.get(paramName); + String result = null; + if (paramValues.length == 1) { + String paramValue = paramValues[0]; + if (StringUtils.isNotEmpty(paramValue)) { + result = paramValue; + } + } + return result; + } + + private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) { + Map<String, String> result = Maps.newLinkedHashMap(); + for (E value : values) { + result.put(value.name(), getText(value.getI18nKey())); + } + return result; + } +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,37 +0,0 @@ -/* - * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Deletes an existing poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Delete extends PollenActionSupport { - - private static final long serialVersionUID = 1L; -} Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -51,7 +51,6 @@ PollService service = newService(PollService.class); service.deleteChoice(pollId, choiceId); - getTransaction().commitTransaction(); return SUCCESS; } 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -64,8 +64,6 @@ service.deleteComment(commentId); - getTransaction().commitTransaction(); - commentName = getDefaultCommentName(); return SUCCESS; Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -0,0 +1,37 @@ +/* + * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Deletes an existing poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class DeletePoll extends AbstractPollUriIdAction { + + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.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/DeleteVote.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -51,7 +51,6 @@ PollService service = newService(PollService.class); service.deleteVote(pollId, voteId); - getTransaction().commitTransaction(); return SUCCESS; } Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -23,8 +23,7 @@ */ package org.chorem.pollen.ui.actions.poll; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.business.persistence.ChoiceImpl; +import org.chorem.pollen.bean.PollDateChoice; /** * To generate the display for a date choice. @@ -39,10 +38,11 @@ public static final String CHOICE_TOKEN = "dateChoice"; @Override - protected Choice createEmptyChoice() { - Choice result = new ChoiceImpl(); + protected PollDateChoice createEmptyChoice() { + PollDateChoice result = new PollDateChoice(); result.setName(""); result.setDescription(""); + result.setDate(null); return result; } } Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,37 +0,0 @@ -/* - * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Display a poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Edit extends PollenActionSupport { - - private static final long serialVersionUID = 1L; -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -0,0 +1,37 @@ +/* + * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Display a poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class EditPoll extends AbstractPollUriIdAction { + + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,37 +0,0 @@ -/* - * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Exports an existing poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Export extends PollenActionSupport { - - private static final long serialVersionUID = 1L; -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -0,0 +1,37 @@ +/* + * #%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 org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Exports an existing poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class ExportPoll extends AbstractPollUriIdAction { + + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: 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 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -1,88 +0,0 @@ -/* - * #%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@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 inputStream; - - public void setPollId(String pollId) { - this.pollId = pollId; - } - - public long getContentLength() { - return contentLength; - } - - public InputStream getInputStream() { - return inputStream; - } - - @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(); - - inputStream = new FileInputStream(feedLocation); - - return SUCCESS; - } -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java (from rev 3163, 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/GetPollFeed.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -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@codelutin.com> + * @since 1.2.6 + */ +public class GetPollFeed extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + protected String pollId; + + protected long contentLength; + + protected transient InputStream inputStream; + + public void setPollId(String pollId) { + this.pollId = pollId; + } + + public long getContentLength() { + return contentLength; + } + + public InputStream getInputStream() { + return inputStream; + } + + @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(); + + inputStream = 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/GetPollFeed.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/ResultForPoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -198,10 +198,6 @@ return topRanking; } -// public List<PollResult> getRanking() { -// return ranking; -// } - public boolean isFreePoll() { return poll.getPollType() == PollType.FREE; } 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-03-07 16:56:43 UTC (rev 3167) @@ -66,12 +66,10 @@ @Override public String execute() throws Exception { - UserService service = newService(UserService.class); - String result = INPUT; try { - UserAccount createdUser = service.createUser(user, false); - getTransaction().commitTransaction(); + UserAccount createdUser = + newService(UserService.class).createUser(user, false); getPollenSession().setUserAccount(createdUser); addActionMessage(_("pollen.information.your.are.loggued")); 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-07 16:56:43 UTC (rev 3167) @@ -42,7 +42,7 @@ <!-- create poll --> <action name="create" - class="org.chorem.pollen.ui.actions.poll.Create"> + class="org.chorem.pollen.ui.actions.poll.CreatePoll"> <result name="input">/WEB-INF/jsp/poll/create.jsp</result> <result>/WEB-INF/jsp/poll/resume.jsp</result> </action> @@ -67,7 +67,7 @@ <!-- edit poll --> <action name="modification/*" - class="org.chorem.pollen.ui.actions.poll.Edit"> + class="org.chorem.pollen.ui.actions.poll.EditPoll"> <param name="uriId">{1}</param> <result name="input">/WEB-INF/jsp/poll/edit.jsp</result> <result>/WEB-INF/jsp/poll/resume.jsp</result> @@ -90,7 +90,7 @@ <!-- clone poll --> <action name="clone/*" - class="org.chorem.pollen.ui.actions.poll.Clone"> + class="org.chorem.pollen.ui.actions.poll.ClonePoll"> <param name="uriId">{1}</param> <result name="input">/WEB-INF/jsp/poll/clone.jsp</result> <result>/WEB-INF/jsp/home.jsp</result> @@ -98,7 +98,7 @@ <!-- export poll --> <action name="export/*" - class="org.chorem.pollen.ui.actions.poll.Export"> + class="org.chorem.pollen.ui.actions.poll.ExportPoll"> <param name="uriId">{1}</param> <result name="input">/WEB-INF/jsp/poll/export.jsp</result> <result>/WEB-INF/jsp/home.jsp</result> @@ -106,7 +106,7 @@ <!-- close poll --> <action name="close/*" - class="org.chorem.pollen.ui.actions.poll.Close"> + class="org.chorem.pollen.ui.actions.poll.ClosePoll"> <param name="uriId">{1}</param> <result name="input">/WEB-INF/jsp/poll/close.jsp</result> <result>/WEB-INF/jsp/home.jsp</result> @@ -114,7 +114,7 @@ <!-- delete poll --> <action name="delete/*" - class="org.chorem.pollen.ui.actions.poll.Delete"> + class="org.chorem.pollen.ui.actions.poll.DeletePoll"> <param name="uriId">{1}</param> <result name="input">/WEB-INF/jsp/poll/delete.jsp</result> <result>/WEB-INF/jsp/home.jsp</result> @@ -163,7 +163,7 @@ </action> <!-- get the feed of a given poll --> - <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetFeed"> + <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetPollFeed"> <result type="stream"> <param name="contentCharSet">UTF-8</param> <param name="contentType">application/atom+xml</param> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-07 16:56:43 UTC (rev 3167) @@ -59,15 +59,6 @@ } }); - $('[name="notification"]').change(function (event) { - var val = $(this).prop('checked'); - if (val) { - $('#notificationPanel').show(); - } else { - $('#notificationPanel').hide(); - } - }); - $('[name="poll.anonymous"]').change(function (event) { var val = $(this).prop('checked'); $('[name="poll.anonymousVoteAllowed"]').prop('checked', val); @@ -207,10 +198,6 @@ </div> <s:checkbox key="notification" label="%{getText('pollen.common.pollOption.notification')}"/> - <div id='notificationPanel' class="hidden"> - <s:textfield key="notificationNumber" - label="%{getText('pollen.common.pollOption.notificationNumber')}"/> - </div> <s:checkbox key="reminder" label="%{getText('pollen.common.pollOption.reminder')}"/> <div id='reminderPanel' class="hidden"> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp 2012-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp 2012-03-07 16:56:43 UTC (rev 3167) @@ -36,7 +36,7 @@ theme="simple" value=''/> <sj:datepicker id='%{#prefix}.name' key="%{#prefix}.name" changeMonth="true" changeYear="true" labelSeparator="" theme="simple" label="" - timepicker="true" value="%{choice.name}"/> + timepicker="true" value="%{choice.date}"/> - <s:label for="%{#prefix}.description" key="pollen.common.description" theme="simple"/> 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-03-07 16:44:51 UTC (rev 3166) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-07 16:56:43 UTC (rev 3167) @@ -483,7 +483,7 @@ <div id="commentFormDiv"> <s:form id='addCommentForm' method="POST" namespace="/poll"> - <s:hidden key="pollId" label=''/> + <s:hidden key="uriId" label=''/> <s:textfield key="commentName" required="true" size="78" label="%{getText('pollen.common.commentName')}"/> <s:textarea key="commentText" required="true" value=''