Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
March 2012
- 3 participants
- 68 discussions
14 Mar '12
Author: tchemit
Date: 2012-03-14 15:40:02 +0100 (Wed, 14 Mar 2012)
New Revision: 3181
Url: http://chorem.org/repositories/revision/pollen/3181
Log:
no more usage of nuiton-struts2 here\! (use TopiafilterPagerBean)
Modified:
branches/pollen-1.2.6-struts2/pollen-services/pom.xml
Modified: branches/pollen-1.2.6-struts2/pollen-services/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/pom.xml 2012-03-14 14:39:03 UTC (rev 3180)
+++ branches/pollen-1.2.6-struts2/pollen-services/pom.xml 2012-03-14 14:40:02 UTC (rev 3181)
@@ -66,10 +66,6 @@
<artifactId>rome</artifactId>
</dependency>
<dependency>
- <groupId>org.nuiton.web</groupId>
- <artifactId>nuiton-struts2</artifactId>
- </dependency>
- <dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
</dependency>
1
0
r3180 - in branches/pollen-1.2.6-struts2/pollen-persistence/src/main: java/org/chorem/pollen/business/persistence java/org/chorem/pollen/entities/migration xmi
by tchemit@users.chorem.org 14 Mar '12
by tchemit@users.chorem.org 14 Mar '12
14 Mar '12
Author: tchemit
Date: 2012-03-14 15:39:03 +0100 (Wed, 14 Mar 2012)
New Revision: 3180
Url: http://chorem.org/repositories/revision/pollen/3180
Log:
move all query from services to persistence layer
add foreign key indexes
Added:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -0,0 +1,67 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.base.Preconditions;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+
+import java.util.List;
+
+public class CommentDAOImpl<E extends Comment> extends CommentDAOAbstract<E> {
+
+ public List<E> getComments(TopiaFilterPagerUtil.FilterPagerBean pager,
+ String pollId) throws TopiaException {
+
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(pollId);
+
+ TopiaQuery countQuery = createQuery("e").
+ addWhere("e." + Comment.PROPERTY_POLL + ".pollId",
+ TopiaQuery.Op.EQ, pollId);
+ long records = countByQuery(countQuery);
+ pager.setRecords((int) records);
+
+ TopiaQuery query = TopiaFilterPagerUtil.addPagerToQuery(countQuery,
+ pager);
+ List<E> result = findAllByQuery(query);
+ return result;
+
+ }
+
+ public List<E> getAllComments(String pollId) throws TopiaException {
+
+ Preconditions.checkNotNull(pollId);
+
+ TopiaQuery query = createQuery("e").
+ addWhere("e." + Comment.PROPERTY_POLL + ".pollId",
+ TopiaQuery.Op.EQ, pollId);
+ query.addOrderDesc(Comment.PROPERTY_POST_DATE);
+ List<E> result = findAllByQuery(query);
+ return result;
+
+ }
+
+} //CommentDAOImpl<E extends Comment>
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -0,0 +1,84 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+
+import java.util.List;
+
+public class PersonListDAOImpl<E extends PersonList> extends PersonListDAOAbstract<E> {
+
+ public List<E> getFavoriteLists(UserAccount user,
+ TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+
+ Preconditions.checkNotNull(user);
+
+ TopiaQuery countQuery = createQuery("e");
+ countQuery.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
+ long records = countByQuery(countQuery);
+
+ pager.setRecords((int) records);
+
+ TopiaQuery query = TopiaFilterPagerUtil.addPagerToQuery(countQuery, pager);
+
+ List<E> result = findAllByQuery(query);
+ return result;
+ }
+
+ public List<E> getFavoriteLists(UserAccount user) throws TopiaException {
+
+ Preconditions.checkNotNull(user);
+
+ TopiaQuery query = createQuery("e");
+ query.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
+ List<E> result = findAllByQuery(query);
+ return result;
+
+ }
+
+ public boolean isPersonListExist(UserAccount user, String name) throws TopiaException {
+
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(name);
+
+ // can't accept favorite list without name
+ Preconditions.checkArgument(StringUtils.isNotEmpty(name));
+
+
+ // check list does not already exists
+
+ TopiaQuery query = createQuery("e");
+
+ query.addWhere("e." + PersonList.PROPERTY_OWNER, TopiaQuery.Op.EQ, user);
+ query.addWhere("e." + PersonList.PROPERTY_NAME, TopiaQuery.Op.EQ, name);
+
+ boolean exist = existByQuery(query);
+ return exist;
+ }
+
+} //PersonListDAOImpl<E extends PersonList>
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-03-14 09:42:22 UTC (rev 3179)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -23,13 +23,17 @@
*/
package org.chorem.pollen.business.persistence;
+import com.google.common.base.Preconditions;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import java.util.List;
+
public class PollAccountDAOImpl<E extends PollAccount> extends PollAccountDAOAbstract<E> {
- public PollAccount getRestrictedPollAccount(String pollId,
- String accountId) throws TopiaException {
+ public E getRestrictedPollAccount(String pollId,
+ String accountId) throws TopiaException {
// List<PersonToList> tmp = transaction.find(
// "FROM " + PersonToList.class.getName() +
@@ -38,11 +42,60 @@
// "accountUId", accountId,
// "pollUId", pollId);
- TopiaQuery query = new TopiaQuery(PersonToList.class,"p").
- setSelect("p."+PersonToList.PROPERTY_POLL_ACCOUNT).
- addWhere("p."+PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_ACCOUNT_ID, TopiaQuery.Op.EQ, accountId).
- addWhere("p."+PersonToList.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL + "." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId);
- PollAccount result = findByQuery(query);
+ TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
+ setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
+ addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_ACCOUNT_ID, TopiaQuery.Op.EQ, accountId).
+ addWhere("p." + PersonToList.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL + "." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId);
+ E result = findByQuery(query);
return result;
}
+
+ public List<E> getFavoriteListUsers(PersonList favoriteList,
+ TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+
+ Preconditions.checkNotNull(favoriteList);
+ Preconditions.checkNotNull(pager);
+
+
+ int records = favoriteList.sizePollAccount();
+ pager.setRecords(records);
+
+ TopiaQuery query = createQuery("e");
+ TopiaFilterPagerUtil.addPagerToQuery(query, pager);
+ query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, favoriteList);
+
+ List<E> result = findAllByQuery(query);
+ return result;
+ }
+
+ public boolean isPollAccountExist(PersonList personListToUpdate,
+ PollAccount pollAccount) throws TopiaException {
+
+ Preconditions.checkNotNull(personListToUpdate);
+ Preconditions.checkNotNull(pollAccount);
+
+ // check there is other poll account in this list with same id
+ TopiaQuery query = createQuery("e");
+ query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
+ query.addWhere("e." + PollAccount.PROPERTY_VOTING_ID, TopiaQuery.Op.EQ, pollAccount.getVotingId());
+ boolean pollAccountExists = existByQuery(query);
+ return pollAccountExists;
+ }
+
+ public boolean isPollAccountAlreadyExist(PersonList personListToUpdate,
+ PollAccount pollAccount) throws TopiaException {
+
+ Preconditions.checkNotNull(personListToUpdate);
+ Preconditions.checkNotNull(pollAccount);
+
+ // check there is another poll account in this list with same id
+ TopiaQuery query = createQuery("e");
+ query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
+ query.addWhere("e." + PollAccount.PROPERTY_VOTING_ID, TopiaQuery.Op.EQ, pollAccount.getVotingId());
+ query.addWhere("e." + PollAccount.TOPIA_ID, TopiaQuery.Op.NEQ, pollAccount.getTopiaId());
+ boolean pollAccountExists = existByQuery(query);
+ return pollAccountExists;
+
+ }
+
} //PollAccountDAOImpl<E extends PollAccount>
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -0,0 +1,188 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.entities.PollenDAOHelper;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+
+import java.util.List;
+
+public class PollDAOImpl<E extends Poll> extends PollDAOAbstract<E> {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(PollDAOImpl.class);
+
+ public List<E> getPolls(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+
+ Preconditions.checkNotNull(pager);
+
+ long records = count();
+ pager.setRecords((int) records);
+
+ TopiaQuery query = createQuery("e");
+ TopiaFilterPagerUtil.addPagerToQuery(query, pager);
+
+ List<E> result = findAllByQuery(query);
+ return result;
+ }
+
+
+ public List<E> getCreatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) throws TopiaException {
+
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(user);
+
+ TopiaQuery countQuery = createQuery("e");
+ countQuery.addWhere("e." + Poll.PROPERTY_CREATOR + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, user);
+ long records = countByQuery(countQuery);
+ pager.setRecords((int) records);
+
+ TopiaQuery query = TopiaFilterPagerUtil.addPagerToQuery(countQuery, pager);
+
+ List<E> result = findAllByQuery(query);
+ return result;
+ }
+
+ public List<E> getInvitedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ UserAccount userToUse) throws TopiaException {
+
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(userToUse);
+
+ //FIXME Use a query to do this to avoid in memory pagination
+ String email = userToUse.getEmail();
+
+ List<E> polls = findAll();
+ List<E> allPolls = Lists.newLinkedList();
+ for (E poll : polls) {
+ for (VotingList votingList : poll.getVotingList()) {
+ for (PersonToList personToList : votingList
+ .getPollAccountPersonToList()) {
+ if (!personToList.isHasVoted()) {
+ PollAccount pollAccount = personToList
+ .getPollAccount();
+
+ if (pollAccount != null
+ && pollAccount.getEmail() != null
+ && pollAccount.getEmail().equals(
+ email)) {
+ allPolls.add(poll);
+ }
+ }
+ }
+ }
+ }
+
+ int records = allPolls.size();
+ pager.setRecords(records);
+
+ List<E> result = TopiaFilterPagerUtil.getPageFromList(allPolls, pager);
+ return result;
+
+// try {
+// PollDAO dao = PollenDAOHelper.getPollDAO(getTransaction());
+// TopiaQuery countQuery = dao.createQuery("e");
+// countQuery.addWhere("e." + Poll.PROPERTY_CREATOR + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, user);
+// long records = dao.countByQuery(countQuery);
+// pager.setRecords((int) records);
+//
+// PagerUtil.computeRecordIndexesAndPagesNumber(pager);
+// TopiaQuery query = dao.createQuery("e");
+// TopiaFilterPagerUtil.addPagerToQuery(pager, query);
+// query.addWhere("e." + Poll.PROPERTY_CREATOR + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, user);
+//
+// List<Poll> result = dao.findAllByQuery(query);
+// return result;
+// } catch (TopiaException e) {
+// throw new PollenTechnicalException(e);
+// }
+ }
+
+ public List<E> getParticipatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ UserAccount userToUse) throws TopiaException {
+
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(userToUse);
+
+ VoteDAO voteDao = PollenDAOHelper.getVoteDAO(context);
+
+ TopiaQuery countQuery = voteDao.createQuery("e").
+ addDistinct().
+ setSelect("e." + Vote.PROPERTY_POLL).
+ addWhere("e." + Vote.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, userToUse);
+
+ long records = countByQuery(countQuery);
+ pager.setRecords((int) records);
+
+ TopiaQuery query = TopiaFilterPagerUtil.addPagerToQuery(countQuery, pager);
+
+ List<E> result = findAllByQuery(query);
+ return result;
+
+ }
+
+ public List<E> getRunningPolls(boolean withEndDate) throws TopiaException {
+
+ List<E> results;
+ TopiaQuery query;
+
+ if (withEndDate) {
+
+ query = createQuery("poll").
+ addWhere("poll.endDate is not null and poll.endDate > current_timestamp()").
+ addWhere("poll.beginDate is null or poll.beginDate < current_timestamp()");
+
+// results = transaction
+// .find("from "
+// + Poll.class.getName()
+// + " as poll where (poll.endDate is not null and poll.endDate > current_timestamp())"
+// + " and (poll.beginDate is null or poll.beginDate < current_timestamp())");
+ } else {
+ query = createQuery("poll").
+ addWhere("poll.endDate is null or poll.endDate > current_timestamp()").
+ addWhere("poll.beginDate is null or poll.beginDate < current_timestamp()");
+
+// results = transaction
+// .find("from "
+// + Poll.class.getName()
+// + " as poll where (poll.endDate is null or poll.endDate > current_timestamp())"
+// + " and (poll.beginDate is null or poll.beginDate < current_timestamp())");
+ }
+
+ results = findAllByQuery(query);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Entities found: "
+ + ((results == null) ? "null" : results.size()));
+ }
+ return results;
+ }
+} //PollDAOImpl<E extends Poll>
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-03-14 09:42:22 UTC (rev 3179)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -42,4 +42,10 @@
}
return resultVote;
}
+
+ @Override
+ public String getAdminId() {
+ String accountId = getCreator().getAccountId();
+ return getPollId() + ":" + accountId;
+ }
} //PollImpl
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -0,0 +1,67 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+
+import java.util.List;
+
+public class UserAccountDAOImpl<E extends UserAccount> extends UserAccountDAOAbstract<E> {
+
+ public boolean isUserExist(UserAccount user) throws TopiaException {
+
+ Preconditions.checkNotNull(user);
+
+ // In case of email change, check if an other user has not already
+ // the new email
+ // FIXME-fdesbois-20100510 : replace by using id directly
+ TopiaQuery query = createQuery().
+ addWhere(UserAccount.PROPERTY_LOGIN,
+ TopiaQuery.Op.NEQ, user.getLogin());
+ query.addEquals(UserAccount.PROPERTY_EMAIL,
+ StringUtils.lowerCase(user.getEmail()));
+
+ // existing user found
+ boolean result = existByQuery(query);
+ return result;
+ }
+
+ public List<E> getUsers(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+
+ Preconditions.checkNotNull(pager);
+
+ long records = count();
+ pager.setRecords((int) records);
+
+ TopiaQuery query = createQuery("e");
+ TopiaFilterPagerUtil.addPagerToQuery(query, pager);
+
+ List<E> result = findAllByQuery(query);
+ return result;
+ }
+} //UserAccountDAOImpl<E extends UserAccount>
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -0,0 +1,115 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+
+import java.util.List;
+
+public class VoteDAOImpl<E extends Vote> extends VoteDAOAbstract<E> {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(VoteDAOImpl.class);
+
+ public List<E> getVotesByPoll(Poll poll,
+ TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+
+ Preconditions.checkNotNull(poll);
+ Preconditions.checkNotNull(pager);
+
+ List<E> results;
+
+ // No need to load votes for an anonymous poll
+ if (poll.isAnonymous()) {
+
+ results = Lists.newArrayList();
+ } else {
+
+ // FIXME-FD20100309 : change model to suppress link from poll to vote
+ // It's not necessary to have votes when retrieving the poll, this
+ // method do this job only when it's needed
+
+// if (log.isDebugEnabled()) {
+// log.debug("Load votes for poll with uid = " + poll.getPollId());
+// log.debug("LIMIT : startIndex = " + startIndex + " _ " +
+// "endIndex = " + endIndex);
+// }
+
+ // FIXME : refactor this to use TopiaQuery from ToPIA 2.3
+ // Order the results by creation date (the last vote done will be
+ // at the end of the list)
+ TopiaQuery query = createQuery("e").
+ addWhere("e.poll", TopiaQuery.Op.EQ, poll).
+ addOrder("topiaCreateDate");
+ TopiaFilterPagerUtil.addPagerToQuery(query, pager);
+ results = findAllByQuery(query);
+
+//
+// List<E> votes = find(
+// "FROM " + Vote.class.getName() +
+// " WHERE poll.pollId = :pollUId" +
+// " ORDER BY topiaCreateDate",
+// startIndex, endIndex,
+// new Object[]{"pollUId", poll.getPollId()});
+
+// if (log.isDebugEnabled()) {
+// log.debug("Nb votes found : " + votes.size());
+// }
+//
+// results = Lists.newArrayList(results);
+ }
+ return results;
+ }
+
+ public boolean hasAlreadyVoted(String votingId, Poll poll) throws TopiaException {
+
+ // Test using a count(*) on votes
+ TopiaQuery query = createQuery("e").
+ addWhere("e.poll", TopiaQuery.Op.EQ, poll).
+ addWhere("e.pollAccount.votingId", TopiaQuery.Op.EQ, votingId).
+ addOrder("topiaCreateDate");
+ boolean result = existByQuery(query);
+ return result;
+// List<Long> tmp = transaction.find(
+// "SELECT COUNT(*)" +
+// " FROM " + Vote.class.getName() +
+// " WHERE poll.pollId = :pollUId" +
+// " AND pollAccount.votingId = :votingId",
+// "pollUId", poll.getPollId(),
+// "votingId", votingId);
+//
+// int count = tmp.get(0).intValue();
+//
+// // If the count is greater than 0, there is an existing votingId
+// // who has already voted for the poll
+// result = count > 0;
+
+ }
+} //VoteDAOImpl<E extends Vote>
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-03-14 09:42:22 UTC (rev 3179)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-03-14 14:39:03 UTC (rev 3180)
@@ -78,12 +78,30 @@
migrateVoteCountingTypes(tx, queries);
// change all Boolean properties to boolean
- migrateToPrimitiveTypes(tx, queries);
+ migrateToPrimitiveTypes(queries);
+
+ // add foreign key indexes
+ addForeignKeyIndexes(queries);
}
- private void migrateToPrimitiveTypes(TopiaContextImplementor tx,
- List<String> queries) throws TopiaException {
+ private void addForeignKeyIndexes(List<String> queries) {
+ queries.add("CREATE INDEX idx_PollAccount_pollsCreated ON poll(creator);");
+ queries.add("CREATE INDEX idx_PollAccount_comment ON comment(pollAccount);");
+ queries.add("CREATE INDEX idx_PollAccount_vote ON vote(pollAccount);");
+ queries.add("CREATE INDEX idx_Poll_vote ON vote(poll);");
+ queries.add("CREATE INDEX idx_Poll_choice ON choice(poll);");
+ queries.add("CREATE INDEX idx_Poll_result ON result(poll);");
+ queries.add("CREATE INDEX idx_Poll_comment ON comment(poll);");
+ queries.add("CREATE INDEX idx_Poll_preventRule ON preventRule(poll);");
+ queries.add("CREATE INDEX idx_Poll_votingList ON votingList(poll);");
+ queries.add("CREATE INDEX idx_UserAccount_favoriteList ON personList(owner);");
+ queries.add("CREATE INDEX idx_UserAccount_pollAccount ON pollAccount(userAccount);");
+ queries.add("CREATE INDEX idx_PersonList_pollAccount ON pollAccount(personList);");
+ }
+
+ private void migrateToPrimitiveTypes(List<String> queries) throws TopiaException {
+
migrateBoolean(queries, "useraccount", "administrator");
migrateBoolean(queries, "choice", "validate");
migrateBoolean(queries, "personToList", "hasVoted");
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties 2012-03-14 09:42:22 UTC (rev 3179)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties 2012-03-14 14:39:03 UTC (rev 3180)
@@ -27,3 +27,4 @@
model.tagvalue.java.lang.String=text
model.tagvalue.version=1.2.6
model.tagvalue.doNotGenerateBooleanGetMethods=true
+model.tagvalue.indexForeignKeys=true
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
1
0
r3179 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions java/org/chorem/pollen/ui/actions/poll resources/config resources/i18n webapp/WEB-INF webapp/WEB-INF/jsp webapp/WEB-INF/jsp/poll
by tchemit@users.chorem.org 14 Mar '12
by tchemit@users.chorem.org 14 Mar '12
14 Mar '12
Author: tchemit
Date: 2012-03-14 10:42:22 +0100 (Wed, 14 Mar 2012)
New Revision: 3179
Url: http://chorem.org/repositories/revision/pollen/3179
Log:
ajout des import de liste de favoris dans sondages restreints
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-14 09:42:22 UTC (rev 3179)
@@ -29,6 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.StrutsStatics;
import org.chorem.pollen.PollenConfiguration;
+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;
@@ -247,4 +248,9 @@
String result = getDateTimeFormat().format(date);
return result;
}
+
+ public boolean isUserLoggued() {
+ UserAccount userAccount = getPollenSession().getUserAccount();
+ return userAccount != null;
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-14 09:42:22 UTC (rev 3179)
@@ -309,6 +309,9 @@
@Override
public void prepare() throws Exception {
+ // remove all stuff from session
+ getPollenSession().clearDynamicData();
+
pollTypes = decorateToName(PollType.values());
choiceTypes = decorateToName(ChoiceType.values());
voteCountingTypes = decorateToName(VoteCountingType.values());
@@ -366,12 +369,13 @@
Preconditions.checkNotNull(poll);
+ informationsError = false;
+
// poll must have a title
if (StringUtils.isEmpty(poll.getTitle())) {
addFieldError("poll.title", _("pollen.error.poll.required.title"));
}
- informationsError = false;
// validate choices
Map<Integer, Choice> orderedChoices = getOrderedChoices();
@@ -381,7 +385,6 @@
// poll must have at least one choice
addFieldError("poll.choices",
_("pollen.error.poll.required.one.choice"));
- informationsError = true;
} else {
//TODO tchemit improve this (from different cases text-date-image)
@@ -398,10 +401,10 @@
if (duplicateNameDetected) {
addFieldError("poll.choices",
_("pollen.error.poll.detected.duplicate.choice.name"));
- informationsError = true;
}
}
+
optionsError = false;
// validate security stuff
@@ -425,6 +428,14 @@
emails);
}
}
+
+ informationsError = hasFieldErrors();
+
+ if (!informationsError && optionsError) {
+
+ // trick to force to go back to form
+ addFieldError("", "");
+ }
}
@Override
@@ -563,7 +574,7 @@
// keep errors to display them in correct action
String errorToken = DisplayVotingList.getVotingListErrorTokenId(
- votingListTokenId, 0);
+ votingListTokenId, votingListNumber);
if (log.isInfoEnabled()) {
log.info("Add " + errors.size() + " errors to " + errorToken);
}
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java 2012-03-14 09:42:22 UTC (rev 3179)
@@ -0,0 +1,116 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.collect.Maps;
+import org.chorem.pollen.business.persistence.PersonList;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.PersonToListImpl;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.services.impl.FavoriteService;
+import org.chorem.pollen.ui.PollenSession;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import java.util.Map;
+
+/**
+ * Load in session a personToList to import into a votingList.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ImportPersonListToVotingList extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String TOKEN = "ImportPersonListToVotingList";
+
+ protected int votingListNumber;
+
+ protected int personToListNumber;
+
+ protected String personListId;
+
+ protected String tokenId;
+
+ /** Count of personToList for this votingList. */
+ protected int nbPersonToLists;
+
+ public int getVotingListNumber() {
+ return votingListNumber;
+ }
+
+ public void setVotingListNumber(int votingListNumber) {
+ this.votingListNumber = votingListNumber;
+ }
+
+ public int getPersonToListNumber() {
+ return personToListNumber;
+ }
+
+ public void setPersonToListNumber(int personToListNumber) {
+ this.personToListNumber = personToListNumber;
+ }
+
+ public String getPersonListId() {
+ return personListId;
+ }
+
+ public void setPersonListId(String personListId) {
+ this.personListId = personListId;
+ }
+
+ public String getTokenId() {
+ return tokenId;
+ }
+
+ public int getNbPersonToLists() {
+ return nbPersonToLists;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ tokenId = getServiceContext().createPollenUrlId() + TOKEN;
+ Map<Integer, PersonToList> data = Maps.newTreeMap();
+ FavoriteService service = newService(FavoriteService.class);
+ PollenSession session = getPollenSession();
+ PersonList favoriteList =
+ service.getFavoriteList(session.getUserAccount(), personListId);
+ nbPersonToLists = favoriteList.sizePollAccount();
+ if (nbPersonToLists > 0) {
+ int index = personToListNumber;
+ for (PollAccount pollAccount : favoriteList.getPollAccount()) {
+ PersonToList p = new PersonToListImpl();
+ p.setPollAccount(pollAccount);
+ p.setWeight(1);
+ data.put(index++, p);
+ }
+ }
+ session.putDynamicData(tokenId, data);
+
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java 2012-03-14 09:42:22 UTC (rev 3179)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.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.services.impl.FavoriteService;
+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(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class SelectPersonListToVotingList extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected int votingListNumber;
+
+ 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;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ FavoriteService service = newService(FavoriteService.class);
+ UserAccount userAccount = getPollenSession().getUserAccount();
+ List<PersonList> personLists = service.getFavoriteLists(userAccount);
+
+ personList = Maps.uniqueIndex(personLists, PollenFunctions.ENTITY_BY_ID);
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-14 09:42:22 UTC (rev 3179)
@@ -115,7 +115,8 @@
<result type="stream">
<param name="contentCharSet">UTF-8</param>
<param name="contentType">application/xml</param>
- <param name="contentDisposition">attachment;filename="${filename}"</param>
+ <param name="contentDisposition">attachment;filename="${filename}"
+ </param>
<param name="encode">true</param>
<param name="bufferSize">4096</param>
</result>
@@ -180,7 +181,8 @@
</action>
<!-- get the feed of a given poll -->
- <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetPollFeed">
+ <action name="getFeed"
+ class="org.chorem.pollen.ui.actions.poll.GetPollFeed">
<result type="stream">
<param name="contentCharSet">UTF-8</param>
<param name="contentType">application/atom+xml</param>
@@ -219,6 +221,25 @@
<result type="redirectToVote"/>
</action>
+ <!-- Select a favorite list to add to a voting list -->
+ <action name="selectPersonListToAddToVotingList"
+ class="org.chorem.pollen.ui.actions.poll.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">
+ <result>/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp
+ </result>
+ </action>
+
+ <!-- Load in session a personList to be imported into a voting list -->
+ <action name="displayPersonListToVotingList"
+ class="org.chorem.pollen.ui.actions.poll.ImportPersonListToVotingList">
+ <result type="json"/>
+ </action>
+
</package>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-14 09:42:22 UTC (rev 3179)
@@ -3,6 +3,7 @@
pollen.action.addPersonToList=Add a voter
pollen.action.addVotingList=Add a group
pollen.action.backToFavoriteLists=Back to favorite lists
+pollen.action.cancel=Cancel
pollen.action.create=Create
pollen.action.createFavoriteList=Create a new list
pollen.action.createPoll=Create the poll
@@ -192,6 +193,8 @@
pollen.label.pollRegisterPage=If you are a logged user, you can find these links on the page
pollen.label.pollVotePage=The link below leads to the page to vote for your poll. Save it and send it to the people that you want to vote \:
pollen.legend.login=Login
+pollen.legend.select.favoriteList.to.add=Sélectionner la liste de favoris à ajouter
+pollen.legend.select.personList.to.create.votingList=Sélectionner la liste des votant à importer dans le nouveau groupe
pollen.menu.admin=Administration
pollen.menu.createPoll=Create a poll
pollen.menu.home=Home
@@ -219,4 +222,6 @@
pollen.title.pollsParticipatedList=Polls participated
pollen.title.pollsParticipatedList.legend=Polls in which you are involved
pollen.title.register=Register
+pollen.title.selectPersonListToAddVotingList=Sélectionner une liste de votant à ajouter
+pollen.title.selectPersonListToCreateVotingList=Sélectionner une liste de votant pour créer un nouveau groupe
pollen.title.usersList=Users administration
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-14 09:42:22 UTC (rev 3179)
@@ -1,8 +1,12 @@
pollen.action.addChoice=Ajouter un choix
pollen.action.addComment=Ajouter un commentaire
+pollen.action.addPersonListFromVotingList=Ajouter des votants à partir d'une liste de votants
+pollen.action.addPersonListToVotingList=Ajouter la liste des votants
pollen.action.addPersonToList=Ajouter un votant
pollen.action.addVotingList=Ajouter un groupe
+pollen.action.addVotingListFromPersonList=Ajouter un groupe à partir d'une liste de votants
pollen.action.backToFavoriteLists=Retour à la liste des favoris
+pollen.action.cancel=Annuler
pollen.action.create=Créer
pollen.action.createFavoriteList=Créer une ouvelle liste
pollen.action.createPoll=Créer le sondage
@@ -18,6 +22,8 @@
pollen.action.editPollAccount=Editer le membre sélectionné
pollen.action.editUser=Editer un utilisateur sélectionné
pollen.action.editVote=Modifier le vote
+pollen.action.importPersonListToExistingVotingList=Ajouter la liste sélectionnée de votants
+pollen.action.importPersonListToNewVotingList=Créer un groupe à partir de la liste sélectionnée
pollen.action.login=M'identifier
pollen.action.modify=Modifier
pollen.action.pollChoiceDelete=Supprimer ce choix
@@ -75,6 +81,7 @@
pollen.common.or=ou
pollen.common.password=Mot de passe
pollen.common.password2=Répétez votre mot de passe
+pollen.common.personList=Liste de votants
pollen.common.personToList=Votant
pollen.common.pollCreator=Créateur
pollen.common.pollOption.anonymous=Sondage anonyme
@@ -193,6 +200,8 @@
pollen.label.pollRegisterPage=Si vous êtes un utilisateur identifié, vous pouvez retrouver ces liens dans la page
pollen.label.pollVotePage=Le lien ci-dessous mène à la page de vote. Enregistrez-le et envoyez-le à ceux que vous voulez voir voter \:
pollen.legend.login=Login
+pollen.legend.select.favoriteList.to.add=Sélectionner la liste de favoris à ajouter
+pollen.legend.select.personList.to.create.votingList=Sélectionner la liste des votant à importer dans le nouveau groupe
pollen.menu.admin=Administration
pollen.menu.createPoll=Créer un sondage
pollen.menu.home=Accueil
@@ -222,5 +231,7 @@
pollen.title.pollsParticipatedList=Sondages participés
pollen.title.pollsParticipatedList.legend=Liste des sondages pour lesquels vous avez voté
pollen.title.register=S'enregistrer
+pollen.title.selectPersonListToAddVotingList=Sélectionner une liste de votants à ajouter
+pollen.title.selectPersonListToCreateVotingList=Sélectionner une liste de votants pour créer un nouveau groupe
pollen.title.usersList=Gestion des utilisateurs
title=Création d'un sondage
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-03-14 09:42:22 UTC (rev 3179)
@@ -31,6 +31,7 @@
<pattern>/json/*</pattern>
<pattern>/poll/confirmDelete*</pattern>
<pattern>/poll/display*</pattern>
+ <pattern>/poll/selectPersonListTo*</pattern>
<pattern>/io/*</pattern>
</excludes>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -32,7 +32,7 @@
</div>
<div class="center">
- <s:a action="createPoll" namespace="/poll">
+ <s:a action="create" namespace="/poll" method="input">
<img src="<s:url value='/img/smallCreation_%{safeLanguage}.png' />" alt="poll creation"/>
</s:a>
<s:a action="createForm" namespace="/poll">
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -34,6 +34,31 @@
<script type="text/javascript">
+ function addPersonListToVotingList(personListId) {
+ console.info("person list to add into votingList : " + personListId);
+ return closeDialog();
+ }
+
+ function selectPersonListToAddToVotingList(votingListNumber) {
+ console.info("Add to votingList "+votingListNumber);
+ $('.ui-dialog-title').html('<s:text name="pollen.title.selectPersonListToAddVotingList"/>')
+ var dialog = $("#selectPersonListDialog");
+ var url = "<s:url action='selectPersonListToAddToVotingList' namespace='/poll'/>";
+ url += '?'+ $.param({votingListNumber:votingListNumber});
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
+ }
+
+ function selectPersonListToCreateNewVotingList() {
+ $('.ui-dialog-title').html('<s:text name="pollen.title.selectPersonListToCreateVotingList"/>')
+ var dialog = $("#selectPersonListDialog");
+ var url = "<s:url action='selectPersonListToCreateNewVotingList' namespace='/poll'/>";
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
+ }
+
jQuery(document).ready(function () {
$('[name="poll.choiceAddAllowed"]').change(function (event) {
var val = $(this).prop('checked');
@@ -285,9 +310,14 @@
<div id="votingLists">
<%--Where to load voting lists --%>
</div>
- <div class="groupPoll">
- <s:submit key="pollen.action.addVotingList" align="center"
+ <div class="groupPoll" align="center">
+ <s:submit key="pollen.action.addVotingList" theme="simple"
onclick="return addNewVotingList();"/>
+ <s:if test="userLoggued">
+ <s:submit key="pollen.action.addVotingListFromPersonList"
+ theme="simple"
+ onclick="return selectPersonListToCreateNewVotingList();"/>
+ </s:if>
</div>
</div>
</fieldset>
@@ -307,18 +337,18 @@
element.append(
'<image src="${errorImg}">'
);
- element.attr('title',
- '<s:text name="pollen.error.pollTabErrorFound"/>');
+ element.attr('title', '<s:text name="pollen.error.pollTabErrorFound"/>');
}
if (<s:property value="%{informationsError}"/>) {
- var tab = $('#tabGeneral a');
- addErrorImage(tab);
+ addErrorImage($('#tabGeneral a'));
}
if (<s:property value="%{optionsError}"/>) {
- tab = $('#tabOptions a');
- addErrorImage(tab);
+ addErrorImage($('#tabOptions a'));
}
});
-</script>
\ No newline at end of file
+</script>
+
+<sj:dialog id="selectPersonListDialog" resizable="true" autoOpen="false"
+ modal="true" width="500"/>
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -0,0 +1,40 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<s:set name="prefix">votingList_<s:property value="votingListNumber"/></s:set>
+
+<script type="text/javascript">
+ jQuery(document).ready(function () {
+ // personToList loading
+ <s:iterator begin="1" end="nbPersonToLists" status="status">
+ addPersonToList(<s:property value="votingListNumber"/>, <s:property value='personToListNumber + %{#status.index}'/>, <s:property value="nbPersonToLists - 1"/>, '<s:property value="tokenId" />');
+ </s:iterator>
+ });
+</script>
+
+<s:div id='personToList_%{votingListNumber}'>
+ <%--Where to load personToList--%>
+</s:div>
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -42,7 +42,7 @@
-
<s:label for="%{#prefix}.email" key="pollen.common.email" theme="simple"/>
<s:textfield cols="30" id="%{#prefix}.email" key="%{#prefix}.email"
- label='' theme="simple"
+ label='' theme="simple" size="30"
value="%{personToList.pollAccount.email}"/>
-
<s:label for="%{#prefix}.weight" key="pollen.common.weight" theme="simple"/>
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -0,0 +1,81 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+
+<script type="text/javascript">
+
+ var votingListNumber = parseInt('<s:property value='%{votingListNumber}'/>');
+
+ function cancel() {
+ $('#selectPersonListDialog').dialog('close');
+ return false;
+ }
+
+ function addPersonListToVotingList(personListId) {
+
+ // get first personToList number available
+ var containerId = "personToList_" + votingListNumber;
+ // get first personToList available position
+ var firstNumber = getFirstEmptyPersonToList(containerId);
+ if (firstNumber == -1) {
+ // no personToList available
+ // let's take a new one (max +1)
+ firstNumber = 1 + getLastPersonToList(containerId);
+ } else {
+ // remove all empty personToList
+ var numbers = getAllPersonToListNumbers(containerId);
+ for (n in numbers) {
+ if (n >= firstNumber) {
+ deletePersonToList(containerId + "_" + n);
+ }
+ }
+ }
+ loadPersonListToVotingList(votingListNumber, firstNumber, personListId);
+ return cancel();
+ }
+
+ jQuery(document).ready(function () {
+ $('#personList').change(function (event) {
+ var val = $(this).val();
+ $('#add').attr('disabled', val == '');
+ });
+ });
+
+</script>
+<fieldset class="ui-widget-content ui-corner-all">
+ <s:select id="personList" listValue="value.name" list="personList"
+ key='pollen.common.personList' headerKey="" headerValue=""/>
+ <hr/>
+ <div align="right">
+ <s:submit onclick="return cancel();" theme="simple"
+ key="pollen.action.cancel"/>
+ <s:submit
+ onclick="return addPersonListToVotingList($('#personList').val());"
+ theme="simple" disabled='true' id='add'
+ key="pollen.action.importPersonListToExistingVotingList"/>
+ </div>
+</fieldset>
+
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -0,0 +1,69 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<script type="text/javascript">
+
+ function cancel() {
+ $('#selectPersonListDialog').dialog('close');
+ return false;
+ }
+
+ function importPersonListToNewVotingList(personListId) {
+ // add a new votingList
+ addNewVotingList();
+ // get his number
+ var votingListNumber = getLastVotingList("votingLists");
+
+ var containerId = "personToList_" + votingListNumber;
+ // remove all personToList of this votingList
+ var numbers = getAllPersonToListNumbers(containerId);
+ for (n in numbers) {
+ deletePersonToList(containerId + "_" + n);
+ }
+ // add personList to this votingList at position 0
+ loadPersonListToVotingList(votingListNumber, 0, personListId);
+ return cancel();
+ }
+ jQuery(document).ready(function () {
+ $('#personList').change(function (event) {
+ var val = $(this).val();
+ $('#import').attr('disabled', val == '');
+ });
+ });
+
+</script>
+<fieldset class="ui-widget-content ui-corner-all">
+ <s:select id="personList" listValue="value.name" list="personList"
+ key='pollen.common.personList' headerKey="" headerValue=""/>
+ <hr/>
+ <div align="right">
+ <s:submit onclick="return cancel();" theme="simple"
+ key="pollen.action.cancel"/>
+ <s:submit id='import' disabled="true" theme="simple"
+ onclick="return importPersonListToNewVotingList($('#personList').val());"
+ key="pollen.action.importPersonListToNewVotingList"/>
+ </div>
+</fieldset>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -28,9 +28,6 @@
<s:set id='deleteTitle'>
<s:text name="pollen.action.pollVotingListDelete"/>
</s:set>
-<s:set id='editTitle'>
- <s:text name="pollen.action.pollVotingListEdit"/>
-</s:set>
<script type="text/javascript">
jQuery(document).ready(function () {
@@ -53,15 +50,11 @@
-
<s:label for="%{#prefix}.weight" key="pollen.common.weight"
theme="simple"/>
- <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight" value="%{votingList.weight}"
+ <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight"
+ value="%{votingList.weight}"
size="1" label='' theme="simple"/>
</div>
<div id='<s:property value="%{#prefix}"/>_actions' class="fright">
- <s:a href='#' onclick="return editVotingList('%{prefix}')">
- <image alt='<s:property value="editTitle"/>'
- title='<s:property value="editTitle"/>'
- src="<s:url value='/img/edit.png'/>"></image>
- </s:a>
<s:a href='#'
onclick="return deleteVotingList('votingLists_%{votingListNumber}')">
<image alt='<s:property value="deleteTitle"/>'
@@ -78,10 +71,20 @@
<%--Where to load personToList--%>
</s:div>
<hr/>
- <div class="cleanBoth"></div>
- <s:submit id='%{#prefix}_addPersonToList' name='%{#prefix}_addPersonToList'
- key="pollen.action.addPersonToList" align="center"
- onclick='return addNewPersonToList("%{votingListNumber}");'/>
+ <div class="cleanBoth" align="center">
+ <s:submit id='%{#prefix}_addPersonToList'
+ name='%{#prefix}_addPersonToList'
+ key="pollen.action.addPersonToList" theme="simple"
+ onclick='return addNewPersonToList("%{votingListNumber}");'/>
+ <s:if test="userLoggued">
+ <s:submit id='%{#prefix}_addPersonToList' theme="simple"
+ name='%{#prefix}_addPersonToList'
+ key="pollen.action.addPersonListFromVotingList"
+ onclick='return selectPersonListToAddToVotingList("%{votingListNumber}");'/>
+ </s:if>
+
+ </div>
+
</fieldset>
<br/>
</s:div>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-03-13 14:06:19 UTC (rev 3178)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-03-14 09:42:22 UTC (rev 3179)
@@ -27,166 +27,230 @@
<script type="text/javascript">
- var votingListText = '<s:text name="pollen.common.votingList"/>';
- var personToListText = '<s:text name="pollen.common.personToList"/>';
+var votingListText = '<s:text name="pollen.common.votingList"/>';
+var personToListText = '<s:text name="pollen.common.personToList"/>';
- function getFirstVotingList(containerId) {
- var result = 65535;
- getAllVotingLists(containerId).each(function () {
- var current = $(this).data('votingListNumber');
- if (current < result) {
- result = current;
- }
- });
- return result;
+function getFirstVotingList(containerId) {
+ var result = 65535;
+ getAllVotingLists(containerId).each(function () {
+ var current = $(this).data('votingListNumber');
+ if (current < result) {
+ result = current;
+ }
+ });
+ return result;
+}
+
+function getLastVotingList(containerId) {
+ var result = 0;
+ getAllVotingLists(containerId).each(function () {
+ var current = $(this).data('votingListNumber');
+ if (current > result) {
+ result = current;
+ }
+ });
+ return result;
+}
+
+function getAllVotingLists(containerId) {
+ return $("div[id^='" + containerId + "_']");
+}
+
+function updateUpdownVotingListActions(containerId) {
+ getAllVotingLists(containerId).each(function (index) {
+ var currentVotingListNumber = $(this).data('votingListNumber');
+ var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label");
+ labelWidget.html(votingListText + ' ' + (index + 1));
+ });
+}
+
+function loadVotingList(containerId, votingListNumber, nbVotingLists, tokenId) {
+ if (votingListNumber == -1) {
+ // to add a new votingList, get the new available votingListNumber
+ votingListNumber = 1 + getLastVotingList(containerId);
}
-
- function getLastVotingList(containerId) {
- var result = 0;
- getAllVotingLists(containerId).each(function () {
- var current = $(this).data('votingListNumber');
- if (current > result) {
- result = current;
+ $.ajax(
+ {
+ url:'<s:url namespace="/poll" action="displayVotingList"/>',
+ data:{ tokenId:tokenId, votingListNumber:votingListNumber },
+ async:false,
+ dataType:"html",
+ success:function (data, textStatus) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store votingListNumber
+ var votingList = $("#" + containerId + "_" + votingListNumber);
+ votingList.data('votingListNumber', votingListNumber);
+ votingList.data('votingListContainerId', containerId);
+ if (votingListNumber == nbVotingLists || !tokenId) {
+ updateUpdownVotingListActions(containerId);
+ }
}
});
- return result;
- }
+}
- function getAllVotingLists(containerId) {
- return $("div[id^='" + containerId + "_']");
- }
+function addVotingList(votingListNumber, nbVotingLists, tokenId) {
+ loadVotingList('votingLists', votingListNumber, nbVotingLists, tokenId);
+}
- function updateUpdownVotingListActions(containerId) {
- getAllVotingLists(containerId).each(function (index) {
- var currentVotingListNumber = $(this).data('votingListNumber');
- var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label");
- labelWidget.html(votingListText + ' ' + (index + 1));
- });
- }
+function addNewVotingList() {
+ addVotingList(-1, -1);
+ return false;
+}
- function loadVotingList(containerId, votingListNumber, nbVotingLists, tokenId) {
- if (votingListNumber == -1) {
- // to add a new votingList, get the new available votingListNumber
- votingListNumber = 1 + getLastVotingList(containerId);
+function deleteVotingList(votingListId) {
+ var votingList = $('#' + votingListId);
+ var containerId = votingList.data('votingListContainerId');
+ votingList.remove();
+ updateUpdownVotingListActions(containerId);
+ return false;
+}
+
+function getFirstPersonToList(containerId) {
+ var result = 65535;
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ if (current < result) {
+ result = current;
}
- $.ajax(
- {
- url:'<s:url namespace="/poll" action="displayVotingList"/>',
- data:{ tokenId:tokenId, votingListNumber:votingListNumber },
- async:false,
- dataType:"html",
- success:function (data, textStatus) {
- var container = $("#" + containerId);
- container.append(data);
- // store votingListNumber
- var votingList = $("#" + containerId + "_" + votingListNumber);
- votingList.data('votingListNumber', votingListNumber);
- votingList.data('votingListContainerId', containerId);
- if (votingListNumber == nbVotingLists || !tokenId) {
- updateUpdownVotingListActions(containerId);
- }
- }
- });
- }
+ });
+ return result;
+}
- function addVotingList(votingListNumber, nbVotingLists, tokenId) {
- loadVotingList('votingLists', votingListNumber, nbVotingLists, tokenId);
- }
+function getLastPersonToList(containerId) {
+ var result = 0;
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ if (current > result) {
+ result = current;
+ }
+ });
+ return result;
+}
- function addNewVotingList() {
- addVotingList(-1, -1);
- return false;
- }
+function getAllPersonToLists(containerId) {
+ return $("div[id^='" + containerId + "_']");
+}
- function deleteVotingList(votingListId) {
- var votingList = $('#' + votingListId);
- var containerId = votingList.data('votingListContainerId');
- votingList.remove();
- updateUpdownVotingListActions(containerId);
- return false;
+function getAllPersonToListNumbers(containerId) {
+ var result = [];
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ result.push(current);
+ });
+ return result;
+}
+
+function getFirstEmptyPersonToList(containerId) {
+ var result = -1;
+ var numbers = getAllPersonToListNumbers(containerId);
+ for (var n in numbers) {
+ var nameInput = $('[name="' + containerId + '_' + n + '.votingId"]');
+ var emailInput = $('[name="' + containerId + '_' + n + '.email"]');
+
+ var name = nameInput.val();
+ var email = emailInput.val();
+ if (name == '' && email == '') {
+ result = n;
+ break;
+ }
}
+ return result;
+}
- function getFirstPersonToList(containerId) {
- var result = 65535;
- getAllPersonToLists(containerId).each(function () {
- var current = $(this).data('personToListNumber');
- if (current < result) {
- result = current;
- }
- });
- return result;
+function updateUpdownPersonToListActions(containerId) {
+ getAllPersonToLists(containerId).each(function (index) {
+ var currentPersonToListNumber = $(this).data('personToListNumber');
+ var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label");
+ labelWidget.html(personToListText + ' ' + (index + 1));
+ });
+}
+
+function loadPersonToList(containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
+ if (personToListNumber == -1) {
+ // to add a new personToList, get the new available personToListNumber
+ personToListNumber = 1 + getLastPersonToList(containerId);
}
-
- function getLastPersonToList(containerId) {
- var result = 0;
- getAllPersonToLists(containerId).each(function () {
- var current = $(this).data('personToListNumber');
- if (current > result) {
- result = current;
+ $.ajax(
+ {
+ url:'<s:url namespace="/poll" action="displayPersonToList"/>',
+ data:{
+ tokenId:tokenId,
+ votingListNumber:votingListNumber,
+ personToListNumber:personToListNumber
+ },
+ async:false,
+ dataType:"html",
+ success:function (data, textStatus) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store personToListNumber
+ var personToList = $("#" + containerId + "_" + personToListNumber);
+ personToList.data('votingListNumber', votingListNumber);
+ personToList.data('personToListNumber', personToListNumber);
+ personToList.data('personToListContainerId', containerId);
+ if (personToListNumber == nbPersonToLists || !tokenId) {
+ updateUpdownPersonToListActions(containerId);
+ }
}
});
- return result;
- }
+}
- function getAllPersonToLists(containerId) {
- return $("div[id^='" + containerId + "_']");
- }
+function addPersonToList(votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
+ loadPersonToList(
+ 'personToList_' + votingListNumber,
+ votingListNumber, personToListNumber, nbPersonToLists, tokenId
+ );
+}
- function updateUpdownPersonToListActions(containerId) {
- getAllPersonToLists(containerId).each(function (index) {
- var currentPersonToListNumber = $(this).data('personToListNumber');
- var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label");
- labelWidget.html(personToListText + ' ' + (index + 1));
- });
- }
+function addNewPersonToList(votingListNumber) {
+ addPersonToList(votingListNumber, -1, -1);
+ return false;
+}
- function loadPerson(containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
- if (personToListNumber == -1) {
- // to add a new personToList, get the new available personToListNumber
- personToListNumber = 1 + getLastPersonToList(containerId);
- }
- $.ajax(
- {
- url:'<s:url namespace="/poll" action="displayPersonToList"/>',
- data:{
- tokenId:tokenId,
- votingListNumber:votingListNumber,
- personToListNumber:personToListNumber
- },
- async:false,
- dataType:"html",
- success:function (data, textStatus) {
- var container = $("#" + containerId);
- container.append(data);
- // store personToListNumber
- var personToList = $("#" + containerId + "_" + personToListNumber);
- personToList.data('votingListNumber', votingListNumber);
- personToList.data('personToListNumber', personToListNumber);
- personToList.data('personToListContainerId', containerId);
- if (personToListNumber == nbPersonToLists || !tokenId) {
- updateUpdownPersonToListActions(containerId);
- }
- }
- });
- }
+function deletePersonToList(personToListId) {
+ var personToList = $('#' + personToListId);
+ var containerId = personToList.data('personToListContainerId');
+ personToList.remove();
+ updateUpdownPersonToListActions(containerId);
+ return false;
+}
- function addPersonToList(votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
- loadPerson(
- 'personToList_' + votingListNumber,
- votingListNumber, personToListNumber, nbPersonToLists, tokenId
- );
- }
- function addNewPersonToList(votingListNumber) {
- addPersonToList(votingListNumber, -1, -1);
- return false;
- }
+function loadPersonListToVotingList(votingListNumber, personToListNumber, personListId) {
- function deletePersonToList(personToListId) {
- var personToList = $('#' + personToListId);
- var containerId = personToList.data('personToListContainerId');
- personToList.remove();
- updateUpdownPersonToListActions(containerId);
- return false;
- }
+ $.ajax(
+ {
+ url:'<s:url namespace="/poll" action="displayPersonListToVotingList"/>',
+ data:{
+ votingListNumber:votingListNumber,
+ personToListNumber:personToListNumber,
+ personListId:personListId },
+ async:false,
+ dataType:"json",
+ success:function (data, textStatus) {
+ var token = data.tokenId;
+ var nbPersonToLists = parseInt(data.nbPersonToLists);
+ var personToListNumber = parseInt(data.personToListNumber);
+ var maxPersonToListNumber = parseInt(personToListNumber) + nbPersonToLists - 1;
+ console.info(">> token = " + token);
+ console.info(">> personListId = " + personListId);
+ console.info(">> incoming votingListNumber = " + votingListNumber);
+ console.info(">> nb personToList to import = " + nbPersonToLists);
+ console.info(">> first personToListNumber = " + personToListNumber);
+ console.info(">> last PersonToListNumber = " + maxPersonToListNumber);
+
+ var index = personToListNumber;
+ while (index <= maxPersonToListNumber) {
+ console.info("Will load personToList = " + index + " / " + maxPersonToListNumber);
+ addPersonToList(votingListNumber,
+ index,
+ maxPersonToListNumber,
+ token
+ );
+ index += 1;
+ }
+ }
+ });
+}
</script>
\ No newline at end of file
1
0
13 Mar '12
Author: tchemit
Date: 2012-03-13 15:06:19 +0100 (Tue, 13 Mar 2012)
New Revision: 3178
Url: http://chorem.org/repositories/revision/pollen/3178
Log:
page de creation de sondage presque finie :)
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/imageChoice.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/resume.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/textChoice.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-13 14:06:19 UTC (rev 3178)
@@ -251,9 +251,7 @@
// email notification
EmailService emailService = newService(EmailService.class);
- emailService.onPollCreated(poll,
- pollVoteUrl,
- pollEditUrl);
+ emailService.onPollCreated(poll, pollVoteUrl, pollEditUrl);
// feed notification
PollFeedService pollFeedService = newService(PollFeedService.class);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-13 14:06:19 UTC (rev 3178)
@@ -55,23 +55,35 @@
this.userAccount = userAccount;
}
- public Map<String, Object> getDynamicData() {
- if (dynamicData == null) {
- dynamicData = Maps.newHashMap();
- }
- return dynamicData;
+ public <T> T getDynamicData(String token) {
+ Object result = getDynamicData().get(token);
+ return (T) result;
}
public void putDynamicData(String token, Object data) {
getDynamicData().put(token, data);
+ if (log.isInfoEnabled()) {
+ log.info("Dynamic attributes size : " + getDynamicData().size());
+ }
}
- public <T> T getDynamicData(String token) {
- Object result = getDynamicData().get(token);
- return (T) result;
- }
-
public void removeDynamicData(String token) {
getDynamicData().remove(token);
+ if (log.isInfoEnabled()) {
+ log.info("Dynamic attributes size : " + getDynamicData().size());
+ }
}
+
+ public void clearDynamicData() {
+ if (dynamicData != null) {
+ dynamicData.clear();
+ }
+ }
+
+ protected Map<String, Object> getDynamicData() {
+ if (dynamicData == null) {
+ dynamicData = Maps.newHashMap();
+ }
+ return dynamicData;
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java 2012-03-13 14:06:19 UTC (rev 3178)
@@ -31,6 +31,8 @@
import org.nuiton.topia.TopiaRuntimeException;
import org.nuiton.web.filter.TopiaTransactionFilter;
+import javax.servlet.ServletRequest;
+
/**
* EchoBase implementation of the {@link TopiaTransactionFilter}.
*
@@ -44,7 +46,7 @@
LogFactory.getLog(PollenTopiaTransactionFilter.class);
@Override
- protected TopiaContext beginTransaction() throws TopiaRuntimeException {
+ protected TopiaContext beginTransaction(ServletRequest request) throws TopiaRuntimeException {
PollenApplicationContext applicationContext =
PollenActionSupport.getPollenApplicationContext();
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-13 14:06:19 UTC (rev 3178)
@@ -24,6 +24,7 @@
package org.chorem.pollen.ui.actions.poll;
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;
@@ -37,9 +38,15 @@
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceImpl;
+import org.chorem.pollen.business.persistence.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.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;
@@ -47,6 +54,7 @@
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.services.impl.PreventRuleService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
+import org.nuiton.util.StringUtil;
import java.io.File;
import java.util.Collections;
@@ -71,14 +79,17 @@
private static final Log log = LogFactory.getLog(CreatePoll.class);
public static final Pattern TEXT_CHOICE_NAME_PATTERN =
- Pattern.compile("textChoice_(\\d+).name");
+ Pattern.compile("textChoice_(\\d+)\\.name");
public static final Pattern DATE_CHOICE_NAME_PATTERN =
- Pattern.compile("dateChoice_(\\d+).name");
+ Pattern.compile("dateChoice_(\\d+)\\.name");
public static final Pattern IMAGE_CHOICE_NAME_PATTERN =
- Pattern.compile("imageChoice_(\\d+).name");
+ Pattern.compile("imageChoice_(\\d+)\\.name");
+ public static final Pattern VOTING_LIST_NAME_PATTERN =
+ Pattern.compile("votingList_(\\d+)\\.name");
+
protected Poll poll;
protected Map<String, String> pollTypes;
@@ -101,12 +112,16 @@
private String imageChoiceTokenId;
+ private String votingListTokenId;
+
private int nbTextChoices;
private int nbDateChoices;
private int nbImageChoices;
+ private int nbVotingLists;
+
/** Uploaded images (for choice type poll). */
private List<File> imageChoice;
@@ -122,6 +137,10 @@
*/
private Map<String, String[]> parameters;
+ private boolean informationsError;
+
+ private boolean optionsError;
+
protected transient PollService pollService;
@Override
@@ -162,6 +181,14 @@
return imageChoiceTokenId;
}
+ public int getNbVotingLists() {
+ return nbVotingLists;
+ }
+
+ public String getVotingListTokenId() {
+ return votingListTokenId;
+ }
+
public Map<String, String> getPollTypes() {
return pollTypes;
}
@@ -239,6 +266,46 @@
addtoList(getImageChoiceFileName(), index, imageChoiceFileName);
}
+ public boolean isInformationsError() {
+ return informationsError;
+ }
+
+ public boolean isOptionsError() {
+ return optionsError;
+ }
+
+ public boolean isFreePoll() {
+ PollType pollType = poll.getPollType();
+ return pollType == PollType.FREE;
+ }
+
+ public boolean isGroupPoll() {
+ PollType pollType = poll.getPollType();
+ return pollType == PollType.GROUP;
+ }
+
+ public String getPollVoteUrl() {
+ return getPollService().getPollVoteUrl(poll);
+ }
+
+ public String getPollEditUrl() {
+ return getPollService().getPollEditUrl(poll);
+ }
+
+ public int getSelectedTab() {
+ int result;
+ if (isInformationsError()) {
+ result = 0;
+ } else {
+ if (isOptionsError()) {
+ result = 1;
+ } else {
+ result = 0;
+ }
+ }
+ return result;
+ }
+
@Override
public void prepare() throws Exception {
@@ -248,6 +315,7 @@
//TODO tchemit-2012-03-05 use a default value from configuration
nbTextChoices = nbDateChoices = nbImageChoices = 5;
+ nbVotingLists = 1;
String tokenSuffix = getServiceContext().createPollenUrlId();
@@ -284,6 +352,13 @@
break;
}
getPollenSession().putDynamicData(tokenId, choices);
+
+ // load votingLists
+
+ votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
+ tokenSuffix;
+ Map<Integer, VotingList> votingLists = buildVotingLists(1);
+ getPollenSession().putDynamicData(votingListTokenId, votingLists);
}
@Override
@@ -293,9 +368,11 @@
// poll must have a title
if (StringUtils.isEmpty(poll.getTitle())) {
- addFieldError("poll.title", _("poll.error.poll.required.title"));
+ addFieldError("poll.title", _("pollen.error.poll.required.title"));
}
+ informationsError = false;
+
// validate choices
Map<Integer, Choice> orderedChoices = getOrderedChoices();
@@ -303,7 +380,8 @@
// poll must have at least one choice
addFieldError("poll.choices",
- _("poll.error.poll.required.one.choice"));
+ _("pollen.error.poll.required.one.choice"));
+ informationsError = true;
} else {
//TODO tchemit improve this (from different cases text-date-image)
@@ -319,12 +397,34 @@
}
if (duplicateNameDetected) {
addFieldError("poll.choices",
- _("poll.error.poll.detected.duplicate.choice.name"));
+ _("pollen.error.poll.detected.duplicate.choice.name"));
+ informationsError = true;
}
}
+ optionsError = false;
+
// validate security stuff
+ if (isFreePoll()) {
+
+ // nothing to validate
+
+ } else {
+ Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+
+ Set<String> groups = Sets.newHashSet();
+ Set<String> voters = Sets.newHashSet();
+ Set<String> emails = Sets.newHashSet();
+
+ for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) {
+ optionsError |= validateVotingList(entry.getKey(),
+ entry.getValue(),
+ groups,
+ voters,
+ emails);
+ }
+ }
}
@Override
@@ -337,6 +437,15 @@
poll.addChoice(choice);
}
+ if (!isFreePoll()) {
+
+ Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+ for (Integer index : votingLists.keySet()) {
+ VotingList votingList = votingLists.get(index);
+ poll.addVotingList(votingList);
+ }
+ }
+
PollService service = getPollService();
PreventRuleService preventRuleService =
@@ -363,20 +472,183 @@
poll = service.createPoll(poll);
// remove all stuff from session
- getPollenSession().removeDynamicData(textChoiceTokenId);
- getPollenSession().removeDynamicData(dateChoiceTokenId);
- getPollenSession().removeDynamicData(imageChoiceTokenId);
+ getPollenSession().clearDynamicData();
- addActionMessage(_("poll.info.poll.created"));
+ addActionMessage(_("pollen.info.poll.created"));
return SUCCESS;
}
- public String getPollVoteUrl() {
- return getPollService().getPollVoteUrl(poll);
+ protected boolean validateVotingList(int votingListNumber,
+ VotingList votingList,
+ Set<String> groups,
+ Set<String> voters,
+ Set<String> emails) {
+
+ boolean result = false;
+ Map<String, String> errors = Maps.newHashMap();
+
+ String votingListErrorPrefix = "poll.votingList_" + 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)) {
+
+ errors.put(votingListErrorPrefix + ".name",
+ _("pollen.error.poll.required.votingList.name"));
+ } else {
+
+ // check no votingList name doublon
+ boolean add = groups.add(votingListName);
+ if (!add) {
+
+ // name doublon
+ errors.put(
+ votingListErrorPrefix + ".name",
+ _("pollen.error.poll.votingList.name.doublon"));
+ }
+
+ }
+ }
+
+ { // validate votingList weight
+
+ if (votingList.getWeight() == 0) {
+
+ // no weight filled (can be a bad conversion)
+ errors.put(
+ votingListErrorPrefix + ".weight",
+ _("pollen.error.poll.votingList.weight.not.valid"));
+ }
+ }
+ }
+
+ // check there is at least one voter
+
+ String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
+ votingListTokenId, votingListNumber);
+
+ Map<Integer, PersonToList> personToLists =
+ getPollenSession().getDynamicData(persontoListToken);
+
+ if (MapUtils.isEmpty(personToLists)) {
+
+ // no personToList found for unique votingList 0
+ errors.put(votingListErrorPrefix,
+ _("pollen.error.poll.required.one.personToList"));
+ } else {
+
+ // check no doublon on voter names
+ // check no doublon on voter emails
+
+ for (Map.Entry<Integer, PersonToList> entry :
+ personToLists.entrySet()) {
+
+ result |= validatePersonList(entry.getKey(), entry.getValue(),
+ voters, emails);
+ }
+ }
+
+ if (MapUtils.isNotEmpty(errors)) {
+
+ // keep errors to display them in correct action
+ String errorToken = DisplayVotingList.getVotingListErrorTokenId(
+ votingListTokenId, 0);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + errors.size() + " errors to " + errorToken);
+ }
+ getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
}
- public String getPollEditUrl() {
- return getPollService().getPollEditUrl(poll);
+ protected boolean validatePersonList(int personToListNumber,
+ PersonToList personToList,
+ Set<String> voters,
+ Set<String> emails) {
+
+ boolean result = false;
+ Map<String, String> errors = Maps.newHashMap();
+ String fieldNamePrefix =
+ "personToList_0_" + personToListNumber;
+ PollAccount pollAccount = personToList.getPollAccount();
+
+ { // validate votingId
+
+ String votingId = pollAccount.getVotingId();
+ // check voter is not doublon
+ boolean add = voters.add(votingId);
+ if (!add) {
+
+ // voter doublon
+ errors.put(
+ fieldNamePrefix + ".votingId",
+ _("pollen.error.poll.personToList.votingId.doublon"));
+ }
+ }
+ { // validate email
+ String email = pollAccount.getEmail();
+
+ if (StringUtils.isEmpty(email)) {
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.required"));
+ } else {
+
+
+ boolean validEmail = StringUtil.isEmail(email);
+ if (!validEmail) {
+
+ // not a valid email
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.not.valid"));
+ } else {
+
+ // check email not doublon
+ boolean add = emails.add(email);
+ if (!add) {
+
+ // email doublon
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.doublon"));
+ }
+ }
+ }
+ }
+ { // validate weight
+ if (personToList.getWeight() == 0) {
+
+ // no weight filled (can be a bad conversion)
+ errors.put(
+ fieldNamePrefix + ".weight",
+ _("pollen.error.poll.personToList.weight.not.valid"));
+ }
+ }
+
+ if (MapUtils.isNotEmpty(errors)) {
+ String errorToken =
+ DisplayPersonToList.getPersonToListErrorTokenId(
+ votingListTokenId, 0, personToListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + errors.size() + " errors to " + errorToken);
+ }
+ getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
}
@Override
@@ -392,27 +664,28 @@
}
protected Map<Integer, Choice> getOrderedChoices() {
-
- Map<Integer, Choice> orderedChoices = null;
+ Map<Integer, Choice> result = null;
switch (poll.getChoiceType()) {
-
case TEXT:
- orderedChoices = getPollenSession().getDynamicData(
- textChoiceTokenId);
-
+ result = getPollenSession().getDynamicData(textChoiceTokenId);
break;
case DATE:
- orderedChoices = getPollenSession().getDynamicData(
- dateChoiceTokenId);
+ result = getPollenSession().getDynamicData(dateChoiceTokenId);
break;
case IMAGE:
- orderedChoices = getPollenSession().getDynamicData(
- imageChoiceTokenId);
+ result = getPollenSession().getDynamicData(imageChoiceTokenId);
break;
}
- return orderedChoices;
+ return result;
}
+ protected Map<Integer, VotingList> getOrderedVotingLists() {
+
+ Map<Integer, VotingList> result = getPollenSession().getDynamicData(
+ votingListTokenId);
+ return result;
+ }
+
protected Map<Integer, Choice> buildTextChoices(int nbDefault) {
Map<Integer, Choice> result = Maps.newTreeMap();
@@ -441,7 +714,7 @@
}
}
}
- result = reindexChoices(result, maxNumber);
+ result = reindexMap(result, maxNumber);
int size = result.size();
nbTextChoices = Math.max(nbDefault, size);
@@ -478,7 +751,7 @@
}
}
}
- result = reindexChoices(result, maxNumber);
+ result = reindexMap(result, maxNumber);
int size = result.size();
nbDateChoices = Math.max(nbDefault, size);
@@ -495,8 +768,11 @@
for (String fileName : getImageChoiceFileName()) {
if (fileName != null) {
- parameters.put("imageChoice_" + index + ".name", new String[]{fileName});
- parameters.put("imageChoice_" + index + ".location", new String[]{getImageChoice().get(index).getAbsolutePath()});
+ parameters.put("imageChoice_" + index + ".name",
+ new String[]{fileName});
+ parameters.put(
+ "imageChoice_" + index + ".location",
+ new String[]{getImageChoice().get(index).getAbsolutePath()});
}
index++;
}
@@ -527,7 +803,7 @@
}
}
}
- result = reindexChoices(result, maxNumber);
+ result = reindexMap(result, maxNumber);
int size = result.size();
nbImageChoices = Math.max(nbDefault, size);
log.info("nbImageChoices (from request) = " + size);
@@ -535,18 +811,186 @@
return result;
}
- private void logChoice(Map<Integer, Choice> result) {
- for (Map.Entry<Integer, Choice> e : result.entrySet()) {
- Integer choiceId = e.getKey();
- Choice choice = e.getValue();
- if (log.isInfoEnabled()) {
- log.info("Choice [" + choiceId + "] = " +
- choice.getName() + " -- " +
- choice.getDescription());
+ protected Map<Integer, VotingList> buildVotingLists(int nbDefault) {
+ Map<Integer, VotingList> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+
+ // get all votingList_ parameters
+ Set<String> votingListParameterNames = Sets.filter(
+ parameters.keySet(),
+ new StringStartWithPredicate("votingList_"));
+
+ for (String paramName : votingListParameterNames) {
+
+ Matcher matcher = VOTING_LIST_NAME_PATTERN.matcher(paramName);
+
+ if (matcher.matches()) {
+
+ // found a voting list name
+
+ int votingListNumber = buildVotingList(paramName,
+ matcher,
+ result
+ );
+ maxNumber = Math.max(maxNumber, votingListNumber);
}
}
+
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+ nbVotingLists = Math.max(nbDefault, size);
+ log.info("nbVotingList (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()) {
+ Integer votingListNumber = entry.getKey();
+ 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);
+ }
+
+ String token = DisplayPersonToList.getPersonToListTokenId(
+ votingListTokenId, votingListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + token + " with " +
+ personToListMap.size() + " personToList");
+ }
+ getPollenSession().putDynamicData(token, personToListMap);
+ }
+ }
+
+ 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 buildVotingList(String votingListParameterName,
+ Matcher votingListMatcher,
+ Map<Integer, VotingList> result) {
+
+ String paramValue = getNonEmptyParameterValue(votingListParameterName);
+ int votingListNumber = Integer.valueOf(votingListMatcher.group(1));
+
+ VotingList votingList = new VotingListImpl();
+
+ votingList.setName(paramValue);
+
+ String prefix = "votingList_" + votingListNumber;
+
+ double weight = getDoubleValue(prefix + ".weight");
+ votingList.setWeight(weight);
+
+ String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
+ votingList.setTopiaId(topiaId);
+
+ result.put(votingListNumber, votingList);
+
+ String personToListPrefix = "personToList_" + votingListNumber + "_";
+
+ // 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) {
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+
+ int personToListNumber = 0;
+
+ if (paramValue != null) {
+
+ // found a PersonToList none empty name, keep it
+
+ personToListNumber = Integer.valueOf(personToListMatcher.group(1));
+
+ PersonToList personToList = new PersonToListImpl();
+
+ PollAccount account = new PollAccountImpl();
+ personToList.setPollAccount(account);
+
+ account.setVotingId(paramValue);
+
+ 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);
+
+ result.put(personToListNumber, personToList);
+ }
+ return personToListNumber;
+ }
+
private Choice createImageChoice(PollImageChoice choice,
String prefix,
String name) {
@@ -581,11 +1025,22 @@
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());
+ }
+ }
+ }
- private Map<Integer, Choice> reindexChoices(Map<Integer, Choice> result,
- int maxNumber) {
- Map<Integer, Choice> result2;
+ private <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
@@ -599,7 +1054,7 @@
result2 = Maps.newTreeMap();
int i = 0;
for (Integer number : numbers) {
- Choice choice = result.get(number);
+ T choice = result.get(number);
result2.put(i++, choice);
}
} else {
@@ -636,4 +1091,17 @@
}
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);
+ }
+ }
}
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-03-13 14:06:19 UTC (rev 3178)
@@ -0,0 +1,158 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.PersonToListImpl;
+import org.chorem.pollen.business.persistence.PollAccountImpl;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import java.util.Map;
+
+/**
+ * To display a personToList (use at a poll creation).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+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;
+ }
+
+ /** Where to find dynamic data (says choices in this case). */
+ protected String tokenId;
+
+ /** Number of the vontingList container. */
+ protected int votingListNumber;
+
+ /** Number of person to display. */
+ protected int personToListNumber;
+
+ protected PersonToList personToList;
+
+ public String getTokenId() {
+ return tokenId;
+ }
+
+ public void setTokenId(String tokenId) {
+ this.tokenId = tokenId;
+ }
+
+ public int getVotingListNumber() {
+ return votingListNumber;
+ }
+
+ public void setVotingListNumber(int votingListNumber) {
+ this.votingListNumber = votingListNumber;
+ }
+
+ 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 (StringUtils.isNotEmpty(tokenId)) {
+
+ Map<Integer, PersonToList> personToLists =
+ getPollenSession().getDynamicData(tokenId);
+
+ if (personToLists != null) {
+
+ // get choices from datas
+ personToList = personToLists.get(personToListNumber);
+
+ if (personToList != null) {
+
+ // remove this choice from session
+ personToLists.remove(personToListNumber);
+ }
+ }
+
+ if (MapUtils.isEmpty(personToLists)) {
+
+ // remove it from session
+ getPollenSession().removeDynamicData(tokenId);
+ }
+ }
+
+ if (personToList == null) {
+ personToList = new PersonToListImpl();
+ personToList.setWeight(1);
+ PollAccountImpl pollAccount = new PollAccountImpl();
+ personToList.setPollAccount(pollAccount);
+ }
+
+ // consume personToList errors
+ String token = getPersonToListErrorTokenId(tokenId, personToListNumber);
+ Map<String, String> errors = getPollenSession().getDynamicData(token);
+ if (MapUtils.isNotEmpty(errors)) {
+ // transmit them as field errors
+ for (Map.Entry<String, String> e : errors.entrySet()) {
+ String fieldName = e.getKey();
+ String errorMessage = e.getValue();
+ if (log.isInfoEnabled()) {
+ log.info("Transmit error on " + fieldName + " [" + errorMessage + "]");
+ }
+ addFieldError(fieldName, errorMessage);
+ }
+ }
+ getPollenSession().removeDynamicData(token);
+ return SUCCESS;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-03-13 14:06:19 UTC (rev 3178)
@@ -0,0 +1,150 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.business.persistence.VotingListImpl;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import java.util.Map;
+
+/**
+ * To display a voting list of a poll (use at a poll creation).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class DisplayVotingList extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String VOTING_LIST_TOKEN = "votingList";
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(DisplayVotingList.class);
+
+ public static String getVotingListErrorTokenId(String votingListTokenId,
+ int votingListNumber) {
+ return votingListTokenId + "_" + votingListNumber + "_errors";
+ }
+
+ /** Where to find dynamic data (says choices in this case). */
+ protected String tokenId;
+
+ /** Number of person to display. */
+ protected int votingListNumber;
+
+ /** Count of personToList for this votingList. */
+ protected int nbPersonToLists;
+
+ /** The voting list ot display. */
+ protected VotingList votingList;
+
+ public String getPersonToListTokenId() {
+ return DisplayPersonToList.getPersonToListTokenId(tokenId, votingListNumber);
+ }
+
+ public int getNbPersonToLists() {
+ return nbPersonToLists;
+ }
+
+ public String getTokenId() {
+ return tokenId;
+ }
+
+ public void setTokenId(String tokenId) {
+ this.tokenId = tokenId;
+ }
+
+ public int getVotingListNumber() {
+ return votingListNumber;
+ }
+
+ public void setVotingListNumber(int votingListNumber) {
+ this.votingListNumber = votingListNumber;
+ }
+
+ public VotingList getVotingList() {
+ return votingList;
+ }
+
+ @Override
+ public String execute() throws Exception {
+ if (StringUtils.isNotEmpty(tokenId)) {
+
+ Map<Integer, VotingList> votingLists =
+ getPollenSession().getDynamicData(tokenId);
+
+ if (votingLists != null) {
+
+ // get choices from datas
+ votingList = votingLists.get(votingListNumber);
+
+ if (votingList != null) {
+
+ // remove this choice from session
+ votingLists.remove(votingListNumber);
+ }
+ }
+
+ if (MapUtils.isEmpty(votingLists)) {
+
+ // remove it from session
+ getPollenSession().removeDynamicData(tokenId);
+ }
+ }
+
+ if (votingList == null) {
+ votingList = new VotingListImpl();
+ votingList.setWeight(1);
+
+ //TODO tchemit use a default value from configuration
+ nbPersonToLists = 5;
+ } else {
+ nbPersonToLists = votingList.sizePollAccountPersonToList();
+ }
+ nbPersonToLists = Math.max(5, nbPersonToLists);
+
+ // consume votingList errors
+ String token = getVotingListErrorTokenId(tokenId, votingListNumber);
+ Map<String, String> errors = getPollenSession().getDynamicData(token);
+ if (MapUtils.isNotEmpty(errors)) {
+ // transmit them as field errors
+ for (Map.Entry<String, String> e : errors.entrySet()) {
+ String fieldName = e.getKey();
+ String errorMessage = e.getValue();
+ if (log.isInfoEnabled()) {
+ log.info("Transmit error on " + fieldName+" ["+errorMessage+"]");
+ }
+ addFieldError(fieldName, errorMessage);
+ }
+ }
+ getPollenSession().removeDynamicData(token);
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-13 14:06:19 UTC (rev 3178)
@@ -65,6 +65,18 @@
<result>/WEB-INF/jsp/poll/imageChoice.jsp</result>
</action>
+ <!-- display a votingList -->
+ <action name="displayVotingList"
+ class="org.chorem.pollen.ui.actions.poll.DisplayVotingList">
+ <result>/WEB-INF/jsp/poll/votingList.jsp</result>
+ </action>
+
+ <!-- display a personToList -->
+ <action name="displayPersonToList"
+ class="org.chorem.pollen.ui.actions.poll.DisplayPersonToList">
+ <result>/WEB-INF/jsp/poll/personToList.jsp</result>
+ </action>
+
<!-- edit poll -->
<action name="modification/*"
class="org.chorem.pollen.ui.actions.poll.EditPoll">
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-13 14:06:19 UTC (rev 3178)
@@ -1,19 +1,7 @@
-poll.common.aboutPoll=About the poll
-poll.common.comments=Comments about this poll
-poll.common.myPolls=My polls
-poll.common.select.choiceType=Select the type of choice
-poll.common.select.userFavoriteList=List
-poll.common.vote.results=Results
-poll.common.vote.results-help=Display results
-poll.common.vote.return=Back to poll
-poll.common.vote.return-help=Back to poll
-poll.error.poll.detected.duplicate.choice.name=Choices must be unique.
-poll.error.poll.required.one.choice=You must provide at least one choice.
-poll.error.poll.required.title=You must provide a title for the poll
-poll.info.poll.created=Poll created
-poll.info.poll.updated=Poll modified
pollen.action.addChoice=Add choice
pollen.action.addComment=Add a comment
+pollen.action.addPersonToList=Add a voter
+pollen.action.addVotingList=Add a group
pollen.action.backToFavoriteLists=Back to favorite lists
pollen.action.create=Create
pollen.action.createFavoriteList=Create a new list
@@ -41,10 +29,14 @@
pollen.action.pollDelete=Delete the poll
pollen.action.pollEdit=Edit poll
pollen.action.pollExport=Export poll
+pollen.action.pollPersonToListDelete=Delete this voter
pollen.action.pollResult=Display poll results
pollen.action.pollVote=Vote
+pollen.action.pollVotingListDelete=Supprimer le groupe de votants
+pollen.action.pollVotingListEdit=Editer ce groupe de votants
pollen.action.register=Register
pollen.action.validate=Submit
+pollen.common.aboutPoll=About the poll
pollen.common.addingChoices=Adding choices
pollen.common.administrator=Admin
pollen.common.beginChoiceDate=Begin choice date
@@ -57,6 +49,7 @@
pollen.common.choice=Choice
pollen.common.commentName=Name
pollen.common.commentText=Comment
+pollen.common.comments=Comments about this poll
pollen.common.csvImport=CSV import
pollen.common.description=Description
pollen.common.displayType-group=Results by groups
@@ -72,6 +65,7 @@
pollen.common.ldapImport=LDAP import
pollen.common.license=Licence
pollen.common.login=Login
+pollen.common.myPolls=My polls
pollen.common.name=Name
pollen.common.nbAccounts=Number of members
pollen.common.newPassword=New password
@@ -80,6 +74,7 @@
pollen.common.or=or
pollen.common.password=Password
pollen.common.password2=Renter your password
+pollen.common.personToList=Voter
pollen.common.pollCreator=Creator
pollen.common.pollOption.anonymous=Anonymous
pollen.common.pollOption.anonymousVoteAllowed=Anonymous vote allowed
@@ -95,10 +90,16 @@
pollen.common.pollType=Who can vote ?
pollen.common.postDate=Comment date
pollen.common.results=Results\:
+pollen.common.select.choiceType=Select the type of choice
+pollen.common.select.userFavoriteList=List
pollen.common.title=Title
pollen.common.userSupport=User support
pollen.common.victories=Winners\:
pollen.common.victory=Winner\:
+pollen.common.vote.results=Results
+pollen.common.vote.results-help=Display results
+pollen.common.vote.return=Back to poll
+pollen.common.vote.return-help=Back to poll
pollen.common.voteAction=Vote
pollen.common.voteCounting-label=Vote Counting\:
pollen.common.voteCountingType=Response type
@@ -107,7 +108,10 @@
pollen.common.voteCountingTypeHelp.number=Voting by number\: The answer is free, leave blank or enter a integer.
pollen.common.voteCountingTypeHelp.percentage=Percentage vote\: allocate choices to get a 100%% total.
pollen.common.voteNbVotes=%d existing votes
+pollen.common.votePerson=Voter
pollen.common.voterName=Votant
+pollen.common.votingList=Group
+pollen.common.weight=Weight
pollen.error.accountNotFound=
pollen.error.comment.name.empty=Comment name mandatory
pollen.error.comment.text.empty=Comment text mandatory
@@ -123,12 +127,25 @@
pollen.error.password.required=Your must provide a password
pollen.error.password2.required=You must repeat your password for confirmation
pollen.error.passwords.not.equals=Les deux mots de passe saisis non identiques
+pollen.error.poll.detected.duplicate.choice.name=Choices must be unique.
pollen.error.poll.notfound=No such poll exists. Please make sure that you are using the correct link and copy it completely into your browser's address field.
+pollen.error.poll.personToList.email.doublon=
+pollen.error.poll.personToList.email.not.valid=
+pollen.error.poll.personToList.email.required=
+pollen.error.poll.personToList.votingId.doublon=
+pollen.error.poll.personToList.weight.not.valid=
+pollen.error.poll.required.one.choice=You must provide at least one choice.
+pollen.error.poll.required.one.personToList=
+pollen.error.poll.required.title=You must provide a title for the poll
+pollen.error.poll.required.votingList.name=
+pollen.error.poll.votingList.name.doublon=
+pollen.error.poll.votingList.weight.not.valid=
pollen.error.pollAccount.email.required=Em@il mandatory
pollen.error.pollAccount.not.found=Poll account not found
pollen.error.pollAccount.votingId.required=Name mandatory
pollen.error.pollNotClosed=The poll is not closed. Results may change.
pollen.error.pollNotFound=The poll you want to count does not exist.
+pollen.error.pollTabErrorFound=Some errors were found on this tab, please fix them to finalize the poll creation.
pollen.error.user.alreadyVoted=Someone has already used the name %s to vote.
pollen.error.user.bad.login.or.password=Login or password invalid.
pollen.error.user.email.already.used=This email is already used
@@ -152,6 +169,8 @@
pollen.fieldset.userInformation.toCreate=User informations to create
pollen.fieldset.userInformation.toDelete=User informations to delete
pollen.fieldset.userInformation.toUpdate=User informations to update
+pollen.info.poll.created=Poll created
+pollen.info.poll.updated=Poll modified
pollen.information.confirmDeleteChoice=Confirm delete of choice %s
pollen.information.confirmDeleteVote=Confirm delete of vote for %s
pollen.information.favoriteList.created=Favorite list %s created.
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-13 14:06:19 UTC (rev 3178)
@@ -1,19 +1,7 @@
-poll.common.aboutPoll=A propos du sondage
-poll.common.comments=Commentaire à propos du sondage
-poll.common.myPolls=Mes sondages
-poll.common.select.choiceType=Sélectionner le type de choix
-poll.common.select.userFavoriteList=Liste
-poll.common.vote.results=Résultats
-poll.common.vote.results-help=Voir les résultats
-poll.common.vote.return=Retour au sondage
-poll.common.vote.return-help=Retour au sondage
-poll.error.poll.detected.duplicate.choice.name=Les choix doivent être uniques.
-poll.error.poll.required.one.choice=Vous devez saisir au moins un choix.
-poll.error.poll.required.title=Vous devez fournir un titre pour le sondage
-poll.info.poll.created=Sondage créé
-poll.info.poll.updated=Sondage mise à jour
pollen.action.addChoice=Ajouter un choix
pollen.action.addComment=Ajouter un commentaire
+pollen.action.addPersonToList=Ajouter un votant
+pollen.action.addVotingList=Ajouter un groupe
pollen.action.backToFavoriteLists=Retour à la liste des favoris
pollen.action.create=Créer
pollen.action.createFavoriteList=Créer une ouvelle liste
@@ -41,10 +29,14 @@
pollen.action.pollDelete=Supprimer le sondage
pollen.action.pollEdit=Editer le sondage
pollen.action.pollExport=Exporter le sondage
+pollen.action.pollPersonToListDelete=Supprimer ce votant
pollen.action.pollResult=Afficher les résultats du sondage
pollen.action.pollVote=Voter
+pollen.action.pollVotingListDelete=Supprimer le groupe de votants
+pollen.action.pollVotingListEdit=Editer ce groupe de votants
pollen.action.register=S'enregistrer
pollen.action.validate=Valider
+pollen.common.aboutPoll=A propos du sondage
pollen.common.addingChoices=Ajout des choix
pollen.common.administrator=Admin
pollen.common.beginChoiceDate=Date de début des choix
@@ -57,6 +49,7 @@
pollen.common.choice=Choix
pollen.common.commentName=Nom
pollen.common.commentText=Commentaire
+pollen.common.comments=Commentaire à propos du sondage
pollen.common.csvImport=Import CSV
pollen.common.description=Description
pollen.common.displayType-group=Résultats par groupes
@@ -72,6 +65,7 @@
pollen.common.ldapImport=Import LDAP
pollen.common.license=Licence
pollen.common.login=Identifiant
+pollen.common.myPolls=Mes sondages
pollen.common.name=Nom
pollen.common.nbAccounts=Nombre de membres
pollen.common.nbVotes=%d votes ont été enregistrés
@@ -81,6 +75,7 @@
pollen.common.or=ou
pollen.common.password=Mot de passe
pollen.common.password2=Répétez votre mot de passe
+pollen.common.personToList=Votant
pollen.common.pollCreator=Créateur
pollen.common.pollOption.anonymous=Sondage anonyme
pollen.common.pollOption.anonymousVoteAllowed=Autoriser le vote anonyme
@@ -96,10 +91,16 @@
pollen.common.pollType=Qui peut voter ?
pollen.common.postDate=Date du commentaire
pollen.common.results=Résultats \:
+pollen.common.select.choiceType=Sélectionner le type de choix
+pollen.common.select.userFavoriteList=Liste
pollen.common.title=Titre
pollen.common.userSupport=Support utilisateur
pollen.common.victories=Gagnants \:
pollen.common.victory=Gagnant \:
+pollen.common.vote.results=Résultats
+pollen.common.vote.results-help=Voir les résultats
+pollen.common.vote.return=Retour au sondage
+pollen.common.vote.return-help=Retour au sondage
pollen.common.voteAction=Vote
pollen.common.voteCountingType=Type de Réponse
pollen.common.voteCountingTypeHelp.condorcet=Vote Condorcet \: classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
@@ -107,7 +108,10 @@
pollen.common.voteCountingTypeHelp.number=Vote par nombre \: La réponse est libre, laissez vide ou entrez un nombre entier
pollen.common.voteCountingTypeHelp.percentage=Vote par pourcentage \: répartir les choix de manière à obtenir 100%% au total.
pollen.common.voteNbVotes=%d votes existants
+pollen.common.votePerson=Votant
pollen.common.voterName=Votant
+pollen.common.votingList=Groupe
+pollen.common.weight=Poids
pollen.common.x=Dépouillement
pollen.error.accountNotFound=
pollen.error.comment.name.empty=Nom du commentaire obligatoire
@@ -124,12 +128,25 @@
pollen.error.password.required=Mot de passe obligatoire
pollen.error.password2.required=Mot de passe répété obligatoire
pollen.error.passwords.not.equals=Les deux mots de passe saisis non identiques
+pollen.error.poll.detected.duplicate.choice.name=Les choix doivent être uniques.
pollen.error.poll.notfound=Il n'y a pas de sondage à cette adresse. Veuillez verifier que vous utilisez le lien correcte et copiez-le complètement dans le champ d'adresse de votre navigateur.
+pollen.error.poll.personToList.email.doublon=Les emails doivent être uniques.
+pollen.error.poll.personToList.email.not.valid=Email non valide
+pollen.error.poll.personToList.email.required=Email obligatoire
+pollen.error.poll.personToList.votingId.doublon=Les noms des votants doivent être uniques.
+pollen.error.poll.personToList.weight.not.valid=Poids du votant non valide (doit être une nombre supérieur à 0).
+pollen.error.poll.required.one.choice=Vous devez saisir au moins un choix.
+pollen.error.poll.required.one.personToList=Aucun votant renseigné
+pollen.error.poll.required.title=Vous devez fournir un titre pour le sondage
+pollen.error.poll.required.votingList.name=nom du groupe non renseigné
+pollen.error.poll.votingList.name.doublon=Les noms de groupes doivent être uniques.
+pollen.error.poll.votingList.weight.not.valid=Poids du groupe votant non valide (doit être une nombre supérieur à 0).
pollen.error.pollAccount.email.required=Em@il obliqatoire
pollen.error.pollAccount.not.found=Membre non trouvé
pollen.error.pollAccount.votingId.required=Nom obliqatoire
pollen.error.pollNotClosed=Ce sondage n'est pas clos. Les résultats peuvent encore changer.
pollen.error.pollNotFound=Le sondage que vous voulez dépouiller n'existe pas.
+pollen.error.pollTabErrorFound=Des erreurs ont été detectées dans cet onglet, veuillez les corriger pour valider la création du sondage.
pollen.error.user.alreadyVoted=Une personne a déjà voté sous le nom %s.
pollen.error.user.bad.login.or.password=Mauvais identifiant ou mot de passe.
pollen.error.user.email.already.used=Le courriel saisi est déjà utilisé par un autre utilisateur
@@ -153,6 +170,8 @@
pollen.fieldset.userInformation.toCreate=Informations de l'utilisateur à créer
pollen.fieldset.userInformation.toDelete=Informations de l'utilisateur à supprimer
pollen.fieldset.userInformation.toUpdate=Informations de l'utilisateur à mettre à jour
+pollen.info.poll.created=Sondage créé
+pollen.info.poll.updated=Sondage mise à jour
pollen.information.confirmDeletePollChoice=Confirmer la suppression du chois %s
pollen.information.confirmDeletePollVote=Confirmer la suppression du vote de %s
pollen.information.favoriteList.created=La liste %s a été créée.
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -28,7 +28,10 @@
href="<s:url value='/css/pollCreation.css'/>"/>
<%@include file="/WEB-INF/jsp/choiceHelper.jsp" %>
+<%@include file="/WEB-INF/jsp/votingListHelper.jsp" %>
+<s:url id='errorImg' value='/img/exclamation.png'/>
+
<script type="text/javascript">
jQuery(document).ready(function () {
@@ -77,10 +80,55 @@
$('[name="poll.choiceType"][value="' + type + '"]').attr('checked', 'checked');
}
+ function changePollType(type, loading) {
+
+ if (!loading) {
+
+ // remove extra votingLists
+ var containerId = "votingLists";
+ var lastVotingList = getLastVotingList(containerId);
+ while (lastVotingList > -1) {
+ deleteVotingList(containerId + "_" + lastVotingList);
+ lastVotingList -= 1;
+ }
+ }
+
+ if (type == 'FREE') {
+
+ // hide everything
+ $('.restrictedPoll').addClass("hidden");
+ $('.groupPoll').addClass("hidden");
+
+ } else if (type == 'RESTRICTED') {
+
+ if (!loading) {
+ addNewVotingList(containerId);
+ }
+
+ // show restricted sutff
+ $('.restrictedPoll').removeClass("hidden");
+ // remove all group stuff
+ $('.groupPoll').addClass("hidden");
+
+ } else if (type == 'GROUP') {
+
+ if (!loading) {
+ addNewVotingList(containerId);
+ }
+
+ $('.restrictedPoll').removeClass("hidden");
+ $('.groupPoll').removeClass("hidden");
+ }
+ }
+
$('[name="poll.choiceType"]').change(function (event) {
changeChoiceType($(this).val());
});
- $('[name="poll.pollType"][value="<s:property value="%{poll.pollType.name()}"/>"]').attr('checked', 'checked');
+
+ $('[name="poll.pollType"]').change(function (event) {
+ changePollType($(this).val(), false);
+ });
+
$('[name="poll.voteCountingType"][value="<s:property value="%{poll.voteCountingType.name()}"/>"]').attr('checked', 'checked');
changeChoiceType('<s:property value="%{poll.choiceType.name()}"/>');
@@ -102,6 +150,13 @@
<s:iterator begin="1" end="nbImageChoices" status="status">
addImageChoice(<s:property value='%{#status.index}'/>, <s:property value="nbImageChoices - 1"/>, '<s:property value="imageChoiceTokenId" />');
</s:iterator>
+
+ // votingLists loading
+ <s:iterator begin="1" end="nbVotingLists" status="status">
+ addVotingList(<s:property value='%{#status.index}'/>, <s:property value="nbVotingLists - 1"/>, '<s:property value="votingListTokenId" />');
+ </s:iterator>
+
+ changePollType('<s:property value="%{poll.pollType.name()}"/>', true);
});
</script>
<title><s:text name="pollen.title.createPoll"/></title>
@@ -111,7 +166,7 @@
<s:form method="POST" id="registerForm" namespace="/poll"
enctype="multipart/form-data">
- <sj:tabbedpanel id="formTabs">
+ <sj:tabbedpanel id="formTabs" selectedTab="%{selectedTab}">
<sj:tab id="tabGeneral" target="tgeneral" key="pollen.tab.poll.general"/>
<sj:tab id="tabOptions" target="toptions" key="pollen.tab.poll.options"/>
@@ -134,24 +189,28 @@
<legend><s:text name="pollen.common.voteCountingType"/></legend>
<s:radio key='poll.voteCountingType' list="voteCountingTypes"
label='' theme="simple"/>
-
</fieldset>
<br/>
<fieldset>
<legend><s:text name="pollen.fieldset.poll.choices"/></legend>
- <s:radio key='poll.choiceType' list="choiceTypes"
- label='' theme="simple"/>
+ <s:radio key='poll.choiceType' list="choiceTypes" label=''
+ theme="simple"/>
<hr/>
<s:fielderror fieldName="poll.choices"/>
- <div id="choicesTEXT" class="choices"></div>
- <div id="choicesDATE" class="choices"></div>
- <div id="choicesIMAGE" class="choices"></div>
+ <div id="choicesTEXT" class="choices">
+ <%--Where to load text choices --%>
+ </div>
+ <div id="choicesDATE" class="choices">
+ <%--Where to load date choices --%>
+ </div>
+ <div id="choicesIMAGE" class="choices">
+ <%--Where to load image choices --%>
+ </div>
<hr/>
<s:submit key="pollen.action.addChoice" align="center"
onclick="return addNewChoice();"/>
-
</fieldset>
</div>
@@ -204,30 +263,62 @@
<s:textfield key="reminderHourCountdown"
label="%{getText('pollen.common.pollOption.reminderHourCountdown')}"/>
</div>
-
</fieldset>
<br/>
-
<fieldset>
<legend><s:text name="pollen.fieldset.poll.general"/></legend>
- <sj:datepicker key="poll.beginDate"
- label="%{getText('pollen.common.beginDate')}"
- displayFormat="dd/mm/yy"/>
- <sj:datepicker key="poll.endDate"
- label="%{getText('pollen.common.endDate')}"
- displayFormat="dd/mm/yy"/>
+ <sj:datepicker key="poll.beginDate" displayFormat="dd/mm/yy"
+ label="%{getText('pollen.common.beginDate')}"/>
+ <sj:datepicker key="poll.endDate" displayFormat="dd/mm/yy"
+ label="%{getText('pollen.common.endDate')}"/>
+ </fieldset>
+
+ <br/>
+ <fieldset>
+ <legend><s:text name="pollen.common.pollType"/></legend>
<s:radio key='poll.pollType' list="pollTypes"
label='%{getText("pollen.common.pollType")}'/>
-
+ <hr/>
+ <div class="restrictedPoll">
+ <div id="votingLists">
+ <%--Where to load voting lists --%>
+ </div>
+ <div class="groupPoll">
+ <s:submit key="pollen.action.addVotingList" align="center"
+ onclick="return addNewVotingList();"/>
+ </div>
+ </div>
</fieldset>
-
</div>
</sj:tabbedpanel>
-
<br/>
<s:submit action="create" key="pollen.action.createPoll" align="center"/>
-</s:form>
\ No newline at end of file
+</s:form>
+
+<script type="text/javascript">
+
+ jQuery(document).ready(function () {
+
+ function addErrorImage(element) {
+ element.append(
+ '<image src="${errorImg}">'
+ );
+ element.attr('title',
+ '<s:text name="pollen.error.pollTabErrorFound"/>');
+ }
+
+ if (<s:property value="%{informationsError}"/>) {
+ var tab = $('#tabGeneral a');
+ addErrorImage(tab);
+ }
+ if (<s:property value="%{optionsError}"/>) {
+ tab = $('#tabOptions a');
+ addErrorImage(tab);
+ }
+
+ });
+</script>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -46,7 +46,7 @@
key="%{#prefix}.description" label='' theme="simple"
value="%{choice.description}"/>
</div>
- <span>
+ <div class="fright">
<s:a href='#' onclick="return deleteChoice('choicesDATE_%{choiceNumber}')">
<image alt='<s:property value="deleteTitle"/>'
title='<s:property value="deleteTitle"/>'
@@ -65,6 +65,6 @@
title='<s:property value="upTitle"/>'
src="<s:url value='/img/1uparrow.png'/>"></image>
</s:a--%>
- </span>
+ </div>
<div class="cleanBoth"></div>
</div>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/imageChoice.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/imageChoice.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/imageChoice.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -55,11 +55,10 @@
theme="simple"/>
</div>
<div class="fleft">
- <s:textarea cols="30" id="%{#prefix}.description"
- key="%{#prefix}.description"
- label='' theme="simple" value="%{choice.description}"/>
+ <s:textarea cols="30" id="%{#prefix}.description" label='' theme="simple"
+ key="%{#prefix}.description" value="%{choice.description}"/>
</div>
- <span>
+ <div class="fright">
<s:a href='#' onclick="return deleteChoice('choicesIMAGE_%{choiceNumber}')">
<image alt='<s:property value="deleteTitle"/>'
title='<s:property value="deleteTitle"/>'
@@ -78,7 +77,7 @@
title='<s:property value="upTitle"/>'
src="<s:url value='/img/1uparrow.png'/>"></image>
</s:a--%>
- </span>
+ </div>
<div class="cleanBoth"></div>
</div>
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -0,0 +1,61 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<s:set name="prefix">personToList_<s:property
+ value="votingListNumber"/>_<s:property value="personToListNumber"/>
+</s:set>
+<s:set id='deleteTitle'>
+ <s:text name="pollen.action.pollPersonToListDelete"/>
+</s:set>
+<s:div id='%{#prefix}'>
+ <s:fielderror/>
+ <s:hidden key='%{#prefix}.topiaId' value='%{personToList.topiaId}' label=''/>
+ <div class="fleft choiceName">
+ <s:label for="%{#prefix}.votingId" id="%{#prefix}_label" theme="simple"
+ value=''/>
+ <s:textfield cssClass="nameField" id='%{#prefix}.votingId'
+ key="%{#prefix}.votingId" label='' theme="simple"
+ value="%{personToList.pollAccount.votingId}"/>
+ -
+ <s:label for="%{#prefix}.email" key="pollen.common.email" theme="simple"/>
+ <s:textfield cols="30" id="%{#prefix}.email" key="%{#prefix}.email"
+ label='' theme="simple"
+ value="%{personToList.pollAccount.email}"/>
+ -
+ <s:label for="%{#prefix}.weight" key="pollen.common.weight" theme="simple"/>
+ <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight" size="1"
+ label='' theme="simple" value="%{personToList.weight}"/>
+ </div>
+ <div class="fright">
+ <s:a href='#' onclick="return deletePersonToList('%{#prefix}')">
+ <image alt='<s:property value="deleteTitle"/>'
+ title='<s:property value="deleteTitle"/>'
+ src="<s:url value='/img/delete.png'/>"></image>
+ </s:a>
+ </div>
+
+ <div class="cleanBoth"></div>
+</s:div>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -69,12 +69,12 @@
<div id="resultTop">
<s:property value="poll.description"/>
<fieldset>
- <legend><s:text name="poll.common.aboutPoll"/></legend>
+ <legend><s:text name="pollen.common.aboutPoll"/></legend>
<div style="float: right">
<s:a namespace="/poll" action="votefor/%{uriId}">
<img src="<s:url value='/img/vote.png'/>"
- title="<s:text name="poll.common.vote.return-help"/>"
- alt="<s:text name="poll.common.vote.return"/>"/>
+ title="<s:text name="pollen.common.vote.return-help"/>"
+ alt="<s:text name="pollen.common.vote.return"/>"/>
</s:a>
</div>
<s:label value="%{poll.creator.votingId}"
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/resume.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/resume.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/resume.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -53,6 +53,6 @@
<div style="margin-top: 30px;">
<s:text name="pollen.label.pollRegisterPage"/>
<s:a namespace="/user" action="myPolls">
- <s:text name="poll.common.myPolls"/>
+ <s:text name="pollen.common.myPolls"/>
</s:a>.
</div>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/textChoice.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/textChoice.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/textChoice.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -38,13 +38,12 @@
-
<s:label for="%{#prefix}.description" key="pollen.common.description"
theme="simple"/>
+ <%--/div>
+ <div class="fleft"--%>
+ <s:textarea cols="30" id="%{#prefix}.description" label='' theme="simple"
+ key="%{#prefix}.description" value="%{choice.description}"/>
</div>
- <div class="fleft">
- <s:textarea cols="30" id="%{#prefix}.description"
- key="%{#prefix}.description"
- label='' theme="simple" value="%{choice.description}"/>
- </div>
- <span>
+ <div class="fright">
<s:a href='#' onclick="return deleteChoice('choicesTEXT_%{choiceNumber}')">
<image alt='<s:property value="deleteTitle"/>'
title='<s:property value="deleteTitle"/>'
@@ -63,6 +62,6 @@
title='<s:property value="upTitle"/>'
src="<s:url value='/img/1uparrow.png'/>"></image>
</s:a--%>
- </span>
+ </div>
<div class="cleanBoth"></div>
</div>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-13 14:01:33 UTC (rev 3177)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -101,14 +101,14 @@
<s:property value="poll.description"/>
</div>
<fieldset>
- <legend><s:text name="poll.common.aboutPoll"/></legend>
+ <legend><s:text name="pollen.common.aboutPoll"/></legend>
<div style="float: right">
<s:if test="poll.publicResults">
<s:a namespace="/poll" action="results/%{uriId}">
<img src="<s:url value='/img/count.png'/>"
- title="<s:text name="poll.common.vote.results-help"/>"
- alt="<s:text name="poll.common.vote.results"/>"/>
+ title="<s:text name="pollen.common.vote.results-help"/>"
+ alt="<s:text name="pollen.common.vote.results"/>"/>
</s:a>
</s:if>
<%--<t:FeedContextLink t:id="feedContext"/>--%>
@@ -382,7 +382,7 @@
<tr>
<td>
<s:a namespace="/poll" action="results/%{poll.pollId}">
- <s:text name="poll.common.vote.results"/>
+ <s:text name="pollen.common.vote.results"/>
</s:a>
</td>
@@ -416,7 +416,7 @@
</div>
<!-- Ajout de commentaires -->
-<h3><s:text name="poll.common.comments"/></h3>
+<h3><s:text name="pollen.common.comments"/></h3>
<div id="commentZone">
<div id="commentsDiv">
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -0,0 +1,87 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<s:set name="prefix">votingList_<s:property value="votingListNumber"/></s:set>
+<s:set id='deleteTitle'>
+ <s:text name="pollen.action.pollVotingListDelete"/>
+</s:set>
+<s:set id='editTitle'>
+ <s:text name="pollen.action.pollVotingListEdit"/>
+</s:set>
+
+<script type="text/javascript">
+ jQuery(document).ready(function () {
+ // personToList loading
+ <s:iterator begin="1" end="nbPersonToLists" status="status">
+ addPersonToList(<s:property value="votingListNumber"/>, <s:property value='%{#status.index}'/>, <s:property value="nbPersonToLists - 1"/>, '<s:property value="personToListTokenId" />');
+ </s:iterator>
+ });
+</script>
+<s:div id='votingLists_%{votingListNumber}'>
+ <fieldset class="ui-widget-content ui-corner-all">
+
+ <s:fielderror/>
+ <div class="groupPoll">
+ <div class="fleft choiceName">
+ <s:label for="%{#prefix}.name" theme="simple"
+ id="votingLists_%{votingListNumber}_label"/>
+ <s:textfield id='%{#prefix}.name' key="%{#prefix}.name" label=''
+ theme="simple" value="%{votingList.name}"/>
+ -
+ <s:label for="%{#prefix}.weight" key="pollen.common.weight"
+ theme="simple"/>
+ <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight" value="%{votingList.weight}"
+ size="1" label='' theme="simple"/>
+ </div>
+ <div id='<s:property value="%{#prefix}"/>_actions' class="fright">
+ <s:a href='#' onclick="return editVotingList('%{prefix}')">
+ <image alt='<s:property value="editTitle"/>'
+ title='<s:property value="editTitle"/>'
+ src="<s:url value='/img/edit.png'/>"></image>
+ </s:a>
+ <s:a href='#'
+ onclick="return deleteVotingList('votingLists_%{votingListNumber}')">
+ <image alt='<s:property value="deleteTitle"/>'
+ title='<s:property value="deleteTitle"/>'
+ src="<s:url value='/img/delete.png'/>"></image>
+ </s:a>
+ </div>
+ <hr/>
+ </div>
+ <div class="cleanBoth"></div>
+ <s:hidden key='%{#prefix}.topiaId' value='%{votingList.topiaId}' label=''/>
+
+ <s:div id='personToList_%{votingListNumber}'>
+ <%--Where to load personToList--%>
+ </s:div>
+ <hr/>
+ <div class="cleanBoth"></div>
+ <s:submit id='%{#prefix}_addPersonToList' name='%{#prefix}_addPersonToList'
+ key="pollen.action.addPersonToList" align="center"
+ onclick='return addNewPersonToList("%{votingListNumber}");'/>
+ </fieldset>
+ <br/>
+</s:div>
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-03-13 14:06:19 UTC (rev 3178)
@@ -0,0 +1,192 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+
+<script type="text/javascript">
+
+ var votingListText = '<s:text name="pollen.common.votingList"/>';
+ var personToListText = '<s:text name="pollen.common.personToList"/>';
+
+ function getFirstVotingList(containerId) {
+ var result = 65535;
+ getAllVotingLists(containerId).each(function () {
+ var current = $(this).data('votingListNumber');
+ if (current < result) {
+ result = current;
+ }
+ });
+ return result;
+ }
+
+ function getLastVotingList(containerId) {
+ var result = 0;
+ getAllVotingLists(containerId).each(function () {
+ var current = $(this).data('votingListNumber');
+ if (current > result) {
+ result = current;
+ }
+ });
+ return result;
+ }
+
+ function getAllVotingLists(containerId) {
+ return $("div[id^='" + containerId + "_']");
+ }
+
+ function updateUpdownVotingListActions(containerId) {
+ getAllVotingLists(containerId).each(function (index) {
+ var currentVotingListNumber = $(this).data('votingListNumber');
+ var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label");
+ labelWidget.html(votingListText + ' ' + (index + 1));
+ });
+ }
+
+ function loadVotingList(containerId, votingListNumber, nbVotingLists, tokenId) {
+ if (votingListNumber == -1) {
+ // to add a new votingList, get the new available votingListNumber
+ votingListNumber = 1 + getLastVotingList(containerId);
+ }
+ $.ajax(
+ {
+ url:'<s:url namespace="/poll" action="displayVotingList"/>',
+ data:{ tokenId:tokenId, votingListNumber:votingListNumber },
+ async:false,
+ dataType:"html",
+ success:function (data, textStatus) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store votingListNumber
+ var votingList = $("#" + containerId + "_" + votingListNumber);
+ votingList.data('votingListNumber', votingListNumber);
+ votingList.data('votingListContainerId', containerId);
+ if (votingListNumber == nbVotingLists || !tokenId) {
+ updateUpdownVotingListActions(containerId);
+ }
+ }
+ });
+ }
+
+ function addVotingList(votingListNumber, nbVotingLists, tokenId) {
+ loadVotingList('votingLists', votingListNumber, nbVotingLists, tokenId);
+ }
+
+ function addNewVotingList() {
+ addVotingList(-1, -1);
+ return false;
+ }
+
+ function deleteVotingList(votingListId) {
+ var votingList = $('#' + votingListId);
+ var containerId = votingList.data('votingListContainerId');
+ votingList.remove();
+ updateUpdownVotingListActions(containerId);
+ return false;
+ }
+
+ function getFirstPersonToList(containerId) {
+ var result = 65535;
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ if (current < result) {
+ result = current;
+ }
+ });
+ return result;
+ }
+
+ function getLastPersonToList(containerId) {
+ var result = 0;
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ if (current > result) {
+ result = current;
+ }
+ });
+ return result;
+ }
+
+ function getAllPersonToLists(containerId) {
+ return $("div[id^='" + containerId + "_']");
+ }
+
+ function updateUpdownPersonToListActions(containerId) {
+ getAllPersonToLists(containerId).each(function (index) {
+ var currentPersonToListNumber = $(this).data('personToListNumber');
+ var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label");
+ labelWidget.html(personToListText + ' ' + (index + 1));
+ });
+ }
+
+ function loadPerson(containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
+ if (personToListNumber == -1) {
+ // to add a new personToList, get the new available personToListNumber
+ personToListNumber = 1 + getLastPersonToList(containerId);
+ }
+ $.ajax(
+ {
+ url:'<s:url namespace="/poll" action="displayPersonToList"/>',
+ data:{
+ tokenId:tokenId,
+ votingListNumber:votingListNumber,
+ personToListNumber:personToListNumber
+ },
+ async:false,
+ dataType:"html",
+ success:function (data, textStatus) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store personToListNumber
+ var personToList = $("#" + containerId + "_" + personToListNumber);
+ personToList.data('votingListNumber', votingListNumber);
+ personToList.data('personToListNumber', personToListNumber);
+ personToList.data('personToListContainerId', containerId);
+ if (personToListNumber == nbPersonToLists || !tokenId) {
+ updateUpdownPersonToListActions(containerId);
+ }
+ }
+ });
+ }
+
+ function addPersonToList(votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
+ loadPerson(
+ 'personToList_' + votingListNumber,
+ votingListNumber, personToListNumber, nbPersonToLists, tokenId
+ );
+ }
+
+ function addNewPersonToList(votingListNumber) {
+ addPersonToList(votingListNumber, -1, -1);
+ return false;
+ }
+
+ function deletePersonToList(personToListId) {
+ var personToList = $('#' + personToListId);
+ var containerId = personToList.data('personToListContainerId');
+ personToList.remove();
+ updateUpdownPersonToListActions(containerId);
+ return false;
+ }
+</script>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r3177 - branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence
by tchemit@users.chorem.org 13 Mar '12
by tchemit@users.chorem.org 13 Mar '12
13 Mar '12
Author: tchemit
Date: 2012-03-13 15:01:33 +0100 (Tue, 13 Mar 2012)
New Revision: 3177
Url: http://chorem.org/repositories/revision/pollen/3177
Log:
add svn properties and header
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-03-13 14:01:09 UTC (rev 3176)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-03-13 14:01:33 UTC (rev 3177)
@@ -1,3 +1,26 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
package org.chorem.pollen.business.persistence;
import com.google.common.base.Preconditions;
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2012-03-13 15:01:09 +0100 (Tue, 13 Mar 2012)
New Revision: 3176
Url: http://chorem.org/repositories/revision/pollen/3176
Log:
use last stable version of nuiton-web
Modified:
branches/pollen-1.2.6-struts2/pom.xml
Modified: branches/pollen-1.2.6-struts2/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pom.xml 2012-03-13 13:59:45 UTC (rev 3175)
+++ branches/pollen-1.2.6-struts2/pom.xml 2012-03-13 14:01:09 UTC (rev 3176)
@@ -439,7 +439,7 @@
<eugenePluginVersion>2.4.2</eugenePluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<tapestryVersion>5.1.0.5</tapestryVersion>
- <nuitonWebVersion>1.9.2</nuitonWebVersion>
+ <nuitonWebVersion>1.10</nuitonWebVersion>
<nuitonUtilsVersion>2.4.4</nuitonUtilsVersion>
<h2Version>1.3.164</h2Version>
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
1
0
r3175 - in branches/pollen-1.2.6-struts2/pollen-domain: . src/main/java/org/chorem/poll/domain src/main/java/org/chorem/poll/domain/poll src/main/java/org/chorem/poll/domain/strategy src/main/resources/i18n src/test/java/org/chorem/poll/domain src/test/java/org/chorem/poll/domain/strategy
by tchemit@users.chorem.org 13 Mar '12
by tchemit@users.chorem.org 13 Mar '12
13 Mar '12
Author: tchemit
Date: 2012-03-13 14:59:45 +0100 (Tue, 13 Mar 2012)
New Revision: 3175
Url: http://chorem.org/repositories/revision/pollen/3175
Log:
add svn properties
Modified:
branches/pollen-1.2.6-struts2/pollen-domain/LICENSE.txt
branches/pollen-1.2.6-struts2/pollen-domain/README.txt
branches/pollen-1.2.6-struts2/pollen-domain/changelog.txt
branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: ChoiceType.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: I18nAble.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: PollType.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: VoteCountingType.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2012-03-12 09:37:14 +0100 (Mon, 12 Mar 2012)
New Revision: 3174
Url: http://chorem.org/repositories/revision/pollen/3174
Log:
domain NG module (will be used with version 1.3
Added:
branches/pollen-1.2.6-struts2/pollen-domain/
branches/pollen-1.2.6-struts2/pollen-domain/LICENSE.txt
branches/pollen-1.2.6-struts2/pollen-domain/README.txt
branches/pollen-1.2.6-struts2/pollen-domain/changelog.txt
branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
branches/pollen-1.2.6-struts2/pollen-domain/src/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/site/
branches/pollen-1.2.6-struts2/pollen-domain/src/site/rst/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain
___________________________________________________________________
Added: svn:ignore
+ target
*.iml
*.ipr
*.iws
*.log
.project
.classpath
.settings.xml
Added: branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/pom.xml (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/pom.xml 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.chorem</groupId>
+ <artifactId>pollen</artifactId>
+ <version>1.2.6-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.chorem.pollen</groupId>
+ <artifactId>pollen-domain</artifactId>
+
+ <name>Pollen :: Domain</name>
+ <description>Pollen Domain</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>parserJava</goal>
+ <goal>gen</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,605 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $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.poll.domain;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.poll.domain.poll.ChoiceType;
+import org.chorem.poll.domain.poll.Poll;
+import org.chorem.poll.domain.poll.PollChoice;
+import org.chorem.poll.domain.poll.PollComment;
+import org.chorem.poll.domain.poll.PollType;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.poll.PollVoteCountingResult;
+import org.chorem.poll.domain.poll.PollVotingChoice;
+import org.chorem.poll.domain.poll.PollVotingGroup;
+import org.chorem.poll.domain.poll.PollVotingPerson;
+import org.chorem.poll.domain.poll.VoteCountingType;
+import org.chorem.poll.domain.strategy.NumberVoteCountingStrategy;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Service to import / export a poll to or from his xml representation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ImportExportService {
+
+ public static final String POLL = "poll";
+
+ public static final String TITLE1 = "title";
+
+ public static final String TITLE = TITLE1;
+
+ public static final String CHOICE = "choice";
+
+ public static final String ID_CHOICE = "idChoice";
+
+ public static final String VALUE = "value";
+
+ public static final String PERCENTAGE = "percentage";
+
+ public static final String NB_VOTES = "nbVotes";
+
+ public static final String IS_BY_GROUP = "isByGroup";
+
+ public static final String CHOICES = "choices";
+
+ public static final String CHOICE_RESULT = "choiceResult";
+
+ public static final String ID_POLL = "idPoll";
+
+ public static final String VOTE_COUNTING_RESULT = "voteCountingResult";
+
+ public static final String DESCRIPTION = "description";
+
+ public static final String NAME = "name";
+
+ public static final String POLL_CHOICE = "pollChoice";
+
+ public static final String VOTING_PERSON = "votingPerson";
+
+ public static final String VOTING_ID = "votingId";
+
+ public static final String WEIGHT = "weight";
+
+ public static final String EMAIL = "email";
+
+ public static final String COMMENT = "comment";
+
+ public static final String VOTING_PERSONS = "votingPersons";
+
+ public static final String ID_GROUP = "idGroup";
+
+ public static final String GROUP = "group";
+
+ public static final String POLL_CHOICES = "pollChoices";
+
+ public static final String VOTE_COUNTING_RESULTS = "voteCountingResults";
+
+ public static final String GROUPS = "groups";
+
+ public static final String COMMENTS = "comments";
+
+ public static final String CREATOR_ID = "creatorId";
+
+ public static final String CREATOR_EMAIL = "creatorEmail";
+
+ public static final String MAX_CHOICE_NB = "maxChoiceNb";
+
+ public static final String POLL_EXPORT = "pollExport";
+
+ public static final String POLL_ID = "pollId";
+
+ public static final String POLL_TYPE = "pollType";
+
+ public static final String CHOICE_TYPE = "choiceType";
+
+ public static final String VOTE_COUNTING = "voteCounting";
+
+ public static final String CLOSED = "closed";
+
+ public static final String CHOICE_ADD_ALLOWED = "choiceAddAllowed";
+
+ public static final String ANONYMOUS_VOTE_ALLOWED = "anonymousVoteAllowed";
+
+ public static final String ANONYMOUS = "anonymous";
+
+ public static final String PUBLIC_RESULTS = "publicResults";
+
+ public static final String CONTINUOUS_RESULTS = "continuousResults";
+
+ public static final String VALUE_TRUE = "true";
+
+ public static final String VALUE_FALSE = "false";
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ImportExportService.class);
+
+ /**
+ * Export the given poll to an xml representation.
+ *
+ * @param exportPoll the poll to export
+ * @return the xml representation of the given poll
+ */
+ public String exportToXml(Poll exportPoll) {
+
+ Document document = toDOM(exportPoll);
+
+ // Mise en forme classique avec getPrettyFormat()
+ XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
+ String content = sortie.outputString(document);
+
+ if (log.isDebugEnabled()) {
+ log.debug(content);
+ }
+ return content;
+ }
+
+ /**
+ * Import into a {@link Poll} his xml representation from the
+ * given file.
+ *
+ * @param file file to load
+ * @return the loaded dto from the xml representation.
+ * @throws JDOMException if could not load xml from file
+ * @throws IOException if could not load the file
+ */
+ public Poll importFromXml(File file) throws JDOMException, IOException {
+
+ // Création d'un nouveau document JDOM avec le fichier XML en argument
+ Document document = new SAXBuilder().build(file);
+
+ // Initialisation d'un nouvel élément racine
+ Element racine = document.getRootElement();
+
+ Poll result = toDTO(racine);
+
+ return result;
+ }
+
+ protected Poll toDTO(Element racine) {
+
+ // Création du sondage
+ Element pollElm = racine.getChild(POLL);
+
+ Poll poll = new Poll();
+ poll.setPollId(pollElm.getAttributeValue(POLL_ID));
+ poll.setTitle(pollElm.getChild(TITLE).getText());
+ poll.setDescription(pollElm.getChild(DESCRIPTION).getText());
+ poll.setCreatorId(pollElm.getChild(CREATOR_ID).getText());
+ poll.setCreatorEmail(pollElm.getChild(CREATOR_EMAIL).getText());
+ poll.setMaxChoiceNb(Integer.parseInt(
+ pollElm.getChild(MAX_CHOICE_NB).getText()));
+
+ poll.setPollType(
+ PollType.valueOf(pollElm.getAttributeValue(POLL_TYPE)));
+ poll.setChoiceType(ChoiceType.valueOf(
+ pollElm.getAttributeValue(CHOICE_TYPE)));
+ poll.setVoteCounting(VoteCountingType.valueOf(
+ pollElm.getAttributeValue(VOTE_COUNTING)));
+ poll.setClosed(Boolean.valueOf(pollElm.getAttributeValue(CLOSED)));
+ poll.setChoiceAddAllowed(Boolean.valueOf(
+ pollElm.getAttributeValue(CHOICE_ADD_ALLOWED)));
+ poll.setAnonymousVoteAllowed(Boolean.valueOf(
+ pollElm.getAttributeValue(ANONYMOUS_VOTE_ALLOWED)));
+ poll.setAnonymous(Boolean.valueOf(
+ pollElm.getAttributeValue(ANONYMOUS)));
+ poll.setPublicResults(Boolean.valueOf(pollElm.getAttributeValue(PUBLIC_RESULTS)));
+ poll.setContinuousResults(Boolean.valueOf(
+ pollElm.getAttributeValue(CONTINUOUS_RESULTS)));
+
+ // Ajout des commentaires
+ Element commentsElm = pollElm.getChild(COMMENTS);
+ List<Element> listComments = commentsElm.getChildren(COMMENT);
+ List vectorComments = toComments(listComments);
+
+ poll.setComments(vectorComments);
+
+ // Ajout des groupes
+ Element groupsElm = pollElm.getChild(GROUPS);
+ List<Element> listGroups = groupsElm.getChildren(GROUP);
+ List vectorGroups = toVotingGroups(listGroups);
+
+ poll.setVotingGroups(vectorGroups);
+
+ // Ajout des choix
+ Element pollChoicesElm = pollElm.getChild(POLL_CHOICES);
+ List<Element> listPollChoices = pollChoicesElm.getChildren(POLL_CHOICE);
+ List<PollChoice> vectorPollChoices = toPollChoices(listPollChoices);
+
+ poll.setChoices(vectorPollChoices);
+
+ // Ajout des résultats
+ Element voteCountingResultsElm = racine.getChild(VOTE_COUNTING_RESULTS);
+ List<Element> listVoteCountingResults =
+ voteCountingResultsElm.getChildren(VOTE_COUNTING_RESULT);
+ List<PollVoteCountingResult> vectorVoteCountingResults =
+ toVoteCountingResults(listVoteCountingResults);
+
+ // Création du sondage PollExportDTO
+ poll.setVoteCountingResult(vectorVoteCountingResults);
+
+ return poll;
+ }
+
+ protected List<PollComment> toComments(List<Element> listComments) {
+ List<PollComment> vectorComments = Lists.newArrayList();
+
+ for (Element commentElm : listComments) {
+ PollComment comment = new PollComment();
+ comment.setVotingID(commentElm.getAttributeValue(VOTING_ID));
+ comment.setText(commentElm.getText());
+ vectorComments.add(comment);
+ }
+
+ return vectorComments;
+ }
+
+ protected List<PollVotingGroup> toVotingGroups(List<Element> listGroups) {
+ List<PollVotingGroup> vectorGroups = Lists.newArrayList();
+
+ for (Element groupElm : listGroups) {
+ PollVotingGroup group = new PollVotingGroup();
+
+ group.setIdGroup(groupElm.getAttributeValue(ID_GROUP));
+ group.setWeight(Double.parseDouble((groupElm.getAttributeValue(WEIGHT))));
+
+ group.setName(groupElm.getAttributeValue(NAME));
+
+ Element votingPersonsElm = groupElm.getChild(VOTING_PERSONS);
+ List<Element> listVotingPersons = votingPersonsElm
+ .getChildren(VOTING_PERSON);
+ List vectorVotingPersons = toVotingPersons(listVotingPersons);
+
+ group.setVotingPersons(vectorVotingPersons);
+
+ vectorGroups.add(group);
+ }
+
+ return vectorGroups;
+ }
+
+ protected List<PollVotingPerson> toVotingPersons(List<Element> listVotingPersons) {
+ List<PollVotingPerson> vectorVotingPersons = Lists.newArrayList();
+
+ for (Element votingPersonElm : listVotingPersons) {
+ PollVotingPerson votingPerson = new PollVotingPerson();
+ votingPerson.setVotingId(votingPersonElm.getAttributeValue(VOTING_ID));
+ votingPerson.setWeight(Double.parseDouble(votingPersonElm.getAttributeValue(WEIGHT)));
+
+ votingPerson.setEmail(votingPersonElm.getChild(EMAIL).getValue());
+ votingPerson.setComment(votingPersonElm.getChild(COMMENT)
+ .getValue());
+
+ Element choicesElm = votingPersonElm.getChild(CHOICES);
+
+ List<Element> listVoteToChoices = choicesElm.getChildren(CHOICE);
+ List vectorVoteToChoices = toVoteToChoices(listVoteToChoices);
+
+ votingPerson.setChoices(vectorVoteToChoices);
+ vectorVotingPersons.add(votingPerson);
+ }
+
+ return vectorVotingPersons;
+ }
+
+ protected List<PollVotingChoice> toVoteToChoices(List<Element> listVoteToChoices) {
+ List<PollVotingChoice> vectorVoteToChoices = Lists.newArrayList();
+
+ for (Element voteToChoiceElm : listVoteToChoices) {
+ PollVotingChoice voteToChoice = new PollVotingChoice(
+ voteToChoiceElm.getAttributeValue(ID_CHOICE),
+ Double.parseDouble(voteToChoiceElm.getAttributeValue(VALUE)));
+ vectorVoteToChoices.add(voteToChoice);
+ }
+ return vectorVoteToChoices;
+ }
+
+ protected List<PollChoice> toPollChoices(List<Element> listPollChoices) {
+ List<PollChoice> vectorPollChoices = Lists.newArrayList();
+
+ for (Element pollChoiceElm : listPollChoices) {
+ PollChoice pollChoice = new PollChoice();
+ pollChoice.setIdChoice(pollChoiceElm.getAttributeValue(ID_CHOICE));
+
+ String pollChoiceName = pollChoiceElm.getChild(NAME).getValue();
+ pollChoice.setName(pollChoiceName);
+ pollChoice.setHidden(pollChoiceName != null
+ && pollChoiceName.startsWith(NumberVoteCountingStrategy.HIDDEN_PREFIX));
+
+ pollChoice.setDescription(pollChoiceElm.getChild(DESCRIPTION)
+ .getValue());
+
+ vectorPollChoices.add(pollChoice);
+ }
+
+ return vectorPollChoices;
+ }
+
+ protected List<PollVoteCountingResult> toVoteCountingResults(List<Element> listVoteCountingResults) {
+ List<PollVoteCountingResult> vectorVoteCountingResults = Lists.newArrayList();
+
+ for (Element voteCountingResultElm : listVoteCountingResults) {
+ PollVoteCountingResult voteCountingResult = new PollVoteCountingResult();
+ voteCountingResult.setIdPoll(
+ voteCountingResultElm.getAttributeValue(ID_POLL));
+ voteCountingResult.setNbVotes(
+ Integer.parseInt(voteCountingResultElm.getChild(NB_VOTES)
+ .getValue()));
+ voteCountingResult.setChoiceResult(voteCountingResultElm.getChild(
+ CHOICE_RESULT).getValue());
+ voteCountingResult.setByGroup(
+ Boolean.parseBoolean(
+ voteCountingResultElm.getChild(IS_BY_GROUP).getValue()));
+
+ Element choicesElm = voteCountingResultElm.getChild(CHOICES);
+ List<Element> listChoices = choicesElm.getChildren(CHOICE);
+ List vectorChoices = toChoices(listChoices);
+ voteCountingResult.setChoices(vectorChoices);
+ vectorVoteCountingResults.add(voteCountingResult);
+ }
+
+ return vectorVoteCountingResults;
+ }
+
+ protected List<PollVoteCountingChoice> toChoices(List<Element> listChoices) {
+ List<PollVoteCountingChoice> vectorChoices = Lists.newArrayList();
+
+ for (Element choiceElm : listChoices) {
+ PollVoteCountingChoice choice = new PollVoteCountingChoice(
+ choiceElm.getAttribute(ID_CHOICE).getName(),
+ Double.parseDouble(choiceElm.getAttribute(VALUE).getValue()),
+ Double.parseDouble(choiceElm.getChild(PERCENTAGE).getValue()),
+ Integer.parseInt((choiceElm.getChild(NB_VOTES).getValue())));
+ vectorChoices.add(choice);
+ }
+
+ return vectorChoices;
+ }
+
+ protected Document toDOM(Poll poll) {
+
+ List<PollVoteCountingResult> voteCountingResults =
+ poll.getVoteCountingResult();
+
+ // Création de la racine et du document
+ Element racine = new Element(POLL_EXPORT);
+ Document document = new Document(racine);
+
+ // Création du sondage
+ Element pollElm = new Element(POLL);
+ pollElm.setAttribute(POLL_ID, poll.getPollId());
+ pollElm.setAttribute(POLL_TYPE, poll.getPollType().name());
+ pollElm.setAttribute(CHOICE_TYPE, poll.getChoiceType().name());
+ pollElm.setAttribute(VOTE_COUNTING, poll.getVoteCounting().name());
+ pollElm.setAttribute(CLOSED, poll.isClosed() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(CHOICE_ADD_ALLOWED,
+ poll.isChoiceAddAllowed() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(ANONYMOUS_VOTE_ALLOWED,
+ poll.isAnonymousVoteAllowed() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(ANONYMOUS,
+ poll.isAnonymous() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(PUBLIC_RESULTS,
+ poll.isPublicResults() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(CONTINUOUS_RESULTS,
+ poll.isContinuousResults() ? VALUE_TRUE : VALUE_FALSE);
+
+ Element titleElm = new Element(TITLE1);
+ titleElm.setText(poll.getTitle());
+ pollElm.addContent(titleElm);
+
+ Element descriptionElm = new Element(DESCRIPTION);
+ descriptionElm.setText(poll.getDescription());
+ pollElm.addContent(descriptionElm);
+
+ Element creatorIdElm = new Element(CREATOR_ID);
+ creatorIdElm.setText(poll.getCreatorId());
+ pollElm.addContent(creatorIdElm);
+
+ Element creatorEmailElm = new Element(CREATOR_EMAIL);
+ creatorEmailElm.setText(poll.getCreatorEmail());
+ pollElm.addContent(creatorEmailElm);
+
+ Element maxChoiceNbElm = new Element(MAX_CHOICE_NB);
+ maxChoiceNbElm.setText(Integer.toString(poll.getMaxChoiceNb()));
+ pollElm.addContent(maxChoiceNbElm);
+
+ // Création des commentaires
+ Element commentsElm = new Element(COMMENTS);
+
+ for (PollComment commentDTO : poll.getComments()) {
+ Element commentElm = toDOM(commentDTO);
+ commentsElm.addContent(commentElm);
+ }
+
+ pollElm.addContent(commentsElm);
+
+ // Création des groupes de votants
+ Element groupsElm = new Element(GROUPS);
+
+ for (PollVotingGroup votingGroupDTO : poll.getVotingGroups()) {
+ Element groupElm = toDOM(votingGroupDTO);
+ groupsElm.addContent(groupElm);
+ }
+
+ pollElm.addContent(groupsElm);
+
+ // Création des choix
+ Element pollChoicesElm = new Element(POLL_CHOICES);
+
+ for (PollChoice pollChoiceDTO : poll.getChoices()) {
+ Element pollChoiceElm = toDOM(pollChoiceDTO);
+ pollChoicesElm.addContent(pollChoiceElm);
+ }
+ pollElm.addContent(pollChoicesElm);
+
+ // Création des résultats
+ Element voteCountingResultsElm = new Element(VOTE_COUNTING_RESULTS);
+
+ for (PollVoteCountingResult voteCountingResult1 : voteCountingResults) {
+ Element voteCountingResult = toDOM(voteCountingResult1);
+ voteCountingResultsElm.addContent(voteCountingResult);
+ }
+
+ // Ajout du sondage et des résultats à la racine
+ racine.addContent(pollElm);
+
+ racine.addContent(voteCountingResultsElm);
+
+ return document;
+ }
+
+ protected Element toDOM(PollComment comment) {
+ Element commentElm = new Element(COMMENT);
+
+ commentElm.setAttribute(VOTING_ID, comment.getVotingID());
+ commentElm.setText(comment.getText());
+
+ return commentElm;
+ }
+
+ protected Element toDOM(PollVotingGroup group) {
+ Element groupElm = new Element(GROUP);
+
+ groupElm.setAttribute(ID_GROUP, group.getIdGroup());
+ groupElm.setAttribute(NAME, group.getName());
+ groupElm.setAttribute(WEIGHT, Double.toString(group.getWeight()));
+
+ Element votingPersonsElm = new Element(VOTING_PERSONS);
+
+ for (PollVotingPerson votingPersonDTO : group.getVotingPersons()) {
+ Element votingPersonElm = toDOM(votingPersonDTO);
+ votingPersonsElm.addContent(votingPersonElm);
+ }
+ groupElm.addContent(votingPersonsElm);
+
+ return groupElm;
+ }
+
+ protected Element toDOM(PollVotingPerson votingPerson) {
+ Element votingPersonElm = new Element(VOTING_PERSON);
+
+ votingPersonElm.setAttribute(VOTING_ID, votingPerson.getVotingId());
+ votingPersonElm.setAttribute(WEIGHT, Double.toString(votingPerson
+ .getWeight()));
+
+ Element emailElm = new Element(EMAIL);
+ emailElm.setText(votingPerson.getEmail());
+ votingPersonElm.addContent(emailElm);
+
+ Element commentElm = new Element(COMMENT);
+ commentElm.setText(votingPerson.getComment());
+ votingPersonElm.addContent(commentElm);
+
+ Element choicesElm = new Element(CHOICES);
+
+ for (PollVotingChoice voteToChoice : votingPerson.getChoices()) {
+ Element choiceElm = new Element(CHOICE);
+ choiceElm.setAttribute(ID_CHOICE, voteToChoice.getIdChoice());
+ choiceElm.setAttribute(VALUE, Double.toString(voteToChoice
+ .getValue()));
+ choicesElm.addContent(choiceElm);
+ }
+
+ votingPersonElm.addContent(choicesElm);
+
+ return votingPersonElm;
+ }
+
+ protected Element toDOM(PollChoice pollChoice) {
+ Element pollChoiceElm = new Element(POLL_CHOICE);
+
+ pollChoiceElm.setAttribute(ID_CHOICE, pollChoice.getIdChoice());
+
+ Element nameElm = new Element(NAME);
+ nameElm.setText(pollChoice.getName());
+ pollChoiceElm.addContent(nameElm);
+
+ Element descriptionElm = new Element(DESCRIPTION);
+ descriptionElm.setText(pollChoice.getDescription());
+ pollChoiceElm.addContent(descriptionElm);
+
+ return pollChoiceElm;
+ }
+
+ protected Element toDOM(PollVoteCountingResult voteCountingResults) {
+ Element voteCountingResultElm = new Element(VOTE_COUNTING_RESULT);
+
+ voteCountingResultElm.setAttribute(ID_POLL, voteCountingResults
+ .getIdPoll());
+
+ Element nbVotesElm = new Element(NB_VOTES);
+ nbVotesElm.setText(Integer.toString(voteCountingResults.getNbVotes()));
+ voteCountingResultElm.addContent(nbVotesElm);
+
+ Element choiceResultElm = new Element(CHOICE_RESULT);
+ choiceResultElm.setText(voteCountingResults.getChoiceResult());
+ voteCountingResultElm.addContent(choiceResultElm);
+
+ Element isByGroupElm = new Element(IS_BY_GROUP);
+ isByGroupElm.setText(Boolean.toString(voteCountingResults.isByGroup()));
+ voteCountingResultElm.addContent(isByGroupElm);
+
+ Element choicesElm = new Element(CHOICES);
+
+ for (PollVoteCountingChoice choiceDTO : voteCountingResults.getChoices()) {
+ Element choiceElm = toDOM(choiceDTO);
+ choicesElm.addContent(choiceElm);
+ }
+
+ voteCountingResultElm.addContent(choicesElm);
+
+ return voteCountingResultElm;
+ }
+
+ protected Element toDOM(PollVoteCountingChoice choice) {
+ Element choiceElm = new Element(CHOICE);
+
+ choiceElm.setAttribute(ID_CHOICE, choice.getIdChoice());
+ choiceElm.setAttribute(VALUE, Double.toString(choice.getValue()));
+
+ Element percentageElm = new Element(PERCENTAGE);
+ percentageElm.setText(Double.toString(choice.getPercentage()));
+ choiceElm.addContent(percentageElm);
+
+ Element nbVotesElm = new Element(NB_VOTES);
+ nbVotesElm.setText(Integer.toString(choice.getNbVotes()));
+ choiceElm.addContent(nbVotesElm);
+
+ return choiceElm;
+ }
+
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,11 @@
+package org.chorem.poll.domain;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollenDomainFunctions {
+
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,392 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $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.poll.domain;
+
+import com.google.common.collect.Iterables;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.poll.domain.poll.Poll;
+import org.chorem.poll.domain.poll.PollChoice;
+import org.chorem.poll.domain.poll.PollType;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.poll.PollVoteCountingResult;
+import org.chorem.poll.domain.poll.PollVotingChoice;
+import org.chorem.poll.domain.poll.PollVotingGroup;
+import org.chorem.poll.domain.poll.PollVotingPerson;
+import org.chorem.poll.domain.strategy.CondorcetVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.NumberVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.PercentageVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.StandardVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.VoteCountingStrategy;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Service qui permet le dépouillement d'un sondage.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class VoteCountingService {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(VoteCountingService.class);
+
+ public PollVoteCountingResult execute(Poll poll) {
+ boolean byGroup = poll.getPollType() == PollType.GROUP;
+ PollVoteCountingResult result = execute(poll, byGroup);
+ return result;
+ }
+
+ public PollVoteCountingResult executeVoteCounting(Poll poll) {
+ return execute(poll, false);
+ }
+
+ public PollVoteCountingResult executeGroupCounting(Poll poll) {
+ return execute(poll, true);
+ }
+
+ /**
+ * Execution du dépouillement
+ *
+ * @param poll : sondage
+ * @return resultat
+ */
+ private PollVoteCountingResult execute(Poll poll, boolean isByGroup) {
+ if (log.isInfoEnabled()) {
+ log.info("Dépouillement (byGroup=" + isByGroup + ") du sondage "
+ + poll.getPollId());
+ }
+
+ // Création et remplissage du contexte
+ VoteCountingContext context = VoteCountingContext.create(poll,
+ isByGroup);
+
+ // Execution
+ if (!context.executeCounting()) {
+ //FIXME tchemit ? Why returning null, prefer use an exception
+ return null;
+ }
+ List<PollVoteCountingChoice> resChoices = context.executeStats();
+
+ PollVoteCountingResult result = new PollVoteCountingResult();
+ result.setNbVotes(calculateNbVotes(poll, isByGroup));
+ result.setTypeVoteCounting(poll.getVoteCounting());
+ result.setByGroup(isByGroup);
+ result.setIdPoll(poll.getPollId());
+ result.setChoices(resChoices);
+ return result;
+ }
+
+ /**
+ * Contexte du dépouillement du sondage (PATTERN STRATEGY).
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+ public static class VoteCountingContext {
+
+ /**
+ * Booléen permettant de savoir si la méthode doit calculer la valeur des
+ * choix en fonction des groupes
+ */
+ private boolean groupCounting;
+
+ /** Liste des choix liés au contexte et résultats */
+ private List<Choice> choices, hiddenChoices, results;
+
+ /** Méthode de dépouillement choisie pour ce contexte */
+ private VoteCountingStrategy method;
+
+
+ /**
+ * Constructeur
+ *
+ * @param method : Méthode de dépouillement
+ * @param groupCounting : Dépouillement pour les groupes ou non
+ */
+ VoteCountingContext(VoteCountingStrategy method, boolean groupCounting) {
+ this.groupCounting = groupCounting;
+ this.choices = new ArrayList<Choice>();
+ this.hiddenChoices = new ArrayList<Choice>();
+ this.results = new ArrayList<Choice>();
+ this.method = method;
+ }
+
+ /**
+ * Création du contexte en fonction du type de dépouillement
+ *
+ * @param poll
+ * @param isByGroup
+ * @return
+ */
+ public static VoteCountingContext create(Poll poll, boolean isByGroup) {
+
+ VoteCountingStrategy method;
+ switch (poll.getVoteCounting()) {
+ case NORMAL:
+ method = new StandardVoteCountingStrategy();
+ break;
+ case PERCENTAGE:
+ method = new PercentageVoteCountingStrategy();
+ break;
+ case CONDORCET:
+ method = new CondorcetVoteCountingStrategy();
+ break;
+ case NUMBER:
+ method = new NumberVoteCountingStrategy();
+ break;
+ default:
+ method = new StandardVoteCountingStrategy();
+ }
+ VoteCountingContext result = new VoteCountingContext(method,
+ isByGroup);
+
+ for (PollChoice choice : poll.getChoices()) {
+ if (choice.isHidden()) {
+ result.addHiddenChoice(choice);
+ } else {
+ result.addChoice(choice);
+ }
+ }
+ for (PollVotingGroup votingGroup : poll.getVotingGroups()) {
+ result.addGroup(votingGroup.getIdGroup(), votingGroup.getWeight());
+ for (PollVotingPerson person : votingGroup.getVotingPersons()) {
+ String currentIdGroup = votingGroup.getIdGroup();
+ for (PollVotingChoice vote : person.getChoices()) {
+
+ Choice choice = result.getChoice(vote.getIdChoice());
+
+ Group group = choice.getGroup(currentIdGroup);
+
+ group.addVote(vote.getValue(),
+ person.getWeight(),
+ person.getVotingId());
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Renvoie un choix de la map
+ *
+ * @param idChoice : identifiant du choix
+ * @return choix
+ */
+ public Choice getChoice(String idChoice) {
+ for (Choice choice : this.choices) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return choice;
+ }
+ }
+ for (Choice choice : this.hiddenChoices) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return choice;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Renvoie la liste des choix
+ *
+ * @return liste des choix
+ */
+ public List<Choice> getChoices() {
+ return this.choices;
+ }
+
+ /**
+ * Renvoie la liste des choix cachés
+ *
+ * @return liste des choix cachés
+ */
+ public List<Choice> getHiddenChoices() {
+ return this.hiddenChoices;
+ }
+
+ /**
+ * Renvoie la liste des résultats
+ *
+ * @return liste des choix résultats
+ */
+ public List<Choice> getResults() {
+ return this.results;
+ }
+
+ /**
+ * Ajout d'un nouveau choix au contexte
+ *
+ * @param choice choix à ajouter
+ */
+ public void addChoice(PollChoice choice) {
+ this.choices.add(new Choice(choice.getIdChoice(), choice.getName()));
+ }
+
+ /**
+ * Ajout d'un nouveau choix au contexte
+ *
+ * @param choice choix à ajouter
+ */
+ public void addHiddenChoice(PollChoice choice) {
+ this.hiddenChoices.add(new Choice(choice.getIdChoice(), choice.getName()));
+ }
+
+ /**
+ * Ajout d'un groupe pour l'ensemble des choix du contexte
+ *
+ * @param idGroup : identifiant du groupe
+ * @param weight : poids du groupe
+ */
+ public void addGroup(String idGroup, double weight) {
+ for (Choice choice : this.choices) {
+ choice.addGroup(idGroup, weight);
+ }
+ for (Choice choice : this.hiddenChoices) {
+ choice.addGroup(idGroup, weight);
+ }
+ }
+
+ /**
+ * Test si le choix est un résultat d'après le contexte A utiliser après
+ * dépouillement sinon aucun résultat
+ *
+ * @param choice : choix à tester
+ * @return true si le choix est un résultat, false sinon
+ */
+ private boolean isChoiceResult(Choice choice) {
+ for (Choice res : results) {
+ if (choice.getIdChoice().equals(res.getIdChoice())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Execution de la méthode de dépouillement et calcul des choix résultats
+ *
+ * @return liste de choix résultats
+ */
+ public boolean executeCounting() {
+
+ method.executeCounting(choices, groupCounting);
+ method.executeCounting(hiddenChoices, groupCounting);
+
+ this.results.clear();
+ Choice result = new Choice("");
+
+ for (Choice curr : this.choices) {
+ if (curr.value() > result.value()) {
+ result = curr;
+ this.results.clear();
+ } else if (curr.value() == result.value()) {
+ this.results.add(curr);
+ }
+ }
+
+ this.results.add(result);
+ return true;
+ }
+
+ public List<PollVoteCountingChoice> executeStats() {
+ List<PollVoteCountingChoice> resChoices = new ArrayList<PollVoteCountingChoice>();
+
+ try {
+ for (Choice choice : choices) {
+ PollVoteCountingChoice choiceDTO = new PollVoteCountingChoice();
+
+ choiceDTO.setIdChoice(choice.getIdChoice());
+ choiceDTO.setName(choice.getName());
+ choiceDTO.setValue(choice.getValue());
+ choiceDTO.setResult(isChoiceResult(choice));
+ choiceDTO.setNbVotes(calculateNbVotes(choice, groupCounting));
+
+ method.executeStats(choices, groupCounting, choice, choiceDTO);
+ resChoices.add(choiceDTO);
+ }
+
+ for (Choice choice : hiddenChoices) {
+ PollVoteCountingChoice choiceDTO = new PollVoteCountingChoice();
+ choiceDTO.setIdChoice(choice.getIdChoice());
+ choiceDTO.setName(choice.getName());
+ choiceDTO.setValue(choice.getValue());
+ resChoices.add(choiceDTO);
+ }
+
+ } catch (Exception e) {
+ log.error("L'exécution des statistiques a échoué", e);
+ resChoices = new ArrayList<PollVoteCountingChoice>();
+ }
+
+ return resChoices;
+ }
+ }
+
+ /**
+ * Calcul le nombre de votes d'une liste
+ *
+ * @param poll
+ * @param byGroup
+ * @return nombre de votes
+ */
+ public static int calculateNbVotes(Poll poll, boolean byGroup) {
+ int result;
+ List<PollVotingGroup> list = poll.getVotingGroups();
+ if (byGroup) {
+ result = 0;
+ for (PollVotingGroup curr : list) {
+ result += Iterables.size(curr);
+ }
+ } else {
+ result = list.size();
+ }
+ return result;
+ }
+
+ /**
+ * Calcul le nombre de votes d'une liste
+ *
+ * @param choice
+ * @param byGroup
+ * @return nombre de votes
+ */
+ public static int calculateNbVotes(Choice choice, boolean byGroup) {
+ int result;
+ List<Group> list = choice.getGroups();
+ if (byGroup) {
+ result = 0;
+ for (Group curr : list) {
+ result += Iterables.size(curr);
+ }
+ } else {
+ result = list.size();
+ }
+ return result;
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/Utils.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain;
+
+import org.chorem.poll.domain.vote.PercentageBehavior;
+
+import java.util.List;
+
+/**
+ * Classe utilitaire pour les algorithmes de dépouillement.
+ *
+ * @version $Id$
+ */
+public class VoteCountingUtils {
+
+ public static double calculatePercentage(PercentageBehavior in,
+ List<PercentageBehavior> list) {
+ double total = 0.;
+ for (PercentageBehavior curr : list) {
+ total += curr.value();
+ }
+ return (in.value() / total * 100);
+ }
+
+// /**
+// * Calcul le nombre de votes d'une liste
+// *
+// * @param poll
+// * @param byGroup
+// * @return nombre de votes
+// */
+// public static int calculateNbVotes(Poll poll, boolean byGroup) {
+// int result;
+// List<PollVotingGroup> list = poll.getVotingGroups();
+// if (byGroup) {
+// result = 0;
+// for (PollVotingGroup curr : list) {
+// result += Iterables.size(curr);
+// }
+// } else {
+// result = list.size();
+// }
+// return result;
+// }
+//
+// /**
+// * Calcul le nombre de votes d'une liste
+// *
+// * @param choice
+// * @param byGroup
+// * @return nombre de votes
+// */
+// public static int calculateNbVotes(Choice choice, boolean byGroup) {
+// int result;
+// List<Group> list = choice.getGroups();
+// if (byGroup) {
+// result = 0;
+// for (Group curr : list) {
+// result += Iterables.size(curr);
+// }
+// } else {
+// result = list.size();
+// }
+// return result;
+// }
+
+}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: ChoiceType.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import static org.nuiton.i18n.I18n.n_;
+
+public enum ChoiceType implements I18nAble {
+ TEXT(n_("pollen.choiceType.text")),
+ DATE(n_("pollen.choiceType.date")),
+ IMAGE(n_("pollen.choiceType.image"));
+
+ private final String i18nKey;
+
+ ChoiceType(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ @Override
+ public String getI18nKey() {
+ return i18nKey;
+ }
+
+ public static ChoiceType valueOf(int ordinal) {
+
+ ChoiceType result = null;
+ for (ChoiceType curr : ChoiceType.values()) {
+ if (curr.ordinal() == ordinal) {
+ result = curr;
+ break;
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,35 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: I18nAble.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Contract to expose a i18n key.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public interface I18nAble {
+
+ String getI18nKey();
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,257 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import com.google.common.collect.Lists;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Classe DTO représentant un sondage.
+ *
+ * @version $Id$
+ */
+public class Poll {
+
+ private String pollId = "";
+
+ private String title = "";
+
+ private String description = "";
+
+ private Date beginDate = new Date();
+
+ private Date endDate = null;
+
+ private Date beginChoiceDate = null;
+
+ private int maxChoiceNb = 0;
+
+ private boolean closed = true;
+
+ private boolean choiceAddAllowed = false;
+
+ private boolean anonymousVoteAllowed = false;
+
+ private boolean anonymous = false;
+
+ private boolean publicResults = false;
+
+ private boolean continuousResults = false;
+
+ private PollType pollType = null;
+
+ private VoteCountingType voteCounting = null;
+
+ private ChoiceType choiceType = null;
+
+ private String creatorId = "";
+
+ private String creatorEmail = "";
+
+ private List<PollVotingGroup> votingGroups = Lists.newArrayList();
+
+ private List<PollChoice> choices = Lists.newArrayList();
+
+ private List<PollComment> comments = Lists.newArrayList();
+
+ private List<PollVoteCountingResult> voteCountingResult;
+
+ public String getPollId() {
+ return pollId;
+ }
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Date beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Date getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate;
+ }
+
+ public Date getBeginChoiceDate() {
+ return beginChoiceDate;
+ }
+
+ public void setBeginChoiceDate(Date beginChoiceDate) {
+ this.beginChoiceDate = beginChoiceDate;
+ }
+
+ public int getMaxChoiceNb() {
+ return maxChoiceNb;
+ }
+
+ public void setMaxChoiceNb(int maxChoiceNb) {
+ this.maxChoiceNb = maxChoiceNb;
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+
+ public void setClosed(boolean closed) {
+ this.closed = closed;
+ }
+
+ public boolean isChoiceAddAllowed() {
+ return choiceAddAllowed;
+ }
+
+ public void setChoiceAddAllowed(boolean choiceAddAllowed) {
+ this.choiceAddAllowed = choiceAddAllowed;
+ }
+
+ public boolean isAnonymousVoteAllowed() {
+ return anonymousVoteAllowed;
+ }
+
+ public void setAnonymousVoteAllowed(boolean anonymousVoteAllowed) {
+ this.anonymousVoteAllowed = anonymousVoteAllowed;
+ }
+
+ public boolean isAnonymous() {
+ return anonymous;
+ }
+
+ public void setAnonymous(boolean anonymous) {
+ this.anonymous = anonymous;
+ }
+
+ public boolean isPublicResults() {
+ return publicResults;
+ }
+
+ public void setPublicResults(boolean publicResults) {
+ this.publicResults = publicResults;
+ }
+
+ public boolean isContinuousResults() {
+ return continuousResults;
+ }
+
+ public void setContinuousResults(boolean continuousResults) {
+ this.continuousResults = continuousResults;
+ }
+
+ public PollType getPollType() {
+ return pollType;
+ }
+
+ public void setPollType(PollType pollType) {
+ this.pollType = pollType;
+ }
+
+ public VoteCountingType getVoteCounting() {
+ return voteCounting;
+ }
+
+ public void setVoteCounting(VoteCountingType voteCounting) {
+ this.voteCounting = voteCounting;
+ }
+
+ public ChoiceType getChoiceType() {
+ return choiceType;
+ }
+
+ public void setChoiceType(ChoiceType choiceType) {
+ this.choiceType = choiceType;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorEmail() {
+ return creatorEmail;
+ }
+
+ public void setCreatorEmail(String creatorEmail) {
+ this.creatorEmail = creatorEmail;
+ }
+
+ public List<PollVotingGroup> getVotingGroups() {
+ return votingGroups;
+ }
+
+ public void setVotingGroups(List<PollVotingGroup> votingGroups) {
+ this.votingGroups = votingGroups;
+ }
+
+ public List<PollChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<PollChoice> choices) {
+ this.choices = choices;
+ }
+
+ public List<PollComment> getComments() {
+ return comments;
+ }
+
+ public void setComments(List<PollComment> comments) {
+ this.comments = comments;
+ }
+
+ public List<PollVoteCountingResult> getVoteCountingResult() {
+ return voteCountingResult;
+ }
+
+ public void setVoteCountingResult(List<PollVoteCountingResult> voteCountingResult) {
+ this.voteCountingResult = voteCountingResult;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollChoiceDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,72 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un choix de vote.
+ *
+ * @version $Id$
+ */
+public class PollChoice {
+
+ private String idChoice;
+
+ private String name;
+
+ private String description;
+
+ private boolean hidden;
+
+ public String getIdChoice() {
+ return idChoice;
+ }
+
+ public void setIdChoice(String idChoice) {
+ this.idChoice = idChoice;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/CommentDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un commentaire.
+ *
+ * @version $Id$
+ */
+public class PollComment {
+
+ private String votingID;
+
+ private String text;
+
+ public String getVotingID() {
+ return votingID;
+ }
+
+ public void setVotingID(String votingID) {
+ this.votingID = votingID;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: PollType.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import static org.nuiton.i18n.I18n.n_;
+
+public enum PollType implements I18nAble {
+
+ FREE(n_("pollen.pollType.free")),
+ RESTRICTED(n_("pollen.pollType.restricted")),
+ GROUP(n_("pollen.pollType.group"));
+
+ private final String i18nKey;
+
+ PollType(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ @Override
+ public String getI18nKey() {
+ return i18nKey;
+ }
+
+ public static PollType valueOf(int ordinal) {
+ PollType result = null;
+ for (PollType curr : PollType.values()) {
+ if (curr.ordinal() == ordinal) {
+ result = curr;
+ break;
+ }
+ }
+ return result;
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/ChoiceDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,124 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un choix et les valeurs du vote correspondant.
+ *
+ * @version $Id$
+ */
+public class PollVoteCountingChoice {
+
+ private String idChoice;
+
+ private String name;
+
+ private double value;
+
+ private double percentage;
+
+ private double average;
+
+ private int nbVotes;
+
+ private int nbBlankVotes;
+
+ private boolean result;
+
+ public PollVoteCountingChoice() {
+ }
+
+ public PollVoteCountingChoice(String idChoice, double value, double percentage,
+ int nbVotes) {
+ this.idChoice = idChoice;
+ this.value = value;
+ this.percentage = percentage;
+ this.nbVotes = nbVotes;
+ }
+
+ public String getIdChoice() {
+ return idChoice;
+ }
+
+ public void setIdChoice(String idChoice) {
+ this.idChoice = idChoice;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ public double getPercentage() {
+ return percentage;
+ }
+
+ public void setPercentage(double percentage) {
+ this.percentage = percentage;
+ }
+
+ public double getAverage() {
+ return average;
+ }
+
+ public void setAverage(double average) {
+ this.average = average;
+ }
+
+ public int getNbVotes() {
+ return nbVotes;
+ }
+
+ public void setNbVotes(int nbVotes) {
+ this.nbVotes = nbVotes;
+ }
+
+ public int getNbBlankVotes() {
+ return nbBlankVotes;
+ }
+
+ public void setNbBlankVotes(int nbBlankVotes) {
+ this.nbBlankVotes = nbBlankVotes;
+ }
+
+ public boolean isResult() {
+ return result;
+ }
+
+ public void setResult(boolean result) {
+ this.result = result;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteCountingResultDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,99 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import java.util.List;
+
+/**
+ * Classe DTO représentant un résultat de sondage.
+ *
+ * @version $Id$
+ */
+public class PollVoteCountingResult {
+
+ private int nbVotes;
+
+ private String choiceResult;
+
+ private String idPoll;
+
+ private VoteCountingType typeVoteCounting;
+
+ private boolean byGroup;
+
+ private List<PollVoteCountingChoice> choices;
+
+ public PollVoteCountingResult() {
+
+ }
+
+ public int getNbVotes() {
+ return nbVotes;
+ }
+
+ public void setNbVotes(int nbVotes) {
+ this.nbVotes = nbVotes;
+ }
+
+ public String getChoiceResult() {
+ return choiceResult;
+ }
+
+ public void setChoiceResult(String choiceResult) {
+ this.choiceResult = choiceResult;
+ }
+
+ public String getIdPoll() {
+ return idPoll;
+ }
+
+ public void setIdPoll(String idPoll) {
+ this.idPoll = idPoll;
+ }
+
+ public VoteCountingType getTypeVoteCounting() {
+ return typeVoteCounting;
+ }
+
+ public void setTypeVoteCounting(VoteCountingType typeVoteCounting) {
+ this.typeVoteCounting = typeVoteCounting;
+ }
+
+ public boolean isByGroup() {
+ return byGroup;
+ }
+
+ public void setByGroup(boolean byGroup) {
+ this.byGroup = byGroup;
+ }
+
+ public List<PollVoteCountingChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<PollVoteCountingChoice> choices) {
+ this.choices = choices;
+ }
+
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteToChoiceDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,63 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un vote.
+ *
+ * @version $Id$
+ */
+public class PollVotingChoice {
+
+ private double value;
+
+ private String idChoice;
+
+ public PollVotingChoice(int idChoice, double value) {
+ this.idChoice = String.valueOf(idChoice);
+ this.value = value;
+ }
+
+ public PollVotingChoice(String idChoice, double value) {
+ this.idChoice = idChoice;
+ this.value = value;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ public String getIdChoice() {
+ return idChoice;
+ }
+
+ public void setIdChoice(String idChoice) {
+ this.idChoice = idChoice;
+ }
+
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VotingGroupDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,83 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import com.google.common.collect.Lists;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Classe DTO représentant un groupe de votants.
+ *
+ * @version $Id$
+ */
+public class PollVotingGroup implements Iterable<PollVotingPerson> {
+
+ private String name;
+
+ private double weight;
+
+ private String idGroup;
+
+ private List<PollVotingPerson> votingPersons = Lists.newArrayList();
+
+ @Override
+ public Iterator<PollVotingPerson> iterator() {
+ return votingPersons.iterator();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getWeight() {
+ return weight;
+ }
+
+ public void setWeight(double weight) {
+ this.weight = weight;
+ }
+
+ public String getIdGroup() {
+ return idGroup;
+ }
+
+ public void setIdGroup(String idGroup) {
+ this.idGroup = idGroup;
+ }
+
+ public List<PollVotingPerson> getVotingPersons() {
+ return votingPersons;
+ }
+
+ public void setVotingPersons(List<PollVotingPerson> votingPersons) {
+ this.votingPersons = votingPersons;
+ }
+
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VotingPersonDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,108 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import com.google.common.collect.Lists;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Classe DTO représentant un votant.
+ *
+ * @version $Id$
+ */
+public class PollVotingPerson {
+
+ private String votingId;
+
+ private double weight;
+
+ private String comment;
+
+ private String email;
+
+ private String login;
+
+ private Date votingDate;
+
+ private List<PollVotingChoice> choices = Lists.newArrayList();
+
+ public String getVotingId() {
+ return votingId;
+ }
+
+ public void setVotingId(String votingId) {
+ this.votingId = votingId;
+ }
+
+ public double getWeight() {
+ return weight;
+ }
+
+ public void setWeight(double weight) {
+ this.weight = weight;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getLogin() {
+ return login;
+ }
+
+ public void setLogin(String login) {
+ this.login = login;
+ }
+
+ public Date getVotingDate() {
+ return votingDate;
+ }
+
+ public void setVotingDate(Date votingDate) {
+ this.votingDate = votingDate;
+ }
+
+ public List<PollVotingChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<PollVotingChoice> choices) {
+ this.choices = choices;
+ }
+
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: VoteCountingType.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import static org.nuiton.i18n.I18n.n_;
+
+public enum VoteCountingType implements I18nAble {
+ NORMAL(n_("pollen.voteCountingType.normal")),
+ PERCENTAGE(n_("pollen.voteCountingType.percentage")),
+ CONDORCET(n_("pollen.voteCountingType.condorcet")),
+ NUMBER(n_("pollen.voteCountingType.number"));
+
+ private final String i18nKey;
+
+ VoteCountingType(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ @Override
+ public String getI18nKey() {
+ return i18nKey;
+ }
+
+ public static VoteCountingType valueOf(int ordinal) {
+ VoteCountingType result = null;
+ for (VoteCountingType curr : VoteCountingType.values()) {
+ if (curr.ordinal() == ordinal) {
+ result = curr;
+ break;
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,337 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.poll.domain.VoteCountingUtils;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+import org.chorem.poll.domain.vote.PercentageBehavior;
+import org.chorem.poll.domain.vote.Vote;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Méthode de dépouillement Condorcet.
+ *
+ * @author rannou
+ * @version $Id$
+ */
+public class CondorcetVoteCountingStrategy implements VoteCountingStrategy {
+
+ /** Victoires pour chaque choix. */
+ private Map<Choice, Double> victories;
+
+ /** Choix de chaque personne. (personne >> choix >> classement) */
+ private Map<String, Map<Choice, Double>> personVotes;
+
+ /** Choix de chaque groupe. (groupe >> choix >> classement) */
+ private Map<String, Map<Choice, Double>> groupVotes;
+
+ /** log. */
+ private static final Log log =
+ LogFactory.getLog(CondorcetVoteCountingStrategy.class);
+
+ @Override
+ public void executeCounting(List<Choice> choices, boolean byGroup) {
+ if (byGroup) {
+ initPersonVotes(choices);
+ initGroupVotes(choices);
+ calculateVictories(choices, groupVotes, byGroup);
+ updateChoices(choices);
+ } else {
+ initPersonVotes(choices);
+ calculateVictories(choices, personVotes, byGroup);
+ updateChoices(choices);
+ }
+ }
+
+ /**
+ * Initialisation des votes par personne. Les votes sont initialisés avec
+ * les valeurs des choix.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ */
+ private void initPersonVotes(List<Choice> choices) {
+ personVotes = new HashMap<String, Map<Choice, Double>>();
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ for (Vote vote : group.getVotes()) {
+ Map<Choice, Double> choicesMap = personVotes.get(vote
+ .getVotingID());
+ if (choicesMap == null) {
+ choicesMap = new HashMap<Choice, Double>();
+ }
+ choicesMap.put(choice, vote.getValue());
+ personVotes.put(vote.getVotingID(), choicesMap);
+ }
+ }
+ }
+ }
+
+ /**
+ * Initialisation des votes par groupes. Les votes sont initialisés avec les
+ * victoires des membres du groupe. Des dépouillements sont donc effectués
+ * au sein de chaque groupe avant d'effectuer le dépouillement global.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ */
+ private void initGroupVotes(List<Choice> choices) {
+ groupVotes = new HashMap<String, Map<Choice, Double>>();
+
+ // Initialisation de la liste des membres de chaque groupe (groupMembers)
+ Map<String, Set<String>> groupMembers = new HashMap<String, Set<String>>();
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ Set<String> members = groupMembers.get(group.getIdGroup());
+ if (members == null) {
+ members = new HashSet<String>();
+ }
+ for (Vote vote : group.getVotes()) {
+ members.add(vote.getVotingID());
+ }
+ groupMembers.put(group.getIdGroup(), members);
+ }
+ }
+
+ // Initialisation des votes de chaque groupe (groupVotes)
+ for (String groupID : groupMembers.keySet()) {
+
+ // Initialisation des votes par membre à partir des personVotes
+ // membersVotes : liste des votes de chaque votant du groupe courant
+ Map<String, Map<Choice, Double>> membersVotes = new HashMap<String, Map<Choice, Double>>();
+ for (String votingID : groupMembers.get(groupID)) {
+ Map<Choice, Double> choicesMap = personVotes.get(votingID);
+ membersVotes.put(votingID, choicesMap);
+ }
+
+ // Calcul des victoires pour le groupe
+ calculateVictories(choices, membersVotes, false);
+ groupVotes.put(groupID, victories2votes(victories));
+
+ //TODO joindre ce résultat (Map) au group.value (Double) ???
+ TreeSet<Double> treeVictories = new TreeSet<Double>(victories
+ .values());
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ if (group.getIdGroup().equals(groupID)) {
+ group.setValue(treeVictories.last());
+ }
+ }
+ }
+
+ // Affichage des victoires et des groupVotes
+ if (log.isDebugEnabled()) {
+ log.debug("> groupe " + groupID);
+ for (Choice choice : victories.keySet()) {
+ log.debug(">> choix= " + choice.getIdChoice()
+ + " _ victoires= " + victories.get(choice)
+ + " _ classement= "
+ + groupVotes.get(groupID).get(choice));
+ }
+ }
+ }
+ }
+
+ /**
+ * Calcul des victoires. Parcours des votants (personnes ou groupes) et de
+ * leurs votes. Pour chaque vote, calcul des victoires par rapport aux
+ * autres votes du votant et mise à jour du nombre de victoires pour ce
+ * vote.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ * @param votes Les votes de chaque votant.
+ * @param byGroup Calcul sur des groupes.
+ * @see #getVictories(String, Choice, Map)
+ */
+ private void calculateVictories(List<Choice> choices,
+ Map<String, Map<Choice, Double>> votes, boolean byGroup) {
+ // Initialisation des victoires à 0.
+ victories = new HashMap<Choice, Double>();
+ for (Choice choice : choices) {
+ victories.put(choice, 0.);
+ }
+
+ // Calcul des victoires
+ for (String keyVotant : votes.keySet()) {
+ for (Choice keyChoice : votes.get(keyVotant).keySet()) {
+
+ // Victoires pour le votant + application du poids du votant
+ Double v = getVictories(keyVotant, keyChoice, votes)
+ .doubleValue();
+ if (byGroup) {
+ v *= getGroupWeight(choices, keyVotant);
+ } else {
+ v *= getPersonWeight(choices, keyVotant);
+ }
+
+ victories.put(keyChoice, victories.get(keyChoice) + v);
+ }
+ }
+ }
+
+ /**
+ * Calcul du nombre de duels gagnés par un choix par rapport aux autres
+ * choix d'un votant (personne ou groupe).
+ *
+ * @param id L'identifiant du votant
+ * @param choice Le choix de référence pour le calcul
+ * @param votes Les votes de chaque votant.
+ * @return Le nombre de duels gagnés
+ */
+ private Integer getVictories(String id, Choice choice,
+ Map<String, Map<Choice, Double>> votes) {
+ int res = 0; // résultat : nombre de victoires
+
+ Double ref = votes.get(id).get(choice); // valeur de référence
+ Double val; // valeur courante
+
+ for (Choice keyChoice : victories.keySet()) {
+ if (votes.get(id).containsKey(keyChoice)) {
+ val = votes.get(id).get(keyChoice);
+ if (ref < val) {
+ res++;
+ }
+ } else { // val == null (choix non renseigné par le votant)
+ res++;
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Transformation des victoires en votes. Les victoires listent le nombre de
+ * duels gagnés pour chaque choix alors que les votes donnent leur
+ * classement.
+ *
+ * @param victories Les victoires.
+ * @return Les votes.
+ */
+ private Map<Choice, Double> victories2votes(Map<Choice, Double> victories) {
+ Map<Choice, Double> victories_ = new HashMap<Choice, Double>(victories);
+ Map<Choice, Double> votes_ = new HashMap<Choice, Double>();
+
+ Integer d = 1;
+ Map<Choice, Double> victoriesMax = getMax(victories_);
+ while (!victoriesMax.isEmpty()) {
+ for (Choice choice : victoriesMax.keySet()) {
+ votes_.put(choice, d.doubleValue());
+ victories_.remove(choice);
+ }
+ d++;
+ victoriesMax = getMax(victories_);
+ }
+
+ return votes_;
+ }
+
+ /**
+ * Retourne le ou les couples choix-valeur de valeur maxmimale.
+ *
+ * @param victories Les victoires.
+ * @return Le ou les choix de valeur maximale.
+ */
+ private Map<Choice, Double> getMax(Map<Choice, Double> victories) {
+ Map<Choice, Double> result = new HashMap<Choice, Double>();
+ if (victories.isEmpty()) {
+ return result;
+ }
+
+ TreeSet<Double> treeVictories = new TreeSet<Double>(victories.values());
+ Double max = treeVictories.last();
+ for (Choice choice : victories.keySet()) {
+ if (victories.get(choice).equals(max)) {
+ result.put(choice, victories.get(choice));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Récupération du poids d'une personne.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ * @param id L'identifiant de la personne.
+ * @return Le poids de la personne.
+ */
+ private Double getPersonWeight(List<Choice> choices, String id) {
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ for (Vote vote : group.getVotes()) {
+ if (id.equals(vote.getVotingID())) {
+ return vote.getWeight();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Récupération du poids d'un groupe.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ * @param id L'identifiant du groupe.
+ * @return Le poids du groupe.
+ */
+ private Double getGroupWeight(List<Choice> choices, String id) {
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ if (id.equals(group.getIdGroup())) {
+ return group.getWeight();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Mise à jour des valeurs des choix.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ */
+ private void updateChoices(List<Choice> choices) {
+ for (Choice choice : choices) {
+ choice.setValue(victories.get(choice));
+ /*for (Group group : choice.getGroups()) {
+ group.setValue(victories.get(choice));
+ }*/
+ }
+ }
+
+ @Override
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO) {
+ List<PercentageBehavior> list = new ArrayList<PercentageBehavior>(choices);
+ choiceDTO.setPercentage(VoteCountingUtils.calculatePercentage(choice, list));
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,97 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+import org.chorem.poll.domain.vote.Vote;
+
+import java.util.List;
+
+/**
+ * Méthode de dépouillement pour vote de type number.
+ *
+ * @version $Revision$ $Date$
+ * @since 1.2.2
+ */
+public class NumberVoteCountingStrategy implements VoteCountingStrategy {
+
+ /** Permet de rajouter des choix cachés */
+ public static final String HIDDEN_PREFIX = "HIDDEN_";
+
+ @Override
+ public void executeCounting(List<Choice> choices, boolean byGroup) {
+
+ for (Choice choice : choices) {
+ double totalChoice = 0.;
+
+ for (Group group : choice.getGroups()) {
+ double totalGroup = 0.;
+
+ for (Vote vote : group.getVotes()) {
+ double value = vote.getValue();
+
+ if (value >= 0) {
+ if (byGroup) {
+ totalGroup += vote.getValue() * vote.getWeight() * group.getWeight();
+ } else {
+ totalGroup += vote.getValue() * vote.getWeight();
+ }
+ }
+ }
+
+ group.setValue(totalGroup);
+ totalChoice += totalGroup;
+ }
+
+ choice.setValue(totalChoice);
+ }
+ }
+
+ @Override
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO) {
+
+ int nbBlankVotes = 0;
+ double average = 0;
+ int nbVotes = 0;
+
+ for (Group group : choice.getGroups()) {
+ for (Vote vote : group.getVotes()) {
+ nbVotes = nbVotes + 1;
+ if (vote.getValue() < 0) {
+ nbBlankVotes = nbBlankVotes + 1;
+ }
+ }
+ }
+
+ if (nbVotes - nbBlankVotes > 0) {
+ average = choice.value() / (nbVotes - nbBlankVotes);
+ }
+
+ choiceDTO.setAverage(average);
+ choiceDTO.setNbBlankVotes(nbBlankVotes);
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/PercentageMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.vote.Choice;
+
+import java.util.List;
+
+/**
+ * Méthode de dépouillement par pourcentage (pondération des choix). Cette
+ * méthode étend la méthode standard en ajoutant la pondération des choix.
+ *
+ * @author rannou
+ * @version $Id$
+ */
+
+public class PercentageVoteCountingStrategy extends StandardVoteCountingStrategy {
+
+ @Override
+ public double getValueForChoiceByGroup(Choice choice, String idGroup,
+ List<String> choicesId) {
+ for (String idChoice : choicesId) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return choice.getGroup(idGroup).getValue()
+ * choice.getGroup(idGroup).getWeight(); // choice.getGroup(idGroup).getValue() remplace 1
+
+ }
+ }
+ return 0;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,132 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.VoteCountingUtils;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+import org.chorem.poll.domain.vote.PercentageBehavior;
+import org.chorem.poll.domain.vote.Vote;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Méthode de dépouillement standard.
+ *
+ * @version $Id$
+ */
+public class StandardVoteCountingStrategy implements VoteCountingStrategy {
+
+ @Override
+ public void executeCounting(List<Choice> choices, boolean byGroup) {
+ calculateGroups(choices);
+ if (byGroup) {
+ calculateChoicesByGroup(choices);
+ }
+ }
+
+ // Pre traitement de la valeur des groupes + totalChoice (tout le monde)
+ public void calculateGroups(List<Choice> choices) {
+ for (Choice choice : choices) {
+ double totalChoice = 0.;
+ for (Group group : choice.getGroups()) {
+ this.getValueForGroup(group);
+ totalChoice += group.getValue();
+ }
+ choice.setValue(totalChoice);
+ }
+ }
+
+ public void getValueForGroup(Group group) {
+ double total = 0.;
+ for (Vote vote : group.getVotes()) {
+ total += vote.getValue() * vote.getWeight();
+ }
+ group.setValue(total);
+ }
+
+ // Calcul avec prise en compte des groupes
+ public void calculateChoicesByGroup(List<Choice> choices) {
+ Map<String, List<String>> mapGroupsChoosenChoices = this
+ .getChoosenChoicesByGroup(choices);
+
+ for (Choice choice : choices) {
+ double totalChoice = 0.;
+ for (String idGroup : mapGroupsChoosenChoices.keySet()) {
+ totalChoice += this.getValueForChoiceByGroup(choice, idGroup,
+ mapGroupsChoosenChoices.get(idGroup));
+ }
+ choice.setValue(totalChoice);
+ }
+ }
+
+ // Récupération du choix de chaque groupe (plusieurs choix si égalité)
+ public Map<String, List<String>> getChoosenChoicesByGroup(
+ List<Choice> choices) {
+ Map<String, List<String>> mapGroupsChoosenChoices = new HashMap<String, List<String>>();
+
+ if (choices != null && choices.size() > 0) {
+ for (Group group : choices.get(0).getGroups()) {
+ double maxValue = 0.;
+ List<String> choosenChoicesId = new ArrayList<String>();
+
+ for (Choice choice : choices) {
+ Group curr = choice.getGroup(group.getIdGroup());
+ if (curr.getValue() > maxValue) {
+ maxValue = curr.getValue();
+ choosenChoicesId.clear();
+ }
+ if (curr.getValue() != 0 && maxValue == curr.getValue()) {
+ choosenChoicesId.add(choice.getIdChoice());
+ }
+ }
+
+ mapGroupsChoosenChoices.put(group.getIdGroup(), choosenChoicesId);
+ }
+ }
+
+ return mapGroupsChoosenChoices;
+ }
+
+ public double getValueForChoiceByGroup(Choice choice, String idGroup,
+ List<String> choicesId) {
+ for (String idChoice : choicesId) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return 1 * choice.getGroup(idGroup).getWeight(); // 1 a remplacer suivant l'algo
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO) {
+ List<PercentageBehavior> list = new ArrayList<PercentageBehavior>(choices);
+ choiceDTO.setPercentage(VoteCountingUtils.calculatePercentage(choice, list));
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,37 @@
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+
+import java.util.List;
+
+/**
+ * Contract of a strategy of a vote countig.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public interface VoteCountingStrategy {
+
+ /**
+ * Execute le dépouillement de l'ensemble des choix spécifiés.
+ *
+ * @param pollchoices les choix à dépouiller
+ * @param groupCounting si le dépouillement doit être groupé
+ */
+ public void executeCounting(List<Choice> pollchoices, boolean groupCounting);
+
+ /**
+ * Effectue des statistiques sur le <code>choice</code> specifié.
+ *
+ * La fonction <code>executeCounting</code> doit avoir été
+ * executée avant d'appeler cette fonction.
+ *
+ * @param choices l'ensemble des choix du dépouillement
+ * @param groupCounting si le dépouillement doit être groupé
+ * @param choice le choix sur lequel effectuer des statistiques
+ * @param choiceDTO le choix contenant les resultats statistiques
+ */
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO);
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Choice.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,157 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Cette classe décrit le choix d'un sondage. Sa valeur sera modifiée au moment
+ * de l'exécution de la méthode de dépouillement.
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+public class Choice implements Iterable<Group>, PercentageBehavior {
+ /** identifiant du choix */
+ private String idChoice;
+
+ /** nom du choix */
+ private String name;
+
+ /** valeur du choix déterminé par le dépouillement */
+ private double value;
+
+ /** Map des groupes liés au choix */
+ private List<Group> groups;
+
+ /**
+ * Constructeur
+ *
+ * @param id : identifiant du choix
+ */
+ public Choice(String id) {
+ this.idChoice = id;
+ this.groups = new ArrayList<Group>();
+ this.value = 0.;
+ }
+
+ /**
+ * Constructeur
+ *
+ * @param id : identifiant du choix
+ * @param name : nom du choix
+ */
+ public Choice(String id, String name) {
+ this(id);
+ this.name = name;
+ }
+
+ /**
+ * setValue : Mise à jour de la valeur du choix
+ *
+ * @param value : nouvelle valeur
+ */
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ /**
+ * getValue : Renvoie la valeur du choix
+ *
+ * @return valeur courante du choix
+ */
+ public double getValue() {
+ return this.value;
+ }
+
+ /**
+ * getId : Renvoie l'identifiant du choix
+ *
+ * @return identifiant du choix
+ */
+ public String getIdChoice() {
+ return this.idChoice;
+ }
+
+ /**
+ * getName : Renvoie le nom du choix
+ *
+ * @return nom du choix
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * getGroups : Renvoie la map des groupes
+ *
+ * @return map des groupes pour ce choix
+ */
+ public List<Group> getGroups() {
+ return this.groups;
+ }
+
+ /**
+ * addGroup : Ajout d'un groupe lié au choix
+ *
+ * @param weight : poids du groupe dans le sondage
+ * @param idGroup : identifiant du groupe
+ */
+ public void addGroup(String idGroup, double weight) {
+ this.groups.add(new Group(idGroup, weight));
+ }
+
+ /**
+ * getGroup : Renvoie un groupe existant dans la map
+ *
+ * @param idGroup : identifiant du groupe dans la map
+ * @return le groupe ayant l'identifiant idGroup
+ */
+ public Group getGroup(String idGroup) {
+ for (Group g : this.groups) {
+ if (g.getIdGroup().equals(idGroup)) {
+ return g;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public double value() {
+ return getValue();
+ }
+
+
+ @Override
+ public Iterator<Group> iterator() {
+ return groups.iterator();
+ }
+
+ @Override
+ public String toString() {
+ return "Choice id=" + idChoice + " _ value=" + value;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Group.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,122 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Cette classe décrit un groupe du sondage. Sa valeur dépend du choix et sera
+ * calculée au moment du dépouillement.
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+public class Group implements Iterable<Vote> {
+ /** Identifiant du groupe */
+ private String idGroup;
+
+ /** Poids du groupe */
+ private double weight;
+
+ /** Valeur du groupe pour le choix dans lequel il appartient */
+ private double value;
+
+ /** Liste des votes liés au groupe */
+ private List<Vote> votes;
+
+ /**
+ * Constructeur
+ *
+ * @param id : identifiant du groupe
+ * @param weight : poids du groupe
+ */
+ public Group(String id, double weight) {
+ this.idGroup = id;
+ this.weight = weight;
+ this.value = 0.;
+ this.votes = new ArrayList<Vote>();
+ }
+
+ /**
+ * getIdGroup : Identifiant du groupe
+ *
+ * @return identifiant du groupe
+ */
+ public String getIdGroup() {
+ return this.idGroup;
+ }
+
+ /**
+ * getWeight : Renvoie le poids du groupe
+ *
+ * @return poids du groupe
+ */
+ public double getWeight() {
+ return this.weight;
+ }
+
+ /**
+ * setValue : Mise à jour de la valeur du groupe
+ *
+ * @param value : nouvelle valeur du groupe
+ */
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ /**
+ * getValue : Renvoie la valeur du groupe pour le choix auquel il appartient
+ *
+ * @return la valeur du groupe
+ */
+ public double getValue() {
+ return this.value;
+ }
+
+ /**
+ * getVotes : Renvoie la liste des votes liés au groupe
+ *
+ * @return liste des votes
+ */
+ public List<Vote> getVotes() {
+ return this.votes;
+ }
+
+ /**
+ * addVote : Ajout d'un nouveau vote au groupe
+ *
+ * @param value : valeur du vote
+ * @param weight : poids du vote
+ */
+ public void addVote(double value, double weight, String votingID) {
+ this.votes.add(new Vote(value, weight, votingID));
+ }
+
+ @Override
+ public Iterator<Vote> iterator() {
+ return votes.iterator();
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/PercentageBehavior.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,33 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+/**
+ * Interface pour le comportement pourcentage.
+ *
+ * @version $Id$
+ */
+public interface PercentageBehavior {
+ public double value();
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Vote.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,82 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+/**
+ * Cette classe décrit un vote du sondage. Le vote récupère l'id et le poids du
+ * votant.
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+public class Vote {
+ /** Valeur du vote (ex : 1, 2, 3 pour condorcet ou 15 pour pourcentage) */
+ private double value;
+
+ /** Poids du vote dans le sondage */
+ private double weight;
+
+ /** Identifiant du votant */
+ private String votingID;
+
+ /**
+ * Constructeur
+ *
+ * @param value : valeur du vote connue pour le choix
+ * @param weight : poids du vote
+ * @param votingID : identifiant du votant
+ */
+ public Vote(double value, double weight, String votingID) {
+ this.value = value;
+ this.weight = weight;
+ this.votingID = votingID;
+ }
+
+ /**
+ * getValue : Renvoie la valeur du vote
+ *
+ * @return valeur du vote
+ */
+ public double getValue() {
+ return this.value;
+ }
+
+ /**
+ * getWeight : Renvoie le poids du vote
+ *
+ * @return poids du vote
+ */
+ public double getWeight() {
+ return this.weight;
+ }
+
+ /**
+ * getVotingID : Renvoie l'identifiant du votant
+ *
+ * @return identifiant du votant
+ */
+ public String getVotingID() {
+ return this.votingID;
+ }
+}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,10 @@
+pollen.choiceType.date=Date
+pollen.choiceType.image=Image
+pollen.choiceType.text=Text
+pollen.pollType.free=Free
+pollen.pollType.group=Group
+pollen.pollType.restricted=Restricted
+pollen.voteCountingType.condorcet=Condorcet
+pollen.voteCountingType.normal=Normal
+pollen.voteCountingType.number=Number
+pollen.voteCountingType.percentage=Percentage
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,10 @@
+pollen.choiceType.date=Date
+pollen.choiceType.image=Image
+pollen.choiceType.text=Texte
+pollen.pollType.free=Libre
+pollen.pollType.group=Groupe
+pollen.pollType.restricted=Restreint
+pollen.voteCountingType.condorcet=Condorcet
+pollen.voteCountingType.normal=Normal
+pollen.voteCountingType.number=Nombre
+pollen.voteCountingType.percentage=Pourcentage
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ImportExportServiceTest {
+
+ @Test
+ public void exportToXml() throws Exception {
+
+ }
+
+ @Test
+ public void importFromXml() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,21 @@
+package org.chorem.poll.domain;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class VoteCountingServiceTest {
+ @Test
+ public void executeVoteCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeGroupCounting() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class CondorcetVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class NumberVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PercentageVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class StandardVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/resources/log4j.properties)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,8 @@
+# Global logging configuration
+log4j.rootLogger=WARN, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.chorem.pollen=INFO
1
0
r3173 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/config webapp/WEB-INF/jsp
by tchemit@users.chorem.org 08 Mar '12
by tchemit@users.chorem.org 08 Mar '12
08 Mar '12
Author: tchemit
Date: 2012-03-08 01:20:50 +0100 (Thu, 08 Mar 2012)
New Revision: 3173
Url: http://chorem.org/repositories/revision/pollen/3173
Log:
export is working + use service api
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-08 00:20:50 UTC (rev 3173)
@@ -92,8 +92,6 @@
private PollAccount pollAccount;
-// private String pollAccountId;
-
private List<PollResult> results;
private List<Comment> comments;
@@ -253,18 +251,13 @@
comments = service.getAllComments(poll.getPollId());
}
- protected void loadPollResults() {
+ protected void loadPollResults() throws PollNotFoundException {
PollResultsService service = getPollResultsService();
- PollResultList resultListDTO;
- if (isGroupPoll()) {
- resultListDTO = service.getGroupResults(poll.getPollId());
- } else {
- resultListDTO = service.getNormalResults(poll.getPollId());
- }
+ PollResultList pollResultList = service.getResults(poll.getPollId());
- results = resultListDTO.getPollResults();
+ results = pollResultList.getPollResults();
if (log.isDebugEnabled()) {
for (PollResult res : results) {
@@ -425,8 +418,6 @@
protected void loadPoll() throws PollNotFoundException {
-// Preconditions.checkNotNull(pollId);
-
PollService service = newService(PollService.class);
if (StringUtils.isNotEmpty(pollId)) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-08 00:20:50 UTC (rev 3173)
@@ -23,8 +23,12 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
+import com.google.common.base.Preconditions;
+import org.apache.commons.io.IOUtils;
+import org.chorem.pollen.services.impl.PollResultsService;
+import java.io.InputStream;
+
/**
* Exports an existing poll.
*
@@ -34,4 +38,40 @@
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 {
+
+ Preconditions.checkNotNull(pollId);
+
+ PollResultsService service = newService(PollResultsService.class);
+
+ String exportContent = service.exportPolltoXml(pollId);
+
+ filename = "exportPoll-" + pollId + ".xml";
+
+ contentLength = exportContent.length() * 2;
+
+ inputStream = IOUtils.toInputStream(exportContent);
+
+ return SUCCESS;
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-08 00:20:50 UTC (rev 3173)
@@ -41,6 +41,7 @@
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.impl.PollResultsService;
import org.chorem.pollen.services.impl.PollService;
import org.nuiton.util.StringUtil;
@@ -246,17 +247,12 @@
this.byGroup = byGroup;
}
- protected void loadResults() {
+ protected void loadResults() throws PollNotFoundException {
- PollResultsService pollResultService =
- newService(PollResultsService.class);
+ PollResultsService service = newService(PollResultsService.class);
- PollResultList resultListDTO;
- if (byGroup) {
- resultListDTO = pollResultService.getGroupResults(poll.getPollId());
- } else {
- resultListDTO = pollResultService.getNormalResults(poll.getPollId());
- }
+ PollResultList resultListDTO =
+ service.getResults(poll.getPollId());
results = resultListDTO.getPollResults();
@@ -276,13 +272,13 @@
// sous-titres des vrais choix (les choix pas cachés)
subtitles = ArrayListMultimap.create();
- results = pollResultService.createNumberVoteCountingResult(
+ results = service.createNumberVoteCountingResult(
resultListDTO,
choicesResults,
subtitles);
}
- topRanking = pollResultService.getTopRanking(results);
+ topRanking = service.getTopRanking(results);
if (log.isInfoEnabled()) {
log.info("topRanking = " + topRanking);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-08 00:20:50 UTC (rev 3173)
@@ -100,8 +100,13 @@
<action name="export/*"
class="org.chorem.pollen.ui.actions.poll.ExportPoll">
<param name="uriId">{1}</param>
- <result name="input">/WEB-INF/jsp/poll/export.jsp</result>
- <result>/WEB-INF/jsp/home.jsp</result>
+ <result type="stream">
+ <param name="contentCharSet">UTF-8</param>
+ <param name="contentType">application/xml</param>
+ <param name="contentDisposition">attachment;filename="${filename}"</param>
+ <param name="encode">true</param>
+ <param name="bufferSize">4096</param>
+ </result>
</action>
<!-- close poll -->
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-03-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-03-08 00:20:50 UTC (rev 3173)
@@ -45,7 +45,7 @@
<s:url id='closeImg' value='/img/close.png'/>
<s:set id='closeTitle'><s:text name="pollen.action.pollClose"/></s:set>
-<s:url id="exportUrl" action="export/" namespace="/poll" method="input"/>
+<s:url id="exportUrl" action="export/" namespace="/poll"/>
<s:url id='exportImg' value='/img/export.png'/>
<s:set id='exportTitle'><s:text name="pollen.action.pollExport"/></s:set>
1
0
r3172 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
by tchemit@users.chorem.org 08 Mar '12
by tchemit@users.chorem.org 08 Mar '12
08 Mar '12
Author: tchemit
Date: 2012-03-08 01:20:21 +0100 (Thu, 08 Mar 2012)
New Revision: 3172
Url: http://chorem.org/repositories/revision/pollen/3172
Log:
continue to clean
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -76,7 +76,7 @@
// add it to poll
pollToUpdate.addComment(commentCreated);
- commitTransaction("Could not create comment "+comment.getText());
+ commitTransaction("Could not create comment " + comment.getText());
// feed notification
@@ -109,7 +109,7 @@
//FIXME Should we also delete the associated pollAccount ?
dao.delete(comment);
- commitTransaction("Could not delete comment "+comment.getText());
+ commitTransaction("Could not delete comment " + comment.getText());
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -29,25 +29,32 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenFunctions;
import org.chorem.pollen.bean.PollResult;
import org.chorem.pollen.bean.PollResultList;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.Result;
import org.chorem.pollen.business.persistence.ResultDAO;
+import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.votecounting.business.NumberMethod;
import org.chorem.pollen.votecounting.dto.ChoiceDTO;
import org.chorem.pollen.votecounting.dto.PollDTO;
+import org.chorem.pollen.votecounting.dto.PollExportDTO;
import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO;
-import org.chorem.pollen.votecounting.services.ServiceVoteCounting;
-import org.chorem.pollen.votecounting.services.ServiceVoteCountingImpl;
+import org.chorem.pollen.votecounting.services.ImportExportService;
+import org.chorem.pollen.votecounting.services.VoteCountingService;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -65,32 +72,38 @@
/** log. */
private static final Log log = LogFactory.getLog(PollResultsService.class);
- public PollResultList getGroupResults(String pollId) {
- return generateResults(pollId, null, true, true);
- }
+ public PollResultList getResults(String pollId) throws PollNotFoundException {
- public PollResultList getNormalResults(String pollId) {
- return generateResults(pollId, null, true, false);
+ PollService pollService = newService(PollService.class);
+ Poll poll = pollService.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+ PollResultList result;
+ if (poll.getPollType() == PollType.GROUP) {
+ result = generateResults(poll, null, true, true);
+ } else {
+ result = generateResults(poll, null, true, false);
+ }
+ return result;
}
/**
* Génère les résultats d'un sondage (= un dépouillement).
*
- * @param pollId le sondage
+ * @param poll le sondage
* @param voteCounting type de dépouillement
* @param byGroup résultats par groupe
* @param groupOnly résultats uniquement par groupe
* @return les résultats du sondage
*/
- private PollResultList generateResults(String pollId,
+ private PollResultList generateResults(Poll poll,
VoteCountingType voteCounting,
boolean byGroup,
boolean groupOnly) {
- PollService pollService = newService(PollService.class);
- Poll poll = pollService.getPollByPollId(pollId);
-// DataResultConverter converter = new DataResultConverter(transaction);
if (log.isDebugEnabled()) {
log.debug(poll.getPollId() + " (" + voteCounting
+ ") has results: " + hasResults(poll, voteCounting));
@@ -99,7 +112,7 @@
// Dépouillement du sondage.
// S'il n'existe pas de résultats ou si le sondage est encore ouvert.
//if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) {
- PollDTO dto = pollService.createPollDTOForVoteCounting(poll);
+ PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll);
if (voteCounting != null) {
dto.setVoteCounting(voteCounting);
@@ -108,15 +121,10 @@
// clear result (they will be regenerated ! (a big shame))
poll.clearResult();
- ServiceVoteCounting service = new ServiceVoteCountingImpl();
+ VoteCountingService service = new VoteCountingService();
- VoteCountingResultDTO result;
+ VoteCountingResultDTO result = service.execute(dto);
- if (PollType.GROUP == poll.getPollType()) {
- result = service.executeGroupCounting(dto);
- } else {
- result = service.executeVoteCounting(dto);
- }
ResultDAO daoResult = getDAO(Result.class);
for (ChoiceDTO choice : result.getChoices()) {
@@ -178,6 +186,47 @@
return resultList;
}
+ public String exportPolltoXml(String pollId) throws PollNotFoundException {
+
+ // Recherche du sondage
+
+ PollService pollService = newService(PollService.class);
+
+ Poll poll = pollService.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+
+ PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll);
+
+ VoteCountingService service = new VoteCountingService();
+
+ List<VoteCountingResultDTO> results = Lists.newArrayList();
+
+ VoteCountingResultDTO result = service.executeVoteCounting(dto);
+
+ results.add(result);
+
+ if (poll.getPollType() == PollType.GROUP) {
+ VoteCountingResultDTO groupResult =
+ service.executeGroupCounting(dto);
+ results.add(groupResult);
+ }
+
+ // Transformation du sondage
+ PollExportDTO pollExport = new PollExportDTO();
+ pollExport.setPollId(dto.getPollId());
+ pollExport.setPoll(dto);
+ pollExport.setVoteCountingResults(results);
+
+ // Export du sondage
+ ImportExportService serviceExport = new ImportExportService();
+ String content = serviceExport.exportToXml(pollExport);
+
+ return content;
+ }
+
/**
* Retourne la liste des résultats d'un sondage sous forme de DTOs.
*
@@ -203,7 +252,8 @@
return results;
}
- public String getResultValue(Choice choice, Collection<PollResult> results) {
+ public String getResultValue(Choice choice,
+ Collection<PollResult> results) {
String val = "";
for (PollResult result : results) {
@@ -215,9 +265,10 @@
return val;
}
- public List<PollResult> createNumberVoteCountingResult(PollResultList resultListDTO,
- Multimap<String, String> choicesResults,
- Multimap<String, String> subtitles) {
+ public List<PollResult> createNumberVoteCountingResult(
+ PollResultList resultListDTO,
+ Multimap<String, String> choicesResults,
+ Multimap<String, String> subtitles) {
Preconditions.checkNotNull(resultListDTO);
Preconditions.checkNotNull(choicesResults);
Preconditions.checkNotNull(subtitles);
@@ -347,31 +398,32 @@
return val;
}
- /**
- * Création des résultats de sondage à partir d'un dto de résultats de
- * sondage.
- *
- * @param ePoll poll à remplir
- * @param dto le dto des résultats de sondage.
- */
- protected void populateResultEntities(Poll ePoll, VoteCountingResultDTO dto) {
- for (ChoiceDTO choice : dto.getChoices()) {
+// /**
+// * Création des résultats de sondage à partir d'un dto de résultats de
+// * sondage.
+// *
+// * @param ePoll poll à remplir
+// * @param dto le dto des résultats de sondage.
+// */
+// protected void populateResultEntities(Poll ePoll,
+// VoteCountingResultDTO dto) {
+// for (ChoiceDTO choice : dto.getChoices()) {
+//
+// ResultDAO daoResult = getDAO(Result.class);
+// Result eResult = create(daoResult);
+//
+// Choice eChoice = ePoll.getChoiceByTopiaId(choice.getIdChoice());
+//
+// ePoll.addResult(eResult);
+//
+// eResult.setName(eChoice.getName());
+// eResult.setByGroup(dto.isByGroup());
+// eResult.setPoll(ePoll);
+// eResult.setResultValue(String.valueOf(choice.getValue()));
+// eResult.setVoteCountingType(dto.getTypeVoteCounting());
+// }
+// }
- ResultDAO daoResult = getDAO(Result.class);
- Result eResult = create(daoResult);
-
- Choice eChoice = ePoll.getChoiceByTopiaId(choice.getIdChoice());
-
- ePoll.addResult(eResult);
-
- eResult.setName(eChoice.getName());
- eResult.setByGroup(dto.isByGroup());
- eResult.setPoll(ePoll);
- eResult.setResultValue(String.valueOf(choice.getValue()));
- eResult.setVoteCountingType(dto.getTypeVoteCounting());
- }
- }
-
/**
* Retourne vrai si le sondage a des résultats.
*
@@ -398,166 +450,6 @@
return hasresult;
}
-// public PollResultList getAllResults(String pollId) {
-// return getResults(pollId, null, false, false);
-// }
-//
-// public PollResultList getResultsByVoteCounting(String pollId,
-// VoteCountingType voteCounting) {
-// return getResults(pollId, voteCounting, false, false);
-// }
-//
-// /**
-// * Récupère les résultats d'un sondage (sans rien dépouiller).
-// *
-// * @param pollId le sondage
-// * @param voteCounting type de dépouillement
-// * @param byGroup résultats par groupe
-// * @param groupOnly résultats uniquement par groupe
-// * @return les résultats du sondage
-// */
-// private PollResultList getResults(String pollId,
-// VoteCountingType voteCounting,
-// boolean byGroup,
-// boolean groupOnly) {
-//
-// PollService pollService = newService(PollService.class);
-// Poll poll = pollService.getPollByPollId(pollId);
-//
-//// DataResultConverter converter = new DataResultConverter(transaction);
-// if (log.isDebugEnabled()) {
-// log.debug(poll.getPollId() + " (" + voteCounting
-// + ") has results: " + hasResults(poll, voteCounting));
-// }
-//
-// // Dépouillement du sondage.
-// // S'il n'existe pas de résultats ou si le sondage est encore ouvert.
-// //if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) {
-// PollDTO dto = pollService.createPollDTOForVoteCounting(poll);
-//
-// if (voteCounting != null) {
-// dto.setVoteCounting(voteCounting);
-// }
-//
-//// // clear result (they will be regenerated ! (a big shame))
-//// poll.clearResult();
-//
-//// ServiceVoteCounting service = new ServiceVoteCountingImpl();
-////
-//// VoteCountingResultDTO result;
-////
-//// if (PollType.GROUP == poll.getPollType()) {
-//// result = service.executeGroupCounting(dto);
-//// } else {
-//// result = service.executeVoteCounting(dto);
-//// }
-//// for (ChoiceDTO choice : result.getChoices()) {
-////
-//// ResultDAO daoResult = getDAO(Result.class);
-//// Result eResult = create(daoResult);
-////
-//// Choice eChoice = poll.getChoiceByTopiaId(choice.getIdChoice());
-////
-//// poll.addResult(eResult);
-////
-//// eResult.setName(eChoice.getName());
-//// eResult.setByGroup(result.isByGroup());
-//// eResult.setPoll(poll);
-//// eResult.setResultValue(String.valueOf(choice.getValue()));
-//// eResult.setVoteCountingType(result.getTypeVoteCounting());
-//// }
-//
-// // Conversion et trie des résultats
-// List<PollResult> list = createPollResults(poll);
-//
-// VoteCountingType voteCountingType = poll.getVoteCountingType();
-//
-// Iterator<PollResult> it = list.iterator();
-// while (it.hasNext()) {
-// PollResult currentResult = it.next();
-//
-// // Cas d'un dépouillement particulier
-// // Suppression des resultats qui ne sont pas de se dépouillement
-// if (voteCounting != null
-// && currentResult.getVoteCountingType() != voteCounting) {
-// it.remove();
-// }
-//
-// // Cas d'un sondage de type GROUP avec filtre
-// if (byGroup) {
-//
-// // Filtre group : Suppression resultats non group
-// if (groupOnly && !currentResult.isByGroup()) {
-// it.remove();
-// }
-//
-// // Filtre non group : Suppression resultats group
-// else if (!groupOnly && currentResult.isByGroup()) {
-// it.remove();
-// }
-//
-// // Suppression des autres resultats de depouillements differents
-// if (currentResult.getVoteCountingType() != voteCountingType) {
-// it.remove();
-// }
-// }
-// }
-//
-// PollResultList resultListDTO = new PollResultList();
-// resultListDTO.setPollResults(list);
-// resultListDTO.setVoteCountingResult(null);
-//
-// return resultListDTO;
-// }
-//
-// public String exportPoll(String pollId) {
-// TopiaContext transaction = getTransaction();
-// try {
-//
-// // Recherche du sondage
-// PollDAO daoPoll = PollenDAOHelper.getPollDAO(transaction);
-// Poll ePoll = daoPoll.findByPollId(pollId);
-//
-// // Dépouillement du sondage.
-// DataResultConverter converter = new DataResultConverter(transaction);
-// PollDTO dto = DataVoteCountingConverter
-// .createPollDTOForVoteCounting(ePoll);
-//
-// ePoll.clearResult();
-//
-// ServiceVoteCounting service = new ServiceVoteCountingImpl();
-// List<VoteCountingResultDTO> results = new ArrayList<VoteCountingResultDTO>();
-// VoteCountingResultDTO result = service.executeVoteCounting(dto);
-// converter.populateResultEntities(result);
-// results.add(result);
-//
-// if (EnumController.isGroupType(ePoll)) {
-// VoteCountingResultDTO groupResult = service
-// .executeGroupCounting(dto);
-// converter.populateResultEntities(groupResult);
-// results.add(groupResult);
-// }
-//
-// // Transformation du sondage
-// PollExportDTO pollExport = new PollExportDTO();
-// pollExport.setPollId(pollId);
-// pollExport.setPoll(dto);
-// pollExport.setVoteCountingResults(results);
-//
-// // Export du sondage
-// ServiceExport serviceExport = new ServiceExportImpl();
-// String filename = serviceExport.executeExport(pollExport);
-//
-// if (log.isInfoEnabled()) {
-// log.info("Poll exported: " + pollId);
-// }
-//
-// return filename;
-// } catch (Exception e) {
-// throw new PollenTechnicalException("Could not export results", e);
-// }
-// }
-
// public String importPoll(String filePath) {
// return importPoll(filePath, null);
// }
@@ -588,31 +480,31 @@
// return topiaId;
// }
-// /**
-// * Retourne une chaîne contenant les résultats du sondage.
-// *
-// * @param poll le sondage
-// * @param results les résultats du sondage
-// * @return les résultats sous forme de chaine de caractères
-// */
-// public String getResultsAsString(Poll poll, Collection<Result> results) {
-//
-// DateFormat dateFormat = new SimpleDateFormat();
-// StringBuilder res = new StringBuilder("");
-// Iterator<Result> it = results.iterator();
-// while (it.hasNext()) {
-// Result result = it.next();
-// if (poll.getChoiceType() == ChoiceType.DATE) {
-// Date date = new Date(Long.parseLong(result.getName()));
-// res.append(dateFormat.format(date));
-// } else {
-// res.append(result.getName());
-// }
-// res.append("=").append(removeTrailing0(result.getResultValue()));
-// if (it.hasNext()) {
-// res.append(", ");
-// }
-// }
-// return res.toString();
-// }
+ /**
+ * Retourne une chaîne contenant les résultats du sondage.
+ *
+ * @param poll le sondage
+ * @param results les résultats du sondage
+ * @return les résultats sous forme de chaine de caractères
+ */
+ public String getResultsAsString(Poll poll, Collection<Result> results) {
+
+ DateFormat dateFormat = new SimpleDateFormat();
+ StringBuilder res = new StringBuilder("");
+ Iterator<Result> it = results.iterator();
+ while (it.hasNext()) {
+ Result result = it.next();
+ if (poll.getChoiceType() == ChoiceType.DATE) {
+ Date date = new Date(Long.parseLong(result.getName()));
+ res.append(dateFormat.format(date));
+ } else {
+ res.append(result.getName());
+ }
+ res.append("=").append(removeTrailing0(result.getResultValue()));
+ if (it.hasNext()) {
+ res.append(", ");
+ }
+ }
+ return res.toString();
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -34,7 +34,6 @@
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceDAO;
-import org.chorem.pollen.business.persistence.Comment;
import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.PersonToListDAO;
import org.chorem.pollen.business.persistence.Poll;
@@ -46,7 +45,6 @@
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteDAO;
-import org.chorem.pollen.business.persistence.VoteToChoice;
import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.common.ChoiceType;
@@ -55,13 +53,6 @@
import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.exceptions.PollVoteNotFoundException;
-import org.chorem.pollen.votecounting.business.NumberMethod;
-import org.chorem.pollen.votecounting.dto.CommentDTO;
-import org.chorem.pollen.votecounting.dto.PollChoiceDTO;
-import org.chorem.pollen.votecounting.dto.PollDTO;
-import org.chorem.pollen.votecounting.dto.VoteToChoiceDTO;
-import org.chorem.pollen.votecounting.dto.VotingGroupDTO;
-import org.chorem.pollen.votecounting.dto.VotingPersonDTO;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.web.struts2.FilterPagerUtil;
@@ -82,11 +73,6 @@
/** Logger. */
private static final Log log = LogFactory.getLog(PollService.class);
-
- /** Représente l'action qui envoi un email de notification. */
- public static final String RULE_EMAIL_ACTION = "emailAction";
-
-
/**
* Build a new Poll instance with given {@code user} as administrator
*
@@ -261,12 +247,13 @@
commitTransaction("Could not create poll " + poll.getTitle());
String pollVoteUrl = getPollVoteUrl(poll);
+ String pollEditUrl = getPollEditUrl(poll);
// email notification
EmailService emailService = newService(EmailService.class);
emailService.onPollCreated(poll,
pollVoteUrl,
- getPollEditUrl(poll));
+ pollEditUrl);
// feed notification
PollFeedService pollFeedService = newService(PollFeedService.class);
@@ -295,21 +282,7 @@
url.append(':').append(poll.getCreator().getAccountId());
return url.toString();
}
- /*
- private void addFeedEntry() {
- PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId());
- String voteURL = siteURL + "poll/votefor/" + poll.getPollId();
- File feedFile = feedContext.getFile(poll.getPollId());
- FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
- "pollFeed_title", poll.getTitle()), siteURL, messages.format(
- "pollFeed_desc", poll.getDescription()));
- FeedUtil.feedFeed(feedFile, messages.format("pollFeed_createTitle",
- creator.getVotingId()), voteURL, messages
- .get("pollFeed_createContent"));
- }
- */
-
public List<Poll> getPolls(FilterPagerUtil.FilterPagerBean pager) {
Preconditions.checkNotNull(pager);
@@ -331,7 +304,8 @@
}
}
- public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) {
+ public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
@@ -354,13 +328,15 @@
}
}
- public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) {
+ public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
UserService userService = newService(UserService.class);
- UserAccount userToUse = userService.getEntityById(UserAccount.class, user.getTopiaId());
+ UserAccount userToUse = userService.getEntityById(UserAccount.class,
+ user.getTopiaId());
//FIXME Use a query to do this to avoid in memory pagination
String email = userToUse.getEmail();
@@ -423,22 +399,6 @@
UserAccount userToUse =
userService.getEntityById(UserAccount.class, user.getTopiaId());
-// List<Poll> allPolls = Lists.newArraPagerUtil.computeRecordIndexesAndPagesNumber(pager);yList();
-// for (PollAccount pollAccount : userToUse.getPollAccount()) {
-// for (Vote vote : pollAccount.getVote()) {
-// Poll poll = vote.getPoll();
-// if (!allPolls.contains(poll)) {
-// allPolls.add(poll);
-// }
-// }
-// }
-// int records = allPolls.size();
-// pager.setRecords(records);
-// PagerUtil.computeRecordIndexesAndPagesNumber(pager);
-// List<Poll> result = FilterPagerUtil.getPageFromList(allPolls, pager);
-// return result;
-
-
PollDAO pollDao = getDAO(Poll.class);
VoteDAO voteDao = getDAO(Vote.class);
@@ -454,10 +414,6 @@
TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery, pager);
-// query.addDistinct();
-// query.setSelect("e." + Vote.PROPERTY_POLL);
-// query.addWhere("e." + Vote.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, userToUse);
-
List<Poll> result = pollDao.findAllByQuery(query);
return result;
} catch (TopiaException e) {
@@ -609,111 +565,6 @@
}
}
- public PollDTO createPollDTOForVoteCounting(Poll poll) {
- PollDTO result = new PollDTO(poll.getPollId());
- result.setTitle(poll.getTitle());
- result.setDescription(poll.getDescription());
- result.setBeginChoiceDate(poll.getBeginChoiceDate());
- result.setBeginDate(poll.getBeginDate());
- result.setEndDate(poll.getEndDate());
- result.setAnonymous(poll.isAnonymous());
- result.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed());
- result.setPublicResults(poll.isPublicResults());
- result.setContinuousResults(poll.isContinuousResults());
- result.setChoiceAddAllowed(poll.isChoiceAddAllowed());
- result.setClosed(poll.isClosed());
- result.setCreatorId(poll.getCreator().getVotingId());
- result.setCreatorEmail(poll.getCreator().getEmail());
- result.setMaxChoiceNb(poll.getMaxChoiceNb());
- result.setPollType(poll.getPollType());
- result.setChoiceType(poll.getChoiceType());
- result.setVoteCounting(poll.getVoteCountingType());
-
- for (Comment comment : poll.getComment()) {
- result.getComments().add(createPollCommentDTO(comment));
- }
- for (Choice choice : poll.getChoice()) {
- result.getChoices().add(createPollChoiceDTO(choice));
- }
- if (poll.getVotingList() != null && !poll.getVotingList().isEmpty()) {
- for (VotingList list : poll.getVotingList()) {
- result.getVotingGroups().add(createVotingGroupDTO(list));
- }
- } else {
- // un groupe par défaut si il y en a pas
- VotingGroupDTO group = new VotingGroupDTO("unique", 1);
- group.setName("unique");
- for (Vote vote : poll.getVote()) {
- group.getVotingPersons().add(createVotingPersonDTO(vote));
- }
- result.getVotingGroups().add(group);
- }
- return result;
- }
-
- private CommentDTO createPollCommentDTO(Comment comment) {
- CommentDTO commentDTO = new CommentDTO(
- comment.getPollAccount().getVotingId(), comment.getText());
- return commentDTO;
- }
-
- private PollChoiceDTO createPollChoiceDTO(Choice choice) {
- PollChoiceDTO choiceDTO = new PollChoiceDTO(choice.getTopiaId());
- String choiceName = choice.getName();
- choiceDTO.setName(choiceName);
- choiceDTO.setHidden(choiceName != null &&
- choiceName.startsWith(NumberMethod.HIDDEN_PREFIX));
- choiceDTO.setDescription(choice.getDescription());
- return choiceDTO;
- }
-
- private VotingGroupDTO createVotingGroupDTO(VotingList list) {
- VotingGroupDTO group = new VotingGroupDTO(list.getTopiaId(), list
- .getWeight());
- group.setName(list.getName());
-
- for (PersonToList pToList : list.getPollAccountPersonToList()) {
- Vote vote = getPollVoteByPollAccount(list.getPoll(), pToList
- .getPollAccount());
- if (vote != null) {
- // Pas de vote pour cette personne : doit engendrer erreur ?!?
- group.getVotingPersons().add(createVotingPersonDTO(vote));
- }
- }
- return group;
- }
-
- private VotingPersonDTO createVotingPersonDTO(Vote vote) {
- VotingPersonDTO votingPerson = new VotingPersonDTO(vote
- .getPollAccount().getVotingId(), vote.getWeight());
- votingPerson.setEmail(vote.getPollAccount().getEmail());
-
- for (VoteToChoice vToChoice : vote.getChoiceVoteToChoice()) {
- if (vToChoice != null && vToChoice.getChoice() != null) {
- votingPerson.getChoices().add(createVoteToChoiceDTO(vToChoice));
- }
- }
- return votingPerson;
- }
-
- private VoteToChoiceDTO createVoteToChoiceDTO(VoteToChoice vToChoice) {
- String topiaId = vToChoice.getChoice().getTopiaId();
- VoteToChoiceDTO vote = new VoteToChoiceDTO(topiaId, vToChoice
- .getVoteValue());
-
- return vote;
- }
-
- /* A Deplacer au bon endroit (PollImpl) si c'est possible */
- private static Vote getPollVoteByPollAccount(Poll poll, PollAccount account) {
- for (Vote vote : poll.getVote()) {
- if (account.getTopiaId().equals(vote.getPollAccount().getTopiaId())) {
- return vote;
- }
- }
- return null;
- }
-
public File getPollChoiceImageFile(String pollId,
String choiceId,
boolean thumb) {
@@ -742,9 +593,12 @@
String location = choice.getLocation();
- File pollChoiceImage = getPollChoiceImageFile(poll.getPollId(), choice.getName(), false);
- File pollChoiceImageThumb = getPollChoiceImageFile(poll.getPollId(), choice.getName(), true);
+ String pollId = poll.getPollId();
+ String name = choice.getName();
+ File pollChoiceImage = getPollChoiceImageFile(pollId, name, false);
+ File pollChoiceImageThumb = getPollChoiceImageFile(pollId, name, true);
+
FileUtils.copyFile(new File(location), pollChoiceImage);
createThumbnail(pollChoiceImage, pollChoiceImageThumb, 100);
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -28,7 +28,6 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PreventRule;
-import org.chorem.pollen.business.persistence.PreventRuleDAO;
import org.chorem.pollen.services.PollenServiceSupport;
import java.util.Date;
@@ -45,8 +44,7 @@
private static final Log log = LogFactory.getLog(PreventRuleService.class);
public PreventRule createAddVotePreventRule() {
- PreventRuleDAO dao = getDAO(PreventRule.class);
- PreventRule rule = newInstance(dao);
+ PreventRule rule = newInstance(getDAO(PreventRule.class));
rule.setScope("vote");
rule.setSensibility(1);
rule.setRepeated(true);
@@ -54,8 +52,7 @@
}
public PreventRule createRemindPreventRule(int sensibility) {
- PreventRuleDAO dao = getDAO(PreventRule.class);
- PreventRule rule = newInstance(dao);
+ PreventRule rule = newInstance(getDAO(PreventRule.class));
rule.setScope("rappel");
rule.setSensibility(sensibility);
rule.setRepeated(false);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -44,12 +44,9 @@
import org.nuiton.util.beans.Binder;
import org.nuiton.web.struts2.FilterPagerUtil;
-import java.net.URL;
import java.util.List;
-import java.util.Locale;
import static org.nuiton.i18n.I18n._;
-import static org.nuiton.i18n.I18n.l_;
public class UserService extends PollenServiceSupport {
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -47,114 +47,103 @@
/** Logger. */
private static final Log log = LogFactory.getLog(VoteService.class);
- public String createVote(Vote vote, PollAccount pollAccount) {
- TopiaContext transaction = getTransaction();
+ public void createVote(Vote vote, PollAccount pollAccount) {
- String topiaId;
- try {
-
- // création du compte associé au vote s'il n'existe pas
- // sinon mise à jour du compte
- //ServicePollAccount spa = new ServicePollAccountImpl();
- if (pollAccount == null) {
- vote.setPollAccount(null);
- } else {
+ // création du compte associé au vote s'il n'existe pas
+ // sinon mise à jour du compte
+ //ServicePollAccount spa = new ServicePollAccountImpl();
+ if (pollAccount == null) {
+ vote.setPollAccount(null);
+ } else {
// pollAccount.setHasVoted(true);
- PollAccountDAO pollAccountDAO =
- PollenDAOHelper.getPollAccountDAO(transaction);
+ PollAccountDAO pollAccountDAO =
+ getDAO(PollAccount.class);
- PollAccount pollAccountEntity =
- pollAccountDAO.findByTopiaId(pollAccount.getTopiaId());
+ PollAccount pollAccountEntity =
+ getEntityById(PollAccount.class, pollAccount.getTopiaId());
// PollAccountDTO account = spa.findPollAccountById(pollAccountDTO
// .getId());
- if (pollAccountEntity == null) {
- log.debug("Nouveau compte associé au vote");
- pollAccountEntity = pollAccountDAO.create();
+ if (pollAccountEntity == null) {
+ log.debug("Nouveau compte associé au vote");
+ pollAccountEntity = create(pollAccountDAO);
// voteDTO.setPollAccountId(spa
// .createPollAccount(pollAccountDTO));
- } else {
- log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId());
- //spa.updatePollAccount(pollAccountDTO);
- //voteDTO.setPollAccountId(account.getId());
+ } else {
+ log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId());
+ //spa.updatePollAccount(pollAccountDTO);
+ //voteDTO.setPollAccountId(account.getId());
- }
- // Fill pollAccountEntity from DTO in argument
+ }
+ // Fill pollAccountEntity from DTO in argument
// DataPollAccountConverter pollAccountConverter = new DataPollAccountConverter();
// pollAccountConverter.setTransaction(transaction);
// pollAccountConverter.populatePollAccountEntity(pollAccountDTO,
// pollAccountEntity);
- // Update pollAccountEntity
- pollAccountDAO.update(pollAccountEntity);
+ // Update pollAccountEntity
+// pollAccountDAO.update(pollAccountEntity);
- vote.setPollAccount(pollAccountEntity);
+ vote.setPollAccount(pollAccountEntity);
// vote.setVotingListId(pollAccount.getVotingListId());
// vote.setWeight(pollAccount.getWeight());
- log.debug("Poids du vote : " + vote.getWeight());
- }
+ log.debug("Poids du vote : " + vote.getWeight());
+ }
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = getDAO(Vote.class);
- Vote voteEntity = voteDAO.create();
+ Vote voteEntity = create(voteDAO);
// converter.setTransaction(transaction);
// converter.populateVoteEntity(vote, voteEntity);
// converter.populateChoiceVote(vote, voteEntity);
- topiaId = voteEntity.getTopiaId();
- if (log.isDebugEnabled()) {
- log.debug("Entity created: " + topiaId);
- }
-
- return topiaId;
- } catch (Exception e) {
- throw new PollenTechnicalException("Could not obtain votes", e);
+ if (log.isDebugEnabled()) {
+ log.debug("Entity created: " + voteEntity.getTopiaId());
}
+
+ commitTransaction("Could not create vote");
+
+ // email notification
+
+ // feed notification
+
+
}
- public boolean updateVote(Vote vote) {
- TopiaContext transaction = getTransaction();
- try {
+ public void updateVote(Vote vote) throws VoteNotFoundException {
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
- Vote voteEntity = voteDAO.findByTopiaId(vote.getTopiaId());
+ Vote entityToUpdate = getEntityById(Vote.class, vote.getTopiaId());
+
+ if (entityToUpdate == null) {
+ throw new VoteNotFoundException();
+ }
// converter.setTransaction(transaction);
// converter.populateVoteEntity(voteDTO, voteEntity);
- voteDAO.update(voteEntity);
- if (log.isDebugEnabled()) {
- log.debug("Entity updated: " + vote.getTopiaId());
- }
-
- return true;
- } catch (Exception e) {
- throw new PollenTechnicalException("Could not update vote", e);
+ if (log.isDebugEnabled()) {
+ log.debug("Entity updated: " + vote.getTopiaId());
}
+ commitTransaction("Could not update vote");
+
}
- public boolean deleteVote(String voteId) {
- TopiaContext transaction = getTransaction();
- try {
+ public void deleteVote(String voteId) throws VoteNotFoundException {
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
- Vote voteEntity = voteDAO.findByTopiaId(voteId);
+ Vote entityToDelete = getEntityById(Vote.class, voteId);
- if (voteEntity == null) {
- throw new VoteNotFoundException();
- }
+ if (entityToDelete == null) {
+ throw new VoteNotFoundException();
+ }
- voteDAO.delete(voteEntity);
+ delete(getDAO(Vote.class), entityToDelete);
- if (log.isDebugEnabled()) {
- log.debug("Entity deleted: " + voteId);
- }
-
- return true;
- } catch (Exception e) {
- throw new PollenTechnicalException("Could not obtain votes", e);
+ if (log.isDebugEnabled()) {
+ log.debug("Entity deleted: " + voteId);
}
+
+ commitTransaction("Could not delete vote");
}
public List<Vote> getVotesByPoll(Poll poll,
1
0