r3611 - in trunk/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui java/org/chorem/pollen/ui/actions java/org/chorem/pollen/ui/actions/admin java/org/chorem/pollen/ui/actions/io java/org/chorem/pollen/ui/actions/json java/org/chorem/pollen/ui/actions/poll java/org/chorem/pollen/ui/actions/poll/admin java/org/chorem/pollen/ui/actions/poll/form java/org/chorem/pollen/ui/actions/poll/vote java/org/chorem/pollen/ui/actions/user java/org/chorem/pollen/ui/converters java/org/chorem/pollen/ui/
Author: tchemit Date: 2012-08-13 16:11:15 +0200 (Mon, 13 Aug 2012) New Revision: 3611 Url: http://chorem.org/repositories/revision/pollen/3611 Log: refs #746: Improve security model + stop using inheritance in action just to obtain a PollUri (security model offers this) + replace uriId by pollUri + relocate actions where they belong + add packages javadoc Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollUriAware.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenUserSecurityAware.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ClosePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ConfirmPollAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/DeletePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/SummaryPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractDisplayChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayDateChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayImageChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayPersonToList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayTextChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ImportPersonListToVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/SelectPersonListToVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ModeratePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/converters/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenSecurityInterceptor.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/results/package-info.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/package-info.java Removed: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractDisplayChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayImageChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayTextChoice.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForEdition.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForVote.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/CreateFavoriteListVoter.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/EditFavoriteListVoter.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java trunk/pollen-ui-struts2/src/main/resources/config/struts-poll.xml trunk/pollen-ui-struts2/src/main/resources/config/struts-user.xml trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties trunk/pollen-ui-struts2/src/main/resources/shiro.ini trunk/pollen-ui-struts2/src/main/resources/struts.xml trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClosePoll.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePoll.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/edit.jsp Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -44,8 +44,6 @@ private static final String POLLEN_USER_SECURITY_CONTEXT = "pollenUserSecurityContext"; -// private static final String ACCOUNT_ID_ROLE = "accountIdRole"; - public static ServletContext getServletContext() { return servletContext; } @@ -59,18 +57,12 @@ request.setAttribute(POLLEN_USER_SECURITY_CONTEXT, userRoles); } - public static PollenUserSecurityContext getUserSecuritycontext(ServletRequest request) { + public static PollenUserSecurityContext getUserSecurityContext(ServletRequest request) { PollenUserSecurityContext result = (PollenUserSecurityContext) request.getAttribute(POLLEN_USER_SECURITY_CONTEXT); return result; } -// public static SecurityService.PollenUserSecurityRole getAccountIdRole(ServletRequest request) { -// SecurityService.PollenUserSecurityRole result = (SecurityService.PollenUserSecurityRole) -// request.getAttribute(ACCOUNT_ID_ROLE); -// return result; -// } - public static String getVoteSizeMessage(Poll poll, Locale locale) { int i = poll.sizeVote(); Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollUriAware.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollUriAware.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollUriAware.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,18 @@ +package org.chorem.pollen.ui.actions; + +import org.chorem.pollen.bean.PollUri; + +/** + * For any action that contains a {@link PollUri} context. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.5 + */ +public interface PollUriAware { + + PollUri getPollUri(); + +// String getPollId(); +// +// String getAccountId(); +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollUriAware.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -22,11 +22,14 @@ */ package org.chorem.pollen.ui.actions; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.inject.Inject; import org.apache.commons.collections.CollectionUtils; -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.StrutsStatics; +import org.apache.struts2.interceptor.ParameterAware; +import org.apache.struts2.interceptor.ServletRequestAware; import org.chorem.pollen.PollenApplicationContext; import org.chorem.pollen.PollenConfiguration; import org.chorem.pollen.PollenUserSecurityContext; @@ -34,9 +37,9 @@ import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.services.DefaultPollenServiceContext; -import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.PollenServiceFactory; +import org.chorem.pollen.services.PollenServiceSupport; import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.services.impl.PollCommentService; import org.chorem.pollen.services.impl.PollFeedService; @@ -48,18 +51,21 @@ import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.services.impl.VoteService; import org.chorem.pollen.ui.PollenSession; +import org.chorem.pollen.ui.interceptors.PollenSecurityInterceptor; +import org.chorem.pollen.ui.security.AbstractPollenAuthorization; import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.framework.TopiaTransactionAware; import org.nuiton.web.filter.TopiaTransactionFilter; import org.nuiton.web.struts2.BaseAction; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import java.net.URL; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Map; /** * Pollen action support. @@ -72,13 +78,13 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class PollenActionSupport extends BaseAction implements TopiaTransactionAware { +public class PollenActionSupport extends BaseAction implements ServletRequestAware { private static final long serialVersionUID = 1L; public static PollenApplicationContext getPollenApplicationContext() { PollenApplicationContext applicationContext = - PollenApplicationContext.get(getActionContext()); + PollenApplicationContext.get(ActionContext.getContext()); return applicationContext; } @@ -86,41 +92,57 @@ return getPollenApplicationContext().getConfiguration(); } - /** Pollen User getPollenSession(). */ + /** Pollen User session. */ private transient PollenSession pollenSession; /** * Provides a way to get a service. * <p/> * Actions may <strong>not</strong> call it directly by use - * {@link #newService(Class)} instead. + * {@link #getService(Class)} instead. */ + @Inject protected transient PollenServiceFactory serviceFactory; protected transient PollenServiceContext serviceContext; protected transient TopiaContext transaction; - private transient PollService pollService; + private transient Map<Class<? extends PollenServiceSupport>, PollenServiceSupport> services; - private transient PollUrlService pollUrlService; + /** + * The incoming request (some stuff are store in it from security filters). + * + * @since 1.4.5 + */ + private transient HttpServletRequest request; - private transient PollResultsService pollResultsService; + /** + * All the parameters send by request used to build back choices of the + * poll. + * <p/> + * This will be setted by the {@link ParameterAware#setParameters(Map)} as soon + * as your action implements {@link ParameterAware}. + * + * @since 1.4.5 + */ + private Map<String, String[]> parameters; - private transient VoteService voteService; + /** + * The user security context for this request. + * <p/> + * This security contains the {@code poll}, {@code userAccount} and {@code userRoles}. + * <p/> + * It will be injected by the {@link PollenSecurityInterceptor} for all + * action which implements {@link PollenUserSecurityAware}. + * <p/> + * <strong>Import Note:</strong> Security context is load by shiro filter + * via method {@link AbstractPollenAuthorization#createSecurityContext(ServletRequest)}. + * + * @since 1.4.5 + */ + private PollenUserSecurityContext securityContext; - private transient PollCommentService pollCommentService; - - private transient PollFeedService pollFeedService; - - private transient UserService userService; - - private transient FavoriteService favoriteService; - - private transient PreventRuleService preventRuleService; - - private transient SecurityService securityService; - private final PageSkin skin; public PollenActionSupport() { @@ -146,7 +168,7 @@ public PollenSession getPollenSession() { if (pollenSession == null) { - pollenSession = PollenSession.get(getActionContext()); + pollenSession = PollenSession.get(ActionContext.getContext()); } return pollenSession; } @@ -175,69 +197,81 @@ } /** - * Fabrique pour récupérer le ServiceContext tel qu'il devrait être fourni - * à la fabrication d'un service. + * Keep in this action the incoming request. * - * @return service context + * @param request the http request to set (can not be null) + * @see ServletRequestAware + * @since 1.4.5 */ - protected PollenServiceContext getServiceContext() { - if (serviceContext == null) { - serviceContext = DefaultPollenServiceContext.newContext( - getLocale(), - getTransaction(), - getConfiguration(), - getServiceFactory(), - getVoteCountingStrategyProvider() - ); - } - return serviceContext; + @Override + public final void setServletRequest(HttpServletRequest request) { + Preconditions.checkNotNull(request); + this.request = request; } - public PollenServiceFactory getServiceFactory() { - if (serviceFactory == null) { - serviceFactory = new PollenServiceFactory(); - } - return serviceFactory; + /** + * Keep in this action the incoming request parameters. + * <p/> + * <strong>Note:</strong> This method will be invoked only if your action + * implements the {@link ParameterAware} contract. + * + * @param parameters paramters of the request (can not be null) + * @see ParameterAware + * @since 1.4.5 + */ + public final void setParameters(Map<String, String[]> parameters) { + Preconditions.checkNotNull(parameters); + this.parameters = Maps.newHashMap(parameters); } - public VoteCountingStrategyProvider getVoteCountingStrategyProvider() { - return getPollenApplicationContext().getVoteCountingStrategyProvider(); + /** + * Keep in this action the incoming security context. + * <p/> + * <strong>Note:</strong> This method will be invoked only if your action + * implements the {@link PollenUserSecurityAware} contract. + * + * @param pollenUserSecurityContext pollen security context to set (can not be null) + * @see PollenUserSecurityAware + * @since 1.4.5 + */ + public final void setPollenUserSecurityContext(PollenUserSecurityContext pollenUserSecurityContext) { + Preconditions.checkNotNull(pollenUserSecurityContext); + this.securityContext = pollenUserSecurityContext; } - protected VoteCountingStrategy getVoteCountingStrategy(Poll poll) { - int voteCountingType = poll.getVoteCountingType(); - VoteCountingStrategy result = - getVoteCountingStrategyProvider().getStrategy(voteCountingType); - return result; - } - /** - * Sub-classes should use this method to easily get a service instance. + * Gets the {@link PollUri} from the incoming request. + * <p/> + * If the action is {@link PollenUserSecurityAware}, then will take it + * from {@link PollenUserSecurityContext#getPollUri()}, otherwise will + * return {@code null} (this means you must override this method in your action. * - * @param serviceClass The type of service to instantiate - * @return A newly created service of the expected type with necessary data set + * @return the pollUri register in this action or null. + * @since 1.4.5 */ - public <E extends PollenService> E newService(Class<E> serviceClass) { - E service = getServiceFactory().newService(serviceClass, - getServiceContext()); - return service; + public PollUri getPollUri() { + PollUri result; + if (this instanceof PollenUserSecurityAware) { + // use the security context to ge the pollUri + result = getUserSecurityContext().getPollUri(); + } else { + // No information from here, must be override in your action + result = null; + } + return result; } - @Override + public VoteCountingStrategyProvider getVoteCountingStrategyProvider() { + return getPollenApplicationContext().getVoteCountingStrategyProvider(); + } + public TopiaContext getTransaction() { if (transaction == null) { - HttpServletRequest request = (HttpServletRequest) - getActionContext().get(StrutsStatics.HTTP_REQUEST); transaction = TopiaTransactionFilter.getTransaction(request); } return transaction; } - @Override - public void setTransaction(TopiaContext transaction) { - this.transaction = transaction; - } - public static final List<String> SAFE_LANGUAGES = Lists.newArrayList("en", "fr"); @@ -249,16 +283,11 @@ return language; } - protected static ActionContext getActionContext() { - return ActionContext.getContext(); - } - public static Date getCurrentDateTime() { return new Date(); } public String getCurrentUrl() { - HttpServletRequest request = ServletActionContext.getRequest(); String result = request.getRequestURL().toString(); return result; } @@ -276,45 +305,44 @@ } public Collection<String> getFlashMessages() { - - List<String> result = getPollenSession().consumeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); + List<String> result = getPollenSession().consumeDynamicListData(PollenSession.SESSION_TOKEN_MESSAGES); return result; } public Collection<String> getFlashErrors() { - List<String> result = getPollenSession().consumeDynamicData(PollenSession.SESSION_TOKEN_ERRORS); + List<String> result = getPollenSession().consumeDynamicListData(PollenSession.SESSION_TOKEN_ERRORS); return result; } public Collection<String> getFlashWarnings() { - List<String> result = getPollenSession().consumeDynamicData(PollenSession.SESSION_TOKEN_WARNINGS); + List<String> result = getPollenSession().consumeDynamicListData(PollenSession.SESSION_TOKEN_WARNINGS); return result; } public boolean hasFlashMessages() { - List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); + List<String> result = getPollenSession().getDynamicListData(PollenSession.SESSION_TOKEN_MESSAGES); return CollectionUtils.isNotEmpty(result); } public boolean hasFlashErrors() { - List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS); + List<String> result = getPollenSession().getDynamicListData(PollenSession.SESSION_TOKEN_ERRORS); return CollectionUtils.isNotEmpty(result); } public boolean hasFlashWarnings() { - List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_WARNINGS); + List<String> result = getPollenSession().getDynamicListData(PollenSession.SESSION_TOKEN_WARNINGS); return CollectionUtils.isNotEmpty(result); } public void clearFlashMessages() { - List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); + List<String> result = getPollenSession().getDynamicListData(PollenSession.SESSION_TOKEN_MESSAGES); if (result != null) { result.clear(); } } public void clearFlashErrors() { - List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS); + List<String> result = getPollenSession().getDynamicListData(PollenSession.SESSION_TOKEN_ERRORS); if (result != null) { result.clear(); } @@ -326,89 +354,133 @@ } protected final PollService getPollService() { - if (pollService == null) { - pollService = newService(PollService.class); - } - return pollService; + return getService(PollService.class); } protected final PollUrlService getPollUrlService() { - if (pollUrlService == null) { - pollUrlService = newService(PollUrlService.class); - } - return pollUrlService; + return getService(PollUrlService.class); } protected final PollResultsService getPollResultsService() { - if (pollResultsService == null) { - pollResultsService = newService(PollResultsService.class); - } - return pollResultsService; + return getService(PollResultsService.class); } protected final VoteService getVoteService() { - if (voteService == null) { - voteService = newService(VoteService.class); - } - return voteService; + return getService(VoteService.class); } protected final PollCommentService getPollCommentService() { - if (pollCommentService == null) { - pollCommentService = newService(PollCommentService.class); - } - return pollCommentService; + return getService(PollCommentService.class); } protected final PollFeedService getPollFeedService() { - if (pollFeedService == null) { - pollFeedService = newService(PollFeedService.class); - } - return pollFeedService; + return getService(PollFeedService.class); } protected final UserService getUserService() { - if (userService == null) { - userService = newService(UserService.class); - } - return userService; + return getService(UserService.class); } protected final FavoriteService getFavoriteService() { - if (favoriteService == null) { - favoriteService = newService(FavoriteService.class); - } - return favoriteService; + return getService(FavoriteService.class); } protected final PreventRuleService getPreventRuleService() { - if (preventRuleService == null) { - preventRuleService = newService(PreventRuleService.class); - } - return preventRuleService; + return getService(PreventRuleService.class); } - public SecurityService getSecurityService() { - if (securityService == null) { - securityService = newService(SecurityService.class); + protected final SecurityService getSecurityService() { + return getService(SecurityService.class); + } + + /** + * Get a instance of a service for the given {@code serviceType}. + * + * @param serviceType type of the required service + * @param <S> type of the required service + * @return instance of the service + * @since 1.4.5 + */ + protected final <S extends PollenServiceSupport> S getService(Class<S> serviceType) { + if (services == null) { + services = Maps.newHashMap(); } - return securityService; + PollenServiceSupport result = services.get(serviceType); + if (result == null) { + result = serviceFactory.newService(serviceType, getServiceContext()); + services.put(serviceType, result); + } + return (S) result; } - protected PollenUserSecurityContext newSecurityContext(String pollId, - String accountId, - Poll poll) { - return newSecurityContext(PollUri.newPollUri(pollId, accountId), poll); + /** + * Tests if the incoming http request is a get method. + * <p/> + * <strong>Note:</strong> {@link #request} must not be null. + * + * @return {@code true} if incoming request uses {@code GET} method. + * @since 1.4.5 + */ + protected boolean isGetMethod() { + Preconditions.checkNotNull(request); + return "GET".equalsIgnoreCase(request.getMethod()); } - protected PollenUserSecurityContext newSecurityContext(PollUri pollUri, - Poll poll) { - PollenUserSecurityContext securityConext = PollenUserSecurityContext.newContext( - getPollenUserAccount(), pollUri - ); - if (poll != null) { - securityConext.setPoll(poll); + /** + * Obtain the injected security context. + * <p/> + * <strong>Note:</strong> {@link #securityContext} must not be null + * (concrete action should implements {@link PollenUserSecurityAware}). + * + * @return the injected security context + * @see PollenUserSecurityContext + * @see PollenUserSecurityAware + * @since 1.4.5 + */ + protected final PollenUserSecurityContext getUserSecurityContext() { + Preconditions.checkNotNull(securityContext, "To use the pollenUserSecurityContext, make your action implements PollenUserSecurityAware."); + return securityContext; + } + + /** + * Obtain the injected request parameters. + * <p/> + * <strong>Note:</strong> {@link #parameters} must not be null + * (concrete action should implements {@link ParameterAware}). + * + * @return the injected request parameters + * @see ParameterAware + * @since 1.4.5 + */ + protected final Map<String, String[]> getParameters() { + Preconditions.checkNotNull(parameters); + return parameters; + } + + protected VoteCountingStrategy getVoteCountingStrategy(Poll poll) { + int voteCountingType = poll.getVoteCountingType(); + VoteCountingStrategy result = + getVoteCountingStrategyProvider().getStrategy(voteCountingType); + return result; + } + + /** + * Fabrique pour récupérer le ServiceContext tel qu'il devrait être fourni + * à la fabrication d'un service. + * + * @return service context + */ + protected PollenServiceContext getServiceContext() { + if (serviceContext == null) { + serviceContext = DefaultPollenServiceContext.newContext( + getLocale(), + getTransaction(), + getConfiguration(), + serviceFactory, + getVoteCountingStrategyProvider() + ); } - return securityConext; + return serviceContext; } + } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForEdition.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForEdition.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForEdition.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -23,9 +23,10 @@ */ /** - * Abase support action with predefine edition skin. + * Base action support with predefined edition skin. * * @author tchemit <chemit@codelutin.com> + * @see PageSkin#EDITION * @since 1.4.5 */ public class PollenActionSupportForEdition extends PollenActionSupport { Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForVote.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForVote.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupportForVote.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -23,9 +23,10 @@ */ /** - * Abase support action with predefine vote skin. + * Base action support with predefined vote skin. * * @author tchemit <chemit@codelutin.com> + * @see PageSkin#VOTE * @since 1.4.5 */ public class PollenActionSupportForVote extends PollenActionSupport { Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenUserSecurityAware.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenUserSecurityAware.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenUserSecurityAware.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,14 @@ +package org.chorem.pollen.ui.actions; + +import org.chorem.pollen.PollenUserSecurityContext; + +/** + * Contract of action which use {@link PollenUserSecurityContext}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.5 + */ +public interface PollenUserSecurityAware { + + void setPollenUserSecurityContext(PollenUserSecurityContext pollenUserSecurityContext); +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenUserSecurityAware.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -154,32 +154,10 @@ addFieldError("editUser.password", _("pollen.error.user.invalid.password")); } - return result; } -// public String delete() throws Exception { -// -// Preconditions.checkNotNull(user); -// -// UserService service = newService(UserService.class); -// -// String result = INPUT; -// -// try { -// service.deleteUser(user.getTopiaId()); -// getTransaction().commitTransaction(); -// addFlashMessage( -// _("pollen.information.user.deleted", user.getDisplayName())); -// -// // remove this user, otherwise it will be reused in the user lists -// user = null; -// action = null; -// result = SUCCESS; -// } catch (UserNotFoundException e) { -// addFieldError("deleteUser.login", -// _("pollen.error.user.not.found")); -// } -// return result; -// } + public boolean isExists() { + return StringUtils.isNotBlank(user.getTopiaId()); + } } Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,8 @@ +/** + * Package for all admin tasks in Pollen. + * + * All actions coming from the admin menu should be placed here. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.admin; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the all io actions. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.io; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/io/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -100,14 +100,15 @@ protected Set<String> getPollFunctions(Poll poll) { Set<String> result = Sets.newHashSet(); - PollenUserSecurityContext securityConext = newSecurityContext( - poll.getPollId(), null, poll - ); + PollenUserSecurityContext securityContext = + PollenUserSecurityContext.newContext( + getPollenUserAccount(), poll.getPollId(), null, poll); SecurityService securityService = getSecurityService(); - securityConext.loadUserRoles(securityService); + securityContext.loadUserRoles(securityService); - boolean canAccessResult = securityService.isCanAccessResult(securityConext); + boolean canAccessResult = + securityService.isCanAccessResult(securityContext); if (canAccessResult) { @@ -117,7 +118,7 @@ result.add("noresult"); } - boolean canVote = securityService.isCanVote(securityConext); + boolean canVote = securityService.isCanVote(securityContext); if (canVote) { result.add("vote"); @@ -125,7 +126,8 @@ // try to see if can access vote - boolean canAccessVote = securityService.isCanAccessVote(securityConext); + boolean canAccessVote = + securityService.isCanAccessVote(securityContext); if (canAccessVote) { result.add("accessVote"); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -109,17 +109,18 @@ protected Set<String> getPollFunctions(Poll poll, PollUri pollUri) { - PollenUserSecurityContext securityConext = newSecurityContext( - pollUri, poll - ); + PollenUserSecurityContext securityContext = + PollenUserSecurityContext.newContext( + getPollenUserAccount(), pollUri, poll); SecurityService securityService = getSecurityService(); - securityConext.loadUserRoles(securityService); + securityContext.loadUserRoles(securityService); Set<String> result = Sets.newHashSet(); result.add("vote"); - boolean canAccessResult = securityService.isCanAccessResult(securityConext); + boolean canAccessResult = + securityService.isCanAccessResult(securityContext); if (canAccessResult) { @@ -129,7 +130,7 @@ result.add("noresult"); } - boolean canAdminResult = securityConext.isCreator(); + boolean canAdminResult = securityContext.isCreator(); if (canAdminResult) { result.add("summary"); } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -116,16 +116,18 @@ PollUri pollUri) { Set<String> result = Sets.newHashSet(); - PollenUserSecurityContext securityConext = newSecurityContext( - pollUri, poll - ); + PollenUserSecurityContext securityContext = + PollenUserSecurityContext.newContext( + getPollenUserAccount(), + pollUri, poll); SecurityService securityService = getSecurityService(); - securityConext.loadUserRoles(securityService); + securityContext.loadUserRoles(securityService); result.add("vote"); - boolean canAccessResult = securityService.isCanAccessResult(securityConext); + boolean canAccessResult = + securityService.isCanAccessResult(securityContext); if (canAccessResult) { @@ -136,7 +138,7 @@ } - boolean canAdminResult = securityConext.isCreator(); + boolean canAdminResult = securityContext.isCreator(); if (canAdminResult) { result.add("summary"); } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -86,8 +86,10 @@ //TODO-tchemit-2012-06-03 Should use also pollAccountId (if specified in url)... Poll poll = getPollService().getExistingPollByPollId(pollId); - PollenUserSecurityContext securityConext = newSecurityContext(pollId, null, poll); - securityConext.loadUserRoles(getSecurityService()); + PollenUserSecurityContext securityContext = + PollenUserSecurityContext.newContext( + getPollenUserAccount(), pollId, null, poll); + securityContext.loadUserRoles(getSecurityService()); comments = new Map[commentList.size()]; Binder<Comment, Comment> binder = @@ -104,7 +106,7 @@ map.put("id", comment.getTopiaId()); Set<String> functions = getCommentFunctions( comment, - securityConext); + securityContext); map.put("functions", functions); comments[index++] = map; } Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the all json actions. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.json; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for all actions. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractDisplayChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractDisplayChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractDisplayChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,114 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.ui.actions.PollenActionSupport; - -import java.util.Map; - -/** - * To generate the display for a text choice. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public abstract class AbstractDisplayChoice extends PollenActionSupport { - - private static final long serialVersionUID = 1L; - - /** - * Where to find dynamic data (says choices in this case). - * - * @since 1.3 - */ - protected String tokenId; - - /** - * Number of choice to display. - * - * @since 1.3 - */ - protected int choiceNumber; - - /** - * Choice to display in ui (come from dynamic data if exists, or fresh - * created one). - * - * @since 1.3 - */ - protected Choice choice; - - public void setTokenId(String tokenId) { - this.tokenId = tokenId; - } - - public void setChoiceNumber(int choiceNumber) { - this.choiceNumber = choiceNumber; - } - - public Choice getChoice() { - return choice; - } - - public int getChoiceNumber() { - return choiceNumber; - } - - protected abstract Choice createEmptyChoice(); - - @Override - public String execute() throws Exception { - if (StringUtils.isNotEmpty(tokenId)) { - - Map<Integer, Choice> choices = - getPollenSession().getDynamicData(tokenId); - - if (choices != null) { - - // get choices from datas - choice = choices.get(choiceNumber); - - if (choice != null) { - - // remove this choice from session - choices.remove(choiceNumber); - } - } - - if (MapUtils.isEmpty(choices)) { - - // remove it from session - getPollenSession().removeDynamicData(tokenId); - } - } - - if (choice == null) { - choice = createEmptyChoice(); - } - return SUCCESS; - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,1972 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Charsets; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.opensymphony.xwork2.Preparable; -import com.opensymphony.xwork2.interceptor.annotations.InputConfig; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.ObjectUtils; -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.apache.struts2.interceptor.ServletRequestAware; -import org.chorem.pollen.PollenTechnicalException; -import org.chorem.pollen.bean.PollDateChoice; -import org.chorem.pollen.bean.PollImageChoice; -import org.chorem.pollen.bean.PollUri; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.business.persistence.ChoiceImpl; -import org.chorem.pollen.business.persistence.PersonToList; -import org.chorem.pollen.business.persistence.PersonToListImpl; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.business.persistence.PollAccount; -import org.chorem.pollen.business.persistence.PollAccountImpl; -import org.chorem.pollen.business.persistence.PollCommentVisibility; -import org.chorem.pollen.business.persistence.PollVoteVisibility; -import org.chorem.pollen.business.persistence.PreventRule; -import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.business.persistence.VotingList; -import org.chorem.pollen.business.persistence.VotingListImpl; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.I18nAble; -import org.chorem.pollen.common.PollType; -import org.chorem.pollen.services.PollenServiceFunctions; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.services.impl.PollService; -import org.chorem.pollen.services.impl.PreventRuleService; -import org.chorem.pollen.ui.actions.FileUploadAware; -import org.chorem.pollen.ui.actions.PollenActionSupportForEdition; -import org.chorem.pollen.ui.converters.DateConverter; -import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; -import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider; -import org.nuiton.util.StringUtil; - -import javax.servlet.http.HttpServletRequest; -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Collection; -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; - -/** - * Created: 04/04/12 - * - * @author fdesbois <desbois@codelutin.com> - * $Id$ - */ -public abstract class AbstractPollForm extends PollenActionSupportForEdition implements Preparable, ParameterAware, FileUploadAware, ServletRequestAware { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractPollForm.class); - - public static final String IMAGECHOICES_THUMB_PREFIX = "imagechoicesThumb_"; - - private static final Pattern TEXT_CHOICE_NAME_PATTERN = - Pattern.compile("textChoice_(\\d+)\\.name"); - - private static final Pattern DATE_CHOICE_NAME_PATTERN = - Pattern.compile("dateChoice_(\\d+)\\.name"); - - private static final Pattern IMAGE_CHOICE_DESCRIPTION_PATTERN = - Pattern.compile("imageChoice_(\\d+)\\.description"); - - protected Poll poll; - - private Map<String, String> pollTypes; - - private Map<String, String> voteCountingTypes; - - private Map<String, String> choiceTypes; - - private Map<String, String> pollVoteVisibilities; - - /** Text choices. */ - private List<Choice> textChoices; - - /** Image choices. */ - private List<Choice> imageChoices; - - /** Date choices. */ - private List<Choice> dateChoices; - - /** restricted Voting lists. */ - private List<VotingList> restrictedVotingList; - - /** Group voting lists. */ - private List<VotingList> groupVotingList; - - private boolean notification; - - private boolean reminder; - - private boolean limitChoice; - - private Integer maxChoices; - - private Integer reminderHourCountdown; - - /** To create a new personToList. */ - private transient Function<PersonToList, PersonToList> persontoListCreator; - - /** To create a new votingList. */ - private transient Function<VotingList, VotingList> votingListCreator; - - /** To create a new text choice. */ - private transient Function<Choice, Choice> textChoiceCreator; - - /** To create a new date choice. */ - private transient Function<Choice, Choice> dateChoiceCreator; - - /** To create a new image choice. */ - private transient Function<Choice, Choice> imageChoiceCreator; - - /** - * Flag when there is some errors on the information panel. - * - * @since 1.3 - */ - protected boolean informationsError; - - /** - * Flag when there is some errors on the options panel. - * - * @since 1.3 - */ - private boolean optionsError; - - /** - * All the parameters send by request used to build back choices of the - * poll. - * - * @since 1.3 - */ - protected final Map<String, String[]> parameters = Maps.newTreeMap(); - - /** - * Indexed choices retreive from parameters for the choiceType selected in - * form. (Other choices are lost). - * - * @since 1.3 - */ - private Map<Integer, Choice> choices; - - /** - * Contains the order of choices (given by the xxx.order field. - * - * @since 1.4 - */ - private Map<Integer, Integer> choicesOrder; - - /** - * Indexed voting lists retreive from parameters for the pollType selected - * in form. (Other voting lists are lost). - * - * @since 1.3 - */ - private Map<Integer, VotingList> votingLists; - - private PollUri pollUri; - - /** - * The incoming request (some stuff are store in it from security filters). - * - * @since 1.4 - */ - private transient HttpServletRequest request; - - public abstract boolean isClone(); - - protected abstract Poll savePoll(Poll poll) throws PollNotFoundException; - - public abstract boolean isEdit(); - - @Override - public void setServletRequest(HttpServletRequest request) { - this.request = request; - } - - @Override - public void prepare() throws Exception { - - prepareFormPage(); - - if (isGetMethod()) { - - // do not prepare when coming as GET - return; - } - - // we are after a submit - - String pollUid = getNonEmptyParameterValue("poll.pollId"); - String userId = getNonEmptyParameterValue("userId"); - if (StringUtils.isBlank(userId)) { - - // try to take the one from current user - UserAccount userAccount = getPollenUserAccount(); - if (userAccount != null) { - userId = userAccount.getTopiaId(); - } - } - UserAccount userAccount = null; - if (StringUtils.isNotBlank(userId)) { - // load use account to use - userAccount = getPollService().getEntityById( - UserAccount.class, userId); - } - - // get a copy (or a fresh new poll) - poll = getPollService().getPollEditable(pollUid, userAccount, false); - - // If vote is started, prepare choices and votingLists is useless - // because they can't be updated. - if (!isVoteStarted()) { - - // Retrieve choiceType from parameters, the poll object will be updated after prepare - String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType"); - ChoiceType pollChoiceType = ChoiceType.valueOf(choiceTypeParam); - poll.setChoiceType(pollChoiceType); - - choicesOrder = Maps.newTreeMap(); - - // build poll choices - - switch (pollChoiceType) { - - case TEXT: - choices = buildTextChoices(); - break; - case DATE: - choices = buildDateChoices(); - break; - case IMAGE: - choices = buildImageChoices(); - break; - } - PollType pollType; - String pollTypeParam = getNonEmptyParameterValue("poll.pollType"); - pollType = PollType.valueOf(pollTypeParam); - switch (pollType) { - - case FREE: - - // empty voting list - votingLists = Maps.newTreeMap(); - break; - case RESTRICTED: - - // restricted voting list - votingLists = buildVotingLists(pollType); - break; - case GROUP: - - // group voting lists - votingLists = buildVotingLists(pollType); - break; - } - } - } - - @Override - public String input() throws Exception { - - UserAccount userAccount = getPollenUserAccount(); - String pollUid = pollUri == null ? null : pollUri.getPollId(); - PollService service = getPollService(); - - poll = service.getPollEditable(pollUid, userAccount, isClone()); - - if (poll.isClosed()) { - addFlashWarning(_("pollen.warning.poll.is.closed.so.read.only")); - } - List<Choice> pollChoices = poll.getChoice(); - - if (isClone()) { - - if (ChoiceType.IMAGE == poll.getChoiceType()) { - - // recopy images to tmp - - File tmpDir = getConfiguration().getTemporaryDirectory(); - for (Choice choice : pollChoices) { - String choiceName = choice.getName(); - - // image from poll to clone - File imageChoiceFile = service.getPollChoiceImageFile( - pollUid, - choiceName - ); - - // new image - File newImageChoiceFile = File.createTempFile( - choiceName, null, tmpDir); - - if (log.isInfoEnabled()) { - log.info("Copy image from " + imageChoiceFile + - " to " + newImageChoiceFile); - } - FileUtils.copyFile(imageChoiceFile, - newImageChoiceFile); - - ((PollImageChoice) choice).setLocation( - newImageChoiceFile.getAbsolutePath()); - } - } - } - - List<VotingList> pollVotingLists = poll.getVotingList(); - - loadChoicesAndvotingLists(poll, - pollChoices, - pollVotingLists, - !isVoteStarted()); - - setLimitChoice(poll.getMaxChoiceNb() > 0); - - if (isLimitChoice()) { - setMaxChoices(poll.getMaxChoiceNb()); - } else { - // set default max choices - setMaxChoices(1); - } - PreventRule reminder = poll.getPreventRuleByScope( - PreventRuleService.SCOPE_REMINDER); - if (reminder != null) { - setReminder(true); - setReminderHourCountdown(reminder.getSensibility()); - } else { - setReminder(false); - // set default reminderHourCountdown - setReminderHourCountdown(2); - } - - PreventRule notification = poll.getPreventRuleByScope( - PreventRuleService.SCOPE_VOTE); - if (notification != null) { - setNotification(true); - } - - if (isVoteStarted()) { - addFlashMessage(_("pollen.information.poll.form.voteStarted")); - } - - return INPUT; - } - - public String inputAfterValidationError() throws Exception { - - Collection<Choice> pollChoices = - isVoteStarted() ? poll.getChoice() : choices.values(); - Collection<VotingList> pollVotingLists = - isVoteStarted() ? poll.getVotingList() : votingLists.values(); - - if (ChoiceType.IMAGE == poll.getChoiceType()) { - - // recopy images for new choices, the one uploaded will be - // destroyed, by the upload interceptor - - File tmpDir = getConfiguration().getTemporaryDirectory(); - - for (Choice choice : pollChoices) { - - PollImageChoice imageChoice = (PollImageChoice) choice; - - String choiceId = choice.getTopiaId(); - String location = imageChoice.getLocation(); - - boolean needCopy = false; - if (!isImageUploadEmpty(imageChoice)) { - - // there is an image in the choice - - if (StringUtils.isBlank(choiceId)) { - - // this is a new choice - needCopy = true; - } else { - - // check that name has not changed - Choice oldChoice = poll.getChoiceByTopiaId(choiceId); - - needCopy = ObjectUtils.notEqual(oldChoice.getName(), imageChoice.getName()); - } - } - - if (needCopy) { - - // not persisted choice with an upload - // let's copy it somewhere safe - - File uploadedImage = new File(location); - File copyImage = File.createTempFile( - uploadedImage.getName(), null, tmpDir); - - if (log.isInfoEnabled()) { - log.info("Copy image from " + uploadedImage + - " to " + copyImage); - } - FileUtils.copyFile(uploadedImage, copyImage); - - imageChoice.setLocation(copyImage.getAbsolutePath()); - - // generate also the thumb file - getPollService().generateThumbIfNeeded(copyImage); - } - } - } - - loadChoicesAndvotingLists(poll, pollChoices, pollVotingLists, true); - return INPUT; - } - - @Override - @InputConfig(methodName = "inputAfterValidationError") - public String execute() throws Exception { - - if (isGetMethod()) { - - // input method - return input(); - } - - // Save choices and votingLists only if vote is not started - if (!isVoteStarted()) { - //TODO-tchemit comment me 2012-06-04 A merge would be nicer but more complex to code - // Clear previous collections to save those from the form - poll.clearChoice(); - poll.clearVotingList(); - for (Integer index : choices.keySet()) { - Choice choice = choices.get(index); - poll.addChoice(choice); - } - - if (!isFreePoll()) { - - for (Integer index : votingLists.keySet()) { - VotingList votingList = votingLists.get(index); - poll.addVotingList(votingList); - } - } - } - - if (isLimitChoice()) { - - // push back filled value - poll.setMaxChoiceNb(getMaxChoices()); - } else { - // reset value - poll.setMaxChoiceNb(0); - } - - if (poll.isAnonymous()) { - - // force to not have choice to vote anonymously - poll.setAnonymousVoteAllowed(false); - } - - //TODO-tchemit comment me 2012-06-04 A merge would be nicer but more complex to code - poll.clearPreventRule(); - - PreventRuleService preventRuleService = getPreventRuleService(); - 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); - } - - // do save poll - poll = savePoll(poll); - - // compute fresh pollUri - pollUri = PollUri.newPollUri(poll.getAdminId()); - - // remove all stuff from session - getPollenSession().clearDynamicData(); - - return SUCCESS; - } - - protected boolean isGetMethod() { - return "GET".equalsIgnoreCase(request.getMethod()); - } - - @Override - public void validate() { - - if (isGetMethod()) { - - // input method - return; - } - validateInformations(); - - validateOptions(); - } - - @Override - public void addFile(int index, File file) { - parameters.put("imageChoice_" + index + ".newLocation", - new String[]{file.getAbsolutePath()}); - } - - @Override - public void addFileContentType(int index, String contentType) { - parameters.put("imageChoice_" + index + ".newContentType", - new String[]{contentType}); - // not used here - } - - @Override - public void addFileName(int index, String fileName) { - parameters.put("imageChoice_" + index + ".newName", new String[]{fileName}); - } - - @Override - public void setParameters(Map<String, String[]> parameters) { - this.parameters.putAll(parameters); - } - - public boolean isInformationsError() { - return informationsError; - } - - public boolean isOptionsError() { - return optionsError; - } - - public int getSelectedTab() { - int result; - if (isInformationsError()) { - result = 0; - } else { - if (isOptionsError()) { - result = 1; - } else { - result = 0; - } - } - return result; - } - - public PollUri getUriId() { - return pollUri; - } - - public void setUriId(PollUri pollUri) { - this.pollUri = pollUri; - } - - public Poll getPoll() { - return poll; - } - - public Map<String, String> getPollTypes() { - return pollTypes; - } - - public Map<String, String> getVoteCountingTypes() { - return voteCountingTypes; - } - - public Map<String, String> getChoiceTypes() { - return choiceTypes; - } - - public Map<String, String> getPollVoteVisibilities() { - return pollVoteVisibilities; - } - - public List<Choice> getTextChoices() { - return textChoices; - } - - public List<Choice> getImageChoices() { - return imageChoices; - } - - public List<Choice> getDateChoices() { - return dateChoices; - } - - public List<VotingList> getRestrictedVotingList() { - return restrictedVotingList; - } - - public List<VotingList> getGroupVotingList() { - return groupVotingList; - } - - public boolean isNotification() { - return notification; - } - - public void setNotification(boolean notification) { - this.notification = notification; - } - - public Integer getMaxChoices() { - return maxChoices; - } - - public void setMaxChoices(Integer maxChoices) { - this.maxChoices = maxChoices; - } - - 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 Integer getReminderHourCountdown() { - return reminderHourCountdown; - } - - public void setReminderHourCountdown(Integer reminderHourCountdown) { - this.reminderHourCountdown = reminderHourCountdown; - } - - public boolean isFreePoll() { - return poll.isPollFree(); - } - - public boolean isGroupPoll() { - PollType pollType = poll.getPollType(); - return pollType == PollType.GROUP; - } - - public boolean isPollCommentVisible() { - PollCommentVisibility pollCommentVisibility = - poll.getPollCommentVisibility(); - return pollCommentVisibility == PollCommentVisibility.EVERYBODY; - } - - public void setPollCommentVisible(boolean newValue) { - if (newValue) { - poll.setPollCommentVisibility(PollCommentVisibility.EVERYBODY); - } else { - poll.setPollCommentVisibility(PollCommentVisibility.NOBODY); - } - } - - public String getActionLabel() { - return isEdit() ? _("pollen.action.editPoll") : - _("pollen.action.createPoll"); - } - - public String getPageTitle() { - return isEdit() ? getPoll().getTitle() : - _("pollen.title.createPoll"); - } - - public boolean isVoteStarted() { - return isEdit() && poll.sizeVote() > 0; - } - - public boolean isCreatorUserAccountDefined() { - PollAccount creator = poll.getCreator(); - return creator.getUserAccount() != null; - } - - public String getImageChoiceName(Choice choice) { - String name = choice.getName(); - try { - String result = URLEncoder.encode(IMAGECHOICES_THUMB_PREFIX + name, - Charsets.UTF_8.name()); - return result; - } catch (UnsupportedEncodingException e) { - throw new PollenTechnicalException( - "Could not encode name " + name, e); - } - } - - public String getVoteCountingHelp() { - - StringBuilder builder = new StringBuilder(); - VoteCountingStrategyProvider strategyProvider = - getVoteCountingStrategyProvider(); - Set<Integer> strategyIds = strategyProvider.getStrategyIds(); - for (Integer strategyId : strategyIds) { - VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId); - String strategyHelp = strategy.getStrategyHelp(getLocale()); - builder.append(strategyHelp).append("<br/><br/>"); - } - return builder.toString(); - } - - public void prepareFormPage() throws Exception { - - getPollenSession().removeDynamicDataWithPrefix(IMAGECHOICES_THUMB_PREFIX); - - pollTypes = decorateToName(PollType.values()); - choiceTypes = decorateToName(ChoiceType.values()); - pollVoteVisibilities = decorateToName(PollVoteVisibility.values()); - voteCountingTypes = Maps.newTreeMap(); - - VoteCountingStrategyProvider strategyProvider = - getVoteCountingStrategyProvider(); - Set<Integer> strategyIds = strategyProvider.getStrategyIds(); - for (Integer strategyId : strategyIds) { - VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId); - String strategyHelp = strategy.getStrategyName(getLocale()); - voteCountingTypes.put(strategyId + "", strategyHelp); - } -// decorateToName(VoteCountingType.values()); - - textChoices = Lists.newArrayList(); - imageChoices = Lists.newArrayList(); - dateChoices = Lists.newArrayList(); - - restrictedVotingList = Lists.newArrayList(); - groupVotingList = Lists.newArrayList(); - } - - public Function<PersonToList, PersonToList> getPersontoListCreator() { - if (persontoListCreator == null) { - persontoListCreator = PollenServiceFunctions.newPersonToListCreator(); - } - return persontoListCreator; - } - - public Function<VotingList, VotingList> getVotingListCreator() { - if (votingListCreator == null) { - votingListCreator = PollenServiceFunctions.newVotingListCreator( - getPersontoListCreator()); - } - return votingListCreator; - } - - public Function<Choice, Choice> getTextChoiceCreator() { - if (textChoiceCreator == null) { - textChoiceCreator = PollenServiceFunctions.newTextChoiceCreator(); - } - return textChoiceCreator; - } - - public Function<Choice, Choice> getDateChoiceCreator() { - if (dateChoiceCreator == null) { - dateChoiceCreator = PollenServiceFunctions.newDateChoiceCreator(); - } - return dateChoiceCreator; - } - - public Function<Choice, Choice> getImageChoiceCreator() { - if (imageChoiceCreator == null) { - imageChoiceCreator = PollenServiceFunctions.newImageChoiceCreator(); - } - return imageChoiceCreator; - } - - 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; - } - - protected void validateInformations() { - - // -- Title : required -- // - if (StringUtils.isBlank(poll.getTitle())) { - addInformationsError("poll.title", - _("pollen.error.poll.required.title")); - } - - if (isVoteStarted()) { - - // no validation on choices if vote is started - - } else { - - // -- Choice -- // - if (MapUtils.isEmpty(choices)) { - - // poll must have at least one choice - addInformationsError("poll.choices", - _("pollen.error.poll.required.one.choice")); - } else { - switch (poll.getChoiceType()) { - - case TEXT: - validateTextChoices(); - break; - case DATE: - validateDateChoices(); - break; - case IMAGE: - validateImageChoices(); - break; - } - } - } - } - - protected void validateTextChoices() { - - String choicePrefix = getChoiceFieldPrefix(ChoiceType.TEXT); - - Set<String> choiceNames = Sets.newHashSet(); - - for (Map.Entry<Integer, Choice> entry : choices.entrySet()) { - Integer choiceIndex = entry.getKey(); - Choice choice = entry.getValue(); - String choiceErrorField = choicePrefix + choiceIndex + ".name"; - String choiceName = choice.getName(); - if (StringUtils.isBlank(choiceName)) { - // no name - addInformationsError( - choiceErrorField, - _("pollen.error.poll.choice.name.required")); - continue; - } - if (choiceNames.contains(choiceName)) { - // duplicated names - addInformationsError( - choiceErrorField, - _("pollen.error.poll.choice.already.used.name")); - continue; - } - choiceNames.add(choiceName); - } - } - - protected void validateDateChoices() { - - String choicePrefix = getChoiceFieldPrefix(ChoiceType.DATE); - - Set<String> choiceNames = Sets.newHashSet(); - - for (Map.Entry<Integer, Choice> entry : choices.entrySet()) { - Integer choiceIndex = entry.getKey(); - PollDateChoice choice = (PollDateChoice) entry.getValue(); - String choiceErrorField = choicePrefix + choiceIndex + ".name"; - if (StringUtils.isBlank(choice.getName())) { - // no name - addInformationsError( - choiceErrorField, - _("pollen.error.poll.dateChoice.required")); - continue; - } - if (choice.getDate() == null) { - - // format error - addInformationsError( - choiceErrorField, - _("pollen.error.poll.dateChoice.badDateFormat")); - continue; - } - - // date is valid - // use now the date.toString() as value to ensure unicity - String choiceValue = choice.getDate().toString(); - - if (choiceNames.contains(choiceValue)) { - // duplicated names - addInformationsError( - choiceErrorField, - _("pollen.error.poll.dateChoice.already.used")); - continue; - } - choiceNames.add(choiceValue); - } - } - - protected void validateImageChoices() { - - String choicePrefix = getChoiceFieldPrefix(ChoiceType.IMAGE); - - Set<String> choiceNames = Sets.newHashSet(); - - for (Map.Entry<Integer, Choice> entry : choices.entrySet()) { - Integer choiceIndex = entry.getKey(); - Choice choice = entry.getValue(); - String choiceErrorField = choicePrefix + choiceIndex + ".name"; - String choiceName = choice.getName(); - if (StringUtils.isBlank(choiceName)) { - // no name - addInformationsError( - choiceErrorField, - _("pollen.error.poll.imageChoice.upload.required")); - continue; - } - if (choiceNames.contains(choiceName)) { - // duplicated names - addInformationsError( - choiceErrorField, - _("pollen.error.poll.imageChoice.already.used")); - continue; - } - choiceNames.add(choiceName); - String contentTypeField = choicePrefix + choiceIndex + ".newContentType"; - String contentTypes = getNonEmptyParameterValue(contentTypeField); - if (contentTypes != null && !contentTypes.startsWith("image/")) { - // Bad content Type - addInformationsError( - choiceErrorField, - _("pollen.error.poll.imageChoice.upload.badContentType")); - //Remove the file and its thumb - PollImageChoice imageChoice = (PollImageChoice) choice; - File imageFile = new File(imageChoice.getLocation()); - File imageThumbFile = getPollService().getImageThumbFile(imageFile); - FileUtils.deleteQuietly(imageThumbFile); - FileUtils.deleteQuietly(imageFile); - // The choice has no more location - String choiceId = imageChoice.getTopiaId(); - if (StringUtils.isBlank(choiceId)) { - imageChoice.setLocation(null); - // As the name of the choice is the fileName, remove it too. - imageChoice.setName(null); - } else { - // in case of update, get back the old values for name and location and keep the old choice - PollImageChoice pollChoice = (PollImageChoice) poll.getChoiceByTopiaId(choiceId); - imageChoice.setName(pollChoice.getName()); - imageChoice.setLocation(pollChoice.getLocation()); - } - continue; - } - } - } - - protected void validateOptions() { - - if (isVoteStarted()) { - - // no validation on votingLists if vote is started - - } else { - - // -- VotingList -- // - - if (isFreePoll()) { - - // nothing to validate - - } else { - - Set<String> groups = Sets.newHashSet(); - Set<String> voters = Sets.newHashSet(); - Set<String> emails = Sets.newHashSet(); - - for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) { - validateVotingList(entry.getKey(), - entry.getValue(), - groups, - voters, - emails); - } - } - } - - String creatorEmail = poll.getCreator().getEmail(); - if (StringUtils.isNotBlank(creatorEmail) && - !StringUtil.isEmail(creatorEmail)) { - - addOptionsError("poll.creator.email", - _("pollen.error.email.invalid")); - } - - Date currentTime = serviceContext.getCurrentTime(); - - if (validateEndDate(poll.getBeginChoiceDate(), poll.getEndChoiceDate())) { - - addOptionsError( - "poll.endChoiceDate", - _("pollen.error.poll.endChoiceDate.before.beginChoiceDate")); - } - - if (validateEndDate(currentTime, poll.getEndChoiceDate())) { - - addOptionsError( - "poll.endChoiceDate", - _("pollen.error.poll.endChoiceDate.before.now")); - } - - if (validateEndDate(poll.getBeginDate(), poll.getEndDate())) { - - addOptionsError("poll.endDate", - _("pollen.error.poll.endDate.before.beginDate")); - } - - - if (validateEndDate(currentTime, poll.getEndDate())) { - - addOptionsError( - "poll.endDate", - _("pollen.error.poll.endDate.before.now")); - } - - if (validateEndDate(poll.getEndChoiceDate(), poll.getEndDate())) { - - addOptionsError("poll.endChoiceDate", - _("pollen.error.poll.endChoiceDate.after.endDate")); - } - - if (isLimitChoice()) { - - // validate maxChoices - - if (getMaxChoices() == null) { - // maxChoices == null - addOptionsError("maxChoices", - _("pollen.error.poll.maxChoice.required")); - } else if (getMaxChoices() < 1) { - // maxChoices <= 0 - addOptionsError("maxChoices", - _("pollen.error.poll.maxChoice.greater.than.0")); - } - } - - if (isReminder()) { - - // validate reminderHourCountdown - - if (getReminderHourCountdown() == null) { - - // reminderHourCountdown == null - addOptionsError("reminderHourCountdown", - _("pollen.error.poll.reminderHourCountdown.required")); - } else if (getReminderHourCountdown() < 1) { - - // reminderHourCountdown <= 0 - addOptionsError("reminderHourCountdown", - _("pollen.error.poll.reminderHourCountdown.greater.than.0")); - } - } - } - - protected void validateVotingList(int votingListNumber, - VotingList votingList, - Set<String> groups, - Set<String> voters, - Set<String> emails) { - - PollType votingListType = poll.getPollType(); - String fieldNamePrefix = "votingList" + votingListType + "_" + - votingListNumber; - - if (isGroupPoll()) { - - // group poll - - // check there is at least one group - // check no doublon on group names - // check there is at least one voter on each group - // check no doublon on voter names - // check no doublon on voter emails - - // validate votingList name - String votingListName = votingList.getName(); - - if (StringUtils.isEmpty(votingListName)) { - - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.required.votingList.name")); - } else { - - // check no votingList name doublon - boolean add = groups.add(votingListName); - if (!add) { - - // name doublon - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.votingList.name.doublon")); - } - } - - // validate votingList weight - - if (votingList.getWeight() == 0) { - - // no weight filled (can be a bad conversion) - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.votingList.weight.not.valid")); - } - - } - - // check there is at least one voter - - List<PersonToList> personToLists = - votingList.getPollAccountPersonToList(); - - if (CollectionUtils.isEmpty(personToLists)) { - - // no personToList found for unique votingList 0 - addOptionsError(fieldNamePrefix, - _("pollen.error.poll.required.one.personToList")); - } else { - - // check no doublon on voter names - - for (int i = 0; i < personToLists.size(); i++) { - - validatePersonList(i, - fieldNamePrefix, - personToLists.get(i), - voters, - emails); - } - } - } - - protected void validatePersonList(int personToListNumber, - String votingListFieldNamePrefix, - PersonToList personToList, - Set<String> voters, - Set<String> emails) { - - String fieldNamePrefix = votingListFieldNamePrefix + - "PersonToList_" + personToListNumber; - - PollAccount pollAccount = personToList.getPollAccount(); - - // -- validate votingId -- // - - String votingId = pollAccount.getVotingId(); - - if (StringUtils.isEmpty(votingId)) { - - // voter name mandatory - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.personToList.votingId.required")); - } else { - - boolean add = voters.add(votingId); - if (!add) { - - // voter name already used - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.personToList.votingId.doublon")); - } - } - - // -- validate email -- // - - String email = pollAccount.getEmail(); - - if (StringUtils.isEmpty(email)) { - - // voter email mandatory - addOptionsError(fieldNamePrefix, - _("pollen.error.email.required")); - } else { - - boolean validEmail = StringUtil.isEmail(email); - if (!validEmail) { - - // not a valid email - addOptionsError(fieldNamePrefix, - _("pollen.error.email.invalid")); - } else { - - boolean add = emails.add(email); - if (!add) { - - // email already used - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.personToList.email.doublon")); - } - } - } - - // -- validate weight -- // - - if (personToList.getWeight() == 0) { - - // no weight filled (can be a bad conversion) - addOptionsError( - fieldNamePrefix, - _("pollen.error.poll.personToList.weight.not.valid")); - } - } - - protected boolean validateEndDate(Date begin, Date end) { - return begin != null - && end != null - && end.before(begin); - } - - public Object getDateChoiceValue(PollDateChoice choice) { - Date date = choice.getDate(); - Object result; - if (date == null) { - result = choice.getName(); - } else { - result = date; - } - return result; - } - - @Override - public void addFieldError(String fieldName, String errorMessage) { - super.addFieldError(fieldName, errorMessage); - if (log.isDebugEnabled()) { - log.debug("VALIDATION [" + fieldName + "] : " + errorMessage); - } - } - - protected void addInformationsError(String fieldName, String errorMessage) { - addFieldError(fieldName, errorMessage); - informationsError = true; - } - - protected void addOptionsError(String fieldName, String errorMessage) { - addFieldError(fieldName, errorMessage); - optionsError = true; - } - - protected void loadChoicesAndvotingLists(Poll poll, - Collection<Choice> pollChoices, - Collection<VotingList> pollVotinLists, - boolean fillLists) throws IOException { - - Preconditions.checkNotNull(poll); - Preconditions.checkNotNull(poll.getChoiceType()); - Preconditions.checkNotNull(poll.getPollType()); - - if (CollectionUtils.isNotEmpty(pollChoices)) { - - //push back choices - - switch (poll.getChoiceType()) { - - case TEXT: - getTextChoices().addAll(pollChoices); - break; - case DATE: - getDateChoices().addAll(pollChoices); - break; - case IMAGE: - getImageChoices().addAll(pollChoices); - - PollService service = getPollService(); - - // if images are not still saved in a poll, then thumb - // does not exists, must create a temporary one - for (Choice choice : pollChoices) { - PollImageChoice imageChoice = (PollImageChoice) choice; - String choiceId = imageChoice.getTopiaId(); - File imageChoiceFile = null; - - if (StringUtils.isBlank(choiceId)) { - - // new choice, - - if (!isImageUploadEmpty(imageChoice)) { - - // ok there is an upload - imageChoiceFile = - new File(imageChoice.getLocation()); - } - - } else { - - // already persisted choice, check choice has not changed - - Choice oldChoice = - poll.getChoiceByTopiaId(choiceId); - - if (ObjectUtils.equals( - imageChoice.getName(), - oldChoice.getName())) { - - // name has not changed, keep persisted choice - imageChoiceFile = service.getPollChoiceImageFile( - poll.getPollId(), choice.getName()); - } else { - - // use new choice image location - imageChoiceFile = - new File(imageChoice.getLocation()); - } - - } - - if (imageChoiceFile != null) { - File thumbFile = service.getImageThumbFile( - imageChoiceFile); - - // keep in session the location of this thumb (do not - // want to expose the full path location in url) - String key = getImageChoiceName(choice); - getPollenSession().putDynamicData(key, thumbFile); - } - } - - break; - } - } - - if (CollectionUtils.isNotEmpty(pollVotinLists)) { - - // push back voting lists - - switch (poll.getPollType()) { - - case FREE: - // not voting lists - break; - case RESTRICTED: - getRestrictedVotingList().addAll(pollVotinLists); - break; - case GROUP: - getGroupVotingList().addAll(pollVotinLists); - break; - } - } - - if (fillLists) { - - // refill lists - - int defaultMaxChoices = 5; - int defaultMaxVoting = 5; - - fillLists(defaultMaxChoices, defaultMaxVoting); - } - } - - protected void fillLists(int defaultMaxChoices, int defaultMaxVoting) { - - PollenServiceFunctions.fillChoiceList(textChoices, - defaultMaxChoices, - getTextChoiceCreator()); - - PollenServiceFunctions.fillChoiceList(dateChoices, - defaultMaxChoices, - getDateChoiceCreator()); - - PollenServiceFunctions.fillChoiceList(imageChoices, - defaultMaxChoices, - getImageChoiceCreator()); - - if (CollectionUtils.isEmpty(restrictedVotingList)) { - restrictedVotingList.add(getVotingListCreator().apply(null)); - } - for (VotingList votingList : restrictedVotingList) { - PollenServiceFunctions.fillVotingList(votingList, - getPersontoListCreator(), - defaultMaxVoting); - } - if (CollectionUtils.isEmpty(groupVotingList)) { - groupVotingList.add(getVotingListCreator().apply(null)); - } - for (VotingList votingList : groupVotingList) { - PollenServiceFunctions.fillVotingList(votingList, - getPersontoListCreator(), - defaultMaxVoting); - } - } - - protected boolean isTextChoiceEmpty(Choice textChoice) { - boolean result = - StringUtils.isBlank(textChoice.getName()) && - StringUtils.isBlank(textChoice.getDescription()); - return result; - } - - protected boolean isDateChoiceEmpty(PollDateChoice dateChoice) { - boolean result = - StringUtils.isBlank(dateChoice.getName()) && - StringUtils.isBlank(dateChoice.getDescription()); - return result; - } - - protected boolean isImageChoiceEmpty(PollImageChoice imageChoice) { - boolean result = - StringUtils.isBlank(imageChoice.getLocation()) && - StringUtils.isBlank(imageChoice.getDescription()); - return result; - } - - protected boolean isImageUploadEmpty(PollImageChoice imageChoice) { - boolean result = - StringUtils.isBlank(imageChoice.getLocation()); - return result; - } - - protected boolean isPersonToListEmpty(PersonToList personToList) { - PollAccount pollAccount = personToList.getPollAccount(); - boolean result = - StringUtils.isBlank(pollAccount.getVotingId()) && - StringUtils.isBlank(pollAccount.getEmail()); - return result; - } - - protected Map<Integer, Choice> buildTextChoices() { - Map<Integer, Choice> result = Maps.newTreeMap(); - - String fieldPrefix = getChoiceFieldPrefix(ChoiceType.TEXT); - - 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); - - // can keep this none empty text choice name - - Integer choiceNumber = Integer.valueOf(matcher.group(1)); - - if (choiceNumber > maxNumber) { - maxNumber = choiceNumber; - } - String choicePrefix = fieldPrefix + choiceNumber; - Choice choice = createChoice(new ChoiceImpl(), - choicePrefix, - paramValue); - if (!isTextChoiceEmpty(choice)) { - - // This is not an empty choice keep it - result.put(choiceNumber, choice); - - // keep order - int order = getIntegerValue(choicePrefix + ".order"); - choicesOrder.put(order, choiceNumber); - } - } - } - result = reindexChoiceMap(result, maxNumber); - - int size = result.size(); - if (log.isInfoEnabled()) { - log.info("nbTextChoices (from request) = " + size); - } - logChoice(result); - return result; - } - - protected Map<Integer, Choice> buildDateChoices() { - Map<Integer, Choice> result = Maps.newTreeMap(); - - String fieldPrefix = getChoiceFieldPrefix(ChoiceType.DATE); - - 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); - - // can keep this none empty text choice name - - Integer choiceNumber = Integer.valueOf(matcher.group(1)); - if (choiceNumber > maxNumber) { - maxNumber = choiceNumber; - } - String choicePrefix = fieldPrefix + choiceNumber; - - PollDateChoice choice = createChoice(new PollDateChoice(), - choicePrefix, - paramValue); - if (StringUtils.isNotBlank(paramValue)) { - Date date = DateConverter.convertFromString(paramValue); - choice.setDate(date); - } - - if (!isDateChoiceEmpty(choice)) { - - // This is not an empty choice keep it - result.put(choiceNumber, choice); - - // keep order - int order = getIntegerValue(choicePrefix + ".order"); - choicesOrder.put(order, choiceNumber); - } - } - } - result = reindexChoiceMap(result, maxNumber); - - int size = result.size(); - if (log.isInfoEnabled()) { - log.info("nbDateChoices (from request) = " + size); - } - logChoice(result); - return result; - } - - protected Map<Integer, Choice> buildImageChoices() { - Map<Integer, Choice> result = Maps.newTreeMap(); - - String fieldPrefix = getChoiceFieldPrefix(ChoiceType.IMAGE); - - int maxNumber = 0; - - Map<String, String> parametersToSwitch = Maps.newTreeMap(); - - for (String paramName : parameters.keySet()) { - - Matcher matcher = IMAGE_CHOICE_DESCRIPTION_PATTERN.matcher(paramName); - if (matcher.matches()) { - - // found an image choice description - // Note: We can not use as for other choices (text and date) - // the name since there is no name parameter submitted... - // the upload filed will implies a such parameter... - - Integer choiceNumber = Integer.valueOf(matcher.group(1)); - if (choiceNumber > maxNumber) { - maxNumber = choiceNumber; - } - - String choicePrefix = fieldPrefix + choiceNumber; - - PollImageChoice choice = createChoice(new PollImageChoice(), - choicePrefix, - null); - String location = getNonEmptyParameterValue( - choicePrefix + ".newLocation"); - if (StringUtils.isNotBlank(location)) { - - // found a real upload file (not jus the location of an - // already choice uploaded choice - choice.setLocation(location); - - // ok so now use also newName - String paramValue = getNonEmptyParameterValue( - choicePrefix + ".newName"); - choice.setName(paramValue); - - parametersToSwitch.put(choicePrefix + ".newLocation", - choicePrefix + ".location"); - - parametersToSwitch.put(choicePrefix + ".newName", - choicePrefix + ".name"); - - } else { - - // try with old location - location = getNonEmptyParameterValue( - choicePrefix + ".location"); - choice.setLocation(location); - - String paramValue = getNonEmptyParameterValue( - choicePrefix + ".name"); - choice.setName(paramValue); - } - - if (!isImageChoiceEmpty(choice)) { - - // This is not an empty choice keep it - result.put(choiceNumber, choice); - - // keep order - int order = getIntegerValue(choicePrefix + ".order"); - choicesOrder.put(order, choiceNumber); - } - } - } - - // switch new uploaded values - for (Map.Entry<String, String> entry : parametersToSwitch.entrySet()) { - String paramNameSource = entry.getKey(); - String paramNameTarget = entry.getValue(); - String[] valueToSwitch = parameters.remove(paramNameSource); - parameters.put(paramNameTarget, valueToSwitch); - } - result = reindexChoiceMap(result, maxNumber); - int size = result.size(); - if (log.isInfoEnabled()) { - log.info("nbImageChoices (from request) = " + size); - } - logChoice(result); - return result; - } - - protected Map<Integer, VotingList> buildVotingLists(PollType pollType) { - Map<Integer, VotingList> result = Maps.newTreeMap(); - - int maxNumber = 0; - - String votingListPrefix = "votingList" + pollType.name(); - - // get all votingList_xxx parameters - Set<String> votingListParameterNames = Sets.filter( - parameters.keySet(), - new StringStartWithPredicate(votingListPrefix)); - - Pattern votingListPattern = Pattern.compile( - "(" + votingListPrefix + ")_(\\d+)\\.name"); - - for (String paramName : votingListParameterNames) { - - Matcher matcher = votingListPattern.matcher(paramName); - - if (matcher.matches()) { - - // found a voting list name - - int votingListNumber = Integer.valueOf(matcher.group(2)); - - buildVotingList(paramName, - votingListPrefix + "_" + votingListNumber, - votingListNumber, - result - ); - maxNumber = Math.max(maxNumber, votingListNumber); - } - } - - result = reindexMap(result, maxNumber); - - int size = result.size(); - if (log.isInfoEnabled()) { - log.info("nbVotingList [" + pollType + "] (from request) = " + size); - } - - // add personToList maps to session (but just now, since votingList - // could have been reindex) - for (Map.Entry<Integer, VotingList> entry : result.entrySet()) { - VotingList votingList = entry.getValue(); - - if (!votingList.isPollAccountPersonToListEmpty()) { - List<PersonToList> personToList = - votingList.getPollAccountPersonToList(); - - Map<Integer, PersonToList> personToListMap = Maps.newTreeMap(); - int index = 0; - for (PersonToList toList : personToList) { - personToListMap.put(index++, toList); - } - } - } - - return result; - } - - private double getDoubleValue(String parameterName) { - String parameterValue = getNonEmptyParameterValue(parameterName); - double result = 0; - if (StringUtils.isNotEmpty(parameterValue)) { - - try { - result = Double.valueOf(parameterValue); - } catch (NumberFormatException e) { - //bad conversion, will be treated later - if (log.isDebugEnabled()) { - log.debug("Bad double conversion from param [" + - parameterName + "] : " + parameterValue); - } - } - } - return result; - } - - private int getIntegerValue(String parameterName) { - String parameterValue = getNonEmptyParameterValue(parameterName); - int result = 0; - if (StringUtils.isNotEmpty(parameterValue)) { - - try { - result = Integer.valueOf(parameterValue); - } catch (NumberFormatException e) { - //bad conversion, will be treated later - if (log.isDebugEnabled()) { - log.debug("Bad double conversion from param [" + - parameterName + "] : " + parameterValue); - } - } - } - return result; - } - - private int buildVotingList(String votingListParameterName, - String votingListPrefix, - int votingListNumber, - Map<Integer, VotingList> result) { - - String paramValue = getNonEmptyParameterValue(votingListParameterName); - - VotingList votingList = new VotingListImpl(); - - votingList.setName(paramValue); - - double weight = getDoubleValue(votingListPrefix + ".weight"); - votingList.setWeight(weight); - - String topiaId = getNonEmptyParameterValue(votingListPrefix + ".topiaId"); - votingList.setTopiaId(topiaId); - - result.put(votingListNumber, votingList); - - String personToListPrefix = votingListPrefix + "PersonToList_"; - - // get all personToList parameters - Set<String> votingListParameterNames = Sets.filter( - parameters.keySet(), - new StringStartWithPredicate(personToListPrefix)); - - Pattern personToListNamePattern = Pattern.compile( - personToListPrefix + "(\\d+)\\.votingId"); - - Map<Integer, PersonToList> personToLists = Maps.newTreeMap(); - - int maxPersonToListNumber = 0; - - // let's build personToList list - for (String personToListNameParameter : votingListParameterNames) { - - Matcher matcher = personToListNamePattern.matcher( - personToListNameParameter); - - if (matcher.matches()) { - - int personToListNumber = buildPersonToList( - personToListPrefix, - personToListNameParameter, - matcher, - votingListNumber, - personToLists); - - maxPersonToListNumber = Math.max(maxPersonToListNumber, - personToListNumber); - } - } - - personToLists = reindexMap(personToLists, maxPersonToListNumber); - - for (PersonToList personToList : personToLists.values()) { - votingList.addPollAccountPersonToList(personToList); - } - - return votingListNumber; - } - - private int buildPersonToList(String personToListPrefix, - String paramName, - Matcher personToListMatcher, - int votingListNumber, - Map<Integer, PersonToList> result) { - - int personToListNumber = Integer.valueOf(personToListMatcher.group(1)); - - PersonToList personToList = new PersonToListImpl(); - - PollAccount account = new PollAccountImpl(); - personToList.setPollAccount(account); - - account.setVotingId(getNonEmptyParameterValue(paramName)); - - String prefix = personToListPrefix + personToListNumber; - - double weight = getDoubleValue(prefix + ".weight"); - personToList.setWeight(weight); - - String topiaId = getNonEmptyParameterValue(prefix + ".topiaId"); - personToList.setTopiaId(topiaId); - - String email = getNonEmptyParameterValue(prefix + ".email"); - account.setEmail(email); - - String accountId = getNonEmptyParameterValue(prefix + ".accountId"); - account.setAccountId(accountId); - - if (!isPersonToListEmpty(personToList)) { - - // can keep this not empty personToList - result.put(personToListNumber, personToList); - } - return personToListNumber; - } - - private <C extends Choice> C createChoice(C choice, - String prefix, - String name) { - String description = getNonEmptyParameterValue(prefix + ".description"); - String topiaId = getNonEmptyParameterValue(prefix + ".topiaId"); - choice.setName(name); - choice.setDescription(description); - choice.setTopiaId(topiaId); - return choice; - } - - 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()); - } - } - } - - protected <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) { - Map<Integer, T> 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) { - T choice = result.get(number); - result2.put(i++, choice); - } - } else { - result2 = result; - } - return result2; - } - - protected <T> Map<Integer, T> reindexChoiceMap(Map<Integer, T> result, int maxNumber) { - Map<Integer, T> result2 = Maps.newTreeMap(); - - for (Integer choiceOrder : choicesOrder.keySet()) { - Integer choiceNumber = choicesOrder.get(choiceOrder); - T choice = result.get(choiceNumber); - if (choice != null) { - result2.put(choiceOrder, choice); - } - } - -// 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) { -// T choice = result.get(number); -// result2.put(i++, choice); -// } -// } else { -// result2 = result; -// } - return result2; - } - - - protected String getNonEmptyParameterValue(String paramName) { - String[] paramValues = parameters.get(paramName); - String result = null; - if (paramValues != null && paramValues.length == 1) { - String paramValue = paramValues[0]; - if (StringUtils.isNotEmpty(paramValue)) { - result = paramValue; - } - } - return result; - } - - private String getChoiceFieldPrefix(ChoiceType choiceType) { - String result = null; - switch (choiceType) { - - case TEXT: - result = "textChoice_"; - break; - case DATE: - result = "dateChoice_"; - break; - case IMAGE: - result = "imageChoice_"; - break; - } - return result; - } - - private static class StringStartWithPredicate implements Predicate<String> { - private final String prefix; - - public StringStartWithPredicate(String prefix) { - this.prefix = prefix; - } - - @Override - public boolean apply(String input) { - return input.startsWith(prefix); - } - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,104 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.bean.PollUri; -import org.chorem.pollen.ui.actions.PageSkin; -import org.chorem.pollen.ui.actions.PollenActionSupport; -import org.chorem.pollen.ui.converters.PollUriConverter; - -import java.util.Map; - -/** - * Abstract action for all actions with a poll uri id. - * - * @author tchemit <chemit@codelutin.com> - * @author fdesbois <fdesbois@codelutin.com> - * @since 1.3 - */ -public abstract class AbstractPollUriIdAction extends PollenActionSupport { - - public static final String PARAM_POLL_URI = "uriId"; - - public static final String PARAM_POLL_PAGE = "page"; - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AbstractPollUriIdAction.class); - - private PollUri pollUri; - - private int page; - - protected AbstractPollUriIdAction() { - } - - protected AbstractPollUriIdAction(PageSkin skin) { - super(skin); - } - - public final PollUri getUriId() { - return pollUri; - } - - public final void setUriId(PollUri pollUri) { - if (log.isDebugEnabled()) { - log.debug("PollUri : " + pollUri.getUri()); - } - this.pollUri = pollUri; - } - - public final int getPage() { - return page; - } - - public final void setPage(int page) { - if (log.isDebugEnabled()) { - log.debug("Page number : " + page); - } - this.page = page; - } - - public final String getPollId() { - return pollUri == null ? null : pollUri.getPollId(); - } - - public final String getAccountId() { - return pollUri == null ? null : pollUri.getAccountId(); - } - - protected void preparePollUri(Map<String, String[]> parameters) { - if (pollUri == null) { - String[] values = parameters.get(PARAM_POLL_URI); - pollUri = PollUriConverter.convertFromString(values); - } - } - - protected void preparePollUri(String pollId, String accountId) { - pollUri = PollUri.newPollUri(pollId, accountId); - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,565 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Charsets; -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.apache.struts2.interceptor.ParameterAware; -import org.apache.struts2.interceptor.ServletRequestAware; -import org.chorem.pollen.PollenTechnicalException; -import org.chorem.pollen.PollenUserSecurityContext; -import org.chorem.pollen.bean.PollResult; -import org.chorem.pollen.bean.PollResultList; -import org.chorem.pollen.bean.PollUrl; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.business.persistence.Comment; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.business.persistence.PollAccount; -import org.chorem.pollen.business.persistence.PollCommentVisibility; -import org.chorem.pollen.business.persistence.PollVoteVisibility; -import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.business.persistence.Vote; -import org.chorem.pollen.business.persistence.VoteToChoice; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; -import org.chorem.pollen.services.exceptions.PollAccountNotFound; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.ui.PollenUIUtils; -import org.chorem.pollen.ui.actions.PageSkin; -import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; - -import javax.servlet.http.HttpServletRequest; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Abstract action for actions on the vote poll page. - * - * @author tchemit <chemit@codelutin.com> - * @author fdesbois <fdesbois@codelutin.com> - * @since 1.3 - */ -public abstract class AbstractVoteAction extends AbstractPollUriIdAction implements ParameterAware, ServletRequestAware { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractVoteAction.class); - - public static final String PREPARE_VOTE_PAGE = "prepareVotePage"; - - /** - * Loaded poll. - * - * @since 1.3 - */ - private Poll poll; - - /** - * Is feed exists for this poll ? - * - * @since 1.3 - */ - private boolean feedFileExisting; - - /** - * Is user the poll's creator ? - * - * @since 1.3 - */ - private boolean creatorUser; - - /** - * Loaded poll account (from the pollUri). - * - * @since 1.3 - */ - private PollAccount pollAccount; - - /** - * Is vote allowed for current user? - * - * @since 1.3 - */ - private boolean voteAllowed; - - /** - * Is current user can go to results. - * - * @since 1.4 - */ - private boolean resultAllowed; - - /** - * All votes for the poll. - * - * @since 1.3 - */ - private List<Vote> votes; - - /** - * Current vote to treat (for create/updatevote action). - * - * @since 1.3 - */ - private Vote vote; - - /** - * Comment author to display in UI. - * - * @since 1.3 - */ - private String commentAuthor; - - /** - * Results of the poll. - * - * @since 1.3 - */ - private List<PollResult> results; - - /** - * List of comments to display. - * - * @since 1.3 - */ - private List<Comment> comments; - - /** - * Injected parameters from request. - * - * @since 1.3 - */ - private Map<String, String[]> parameters; - -// /** -// * The accountId role on this page. -// * -// * @since 1.4 -// */ -// private SecurityService.PollenUserSecurityRole accountIdRole; - - /** - * The user security context for this request. - * - * @since 1.4.5 - */ - private PollenUserSecurityContext securityContext; - - /** - * The incoming request (some stuff are store in it from security filters). - * - * @since 1.4 - */ - private transient HttpServletRequest request; - - protected AbstractVoteAction() { - super(PageSkin.VOTE); - } - - /** - * @return {@code true} if moderation is possible, {@code false} otherwise - * @since 1.4 - */ - public abstract boolean isModerate(); - - @Override - public void setParameters(Map<String, String[]> parameters) { - this.parameters = parameters; - } - - @Override - public void setServletRequest(HttpServletRequest request) { - this.request = request; - } - - public Poll getPoll() { - return poll; - } - - public PollAccount getPollAccount() { - return pollAccount; - } - - public List<Vote> getVotes() { - return votes; - } - - public Vote getVote() { - return vote; - } - - public List<PollResult> getResults() { - return results; - } - - public List<Comment> getComments() { - return comments; - } - - public String getCreatorName() { - return poll.getCreator().getVotingId(); - } - - public String getVoteSizeMessage() { - String result = PollenUIUtils.getVoteSizeMessage(getPoll(), - getLocale()); - return result; - } - - public String getVoteCountingTypeName() { - VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); - String result = strategy.getStrategyName(getLocale()); - return result; - } - - public String getVoteCountingTypeHelp() { - VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); - String result = strategy.getStrategyHelp(getLocale()); - return result; - } - - /** - * Is comment can be displayed (and then added) on this poll. - * - * @return {@code true} if comments can be displayed and then added or - * removed for this poll. - * @since 1.4.5 - */ - public boolean isCommentAllowed() { - PollCommentVisibility pollCommentVisibility = - getPoll().getPollCommentVisibility(); - return pollCommentVisibility == PollCommentVisibility.EVERYBODY; - } - - /** - * Retourne si le choix fait partie du vote (s'il a été renseigné par le - * votant). - * - * @param choice le choix concerné - * @return true si le choix est dans le vote - */ - public boolean isChoiceInVote(VoteToChoice choice) { - VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); - boolean result = strategy.isChoiceInVote(choice.getVoteValue()); - return result; -// Integer voteValue = choice.getVoteValue(); -// boolean result = false; -// if (choice != null) { -// switch (poll.getVoteCountingType()) { -// case NORMAL: -// result = voteValue > 0; -// break; -// case PERCENTAGE: -// result = true; -// break; -// case CONDORCET: -// result = voteValue < 100; -// break; -// case NUMBER: -// result = voteValue >= 0; -// } -// } -// return result; - } - - public String getChoiceValue(VoteToChoice choice) { - VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); - String result = strategy.getDisplayVoteValue(choice.getVoteValue()); - return result; -// switch (poll.getVoteCountingType()) { -// case NORMAL: -// result = "OK"; -// break; -// default: -// result = choice.getVoteValue() + ""; -// } -// return result; - } - - public String getCommentAuthor() { - if (commentAuthor == null) { - - UserAccount user = getPollenUserAccount(); - if (user == null) { - - // Use current pollAccount name for comment - commentAuthor = getPollAccount().getVotingId(); - - } else { - - // Connecter user name - commentAuthor = user.getDisplayName(); - } - } - return commentAuthor; - } - - public String getSummaryUrl() { - PollUrl url = getPollUrlService().getPollSummaryUrl(poll); - url.getPollUri().setAccountId(getAccountId()); - return url.getUrl(); - } - - public String getResultUrl() { - PollUrl url = getPollUrlService().getPollResultUrl(poll); - url.getPollUri().setAccountId(getAccountId()); - securityContext.removeAccountIdWhenConnected(url); - return url.getUrl(); - } - - public String getVoteMessages() { - return _("pollen.common.voteNbVotes", poll.sizeVote()); - } - - public boolean isFeedFileExisting() { - return feedFileExisting; - } - - public boolean isCreatorOrAdmin() { - return creatorUser || isUserAdmin(); - } - - public boolean isAccountFieldDisplayed() { - return !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll(); - } - - public boolean isPollChoiceOrVoteStarted() { - Date now = serviceContext.getCurrentTime(); - return poll.isAddChoiceStarted(now) || poll.isStarted(now); - } - - public boolean isAnonymousVote() { - PollVoteVisibility pollVoteVisibility = poll.getPollVoteVisibility(); - return pollVoteVisibility == PollVoteVisibility.NOBODY; - } - - public boolean isPollChoiceRunning() { - Date now = serviceContext.getCurrentTime(); - return poll.isAddChoiceRunning(now); - } - - public boolean isPollStarted() { - Date now = serviceContext.getCurrentTime(); - return poll.getBeginDate() == null || poll.getBeginDate().before(now); - } - - public boolean isPollFinished() { - Date now = serviceContext.getCurrentTime(); - return poll.getEndDate() != null && poll.getEndDate().before(now); - } - - public boolean isDescNull(Choice choice) { - return StringUtils.isEmpty(choice.getDescription()); - } - - public boolean isFreePoll() { - return poll.isPollFree(); - } - - public boolean isRestrictedPoll() { - return poll.getPollType() == PollType.RESTRICTED; - } - - public boolean isGroupPoll() { - return poll.getPollType() == PollType.GROUP; - } - - public boolean isTextType() { - return poll.getChoiceType() == ChoiceType.TEXT; - } - - public boolean isDateType() { - return poll.getChoiceType() == ChoiceType.DATE; - } - - public boolean isImageType() { - return poll.getChoiceType() == ChoiceType.IMAGE; - } - - public boolean isVoteAllowed() { - return voteAllowed; - } - - public boolean isResultAllowed() { - return resultAllowed; - } - - public boolean isModifyVoteAllowed(Vote vote) { - return getSecurityService().isCanModifyVote(securityContext, - vote.getTopiaId()); - } - - public boolean isDeleteCommentAllowed(Comment comment) { - return getSecurityService().isCanDeleteComment(securityContext, - comment); - } - - public boolean isDeleteVoteAllowed(Vote vote) { - return getSecurityService().isCanDeleteVote(securityContext, - vote.getTopiaId()); - } - - public String getResultValue(Choice choice) { - - String val = getPollResultsService().getResultValue(choice, results); - return val; - } - - public String getChoiceFragment() { - VoteCountingStrategy strategy = getVoteCountingStrategy(poll); - String result = - "displayVote_" + strategy.getVoteValueEditorType().name() + ".jsp"; - return result; - } - - public Date getChoiceAsDate(Choice choice) { - return new Date(Long.valueOf(choice.getName())); - } - - public void setCommentAuthor(String commentAuthor) { - this.commentAuthor = commentAuthor; - } - - public String prepareVotePage() throws Exception { - - securityContext = PollenUIUtils.getUserSecuritycontext(request); - - boolean moderate = isModerate(); - - loadPoll(); - - // Current poll account - loadPollAccount(); - - // All votes - // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount - votes = getVoteService().getAllVotes(poll); - - // is vote allowed ? - if (moderate) { - - // while moderate vote, no way to vote - voteAllowed = false; - - } else { -// String accountId = getAccountId(); -// if (accountIdRole == SecurityService.PollenUserSecurityRole.CREATOR) { -// -// // remove accountId (can vote even if creator ?) -// accountId = null; -// } - voteAllowed = getSecurityService().isCanVote(securityContext); - } - - // is can display result link ? - resultAllowed = getSecurityService().isCanAccessResult(securityContext); - - if (voteAllowed) { - - // load modifiable vote - vote = getVoteService().getVoteEditable(poll, pollAccount); - } - - // load poll results - PollResultList pollResultList = - getPollResultsService().getResults(poll); - - results = pollResultList.getPollResults(); - - if (log.isDebugEnabled()) { - for (PollResult res : results) { - log.debug(res.getName() + ": " + res.getValue() - + ", (voteCounting=" + res.getVoteCountingType() - + ", byGroup=" + res.isByGroup() + ")"); - } - } - - // load comments - comments = getPollCommentService().getAllComments(poll.getPollId()); - - feedFileExisting = getPollFeedService().isFeedExists(poll); - -// creatorUser = getSecurityService().isPollCreator(poll, -// getAccountId(), -// getPollenUserAccount()); - - creatorUser = securityContext.isCreator(); - - if (log.isInfoEnabled()) { - Date now = serviceContext.getCurrentTime(); - log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted()); - log.info("pollChoiceRunning = " + isPollChoiceRunning()); - log.info("pollRunning = " + poll.isRunning(now)); - log.info("accountFieldDisplayed = " + isAccountFieldDisplayed()); - log.info("creatorUser = " + creatorUser); - } - return INPUT; - } - - public String escapeLineBreak(String text) { - return text; - } - - public String getImageChoiceName(Choice choice) { - String name = choice.getName(); - try { - String result = URLEncoder.encode(name, Charsets.UTF_8.name()); - return result; - } catch (UnsupportedEncodingException e) { - throw new PollenTechnicalException( - "Could not encode name " + name, e); - } - } - - protected void loadPollAccount() throws PollAccountNotFound { - - // Current poll account - pollAccount = getPollService().getPollAccountEditable( - getAccountId(), getPollenUserAccount(), poll); - } - - protected void loadPoll() throws PollNotFoundException { - - // Ensure uri for poll and pollAccount loading - preparePollUri(parameters); - - String pollId = getPollId(); - if (StringUtils.isNotEmpty(pollId)) { - poll = getPollService().getExistingPollByPollId(pollId); - } - Preconditions.checkNotNull(poll, - "Can't load poll with id = [" + pollId + "]"); - - if (log.isDebugEnabled()) { - log.debug("Poll TopiaId: " + poll.getTopiaId()); - } - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,138 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.opensymphony.xwork2.Preparable; -import com.opensymphony.xwork2.interceptor.annotations.InputConfig; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.bean.PollImageChoice; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.services.PollenServiceFunctions; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.ui.actions.FileUploadAware; - -import java.io.File; - -/** - * To add a poll comment. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class AddChoice extends AbstractVoteAction implements Preparable, FileUploadAware { - - private static final long serialVersionUID = 1L; - - protected Choice choice; - - private File imageChoice; - - private String imageChoiceContentType; - - private String imageChoiceFileName; - - public Choice getChoice() { - return choice; - } - - @Override - public void addFile(int index, File file) { - imageChoice = file; - } - - @Override - public void addFileContentType(int index, String contentType) { - imageChoiceContentType = contentType; - } - - @Override - public void addFileName(int index, String fileName) { - imageChoiceFileName = fileName; - } - - @Override - public boolean isModerate() { - return false; - } - - @Override - public void prepare() throws PollNotFoundException { - - loadPoll(); - - ChoiceType choiceType = getPoll().getChoiceType(); - choice = getPollService().getNewChoice(choiceType); - - // Push image choice data from uploaded file - if (ChoiceType.IMAGE == choiceType && imageChoice != null) { - - String fileName = imageChoiceFileName; - String location = imageChoice.getAbsolutePath(); - choice.setName(fileName); - ((PollImageChoice) choice).setLocation(location); - } - } - - @Override - public void validate() { - - ChoiceType choiceType = getPoll().getChoiceType(); - - String propName = PollenServiceFunctions.CHOICE_TYPE_TO_PROPERTY_NAME.apply(choiceType); - - String choiceName = choice.getName(); - - // -- Validate value notEmpty - if (StringUtils.isBlank(choiceName)) { - String typeLabel = getText(choiceType.getI18nKey()); - addFieldError("choice." + propName, - _("pollen.error.choice.empty", typeLabel)); - } else { - - if (!getPoll().isChoiceEmpty()) { - - // check that the choice is not already used - - for (Choice pollChoice : getPoll().getChoice()) { - String pollChoiceName = pollChoice.getName(); - if (pollChoiceName.equals(choiceName)) { - addFieldError("choice." + propName, - _("pollen.error.poll.choice.already.used.name")); - break; - } - } - } - } - } - - @InputConfig(methodName = PREPARE_VOTE_PAGE) - @Override - public String execute() throws Exception { - - getPollService().addChoice(getPollId(), choice); - - return SUCCESS; - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,93 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.opensymphony.xwork2.Preparable; -import com.opensymphony.xwork2.interceptor.annotations.InputConfig; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.business.persistence.Comment; - -/** - * To add a poll comment. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class AddComment extends AbstractVoteAction implements Preparable { - - private static final long serialVersionUID = 1L; - - /** - * Text of the comment to add. - * - * @since 1.3 - */ - private String commentText; - - public void setCommentText(String commentText) { - this.commentText = commentText; - } - - public String getCommentText() { - return commentText; - } - - @Override - public boolean isModerate() { - return false; - } - - @Override - public void prepare() throws Exception { - - loadPoll(); - loadPollAccount(); - } - - @Override - public void validate() { - - if (StringUtils.isBlank(getCommentAuthor())) { - addFieldError("commentAuthor", _("pollen.error.comment.name.empty")); - } - - if (StringUtils.isBlank(getCommentText())) { - addFieldError("commentText", _("pollen.error.comment.text.empty")); - } - } - - @InputConfig(methodName = PREPARE_VOTE_PAGE) - @Override - public String execute() throws Exception { - - // prepare a new comment - Comment comment = getPollCommentService().getNewComment( - getPollAccount(), getCommentAuthor(), getCommentText()); - - // create the comment - getPollCommentService().createComment(getPoll(), comment); - - addFlashMessage(_("pollen.information.comment.added")); - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,54 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.business.persistence.Poll; - -/** - * Clones a poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class ClonePoll extends AbstractPollForm { - - private static final long serialVersionUID = 1L; - - @Override - public boolean isClone() { - return true; - } - - @Override - public boolean isEdit() { - return false; - } - - @Override - protected Poll savePoll(Poll poll) { - poll = getPollService().createPoll(poll); - addFlashMessage(_("pollen.information.poll.created", poll.getTitle())); - return poll; - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,65 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.business.persistence.Poll; - -/** - * Closes an existing poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ClosePoll extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - /** - * Redirect url. - * - * @since 1.3 - */ - protected String redirectUrl; - - public String getRedirectUrl() { - return redirectUrl; - } - - public void setRedirectUrl(String redirectUrl) { - this.redirectUrl = redirectUrl; - } - - @Override - public String execute() throws Exception { - - Poll poll = getPollService().getExistingPollByPollId(getPollId()); - - getPollService().closePoll(getPollId(), - getPollenUserAccount(), - getAccountId()); - - addFlashMessage(_("pollen.information.poll.closed", poll.getTitle())); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,64 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Choice; -import org.chorem.pollen.business.persistence.Poll; - -/** - * To confirm delete of a poll choice. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ConfirmDeleteChoice extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - protected String choiceId; - - protected Choice choice; - - public void setChoiceId(String choiceId) { - this.choiceId = choiceId; - } - - public Choice getChoice() { - return choice; - } - - @Override - public String execute() throws Exception { - - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(choiceId); - - Poll poll = getPollService().getExistingPollByPollId(pollId); - - choice = poll.getChoiceByTopiaId(choiceId); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,73 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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; - -/** - * To confirm a comment delete. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ConfirmDeleteComment extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - /** - * Id of the comment. - * - * @since 1.3 - */ - protected String commentId; - - /** - * Loaded comment to delete. - * - * @since 1.3 - */ - protected Comment comment; - - public void setCommentId(String commentId) { - this.commentId = commentId; - } - - public Comment getComment() { - return comment; - } - - @Override - public String execute() throws Exception { - - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(commentId); - - getPollService().getExistingPollByPollId(pollId); - - comment = getPollCommentService().getExistingPollComment(commentId); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,74 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Poll; -import org.chorem.pollen.business.persistence.Vote; - -/** - * To confirm delete of a poll vote - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ConfirmDeleteVote extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - /** - * Id of the vote to delete. - * - * @since 1.3 - */ - protected String voteId; - - /** - * Loaded vote to delete. - * - * @since 1.3 - */ - protected Vote vote; - - public void setVoteId(String voteId) { - this.voteId = voteId; - } - - public Vote getVote() { - return vote; - } - - @Override - public String execute() throws Exception { - - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(voteId); - - Poll poll = getPollService().getExistingPollByPollId(pollId); - - vote = poll.getVoteByTopiaId(voteId); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,62 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Poll; - -/** - * To confirm a poll action (such as delete or close). - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ConfirmPollAction extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - protected Poll poll; - - protected String redirectUrl; - - public String getRedirectUrl() { - return redirectUrl; - } - - public void setRedirectUrl(String redirectUrl) { - this.redirectUrl = redirectUrl; - } - - public Poll getPoll() { - return poll; - } - - @Override - public String execute() throws Exception { - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - - poll = getPollService().getExistingPollByPollId(pollId); - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,54 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.business.persistence.Poll; - -/** - * Creates a poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class CreatePoll extends AbstractPollForm { - - private static final long serialVersionUID = 1L; - - @Override - public boolean isClone() { - return false; - } - - @Override - public boolean isEdit() { - return false; - } - - @Override - protected Poll savePoll(Poll poll) { - poll = getPollService().createPoll(poll); - addFlashMessage(_("pollen.information.poll.created", poll.getTitle())); - return poll; - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,55 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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; - -/** - * To delete a poll choice - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DeleteChoice extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - protected String choiceId; - - public void setChoiceId(String choiceId) { - this.choiceId = choiceId; - } - - @Override - public String execute() throws Exception { - - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(choiceId); - - getPollService().deleteChoice(pollId, choiceId); - - addFlashMessage(_("pollen.information.choice.deleted")); - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,80 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.opensymphony.xwork2.interceptor.annotations.InputConfig; -import org.chorem.pollen.business.persistence.Poll; - -/** - * To delete a poll comment. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DeleteComment extends AbstractVoteAction { - - private static final long serialVersionUID = 1L; - - /** - * Id of the comment to delete. - * - * @since 1.3 - */ - protected String commentId; - - /** - * Reason for deleting this comment (if any). - * - * @since 1.4 - */ - protected String reason; - - public void setCommentId(String commentId) { - this.commentId = commentId; - } - - public void setReason(String reason) { - this.reason = reason; - } - - @Override - public boolean isModerate() { - return false; - } - - @InputConfig(methodName = PREPARE_VOTE_PAGE) - @Override - public String execute() throws Exception { - - Preconditions.checkNotNull(getPollId()); - Preconditions.checkNotNull(commentId); - - Poll poll = getPollService().getExistingPollByPollId(getPollId()); - - getPollCommentService().deleteComment(poll, commentId, reason); - - addFlashMessage(_("pollen.information.comment.deleted")); - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,56 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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; - -/** - * Deletes an existing poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DeletePoll extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - protected String redirectUrl; - - public String getRedirectUrl() { - return redirectUrl; - } - - public void setRedirectUrl(String redirectUrl) { - this.redirectUrl = redirectUrl; - } - - @Override - public String execute() throws Exception { - - - getPollService().deletePoll(getPollId(), - getPollenUserAccount(), - getAccountId()); - return SUCCESS; - } - - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,81 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Poll; - -/** - * To delete a poll vote. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DeleteVote extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - /** - * Id of the vote to delete. - * - * @since 1.3 - */ - protected String voteId; - - /** - * Reason for deleting this vote (if any). - * - * @since 1.4 - */ - protected String reason; - - public void setVoteId(String voteId) { - this.voteId = voteId; - } - - public void setReason(String reason) { - this.reason = reason; - } - - @Override - public String execute() throws Exception { - - Preconditions.checkNotNull(getPollId()); - Preconditions.checkNotNull(voteId); - - Poll poll = getPollService().getExistingPollByPollId(getPollId()); - - getVoteService().deleteVote(poll, voteId, reason); - - addFlashMessage(_("pollen.information.vote.deleted")); - - if (poll.isPollFree() && - getUriId().isAccountIdNotBlank() && - !poll.getCreator().getAccountId().equals(getAccountId())) { - - // remove accountId from url, voter does no longer exists. - getUriId().setAccountId(null); - } - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,47 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.bean.PollDateChoice; - -/** - * To generate the display for a date choice. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DisplayDateChoice extends AbstractDisplayChoice { - - private static final long serialVersionUID = 1L; - - public static final String CHOICE_TOKEN = "dateChoice"; - - @Override - protected PollDateChoice createEmptyChoice() { - PollDateChoice result = new PollDateChoice(); - result.setName(""); - result.setDescription(""); - result.setDate(null); - return result; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayImageChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayImageChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayImageChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,48 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.bean.PollImageChoice; -import org.chorem.pollen.business.persistence.Choice; - -/** - * To generate the display for a image choice. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DisplayImageChoice extends AbstractDisplayChoice { - - private static final long serialVersionUID = 1L; - - public static final String CHOICE_TOKEN = "imageChoice"; - - @Override - protected Choice createEmptyChoice() { - PollImageChoice result = new PollImageChoice(); - result.setName(""); - result.setDescription(""); - result.setLocation(""); - return result; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,109 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.persistence.PersonToList; -import org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * To display a personToList (use at a poll creation). - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DisplayPersonToList extends PollenActionSupport { - - private static final long serialVersionUID = 1L; - - public static final String TOKEN = "personToList"; - - /** Logger. */ - private static final Log log = LogFactory.getLog(DisplayPersonToList.class); - - public static String getPersonToListTokenId(String votingListTokenId, - int votingListNumber) { - return votingListTokenId + "_" + votingListNumber + TOKEN; - } - - public static String getPersonToListErrorTokenId(String votingListTokenId, - int votingListNumber, - int personToListNumber) { - return getPersonToListErrorTokenId(getPersonToListTokenId(votingListTokenId, votingListNumber), personToListNumber); - } - - public static String getPersonToListErrorTokenId(String personToListTokenId, - int personToListNumber) { - return personToListTokenId + "_error_" + personToListNumber; - } - - /** Type of the voting list. */ - protected String votingListType; - - /** Number of the vontingList container. */ - protected int votingListNumber; - - /** Number of person to display. */ - protected int personToListNumber; - - protected PersonToList personToList; - - public int getVotingListNumber() { - return votingListNumber; - } - - public void setVotingListNumber(int votingListNumber) { - this.votingListNumber = votingListNumber; - } - - public String getVotingListType() { - return votingListType; - } - - public void setVotingListType(String votingListType) { - this.votingListType = votingListType; - } - - public int getPersonToListNumber() { - return personToListNumber; - } - - public void setPersonToListNumber(int personToListNumber) { - this.personToListNumber = personToListNumber; - } - - public PersonToList getPersonToList() { - return personToList; - } - - @Override - public String execute() throws Exception { - - if (personToList == null) { - personToList = getPollService().getNewPersonToList(null); - } - return SUCCESS; - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayTextChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayTextChoice.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayTextChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,47 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.business.persistence.Choice; -import org.chorem.pollen.business.persistence.ChoiceImpl; - -/** - * To generate the display for a text choice. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DisplayTextChoice extends AbstractDisplayChoice { - - private static final long serialVersionUID = 1L; - - public static final String CHOICE_TOKEN = "textChoice"; - - @Override - protected Choice createEmptyChoice() { - Choice result = new ChoiceImpl(); - result.setName(""); - result.setDescription(""); - return result; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,88 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Function; -import org.chorem.pollen.business.persistence.PersonToList; -import org.chorem.pollen.business.persistence.VotingList; -import org.chorem.pollen.services.PollenServiceFunctions; -import org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * To display a voting list of a poll (use at a poll creation). - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class DisplayVotingList extends PollenActionSupport { - - private static final long serialVersionUID = 1L; - - /** Type of the voting list. */ - protected String votingListType; - - /** Number of person to display. */ - protected int votingListNumber; - - /** The voting list ot display. */ - protected VotingList votingList; - - public int getVotingListNumber() { - return votingListNumber; - } - - public void setVotingListNumber(int votingListNumber) { - this.votingListNumber = votingListNumber; - } - - public VotingList getVotingList() { - return votingList; - } - - public String getVotingListType() { - return votingListType; - } - - public void setVotingListType(String votingListType) { - this.votingListType = votingListType; - } - - public int getStartNumber() { - return 0; - } - - @Override - public String execute() throws Exception { - - Function<PersonToList, PersonToList> persontoListCreator = - PollenServiceFunctions.newPersonToListCreator(); - Function<VotingList, VotingList> votingListCreator = - PollenServiceFunctions.newVotingListCreator(persontoListCreator); - - votingList = votingListCreator.apply(null); - - PollenServiceFunctions.fillVotingList(votingList, - persontoListCreator, 5); - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,58 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.business.persistence.Poll; -import org.chorem.pollen.services.exceptions.PollNotFoundException; - -/** - * Edit a poll (load it via {@link #input()}), and save it - * via {@link #execute()}). - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class EditPoll extends AbstractPollForm { - - private static final long serialVersionUID = 1L; - - @Override - public boolean isClone() { - - // in edit mode never can be a clone - return false; - } - - @Override - public boolean isEdit() { - return true; - } - - @Override - protected Poll savePoll(Poll poll) throws PollNotFoundException { - poll = getPollService().updatePoll(poll); - addFlashMessage(_("pollen.information.poll.updated", poll.getTitle())); - return poll; - } - -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,55 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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; - -/** - * EditVote is a redirection to vote page. This action will simply update the - * uri with {@code accountId} and {@code pollId}. - * - * @author fdesbois <fdesbois@codelutin.com> - * @since 1.3 - */ -public class EditVote extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - private String accountId; - - private String pollId; - - public void setAccountId(String accountId) { - this.accountId = accountId; - } - - public void setPollId(String pollId) { - this.pollId = pollId; - } - - @Override - public String execute() throws Exception { - - preparePollUri(pollId, accountId); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,74 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.apache.commons.io.IOUtils; - -import java.io.InputStream; - -/** - * Exports an existing poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ExportPoll extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - protected String filename; - - protected long contentLength; - - protected transient InputStream inputStream; - - public long getContentLength() { - return contentLength; - } - - public InputStream getInputStream() { - return inputStream; - } - - public String getFilename() { - return filename; - } - - @Override - public String execute() throws Exception { - - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - - String exportContent = getPollResultsService().exportPolltoXml(pollId); - - filename = "exportPoll-" + pollId + ".xml"; - - contentLength = exportContent.length() * 2; - - inputStream = IOUtils.toInputStream(exportContent); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,113 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.Function; -import org.chorem.pollen.business.persistence.PersonList; -import org.chorem.pollen.business.persistence.PersonToList; -import org.chorem.pollen.business.persistence.PollAccount; -import org.chorem.pollen.business.persistence.VotingList; -import org.chorem.pollen.services.PollenServiceFunctions; -import org.chorem.pollen.services.impl.PollService; -import org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Load in session a personToList to import into a votingList. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ImportPersonListToVotingList extends PollenActionSupport { - - private static final long serialVersionUID = 1L; - - /** Type of the voting list. */ - protected String votingListType; - - /** Number of person to display. */ - protected int votingListNumber; - - /** The voting list ot display. */ - protected VotingList votingList; - - protected int startNumber; - - protected String personListId; - - public int getVotingListNumber() { - return votingListNumber; - } - - public int getStartNumber() { - return startNumber; - } - - public String getVotingListType() { - return votingListType; - } - - public VotingList getVotingList() { - return votingList; - } - - public void setVotingListNumber(int votingListNumber) { - this.votingListNumber = votingListNumber; - } - - public void setVotingListType(String votingListType) { - this.votingListType = votingListType; - } - - public void setStartNumber(int startNumber) { - this.startNumber = startNumber; - } - - public void setPersonListId(String personListId) { - this.personListId = personListId; - } - - @Override - public String execute() throws Exception { - - PersonList favoriteList = - getFavoriteService().getFavoriteList(getPollenUserAccount(), personListId); - - Function<PersonToList, PersonToList> persontoListCreator = - PollenServiceFunctions.newPersonToListCreator(); - - Function<VotingList, VotingList> votingListCreator = - PollenServiceFunctions.newVotingListCreator(persontoListCreator); - - votingList = votingListCreator.apply(null); - - PollService pollService = getPollService(); - - for (PollAccount pollAccount : favoriteList.getPollAccount()) { - - PersonToList p = pollService.getNewPersonToList(pollAccount); - votingList.addPollAccountPersonToList(p); - } - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,48 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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; - -/** - * To moderate votes and comment of a given poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class ModeratePoll extends AbstractVoteAction { - - private static final long serialVersionUID = 1L; - - @Override - public String input() throws Exception { - - prepareVotePage(); - - addFlashWarning(_("pollen.information.moderate.page")); - return INPUT; - } - - @Override - public boolean isModerate() { - return true; - } -} Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -22,7 +22,6 @@ */ package org.chorem.pollen.ui.actions.poll; -import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Lists; @@ -30,25 +29,27 @@ import com.google.common.collect.Multimap; import com.opensymphony.xwork2.inject.Inject; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.views.util.UrlHelper; -import org.chorem.pollen.PollenUserSecurityContext; import org.chorem.pollen.bean.PollResult; import org.chorem.pollen.bean.PollResultList; import org.chorem.pollen.bean.PollUrl; import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; import org.chorem.pollen.services.impl.PollResultsService; import org.chorem.pollen.ui.PollenUIUtils; import org.chorem.pollen.ui.actions.PageSkin; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; import org.chorem.pollen.ui.converters.DateConverter; import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; import org.nuiton.util.StringUtil; -import javax.servlet.http.HttpServletRequest; import java.net.URL; import java.util.Date; import java.util.List; @@ -61,7 +62,7 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class ResultForPoll extends AbstractPollUriIdAction implements ServletRequestAware { +public class ResultForPoll extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { private static final long serialVersionUID = 1L; @@ -134,20 +135,6 @@ @Inject(required = true) private UrlHelper urlHelper; - /** - * The user security context for this request. - * - * @since 1.4.5 - */ - private PollenUserSecurityContext securityContext; - - /** - * The incoming request (some stuff are store in it from security filters). - * - * @since 1.4.5 - */ - private transient HttpServletRequest request; - public ResultForPoll() { super(PageSkin.RESULT); } @@ -178,13 +165,13 @@ public String getSummaryUrl() { PollUrl url = getPollUrlService().getPollSummaryUrl(poll); - url.getPollUri().setAccountId(getAccountId()); + url.getPollUri().setAccountId(getUserSecurityContext().getAccountId()); return url.getUrl(); } public String getResultUrl(boolean byGroup) { PollUrl url = getPollUrlService().getPollResultUrl(poll); - url.getPollUri().setAccountId(getAccountId()); + url.getPollUri().setAccountId(getUserSecurityContext().getAccountId()); String result = url.getUrl(); if (!byGroup) { result += "?byGroup=false"; @@ -194,12 +181,12 @@ public String getVoteUrl() { PollUrl url = getPollUrlService().getPollVoteUrl(poll); - url.getPollUri().setAccountId(getAccountId()); + url.getPollUri().setAccountId(getUserSecurityContext().getAccountId()); if (poll.isPollFree()) { // can removed accountId only for free poll //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given - securityContext.removeAccountIdWhenConnected(url); + getUserSecurityContext().removeAccountIdWhenConnected(url); } return url.getUrl(); } @@ -208,6 +195,32 @@ return results; } + public String getPollCreatorName() { + PollAccount creator = poll.getCreator(); + String result = creator.getVotingId(); + if (StringUtils.isBlank(result)) { + result = creator.getEmail(); + } + if (StringUtils.isBlank(result)) { + result = _("pollen.common.undefined"); + } + return result; + } + + public String getPollBeginDate() { + Date date = poll.getBeginDate(); + String result = date == null ? _("pollen.common.undefined") : + getPollService().decorateDate(date); + return result; + } + + public String getPollEndDate() { + Date date = poll.getEndDate(); + String result = date == null ? _("pollen.common.undefined") : + getPollService().decorateDate(date); + return result; + } + public Date getResultAsDate(PollResult result) { Date date = new Date(Long.valueOf(result.getName())); return date; @@ -264,15 +277,8 @@ @Override public String execute() throws Exception { + poll = getUserSecurityContext().getPoll(); - securityContext = PollenUIUtils.getUserSecuritycontext(request); - - String pollId = getPollId(); - Preconditions.checkNotNull(pollId); - -// poll = getPollService().getExistingPollByPollId(pollId); - poll = securityContext.getPoll(); - feedFileExisting = getPollFeedService().isFeedExists(poll); if (byGroup == null) { @@ -281,12 +287,8 @@ byGroup = isGroupPoll(); } - creatorUser = securityContext.isCreator(); + creatorUser = getUserSecurityContext().isCreator(); -// creatorUser = getSecurityService().isPollCreator( -// poll, -// getAccountId(), getPollenUserAccount()); - if (poll.isRunning(serviceContext.getCurrentTime())) { addFlashWarning(_("pollen.information.pollRunning")); } @@ -438,8 +440,4 @@ return StringUtil.join(choices, ",", true); } - @Override - public void setServletRequest(HttpServletRequest request) { - this.request = request; - } } Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,91 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.collect.Maps; -import org.chorem.pollen.PollenFunctions; -import org.chorem.pollen.business.persistence.PersonList; -import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.ui.actions.PollenActionSupport; - -import java.util.List; -import java.util.Map; - -/** - * Select a person list to add into an existing voting list. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class SelectPersonListToVotingList extends PollenActionSupport { - - private static final long serialVersionUID = 1L; - - protected String votingListType; - - protected int votingListNumber; - - protected String containerId; - - protected Map<String, PersonList> personList; - - public Map<String, PersonList> getPersonList() { - return personList; - } - - public int getVotingListNumber() { - return votingListNumber; - } - - public void setVotingListNumber(int votingListNumber) { - this.votingListNumber = votingListNumber; - } - - public String getVotingListType() { - return votingListType; - } - - public void setVotingListType(String votingListType) { - this.votingListType = votingListType; - } - - public String getContainerId() { - return containerId; - } - - public void setContainerId(String containerId) { - this.containerId = containerId; - } - - @Override - public String execute() throws Exception { - - UserAccount userAccount = getPollenUserAccount(); - List<PersonList> personLists = - getFavoriteService().getFavoriteLists(userAccount); - - personList = Maps.uniqueIndex(personLists, PollenFunctions.ENTITY_BY_ID); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,172 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.apache.struts2.interceptor.ServletRequestAware; -import org.chorem.pollen.PollenUserSecurityContext; -import org.chorem.pollen.bean.PollUrl; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.ui.PollenUIUtils; -import org.chorem.pollen.ui.actions.PageSkin; - -import javax.servlet.http.HttpServletRequest; - -/** - * Action to display summary of a poll for his creator (or an admin). - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class SummaryPoll extends AbstractPollUriIdAction implements ServletRequestAware { - - private static final long serialVersionUID = 1L; - - /** - * Loaded poll. - * - * @since 1.4 - */ - private Poll poll; - - /** - * The user security context for this request. - * - * @since 1.4.5 - */ - private PollenUserSecurityContext securityContext; - - /** - * The incoming request (some stuff are store in it from security filters). - * - * @since 1.4 - */ - private transient HttpServletRequest request; - - public SummaryPoll() { - super(PageSkin.EDITION); - } - - @Override - public void setServletRequest(HttpServletRequest request) { - this.request = request; - } - - public Poll getPoll() { - return securityContext.getPoll(); - } - - public String getVoteUrl() { - PollUrl url = getPollUrlService().getPollVoteUrl(poll); - if (poll.isPollFree()) { - - // can removed accountId only for free poll - //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given - securityContext.removeAccountIdWhenConnected(url); - } - return url.getUrl(); - } - - public String getShowVoteUrl() { - PollUrl url = getPollUrlService().getPollVoteUrl(poll); - if (poll.isPollFree()) { - - // can removed accountId only for free poll - //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given - securityContext.removeAccountIdWhenConnected(url); - } - return url.getUrl(); - } - - public String getModerateUrl() { - PollUrl url = getPollUrlService().getPollModerateUrl(poll); - securityContext.removeAccountIdWhenConnected(url); - return url.getUrl(); - } - - public String getEditUrl() { - PollUrl url = getPollUrlService().getPollEditUrl(poll); - securityContext.removeAccountIdWhenConnected(url); - return url.getUrl(); - } - - public String getCloneUrl() { - PollUrl url = getPollUrlService().getPollCloneUrl(poll); - securityContext.removeAccountIdWhenConnected(url); - return url.getUrl(); - } - - public String getExportUrl() { - PollUrl url = getPollUrlService().getPollExportUrl(poll); - securityContext.removeAccountIdWhenConnected(url); - return url.getUrl(); - } - - public String getResultUrl() { - PollUrl url = getPollUrlService().getPollResultUrl(poll); - securityContext.removeAccountIdWhenConnected(url); - return url.getUrl(); - } - - public boolean isCanClose() { - return getSecurityService().isCanClosePoll(securityContext); - } - - public boolean isCanShowVote() { - return poll.isPublicResults() && !isCanVote(); - } - - public boolean isCanShowResult() { - boolean result = getSecurityService().isCanAccessResult(securityContext); - return result; - } - - public boolean isCanVote() { -// String accountId = getAccountId(); -// if (accountIdRole == SecurityService.PollenUserSecurityRole.CREATOR) { -// -// if (poll.getPollType() != PollType.FREE) { -// -// } else { -// accountId = null; -// } -// } - return getSecurityService().isCanVote(securityContext); - } - - @Override - public String execute() throws Exception { - -// Preconditions.checkNotNull(getUriId()); - -// String pollId = getUriId().getPollId(); - - securityContext = PollenUIUtils.getUserSecuritycontext(request); - Preconditions.checkNotNull(securityContext); - -// poll = getPollService().getExistingPollByPollId(pollId); -// poll = securityContext.getPoll(); - - return SUCCESS; - } -} Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,214 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.opensymphony.xwork2.Preparable; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.bean.PollUrl; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.business.persistence.PollAccount; -import org.chorem.pollen.business.persistence.Vote; -import org.chorem.pollen.business.persistence.VoteToChoice; -import org.chorem.pollen.services.impl.VoteService; -import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; - -/** - * Votes to a poll. - * - * @author tchemit <chemit@codelutin.com> - * @author fdesbois <fdesbois@codelutin.com> - * @since 1.3 - */ -public class VoteForPoll extends AbstractVoteAction implements Preparable { - - private static final Log log = LogFactory.getLog(VoteForPoll.class); - - private static final long serialVersionUID = 1L; - - @Override - public boolean isModerate() { - return false; - } - - @Override - public void prepare() throws Exception { - - prepareVotePage(); - - // Messages - if (getPoll().isClosed()) { - addFlashWarning(_("pollen.information.pollClosed")); - } else if (!isPollStarted()) { - addFlashWarning(_("pollen.information.pollNotStarted")); - } else if (isPollFinished()) { - addFlashWarning(_("pollen.information.pollFinished")); - } else if (!isVoteAllowed()) { - addFlashWarning(_("pollen.information.pollCanNotVote")); - } - if (isPollChoiceRunning()) { - addFlashMessage(_("pollen.information.pollChoiceRunning")); - } if (!isCommentAllowed()) { addFlashMessage(_("pollen.information.pollCommentNotAuthorized")); } - - } - - @Override - public void validate() { - - Vote vote = getVote(); - Preconditions.checkNotNull(vote); - - PollAccount pollAccount = getVote().getPollAccount(); - Preconditions.checkNotNull(pollAccount); - - Poll poll = getPoll(); - - if (!vote.isAnonymous()) { - - String name = pollAccount.getVotingId(); - if (StringUtils.isBlank(name)) { - addFieldError("pollAccount.votingId", - _("pollen.error.pollAccount.votingId.required")); - } - - // check if the new pollAccount (topiaId = null) has already voted - if (pollAccount.getTopiaId() == null && - getVoteService().hasAlreadyVoted(poll, name)) { - addFieldError("pollAccount.votingId", - _("pollen.error.user.alreadyVoted", name)); - } - } - - int nbVotes = 0; - int totalValues = 0; - - VoteCountingStrategy strategy = - getVoteCountingStrategy(getPoll()); - - boolean voteValid = true; - for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { - - Integer value = voteToChoice.getVoteValue(); - - // check if vote is null ? - boolean voteNull = strategy.isVoteValueNull(value); - - if (voteNull) { - // null vote, can skip his validation - continue; - } - - // check if vote value is valid ? - boolean valid = strategy.isVoteValueValid(value); - - if (valid) { - - // ok this vote value is valid, use it - nbVotes++; - totalValues += value; - } else { - - // not a valid vote value, mark it and skip other fields validation - String validMessage = - strategy.getVoteValueNotValidMessage(getLocale()); - addFieldError("vote.choices", validMessage); - voteValid = false; - break; - } - } - if (voteValid) { - - // check that the number of choices is not greater than maxChoiceNb - int maxChoice = getPoll().getMaxChoiceNb(); - if (maxChoice != 0 && nbVotes > maxChoice) { - addFieldError("vote.choices", - _("pollen.error.vote.maxChoiceNb", maxChoice)); - } - - // check that total vote value is ok - if (!strategy.isTotalVoteValueValid(totalValues)) { - - // not valid - String errorMessage = strategy.getTotalVoteValueNotValidMessage(getLocale()); - addFieldError("vote.choices", errorMessage); - } - } - } - - @Override - public String execute() throws Exception { - - // REMARQUES : - // - pas le droit de modif si le pollAccount est rattaché a un userAccount et qu'on est pas loggé ?!? - // - Ce serait plus simple que l'Admin ne puisse jamais voter, il ne peut que modérer les votes - - Poll poll = getPoll(); - - Vote vote = getVote(); - - VoteService voteService = getVoteService(); - - Vote newVote; - if (StringUtils.isBlank(vote.getTopiaId())) { - - // create a new vote - newVote = voteService.createVote(poll, vote); - } else { - - // update existing vote - newVote = voteService.updateVote(poll, vote); - } - - //TODO tchemit-2012-05-18 Why clean messages and just messages here ? - clearFlashMessages(); - - // For free Poll, display the update Url (useless if user is logged or - // not using a modify url) - if (poll.isPollFree() && - !isUserLoggued() && - StringUtils.isBlank(getAccountId())) { - - String pollId = poll.getPollId(); - String accountId = newVote.getPollAccount().getAccountId(); - - PollUrl updateUrl = getPollUrlService().getPollVoteUrl( - poll, newVote.getPollAccount()); - - if (log.isDebugEnabled()) { - log.debug(String.format( - "UpdateURL for poll '%s' and account '%s' = %s", - pollId, accountId, updateUrl)); - } - - addFlashMessage( - _("pollen.information.vote.createdWithUpdateUrl", updateUrl)); - - } else { - - addFlashMessage(_("pollen.information.vote.created")); - } - return SUCCESS; - } -} Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ClosePoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ClosePoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ClosePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,81 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.admin; + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * Closes an existing poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ClosePoll extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(ClosePoll.class); + + /** + * Redirect url. + * + * @since 1.3 + */ + protected String redirectUrl; + + public String getRedirectUrl() { + return redirectUrl; + } + + public void setRedirectUrl(String redirectUrl) { + this.redirectUrl = redirectUrl; + } + + @Override + public String execute() throws Exception { + + // must be poll creator/admin to perform this action + Preconditions.checkState(getUserSecurityContext().isCreator()); + + Poll poll = getUserSecurityContext().getPoll(); + + String title = poll.getTitle(); + + if (log.isDebugEnabled()) { + log.debug(String.format("Will delete poll %s", title)); + } + + getPollService().closePoll(poll.getPollId()); + + addFlashMessage(_("pollen.information.poll.closed", title)); + + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ClosePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ConfirmPollAction.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ConfirmPollAction.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ConfirmPollAction.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,63 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.admin; + +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To confirm a poll action (such as delete or close). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ConfirmPollAction extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + protected Poll poll; + + protected String redirectUrl; + + public String getRedirectUrl() { + return redirectUrl; + } + + public void setRedirectUrl(String redirectUrl) { + this.redirectUrl = redirectUrl; + } + + public Poll getPoll() { + return poll; + } + + @Override + public String execute() throws Exception { + poll = getUserSecurityContext().getPoll(); + + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ConfirmPollAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/DeletePoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/DeletePoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/DeletePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,75 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.admin; + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * Deletes an existing poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DeletePoll extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(DeletePoll.class); + + protected String redirectUrl; + + public String getRedirectUrl() { + return redirectUrl; + } + + public void setRedirectUrl(String redirectUrl) { + this.redirectUrl = redirectUrl; + } + + @Override + public String execute() throws Exception { + + // must be poll creator/admin to perform this action + Preconditions.checkState(getUserSecurityContext().isCreator()); + + Poll poll = getUserSecurityContext().getPoll(); + + String title = getUserSecurityContext().getPoll().getTitle(); + + if (log.isDebugEnabled()) { + log.debug(String.format("Will delete poll %s", title)); + } + getPollService().deletePoll(poll.getPollId()); + + addFlashMessage(_("pollen.information.poll.deleted", title)); + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/DeletePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,74 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.admin; + +import org.apache.commons.io.IOUtils; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +import java.io.InputStream; + +/** + * Exports an existing poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ExportPoll extends PollenActionSupport implements PollenUserSecurityAware { + + private static final long serialVersionUID = 1L; + + protected String filename; + + protected long contentLength; + + protected transient InputStream inputStream; + + public long getContentLength() { + return contentLength; + } + + public InputStream getInputStream() { + return inputStream; + } + + public String getFilename() { + return filename; + } + + @Override + public String execute() throws Exception { + + String pollId = getUserSecurityContext().getPoll().getPollId(); + + String exportContent = getPollResultsService().exportPolltoXml(pollId); + + filename = "exportPoll-" + pollId + ".xml"; + + contentLength = exportContent.length() * 2; + + inputStream = IOUtils.toInputStream(exportContent); + + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/SummaryPoll.java (from rev 3595, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/SummaryPoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/SummaryPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,124 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.admin; + +import org.chorem.pollen.bean.PollUrl; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PageSkin; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * Action to display summary of a poll for his creator (or an admin). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class SummaryPoll extends PollenActionSupport implements PollenUserSecurityAware { + + private static final long serialVersionUID = 1L; + + public SummaryPoll() { + super(PageSkin.EDITION); + } + + public Poll getPoll() { + return getUserSecurityContext().getPoll(); + } + + public String getVoteUrl() { + PollUrl url = getPollUrlService().getPollVoteUrl(getPoll()); + if (getPoll().isPollFree()) { + + // can removed accountId only for free poll + //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given + getUserSecurityContext().removeAccountIdWhenConnected(url); + } + return url.getUrl(); + } + + public String getShowVoteUrl() { + PollUrl url = getPollUrlService().getPollVoteUrl(getPoll()); + if (getPoll().isPollFree()) { + + // can removed accountId only for free poll + //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given + getUserSecurityContext().removeAccountIdWhenConnected(url); + } + return url.getUrl(); + } + + public String getModerateUrl() { + PollUrl url = getPollUrlService().getPollModerateUrl(getPoll()); + getUserSecurityContext().removeAccountIdWhenConnected(url); + return url.getUrl(); + } + + public String getEditUrl() { + PollUrl url = getPollUrlService().getPollEditUrl(getPoll()); + getUserSecurityContext().removeAccountIdWhenConnected(url); + return url.getUrl(); + } + + public String getCloneUrl() { + PollUrl url = getPollUrlService().getPollCloneUrl(getPoll()); + getUserSecurityContext().removeAccountIdWhenConnected(url); + return url.getUrl(); + } + + public String getExportUrl() { + PollUrl url = getPollUrlService().getPollExportUrl(getPoll()); + getUserSecurityContext().removeAccountIdWhenConnected(url); + return url.getUrl(); + } + + public String getResultUrl() { + PollUrl url = getPollUrlService().getPollResultUrl(getPoll()); + getUserSecurityContext().removeAccountIdWhenConnected(url); + return url.getUrl(); + } + + public boolean isCanClose() { + return getSecurityService().isCanClosePoll(getUserSecurityContext()); + } + + public boolean isCanShowVote() { + return getPoll().isPublicResults() && !isCanVote(); + } + + public boolean isCanShowResult() { + boolean result = getSecurityService().isCanAccessResult(getUserSecurityContext()); + return result; + } + + public boolean isCanVote() { + return getSecurityService().isCanVote(getUserSecurityContext()); + } + + @Override + public String execute() throws Exception { + + // nothing to do, everything is contains in the security context. + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/SummaryPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the all poll admin actions. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.poll.admin; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractDisplayChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractDisplayChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractDisplayChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractDisplayChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,114 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +import java.util.Map; + +/** + * To generate the display for a text choice. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public abstract class AbstractDisplayChoice extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + /** + * Where to find dynamic data (says choices in this case). + * + * @since 1.3 + */ + protected String tokenId; + + /** + * Number of choice to display. + * + * @since 1.3 + */ + protected int choiceNumber; + + /** + * Choice to display in ui (come from dynamic data if exists, or fresh + * created one). + * + * @since 1.3 + */ + protected Choice choice; + + public void setTokenId(String tokenId) { + this.tokenId = tokenId; + } + + public void setChoiceNumber(int choiceNumber) { + this.choiceNumber = choiceNumber; + } + + public Choice getChoice() { + return choice; + } + + public int getChoiceNumber() { + return choiceNumber; + } + + protected abstract Choice createEmptyChoice(); + + @Override + public String execute() throws Exception { + if (StringUtils.isNotEmpty(tokenId)) { + + Map<Integer, Choice> choices = + (Map<Integer, Choice>) getPollenSession().getDynamicData(tokenId); + + if (choices != null) { + + // get choices from datas + choice = choices.get(choiceNumber); + + if (choice != null) { + + // remove this choice from session + choices.remove(choiceNumber); + } + } + + if (MapUtils.isEmpty(choices)) { + + // remove it from session + getPollenSession().removeDynamicData(tokenId); + } + } + + if (choice == null) { + choice = createEmptyChoice(); + } + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractDisplayChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java (from rev 3595, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,1941 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import com.google.common.base.Charsets; +import com.google.common.base.Function; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.opensymphony.xwork2.Preparable; +import com.opensymphony.xwork2.interceptor.annotations.InputConfig; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.ObjectUtils; +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.PollenTechnicalException; +import org.chorem.pollen.bean.PollDateChoice; +import org.chorem.pollen.bean.PollImageChoice; +import org.chorem.pollen.bean.PollUri; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.ChoiceImpl; +import org.chorem.pollen.business.persistence.PersonToList; +import org.chorem.pollen.business.persistence.PersonToListImpl; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.PollAccountImpl; +import org.chorem.pollen.business.persistence.PollCommentVisibility; +import org.chorem.pollen.business.persistence.PollVoteVisibility; +import org.chorem.pollen.business.persistence.PreventRule; +import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.business.persistence.VotingList; +import org.chorem.pollen.business.persistence.VotingListImpl; +import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.common.I18nAble; +import org.chorem.pollen.common.PollType; +import org.chorem.pollen.services.PollenServiceFunctions; +import org.chorem.pollen.services.exceptions.PollNotFoundException; +import org.chorem.pollen.services.impl.PollService; +import org.chorem.pollen.services.impl.PreventRuleService; +import org.chorem.pollen.ui.actions.FileUploadAware; +import org.chorem.pollen.ui.actions.PollenActionSupportForEdition; +import org.chorem.pollen.ui.converters.DateConverter; +import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; +import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider; +import org.nuiton.util.StringUtil; + +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Collection; +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; + +/** + * Created: 04/04/12 + * + * @author fdesbois <desbois@codelutin.com> + * $Id$ + */ +public abstract class AbstractPollForm extends PollenActionSupportForEdition implements Preparable, ParameterAware, FileUploadAware { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(AbstractPollForm.class); + + public static final String IMAGECHOICES_THUMB_PREFIX = "imagechoicesThumb_"; + + private static final Pattern TEXT_CHOICE_NAME_PATTERN = + Pattern.compile("textChoice_(\\d+)\\.name"); + + private static final Pattern DATE_CHOICE_NAME_PATTERN = + Pattern.compile("dateChoice_(\\d+)\\.name"); + + private static final Pattern IMAGE_CHOICE_DESCRIPTION_PATTERN = + Pattern.compile("imageChoice_(\\d+)\\.description"); + + protected Poll poll; + + private Map<String, String> pollTypes; + + private Map<String, String> voteCountingTypes; + + private Map<String, String> choiceTypes; + + private Map<String, String> pollVoteVisibilities; + + /** Text choices. */ + private List<Choice> textChoices; + + /** Image choices. */ + private List<Choice> imageChoices; + + /** Date choices. */ + private List<Choice> dateChoices; + + /** restricted Voting lists. */ + private List<VotingList> restrictedVotingList; + + /** Group voting lists. */ + private List<VotingList> groupVotingList; + + private boolean notification; + + private boolean reminder; + + private boolean limitChoice; + + private Integer maxChoices; + + private Integer reminderHourCountdown; + + /** To create a new personToList. */ + private transient Function<PersonToList, PersonToList> persontoListCreator; + + /** To create a new votingList. */ + private transient Function<VotingList, VotingList> votingListCreator; + + /** To create a new text choice. */ + private transient Function<Choice, Choice> textChoiceCreator; + + /** To create a new date choice. */ + private transient Function<Choice, Choice> dateChoiceCreator; + + /** To create a new image choice. */ + private transient Function<Choice, Choice> imageChoiceCreator; + + /** + * Flag when there is some errors on the information panel. + * + * @since 1.3 + */ + protected boolean informationsError; + + /** + * Flag when there is some errors on the options panel. + * + * @since 1.3 + */ + private boolean optionsError; + + /** + * Indexed choices retreive from parameters for the choiceType selected in + * form. (Other choices are lost). + * + * @since 1.3 + */ + private Map<Integer, Choice> choices; + + /** + * Contains the order of choices (given by the xxx.order field. + * + * @since 1.4 + */ + private Map<Integer, Integer> choicesOrder; + + /** + * Indexed voting lists retreive from parameters for the pollType selected + * in form. (Other voting lists are lost). + * + * @since 1.3 + */ + private Map<Integer, VotingList> votingLists; + + private PollUri pollUri; + + public abstract boolean isClone(); + + protected abstract Poll savePoll(Poll poll) throws PollNotFoundException; + + public abstract boolean isEdit(); + + @Override + public void prepare() throws Exception { + + prepareFormPage(); + + if (isGetMethod()) { + + // do not prepare when coming as GET + return; + } + + // we are after a submit + + String pollUid = getNonEmptyParameterValue("poll.pollId"); + String userId = getNonEmptyParameterValue("userId"); + if (StringUtils.isBlank(userId)) { + + // try to take the one from current user + UserAccount userAccount = getPollenUserAccount(); + if (userAccount != null) { + userId = userAccount.getTopiaId(); + } + } + UserAccount userAccount = null; + if (StringUtils.isNotBlank(userId)) { + // load use account to use + userAccount = getPollService().getEntityById( + UserAccount.class, userId); + } + + // get a copy (or a fresh new poll) + poll = getPollService().getPollEditable(pollUid, userAccount, false); + + // If vote is started, prepare choices and votingLists is useless + // because they can't be updated. + if (!isVoteStarted()) { + + // Retrieve choiceType from parameters, the poll object will be updated after prepare + String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType"); + ChoiceType pollChoiceType = ChoiceType.valueOf(choiceTypeParam); + poll.setChoiceType(pollChoiceType); + + choicesOrder = Maps.newTreeMap(); + + // build poll choices + + switch (pollChoiceType) { + + case TEXT: + choices = buildTextChoices(); + break; + case DATE: + choices = buildDateChoices(); + break; + case IMAGE: + choices = buildImageChoices(); + break; + } + PollType pollType; + String pollTypeParam = getNonEmptyParameterValue("poll.pollType"); + pollType = PollType.valueOf(pollTypeParam); + switch (pollType) { + + case FREE: + + // empty voting list + votingLists = Maps.newTreeMap(); + break; + case RESTRICTED: + + // restricted voting list + votingLists = buildVotingLists(pollType); + break; + case GROUP: + + // group voting lists + votingLists = buildVotingLists(pollType); + break; + } + } + } + + @Override + public String input() throws Exception { + + UserAccount userAccount = getPollenUserAccount(); + String pollUid = pollUri == null ? null : pollUri.getPollId(); + PollService service = getPollService(); + + poll = service.getPollEditable(pollUid, userAccount, isClone()); + + if (poll.isClosed()) { + addFlashWarning(_("pollen.warning.poll.is.closed.so.read.only")); + } + List<Choice> pollChoices = poll.getChoice(); + + if (isClone()) { + + if (ChoiceType.IMAGE == poll.getChoiceType()) { + + // recopy images to tmp + + File tmpDir = getConfiguration().getTemporaryDirectory(); + for (Choice choice : pollChoices) { + String choiceName = choice.getName(); + + // image from poll to clone + File imageChoiceFile = service.getPollChoiceImageFile( + pollUid, + choiceName + ); + + // new image + File newImageChoiceFile = File.createTempFile( + choiceName, null, tmpDir); + + if (log.isInfoEnabled()) { + log.info("Copy image from " + imageChoiceFile + + " to " + newImageChoiceFile); + } + FileUtils.copyFile(imageChoiceFile, + newImageChoiceFile); + + ((PollImageChoice) choice).setLocation( + newImageChoiceFile.getAbsolutePath()); + } + } + } + + List<VotingList> pollVotingLists = poll.getVotingList(); + + loadChoicesAndvotingLists(poll, + pollChoices, + pollVotingLists, + !isVoteStarted()); + + setLimitChoice(poll.getMaxChoiceNb() > 0); + + if (isLimitChoice()) { + setMaxChoices(poll.getMaxChoiceNb()); + } else { + // set default max choices + setMaxChoices(1); + } + PreventRule reminder = poll.getPreventRuleByScope( + PreventRuleService.SCOPE_REMINDER); + if (reminder != null) { + setReminder(true); + setReminderHourCountdown(reminder.getSensibility()); + } else { + setReminder(false); + // set default reminderHourCountdown + setReminderHourCountdown(2); + } + + PreventRule notification = poll.getPreventRuleByScope( + PreventRuleService.SCOPE_VOTE); + if (notification != null) { + setNotification(true); + } + + if (isVoteStarted()) { + addFlashMessage(_("pollen.information.poll.form.voteStarted")); + } + + return INPUT; + } + + public String inputAfterValidationError() throws Exception { + + Collection<Choice> pollChoices = + isVoteStarted() ? poll.getChoice() : choices.values(); + Collection<VotingList> pollVotingLists = + isVoteStarted() ? poll.getVotingList() : votingLists.values(); + + if (ChoiceType.IMAGE == poll.getChoiceType()) { + + // recopy images for new choices, the one uploaded will be + // destroyed, by the upload interceptor + + File tmpDir = getConfiguration().getTemporaryDirectory(); + + for (Choice choice : pollChoices) { + + PollImageChoice imageChoice = (PollImageChoice) choice; + + String choiceId = choice.getTopiaId(); + String location = imageChoice.getLocation(); + + boolean needCopy = false; + if (!isImageUploadEmpty(imageChoice)) { + + // there is an image in the choice + + if (StringUtils.isBlank(choiceId)) { + + // this is a new choice + needCopy = true; + } else { + + // check that name has not changed + Choice oldChoice = poll.getChoiceByTopiaId(choiceId); + + needCopy = ObjectUtils.notEqual(oldChoice.getName(), imageChoice.getName()); + } + } + + if (needCopy) { + + // not persisted choice with an upload + // let's copy it somewhere safe + + File uploadedImage = new File(location); + File copyImage = File.createTempFile( + uploadedImage.getName(), null, tmpDir); + + if (log.isInfoEnabled()) { + log.info("Copy image from " + uploadedImage + + " to " + copyImage); + } + FileUtils.copyFile(uploadedImage, copyImage); + + imageChoice.setLocation(copyImage.getAbsolutePath()); + + // generate also the thumb file + getPollService().generateThumbIfNeeded(copyImage); + } + } + } + + loadChoicesAndvotingLists(poll, pollChoices, pollVotingLists, true); + return INPUT; + } + + @Override + @InputConfig(methodName = "inputAfterValidationError") + public String execute() throws Exception { + + if (isGetMethod()) { + + // input method + return input(); + } + + // Save choices and votingLists only if vote is not started + if (!isVoteStarted()) { + //TODO-tchemit comment me 2012-06-04 A merge would be nicer but more complex to code + // Clear previous collections to save those from the form + poll.clearChoice(); + poll.clearVotingList(); + for (Integer index : choices.keySet()) { + Choice choice = choices.get(index); + poll.addChoice(choice); + } + + if (!isFreePoll()) { + + for (Integer index : votingLists.keySet()) { + VotingList votingList = votingLists.get(index); + poll.addVotingList(votingList); + } + } + } + + if (isLimitChoice()) { + + // push back filled value + poll.setMaxChoiceNb(getMaxChoices()); + } else { + // reset value + poll.setMaxChoiceNb(0); + } + + if (poll.isAnonymous()) { + + // force to not have choice to vote anonymously + poll.setAnonymousVoteAllowed(false); + } + + //TODO-tchemit comment me 2012-06-04 A merge would be nicer but more complex to code + poll.clearPreventRule(); + + PreventRuleService preventRuleService = getPreventRuleService(); + 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); + } + + // do save poll + poll = savePoll(poll); + + // compute fresh pollUri + pollUri = PollUri.newPollUri(poll.getAdminId()); + + // remove all stuff from session + getPollenSession().clearDynamicData(); + + return SUCCESS; + } + + @Override + public void validate() { + + if (isGetMethod()) { + + // input method + return; + } + validateInformations(); + + validateOptions(); + } + + @Override + public void addFile(int index, File file) { + getParameters().put("imageChoice_" + index + ".newLocation", + new String[]{file.getAbsolutePath()}); + } + + @Override + public void addFileContentType(int index, String contentType) { + getParameters().put("imageChoice_" + index + ".newContentType", + new String[]{contentType}); + // not used here + } + + @Override + public void addFileName(int index, String fileName) { + getParameters().put("imageChoice_" + index + ".newName", new String[]{fileName}); + } + + public boolean isInformationsError() { + return informationsError; + } + + public boolean isOptionsError() { + return optionsError; + } + + public int getSelectedTab() { + int result; + if (isInformationsError()) { + result = 0; + } else { + if (isOptionsError()) { + result = 1; + } else { + result = 0; + } + } + return result; + } + + public PollUri getPollUri() { + return pollUri; + } + + public void setPollUri(PollUri pollUri) { + this.pollUri = pollUri; + } + + public Poll getPoll() { + return poll; + } + + public Map<String, String> getPollTypes() { + return pollTypes; + } + + public Map<String, String> getVoteCountingTypes() { + return voteCountingTypes; + } + + public Map<String, String> getChoiceTypes() { + return choiceTypes; + } + + public Map<String, String> getPollVoteVisibilities() { + return pollVoteVisibilities; + } + + public List<Choice> getTextChoices() { + return textChoices; + } + + public List<Choice> getImageChoices() { + return imageChoices; + } + + public List<Choice> getDateChoices() { + return dateChoices; + } + + public List<VotingList> getRestrictedVotingList() { + return restrictedVotingList; + } + + public List<VotingList> getGroupVotingList() { + return groupVotingList; + } + + public boolean isNotification() { + return notification; + } + + public void setNotification(boolean notification) { + this.notification = notification; + } + + public Integer getMaxChoices() { + return maxChoices; + } + + public void setMaxChoices(Integer maxChoices) { + this.maxChoices = maxChoices; + } + + 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 Integer getReminderHourCountdown() { + return reminderHourCountdown; + } + + public void setReminderHourCountdown(Integer reminderHourCountdown) { + this.reminderHourCountdown = reminderHourCountdown; + } + + public boolean isFreePoll() { + return poll.isPollFree(); + } + + public boolean isGroupPoll() { + PollType pollType = poll.getPollType(); + return pollType == PollType.GROUP; + } + + public boolean isPollCommentVisible() { + PollCommentVisibility pollCommentVisibility = + poll.getPollCommentVisibility(); + return pollCommentVisibility == PollCommentVisibility.EVERYBODY; + } + + public void setPollCommentVisible(boolean newValue) { + if (newValue) { + poll.setPollCommentVisibility(PollCommentVisibility.EVERYBODY); + } else { + poll.setPollCommentVisibility(PollCommentVisibility.NOBODY); + } + } + + public String getActionLabel() { + return isEdit() ? _("pollen.action.editPoll") : + _("pollen.action.createPoll"); + } + + public String getPageTitle() { + return isEdit() ? getPoll().getTitle() : + _("pollen.title.createPoll"); + } + + public boolean isVoteStarted() { + return isEdit() && poll.sizeVote() > 0; + } + + public boolean isCreatorUserAccountDefined() { + PollAccount creator = poll.getCreator(); + return creator.getUserAccount() != null; + } + + public String getImageChoiceName(Choice choice) { + String name = choice.getName(); + try { + String result = URLEncoder.encode(IMAGECHOICES_THUMB_PREFIX + name, + Charsets.UTF_8.name()); + return result; + } catch (UnsupportedEncodingException e) { + throw new PollenTechnicalException( + "Could not encode name " + name, e); + } + } + + public String getVoteCountingHelp() { + + StringBuilder builder = new StringBuilder(); + VoteCountingStrategyProvider strategyProvider = + getVoteCountingStrategyProvider(); + Set<Integer> strategyIds = strategyProvider.getStrategyIds(); + for (Integer strategyId : strategyIds) { + VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId); + String strategyHelp = strategy.getStrategyHelp(getLocale()); + builder.append(strategyHelp).append("<br/><br/>"); + } + return builder.toString(); + } + + public void prepareFormPage() throws Exception { + + getPollenSession().removeDynamicDataWithPrefix(IMAGECHOICES_THUMB_PREFIX); + + pollTypes = decorateToName(PollType.values()); + choiceTypes = decorateToName(ChoiceType.values()); + pollVoteVisibilities = decorateToName(PollVoteVisibility.values()); + voteCountingTypes = Maps.newTreeMap(); + + VoteCountingStrategyProvider strategyProvider = + getVoteCountingStrategyProvider(); + Set<Integer> strategyIds = strategyProvider.getStrategyIds(); + for (Integer strategyId : strategyIds) { + VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId); + String strategyHelp = strategy.getStrategyName(getLocale()); + voteCountingTypes.put(strategyId + "", strategyHelp); + } +// decorateToName(VoteCountingType.values()); + + textChoices = Lists.newArrayList(); + imageChoices = Lists.newArrayList(); + dateChoices = Lists.newArrayList(); + + restrictedVotingList = Lists.newArrayList(); + groupVotingList = Lists.newArrayList(); + } + + public Function<PersonToList, PersonToList> getPersontoListCreator() { + if (persontoListCreator == null) { + persontoListCreator = PollenServiceFunctions.newPersonToListCreator(); + } + return persontoListCreator; + } + + public Function<VotingList, VotingList> getVotingListCreator() { + if (votingListCreator == null) { + votingListCreator = PollenServiceFunctions.newVotingListCreator( + getPersontoListCreator()); + } + return votingListCreator; + } + + public Function<Choice, Choice> getTextChoiceCreator() { + if (textChoiceCreator == null) { + textChoiceCreator = PollenServiceFunctions.newTextChoiceCreator(); + } + return textChoiceCreator; + } + + public Function<Choice, Choice> getDateChoiceCreator() { + if (dateChoiceCreator == null) { + dateChoiceCreator = PollenServiceFunctions.newDateChoiceCreator(); + } + return dateChoiceCreator; + } + + public Function<Choice, Choice> getImageChoiceCreator() { + if (imageChoiceCreator == null) { + imageChoiceCreator = PollenServiceFunctions.newImageChoiceCreator(); + } + return imageChoiceCreator; + } + + 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; + } + + protected void validateInformations() { + + // -- Title : required -- // + if (StringUtils.isBlank(poll.getTitle())) { + addInformationsError("poll.title", + _("pollen.error.poll.required.title")); + } + + if (isVoteStarted()) { + + // no validation on choices if vote is started + + } else { + + // -- Choice -- // + if (MapUtils.isEmpty(choices)) { + + // poll must have at least one choice + addInformationsError("poll.choices", + _("pollen.error.poll.required.one.choice")); + } else { + switch (poll.getChoiceType()) { + + case TEXT: + validateTextChoices(); + break; + case DATE: + validateDateChoices(); + break; + case IMAGE: + validateImageChoices(); + break; + } + } + } + } + + protected void validateTextChoices() { + + String choicePrefix = getChoiceFieldPrefix(ChoiceType.TEXT); + + Set<String> choiceNames = Sets.newHashSet(); + + for (Map.Entry<Integer, Choice> entry : choices.entrySet()) { + Integer choiceIndex = entry.getKey(); + Choice choice = entry.getValue(); + String choiceErrorField = choicePrefix + choiceIndex + ".name"; + String choiceName = choice.getName(); + if (StringUtils.isBlank(choiceName)) { + // no name + addInformationsError( + choiceErrorField, + _("pollen.error.poll.choice.name.required")); + continue; + } + if (choiceNames.contains(choiceName)) { + // duplicated names + addInformationsError( + choiceErrorField, + _("pollen.error.poll.choice.already.used.name")); + continue; + } + choiceNames.add(choiceName); + } + } + + protected void validateDateChoices() { + + String choicePrefix = getChoiceFieldPrefix(ChoiceType.DATE); + + Set<String> choiceNames = Sets.newHashSet(); + + for (Map.Entry<Integer, Choice> entry : choices.entrySet()) { + Integer choiceIndex = entry.getKey(); + PollDateChoice choice = (PollDateChoice) entry.getValue(); + String choiceErrorField = choicePrefix + choiceIndex + ".name"; + if (StringUtils.isBlank(choice.getName())) { + // no name + addInformationsError( + choiceErrorField, + _("pollen.error.poll.dateChoice.required")); + continue; + } + if (choice.getDate() == null) { + + // format error + addInformationsError( + choiceErrorField, + _("pollen.error.poll.dateChoice.badDateFormat")); + continue; + } + + // date is valid + // use now the date.toString() as value to ensure unicity + String choiceValue = choice.getDate().toString(); + + if (choiceNames.contains(choiceValue)) { + // duplicated names + addInformationsError( + choiceErrorField, + _("pollen.error.poll.dateChoice.already.used")); + continue; + } + choiceNames.add(choiceValue); + } + } + + protected void validateImageChoices() { + + String choicePrefix = getChoiceFieldPrefix(ChoiceType.IMAGE); + + Set<String> choiceNames = Sets.newHashSet(); + + for (Map.Entry<Integer, Choice> entry : choices.entrySet()) { + Integer choiceIndex = entry.getKey(); + Choice choice = entry.getValue(); + String choiceErrorField = choicePrefix + choiceIndex + ".name"; + String choiceName = choice.getName(); + if (StringUtils.isBlank(choiceName)) { + // no name + addInformationsError( + choiceErrorField, + _("pollen.error.poll.imageChoice.upload.required")); + continue; + } + if (choiceNames.contains(choiceName)) { + // duplicated names + addInformationsError( + choiceErrorField, + _("pollen.error.poll.imageChoice.already.used")); + continue; + } + choiceNames.add(choiceName); + String contentTypeField = choicePrefix + choiceIndex + ".newContentType"; + String contentTypes = getNonEmptyParameterValue(contentTypeField); + if (contentTypes != null && !contentTypes.startsWith("image/")) { + // Bad content Type + addInformationsError( + choiceErrorField, + _("pollen.error.poll.imageChoice.upload.badContentType")); + //Remove the file and its thumb + PollImageChoice imageChoice = (PollImageChoice) choice; + File imageFile = new File(imageChoice.getLocation()); + File imageThumbFile = getPollService().getImageThumbFile(imageFile); + FileUtils.deleteQuietly(imageThumbFile); + FileUtils.deleteQuietly(imageFile); + // The choice has no more location + String choiceId = imageChoice.getTopiaId(); + if (StringUtils.isBlank(choiceId)) { + imageChoice.setLocation(null); + // As the name of the choice is the fileName, remove it too. + imageChoice.setName(null); + } else { + // in case of update, get back the old values for name and location and keep the old choice + PollImageChoice pollChoice = (PollImageChoice) poll.getChoiceByTopiaId(choiceId); + imageChoice.setName(pollChoice.getName()); + imageChoice.setLocation(pollChoice.getLocation()); + } + continue; + } + } + } + + protected void validateOptions() { + + if (isVoteStarted()) { + + // no validation on votingLists if vote is started + + } else { + + // -- VotingList -- // + + if (isFreePoll()) { + + // nothing to validate + + } else { + + Set<String> groups = Sets.newHashSet(); + Set<String> voters = Sets.newHashSet(); + Set<String> emails = Sets.newHashSet(); + + for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) { + validateVotingList(entry.getKey(), + entry.getValue(), + groups, + voters, + emails); + } + } + } + + String creatorEmail = poll.getCreator().getEmail(); + if (StringUtils.isNotBlank(creatorEmail) && + !StringUtil.isEmail(creatorEmail)) { + + addOptionsError("poll.creator.email", + _("pollen.error.email.invalid")); + } + + Date currentTime = serviceContext.getCurrentTime(); + + if (validateEndDate(poll.getBeginChoiceDate(), poll.getEndChoiceDate())) { + + addOptionsError( + "poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.before.beginChoiceDate")); + } + + if (validateEndDate(currentTime, poll.getEndChoiceDate())) { + + addOptionsError( + "poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.before.now")); + } + + if (validateEndDate(poll.getBeginDate(), poll.getEndDate())) { + + addOptionsError("poll.endDate", + _("pollen.error.poll.endDate.before.beginDate")); + } + + + if (validateEndDate(currentTime, poll.getEndDate())) { + + addOptionsError( + "poll.endDate", + _("pollen.error.poll.endDate.before.now")); + } + + if (validateEndDate(poll.getEndChoiceDate(), poll.getEndDate())) { + + addOptionsError("poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.after.endDate")); + } + + if (isLimitChoice()) { + + // validate maxChoices + + if (getMaxChoices() == null) { + // maxChoices == null + addOptionsError("maxChoices", + _("pollen.error.poll.maxChoice.required")); + } else if (getMaxChoices() < 1) { + // maxChoices <= 0 + addOptionsError("maxChoices", + _("pollen.error.poll.maxChoice.greater.than.0")); + } + } + + if (isReminder()) { + + // validate reminderHourCountdown + + if (getReminderHourCountdown() == null) { + + // reminderHourCountdown == null + addOptionsError("reminderHourCountdown", + _("pollen.error.poll.reminderHourCountdown.required")); + } else if (getReminderHourCountdown() < 1) { + + // reminderHourCountdown <= 0 + addOptionsError("reminderHourCountdown", + _("pollen.error.poll.reminderHourCountdown.greater.than.0")); + } + } + } + + protected void validateVotingList(int votingListNumber, + VotingList votingList, + Set<String> groups, + Set<String> voters, + Set<String> emails) { + + PollType votingListType = poll.getPollType(); + String fieldNamePrefix = "votingList" + votingListType + "_" + + votingListNumber; + + if (isGroupPoll()) { + + // group poll + + // check there is at least one group + // check no doublon on group names + // check there is at least one voter on each group + // check no doublon on voter names + // check no doublon on voter emails + + // validate votingList name + String votingListName = votingList.getName(); + + if (StringUtils.isEmpty(votingListName)) { + + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.required.votingList.name")); + } else { + + // check no votingList name doublon + boolean add = groups.add(votingListName); + if (!add) { + + // name doublon + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.votingList.name.doublon")); + } + } + + // validate votingList weight + + if (votingList.getWeight() == 0) { + + // no weight filled (can be a bad conversion) + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.votingList.weight.not.valid")); + } + + } + + // check there is at least one voter + + List<PersonToList> personToLists = + votingList.getPollAccountPersonToList(); + + if (CollectionUtils.isEmpty(personToLists)) { + + // no personToList found for unique votingList 0 + addOptionsError(fieldNamePrefix, + _("pollen.error.poll.required.one.personToList")); + } else { + + // check no doublon on voter names + + for (int i = 0; i < personToLists.size(); i++) { + + validatePersonList(i, + fieldNamePrefix, + personToLists.get(i), + voters, + emails); + } + } + } + + protected void validatePersonList(int personToListNumber, + String votingListFieldNamePrefix, + PersonToList personToList, + Set<String> voters, + Set<String> emails) { + + String fieldNamePrefix = votingListFieldNamePrefix + + "PersonToList_" + personToListNumber; + + PollAccount pollAccount = personToList.getPollAccount(); + + // -- validate votingId -- // + + String votingId = pollAccount.getVotingId(); + + if (StringUtils.isEmpty(votingId)) { + + // voter name mandatory + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.personToList.votingId.required")); + } else { + + boolean add = voters.add(votingId); + if (!add) { + + // voter name already used + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.personToList.votingId.doublon")); + } + } + + // -- validate email -- // + + String email = pollAccount.getEmail(); + + if (StringUtils.isEmpty(email)) { + + // voter email mandatory + addOptionsError(fieldNamePrefix, + _("pollen.error.email.required")); + } else { + + boolean validEmail = StringUtil.isEmail(email); + if (!validEmail) { + + // not a valid email + addOptionsError(fieldNamePrefix, + _("pollen.error.email.invalid")); + } else { + + boolean add = emails.add(email); + if (!add) { + + // email already used + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.personToList.email.doublon")); + } + } + } + + // -- validate weight -- // + + if (personToList.getWeight() == 0) { + + // no weight filled (can be a bad conversion) + addOptionsError( + fieldNamePrefix, + _("pollen.error.poll.personToList.weight.not.valid")); + } + } + + protected boolean validateEndDate(Date begin, Date end) { + return begin != null + && end != null + && end.before(begin); + } + + public Object getDateChoiceValue(PollDateChoice choice) { + Date date = choice.getDate(); + Object result; + if (date == null) { + result = choice.getName(); + } else { + result = date; + } + return result; + } + + @Override + public void addFieldError(String fieldName, String errorMessage) { + super.addFieldError(fieldName, errorMessage); + if (log.isDebugEnabled()) { + log.debug("VALIDATION [" + fieldName + "] : " + errorMessage); + } + } + + protected void addInformationsError(String fieldName, String errorMessage) { + addFieldError(fieldName, errorMessage); + informationsError = true; + } + + protected void addOptionsError(String fieldName, String errorMessage) { + addFieldError(fieldName, errorMessage); + optionsError = true; + } + + protected void loadChoicesAndvotingLists(Poll poll, + Collection<Choice> pollChoices, + Collection<VotingList> pollVotinLists, + boolean fillLists) throws IOException { + + Preconditions.checkNotNull(poll); + Preconditions.checkNotNull(poll.getChoiceType()); + Preconditions.checkNotNull(poll.getPollType()); + + if (CollectionUtils.isNotEmpty(pollChoices)) { + + //push back choices + + switch (poll.getChoiceType()) { + + case TEXT: + getTextChoices().addAll(pollChoices); + break; + case DATE: + getDateChoices().addAll(pollChoices); + break; + case IMAGE: + getImageChoices().addAll(pollChoices); + + PollService service = getPollService(); + + // if images are not still saved in a poll, then thumb + // does not exists, must create a temporary one + for (Choice choice : pollChoices) { + PollImageChoice imageChoice = (PollImageChoice) choice; + String choiceId = imageChoice.getTopiaId(); + File imageChoiceFile = null; + + if (StringUtils.isBlank(choiceId)) { + + // new choice, + + if (!isImageUploadEmpty(imageChoice)) { + + // ok there is an upload + imageChoiceFile = + new File(imageChoice.getLocation()); + } + + } else { + + // already persisted choice, check choice has not changed + + Choice oldChoice = + poll.getChoiceByTopiaId(choiceId); + + if (ObjectUtils.equals( + imageChoice.getName(), + oldChoice.getName())) { + + // name has not changed, keep persisted choice + imageChoiceFile = service.getPollChoiceImageFile( + poll.getPollId(), choice.getName()); + } else { + + // use new choice image location + imageChoiceFile = + new File(imageChoice.getLocation()); + } + + } + + if (imageChoiceFile != null) { + File thumbFile = service.getImageThumbFile( + imageChoiceFile); + + // keep in session the location of this thumb (do not + // want to expose the full path location in url) + String key = getImageChoiceName(choice); + getPollenSession().putDynamicData(key, thumbFile); + } + } + + break; + } + } + + if (CollectionUtils.isNotEmpty(pollVotinLists)) { + + // push back voting lists + + switch (poll.getPollType()) { + + case FREE: + // not voting lists + break; + case RESTRICTED: + getRestrictedVotingList().addAll(pollVotinLists); + break; + case GROUP: + getGroupVotingList().addAll(pollVotinLists); + break; + } + } + + if (fillLists) { + + // refill lists + + int defaultMaxChoices = 5; + int defaultMaxVoting = 5; + + fillLists(defaultMaxChoices, defaultMaxVoting); + } + } + + protected void fillLists(int defaultMaxChoices, int defaultMaxVoting) { + + PollenServiceFunctions.fillChoiceList(textChoices, + defaultMaxChoices, + getTextChoiceCreator()); + + PollenServiceFunctions.fillChoiceList(dateChoices, + defaultMaxChoices, + getDateChoiceCreator()); + + PollenServiceFunctions.fillChoiceList(imageChoices, + defaultMaxChoices, + getImageChoiceCreator()); + + if (CollectionUtils.isEmpty(restrictedVotingList)) { + restrictedVotingList.add(getVotingListCreator().apply(null)); + } + for (VotingList votingList : restrictedVotingList) { + PollenServiceFunctions.fillVotingList(votingList, + getPersontoListCreator(), + defaultMaxVoting); + } + if (CollectionUtils.isEmpty(groupVotingList)) { + groupVotingList.add(getVotingListCreator().apply(null)); + } + for (VotingList votingList : groupVotingList) { + PollenServiceFunctions.fillVotingList(votingList, + getPersontoListCreator(), + defaultMaxVoting); + } + } + + protected boolean isTextChoiceEmpty(Choice textChoice) { + boolean result = + StringUtils.isBlank(textChoice.getName()) && + StringUtils.isBlank(textChoice.getDescription()); + return result; + } + + protected boolean isDateChoiceEmpty(PollDateChoice dateChoice) { + boolean result = + StringUtils.isBlank(dateChoice.getName()) && + StringUtils.isBlank(dateChoice.getDescription()); + return result; + } + + protected boolean isImageChoiceEmpty(PollImageChoice imageChoice) { + boolean result = + StringUtils.isBlank(imageChoice.getLocation()) && + StringUtils.isBlank(imageChoice.getDescription()); + return result; + } + + protected boolean isImageUploadEmpty(PollImageChoice imageChoice) { + boolean result = + StringUtils.isBlank(imageChoice.getLocation()); + return result; + } + + protected boolean isPersonToListEmpty(PersonToList personToList) { + PollAccount pollAccount = personToList.getPollAccount(); + boolean result = + StringUtils.isBlank(pollAccount.getVotingId()) && + StringUtils.isBlank(pollAccount.getEmail()); + return result; + } + + protected Map<Integer, Choice> buildTextChoices() { + Map<Integer, Choice> result = Maps.newTreeMap(); + + String fieldPrefix = getChoiceFieldPrefix(ChoiceType.TEXT); + + int maxNumber = 0; + + for (String paramName : getParameters().keySet()) { + + Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName); + if (matcher.matches()) { + + // found a text choice name + + String paramValue = getNonEmptyParameterValue(paramName); + + // can keep this none empty text choice name + + Integer choiceNumber = Integer.valueOf(matcher.group(1)); + + if (choiceNumber > maxNumber) { + maxNumber = choiceNumber; + } + String choicePrefix = fieldPrefix + choiceNumber; + Choice choice = createChoice(new ChoiceImpl(), + choicePrefix, + paramValue); + if (!isTextChoiceEmpty(choice)) { + + // This is not an empty choice keep it + result.put(choiceNumber, choice); + + // keep order + int order = getIntegerValue(choicePrefix + ".order"); + choicesOrder.put(order, choiceNumber); + } + } + } + result = reindexChoiceMap(result, maxNumber); + + int size = result.size(); + if (log.isInfoEnabled()) { + log.info("nbTextChoices (from request) = " + size); + } + logChoice(result); + return result; + } + + protected Map<Integer, Choice> buildDateChoices() { + Map<Integer, Choice> result = Maps.newTreeMap(); + + String fieldPrefix = getChoiceFieldPrefix(ChoiceType.DATE); + + int maxNumber = 0; + for (String paramName : getParameters().keySet()) { + + Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName); + if (matcher.matches()) { + + // found a text choice name + + String paramValue = getNonEmptyParameterValue(paramName); + + // can keep this none empty text choice name + + Integer choiceNumber = Integer.valueOf(matcher.group(1)); + if (choiceNumber > maxNumber) { + maxNumber = choiceNumber; + } + String choicePrefix = fieldPrefix + choiceNumber; + + PollDateChoice choice = createChoice(new PollDateChoice(), + choicePrefix, + paramValue); + if (StringUtils.isNotBlank(paramValue)) { + Date date = DateConverter.convertFromString(paramValue); + choice.setDate(date); + } + + if (!isDateChoiceEmpty(choice)) { + + // This is not an empty choice keep it + result.put(choiceNumber, choice); + + // keep order + int order = getIntegerValue(choicePrefix + ".order"); + choicesOrder.put(order, choiceNumber); + } + } + } + result = reindexChoiceMap(result, maxNumber); + + int size = result.size(); + if (log.isInfoEnabled()) { + log.info("nbDateChoices (from request) = " + size); + } + logChoice(result); + return result; + } + + protected Map<Integer, Choice> buildImageChoices() { + Map<Integer, Choice> result = Maps.newTreeMap(); + + String fieldPrefix = getChoiceFieldPrefix(ChoiceType.IMAGE); + + int maxNumber = 0; + + Map<String, String> parametersToSwitch = Maps.newTreeMap(); + + for (String paramName : getParameters().keySet()) { + + Matcher matcher = IMAGE_CHOICE_DESCRIPTION_PATTERN.matcher(paramName); + if (matcher.matches()) { + + // found an image choice description + // Note: We can not use as for other choices (text and date) + // the name since there is no name parameter submitted... + // the upload filed will implies a such parameter... + + Integer choiceNumber = Integer.valueOf(matcher.group(1)); + if (choiceNumber > maxNumber) { + maxNumber = choiceNumber; + } + + String choicePrefix = fieldPrefix + choiceNumber; + + PollImageChoice choice = createChoice(new PollImageChoice(), + choicePrefix, + null); + String location = getNonEmptyParameterValue( + choicePrefix + ".newLocation"); + if (StringUtils.isNotBlank(location)) { + + // found a real upload file (not jus the location of an + // already choice uploaded choice + choice.setLocation(location); + + // ok so now use also newName + String paramValue = getNonEmptyParameterValue( + choicePrefix + ".newName"); + choice.setName(paramValue); + + parametersToSwitch.put(choicePrefix + ".newLocation", + choicePrefix + ".location"); + + parametersToSwitch.put(choicePrefix + ".newName", + choicePrefix + ".name"); + + } else { + + // try with old location + location = getNonEmptyParameterValue( + choicePrefix + ".location"); + choice.setLocation(location); + + String paramValue = getNonEmptyParameterValue( + choicePrefix + ".name"); + choice.setName(paramValue); + } + + if (!isImageChoiceEmpty(choice)) { + + // This is not an empty choice keep it + result.put(choiceNumber, choice); + + // keep order + int order = getIntegerValue(choicePrefix + ".order"); + choicesOrder.put(order, choiceNumber); + } + } + } + + // switch new uploaded values + for (Map.Entry<String, String> entry : parametersToSwitch.entrySet()) { + String paramNameSource = entry.getKey(); + String paramNameTarget = entry.getValue(); + String[] valueToSwitch = getParameters().remove(paramNameSource); + getParameters().put(paramNameTarget, valueToSwitch); + } + result = reindexChoiceMap(result, maxNumber); + int size = result.size(); + if (log.isInfoEnabled()) { + log.info("nbImageChoices (from request) = " + size); + } + logChoice(result); + return result; + } + + protected Map<Integer, VotingList> buildVotingLists(PollType pollType) { + Map<Integer, VotingList> result = Maps.newTreeMap(); + + int maxNumber = 0; + + String votingListPrefix = "votingList" + pollType.name(); + + // get all votingList_xxx parameters + Set<String> votingListParameterNames = Sets.filter( + getParameters().keySet(), + new StringStartWithPredicate(votingListPrefix)); + + Pattern votingListPattern = Pattern.compile( + "(" + votingListPrefix + ")_(\\d+)\\.name"); + + for (String paramName : votingListParameterNames) { + + Matcher matcher = votingListPattern.matcher(paramName); + + if (matcher.matches()) { + + // found a voting list name + + int votingListNumber = Integer.valueOf(matcher.group(2)); + + buildVotingList(paramName, + votingListPrefix + "_" + votingListNumber, + votingListNumber, + result + ); + maxNumber = Math.max(maxNumber, votingListNumber); + } + } + + result = reindexMap(result, maxNumber); + + int size = result.size(); + if (log.isInfoEnabled()) { + log.info("nbVotingList [" + pollType + "] (from request) = " + size); + } + + // add personToList maps to session (but just now, since votingList + // could have been reindex) + for (Map.Entry<Integer, VotingList> entry : result.entrySet()) { + VotingList votingList = entry.getValue(); + + if (!votingList.isPollAccountPersonToListEmpty()) { + List<PersonToList> personToList = + votingList.getPollAccountPersonToList(); + + Map<Integer, PersonToList> personToListMap = Maps.newTreeMap(); + int index = 0; + for (PersonToList toList : personToList) { + personToListMap.put(index++, toList); + } + } + } + + return result; + } + + private double getDoubleValue(String parameterName) { + String parameterValue = getNonEmptyParameterValue(parameterName); + double result = 0; + if (StringUtils.isNotEmpty(parameterValue)) { + + try { + result = Double.valueOf(parameterValue); + } catch (NumberFormatException e) { + //bad conversion, will be treated later + if (log.isDebugEnabled()) { + log.debug("Bad double conversion from param [" + + parameterName + "] : " + parameterValue); + } + } + } + return result; + } + + private int getIntegerValue(String parameterName) { + String parameterValue = getNonEmptyParameterValue(parameterName); + int result = 0; + if (StringUtils.isNotEmpty(parameterValue)) { + + try { + result = Integer.valueOf(parameterValue); + } catch (NumberFormatException e) { + //bad conversion, will be treated later + if (log.isDebugEnabled()) { + log.debug("Bad double conversion from param [" + + parameterName + "] : " + parameterValue); + } + } + } + return result; + } + + private int buildVotingList(String votingListParameterName, + String votingListPrefix, + int votingListNumber, + Map<Integer, VotingList> result) { + + String paramValue = getNonEmptyParameterValue(votingListParameterName); + + VotingList votingList = new VotingListImpl(); + + votingList.setName(paramValue); + + double weight = getDoubleValue(votingListPrefix + ".weight"); + votingList.setWeight(weight); + + String topiaId = getNonEmptyParameterValue(votingListPrefix + ".topiaId"); + votingList.setTopiaId(topiaId); + + result.put(votingListNumber, votingList); + + String personToListPrefix = votingListPrefix + "PersonToList_"; + + // get all personToList parameters + Set<String> votingListParameterNames = Sets.filter( + getParameters().keySet(), + new StringStartWithPredicate(personToListPrefix)); + + Pattern personToListNamePattern = Pattern.compile( + personToListPrefix + "(\\d+)\\.votingId"); + + Map<Integer, PersonToList> personToLists = Maps.newTreeMap(); + + int maxPersonToListNumber = 0; + + // let's build personToList list + for (String personToListNameParameter : votingListParameterNames) { + + Matcher matcher = personToListNamePattern.matcher( + personToListNameParameter); + + if (matcher.matches()) { + + int personToListNumber = buildPersonToList( + personToListPrefix, + personToListNameParameter, + matcher, + votingListNumber, + personToLists); + + maxPersonToListNumber = Math.max(maxPersonToListNumber, + personToListNumber); + } + } + + personToLists = reindexMap(personToLists, maxPersonToListNumber); + + for (PersonToList personToList : personToLists.values()) { + votingList.addPollAccountPersonToList(personToList); + } + + return votingListNumber; + } + + private int buildPersonToList(String personToListPrefix, + String paramName, + Matcher personToListMatcher, + int votingListNumber, + Map<Integer, PersonToList> result) { + + int personToListNumber = Integer.valueOf(personToListMatcher.group(1)); + + PersonToList personToList = new PersonToListImpl(); + + PollAccount account = new PollAccountImpl(); + personToList.setPollAccount(account); + + account.setVotingId(getNonEmptyParameterValue(paramName)); + + String prefix = personToListPrefix + personToListNumber; + + double weight = getDoubleValue(prefix + ".weight"); + personToList.setWeight(weight); + + String topiaId = getNonEmptyParameterValue(prefix + ".topiaId"); + personToList.setTopiaId(topiaId); + + String email = getNonEmptyParameterValue(prefix + ".email"); + account.setEmail(email); + + String accountId = getNonEmptyParameterValue(prefix + ".accountId"); + account.setAccountId(accountId); + + if (!isPersonToListEmpty(personToList)) { + + // can keep this not empty personToList + result.put(personToListNumber, personToList); + } + return personToListNumber; + } + + private <C extends Choice> C createChoice(C choice, + String prefix, + String name) { + String description = getNonEmptyParameterValue(prefix + ".description"); + String topiaId = getNonEmptyParameterValue(prefix + ".topiaId"); + choice.setName(name); + choice.setDescription(description); + choice.setTopiaId(topiaId); + return choice; + } + + 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()); + } + } + } + + protected <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) { + Map<Integer, T> 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) { + T choice = result.get(number); + result2.put(i++, choice); + } + } else { + result2 = result; + } + return result2; + } + + protected <T> Map<Integer, T> reindexChoiceMap(Map<Integer, T> result, int maxNumber) { + Map<Integer, T> result2 = Maps.newTreeMap(); + + for (Integer choiceOrder : choicesOrder.keySet()) { + Integer choiceNumber = choicesOrder.get(choiceOrder); + T choice = result.get(choiceNumber); + if (choice != null) { + result2.put(choiceOrder, choice); + } + } + +// 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) { +// T choice = result.get(number); +// result2.put(i++, choice); +// } +// } else { +// result2 = result; +// } + return result2; + } + + + protected String getNonEmptyParameterValue(String paramName) { + String[] paramValues = getParameters().get(paramName); + String result = null; + if (paramValues != null && paramValues.length == 1) { + String paramValue = paramValues[0]; + if (StringUtils.isNotEmpty(paramValue)) { + result = paramValue; + } + } + return result; + } + + private String getChoiceFieldPrefix(ChoiceType choiceType) { + String result = null; + switch (choiceType) { + + case TEXT: + result = "textChoice_"; + break; + case DATE: + result = "dateChoice_"; + break; + case IMAGE: + result = "imageChoice_"; + break; + } + return result; + } + + private static class StringStartWithPredicate implements Predicate<String> { + private final String prefix; + + public StringStartWithPredicate(String prefix) { + this.prefix = prefix; + } + + @Override + public boolean apply(String input) { + return input.startsWith(prefix); + } + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,54 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.chorem.pollen.business.persistence.Poll; + +/** + * Clones a poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class ClonePoll extends AbstractPollForm { + + private static final long serialVersionUID = 1L; + + @Override + public boolean isClone() { + return true; + } + + @Override + public boolean isEdit() { + return false; + } + + @Override + protected Poll savePoll(Poll poll) { + poll = getPollService().createPoll(poll); + addFlashMessage(_("pollen.information.poll.created", poll.getTitle())); + return poll; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,54 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.chorem.pollen.business.persistence.Poll; + +/** + * Creates a poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class CreatePoll extends AbstractPollForm { + + private static final long serialVersionUID = 1L; + + @Override + public boolean isClone() { + return false; + } + + @Override + public boolean isEdit() { + return false; + } + + @Override + protected Poll savePoll(Poll poll) { + poll = getPollService().createPoll(poll); + addFlashMessage(_("pollen.information.poll.created", poll.getTitle())); + return poll; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayDateChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayDateChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayDateChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,47 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.chorem.pollen.bean.PollDateChoice; + +/** + * To generate the display for a date choice. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DisplayDateChoice extends AbstractDisplayChoice { + + private static final long serialVersionUID = 1L; + + public static final String CHOICE_TOKEN = "dateChoice"; + + @Override + protected PollDateChoice createEmptyChoice() { + PollDateChoice result = new PollDateChoice(); + result.setName(""); + result.setDescription(""); + result.setDate(null); + return result; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayDateChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayImageChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayImageChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayImageChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayImageChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,48 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.chorem.pollen.bean.PollImageChoice; +import org.chorem.pollen.business.persistence.Choice; + +/** + * To generate the display for a image choice. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DisplayImageChoice extends AbstractDisplayChoice { + + private static final long serialVersionUID = 1L; + + public static final String CHOICE_TOKEN = "imageChoice"; + + @Override + protected Choice createEmptyChoice() { + PollImageChoice result = new PollImageChoice(); + result.setName(""); + result.setDescription(""); + result.setLocation(""); + return result; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayImageChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayPersonToList.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayPersonToList.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayPersonToList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,109 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.PersonToList; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * To display a personToList (use at a poll creation). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DisplayPersonToList extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + public static final String TOKEN = "personToList"; + + /** Logger. */ + private static final Log log = LogFactory.getLog(DisplayPersonToList.class); + + public static String getPersonToListTokenId(String votingListTokenId, + int votingListNumber) { + return votingListTokenId + "_" + votingListNumber + TOKEN; + } + + public static String getPersonToListErrorTokenId(String votingListTokenId, + int votingListNumber, + int personToListNumber) { + return getPersonToListErrorTokenId(getPersonToListTokenId(votingListTokenId, votingListNumber), personToListNumber); + } + + public static String getPersonToListErrorTokenId(String personToListTokenId, + int personToListNumber) { + return personToListTokenId + "_error_" + personToListNumber; + } + + /** Type of the voting list. */ + protected String votingListType; + + /** Number of the vontingList container. */ + protected int votingListNumber; + + /** Number of person to display. */ + protected int personToListNumber; + + protected PersonToList personToList; + + public int getVotingListNumber() { + return votingListNumber; + } + + public void setVotingListNumber(int votingListNumber) { + this.votingListNumber = votingListNumber; + } + + public String getVotingListType() { + return votingListType; + } + + public void setVotingListType(String votingListType) { + this.votingListType = votingListType; + } + + public int getPersonToListNumber() { + return personToListNumber; + } + + public void setPersonToListNumber(int personToListNumber) { + this.personToListNumber = personToListNumber; + } + + public PersonToList getPersonToList() { + return personToList; + } + + @Override + public String execute() throws Exception { + + if (personToList == null) { + personToList = getPollService().getNewPersonToList(null); + } + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayPersonToList.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayTextChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayTextChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayTextChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayTextChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,47 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.ChoiceImpl; + +/** + * To generate the display for a text choice. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DisplayTextChoice extends AbstractDisplayChoice { + + private static final long serialVersionUID = 1L; + + public static final String CHOICE_TOKEN = "textChoice"; + + @Override + protected Choice createEmptyChoice() { + Choice result = new ChoiceImpl(); + result.setName(""); + result.setDescription(""); + return result; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayTextChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayVotingList.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayVotingList.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayVotingList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,88 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import com.google.common.base.Function; +import org.chorem.pollen.business.persistence.PersonToList; +import org.chorem.pollen.business.persistence.VotingList; +import org.chorem.pollen.services.PollenServiceFunctions; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * To display a voting list of a poll (use at a poll creation). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DisplayVotingList extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + /** Type of the voting list. */ + protected String votingListType; + + /** Number of person to display. */ + protected int votingListNumber; + + /** The voting list ot display. */ + protected VotingList votingList; + + public int getVotingListNumber() { + return votingListNumber; + } + + public void setVotingListNumber(int votingListNumber) { + this.votingListNumber = votingListNumber; + } + + public VotingList getVotingList() { + return votingList; + } + + public String getVotingListType() { + return votingListType; + } + + public void setVotingListType(String votingListType) { + this.votingListType = votingListType; + } + + public int getStartNumber() { + return 0; + } + + @Override + public String execute() throws Exception { + + Function<PersonToList, PersonToList> persontoListCreator = + PollenServiceFunctions.newPersonToListCreator(); + Function<VotingList, VotingList> votingListCreator = + PollenServiceFunctions.newVotingListCreator(persontoListCreator); + + votingList = votingListCreator.apply(null); + + PollenServiceFunctions.fillVotingList(votingList, + persontoListCreator, 5); + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/DisplayVotingList.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,58 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.services.exceptions.PollNotFoundException; + +/** + * Edit a poll (load it via {@link #input()}), and save it + * via {@link #execute()}). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class EditPoll extends AbstractPollForm { + + private static final long serialVersionUID = 1L; + + @Override + public boolean isClone() { + + // in edit mode never can be a clone + return false; + } + + @Override + public boolean isEdit() { + return true; + } + + @Override + protected Poll savePoll(Poll poll) throws PollNotFoundException { + poll = getPollService().updatePoll(poll); + addFlashMessage(_("pollen.information.poll.updated", poll.getTitle())); + return poll; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ImportPersonListToVotingList.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ImportPersonListToVotingList.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ImportPersonListToVotingList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,113 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import com.google.common.base.Function; +import org.chorem.pollen.business.persistence.PersonList; +import org.chorem.pollen.business.persistence.PersonToList; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.VotingList; +import org.chorem.pollen.services.PollenServiceFunctions; +import org.chorem.pollen.services.impl.PollService; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Load in session a personToList to import into a votingList. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ImportPersonListToVotingList extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + /** Type of the voting list. */ + protected String votingListType; + + /** Number of person to display. */ + protected int votingListNumber; + + /** The voting list ot display. */ + protected VotingList votingList; + + protected int startNumber; + + protected String personListId; + + public int getVotingListNumber() { + return votingListNumber; + } + + public int getStartNumber() { + return startNumber; + } + + public String getVotingListType() { + return votingListType; + } + + public VotingList getVotingList() { + return votingList; + } + + public void setVotingListNumber(int votingListNumber) { + this.votingListNumber = votingListNumber; + } + + public void setVotingListType(String votingListType) { + this.votingListType = votingListType; + } + + public void setStartNumber(int startNumber) { + this.startNumber = startNumber; + } + + public void setPersonListId(String personListId) { + this.personListId = personListId; + } + + @Override + public String execute() throws Exception { + + PersonList favoriteList = + getFavoriteService().getFavoriteList(getPollenUserAccount(), personListId); + + Function<PersonToList, PersonToList> persontoListCreator = + PollenServiceFunctions.newPersonToListCreator(); + + Function<VotingList, VotingList> votingListCreator = + PollenServiceFunctions.newVotingListCreator(persontoListCreator); + + votingList = votingListCreator.apply(null); + + PollService pollService = getPollService(); + + for (PollAccount pollAccount : favoriteList.getPollAccount()) { + + PersonToList p = pollService.getNewPersonToList(pollAccount); + votingList.addPollAccountPersonToList(p); + } + + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ImportPersonListToVotingList.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/SelectPersonListToVotingList.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/SelectPersonListToVotingList.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/SelectPersonListToVotingList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,91 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.form; + +import com.google.common.collect.Maps; +import org.chorem.pollen.PollenFunctions; +import org.chorem.pollen.business.persistence.PersonList; +import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +import java.util.List; +import java.util.Map; + +/** + * Select a person list to add into an existing voting list. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class SelectPersonListToVotingList extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + protected String votingListType; + + protected int votingListNumber; + + protected String containerId; + + protected Map<String, PersonList> personList; + + public Map<String, PersonList> getPersonList() { + return personList; + } + + public int getVotingListNumber() { + return votingListNumber; + } + + public void setVotingListNumber(int votingListNumber) { + this.votingListNumber = votingListNumber; + } + + public String getVotingListType() { + return votingListType; + } + + public void setVotingListType(String votingListType) { + this.votingListType = votingListType; + } + + public String getContainerId() { + return containerId; + } + + public void setContainerId(String containerId) { + this.containerId = containerId; + } + + @Override + public String execute() throws Exception { + + UserAccount userAccount = getPollenUserAccount(); + List<PersonList> personLists = + getFavoriteService().getFavoriteLists(userAccount); + + personList = Maps.uniqueIndex(personLists, PollenFunctions.ENTITY_BY_ID); + + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/SelectPersonListToVotingList.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the all poll form actions (create, clone and edit poll). + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.poll.form; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the all poll actions. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.poll; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java (from rev 3595, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,545 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Charsets; +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.PollenTechnicalException; +import org.chorem.pollen.bean.PollResult; +import org.chorem.pollen.bean.PollResultList; +import org.chorem.pollen.bean.PollUrl; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.Comment; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.PollCommentVisibility; +import org.chorem.pollen.business.persistence.PollVoteVisibility; +import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.business.persistence.Vote; +import org.chorem.pollen.business.persistence.VoteToChoice; +import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.common.PollType; +import org.chorem.pollen.services.exceptions.PollAccountNotFound; +import org.chorem.pollen.services.exceptions.PollNotFoundException; +import org.chorem.pollen.ui.PollenUIUtils; +import org.chorem.pollen.ui.actions.PageSkin; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; +import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Date; +import java.util.List; + +/** + * Abstract action for actions on the vote poll page. + * + * @author tchemit <chemit@codelutin.com> + * @author fdesbois <fdesbois@codelutin.com> + * @since 1.3 + */ +public abstract class AbstractVoteAction extends PollenActionSupport implements ParameterAware, PollUriAware, PollenUserSecurityAware { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(AbstractVoteAction.class); + + public static final String PREPARE_VOTE_PAGE = "prepareVotePage"; + + /** + * Loaded poll. + * + * @since 1.3 + */ + private Poll poll; + + /** + * Is feed exists for this poll ? + * + * @since 1.3 + */ + private boolean feedFileExisting; + + /** + * Is user the poll's creator ? + * + * @since 1.3 + */ + private boolean creatorUser; + + /** + * Loaded poll account (from the pollUri). + * + * @since 1.3 + */ + private PollAccount pollAccount; + + /** + * Is vote allowed for current user? + * + * @since 1.3 + */ + private boolean voteAllowed; + + /** + * Is current user can go to results. + * + * @since 1.4 + */ + private boolean resultAllowed; + + /** + * All votes for the poll. + * + * @since 1.3 + */ + private List<Vote> votes; + + /** + * Current vote to treat (for create/updatevote action). + * + * @since 1.3 + */ + private Vote vote; + + /** + * Comment author to display in UI. + * + * @since 1.3 + */ + private String commentAuthor; + + /** + * Results of the poll. + * + * @since 1.3 + */ + private List<PollResult> results; + + /** + * List of comments to display. + * + * @since 1.3 + */ + private List<Comment> comments; + + protected AbstractVoteAction() { + super(PageSkin.VOTE); + } + + /** + * @return {@code true} if moderation is possible, {@code false} otherwise + * @since 1.4 + */ + public abstract boolean isModerate(); + + public Poll getPoll() { + return poll; + } + + public PollAccount getPollAccount() { + return pollAccount; + } + + public List<Vote> getVotes() { + return votes; + } + + public Vote getVote() { + return vote; + } + + public List<PollResult> getResults() { + return results; + } + + public List<Comment> getComments() { + return comments; + } + + public String getVoteSizeMessage() { + String result = PollenUIUtils.getVoteSizeMessage(getPoll(), + getLocale()); + return result; + } + + public String getVoteCountingTypeName() { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getStrategyName(getLocale()); + return result; + } + + public String getVoteCountingTypeHelp() { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getStrategyHelp(getLocale()); + return result; + } + + /** + * Is comment can be displayed (and then added) on this poll. + * + * @return {@code true} if comments can be displayed and then added or + * removed for this poll. + * @since 1.4.5 + */ + public boolean isCommentAllowed() { + PollCommentVisibility pollCommentVisibility = + getPoll().getPollCommentVisibility(); + return pollCommentVisibility == PollCommentVisibility.EVERYBODY; + } + + /** + * Retourne si le choix fait partie du vote (s'il a été renseigné par le + * votant). + * + * @param choice le choix concerné + * @return true si le choix est dans le vote + */ + public boolean isChoiceInVote(VoteToChoice choice) { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + boolean result = strategy.isChoiceInVote(choice.getVoteValue()); + return result; +// Integer voteValue = choice.getVoteValue(); +// boolean result = false; +// if (choice != null) { +// switch (poll.getVoteCountingType()) { +// case NORMAL: +// result = voteValue > 0; +// break; +// case PERCENTAGE: +// result = true; +// break; +// case CONDORCET: +// result = voteValue < 100; +// break; +// case NUMBER: +// result = voteValue >= 0; +// } +// } +// return result; + } + + public String getChoiceValue(VoteToChoice choice) { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getDisplayVoteValue(choice.getVoteValue()); + return result; +// switch (poll.getVoteCountingType()) { +// case NORMAL: +// result = "OK"; +// break; +// default: +// result = choice.getVoteValue() + ""; +// } +// return result; + } + + public String getCommentAuthor() { + if (commentAuthor == null) { + + UserAccount user = getUserSecurityContext().getUserAccount(); + if (user == null) { + + // Use current pollAccount name for comment + commentAuthor = getPollAccount().getVotingId(); + + } else { + + // Connecter user name + commentAuthor = user.getDisplayName(); + } + } + return commentAuthor; + } + + public String getSummaryUrl() { + PollUrl url = getPollUrlService().getPollSummaryUrl(poll); + url.getPollUri().setAccountId(getUserSecurityContext().getAccountId()); + return url.getUrl(); + } + + public String getResultUrl() { + PollUrl url = getPollUrlService().getPollResultUrl(poll); + url.getPollUri().setAccountId(getUserSecurityContext().getAccountId()); + getUserSecurityContext().removeAccountIdWhenConnected(url); + return url.getUrl(); + } + + public String getVoteMessages() { + return _("pollen.common.voteNbVotes", poll.sizeVote()); + } + + public boolean isFeedFileExisting() { + return feedFileExisting; + } + + public boolean isCreatorOrAdmin() { + return creatorUser || isUserAdmin(); + } + + public boolean isAccountFieldDisplayed() { + return !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll(); + } + + public boolean isPollChoiceOrVoteStarted() { + Date now = serviceContext.getCurrentTime(); + return poll.isAddChoiceStarted(now) || poll.isStarted(now); + } + + public boolean isAnonymousVote() { + PollVoteVisibility pollVoteVisibility = poll.getPollVoteVisibility(); + return pollVoteVisibility == PollVoteVisibility.NOBODY; + } + + public boolean isPollChoiceRunning() { + Date now = serviceContext.getCurrentTime(); + return poll.isAddChoiceRunning(now); + } + + public boolean isPollStarted() { + Date now = serviceContext.getCurrentTime(); + return poll.getBeginDate() == null || poll.getBeginDate().before(now); + } + + public boolean isPollFinished() { + Date now = serviceContext.getCurrentTime(); + return poll.getEndDate() != null && poll.getEndDate().before(now); + } + + public boolean isDescNull(Choice choice) { + return StringUtils.isEmpty(choice.getDescription()); + } + + public boolean isFreePoll() { + return poll.isPollFree(); + } + + public boolean isRestrictedPoll() { + return poll.getPollType() == PollType.RESTRICTED; + } + + public boolean isGroupPoll() { + return poll.getPollType() == PollType.GROUP; + } + + public boolean isTextType() { + return poll.getChoiceType() == ChoiceType.TEXT; + } + + public boolean isDateType() { + return poll.getChoiceType() == ChoiceType.DATE; + } + + public boolean isImageType() { + return poll.getChoiceType() == ChoiceType.IMAGE; + } + + public boolean isVoteAllowed() { + return voteAllowed; + } + + public boolean isResultAllowed() { + return resultAllowed; + } + + public String getPollCreatorName() { + PollAccount creator = poll.getCreator(); + String result = creator.getVotingId(); + if (StringUtils.isBlank(result)) { + result = creator.getEmail(); + } + if (StringUtils.isBlank(result)) { + result = _("pollen.common.undefined"); + } + return result; + } + + public String getPollBeginDate() { + Date date = poll.getBeginDate(); + String result = date == null ? _("pollen.common.undefined") : + getPollService().decorateDate(date); + return result; + } + + public String getPollEndDate() { + Date date = poll.getEndDate(); + String result = date == null ? _("pollen.common.undefined") : + getPollService().decorateDate(date); + return result; + } + + public boolean isModifyVoteAllowed(Vote vote) { + return getSecurityService().isCanModifyVote(getUserSecurityContext(), + vote.getTopiaId()); + } + + public boolean isDeleteCommentAllowed(Comment comment) { + return getSecurityService().isCanDeleteComment(getUserSecurityContext(), + comment); + } + + public boolean isDeleteVoteAllowed(Vote vote) { + return getSecurityService().isCanDeleteVote(getUserSecurityContext(), + vote.getTopiaId()); + } + + public String getResultValue(Choice choice) { + + String val = getPollResultsService().getResultValue(choice, results); + return val; + } + + public String getChoiceFragment() { + VoteCountingStrategy strategy = getVoteCountingStrategy(poll); + String result = + "displayVote_" + strategy.getVoteValueEditorType().name() + ".jsp"; + return result; + } + + public Date getChoiceAsDate(Choice choice) { + return new Date(Long.valueOf(choice.getName())); + } + + public void setCommentAuthor(String commentAuthor) { + this.commentAuthor = commentAuthor; + } + + public String prepareVotePage() throws Exception { + + boolean moderate = isModerate(); + + loadPoll(); + + // Current poll account + loadPollAccount(); + + // All votes + // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount + votes = getVoteService().getAllVotes(poll); + + // is vote allowed ? + if (moderate) { + + // while moderate vote, no way to vote + voteAllowed = false; + + } else { + voteAllowed = getSecurityService().isCanVote(getUserSecurityContext()); + } + + // is can display result link ? + resultAllowed = getSecurityService().isCanAccessResult(getUserSecurityContext()); + + if (voteAllowed) { + + // load modifiable vote + vote = getVoteService().getVoteEditable(poll, pollAccount); + } + + // load poll results + PollResultList pollResultList = + getPollResultsService().getResults(poll); + + results = pollResultList.getPollResults(); + + if (log.isDebugEnabled()) { + for (PollResult res : results) { + log.debug(res.getName() + ": " + res.getValue() + + ", (voteCounting=" + res.getVoteCountingType() + + ", byGroup=" + res.isByGroup() + ")"); + } + } + + // load comments + comments = getPollCommentService().getAllComments(poll.getPollId()); + + feedFileExisting = getPollFeedService().isFeedExists(poll); + + creatorUser = getUserSecurityContext().isCreator(); + + if (log.isInfoEnabled()) { + Date now = serviceContext.getCurrentTime(); + log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted()); + log.info("pollChoiceRunning = " + isPollChoiceRunning()); + log.info("pollRunning = " + poll.isRunning(now)); + log.info("accountFieldDisplayed = " + isAccountFieldDisplayed()); + log.info("creatorUser = " + creatorUser); + } + return INPUT; + } + + public String escapeLineBreak(String text) { + return text; + } + + public String getImageChoiceName(Choice choice) { + String name = choice.getName(); + try { + String result = URLEncoder.encode(name, Charsets.UTF_8.name()); + return result; + } catch (UnsupportedEncodingException e) { + throw new PollenTechnicalException( + "Could not encode name " + name, e); + } + } + + protected void loadPollAccount() throws PollAccountNotFound { + + // Current poll account + pollAccount = getPollService().getPollAccountEditable( + getUserSecurityContext().getAccountId(), + getUserSecurityContext().getUserAccount(), poll); + } + + protected void loadPoll() throws PollNotFoundException { + +// setPollUri(getUserSecurityContext().getPollUri()); + + poll = getUserSecurityContext().getPoll(); + +// // Ensure uri for poll and pollAccount loading +// PollUri pollUri = getPollUri(); +// if (pollUri == null) { +// String[] values = getParameters().get(PARAM_POLL_URI); +// pollUri = PollUriConverter.convertFromString(values); +// setPollUri(pollUri); +// } +// +// String pollId = pollUri.getPollId(); +// if (StringUtils.isNotEmpty(pollId)) { +// poll = getPollService().getExistingPollByPollId(pollId); +// } +//// Preconditions.checkNotNull(poll, +//// "Can't load poll with id = [" + pollId + "]"); +//// +//// if (log.isDebugEnabled()) { +//// log.debug("Poll TopiaId: " + poll.getTopiaId()); +//// } + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,138 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.opensymphony.xwork2.Preparable; +import com.opensymphony.xwork2.interceptor.annotations.InputConfig; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.bean.PollImageChoice; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.services.PollenServiceFunctions; +import org.chorem.pollen.services.exceptions.PollNotFoundException; +import org.chorem.pollen.ui.actions.FileUploadAware; + +import java.io.File; + +/** + * To add a poll comment. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class AddChoice extends AbstractVoteAction implements Preparable, FileUploadAware { + + private static final long serialVersionUID = 1L; + + protected Choice choice; + + private File imageChoice; + + private String imageChoiceFileName; + + public Choice getChoice() { + return choice; + } + + @Override + public void addFile(int index, File file) { + imageChoice = file; + } + + @Override + public void addFileContentType(int index, String contentType) { + } + + @Override + public void addFileName(int index, String fileName) { + imageChoiceFileName = fileName; + } + + @Override + public boolean isModerate() { + return false; + } + + @Override + public void prepare() throws PollNotFoundException { + + loadPoll(); + + ChoiceType choiceType = getPoll().getChoiceType(); + choice = getPollService().getNewChoice(choiceType); + + // Push image choice data from uploaded file + if (ChoiceType.IMAGE == choiceType && imageChoice != null) { + + String fileName = imageChoiceFileName; + String location = imageChoice.getAbsolutePath(); + choice.setName(fileName); + ((PollImageChoice) choice).setLocation(location); + } + } + + @Override + public void validate() { + + Poll poll = getPoll(); + + ChoiceType choiceType = poll.getChoiceType(); + + String propName = PollenServiceFunctions.CHOICE_TYPE_TO_PROPERTY_NAME.apply(choiceType); + + String choiceName = choice.getName(); + + // -- Validate value notEmpty + if (StringUtils.isBlank(choiceName)) { + String typeLabel = getText(choiceType.getI18nKey()); + addFieldError("choice." + propName, + _("pollen.error.choice.empty", typeLabel)); + } else { + + if (!poll.isChoiceEmpty()) { + + // check that the choice is not already used + + for (Choice pollChoice : poll.getChoice()) { + String pollChoiceName = pollChoice.getName(); + if (pollChoiceName.equals(choiceName)) { + addFieldError("choice." + propName, + _("pollen.error.poll.choice.already.used.name")); + break; + } + } + } + } + } + + @InputConfig(methodName = PREPARE_VOTE_PAGE) + @Override + public String execute() throws Exception { + + getPollService().addChoice(getPollUri().getPollId(), choice); + + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddComment.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddComment.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddComment.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,93 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.opensymphony.xwork2.Preparable; +import com.opensymphony.xwork2.interceptor.annotations.InputConfig; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.business.persistence.Comment; + +/** + * To add a poll comment. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class AddComment extends AbstractVoteAction implements Preparable { + + private static final long serialVersionUID = 1L; + + /** + * Text of the comment to add. + * + * @since 1.3 + */ + private String commentText; + + public void setCommentText(String commentText) { + this.commentText = commentText; + } + + public String getCommentText() { + return commentText; + } + + @Override + public boolean isModerate() { + return false; + } + + @Override + public void prepare() throws Exception { + + loadPoll(); + loadPollAccount(); + } + + @Override + public void validate() { + + if (StringUtils.isBlank(getCommentAuthor())) { + addFieldError("commentAuthor", _("pollen.error.comment.name.empty")); + } + + if (StringUtils.isBlank(getCommentText())) { + addFieldError("commentText", _("pollen.error.comment.text.empty")); + } + } + + @InputConfig(methodName = PREPARE_VOTE_PAGE) + @Override + public String execute() throws Exception { + + // prepare a new comment + Comment comment = getPollCommentService().getNewComment( + getPollAccount(), getCommentAuthor(), getCommentText()); + + // create the comment + getPollCommentService().createComment(getPoll(), comment); + + addFlashMessage(_("pollen.information.comment.added")); + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddComment.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,65 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To confirm delete of a poll choice. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ConfirmDeleteChoice extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + protected String choiceId; + + protected Choice choice; + + public void setChoiceId(String choiceId) { + this.choiceId = choiceId; + } + + public Choice getChoice() { + return choice; + } + + @Override + public String execute() throws Exception { + + Preconditions.checkNotNull(choiceId); + + Poll poll = getUserSecurityContext().getPoll(); + + choice = poll.getChoiceByTopiaId(choiceId); + + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteComment.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteComment.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteComment.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,76 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.business.persistence.Comment; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To confirm a comment delete. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ConfirmDeleteComment extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + /** + * Id of the comment. + * + * @since 1.3 + */ + protected String commentId; + + /** + * Loaded comment to delete. + * + * @since 1.3 + */ + 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); + + Poll poll = getUserSecurityContext().getPoll(); + + comment = poll.getCommentByTopiaId(commentId); + + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteComment.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteVote.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteVote.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteVote.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,76 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.Vote; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To confirm delete of a poll vote + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ConfirmDeleteVote extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + /** + * Id of the vote to delete. + * + * @since 1.3 + */ + protected String voteId; + + /** + * Loaded vote to delete. + * + * @since 1.3 + */ + protected Vote vote; + + public void setVoteId(String voteId) { + this.voteId = voteId; + } + + public Vote getVote() { + return vote; + } + + @Override + public String execute() throws Exception { + + Preconditions.checkNotNull(voteId); + + Poll poll = getUserSecurityContext().getPoll(); + + vote = poll.getVoteByTopiaId(voteId); + + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ConfirmDeleteVote.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteChoice.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteChoice.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteChoice.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,57 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To delete a poll choice + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DeleteChoice extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + protected String choiceId; + + public void setChoiceId(String choiceId) { + this.choiceId = choiceId; + } + + @Override + public String execute() throws Exception { + + Preconditions.checkNotNull(choiceId); + + getPollService().deleteChoice(getPollUri().getPollId(), choiceId); + + addFlashMessage(_("pollen.information.choice.deleted")); + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteChoice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteComment.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteComment.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteComment.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,75 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To delete a poll comment. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DeleteComment extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + /** + * Id of the comment to delete. + * + * @since 1.3 + */ + protected String commentId; + + /** + * Reason for deleting this comment (if any). + * + * @since 1.4 + */ + protected String reason; + + public void setCommentId(String commentId) { + this.commentId = commentId; + } + + public void setReason(String reason) { + this.reason = reason; + } + + @Override + public String execute() throws Exception { + + Preconditions.checkNotNull(commentId); + + Poll poll = getUserSecurityContext().getPoll(); + + getPollCommentService().deleteComment(poll, commentId, reason); + + addFlashMessage(_("pollen.information.comment.deleted")); + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteComment.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteVote.java (from rev 3595, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteVote.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteVote.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,84 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.ui.actions.PollUriAware; +import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +/** + * To delete a poll vote. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class DeleteVote extends PollenActionSupport implements PollenUserSecurityAware, PollUriAware { + + private static final long serialVersionUID = 1L; + + /** + * Id of the vote to delete. + * + * @since 1.3 + */ + protected String voteId; + + /** + * Reason for deleting this vote (if any). + * + * @since 1.4 + */ + protected String reason; + + public void setVoteId(String voteId) { + this.voteId = voteId; + } + + public void setReason(String reason) { + this.reason = reason; + } + + @Override + public String execute() throws Exception { + + Preconditions.checkNotNull(voteId); + + Poll poll = getUserSecurityContext().getPoll(); + + getVoteService().deleteVote(poll, voteId, reason); + + addFlashMessage(_("pollen.information.vote.deleted")); + + if (poll.isPollFree() && + getUserSecurityContext().isWithAccountId() && + !getUserSecurityContext().isCreator()) { + + // remove accountId from url, voter does no longer exists. + getPollUri().setAccountId(null); + } + return SUCCESS; + } + +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/DeleteVote.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ModeratePoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ModeratePoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ModeratePoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,48 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +/** + * To moderate votes and comment of a given poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class ModeratePoll extends AbstractVoteAction { + + private static final long serialVersionUID = 1L; + + @Override + public String input() throws Exception { + + prepareVotePage(); + + addFlashWarning(_("pollen.information.moderate.page")); + return INPUT; + } + + @Override + public boolean isModerate() { + return true; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/ModeratePoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java (from rev 3595, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,218 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $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.vote; + +import com.google.common.base.Preconditions; +import com.opensymphony.xwork2.Preparable; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.bean.PollUrl; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.Vote; +import org.chorem.pollen.business.persistence.VoteToChoice; +import org.chorem.pollen.services.impl.VoteService; +import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; + +/** + * Votes to a poll. + * + * @author tchemit <chemit@codelutin.com> + * @author fdesbois <fdesbois@codelutin.com> + * @since 1.3 + */ +public class VoteForPoll extends AbstractVoteAction implements Preparable { + + private static final Log log = LogFactory.getLog(VoteForPoll.class); + + private static final long serialVersionUID = 1L; + + @Override + public boolean isModerate() { + return false; + } + + @Override + public void prepare() throws Exception { + + prepareVotePage(); + + // Messages + if (getPoll().isClosed()) { + addFlashWarning(_("pollen.information.pollClosed")); + } else if (!isPollStarted()) { + addFlashWarning(_("pollen.information.pollNotStarted")); + } else if (isPollFinished()) { + addFlashWarning(_("pollen.information.pollFinished")); + } else if (!isVoteAllowed()) { + addFlashWarning(_("pollen.information.pollCanNotVote")); + } + if (isPollChoiceRunning()) { + addFlashMessage(_("pollen.information.pollChoiceRunning")); + } + if (!isCommentAllowed()) { + addFlashMessage(_("pollen.information.pollCommentNotAuthorized")); + } + } + + @Override + public void validate() { + + Vote vote = getVote(); + Preconditions.checkNotNull(vote); + + PollAccount pollAccount = getVote().getPollAccount(); + Preconditions.checkNotNull(pollAccount); + + Poll poll = getPoll(); + + if (!vote.isAnonymous()) { + + String name = pollAccount.getVotingId(); + if (StringUtils.isBlank(name)) { + addFieldError("pollAccount.votingId", + _("pollen.error.pollAccount.votingId.required")); + } + + // check if the new pollAccount (topiaId = null) has already voted + if (pollAccount.getTopiaId() == null && + getVoteService().hasAlreadyVoted(poll, name)) { + addFieldError("pollAccount.votingId", + _("pollen.error.user.alreadyVoted", name)); + } + } + + int nbVotes = 0; + int totalValues = 0; + + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + + boolean voteValid = true; + for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { + + Integer value = voteToChoice.getVoteValue(); + + // check if vote is null ? + boolean voteNull = strategy.isVoteValueNull(value); + + if (voteNull) { + // null vote, can skip his validation + continue; + } + + // check if vote value is valid ? + boolean valid = strategy.isVoteValueValid(value); + + if (valid) { + + // ok this vote value is valid, use it + nbVotes++; + totalValues += value; + } else { + + // not a valid vote value, mark it and skip other fields validation + String validMessage = + strategy.getVoteValueNotValidMessage(getLocale()); + addFieldError("vote.choices", validMessage); + voteValid = false; + break; + } + } + if (voteValid) { + + // check that the number of choices is not greater than maxChoiceNb + int maxChoice = getPoll().getMaxChoiceNb(); + if (maxChoice != 0 && nbVotes > maxChoice) { + addFieldError("vote.choices", + _("pollen.error.vote.maxChoiceNb", maxChoice)); + } + + // check that total vote value is ok + if (!strategy.isTotalVoteValueValid(totalValues)) { + + // not valid + String errorMessage = + strategy.getTotalVoteValueNotValidMessage(getLocale()); + addFieldError("vote.choices", errorMessage); + } + } + } + + @Override + public String execute() throws Exception { + + // REMARQUES : + // - pas le droit de modif si le pollAccount est rattaché a un userAccount et qu'on est pas loggé ?!? + // - Ce serait plus simple que l'Admin ne puisse jamais voter, il ne peut que modérer les votes + //TODO tchemit-2012-08-12 Non l'admin est un user comme les autres, + //TODO on doit pouvoir gérer tous les cas de manière simple (enfin je crois) + + Poll poll = getPoll(); + + Vote vote = getVote(); + + VoteService voteService = getVoteService(); + + Vote newVote; + if (StringUtils.isBlank(vote.getTopiaId())) { + + // create a new vote + newVote = voteService.createVote(poll, vote); + } else { + + // update existing vote + newVote = voteService.updateVote(poll, vote); + } + + //TODO tchemit-2012-05-18 Why clean messages and just messages here ? + clearFlashMessages(); + + // For free Poll, display the update Url (useless if user is logged or + // not using a modify url) + if (poll.isPollFree() && + !isUserLoggued() && + StringUtils.isBlank(getUserSecurityContext().getAccountId())) { + + String pollId = poll.getPollId(); + String accountId = newVote.getPollAccount().getAccountId(); + + PollUrl updateUrl = getPollUrlService().getPollVoteUrl( + poll, newVote.getPollAccount()); + + if (log.isDebugEnabled()) { + log.debug(String.format( + "UpdateURL for poll '%s' and account '%s' = %s", + pollId, accountId, updateUrl)); + } + + addFlashMessage( + _("pollen.information.vote.createdWithUpdateUrl", updateUrl)); + + } else { + + addFlashMessage(_("pollen.information.vote.created")); + } + return SUCCESS; + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,7 @@ +/** + * Base Package for the all poll vote actions (means all actions specific to + * the vote page). + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.poll.vote; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/CreateFavoriteListVoter.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/CreateFavoriteListVoter.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/CreateFavoriteListVoter.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -34,8 +34,6 @@ import org.chorem.pollen.ui.actions.PollenActionSupportForEdition; import org.nuiton.util.StringUtil; -import java.util.Map; - /** * Creates a new {@link PollAccount} inside a selected {@link PersonList}. * @@ -46,8 +44,6 @@ private static final long serialVersionUID = 1L; - private Map<String, String[]> parameters; - protected PersonList favoriteList; protected PollAccount pollAccount; @@ -71,7 +67,7 @@ @Override public void prepare() throws Exception { - String[] favoriteListIds = parameters.get("favoriteListId"); + String[] favoriteListIds = getParameters().get("favoriteListId"); Preconditions.checkNotNull(favoriteListIds); Preconditions.checkArgument(favoriteListIds.length == 1); String favoriteListId = favoriteListIds[0]; @@ -138,9 +134,4 @@ } return pollAccount; } - - @Override - public void setParameters(Map<String, String[]> parameters) { - this.parameters = parameters; - } } \ No newline at end of file Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Edit.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -141,4 +141,8 @@ return result; } + public boolean isExists() { + return StringUtils.isNotBlank(pollenUserAccount.getTopiaId()); + } + } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/EditFavoriteListVoter.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/EditFavoriteListVoter.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/EditFavoriteListVoter.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -34,8 +34,6 @@ import org.chorem.pollen.ui.actions.PollenActionSupportForEdition; import org.nuiton.util.StringUtil; -import java.util.Map; - /** * Edits a {@link PollAccount} inside a selected {@link PersonList}. * @@ -46,8 +44,6 @@ private static final long serialVersionUID = 1L; - private Map<String, String[]> parameters; - protected PersonList favoriteList; protected PollAccount editPollAccount; @@ -74,7 +70,7 @@ @Override public void prepare() throws Exception { - String[] favoriteListIds = parameters.get("favoriteListId"); + String[] favoriteListIds = getParameters().get("favoriteListId"); Preconditions.checkNotNull(favoriteListIds); Preconditions.checkArgument(favoriteListIds.length == 1); String favoriteListId = favoriteListIds[0]; @@ -135,8 +131,4 @@ return result; } - @Override - public void setParameters(Map<String, String[]> parameters) { - this.parameters = parameters; - } } \ No newline at end of file Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -1,226 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $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.user; - -import com.google.common.base.Preconditions; -import com.opensymphony.xwork2.Preparable; -import org.apache.commons.lang3.StringUtils; -import org.apache.struts2.interceptor.ParameterAware; -import org.chorem.pollen.business.persistence.PersonList; -import org.chorem.pollen.business.persistence.PollAccount; -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.ui.actions.PollenActionSupportForEdition; -import org.nuiton.util.StringUtil; - -import java.util.Map; - -/** - * Manage a selected favorite lists of a connected user. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class ManageFavoriteList extends PollenActionSupportForEdition implements Preparable, ParameterAware { - - private static final long serialVersionUID = 1L; - - private Map<String, String[]> parameters; - - protected String action; - -// protected String favoriteListId; - - protected PersonList favoriteList; - - protected PollAccount pollAccount; - - public PollAccount getCreatePollAccount() { - return getPollAccount(); - } - - public PollAccount getEditPollAccount() { - return getPollAccount(); - } - - public PollAccount getDeletePollAccount() { - return getPollAccount(); - } - - public PersonList getFavoriteList() { - return favoriteList; - } - - public String getFavoriteListId() { - return favoriteList.getTopiaId(); - } - - public String getAction() { - return action; - } - - @Override - public void prepare() throws Exception { - - String[] favoriteListIds = parameters.get("favoriteListId"); - Preconditions.checkNotNull(favoriteListIds); - Preconditions.checkArgument(favoriteListIds.length == 1); - String favoriteListId = favoriteListIds[0]; - - String[] actions = parameters.get("action"); - if (actions != null && actions.length == 1) { - action = actions[0]; - } - - try { - favoriteList = getFavoriteService().getFavoriteList( - getPollenUserAccount(), favoriteListId); - } catch (FavoriteListNotFoundException e) { - addFlashError(_("pollen.error.favoriteList.not.found")); - } catch (FavoriteListNotOwnedByUserException e) { - addFlashError(_("pollen.error.favoriteList.not.owned.by.user")); - } - } - - @Override - public void validate() { - - if ("create".equals(action)) { - - PollAccount account = getCreatePollAccount(); - - if (StringUtils.isBlank(account.getVotingId())) { - addFieldError("createPollAccount.votingId", - _("pollen.error.pollAccount.votingId.required")); - } - - if (StringUtils.isBlank(account.getEmail())) { - addFieldError("createPollAccount.email", - _("pollen.error.email.required")); - } else if (!StringUtil.isEmail(account.getEmail())) { - addFieldError("createPollAccount.email", - _("pollen.error.email.invalid")); - } - } else if ("edit".equals(action)) { - - PollAccount account = getEditPollAccount(); - - if (StringUtils.isBlank(account.getVotingId())) { - addFieldError("editPollAccount.votingId", - _("pollen.error.pollAccount.votingId.required")); - } - - if (StringUtils.isBlank(account.getEmail())) { - addFieldError("editPollAccount.email", - _("pollen.error.email.required")); - } else if (!StringUtil.isEmail(account.getEmail())) { - addFieldError("editPollAccount.email", - _("pollen.error.email.invalid")); - } - } - } - - public String create() throws Exception { - - Preconditions.checkNotNull(favoriteList); - Preconditions.checkNotNull(pollAccount); - - String result = INPUT; - - try { - - getFavoriteService().addPollAccountToFavoriteList( - favoriteList, pollAccount); - - addFlashMessage( - _("pollen.information.pollAccount.addedTofavoriteList", - pollAccount.getVotingId())); - - pollAccount = null; - action = null; - result = SUCCESS; - } catch (ParticipantAlreadyFoundInListException e) { - addFieldError("createPollAccount.email", - _("pollen.error.favoriteList.participant.already.found.in.list")); - } - return result; - } - - public String edit() throws Exception { - - Preconditions.checkNotNull(favoriteList); - Preconditions.checkNotNull(pollAccount); - - String result = INPUT; - - try { - - getFavoriteService().editPollAccountToFavoriteList( - favoriteList, pollAccount); - - addFlashMessage( - _("pollen.information.pollAccount.updatedTofavoriteList", - pollAccount.getVotingId())); - - pollAccount = null; - action = null; - result = SUCCESS; - } catch (ParticipantAlreadyFoundInListException e) { - addFieldError("editPollAccount.email", - _("pollen.error.favoriteList.participant.already.found.in.list")); - } - return result; - } - - public String delete() throws Exception { - - Preconditions.checkNotNull(favoriteList); - Preconditions.checkNotNull(pollAccount); - Preconditions.checkNotNull(pollAccount.getTopiaId()); - - getFavoriteService().removePollAccountToFavoriteList( - favoriteList, pollAccount); - - addFlashMessage( - _("pollen.information.pollAccount.removedFromFavoriteList", - pollAccount.getVotingId())); - - action = null; - pollAccount = null; - - return SUCCESS; - } - - protected PollAccount getPollAccount() { - if (pollAccount == null) { - pollAccount = getFavoriteService().newPollAccountForFavoriteList(); - } - return pollAccount; - } - - @Override - public void setParameters(Map<String, String[]> parameters) { - this.parameters = parameters; - } -} Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the all user actions. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui.actions.user; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/converters/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/converters/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/converters/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,9 @@ +/** + * Base Package for the converters used in ui module. + * + * @author tchemit <chemit@codelutin.com> + * @see StrutsTypeConverter + */ +package org.chorem.pollen.ui.converters; + +import org.apache.struts2.util.StrutsTypeConverter; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/converters/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenSecurityInterceptor.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenSecurityInterceptor.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenSecurityInterceptor.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,39 @@ +package org.chorem.pollen.ui.interceptors; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.interceptor.AbstractInterceptor; +import org.apache.struts2.StrutsStatics; +import org.chorem.pollen.PollenUserSecurityContext; +import org.chorem.pollen.ui.PollenUIUtils; +import org.chorem.pollen.ui.actions.PollenUserSecurityAware; + +import javax.servlet.http.HttpServletRequest; + +/** + * Interceptor to inject the {@link PollenUserSecurityContext} for + * {@link PollenUserSecurityAware}. + * + * @author tchemit <chemit@codelutin.com> + * @see PollenUserSecurityAware + * @see PollenUserSecurityContext + * @since 1.4.5 + */ +public class PollenSecurityInterceptor extends AbstractInterceptor implements StrutsStatics { + + private static final long serialVersionUID = 1L; + + @Override + public String intercept(ActionInvocation invocation) throws Exception { + final Object action = invocation.getAction(); + final ActionContext context = invocation.getInvocationContext(); + + if (action instanceof PollenUserSecurityAware) { + + HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST); + PollenUserSecurityContext userSecurityContext = PollenUIUtils.getUserSecurityContext(request); + ((PollenUserSecurityAware) action).setPollenUserSecurityContext(userSecurityContext); + } + return invocation.invoke(); + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenSecurityInterceptor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,9 @@ +/** + * Base Package for the interceptors used in ui module. + * + * @author tchemit <chemit@codelutin.com> + * @see Interceptor + */ +package org.chorem.pollen.ui.interceptors; + +import com.opensymphony.xwork2.interceptor.Interceptor; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,6 @@ +/** + * Base Package for the ui module. + * + * @author tchemit <chemit@codelutin.com> + */ +package org.chorem.pollen.ui; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/results/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/results/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/results/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,9 @@ +/** + * Base Package for the results used in ui module. + * + * @author tchemit <chemit@codelutin.com> + * @see StrutsResultSupport + */ +package org.chorem.pollen.ui.results; + +import org.apache.struts2.dispatcher.StrutsResultSupport; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/results/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -97,55 +97,27 @@ protected PollenUserSecurityContext createSecurityContext(ServletRequest request) { - UserAccount userAccount = getPollenUserAccount(request); - PollUri pollUri = getPollUri(request); - PollenUserSecurityContext securityContext = PollenUserSecurityContext.newContext( - userAccount, pollUri - ); - - PollenServiceContext serviceContext = getServiceContext(request); - - SecurityService securityService = - serviceContext.newService(SecurityService.class); - - Poll poll = getPollIdSane(pollUri, serviceContext, request); - - if (poll != null) { - - securityContext.setPoll(poll); - - // load user roles - securityContext.loadUserRoles(securityService); - } - return securityContext; - } - - protected UserAccount getPollenUserAccount(ServletRequest request) { PollenSession pollenSession = PollenSession.get(request); + UserAccount userAccount = pollenSession.getUserAccount(); - return pollenSession.getUserAccount(); - } - - private PollUri getPollUri(ServletRequest request) { String servletPath = ((HttpServletRequest) request).getServletPath(); Matcher m = URI_PATTERN.matcher(servletPath); - PollUri result = null; + PollUri pollUri = null; if (m.find()) { String uriId = m.group(3); - result = PollUri.newPollUri(uriId); - + pollUri = PollUri.newPollUri(uriId); } - return result; - } - private Poll getPollIdSane(PollUri pollUri, - PollenServiceContext serviceContext, - ServletRequest request) { + PollenUserSecurityContext securityContext = + PollenUserSecurityContext.newContext(userAccount, pollUri); + SecurityService securityService = getSecurityService(request); + Poll poll = null; String errorMessage = null; + if (pollUri == null) { // no pollUri in url @@ -162,7 +134,7 @@ // there is a pollId check that it exists PollService pollService = - serviceContext.newService(PollService.class); + securityService.newService(PollService.class); poll = pollService.getPollByPollId(pollUri.getPollId()); @@ -185,26 +157,24 @@ registerError(request, errorMessage); } - return poll; - } + if (poll != null) { - protected PollenServiceContext getServiceContext(ServletRequest request) { - PollenApplicationContext applicationContext = - PollenApplicationContext.get(getServletContext()); + securityContext.setPoll(poll); - PollenServiceFactory serviceFactory = new PollenServiceFactory(); + // load user roles + securityContext.loadUserRoles(securityService); + } - TopiaContext transaction = - TopiaTransactionFilter.getTransaction(request); - - Locale locale = Locale.getDefault(); - return DefaultPollenServiceContext.newContext( - locale, - transaction, - applicationContext.getConfiguration(), - serviceFactory, - applicationContext.getVoteCountingStrategyProvider() - ); + if (log.isInfoEnabled()) { + log.info(String.format("request [%s], pollUri %s, user %s%s - roles %s", + ((HttpServletRequest) request).getServletPath(), + securityContext.getPollUri(), + securityContext.getUserAccount() == null ? "no connected" : securityContext.getUserAccount().getEmail(), + securityContext.isAdmin() ? " Pollen Admin" : "", + securityContext.getUserRoles()) + ); + } + return securityContext; } @Override @@ -231,6 +201,27 @@ return false; } + protected SecurityService getSecurityService(ServletRequest request) { + PollenApplicationContext applicationContext = + PollenApplicationContext.get(getServletContext()); + + PollenServiceFactory serviceFactory = new PollenServiceFactory(); + + TopiaContext transaction = + TopiaTransactionFilter.getTransaction(request); + + Locale locale = Locale.getDefault(); + PollenServiceContext serviceContext = DefaultPollenServiceContext.newContext( + locale, + transaction, + applicationContext.getConfiguration(), + serviceFactory, + applicationContext.getVoteCountingStrategyProvider() + ); + + return serviceContext.newService(SecurityService.class); + } + protected void registerError(ServletRequest request, String errorMessage) { request.setAttribute(ERROR_MESSAGE_PARAMETER, errorMessage); } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -10,48 +10,39 @@ * 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.security; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.apache.shiro.web.filter.authc.UserFilter; import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.ui.PollenSession; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -public class AdminUserRequired extends AbstractPollenAuthorization { +public class AdminUserRequired extends UserFilter { - private static final Log log = - LogFactory.getLog(AdminUserRequired.class); - @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) { - UserAccount userAccount = getPollenUserAccount(request); + PollenSession pollenSession = PollenSession.get(request); + UserAccount userAccount = pollenSession.getUserAccount(); + boolean isAccessAllowed = userAccount != null && userAccount.isAdministrator(); - if (log.isDebugEnabled()) { - if (isAccessAllowed) { - log.debug("granting access to an admin-reserved page"); - } else { - log.debug("illegal access to an admin-reserved page, user will be sent to " + getUnauthorizedUrl()); - } - } - return isAccessAllowed; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -10,12 +10,12 @@ * 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% @@ -35,9 +35,9 @@ protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) { - PollenSession pollenSession = - PollenSession.get(request); + PollenSession pollenSession = PollenSession.get(request); + UserAccount userAccount = pollenSession.getUserAccount(); boolean isAccessAllowed = userAccount != null; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -75,8 +75,7 @@ // check now poll results can be displayed - SecurityService securityService = - getServiceContext(request).newService(SecurityService.class); + SecurityService securityService = getSecurityService(request); String errorMessage = securityService.checkAccessResult(securityContext); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -73,8 +73,7 @@ // check now poll votes can be displayed - SecurityService securityService = - getServiceContext(request).newService(SecurityService.class); + SecurityService securityService =getSecurityService(request); String errorMessage = securityService.checkCanAccessVote(securityContext); Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/package-info.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/package-info.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/package-info.java 2012-08-13 14:11:15 UTC (rev 3611) @@ -0,0 +1,11 @@ +/** + * Base Package for the security stuff in ui module. + * + * Security is done using shiro {@link AccessControlFilter}. + * + * @author tchemit <chemit@codelutin.com> + * @see AccessControlFilter + */ +package org.chorem.pollen.ui.security; + +import org.apache.shiro.web.filter.AccessControlFilter; \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/resources/config/struts-poll.xml =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-08-13 14:11:15 UTC (rev 3611) @@ -34,51 +34,51 @@ <result-type name="redirectToVote" class="org.chorem.pollen.ui.results.PollenServletActionRedirectResult"> <param name="namespace">/poll</param> - <param name="actionName">votefor/${uriId}</param> + <param name="actionName">votefor/${pollUri}</param> </result-type> <result-type name="redirectToSummary" class="org.chorem.pollen.ui.results.PollenServletActionRedirectResult"> <param name="namespace">/poll</param> - <param name="actionName">summary/${uriId}</param> + <param name="actionName">summary/${pollUri}</param> </result-type> </result-types> <!-- create poll --> - <action name="create" class="org.chorem.pollen.ui.actions.poll.CreatePoll" + <action name="create" class="org.chorem.pollen.ui.actions.poll.form.CreatePoll" method="execute"> <result name="input">/WEB-INF/jsp/poll/pollForm.jsp</result> <result type="redirectToSummary"/> </action> <!-- edit poll --> - <action name="edit/*" class="org.chorem.pollen.ui.actions.poll.EditPoll" + <action name="edit/*" class="org.chorem.pollen.ui.actions.poll.form.EditPoll" method="execute"> - <param name="uriId">{1}</param> + <param name="pollUri">{1}</param> <result name="input">/WEB-INF/jsp/poll/pollForm.jsp</result> <result type="redirectToSummary"/> </action> <!-- clone poll --> - <action name="clone/*" class="org.chorem.pollen.ui.actions.poll.ClonePoll" + <action name="clone/*" class="org.chorem.pollen.ui.actions.poll.form.ClonePoll" method="execute"> - <param name="uriId">{1}</param> + <param name="pollUri">{1}</param> <result name="input">/WEB-INF/jsp/poll/pollForm.jsp</result> <result type="redirectToSummary"/> </action> <!-- resume poll --> <action name="summary/*" method="execute" - class="org.chorem.pollen.ui.actions.poll.SummaryPoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.admin.SummaryPoll"> + <!--<param name="pollUri">{1}</param>--> <result>/WEB-INF/jsp/poll/summary.jsp</result> </action> <!-- export poll --> <action name="export/*" - class="org.chorem.pollen.ui.actions.poll.ExportPoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.admin.ExportPoll"> + <!--<param name="pollUri">{1}</param>--> <result type="stream"> <param name="contentCharSet">UTF-8</param> <param name="contentType">application/xml</param> @@ -92,131 +92,123 @@ <!-- confirm close poll --> <action name="confirmClosePoll/*" - class="org.chorem.pollen.ui.actions.poll.ConfirmPollAction"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.admin.ConfirmPollAction"> <result>/WEB-INF/jsp/poll/confirmClosePoll.jsp</result> </action> <!-- close poll --> - <action name="close/*" class="org.chorem.pollen.ui.actions.poll.ClosePoll"> - <param name="uriId">{1}</param> + <action name="close/*" class="org.chorem.pollen.ui.actions.poll.admin.ClosePoll"> + <!--<param name="pollUri">{1}</param>--> <result type="redirect2"/> </action> <!-- confirm delete poll --> <action name="confirmDeletePoll/*" - class="org.chorem.pollen.ui.actions.poll.ConfirmPollAction"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.admin.ConfirmPollAction"> <result>/WEB-INF/jsp/poll/confirmDeletePoll.jsp</result> </action> <!-- delete poll --> <action name="delete/*" - class="org.chorem.pollen.ui.actions.poll.DeletePoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.admin.DeletePoll"> + <!--<param name="pollUri">{1}</param>--> <result type="redirectToHome"/> </action> <!-- vote poll --> <action name="vote/*" method="execute" - class="org.chorem.pollen.ui.actions.poll.VoteForPoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.vote.VoteForPoll"> + <!--<param name="pollUri">{1}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> <result type="redirectToVote"/> </action> <!-- vote poll (input) --> <action name="votefor/*" method="input" - class="org.chorem.pollen.ui.actions.poll.VoteForPoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.vote.VoteForPoll"> + <!--<param name="pollUri">{1}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> </action> <!-- vote poll (input) + page number (for future paginated polls) --> <action name="votefor/*/*" method="input" - class="org.chorem.pollen.ui.actions.poll.VoteForPoll"> - <param name="uriId">{1}</param> - <param name="page">{2}</param> + class="org.chorem.pollen.ui.actions.poll.vote.VoteForPoll"> + <!--<param name="pollUri">{1}</param>--> + <!--<param name="page">{2}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> </action> <!-- vote poll (input) (to fix http://chorem.org/issues/550) --> <action name="VoteFor/*" method="input" - class="org.chorem.pollen.ui.actions.poll.VoteForPoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.vote.VoteForPoll"> + <!--<param name="pollUri">{1}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> </action> <!-- vote poll (input) + page number (for future paginated polls)(to fix http://chorem.org/issues/550) --> <action name="VoteFor/*/*" method="input" - class="org.chorem.pollen.ui.actions.poll.VoteForPoll"> - <param name="uriId">{1}</param> - <param name="page">{2}</param> + class="org.chorem.pollen.ui.actions.poll.vote.VoteForPoll"> + <!--<param name="pollUri">{1}</param>--> + <!--<param name="page">{2}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> </action> <!-- moderate vote poll (input) --> <action name="moderate/*" method="input" - class="org.chorem.pollen.ui.actions.poll.ModeratePoll"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.vote.ModeratePoll"> + <!--<param name="pollUri">{1}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> </action> - <!-- edit poll vote --> - <action name="editVote" - class="org.chorem.pollen.ui.actions.poll.EditVote"> - <result type="redirectToVote"/> - </action> - <!-- confirm delete poll vote --> - <action name="confirmDeleteVote" - class="org.chorem.pollen.ui.actions.poll.ConfirmDeleteVote"> + <action name="confirmDeleteVote/*" + class="org.chorem.pollen.ui.actions.poll.vote.ConfirmDeleteVote"> <result>/WEB-INF/jsp/poll/confirmDeletePollVote.jsp</result> </action> <!-- delete poll vote --> - <action name="deleteVote" - class="org.chorem.pollen.ui.actions.poll.DeleteVote"> + <action name="deleteVote/*" + class="org.chorem.pollen.ui.actions.poll.vote.DeleteVote"> <result type="redirectToVote"/> </action> <!-- add a poll comment --> <action name="addComment/*" - class="org.chorem.pollen.ui.actions.poll.AddComment"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.vote.AddComment"> + <!--<param name="pollUri">{1}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> <result type="redirectToVote"/> </action> <!-- confirm delete comment --> - <action name="confirmDeleteComment" - class="org.chorem.pollen.ui.actions.poll.ConfirmDeleteComment"> + <action name="confirmDeleteComment/*" + class="org.chorem.pollen.ui.actions.poll.vote.ConfirmDeleteComment"> <result>/WEB-INF/jsp/poll/confirmDeletePollComment.jsp</result> </action> <!-- delete a poll comment --> - <action name="deleteComment" - class="org.chorem.pollen.ui.actions.poll.DeleteComment"> + <action name="deleteComment/*" + class="org.chorem.pollen.ui.actions.poll.vote.DeleteComment"> <result type="redirectToVote"/> </action> <!-- add a choice --> <action name="addChoice/*" - class="org.chorem.pollen.ui.actions.poll.AddChoice"> - <param name="uriId">{1}</param> + class="org.chorem.pollen.ui.actions.poll.vote.AddChoice"> + <!--<param name="pollUri">{1}</param>--> <result name="input">/WEB-INF/jsp/poll/vote.jsp</result> <result type="redirectToVote"/> </action> <!-- confirm delete poll choice --> - <action name="confirmDeleteChoice" - class="org.chorem.pollen.ui.actions.poll.ConfirmDeleteChoice"> + <action name="confirmDeleteChoice/*" + class="org.chorem.pollen.ui.actions.poll.vote.ConfirmDeleteChoice"> <result>/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp</result> </action> <!-- delete poll choice --> - <action name="deleteChoice" - class="org.chorem.pollen.ui.actions.poll.DeleteChoice"> + <action name="deleteChoice/*" + class="org.chorem.pollen.ui.actions.poll.vote.DeleteChoice"> <result type="redirectToVote"/> </action> @@ -229,7 +221,7 @@ <!-- display poll result --> <action name="results/*" method="execute" class="org.chorem.pollen.ui.actions.poll.ResultForPoll"> - <param name="uriId">{1}</param> + <!--<param name="pollUri">{1}</param>--> <result>/WEB-INF/jsp/poll/result.jsp</result> </action> @@ -246,26 +238,26 @@ <!-- Select a favorite list to add to a voting list --> <action name="selectPersonListToAddToVotingList" - class="org.chorem.pollen.ui.actions.poll.SelectPersonListToVotingList"> + class="org.chorem.pollen.ui.actions.poll.form.SelectPersonListToVotingList"> <result>/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp</result> </action> <!-- Select a favorite list to import into a new voting list --> <action name="selectPersonListToCreateNewVotingList" - class="org.chorem.pollen.ui.actions.poll.SelectPersonListToVotingList"> + class="org.chorem.pollen.ui.actions.poll.form.SelectPersonListToVotingList"> <result>/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp </result> </action> <!-- Load in session a personList to be imported into a voting list --> <action name="importPersonListToVotingList" - class="org.chorem.pollen.ui.actions.poll.ImportPersonListToVotingList"> + class="org.chorem.pollen.ui.actions.poll.form.ImportPersonListToVotingList"> <result>/WEB-INF/jsp/poll/displayVotingListPersons.jsp</result> </action> <!-- Load in session a personList to be imported into a new voting list --> <action name="importPersonListToNewVotingList" - class="org.chorem.pollen.ui.actions.poll.ImportPersonListToVotingList"> + class="org.chorem.pollen.ui.actions.poll.form.ImportPersonListToVotingList"> <result>/WEB-INF/jsp/poll/displayVotingList.jsp</result> </action> </package> Modified: trunk/pollen-ui-struts2/src/main/resources/config/struts-user.xml =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/config/struts-user.xml 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/resources/config/struts-user.xml 2012-08-13 14:11:15 UTC (rev 3611) @@ -147,7 +147,7 @@ <!-- attach poll to the connected user account --> <action name="attachPoll" - class="org.chorem.pollen.ui.actions.poll.AttachPoll"> + class="org.chorem.pollen.ui.actions.user.AttachPoll"> <result name="input">/WEB-INF/jsp/user/createdList.jsp</result> <result type="redirectAction"> <param name="namespace">/user</param> Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-08-13 14:11:15 UTC (rev 3611) @@ -148,6 +148,7 @@ pollen.common.select.choiceType=Select the type of choice pollen.common.select.userFavoriteList=List pollen.common.title=Title +pollen.common.undefined= pollen.common.userSupport=User support pollen.common.victories=Winners\: pollen.common.victory=Winner\: @@ -281,6 +282,7 @@ pollen.information.poll.attached=Poll '<strong>%s</strong>' attached to your user account. pollen.information.poll.closed=Poll '<strong>%s</strong>' closed. pollen.information.poll.created=Poll '<strong>%s</strong>' created. +pollen.information.poll.deleted=Poll '<strong>%s</strong>' deleted. pollen.information.poll.form.voteStarted=Votes are started, some options can't be updated. pollen.information.poll.updated=Poll '<strong>%s</strong>' modified. pollen.information.pollAccount.addedTofavoriteList=Member '<strong>%s</strong>' added to favorite list. Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-08-13 14:11:15 UTC (rev 3611) @@ -148,6 +148,7 @@ pollen.common.select.choiceType=Sélectionner le type de choix pollen.common.select.userFavoriteList=Liste pollen.common.title=Titre +pollen.common.undefined= pollen.common.userSupport=Support utilisateur pollen.common.victories=Gagnants \: pollen.common.victory=Gagnant \: @@ -282,6 +283,7 @@ pollen.information.poll.attached=Sondage '<strong>%s</strong>' rattaché à votre compte. pollen.information.poll.closed=Sondage '<strong>%s</strong>' clos. pollen.information.poll.created=Sondage '<strong>%s</strong>' créé. +pollen.information.poll.deleted=Sondage '<strong>%s</strong>' supprimé. pollen.information.poll.form.voteStarted=Les votes ont commencé, certaines options ne sont pas modifiables. pollen.information.poll.updated=Sondage '<strong>%s</strong>' mise à jour. pollen.information.pollAccount.addedTofavoriteList=Le membre '<strong>%s</strong>' a été ajouté à la liste des favoris. Modified: trunk/pollen-ui-struts2/src/main/resources/shiro.ini =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/shiro.ini 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/resources/shiro.ini 2012-08-13 14:11:15 UTC (rev 3611) @@ -27,7 +27,7 @@ connected.loginUrl=/security/connected_required admin=org.chorem.pollen.ui.security.AdminUserRequired -admin.unauthorizedUrl=/security/admin_required +admin.loginUrl=/security/admin_required pollCreatorAccess=org.chorem.pollen.ui.security.PollCreatorAccessRequired pollCreatorAccess.unauthorizedUrl=/security/illegal_access @@ -66,6 +66,12 @@ # is poll exists and user can vote to it /poll/votefor/**=pollVoteAccess /poll/VoteFor/**=pollVoteAccess +/poll/addChoice/**=pollVoteAccess +/poll/addComment/**=pollVoteAccess +/poll/confirmDeleteComment/**=pollVoteAccess +/poll/confirmDeleteVote/**=pollVoteAccess +/poll/deleteComment/**=pollVoteAccess +/poll/deleteVote/**=pollVoteAccess # is poll exists and user can access to his result /poll/results/**=pollResultAccess @@ -75,4 +81,10 @@ /poll/summary/**=pollCreatorAccess /poll/moderate/**=pollCreatorAccess /poll/clone/**=pollCreatorAccess -/poll/resume/**=pollCreatorAccess \ No newline at end of file +/poll/close/**=pollCreatorAccess +/poll/delete/**=pollCreatorAccess +/poll/export/**=pollCreatorAccess +/poll/confirmClosePoll/**=pollCreatorAccess +/poll/confirmDeletePoll/**=pollCreatorAccess +/poll/confirmDeleteChoice/**=pollCreatorAccess +/poll/deleteChoice/**=pollCreatorAccess Modified: trunk/pollen-ui-struts2/src/main/resources/struts.xml =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/struts.xml 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/resources/struts.xml 2012-08-13 14:11:15 UTC (rev 3611) @@ -44,6 +44,8 @@ <constant name="struts.enable.SlashesInActionNames" value="true"/> <constant name="struts.devMode" value="false"/> + <bean class="org.chorem.pollen.services.PollenServiceFactory" /> + <!--Performance tuning--> <!--see http://struts.apache.org/2.2.3/docs/performance-tuning.html--> <constant name="struts.freemarker.templatesCache" value="true"/> @@ -76,10 +78,23 @@ <interceptor name="pollenFileUpload" class="org.chorem.pollen.ui.interceptors.PollenFileUploadInterceptor"/> + <interceptor name="pollenUserSecurity" + class="org.chorem.pollen.ui.interceptors.PollenSecurityInterceptor"/> + <!-- basic stack --> <interceptor-stack name="pollenBasicStack"> <interceptor-ref name="i18n"/> - <interceptor-ref name="basicStack"/> + <interceptor-ref name="exception"/> + <interceptor-ref name="servletConfig"/> + <interceptor-ref name="pollenUserSecurity"/> + <interceptor-ref name="prepare"/> + <interceptor-ref name="checkbox"/> + <interceptor-ref name="multiselect"/> + <interceptor-ref name="actionMappingParams"/> + <interceptor-ref name="params"> + <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param> + </interceptor-ref> + <interceptor-ref name="conversionError"/> </interceptor-stack> <!-- params stack with params--> @@ -92,6 +107,7 @@ <interceptor-ref name="multiselect"/> <interceptor-ref name="pollenFileUpload"/> <interceptor-ref name="servletConfig"/> + <interceptor-ref name="pollenUserSecurity"/> <interceptor-ref name="staticParams"/> <interceptor-ref name="prepare"/> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-08-13 14:11:15 UTC (rev 3611) @@ -29,6 +29,7 @@ <pattern>/config-browser/*</pattern> <pattern>/json/*</pattern> <pattern>/*/confirm*</pattern> + <pattern>/*/confirm*/*</pattern> <pattern>/poll/display*</pattern> <pattern>/user/lostPassword*</pattern> <pattern>/poll/importPersonList*</pattern> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -116,7 +116,7 @@ <s:textfield key="editUser.login" label="%{getText('pollen.common.login')}" required="true" readonly="true" size="40"/> <s:textfield key="editUser.email" label="%{getText('pollen.common.email')}" - required="true" size="40"/> + required="true" size="40" disabled="%{exists}"/> <s:textfield key="editUser.firstName" label="%{getText('pollen.common.firstName')}" size="40"/> <s:textfield key="editUser.lastName" Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -30,7 +30,6 @@ <fieldset class="ui-widget-content ui-corner-all"> <s:hidden key="redirectUrl" label=''/> - <s:hidden key="uriId" label=''/> <s:text name="pollen.information.confirmClonePoll"/> <div align="center" style="padding-top: 1em;"> @@ -50,7 +49,7 @@ <s:submit onclick="return cancel();" theme="simple" key="pollen.action.cancel"/> <s:submit key="pollen.action.clone" theme="simple" disabled="true" - action="clone/%{pollId}"/> + action="clone/%{pollUri}"/> </div> </fieldset> </s:form> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClosePoll.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClosePoll.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClosePoll.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -30,7 +30,6 @@ <fieldset class="ui-widget-content ui-corner-all"> <s:hidden key="redirectUrl" label=''/> - <s:hidden key="uriId" label=''/> <s:text name="pollen.information.confirmClosePoll"/> <div align="center" style="padding-top: 1em;"> @@ -47,7 +46,7 @@ <s:submit onclick="return cancel();" theme="simple" key="pollen.action.cancel"/> <s:submit key="pollen.action.close" theme="simple" - action="close/%{pollId}"/> + action="close/%{pollUri}"/> </div> </fieldset> </s:form> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePoll.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePoll.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePoll.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -30,7 +30,6 @@ <fieldset class="ui-widget-content ui-corner-all"> <s:hidden key="redirectUrl" label=''/> - <s:hidden key="uriId" label=''/> <s:text name="pollen.information.confirmDeletePoll"/> <div align="center" style="padding-top: 1em;"> @@ -47,7 +46,7 @@ <s:submit onclick="return cancel();" theme="simple" key="pollen.action.cancel"/> <s:submit key="pollen.action.delete" theme="simple" - action="delete/%{pollId}"/> + action="delete/%{pollUri}"/> </div> </fieldset> </s:form> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -26,7 +26,6 @@ <br/> <s:form method="POST" namespace="/poll"> - <s:hidden key="uriId" label=''/> <s:hidden key="choiceId" value="%{choice.topiaId}" label=''/> <s:text name="pollen.information.confirmDeletePollChoice"> @@ -40,6 +39,7 @@ <div align="right"> <s:submit onclick="return closeConfirmDialog();" theme="simple" key="pollen.action.cancel"/> - <s:submit key="pollen.action.delete" theme="simple" action="deleteChoice"/> + <s:submit key="pollen.action.delete" theme="simple" + action="deleteChoice/%{pollUri}"/> </div> </s:form> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -25,7 +25,6 @@ <br/> <s:form method="POST" namespace="/poll"> - <s:hidden name="uriId" value='%{uriId}'/> <s:hidden name="commentId" value='%{comment.topiaId}'/> <s:textfield key='comment.postDate' readonly="true" size="50" @@ -45,6 +44,7 @@ <div align="right"> <s:submit onclick="return closeConfirmDialog();" theme="simple" key="pollen.action.cancel"/> - <s:submit key="pollen.action.delete" theme="simple" action="deleteComment"/> + <s:submit key="pollen.action.delete" theme="simple" + action="deleteComment/%{pollUri}"/> </div> </s:form> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -25,7 +25,6 @@ <br/> <s:form method="POST" namespace="/poll"> - <s:hidden key="uriId" label=''/> <s:hidden key="voteId" value="%{vote.topiaId}" label=''/> <s:text name="pollen.information.confirmDeletePollVote"> @@ -42,6 +41,7 @@ <div align="right"> <s:submit onclick="return closeConfirmDialog();" theme="simple" key="pollen.action.cancel"/> - <s:submit key="pollen.action.delete" theme="simple" action="deleteVote"/> + <s:submit key="pollen.action.delete" theme="simple" + action="deleteVote/%{pollUri}"/> </div> </s:form> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -35,7 +35,7 @@ var url = "<s:url action='confirmDeletePoll/' namespace='/poll'/>"; url += id + '?' + $.param( { - redirectUrl:'<s:url namespace="/poll" action="summary/%{uriId}"/>' + redirectUrl:'<s:url namespace="/poll" action="summary/%{pollUri}"/>' }); dialog.load(url); dialog.dialog('open'); @@ -49,7 +49,7 @@ var url = "<s:url action='confirmClosePoll/' namespace='/poll'/>"; url += id + '?' + $.param( { - redirectUrl:'<s:url namespace="/poll" action="summary/%{uriId}"/>' + redirectUrl:'<s:url namespace="/poll" action="summary/%{pollUri}"/>' }); dialog.load(url); dialog.dialog('open'); @@ -88,7 +88,10 @@ <div class="ui-widget-content ui-corner-all"> - <s:label key="pollen.common.pollId" value="%{poll.pollId}"/> + <s:label key="pollen.common.pollId" value=""/> + <span class="fright url" id='pollId'> + <s:property value="%{poll.pollId}"/> + </span> <br/> </div> @@ -187,7 +190,7 @@ <img src="<s:url value='/img/close.png'/>" class="imgAction" alt="<s:text name='pollen.action.closePoll.help'/>" title="<s:text name='pollen.action.closePoll.help'/>"/> - <s:a href="#" onclick="return confirmClosePoll('%{uriId}')"> + <s:a href="#" onclick="return confirmClosePoll('%{pollUri}')"> <strong><s:text name='pollen.label.pollClosePage'/></strong> </s:a> @@ -199,7 +202,7 @@ <img src="<s:url value='/img/delete.png'/>" class="imgAction" alt="<s:text name='pollen.action.deletePoll.help'/>" title="<s:text name='pollen.action.deletePoll.help'/>"/> - <s:a href="#" onclick="return confirmDeletePoll('%{uriId}')"> + <s:a href="#" onclick="return confirmDeletePoll('%{pollUri}')"> <s:text name='pollen.label.pollDeletePage'/> </s:a> </div> Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/edit.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/edit.jsp 2012-08-13 14:08:57 UTC (rev 3610) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/edit.jsp 2012-08-13 14:11:15 UTC (rev 3611) @@ -47,7 +47,7 @@ <legend><s:text name="pollen.fieldset.userInformation"/></legend> <s:textfield name="pollenUserAccount.email" key="pollen.common.email" - required="true"/> + required="true" disabled="%{exists}"/> <s:textfield name="pollenUserAccount.firstName" key="pollen.common.firstName"/> <s:textfield name="pollenUserAccount.lastName"
participants (1)
-
tchemit@users.chorem.org