r3604 - in trunk/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll java/org/chorem/pollen/ui/actions/user webapp/WEB-INF/jsp/user
Author: tchemit Date: 2012-08-13 16:02:08 +0200 (Mon, 13 Aug 2012) New Revision: 3604 Url: http://chorem.org/repositories/revision/pollen/3604 Log: fixes #767: Can not attach poll when pollId contains have some trim spaces (+ move this action to user package + stop using inheritance for nothing :() Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java Removed: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java 2012-08-13 13:08:27 UTC (rev 3603) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java 2012-08-13 14:02:08 UTC (rev 3604) @@ -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.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.ui.actions.PageSkin; - -/** - * To attach a anonymous poll to a connected user account. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class AttachPoll extends AbstractPollUriIdAction { - - private static final long serialVersionUID = 1L; - - public AttachPoll() { - super(PageSkin.EDITION); - } - - @Override - public String execute() throws Exception { - - String pollId = getPollId(); - - Preconditions.checkNotNull(pollId); - - Poll poll = getPollService().getExistingPollByPollId(pollId); - - UserAccount userAccount = getPollenSession().getUserAccount(); - - getPollService().attachPoll(poll, userAccount); - - addFlashMessage(_("pollen.information.poll.attached", poll.getTitle())); - - return SUCCESS; - } - - @Override - public void validate() { - - if (StringUtils.isEmpty(getPollId())) { - addFieldError("uriId", _("pollen.error.pollId.empty")); - } else { - - String pollId = getPollId(); - - try { - - // check that poll exists - Poll poll = getPollService().getExistingPollByPollId(pollId); - - // check that poll is not yet attached to another user account - - UserAccount userAccount = poll.getCreator().getUserAccount(); - if (userAccount != null) { - - addFieldError("uriId", - _("pollen.error.pollAlreadyAttached")); - } - } catch (PollNotFoundException e) { - - addFieldError("uriId", _("pollen.error.pollNotFound")); - } - - } - } -} Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java) =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java (rev 0) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java 2012-08-13 14:02:08 UTC (rev 3604) @@ -0,0 +1,115 @@ +/* + * #%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 org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.services.exceptions.PollNotFoundException; +import org.chorem.pollen.ui.actions.PageSkin; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * To attach a anonymous poll to a connected user account. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class AttachPoll extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(AttachPoll.class); + + /** + * Id of the poll to attach to the connected user account. + * + * @since 1.4.5 + */ + private String pollId; + + public AttachPoll() { + super(PageSkin.EDITION); + } + + public String getPollId() { + return pollId == null ? null : pollId.trim(); + } + + public void setPollId(String pollId) { + this.pollId = pollId; + } + + @Override + public String execute() throws Exception { + + String id = getPollId(); + + UserAccount userAccount = getPollenUserAccount(); + + Poll poll = getPollService().getExistingPollByPollId(id); + + if (log.isInfoEnabled()) { + log.info(String.format("Will attach poll %s to user %s", + id, userAccount.getEmail())); + } + + getPollService().attachPoll(id, userAccount); + + addFlashMessage(_("pollen.information.poll.attached", poll.getTitle())); + + return SUCCESS; + } + + @Override + public void validate() { + + String id = getPollId(); + + if (StringUtils.isBlank(id)) { + addFieldError("pollId", _("pollen.error.pollId.empty")); + } else { + + try { + + // check that poll exists + Poll poll = getPollService().getExistingPollByPollId(id); + + // check that poll is not yet attached to another user account + + UserAccount userAccount = poll.getCreator().getUserAccount(); + if (userAccount != null) { + + addFieldError("pollId", _("pollen.error.pollAlreadyAttached")); + } + } catch (PollNotFoundException e) { + + addFieldError("pollId", _("pollen.error.pollNotFound")); + } + + } + } +} Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp 2012-08-13 13:08:27 UTC (rev 3603) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp 2012-08-13 14:02:08 UTC (rev 3604) @@ -73,7 +73,7 @@ title='%{getText("pollen.common.createDate")}'/> <sjg:gridColumn name="addingChoices" sortable="false" title='%{getText("pollen.common.addingChoices")}'/> - <sjg:gridColumn name="beginDate" width="100" + <sjg:gridColumn name="beginDate" width="100" title='%{getText("pollen.common.beginDate")}'/> <sjg:gridColumn name="endDate" width="100" title='%{getText("pollen.common.endDate")}'/> @@ -91,10 +91,9 @@ <s:form namespace="/user" method="POST"> - <s:textfield key="uriId" label='%{getText("pollen.common.pollId")}' - required="true" size="80" value='%{pollId}' - tooltip='%{getText("poll.help.pollId")}' - tooltipIconPath="/img/tooltip.png"/> + <s:textfield key="pollId" label='%{getText("pollen.common.pollId")}' + required="true" size="80" tooltipIconPath="/img/tooltip.png" + tooltip='%{getText("poll.help.pollId")}'/> <br/> <s:submit action="attachPoll" key="pollen.action.attachPoll"/>
participants (1)
-
tchemit@users.chorem.org