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
- 3196 discussions
02 Jun '10
Author: fdesbois
Date: 2010-06-02 17:08:28 +0200 (Wed, 02 Jun 2010)
New Revision: 3025
Url: http://chorem.org/repositories/revision/pollen/3025
Log:
Change some queries using Join + tests
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-business/src/main/xmi/pollen.properties
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
trunk/pollen-business/src/test/resources/PollenTest.properties
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsCreated.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -49,7 +49,7 @@
* @param element
* @param collection
* @return the TopiaQuery created
- * @see #prepareQuery(TopiaQuery, Filter, EntityQueryProperty)
+ * @see #prepareQuery(TopiaQuery, Filter, String, EntityQueryProperty)
*/
public static TopiaQuery createQueryFindElementsByCollection(
EntityQueryProperty element,
@@ -69,21 +69,25 @@
if (filter != null) {
// Add constraints from filter, the collection is given to provide
// the name of its ID property.
- prepareQuery(query, filter, collection);
+ prepareQuery(query, filter, null, collection);
}
return query;
}
+ public static void prepareQuery(TopiaQuery query, Filter filter) {
+ prepareQuery(query, filter, null, null);
+ }
+
/**
* Prepare a query with filter : adding startIndex and endIndex as limit
* and orderBy if defined. Need an existing query in builder.
*
* @param filter Filter to add in the query
- * @see #prepareQuery(TopiaQuery, Filter, EntityQueryProperty)
+ * @see #prepareQuery(TopiaQuery, Filter, String, EntityQueryProperty)
*/
- public static void prepareQuery(TopiaQuery query, Filter filter) {
- prepareQuery(query, filter, null);
+ public static void prepareQuery(TopiaQuery query, Filter filter, String mainAlias) {
+ prepareQuery(query, filter, mainAlias, null);
}
/**
@@ -95,15 +99,19 @@
* @param reference used to filter on referenceId
*/
public static void prepareQuery(TopiaQuery query, Filter filter,
- EntityQueryProperty reference) {
+ String mainAlias,
+ EntityQueryProperty reference) {
Integer startIndex = filter.getStartIndex();
Integer endIndex = filter.getEndIndex();
String orderBy = filter.getOrderBy();
String referenceId = filter.getReferenceId();
+ if (mainAlias == null) {
+ mainAlias = query.getMainAlias();
+ }
EntityQueryProperty mainProperty =
- getEntityQueryProperty(query.getMainAlias());
+ getEntityQueryProperty(mainAlias);
if (log.isDebugEnabled()) {
log.debug("Filter added to the query : " +
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -17,19 +17,22 @@
@Override
public TopiaQuery createQueryFindAllByPoll(Filter filter) {
- EntityQueryProperty accountProperty =
- PollenUtils.getEntityQueryProperty(PollAccount.class, "A");
+ String pollAlias = "P";
+ String pollAccountProperty =
+ TopiaQuery.getProperty(pollAlias, Poll.POLL_ACCOUNT);
- EntityQueryProperty pollProperty =
- PollenUtils.getEntityQueryProperty(Poll.class, "P");
+ String participantAlias = "A";
+ String participantVoteDateProperty =
+ TopiaQuery.getProperty(participantAlias, PollAccount.VOTE_DATE);
- pollProperty.setPropertyJoin(Poll.POLL_ACCOUNT);
+ // Will return lists in case of GROUP poll
+ TopiaQuery query = new TopiaQuery(Poll.class, pollAlias).
+ setSelect(participantAlias).
+ addJoin(pollAccountProperty, participantAlias, false).
+ addNotNull(participantVoteDateProperty);
- TopiaQuery query = PollenUtils.createQueryFindElementsByCollection(
- accountProperty, pollProperty, filter);
+ PollenUtils.prepareQuery(query, filter, participantAlias);
- query.addNotNull(accountProperty.nameProperty(PollAccount.VOTE_DATE));
-
return query;
}
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -28,11 +28,13 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaEntity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -297,29 +299,99 @@
throws TopiaException {
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
+ Map<PollAccount, Poll> polls = new LinkedHashMap<PollAccount, Poll>();
- TopiaQuery query = dao.createQuery("P").addDistinct().
- addFrom(PollAccount.class, "A").
- addFrom(PollAccount.class, "G").
- addInElements("G", "P." + Poll.POLL_ACCOUNT).
- addEquals("A." + PollAccount.USER_ACCOUNT, user).
- addWhere("A IN elements (P." + Poll.POLL_ACCOUNT + ") OR " +
- "A IN elements (G." + PollAccount.CHILD + ") OR " +
- "A = P." + Poll.CREATOR);
+ // Property names for poll
+ String pollAlias = "P";
+ String pollCreatorProperty =
+ TopiaQuery.getProperty(pollAlias, Poll.CREATOR);
+ String pollAccountProperty =
+ TopiaQuery.getProperty(pollAlias, Poll.POLL_ACCOUNT);
+ String pollCreateDateProperty =
+ TopiaQuery.getProperty(pollAlias, TopiaEntity.TOPIA_CREATE_DATE);
- Map<PollAccount, Poll> polls = new HashMap<PollAccount, Poll>();
+ // Property names for participant
+ String participantAlias = "A";
+ String participantUserProperty =
+ TopiaQuery.getProperty(participantAlias, PollAccount.USER_ACCOUNT);
- List<Object[]> results = transaction.findByQuery(query.addSelect("A"));
+ // Property names for participant list
+ String listAlias = "G";
+ String listChildProperty =
+ TopiaQuery.getProperty(listAlias, PollAccount.CHILD);
- for (Object[] result : results) {
- Poll poll = (Poll)result[0];
- PollAccount account = (PollAccount)result[1];
- polls.put(account, poll);
- }
+ // ALGO 1 with three queries : can't keep order, need Comparator
+// // Case 1 : creator
+// TopiaQuery queryCreator = dao.createQuery(pollAlias).
+// addSelect(participantAlias).
+// addJoin(pollCreatorProperty, participantAlias).
+// addEquals(participantUserProperty, user);
+//
+// preparePollResults(transaction, queryCreator, polls);
+//
+// // Case 2 : participants (direct accounts)
+// TopiaQuery queryParticipants = dao.createQuery(pollAlias).
+// addSelect(participantAlias).
+// addJoin(pollAccountProperty, participantAlias).
+// addEquals(participantUserProperty, user);
+//
+// preparePollResults(transaction, queryParticipants, polls);
+//
+// // Case 3 : by groups (child accounts)
+// TopiaQuery queryGroups = dao.createQuery(pollAlias).
+// addSelect(participantAlias).
+// addJoin(pollAccountProperty, groupAlias).
+// addJoin(groupChildProperty, participantAlias).
+// addEquals(participantUserProperty, user);
+//
+// preparePollResults(transaction, queryGroups, polls);
+ // ALGO 2 with one query and ordered
+ TopiaQuery query = dao.createQuery(pollAlias).
+ addDistinct().
+ addSelect(participantAlias).
+ addLeftJoin(pollAccountProperty, listAlias, false).
+ addFrom(PollAccount.class, participantAlias).
+ addEquals(participantUserProperty, user).
+ addOrderDesc(pollCreateDateProperty);
+
+ StringBuilder orBuilder = new StringBuilder(participantAlias).
+ // IN poll.pollAccount (NORMAL)
+ append(" IN (").append(listAlias).append(')').
+ append(" OR ").append(participantAlias).
+ // IN poll.pollAccount.child (GROUP)
+ append(" IN elements(").append(listChildProperty).append(')').
+ append(" OR ").append(participantAlias).
+ // = poll.creator (CREATOR)
+ append(" = ").append(pollCreatorProperty);
+
+ query.addWhere(orBuilder.toString());
+
+ log.debug("Query : " + query);
+
+ preparePollResults(transaction, query, polls);
+
return polls;
}
+ protected void preparePollResults(TopiaContext transaction,
+ TopiaQuery query,
+ Map<PollAccount, Poll> results)
+ throws TopiaException {
+
+ List<Object[]> queryResults = transaction.findByQuery(query);
+ for (Object[] row : queryResults) {
+ Poll poll = (Poll)row[0];
+ PollAccount account = (PollAccount)row[1];
+ log.debug("account : " + account.getUid() + " : " +
+ account.getName() +
+ " list(" + account.isList() + ")" +
+ " admin(" + account.isAdmin() + ")" +
+ " for poll " + poll.getTitle());
+ results.put(account, poll);
+ }
+ }
+
@Override
protected List<Comment> executeGetComments(TopiaContext transaction,
Poll poll, int startIndex, int endIndex)
@@ -384,10 +456,18 @@
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
+// TopiaQuery query = dao.createQuery().
+// addLoad(properties).
+// addEquals(Poll.UID, pollUid);
+
TopiaQuery query = dao.createQuery().
- addEquals(Poll.UID, pollUid).
- addLoad(properties);
+ addFetch(properties);
+ String pollUidProperty =
+ TopiaQuery.getProperty(query.getMainAlias(), Poll.UID);
+
+ query.addEquals(pollUidProperty, pollUid);
+
Poll result = dao.findByQuery(query);
if (result == null) {
throw new PollenBusinessException(
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -208,9 +208,9 @@
PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
TopiaQuery query = dao.createQueryFindAllByPoll(filter);
+
+ //query.addLoad(PollAccount.CHOICE_VOTE);
- query.addLoad(PollAccount.CHOICE_VOTE);
-
List<PollAccount> results = dao.findAllByQuery(query);
if (log.isDebugEnabled()) {
Modified: trunk/pollen-business/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-business/src/main/xmi/pollen.properties 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/main/xmi/pollen.properties 2010-06-02 15:08:28 UTC (rev 3025)
@@ -12,7 +12,7 @@
org.chorem.pollen.entity.PollAccount.attribute.uid.tagvalue.naturalId=true
-org.chorem.pollen.entity.Vote.attribute.choice.tagvalue.lazy=false
+#org.chorem.pollen.entity.Vote.attribute.choice.tagvalue.lazy=false
org.chorem.pollen.entity.FavoriteList.attribute.userAccount.tagvalue.naturalId=true
org.chorem.pollen.entity.FavoriteList.attribute.name.tagvalue.naturalId=true
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -4,8 +4,10 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenDAOHelper;
+import org.chorem.pollen.bean.Filter;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.common.VoteCountingType;
import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.Participant;
@@ -16,6 +18,7 @@
import org.chorem.pollen.entity.PollDAO;
import org.chorem.pollen.entity.PollImpl;
import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.entity.Vote;
import org.chorem.pollen.test.AbstractServiceTest;
import org.junit.Assert;
import org.junit.Test;
@@ -332,18 +335,69 @@
}
@Test
- public void testGetPollsByUser2() throws PollenBusinessException, TopiaException {
+ public void testGetPollsByUser() throws PollenBusinessException, TopiaException {
- poll = createGroupPoll("POLL", user, null, 3, "group1", "group2");
+ createGroupPoll("POLL", user, null, 3, "group1", "group2");
+ Poll freePoll = createFreePoll("POLL2", user, null);
+
+ PollAccount participant = getServiceVote().getNewPollAccount(user);
+ participant.setChoiceVote(new ArrayList<Vote>());
+
+ getServiceVote().saveVote(freePoll, participant);
+
+
/** EXEC METHOD **/
Map<PollAccount, Poll> polls = servicePoll.getPollsByUser(user);
- for (Map.Entry<PollAccount, Poll> poll : polls.entrySet()) {
- log.debug("Poll : " + poll.getValue().getTitle());
- log.debug("Account : " + poll.getKey().getName() +
- " admin (" + poll.getKey().isAdmin() + ")");
+ // POLL 2 : user both creator and participant (+2)
+ // POLL : user creator + added in each group (+3)
+
+ Assert.assertEquals(5, polls.size());
+ }
+
+ @Test
+ public void testFetchOnGetter() throws TopiaException, PollenBusinessException {
+
+ poll = createFreePoll("POLL2", user, VoteCountingType.NORMAL);
+ List<Choice> choices =
+ addChoicesToPoll(poll, ChoiceType.TEXT, "choice1", "choice2", "choice3");
+
+ PollAccount participant = getServiceVote().getNewPollAccount(user);
+ Vote voteImpl = getServiceVote().getNewVote(choices.get(0));
+ voteImpl.setVoteValue(1.);
+ participant.addChoiceVote(voteImpl);
+ voteImpl = getServiceVote().getNewVote(choices.get(1));
+ voteImpl.setVoteValue(1.);
+ participant.addChoiceVote(voteImpl);
+ voteImpl = getServiceVote().getNewVote(choices.get(2));
+ voteImpl.setVoteValue(1.);
+ participant.addChoiceVote(voteImpl);
+
+ getServiceVote().saveVote(poll, participant);
+
+ poll = loadEntity(poll);
+
+ /** EXEC METHOD **/
+
+ Poll pollFound = servicePoll.getPoll(poll.getUid(), Poll.CHOICE);
+
+ Filter filter = new Filter();
+ filter.setReference(pollFound);
+ List<PollAccount> accounts = getServiceVote().getVotes(filter);
+
+ for (PollAccount account : accounts) {
+ log.debug("Account : " + account.getUid());
}
-
+ Assert.assertEquals(1, accounts.size());
+
+ Assert.assertNotNull(accounts.get(0).getChoiceVote());
+ Assert.assertEquals(3, accounts.get(0).getChoiceVote().size());
+
+ for (Vote vote : accounts.get(0).getChoiceVote()) {
+ log.debug("Vote choice : " + vote.getChoice().getName() +
+ " value=" + vote.getVoteValue());
+ }
+
}
}
Modified: trunk/pollen-business/src/test/resources/PollenTest.properties
===================================================================
--- trunk/pollen-business/src/test/resources/PollenTest.properties 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-business/src/test/resources/PollenTest.properties 2010-06-02 15:08:28 UTC (rev 3025)
@@ -1,5 +1,5 @@
hibernate.hbm2ddl.auto=create
-hibernate.show_sql=false
+hibernate.show_sql=true
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.connection.username=sa
hibernate.connection.password=
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -594,7 +594,7 @@
public String getParticipantNameStyle() {
if (!participant.isAnonymous() &&
- participant.getName().equals(getPollAccount().getName())) {
+ participant.getUid().equals(getPollAccount().getUid())) {
return "selected";
}
return evenOdd.getNext();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsCreated.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsCreated.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsCreated.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -105,7 +105,7 @@
public void onActivate() {
super.onActivate();
if (isUserConnected()) {
- polls = servicePoll.getPollsByUser(getUserConnected());
+ //polls = servicePoll.getPollsByUser(getUserConnected());
}
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-06-02 10:31:35 UTC (rev 3024)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-06-02 15:08:28 UTC (rev 3025)
@@ -87,8 +87,7 @@
public void onActivate() {
super.onActivate();
if (isUserConnected()) {
- invitedPolls = participatedPolls = servicePoll.getPollsByUser(
- getUserConnected());
+ //invitedPolls = participatedPolls = servicePoll.getPollsByUser(getUserConnected());
// invitedPolls = servicePoll.findInvitedPolls(user.getId());
}
}
1
0
Author: tchemit
Date: 2010-06-02 12:31:35 +0200 (Wed, 02 Jun 2010)
New Revision: 3024
Url: http://chorem.org/repositories/revision/pollen/3024
Log:
Utilisation de mavenpom4redmine 2.1.5
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-02 10:05:36 UTC (rev 3023)
+++ trunk/pom.xml 2010-06-02 10:31:35 UTC (rev 3024)
@@ -1,7 +1,5 @@
<?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">
+<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>
@@ -12,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.1.3</version>
+ <version>2.1.5</version>
</parent>
<groupId>org.chorem</groupId>
1
0
r3023 - in trunk/pollen-business/src: main/java/org/chorem/pollen main/java/org/chorem/pollen/service main/xmi test/java/org/chorem/pollen/service test/java/org/chorem/pollen/test
by fdesbois@users.chorem.org 02 Jun '10
by fdesbois@users.chorem.org 02 Jun '10
02 Jun '10
Author: fdesbois
Date: 2010-06-02 12:05:36 +0200 (Wed, 02 Jun 2010)
New Revision: 3023
Url: http://chorem.org/repositories/revision/pollen/3023
Log:
Implement getPollsByUser
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java 2010-06-01 14:06:41 UTC (rev 3022)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java 2010-06-02 10:05:36 UTC (rev 3023)
@@ -168,6 +168,11 @@
return nameProperty(propertyJoin);
}
+ public String namePropertyForJoin(String collectionProperty,
+ EntityQueryProperty elementProperty) {
+ return nameProperty(collectionProperty) + " as " + elementProperty.name();
+ }
+
/**
* Get the entityClass associated with this EntityQueryProperty. Can be
* useful in some case, to create other query for exemple or to use it in
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-06-01 14:06:41 UTC (rev 3022)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-06-02 10:05:36 UTC (rev 3023)
@@ -1,12 +1,15 @@
package org.chorem.pollen.service;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.EntityQueryProperty;
import org.chorem.pollen.PollenBinderHelper;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
+import org.chorem.pollen.PollenUtils;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
@@ -28,7 +31,10 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* ServicePoll
@@ -43,6 +49,8 @@
*/
public class ServicePollImpl extends ServicePollAbstract {
+ private static final Log log = LogFactory.getLog(ServicePollImpl.class);
+
private PollenContext context;
public void setContext(PollenContext context) {
@@ -284,9 +292,32 @@
}
@Override
- protected List<Poll> executeGetPollsByUser(TopiaContext transaction,
- UserAccount user) throws TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
+ protected Map<PollAccount, Poll> executeGetPollsByUser(TopiaContext transaction,
+ UserAccount user)
+ throws TopiaException {
+
+ PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
+
+ TopiaQuery query = dao.createQuery("P").addDistinct().
+ addFrom(PollAccount.class, "A").
+ addFrom(PollAccount.class, "G").
+ addInElements("G", "P." + Poll.POLL_ACCOUNT).
+ addEquals("A." + PollAccount.USER_ACCOUNT, user).
+ addWhere("A IN elements (P." + Poll.POLL_ACCOUNT + ") OR " +
+ "A IN elements (G." + PollAccount.CHILD + ") OR " +
+ "A = P." + Poll.CREATOR);
+
+ Map<PollAccount, Poll> polls = new HashMap<PollAccount, Poll>();
+
+ List<Object[]> results = transaction.findByQuery(query.addSelect("A"));
+
+ for (Object[] result : results) {
+ Poll poll = (Poll)result[0];
+ PollAccount account = (PollAccount)result[1];
+ polls.put(account, poll);
+ }
+
+ return polls;
}
@Override
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-06-01 14:06:41 UTC (rev 3022)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-06-02 10:05:36 UTC (rev 3023)
@@ -2,9 +2,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.Participant;
import org.chorem.pollen.entity.ParticipantList;
@@ -18,10 +20,12 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
/**
* Created: 14 mai 2010
@@ -62,6 +66,7 @@
poll.setCreator(creator);
poll.setTitle("Poll");
poll.setUid(context.createPollenUrlId());
+ poll.setChoice(new ArrayList<Choice>());
// Participant Lists
// First list : new list specific for poll restriction
@@ -325,4 +330,20 @@
transaction.closeContext();
}
}
+
+ @Test
+ public void testGetPollsByUser2() throws PollenBusinessException, TopiaException {
+
+ poll = createGroupPoll("POLL", user, null, 3, "group1", "group2");
+
+ /** EXEC METHOD **/
+ Map<PollAccount, Poll> polls = servicePoll.getPollsByUser(user);
+
+ for (Map.Entry<PollAccount, Poll> poll : polls.entrySet()) {
+ log.debug("Poll : " + poll.getValue().getTitle());
+ log.debug("Account : " + poll.getKey().getName() +
+ " admin (" + poll.getKey().isAdmin() + ")");
+ }
+
+ }
}
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-06-01 14:06:41 UTC (rev 3022)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-06-02 10:05:36 UTC (rev 3023)
@@ -354,6 +354,9 @@
participant.setName(groupName + "_participant" + i);
participant.setEmail(groupName + "_email" + i + "@domain.org");
participant.setWeight(1.);
+ if (i == 1) {
+ participant.setUserAccount(user);
+ }
group.addChild(participant);
}
1
0
Author: fdesbois
Date: 2010-06-01 16:06:41 +0200 (Tue, 01 Jun 2010)
New Revision: 3022
Url: http://chorem.org/repositories/revision/pollen/3022
Log:
Vote is working. Creator can also delete votes. (only tested for free poll)
Modified:
trunk/doc/business-rules.rst
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenBusinessException.java
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
trunk/pollen-ui/src/main/webapp/css/common.css
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
Modified: trunk/doc/business-rules.rst
===================================================================
--- trunk/doc/business-rules.rst 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/doc/business-rules.rst 2010-06-01 14:06:41 UTC (rev 3022)
@@ -139,7 +139,7 @@
- Ajout d'un vote : pollUri = pollUid / participantUid (RESTRICTED/GROUP) ou null (FREE)
- Modification d'un vote : pollUri = pollUid / participantUid ou ADMIN
-- Suppression d'un vote : pollUri = pollUid / participantUid ou creatorUid ou ADMIN
+- Suppression d'un vote : pollUri = pollUid / creatorUid ou ADMIN
- Ajout d'un choix : même chose que pour l'ajout d'un vote
- Suppression d'un choix : pollUri = pollUid / creatorUid ou ADMIN
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenBusinessException.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenBusinessException.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenBusinessException.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -69,7 +69,15 @@
* Exception when doubloons ($2) are found when adding participants in a
* list ($1).
*/
- PARTICIPANT_DOUBLOONS(n_("pollen.exception.participant_doubloons"));
+ PARTICIPANT_DOUBLOONS(n_("pollen.exception.participant_doubloons")),
+ /**
+ * Exception when doubloon are found on vote name ($1)
+ */
+ VOTE_DOUBLOON(n_("pollen.exception.vote_doubloon")),
+ /**
+ * Exception when participant with uid ($1) can't vote
+ */
+ VOTE_NOT_ALLOWED(n_("pollen.exception.vote_not_allowed"));
private String message;
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -360,16 +360,12 @@
return UUID.randomUUID().toString().replaceAll("-", "");
}
-// public void setCurrentDate(Date currentDate) {
-// PollenContextBusiness.currentDate = currentDate;
-// }
-
@Override
public Date getCurrentDate() {
- if (currentDate == null) {
- currentDate = new Date();
+ if (currentDate != null) {
+ return currentDate;
}
- return currentDate;
+ return new Date();
}
/**
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -1,9 +1,11 @@
package org.chorem.pollen.service;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.EntityQueryProperty;
import org.chorem.pollen.PollenBinderHelper;
+import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
@@ -15,6 +17,7 @@
import org.chorem.pollen.entity.PollAccountDAO;
import org.chorem.pollen.entity.PollAccountImpl;
import org.chorem.pollen.entity.PollDAO;
+import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.Vote;
import org.chorem.pollen.entity.VoteDAO;
import org.chorem.pollen.entity.VoteImpl;
@@ -107,6 +110,9 @@
log.info("Poll is no longer running... Participant can't vote");
}
result = false;
+ // Creator can't vote
+ } else if (poll.getCreator().equals(participant)) {
+ return false;
} else if (poll.getPollType().isRestrictedOrGroup()) {
if (log.isInfoEnabled()) {
log.info("Poll is restricted... Participant need to be identified");
@@ -115,38 +121,16 @@
PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
EntityQueryProperty participantProperty =
- PollenUtils.getEntityQueryProperty("A");
+ PollenUtils.getEntityQueryProperty(PollAccount.class, "A");
EntityQueryProperty pollProperty =
- PollenUtils.getEntityQueryProperty("P");
+ PollenUtils.getEntityQueryProperty(Poll.class, "P");
EntityQueryProperty groupProperty =
- PollenUtils.getEntityQueryProperty("G");
+ PollenUtils.getEntityQueryProperty(PollAccount.class, "G");
- TopiaQuery query = dao.createQuery(participantProperty.name()).
- addFrom(Poll.class, pollProperty.name()).
- addEquals(pollProperty.name(), poll);
+ TopiaQuery query = createQueryFindParticipantByPoll(
+ participantProperty, groupProperty, pollProperty, poll);
- // By default the parentCollection is pollAccount in poll
- String parentCollectionProperty =
- pollProperty.nameProperty(Poll.POLL_ACCOUNT);
-
- if (poll.getPollType().isGroup()) {
- // Add the group into the query
- query.addFrom(PollAccount.class, groupProperty.name()).
- // It's not really necessary, but better to be sure
- addEquals(groupProperty.nameProperty(PollAccount.LIST),
- Boolean.TRUE).
- // Add link between the group and the poll
- addInElements(groupProperty.name(), parentCollectionProperty);
-
- // In case of group, the parentCollection is the child
- // pollAccount from the group
- parentCollectionProperty =
- groupProperty.nameProperty(PollAccount.CHILD);
- }
-
- // Add link between the participant to find and his parent
- query.addInElements(participantProperty.name(), parentCollectionProperty).
- addEquals(participantProperty.name(), participant).
+ query.addEquals(participantProperty.name(), participant).
addWhere(pollProperty.nameProperty(Poll.CREATOR),
TopiaQuery.Op.NEQ,
participant
@@ -158,14 +142,50 @@
result = dao.existByQuery(query);
}
-
- // Note for freePoll, maybe check doubloons on participant name/email
return result;
}
+ protected TopiaQuery createQueryFindParticipantByPoll(EntityQueryProperty participantProperty,
+ EntityQueryProperty groupProperty,
+ EntityQueryProperty pollProperty,
+ Poll poll) {
+ TopiaQuery query = participantProperty.newQuery().
+ addFrom(Poll.class, pollProperty.name()).
+ addEquals(pollProperty.name(), poll);
+
+ // By default the parentCollection is pollAccount in poll
+ String parentCollectionProperty =
+ pollProperty.nameProperty(Poll.POLL_ACCOUNT);
+
+ if (poll.getPollType().isGroup()) {
+ // Add the group into the query
+ query.addFrom(PollAccount.class, groupProperty.name()).
+ // It's not really necessary, but better to be sure
+ addEquals(groupProperty.nameProperty(PollAccount.LIST),
+ Boolean.TRUE).
+ // Add link between the group and the poll
+ addInElements(groupProperty.name(), parentCollectionProperty);
+
+ // In case of group, the parentCollection is the child
+ // pollAccount from the group
+ parentCollectionProperty =
+ groupProperty.nameProperty(PollAccount.CHILD);
+ }
+
+ // Add link between the participant to find and his parent
+ query.addInElements(participantProperty.name(), parentCollectionProperty);
+
+ return query;
+ }
+
@Override
- protected PollAccount executeGetNewPollAccount() throws Exception {
+ protected PollAccount executeGetNewPollAccount(UserAccount user) {
PollAccount account = new PollAccountImpl();
+ if (user != null) {
+ account.setName(user.getDisplayName());
+ account.setEmail(user.getEmail());
+ account.setUserAccount(user);
+ }
return account;
}
@@ -193,6 +213,10 @@
List<PollAccount> results = dao.findAllByQuery(query);
+ if (log.isDebugEnabled()) {
+ log.debug("Query : " + query);
+ }
+
return results;
}
@@ -266,7 +290,7 @@
@Override
protected String executeSaveVote(TopiaContext transaction, Poll poll,
PollAccount participant)
- throws TopiaException {
+ throws TopiaException, PollenBusinessException {
// 1- executeCanVote(transaction, poll, participant);
// 2- generate uid if needed
@@ -286,6 +310,8 @@
PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+ checkParticipantDoubloons(dao, poll, participant);
+
PollAccount participantToSave =
dao.findByTopiaId(participant.getTopiaId());
@@ -304,6 +330,11 @@
// Update vote date
participantToSave.setVoteDate(context.getCurrentDate());
+ if (log.isDebugEnabled()) {
+ log.debug("Vote " + participantToSave.getName() +
+ " updated : " + participantToSave.getVoteDate());
+ }
+
// Save votes
saveParticipantVotes(transaction, participant, participantToSave);
@@ -315,12 +346,45 @@
transaction.commitTransaction();
} else {
- // maybe throw exception
+ throw new PollenBusinessException(
+ PollenBusinessException.PollenExceptionType.VOTE_NOT_ALLOWED,
+ participant.getUid());
}
return result;
}
+ protected void checkParticipantDoubloons(PollAccountDAO dao,
+ Poll poll,
+ PollAccount participant)
+ throws PollenBusinessException, TopiaException {
+
+ EntityQueryProperty participantProperty =
+ PollenUtils.getEntityQueryProperty(PollAccount.class, "A");
+ EntityQueryProperty pollProperty =
+ PollenUtils.getEntityQueryProperty(Poll.class, "P");
+ EntityQueryProperty groupProperty =
+ PollenUtils.getEntityQueryProperty(PollAccount.class, "G");
+
+ TopiaQuery query = createQueryFindParticipantByPoll(
+ participantProperty, groupProperty, pollProperty, poll);
+
+ query.addEquals(participantProperty.nameProperty(PollAccount.NAME),
+ participant.getName());
+
+ if (StringUtils.isNotEmpty(participant.getTopiaId())) {
+ query.addWhere(participantProperty.namePropertyId(),
+ TopiaQuery.Op.NEQ,
+ participant.getTopiaId());
+ }
+
+ if (dao.existByQuery(query)) {
+ throw new PollenBusinessException(
+ PollenBusinessException.PollenExceptionType.VOTE_DOUBLOON,
+ participant.getName());
+ }
+ }
+
/**
* Create a new participant for a running {@code poll}. The participant uid
* will be generated and the new instance of pollAccount will be added to
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-06-01 14:06:41 UTC (rev 3022)
@@ -100,6 +100,8 @@
pollen.exception.user_login_exist=
pollen.exception.user_not_exist=
pollen.exception.user_wrong_password=
+pollen.exception.vote_doubloon=
+pollen.exception.vote_not_allowed=
pollen.info.admin.created=Super admin was created with login %1$s
pollen.info.admin.exists=Super admin already exists
pollen.info.start=Start Pollen
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-06-01 14:06:41 UTC (rev 3022)
@@ -97,6 +97,8 @@
pollen.exception.user_login_exist=Un utilisateur est d\u00E9j\u00E0 enregistr\u00E9 avec cet identifiant.
pollen.exception.user_not_exist=L'identifiant '%1$s' ne correspond \u00E0 aucun utilisateur connu.
pollen.exception.user_wrong_password=Le mot de passe renseign\u00E9 est incorrect pour l'utilisateur '%1$s'.
+pollen.exception.vote_doubloon=
+pollen.exception.vote_not_allowed=
pollen.info.admin.created=Le super admin a \u00E9t\u00E9 cr\u00E9\u00E9 avec l'identifiant %1$s.
pollen.info.admin.exists=Le super admin existe d\u00E9j\u00E0
pollen.info.start=D\u00E9marrage de Pollen...
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -147,6 +147,7 @@
log.info("test 2 : anonymous participant");
participant.setAnonymous(true);
+ participant.setName("participant2");
uid = serviceVote.saveVote(poll, participant);
transaction = beginTransaction();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -135,20 +135,21 @@
rightarrow2, "p-pager-last");
}
}
+ }
- int doubleNbPerPage = range * 2;
- int quadrupleNbPerPage = range * 4;
- writer.element("div", "class", "p-pager-nbrows");
- writer.write(messages.format("showPerPage"));
- writer.write(" ");
- writeChangeNbRowsLink(writer, range);
- writer.write(", ");
- writeChangeNbRowsLink(writer, doubleNbPerPage);
- writer.write(", ");
- writeChangeNbRowsLink(writer, quadrupleNbPerPage);
- writer.end();
- }
+ int doubleNbPerPage = range * 2;
+ int quadrupleNbPerPage = range * 4;
+ writer.element("div", "class", "p-pager-nbrows");
+ writer.write(messages.format("showPerPage"));
+ writer.write(" ");
+ writeChangeNbRowsLink(writer, range);
+ writer.write(", ");
+ writeChangeNbRowsLink(writer, doubleNbPerPage);
+ writer.write(", ");
+ writeChangeNbRowsLink(writer, quadrupleNbPerPage);
writer.end();
+
+ writer.end();
}
void afterRender(MarkupWriter writer) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -742,11 +742,12 @@
email.setSubject(messages.format(
"pollen.email.createPoll.subject",
getPoll().getTitle()));
+
email.setContent(messages.format(
"pollen.email.createPoll.content",
getPoll().getTitle(),
servicePollUri.getVoteUrl(uri),
- servicePollUri.getModerateVoteUrl(uri),
+ servicePollUri.getVoteUpdateUrl(uri),
servicePollUri.getPollUpdateUrl(uri)));
serviceEmail.sendEmail(email);
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -90,7 +90,7 @@
}
public Link getModerateVoteLink() {
- return servicePollUri.getModerateVoteLink(pollUri);
+ return servicePollUri.getVoteUpdateLink(pollUri);
}
public Link getPollLink() {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -22,10 +22,12 @@
import java.util.Locale;
+import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -33,16 +35,20 @@
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenProperty;
import org.chorem.pollen.bean.Filter;
+import org.chorem.pollen.bean.PollenEmail;
+import org.chorem.pollen.bean.PollenEmailImpl;
import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.Vote;
+import org.chorem.pollen.service.ServiceEmail;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.service.ServiceUser;
import org.chorem.pollen.service.ServiceVote;
@@ -55,6 +61,8 @@
import org.chorem.pollen.ui.data.PollUri;
import org.chorem.pollen.ui.services.PollenManager;
import org.chorem.pollen.ui.services.ServiceImage;
+import org.chorem.pollen.ui.services.ServicePollUri;
+import org.nuiton.web.tapestry5.components.FeedBack;
import org.slf4j.Logger;
/**
@@ -206,9 +214,21 @@
public PollAccount getPollAccount() {
if (pollAccount == null) {
if (uri.hasAccountUid()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Loading existing pollAccount : " + uri.getAccountUid());
+ }
pollAccount = serviceVote.getPollAccount(uri.getAccountUid());
+ if (logger.isDebugEnabled() && pollAccount != null) {
+ logger.debug("Pollaccount loaded : " +
+ pollAccount.getName() + " admin=" +
+ pollAccount.isAdmin());
+ }
} else {
- pollAccount = serviceVote.getNewPollAccount();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Instantiate new pollAccount from connected" +
+ " user (defined=" + isUserConnected() + ")");
+ }
+ pollAccount = serviceVote.getNewPollAccount(getUserConnected());
}
}
return pollAccount;
@@ -513,6 +533,7 @@
filter.setStartIndex(pager.getStartIndex());
filter.setEndIndex(pager.getEndIndex());
filter.setReference(getPoll());
+ filter.setOrderBy(PollAccount.VOTE_DATE + " desc");
return filter;
}
@@ -536,7 +557,26 @@
@Property
private PollAccount participant;
+
+ private List<Vote> editedVotes;
+ @Property
+ private Vote editedVote;
+
+ @InjectComponent
+ private Form voteForm;
+
+ private Boolean canVote;
+
+ @InjectComponent
+ private FeedBack voteFeedback;
+
+ @Inject
+ private ServicePollUri servicePollUri;
+
+ @Inject
+ private ServiceEmail serviceEmail;
+
/**
* Retrieve votes of the current poll from business module.
* The votes are ordered by creation date, only the ones to display are
@@ -552,22 +592,31 @@
return participants;
}
+ public String getParticipantNameStyle() {
+ if (!participant.isAnonymous() &&
+ participant.getName().equals(getPollAccount().getName())) {
+ return "selected";
+ }
+ return evenOdd.getNext();
+ }
+
public Vote getVote() {
Vote vote = participant.getChoiceVote(choice.getChoice());
return vote;
}
- private List<Vote> editedVotes;
-
- @Property
- private Vote editedVote;
-
public List<Vote> getEditedVotes() {
if (editedVotes == null) {
editedVotes = new ArrayList<Vote>();
for (ChoiceField choice : choices) {
Vote vote = getPollAccount().getChoiceVote(choice.getChoice());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Load previous vote : " +
+ (vote != null ?
+ vote.getChoice().getName() + " with value " +
+ vote.getVoteValue() : "null"));
+ }
if (vote == null) {
vote = serviceVote.getNewVote(choice.getChoice());
}
@@ -577,16 +626,135 @@
return editedVotes;
}
+ public boolean canVote() throws PollenBusinessException {
+ if (canVote == null) {
+ canVote = serviceVote.canVote(getPoll(), getPollAccount());
+ }
+ return canVote;
+ }
+
+ public boolean canDeleteVote() {
+ return getPollAccount().isAdmin();
+ }
+
+ @Log
+ void onActionFromDeleteVote(int participantIndex) throws PollenBusinessException {
+ if (canDeleteVote()) {
+ PollAccount participant = getParticipants().get(participantIndex);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Delete vote from participant index " +
+ participantIndex + " name = " + participant.getName());
+ }
+
+ serviceVote.deleteVote(getPoll(), participant);
+ }
+ }
+
+ @Log
void onValidateFormFromVoteForm() {
// percentage : check total = 100
getPollAccount().setChoiceVote(getEditedVotes());
try {
- serviceVote.saveVote(getPoll(), getPollAccount());
+ // Link with user account
+ boolean linkWithUser = linkUserConnected();
+
+ // Execute the save
+ String uid = serviceVote.saveVote(getPoll(), getPollAccount());
+ getPollAccount().setUid(uid);
+
+ if (linkWithUser) {
+ voteFeedback.addInfo("Votre vote a été lié à votre compte utilisateur.");
+ }
} catch (PollenBusinessException eee) {
- // record error
+ String message = manager.getErrorMessage(logger, messages, eee);
+ voteForm.recordError(message);
}
}
+ protected boolean linkUserConnected() {
+ if (isUserConnected() && getPollAccount().getUserAccount() == null) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Link participant with user connected : " +
+ getUserConnected().getDisplayName());
+ }
+ getPollAccount().setUserAccount(getUserConnected());
+ return true;
+ }
+ return false;
+ }
+
+ protected Object manageFreeVote() throws PollenBusinessException {
+ // Prepare uri for redirection and being display to user
+ String uid = getPollAccount().getUid();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("New vote with uid : " + uid);
+ }
+ PollUri updateUri =
+ servicePollUri.getNewPollUri(uid, getPoll().getUid());
+ String updateUrl = servicePollUri.getVoteUpdateUrl(updateUri);
+
+ // with unconnected user
+ if (!isUserConnected()) {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Vote created for free poll with unconnected user");
+ }
+
+ String email = getPollAccount().getEmail();
+ boolean anonymous = getPollAccount().isAnonymous();
+
+ // send email
+ if (StringUtils.isNotEmpty(email) && !anonymous) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Send an email to '" + email + "' with url : " +
+ updateUrl);
+ }
+
+ PollenEmail pollenEmail = new PollenEmailImpl();
+ pollenEmail.setTo(email);
+ pollenEmail.setSubject("Vote OK");
+ pollenEmail.setContent("Url de modification de votre vote : " +
+ updateUrl);
+ try {
+ serviceEmail.sendEmail(pollenEmail);
+ } catch (PollenBusinessException eee) {
+ String message = manager.getErrorMessage(logger, messages, eee);
+ voteFeedback.addError(message);
+ }
+
+ voteFeedback.addInfo("Envoi d'un email avec l'url de modification de votre vote.");
+
+ // display url to update vote
+ } else {
+ voteFeedback.addInfo("Url de modification de votre vote : " +
+ updateUrl);
+ }
+ }
+ voteFeedback.addInfo("La page a été rechargée, vous pouvez modifier votre vote.");
+ return servicePollUri.getVoteUpdateLink(updateUri);
+ }
+
+ @Log
+ Object onSuccessFromVoteForm() throws PollenBusinessException {
+ voteFeedback.addInfo("Enregistrement du vote OK");
+
+ boolean newFreeVote = StringUtils.isEmpty(uri.getAccountUid());
+
+ Object redirect = this;
+ // Case of new Free vote
+ if (newFreeVote && getPoll().getPollType().isFree()) {
+ redirect = manageFreeVote();
+ }
+ page = 1;
+ return redirect;
+ }
+
+ Object onFailureFromVoteForm() {
+ return voteForm;
+ }
+
// /**
// * Retourne vrai si le champs pollAccount doit apparaître.
// *
@@ -604,17 +772,6 @@
// return !getPoll().isAnonymous() || isRestrictedPoll() || isGroupPoll();
// }
- public boolean getCanVote() {
- // FIXME-fdesbois-2010-05-25 : copy check treatment directly in service
- if (poll.isFinished()) {
- return false;
- }
- if (poll.getPollType().isRestrictedOrGroup() || poll.isAnonymous()) {
- return serviceVote.canVote(poll, pollAccount);
- }
- return true;
- }
-
public boolean canEditVote() throws PollenBusinessException {
// If the current pollAccount exist from uri and equals to the current vote
// String newAccountId = getPollAccount().getId();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -206,7 +206,6 @@
return uri;
}
};
-
Coercion<PollUri, String> coercion2 = new Coercion<PollUri, String>() {
@Override
@@ -215,12 +214,36 @@
}
};
+ Coercion<Boolean, Double> coercion3 = new Coercion<Boolean, Double>() {
+
+ @Override
+ public Double coerce(Boolean input) {
+ return input ? 1. : 0.;
+ }
+ };
+ Coercion<Double, Boolean> coercion4 = new Coercion<Double, Boolean>() {
+
+ @Override
+ public Boolean coerce(Double input) {
+ return input > 1;
+ }
+ };
+
+ // coercions for String <-> PollUri
configuration.add(
new CoercionTuple<String, PollUri>(
String.class, PollUri.class, coercion1));
configuration.add(
new CoercionTuple<PollUri, String>(
PollUri.class, String.class, coercion2));
+
+ // coercions for Double <-> Boolean : use for voteValue
+ configuration.add(
+ new CoercionTuple<Boolean, Double>(
+ Boolean.class, Double.class, coercion3));
+ configuration.add(
+ new CoercionTuple<Double, Boolean>(
+ Double.class, Boolean.class, coercion4));
}
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -42,7 +42,7 @@
* @param uri PollUri that contains pollUid and creatorUid (moderator)
* @return the Link to used for moderation on vote page
*/
- Link getModerateVoteLink(PollUri uri);
+ Link getVoteUpdateLink(PollUri uri);
/**
* Retrieve url for poll update page.
@@ -66,7 +66,7 @@
* @param uri PollUri that contains pollUid and creatorUid (moderator)
* @return the full url to used for moderation on vote page
*/
- String getModerateVoteUrl(PollUri uri);
+ String getVoteUpdateUrl(PollUri uri);
/**
* Retrieve a new instance of PollUri with {@code accountUid} and {@code
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java 2010-06-01 14:06:41 UTC (rev 3022)
@@ -45,7 +45,7 @@
}
@Override
- public Link getModerateVoteLink(PollUri uri) {
+ public Link getVoteUpdateLink(PollUri uri) {
Link link = linkSource.createPageRenderLinkWithContext(
VoteForPoll.class, uri);
return link;
@@ -53,17 +53,17 @@
@Override
public String getPollUpdateUrl(PollUri uri) {
- return contextPath + getPollUpdateLink(uri);
+ return contextPath + getPollUpdateLink(uri).toAbsoluteURI();
}
@Override
public String getVoteUrl(PollUri uri) {
- return contextPath + getVoteLink(uri);
+ return contextPath + getVoteLink(uri).toAbsoluteURI();
}
@Override
- public String getModerateVoteUrl(PollUri uri) {
- return contextPath + getModerateVoteLink(uri);
+ public String getVoteUpdateUrl(PollUri uri) {
+ return contextPath + getVoteUpdateLink(uri).toAbsoluteURI();
}
@Override
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-06-01 14:06:41 UTC (rev 3022)
@@ -79,6 +79,8 @@
pollen.ui.poll.links.creatorEmail.success=Un email vous a \u00e9t\u00e9 envoy\u00e9 avec les liens ci-dessous.
pollen.ui.poll.links.creatorEmail.notDefined=Aucun email n'a \u00e9t\u00e9 d\u00e9fini \u00e0 la cr\u00e9ation du sondage, vous devriez enregistrer cette page dans vos favoris pour ne pas perdre les liens.
+############################ VOTE ##############################################
+pollen.ui.vote.delete.confirmMessage=Etes-vous s\u00fbr de vouloir supprimer ce vote ?
# OLD LOGIN_COMPONENT
connectionLegend=Connexion
Modified: trunk/pollen-ui/src/main/webapp/css/common.css
===================================================================
--- trunk/pollen-ui/src/main/webapp/css/common.css 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/webapp/css/common.css 2010-06-01 14:06:41 UTC (rev 3022)
@@ -38,6 +38,10 @@
text-align: center;
}
+.selected {
+ background-color: yellow;
+}
+
input.ico {
border: 0 none;
font-size: 0;
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-31 15:57:48 UTC (rev 3021)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-06-01 14:06:41 UTC (rev 3022)
@@ -43,16 +43,16 @@
<!-- Sondage -->
- <!--<t:zone t:id="pollZone" t:show="show" t:update="show">-->
- <t:if t:test="pagerNeeded">
- <t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="nbVotes"
- t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>
- <!--<t:feedback t:id="voteFeedback"/>-->
- <p:else>
- <p>${format:vote-size=nbVotes}</p>
- </p:else>
- </t:if>
- <t:form t:id="voteForm">
+ <t:zone t:id="voteZone" t:update="show">
+ <form t:type="form" t:id="voteForm" t:zone="voteZone">
+ <t:nuiton.feedback t:id="voteFeedback" />
+ <!--<t:if t:test="pagerNeeded">-->
+ <t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="nbVotes"
+ t:currentPage="page" t:noPagerText="format:vote-size=nbVotes" t:range="pagerRange"/>
+ <!--<p:else>-->
+ <!--<p>${format:vote-size=nbVotes}</p>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
<table id="poll">
<thead>
<tr>
@@ -98,7 +98,7 @@
</th>
</tr>
</thead>
- <t:if test="canVote">
+ <t:if test="canVote()">
<tfoot>
<tr>
<!--<t:if test="accountFieldDisplayed">-->
@@ -110,8 +110,8 @@
<!--</p:else>-->
<!--</t:if>-->
<t:loop t:source="editedVotes" t:value="editedVote" volatile="true">
- <t:unless test="editedChoice.hidden">
- <th>
+ <t:unless test="editedVote.choice.hidden">
+ <th class="center">
<t:if test="poll.voteCountingType.normal">
<input t:type="checkbox" value="editedVote.voteValue" />
</t:if>
@@ -132,9 +132,9 @@
</t:if>
<tbody>
<t:unless t:test="poll.anonymous">
- <t:loop t:source="participants" t:value="participant" t:rowIndex="participantIndex" volatile="true">
+ <t:loop t:source="participants" t:value="participant" t:index="participantIndex" volatile="true">
<tr>
- <td class="${evenodd.next}">
+ <td class="${participantNameStyle}">
<!--<t:if test="accountFieldDisplayed">-->
<t:if test="participant.anonymous">
?
@@ -149,11 +149,12 @@
<!--<img src="${asset:context:img/editSmall.png}" title="${message:edit}" alt="${message:edit}"/>-->
<!--</t:actionlink>-->
<!--</t:if>-->
- <!--<t:if test="creatorUser">-->
- <!--<t:actionlink t:id="deleteVote" context="vote.id" t:zone="pollZone">-->
- <!--<img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>-->
- <!--</t:actionlink>-->
- <!--</t:if>-->
+ <t:if test="canDeleteVote()">
+ <a t:type="actionlink" t:id="deleteVote" t:context="participantIndex" t:mixins="nuiton/confirm"
+ t:message="${message:pollen.ui.vote.delete.confirmMessage}">
+ <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>
+ </a>
+ </t:if>
<!--</t:unless>-->
</td>
<t:loop t:source="choices" t:value="choice" volatile="true">
@@ -221,18 +222,22 @@
<div id="voteError">
<t:errors/>
</div>
- <!--<t:if test="poll.running">-->
- <!--<div id="buttons">-->
- <!--<t:if test="anonymousVoteDisplayed">-->
- <!--<t:checkbox t:id="anonymousVote" t:value="anonymousVote" />-->
- <!--<t:label for="anonymousVote" />-->
- <!--<br/>-->
- <!--</t:if>-->
- <!--<input t:id="submitVote" t:type="Submit" t:value="${message:submitVote}" />-->
- <!--</div>-->
- <!--</t:if>-->
- </t:form>
- <!--</t:zone>-->
+ <t:if test="canVote()">
+ <div id="buttons">
+ <t:if t:test="poll.pollType.free">
+ <label t:type="label" t:for="pollAccountEmail" />
+ <input t:type="textfield" t:id="pollAccountEmail" value="pollAccount.email" />
+ </t:if>
+ <t:if t:test="poll.anonymousVoteAllowed">
+ <input t:type="checkbox" t:id="anonymousVote" value="pollAccount.anonymous" />
+ <t:label t:for="anonymousVote" />
+ <br/>
+ </t:if>
+ <input t:id="submitVote" t:type="Submit" t:value="${message:submitVote}" />
+ </div>
+ </t:if>
+ </form>
+ </t:zone>
<!--</t:if>-->
1
0
r3021 - in trunk/pollen-business/src: main/java/org/chorem/pollen/service main/xmi test/java/org/chorem/pollen/service test/java/org/chorem/pollen/test
by fdesbois@users.chorem.org 31 May '10
by fdesbois@users.chorem.org 31 May '10
31 May '10
Author: fdesbois
Date: 2010-05-31 17:57:48 +0200 (Mon, 31 May 2010)
New Revision: 3021
Url: http://chorem.org/repositories/revision/pollen/3021
Log:
Implement deleteVote method + tests
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-business/src/main/xmi/pollen.properties
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-28 13:21:09 UTC (rev 3020)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-31 15:57:48 UTC (rev 3021)
@@ -146,11 +146,11 @@
// Add link between the participant to find and his parent
query.addInElements(participantProperty.name(), parentCollectionProperty).
- addEquals(participantProperty.name(), participant).
- addWhere(pollProperty.nameProperty(Poll.CREATOR),
- TopiaQuery.Op.NEQ,
- participant
- );
+ addEquals(participantProperty.name(), participant).
+ addWhere(pollProperty.nameProperty(Poll.CREATOR),
+ TopiaQuery.Op.NEQ,
+ participant
+ );
if (log.isDebugEnabled()) {
log.debug("Query : " + query);
@@ -209,10 +209,51 @@
}
@Override
- protected void executeDeleteVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
+ protected void executeDeleteVote(TopiaContext transaction, Poll poll,
+ PollAccount participant) throws TopiaException {
// For free poll, delete the participant
// For other types, delete all votes and set voteDate to null
+
+ if (poll.getPollType().isFree()) {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount participantToDelete =
+ dao.findByTopiaId(participant.getTopiaId());
+
+ dao.delete(participantToDelete);
+
+ // Next code has equivalent results -> remove the entity from the poll
+ // then delete it because of delete-orphan
+
+// PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
+//
+// Poll pollToUpdate = dao.findByTopiaId(poll.getTopiaId());
+//
+// // participant will be deleted because of composition on pollAccount
+// // collection
+// pollToUpdate.removePollAccount(participant);
+//
+// dao.update(pollToUpdate);
+
+ } else if (poll.getPollType().isRestrictedOrGroup()) {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount participantToUpdate =
+ dao.findByTopiaId(participant.getTopiaId());
+
+ // Remove all votes deleted by cascade
+ participantToUpdate.clearChoiceVote();
+ // Reset date, the participant is considered like he has not alerady
+ // voted
+ participantToUpdate.setVoteDate(null);
+
+ dao.update(participantToUpdate);
+ }
+
+ transaction.commitTransaction();
}
@Override
Modified: trunk/pollen-business/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-business/src/main/xmi/pollen.properties 2010-05-28 13:21:09 UTC (rev 3020)
+++ trunk/pollen-business/src/main/xmi/pollen.properties 2010-05-31 15:57:48 UTC (rev 3021)
@@ -2,6 +2,7 @@
model.tagvalue.copyright=/* *##%\n Copyright (C) 2009 Pollen\n *##%*/
# toString are particularly difficult to use because of lazy initialization
model.tagvalue.notGenerateToString=true
+#model.tagvalue.useLegacyDAO=true
#model.tagvalue.dbSchema=Pollen
model.tagvalue.java.lang.String=text
model.tagvalue.exceptionClass=org.chorem.pollen.PollenException
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-05-28 13:21:09 UTC (rev 3020)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-05-31 15:57:48 UTC (rev 3021)
@@ -11,8 +11,10 @@
import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.PollAccountDAO;
import org.chorem.pollen.entity.PollAccountImpl;
+import org.chorem.pollen.entity.PollDAO;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.Vote;
+import org.chorem.pollen.entity.VoteDAO;
import org.chorem.pollen.entity.VoteImpl;
import org.chorem.pollen.test.AbstractServiceTest;
import org.junit.Assert;
@@ -21,7 +23,10 @@
import org.nuiton.topia.TopiaException;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Created: 27 mai 2010
@@ -33,9 +38,13 @@
private static final Log log = LogFactory.getLog(ServiceVoteImplTest.class);
+ protected UserAccount user;
+
@Override
protected void init() throws Exception {
getServiceVote();
+
+ user = createUser(false);
}
@Test
@@ -43,7 +52,6 @@
throws PollenBusinessException, TopiaException {
/** PREPARE DATA **/
- UserAccount user = createUser(false);
Poll pollCreated = createGroupPoll("Poll", user, null, 3, "Group1", "Group2");
@@ -80,8 +88,6 @@
@Test
public void testSaveVoteForFreePoll() throws PollenBusinessException, TopiaException {
/** PREPARE DATA **/
- UserAccount user = createUser(false);
-
Poll pollCreated = createFreePoll("Poll", user, VoteCountingType.NORMAL);
List<Choice> choices =
addChoicesToPoll(pollCreated, ChoiceType.TEXT,
@@ -200,8 +206,140 @@
} finally {
transaction.closeContext();
}
+ }
-
+ @Test
+ public void testDeleteVoteForFreePoll()
+ throws TopiaException, PollenBusinessException {
+ /** PREPARE DATA */
+ Poll pollCreated = createFreePoll("Poll", user, VoteCountingType.NORMAL);
+
+ List<Choice> choices =
+ addChoicesToPoll(pollCreated, ChoiceType.TEXT,
+ "choice1", "choice2", "choice3");
+
+ PollAccount participant = new PollAccountImpl();
+ participant.setName("participant");
+ participant.setEmail("participant(a)domain.org");
+ participant.setUserAccount(user);
+
+ for (Choice choice : choices) {
+ Vote vote = new VoteImpl();
+ vote.setChoice(choices.get(0)); // choice1
+ vote.setVoteValue(1); // TRUE
+ participant.addChoiceVote(vote);
+ }
+
+ String uid = serviceVote.saveVote(pollCreated, participant);
+ TopiaContext transaction = beginTransaction();
+ PollAccount account = null;
+ Collection<Vote> votes = null;
+ try {
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ account = dao.findByNaturalId(uid);
+ votes = account.getChoiceVote();
+
+ } finally {
+ transaction.closeContext();
+ }
+
+ Poll poll = loadEntity(pollCreated);
+
+ /** EXEC METHOD */
+
+ serviceVote.deleteVote(poll, account);
+
+ transaction = beginTransaction();
+ try {
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ // Check account are correctly deleted
+ account = dao.findByNaturalId(uid);
+ Assert.assertNull(account);
+
+ VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
+ // Check all votes are not in database anymore
+ for (Vote vote : votes) {
+ Vote voteFound = voteDAO.findByTopiaId(vote.getTopiaId());
+ Assert.assertNull(voteFound);
+ }
+
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(transaction);
+
+ Poll pollFound = pollDAO.findByTopiaId(poll.getTopiaId());
+ Assert.assertEquals(0, pollFound.getPollAccount().size());
+ Assert.assertNotNull(pollFound.getCreator());
+
+ } finally {
+ transaction.closeContext();
+ }
}
+
+ @Test
+ public void testDeleteVoteForGroupPoll()
+ throws TopiaException, PollenBusinessException {
+
+ /** PREPARE DATA */
+ Poll pollCreated = createGroupPoll("Poll", user,
+ VoteCountingType.NORMAL, 3, "group1", "group2");
+
+ PollAccount group1 = pollCreated.getPollAccount().iterator().next();
+ PollAccount existingParticipant = group1.getChild().iterator().next();
+
+ List<Choice> choices =
+ addChoicesToPoll(pollCreated, ChoiceType.TEXT,
+ "choice1", "choice2", "choice3");
+
+ for (Choice choice : choices) {
+ Vote vote = new VoteImpl();
+ vote.setChoice(choices.get(0)); // choice1
+ vote.setVoteValue(1); // TRUE
+ existingParticipant.addChoiceVote(vote);
+ }
+
+ String uid = serviceVote.saveVote(pollCreated, existingParticipant);
+ TopiaContext transaction = beginTransaction();
+ PollAccount account = null;
+ Collection<Vote> votes = null;
+ try {
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ account = dao.findByNaturalId(uid);
+ votes = account.getChoiceVote();
+
+ } finally {
+ transaction.closeContext();
+ }
+
+ Poll poll = loadEntity(pollCreated);
+
+ /** EXEC METHOD */
+
+ serviceVote.deleteVote(poll, account);
+
+ transaction = beginTransaction();
+ try {
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ // Check account are correctly deleted
+ account = dao.findByNaturalId(uid);
+ Assert.assertFalse(account.isList());
+ Assert.assertNotNull(account);
+ Assert.assertNull(account.getVoteDate());
+
+ VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
+ // Check all votes are not in database anymore
+ for (Vote vote : votes) {
+ Vote voteFound = voteDAO.findByTopiaId(vote.getTopiaId());
+ Assert.assertNull(voteFound);
+ }
+
+ } finally {
+ transaction.closeContext();
+ }
+
+
+ }
}
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-28 13:21:09 UTC (rev 3020)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-31 15:57:48 UTC (rev 3021)
@@ -21,6 +21,8 @@
import org.chorem.pollen.entity.PollDAO;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.UserAccountDAO;
+import org.chorem.pollen.entity.Vote;
+import org.chorem.pollen.entity.VoteDAO;
import org.chorem.pollen.service.ServiceFavoriteImpl;
import org.chorem.pollen.service.ServicePollImpl;
import org.chorem.pollen.service.ServiceUserImpl;
@@ -43,6 +45,7 @@
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
/**
1
0
r3020 - in trunk/pollen-business/src: main/java/org/chorem/pollen/service main/xmi test/java/org/chorem/pollen test/java/org/chorem/pollen/service test/java/org/chorem/pollen/test
by fdesbois@users.chorem.org 28 May '10
by fdesbois@users.chorem.org 28 May '10
28 May '10
Author: fdesbois
Date: 2010-05-28 15:21:09 +0200 (Fri, 28 May 2010)
New Revision: 3020
Url: http://chorem.org/repositories/revision/pollen/3020
Log:
Evo #197 : Tests for saveVote
Added:
trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java
Removed:
trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/test/TestData.java
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-business/src/main/xmi/pollen.properties
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-28 08:40:01 UTC (rev 3019)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-28 13:21:09 UTC (rev 3020)
@@ -57,13 +57,28 @@
context.closeTransaction(transaction);
}
+ /**
+ * Copy from account {@code source} to {@code destination}. The {@code
+ * destination} will be persisted. The anonymous case is manage, properties
+ * that identify the person are excluded from the copy in this case.
+ *
+ * @param source PollAccount to save
+ * @param destination PollAccount with up to date data to persist
+ * @see TopiaEntityBinder#copyExcluding(Object, Object, String...)
+ */
protected void copyPollAccount(PollAccount source, PollAccount destination) {
+ // Uid is the naturalId, don't copy it
+ String[] excludes = new String[] {PollAccount.UID};
- String[] excludes = null;
-
// Exclude properties for anonymous account
if (source.isAnonymous()) {
+ if (log.isInfoEnabled()) {
+ log.info("Anonymous vote, doesn't copy participant's data : " +
+ "name, email, userAccount");
+ }
+
excludes = new String[]{
+ PollAccount.UID,
PollAccount.NAME,
PollAccount.EMAIL,
PollAccount.USER_ACCOUNT};
@@ -117,25 +132,25 @@
if (poll.getPollType().isGroup()) {
// Add the group into the query
query.addFrom(PollAccount.class, groupProperty.name()).
- // It's not really necessary, but better to be sure
- addEquals(groupProperty.nameProperty(PollAccount.LIST),
+ // It's not really necessary, but better to be sure
+ addEquals(groupProperty.nameProperty(PollAccount.LIST),
Boolean.TRUE).
- // Add link between the group and the poll
- addInElements(groupProperty.name(), parentCollectionProperty);
+ // Add link between the group and the poll
+ addInElements(groupProperty.name(), parentCollectionProperty);
// In case of group, the parentCollection is the child
// pollAccount from the group
parentCollectionProperty =
- groupProperty.nameProperty(PollAccount.CHILD);
+ groupProperty.nameProperty(PollAccount.CHILD);
}
// Add link between the participant to find and his parent
query.addInElements(participantProperty.name(), parentCollectionProperty).
- addEquals(participantProperty.name(), participant).
- addWhere(pollProperty.nameProperty(Poll.CREATOR),
- TopiaQuery.Op.NEQ,
- participant
- );
+ addEquals(participantProperty.name(), participant).
+ addWhere(pollProperty.nameProperty(Poll.CREATOR),
+ TopiaQuery.Op.NEQ,
+ participant
+ );
if (log.isDebugEnabled()) {
log.debug("Query : " + query);
@@ -143,6 +158,8 @@
result = dao.existByQuery(query);
}
+
+ // Note for freePoll, maybe check doubloons on participant name/email
return result;
}
@@ -193,6 +210,9 @@
@Override
protected void executeDeleteVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
+
+ // For free poll, delete the participant
+ // For other types, delete all votes and set voteDate to null
}
@Override
@@ -204,7 +224,7 @@
@Override
protected String executeSaveVote(TopiaContext transaction, Poll poll,
- PollAccount participant)
+ PollAccount participant)
throws TopiaException {
// 1- executeCanVote(transaction, poll, participant);
@@ -231,6 +251,9 @@
// canVote method check the existence of participant for a
// restricted poll, so the create case is only for FREE poll.
if (participantToSave == null) {
+ if (log.isInfoEnabled()) {
+ log.info("Create new participant for FREE poll");
+ }
participantToSave = createNewParticipant(transaction, poll);
}
@@ -257,6 +280,16 @@
return result;
}
+ /**
+ * Create a new participant for a running {@code poll}. The participant uid
+ * will be generated and the new instance of pollAccount will be added to
+ * the {@code poll}.
+ *
+ * @param transaction TopiaContext to retrieve daos
+ * @param poll Poll where the new participant will be added
+ * @return a new PollAccount added to the poll
+ * @throws TopiaException for Topia errors
+ */
protected PollAccount createNewParticipant(TopiaContext transaction,
Poll poll)
throws TopiaException {
@@ -277,12 +310,22 @@
return newParticipant;
}
+ /**
+ * Save all votes from a participant. Votes will be added/updated or deleted
+ * depends on voteValue and existence in database.
+ *
+ * @param transaction TopiaContext to retrieve daos
+ * @param source PollAccount source that contains vote to save
+ * @param destination PollAccount destination where votes will be added to
+ * be persisted
+ * @throws TopiaException for Topia errors
+ */
protected void saveParticipantVotes(TopiaContext transaction,
PollAccount source,
PollAccount destination)
throws TopiaException {
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
for (Vote vote : source.getChoiceVote()) {
Vote voteToSave = voteDAO.findByTopiaId(vote.getTopiaId());
@@ -290,6 +333,9 @@
if (vote.getVoteValue() != 0) {
// Create vote
if (voteToSave == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Create vote for " + destination.getUid());
+ }
voteToSave = voteDAO.create();
voteToSave.setChoice(vote.getChoice());
// Add new vote to destination participant
@@ -300,11 +346,13 @@
voteToSave.setVoteValue(vote.getVoteValue());
voteDAO.update(voteToSave);
- // Delete vote if exist and new value is 0
+ // Delete vote if exist and new value is 0
} else if (voteToSave != null) {
- // Normally the vote will be removed from ChoiceVote list in
- // pollAccount.
- voteDAO.delete(voteToSave);
+ if (log.isDebugEnabled()) {
+ log.debug("Delete vote for " + destination.getUid());
+ }
+ // Normally the vote will be deleted
+ destination.removeChoiceVote(voteToSave);
}
}
}
Modified: trunk/pollen-business/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-business/src/main/xmi/pollen.properties 2010-05-28 08:40:01 UTC (rev 3019)
+++ trunk/pollen-business/src/main/xmi/pollen.properties 2010-05-28 13:21:09 UTC (rev 3020)
@@ -11,6 +11,8 @@
org.chorem.pollen.entity.PollAccount.attribute.uid.tagvalue.naturalId=true
+org.chorem.pollen.entity.Vote.attribute.choice.tagvalue.lazy=false
+
org.chorem.pollen.entity.FavoriteList.attribute.userAccount.tagvalue.naturalId=true
org.chorem.pollen.entity.FavoriteList.attribute.name.tagvalue.naturalId=true
Copied: trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java (from rev 3018, trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java)
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java (rev 0)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java 2010-05-28 13:21:09 UTC (rev 3020)
@@ -0,0 +1,122 @@
+
+package org.chorem.pollen;
+
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.bean.Filter;
+import org.chorem.pollen.entity.FavoriteList;
+import org.chorem.pollen.entity.FavoriteParticipant;
+import org.chorem.pollen.entity.UserAccount;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ *
+ * @author fdesbois
+ */
+public class PollenUtilsTest {
+
+ private static final Log log =
+ LogFactory.getLog(PollenUtilsTest.class);
+
+ /**
+ * Test of prepareQuery method, of class Filter.
+ */
+ @Test
+ public void testPrepareQueryForFilter() {
+ log.info("testPrepareQueryForFilter");
+
+ Filter filter = new Filter();
+ filter.setStartIndex(1);
+ filter.setEndIndex(40);
+ filter.setOrderBy(UserAccount.LOGIN);
+
+// TopiaQueryBuilder builder = new TopiaQueryBuilder();
+// builder.setQuery(new TopiaQuery(UserAccount.class));
+ TopiaQuery query = new TopiaQuery(UserAccount.class);
+ PollenUtils.prepareQuery(query, filter);
+
+ log.debug("Query : " + query);
+
+ Assert.assertEquals(query.fullQuery(),
+ "FROM " + UserAccount.class.getName() +
+ " ORDER BY " + UserAccount.LOGIN);
+
+ filter.setOrderBy(null);
+
+ query = new TopiaQuery(UserAccount.class);
+ PollenUtils.prepareQuery(query, filter);
+
+ log.debug("Query : " + query);
+
+ Assert.assertEquals(query.fullQuery(),
+ "FROM " + UserAccount.class.getName() +
+ " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
+
+ }
+
+ @Test
+ public void testCreateQueryFindElementsByCollection() throws IOException {
+
+ //TopiaQueryBuilder builder = new TopiaQueryBuilder();
+
+ Filter filter = new Filter();
+ filter.setStartIndex(1);
+ filter.setEndIndex(40);
+ filter.setOrderBy(FavoriteParticipant.NAME);
+
+ EntityQueryProperty participantPropertyProvider =
+ PollenUtils.getEntityQueryProperty(FavoriteParticipant.class, "P");
+
+ EntityQueryProperty listPropertyProvider =
+ PollenUtils.getEntityQueryProperty(FavoriteList.class, "L");
+ listPropertyProvider.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT);
+
+ log.info("test1 : orderBy FavoriteParticipant name");
+ TopiaQuery result = PollenUtils.createQueryFindElementsByCollection(
+ participantPropertyProvider, listPropertyProvider, filter);
+
+ log.debug("Query : " + result);
+
+ Assert.assertEquals(result.fullQuery(),
+ "SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ + FavoriteList.class.getName() + " L" +
+ " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
+ ") ORDER BY P." + FavoriteParticipant.NAME);
+
+ log.info("test2 : orderBy not set (default to topiaCreateDate desc)");
+ filter.setOrderBy(null);
+
+ result = PollenUtils.createQueryFindElementsByCollection(
+ participantPropertyProvider, listPropertyProvider, filter);
+
+ log.debug("Query : " + result);
+
+ Assert.assertEquals(result.fullQuery(),
+ "SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ + FavoriteList.class.getName() + " L" +
+ " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
+ ") ORDER BY P." + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
+
+ log.info("test3 : orderBy name and email desc");
+ String orderBy = FavoriteParticipant.NAME + ", " + FavoriteParticipant.EMAIL + " desc";
+ filter.setOrderBy(orderBy);
+
+ result = PollenUtils.createQueryFindElementsByCollection(
+ participantPropertyProvider, listPropertyProvider, filter);
+
+ log.debug("Query : " + result);
+
+ Assert.assertEquals(result.fullQuery(),
+ "SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ + FavoriteList.class.getName() + " L" +
+ " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
+ ") ORDER BY P." + FavoriteParticipant.NAME + ", P." +
+ FavoriteParticipant.EMAIL + " desc");
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Deleted: trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-28 08:40:01 UTC (rev 3019)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-28 13:21:09 UTC (rev 3020)
@@ -1,122 +0,0 @@
-
-package org.chorem.pollen;
-
-import java.io.IOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.bean.Filter;
-import org.chorem.pollen.entity.FavoriteList;
-import org.chorem.pollen.entity.FavoriteParticipant;
-import org.chorem.pollen.entity.UserAccount;
-import org.junit.Assert;
-import org.junit.Test;
-import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-/**
- *
- * @author fdesbois
- */
-public class TopiaQueryBuilderTest {
-
- private static final Log log =
- LogFactory.getLog(TopiaQueryBuilderTest.class);
-
- /**
- * Test of prepareQuery method, of class Filter.
- */
- @Test
- public void testPrepareQueryForFilter() {
- log.info("testPrepareQueryForFilter");
-
- Filter filter = new Filter();
- filter.setStartIndex(1);
- filter.setEndIndex(40);
- filter.setOrderBy(UserAccount.LOGIN);
-
-// TopiaQueryBuilder builder = new TopiaQueryBuilder();
-// builder.setQuery(new TopiaQuery(UserAccount.class));
- TopiaQuery query = new TopiaQuery(UserAccount.class);
- PollenUtils.prepareQuery(query, filter);
-
- log.debug("Query : " + query);
-
- Assert.assertEquals(query.fullQuery(),
- "FROM " + UserAccount.class.getName() +
- " ORDER BY " + UserAccount.LOGIN);
-
- filter.setOrderBy(null);
-
- query = new TopiaQuery(UserAccount.class);
- PollenUtils.prepareQuery(query, filter);
-
- log.debug("Query : " + query);
-
- Assert.assertEquals(query.fullQuery(),
- "FROM " + UserAccount.class.getName() +
- " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
-
- }
-
- @Test
- public void testCreateQueryFindElementsByCollection() throws IOException {
-
- //TopiaQueryBuilder builder = new TopiaQueryBuilder();
-
- Filter filter = new Filter();
- filter.setStartIndex(1);
- filter.setEndIndex(40);
- filter.setOrderBy(FavoriteParticipant.NAME);
-
- EntityQueryProperty participantPropertyProvider =
- PollenUtils.getEntityQueryProperty(FavoriteParticipant.class, "P");
-
- EntityQueryProperty listPropertyProvider =
- PollenUtils.getEntityQueryProperty(FavoriteList.class, "L");
- listPropertyProvider.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT);
-
- log.info("test1 : orderBy FavoriteParticipant name");
- TopiaQuery result = PollenUtils.createQueryFindElementsByCollection(
- participantPropertyProvider, listPropertyProvider, filter);
-
- log.debug("Query : " + result);
-
- Assert.assertEquals(result.fullQuery(),
- "SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
- + FavoriteList.class.getName() + " L" +
- " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
- ") ORDER BY P." + FavoriteParticipant.NAME);
-
- log.info("test2 : orderBy not set (default to topiaCreateDate desc)");
- filter.setOrderBy(null);
-
- result = PollenUtils.createQueryFindElementsByCollection(
- participantPropertyProvider, listPropertyProvider, filter);
-
- log.debug("Query : " + result);
-
- Assert.assertEquals(result.fullQuery(),
- "SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
- + FavoriteList.class.getName() + " L" +
- " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
- ") ORDER BY P." + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
-
- log.info("test3 : orderBy name and email desc");
- String orderBy = FavoriteParticipant.NAME + ", " + FavoriteParticipant.EMAIL + " desc";
- filter.setOrderBy(orderBy);
-
- result = PollenUtils.createQueryFindElementsByCollection(
- participantPropertyProvider, listPropertyProvider, filter);
-
- log.debug("Query : " + result);
-
- Assert.assertEquals(result.fullQuery(),
- "SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
- + FavoriteList.class.getName() + " L" +
- " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
- ") ORDER BY P." + FavoriteParticipant.NAME + ", P." +
- FavoriteParticipant.EMAIL + " desc");
-
- }
-
-}
\ No newline at end of file
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-05-28 08:40:01 UTC (rev 3019)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-05-28 13:21:09 UTC (rev 3020)
@@ -4,17 +4,24 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenDAOHelper;
+import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.PollAccountDAO;
+import org.chorem.pollen.entity.PollAccountImpl;
import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.entity.Vote;
+import org.chorem.pollen.entity.VoteImpl;
import org.chorem.pollen.test.AbstractServiceTest;
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
/**
* Created: 27 mai 2010
@@ -32,27 +39,19 @@
}
@Test
- public void testCanVoteForGroupPoll()
+ public void testCanVoteForGroupPoll()
throws PollenBusinessException, TopiaException {
/** PREPARE DATA **/
UserAccount user = createUser(false);
- Poll pollCreated = createGroupPoll("Poll", user, 3, "Group1", "Group2");
+ Poll pollCreated = createGroupPoll("Poll", user, null, 3, "Group1", "Group2");
PollAccount group1 = pollCreated.getPollAccount().iterator().next();
PollAccount existingParticipant = group1.getChild().iterator().next();
// Reload the poll to really be unconnected (no loading of PollAccount)
- TopiaContext transaction = beginTransaction();
- Poll poll = null;
- try {
- poll = PollenDAOHelper.getPollDAO(transaction).
- findByTopiaId(pollCreated.getTopiaId());
- transaction.commitTransaction();
- } finally {
- transaction.closeContext();
- }
+ Poll poll = loadEntity(pollCreated);
/** EXEC METHOD **/
log.info("test 1 : participant found and can vote");
@@ -66,7 +65,7 @@
log.info("test 3 : existingParticipant can't vote, poll is closed");
poll.setClosed(true);
- transaction = beginTransaction();
+ TopiaContext transaction = beginTransaction();
try {
PollenDAOHelper.getPollDAO(transaction).update(poll);
transaction.commitTransaction();
@@ -77,4 +76,132 @@
result = serviceVote.canVote(poll, existingParticipant);
Assert.assertFalse(result);
}
+
+ @Test
+ public void testSaveVoteForFreePoll() throws PollenBusinessException, TopiaException {
+ /** PREPARE DATA **/
+ UserAccount user = createUser(false);
+
+ Poll pollCreated = createFreePoll("Poll", user, VoteCountingType.NORMAL);
+ List<Choice> choices =
+ addChoicesToPoll(pollCreated, ChoiceType.TEXT,
+ "choice1", "choice2", "choice3");
+
+ Poll poll = loadEntity(pollCreated);
+
+ // Instantiate new participant with votes
+ PollAccount participant = new PollAccountImpl();
+ participant.setName("participant");
+ participant.setEmail("participant(a)domain.org");
+ participant.setUserAccount(user);
+
+ Vote vote1 = new VoteImpl();
+ vote1.setChoice(choices.get(0)); // choice1
+ vote1.setVoteValue(1); // TRUE
+ participant.addChoiceVote(vote1);
+
+ Vote vote2 = new VoteImpl();
+ vote2.setChoice(choices.get(1)); // choice2
+ vote2.setVoteValue(0); // FALSE
+ participant.addChoiceVote(vote2);
+
+ Vote vote3 = new VoteImpl();
+ vote3.setChoice(choices.get(2)); // choice3
+ vote3.setVoteValue(1); // TRUE
+ participant.addChoiceVote(vote3);
+
+ /** EXEC METHOD **/
+
+ log.info("test 1 : new participant with 2 votes with value to 1");
+
+ String uid = serviceVote.saveVote(poll, participant);
+
+ TopiaContext transaction = beginTransaction();
+ try {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount accountFound = dao.findByNaturalId(uid);
+
+ Assert.assertNotNull(accountFound);
+ Assert.assertEquals(context.getCurrentDate(), accountFound.getVoteDate());
+ Assert.assertEquals(2, accountFound.getChoiceVote().size());
+ List<String> choicesExist = new ArrayList<String>();
+ for (Vote curr : accountFound.getChoiceVote()) {
+ Assert.assertEquals(1, curr.getVoteValue(), 0);
+ choicesExist.add(curr.getChoice().getName());
+ }
+
+ Assert.assertTrue(choicesExist.contains("choice1"));
+ Assert.assertTrue(choicesExist.contains("choice3"));
+
+ } finally {
+ transaction.closeContext();
+ }
+
+ log.info("test 2 : anonymous participant");
+ participant.setAnonymous(true);
+
+ uid = serviceVote.saveVote(poll, participant);
+ transaction = beginTransaction();
+ try {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount accountFound = dao.findByNaturalId(uid);
+ Assert.assertTrue(accountFound.isAnonymous());
+ Assert.assertNull(accountFound.getName());
+ Assert.assertNull(accountFound.getUserAccount());
+ Assert.assertNull(accountFound.getEmail());
+
+ // Update topiaId for next test
+ participant.setTopiaId(accountFound.getTopiaId());
+
+ } finally {
+ transaction.closeContext();
+ }
+
+ log.info("test 3 : update participant votes");
+
+ PollAccount participantExist =
+ loadEntity(participant, PollAccount.CHOICE_VOTE);
+
+ for (Vote vote : participantExist.getChoiceVote()) {
+ // Update choice 1 with value 0 -> will be deleted
+ if (vote.getChoice().equals(choices.get(0))) {
+ vote.setVoteValue(0);
+ }
+ }
+ // Add choice2
+ vote2 = new VoteImpl();
+ vote2.setChoice(choices.get(1));
+ vote2.setVoteValue(1); // TRUE
+ participantExist.addChoiceVote(vote2);
+
+ uid = serviceVote.saveVote(poll, participantExist);
+
+ transaction = beginTransaction();
+ try {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount accountFound = dao.findByNaturalId(uid);
+
+ Assert.assertEquals(context.getCurrentDate(), accountFound.getVoteDate());
+ Assert.assertEquals(2, accountFound.getChoiceVote().size());
+ List<String> choicesExist = new ArrayList<String>();
+ for (Vote curr : accountFound.getChoiceVote()) {
+ choicesExist.add(curr.getChoice().getName());
+ }
+
+ Assert.assertTrue(choicesExist.contains("choice2"));
+ Assert.assertTrue(choicesExist.contains("choice3"));
+
+ } finally {
+ transaction.closeContext();
+ }
+
+
+
+ }
}
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-28 08:40:01 UTC (rev 3019)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-28 13:21:09 UTC (rev 3020)
@@ -6,7 +6,11 @@
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenContextImpl;
import org.chorem.pollen.PollenDAOHelper;
+import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.entity.Choice;
+import org.chorem.pollen.entity.ChoiceDAO;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.FavoriteListDAO;
import org.chorem.pollen.entity.FavoriteParticipant;
@@ -35,8 +39,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
+import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.List;
import java.util.Properties;
/**
@@ -45,10 +51,7 @@
* Created: 24 févr. 2010
*
* @author fdesbois
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$
- * par : $Author$
+ * @version $Id$
*/
@Ignore
public abstract class AbstractServiceTest {
@@ -258,7 +261,8 @@
}
protected Poll createPoll(TopiaContext transaction,
- String title, UserAccount user, PollType type)
+ String title, UserAccount user,
+ PollType type, VoteCountingType voteCounting)
throws TopiaException {
PollAccountDAO accountDAO =
@@ -276,12 +280,54 @@
poll.setCreator(creator);
poll.setTitle(title);
poll.setPollType(type);
+ if (voteCounting == null) {
+ voteCounting = VoteCountingType.NORMAL;
+ }
+ poll.setVoteCountingType(voteCounting);
return poll;
}
+ public Poll createFreePoll(String title, UserAccount user, VoteCountingType voteCounting)
+ throws TopiaException {
+ TopiaContext transaction = beginTransaction();
+ try {
+ Poll poll = createPoll(transaction, title, user, PollType.FREE, voteCounting);
+
+ transaction.commitTransaction();
+
+ return poll;
+ } finally {
+ transaction.closeContext();
+ }
+ }
+
+ public List<Choice> addChoicesToPoll(Poll poll, ChoiceType choiceType, String... choices)
+ throws TopiaException {
+
+ TopiaContext transaction = beginTransaction();
+ try {
+ ChoiceDAO dao = PollenDAOHelper.getChoiceDAO(transaction);
+
+ poll.setChoiceType(choiceType);
+
+ for (String choice : choices) {
+ Choice newChoice = dao.create();
+ newChoice.setName(choice);
+ newChoice.setChoiceType(choiceType);
+ poll.addChoice(newChoice);
+ }
+
+ transaction.commitTransaction();
+
+ return poll.getChoice();
+ } finally {
+ transaction.closeContext();
+ }
+ }
+
public Poll createGroupPoll(String title,
- UserAccount user,
+ UserAccount user, VoteCountingType voteCounting,
int nbParticipantsByGroup,
String... groupNames)
throws TopiaException {
@@ -289,7 +335,7 @@
TopiaContext transaction = beginTransaction();
try {
- Poll poll = createPoll(transaction, title, user, PollType.GROUP);
+ Poll poll = createPoll(transaction, title, user, PollType.GROUP, voteCounting);
PollAccountDAO accountDAO =
PollenDAOHelper.getPollAccountDAO(transaction);
@@ -320,4 +366,27 @@
}
}
+ public <E extends TopiaEntity> E loadEntity(E source, String... properties)
+ throws TopiaException {
+
+ TopiaContext transaction = beginTransaction();
+ try {
+ TopiaQuery query = new TopiaQuery(source.getClass());
+ query.addLoad(properties).
+ addEquals(TopiaEntity.TOPIA_ID, source.getTopiaId()).
+ setMaxResults(1);
+
+ E result = (E)query.executeToEntity(transaction, source.getClass());
+
+ if (result != null) {
+ return result;
+ }
+
+ throw new NullPointerException("nothing to find... from " +
+ source.getTopiaId());
+ } finally {
+ transaction.closeContext();
+ }
+ }
+
}
Deleted: trunk/pollen-business/src/test/java/org/chorem/pollen/test/TestData.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/TestData.java 2010-05-28 08:40:01 UTC (rev 3019)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/TestData.java 2010-05-28 13:21:09 UTC (rev 3020)
@@ -1,40 +0,0 @@
-package org.chorem.pollen.test;
-
-import org.nuiton.topia.TopiaContext;
-
-/**
- * TestData
- *
- * Created: 24 févr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public abstract class TestData {
-
- protected TopiaContext transaction;
-
- public void execute() throws Exception {
- transaction = null;
- try {
- //transaction = beginTransaction();
-
- test();
-
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollbackTransaction();
- }
- throw eee;
- } finally {
- if (transaction != null) {
- transaction.closeContext();
- }
- }
- }
-
- protected abstract void test() throws Exception;
-}
1
0
r3019 - in trunk: pollen-business pollen-business/src/main/java/org/chorem/pollen/entity pollen-business/src/main/java/org/chorem/pollen/service pollen-business/src/main/xmi pollen-ui/src/main/java/org/chorem/pollen/ui/models pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll
by fdesbois@users.chorem.org 28 May '10
by fdesbois@users.chorem.org 28 May '10
28 May '10
Author: fdesbois
Date: 2010-05-28 10:40:01 +0200 (Fri, 28 May 2010)
New Revision: 3019
Url: http://chorem.org/repositories/revision/pollen/3019
Log:
- use EntityTransformer from ToPIA
- implement saveVote method (need javadoc and tests)
Modified:
trunk/pollen-business/pom.xml
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
Modified: trunk/pollen-business/pom.xml
===================================================================
--- trunk/pollen-business/pom.xml 2010-05-27 11:35:27 UTC (rev 3018)
+++ trunk/pollen-business/pom.xml 2010-05-28 08:40:01 UTC (rev 3019)
@@ -113,11 +113,17 @@
<defaultPackage>org.chorem.pollen</defaultPackage>
<templates>
org.nuiton.topia.generator.TopiaMetaTransformer,
+ org.nuiton.topia.generator.EntityTransformer,
org.nuiton.topia.generator.ServiceTransformer,
org.nuiton.eugene.java.JavaInterfaceTransformer,
org.nuiton.eugene.java.JavaBeanTransformer,
org.nuiton.topia.generator.BinderHelperTransformer
</templates>
+ <excludeTemplates>
+ <excludeTemplate>org.nuiton.topia.generator.EntityAbstractTransformer</excludeTemplate>
+ <excludeTemplate>org.nuiton.topia.generator.EntityImplTransformer</excludeTemplate>
+ <excludeTemplate>org.nuiton.topia.generator.EntityInterfaceTransformer</excludeTemplate>
+ </excludeTemplates>
</configuration>
<goals>
<goal>smart-generate</goal>
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java 2010-05-27 11:35:27 UTC (rev 3018)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java 2010-05-28 08:40:01 UTC (rev 3019)
@@ -1,7 +1,6 @@
package org.chorem.pollen.entity;
-import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenUtils;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
@@ -80,6 +79,6 @@
@Override
public boolean isRunning() {
- return isStarted() && !isFinished() && !getClosed();
+ return isStarted() && !isFinished() && !isClosed();
}
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-27 11:35:27 UTC (rev 3018)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-28 08:40:01 UTC (rev 3019)
@@ -3,27 +3,25 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.EntityQueryProperty;
-import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.PollenBinderHelper;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
import org.chorem.pollen.PollenUtils;
import org.chorem.pollen.bean.Filter;
-import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.PollAccountDAO;
import org.chorem.pollen.entity.PollAccountImpl;
import org.chorem.pollen.entity.PollDAO;
-import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.Vote;
import org.chorem.pollen.entity.VoteDAO;
import org.chorem.pollen.entity.VoteImpl;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.util.TopiaEntityBinder;
import java.util.List;
@@ -59,15 +57,34 @@
context.closeTransaction(transaction);
}
+ protected void copyPollAccount(PollAccount source, PollAccount destination) {
+
+ String[] excludes = null;
+
+ // Exclude properties for anonymous account
+ if (source.isAnonymous()) {
+ excludes = new String[]{
+ PollAccount.NAME,
+ PollAccount.EMAIL,
+ PollAccount.USER_ACCOUNT};
+ }
+
+ TopiaEntityBinder binder =
+ PollenBinderHelper.getSimpleTopiaBinder(PollAccount.class);
+
+ binder.copyExcluding(source, destination, excludes);
+ }
+
@Override
protected boolean executeCanVote(TopiaContext transaction,
Poll poll,
- PollAccount participant) throws Exception {
+ PollAccount participant)
+ throws TopiaException {
if (log.isDebugEnabled()) {
log.debug("Poll started : " + poll.isStarted());
log.debug("Poll finished : " + poll.isFinished());
- log.debug("Poll closed : " + poll.getClosed());
+ log.debug("Poll closed : " + poll.isClosed());
}
boolean result = true;
if (!poll.isRunning()) {
@@ -120,31 +137,6 @@
participant
);
-// TopiaQuery query = dao.createQuery("participant").
-// addFrom(Poll.class, "poll").
-// addEquals("poll", poll);
-//
-// // By default the parentCollection is pollAccount in poll
-// String parentCollectionProperty =
-// TopiaQuery.getProperty("poll", Poll.POLL_ACCOUNT);
-//
-// if (poll.getPollType().isGroup()) {
-// query.addFrom(PollAccount.class, "group").
-// // It's not really necessary, but better to be sure
-// addEquals("group." + PollAccount.LIST, Boolean.TRUE).
-// addInElements("group", parentCollectionProperty);
-//
-// // In case of group, the parentCollection is the child
-// // pollAccount from the list
-// parentCollectionProperty =
-// TopiaQuery.getProperty("group", PollAccount.CHILD);
-// }
-//
-// // Add link between the Account to find and his parent
-// query.addInElements("participant", parentCollectionProperty).
-// addEquals("participant." + TopiaEntity.TOPIA_ID,
-// participant.getTopiaId());
-
if (log.isDebugEnabled()) {
log.debug("Query : " + query);
}
@@ -161,8 +153,14 @@
}
@Override
- protected PollAccount executeGetPollAccount(TopiaContext transaction, String accountUid) throws Exception {
- return null;
+ protected PollAccount executeGetPollAccount(TopiaContext transaction,
+ String accountUid)
+ throws Exception {
+
+ PollAccount result = PollenDAOHelper.getPollAccountDAO(transaction).
+ findByUid(accountUid);
+
+ return result;
}
@Override
@@ -205,24 +203,109 @@
}
@Override
- protected void executeSaveVote(TopiaContext transaction, Poll poll,
+ protected String executeSaveVote(TopiaContext transaction, Poll poll,
PollAccount participant)
- throws PollenBusinessException {
+ throws TopiaException {
// 1- executeCanVote(transaction, poll, participant);
// 2- generate uid if needed
// 3- update or create participant
// 4- add participant in the poll if needed
- // 5- save only votes with voteValue != 0 : update or votes
- // 6- maybe execute calcul for continuousResults poll
+ // 5- save only votes with voteValue != 0 : update/create/delete
+ // 6- execute calcul for continuousResults poll
// NEED test :
// need existing poll with choices
// getNewPollAccount
// set some votes for poll choices
// saveVote
-
-
+ String result = null;
+ if (executeCanVote(transaction, poll, participant)) {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount participantToSave =
+ dao.findByTopiaId(participant.getTopiaId());
+
+ // canVote method check the existence of participant for a
+ // restricted poll, so the create case is only for FREE poll.
+ if (participantToSave == null) {
+ participantToSave = createNewParticipant(transaction, poll);
+ }
+
+ // Copy data (care about anonymous case)
+ copyPollAccount(participant, participantToSave);
+
+ // Update vote date
+ participantToSave.setVoteDate(context.getCurrentDate());
+
+ // Save votes
+ saveParticipantVotes(transaction, participant, participantToSave);
+
+ dao.update(participantToSave);
+
+ result = participantToSave.getUid();
+
+ // TODO-fdesbois-2010-05-27 : execute vote counting if poll.isContinuousResults()
+
+ transaction.commitTransaction();
+ } else {
+ // maybe throw exception
+ }
+
+ return result;
}
+
+ protected PollAccount createNewParticipant(TopiaContext transaction,
+ Poll poll)
+ throws TopiaException {
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ // Generate new uid
+ String newUid = context.createPollenUrlId();
+ PollAccount newParticipant = dao.create(newUid);
+
+ // Add the new participant in poll
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(transaction);
+
+ Poll pollFound = pollDAO.findByTopiaId(poll.getTopiaId());
+ pollFound.addPollAccount(newParticipant);
+
+ pollDAO.update(pollFound);
+ return newParticipant;
+ }
+
+ protected void saveParticipantVotes(TopiaContext transaction,
+ PollAccount source,
+ PollAccount destination)
+ throws TopiaException {
+
+ VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
+ for (Vote vote : source.getChoiceVote()) {
+
+ Vote voteToSave = voteDAO.findByTopiaId(vote.getTopiaId());
+
+ if (vote.getVoteValue() != 0) {
+ // Create vote
+ if (voteToSave == null) {
+ voteToSave = voteDAO.create();
+ voteToSave.setChoice(vote.getChoice());
+ // Add new vote to destination participant
+ destination.addChoiceVote(voteToSave);
+ }
+
+ // Update vote
+ voteToSave.setVoteValue(vote.getVoteValue());
+ voteDAO.update(voteToSave);
+
+ // Delete vote if exist and new value is 0
+ } else if (voteToSave != null) {
+ // Normally the vote will be removed from ChoiceVote list in
+ // pollAccount.
+ voteDAO.delete(voteToSave);
+ }
+ }
+ }
}
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-27 11:35:27 UTC (rev 3018)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-28 08:40:01 UTC (rev 3019)
@@ -4,7 +4,6 @@
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.ioc.Messages;
import org.chorem.pollen.PollenBusinessException;
-import org.chorem.pollen.PollenException;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.Choice;
@@ -363,7 +362,7 @@
}
// Add choices is allowed after creation
- if (poll.getChoiceAddAllowed()) {
+ if (poll.isChoiceAddAllowed()) {
// Initialize beginChoiceDate if needed
Date beginChoiceDate = poll.getBeginChoiceDate();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-05-27 11:35:27 UTC (rev 3018)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-05-28 08:40:01 UTC (rev 3019)
@@ -486,7 +486,7 @@
creator = poll.getCreator();
// creator = servicePollAccount.findPollAccountById(poll
// .getCreatorId());
- if (poll.getPublicResults()) {
+ if (poll.isPublicResults()) {
userAllowed = true;
} else if (id.split(":", 2).length == 2) {
String creatorId = id.split(":", 2)[1];
@@ -502,7 +502,7 @@
feedback.addError(messages.get("pollNotFound"));
} else if (!userAllowed) {
feedback.addError(messages.get("userNotAllowed"));
- } else if (!poll.getClosed()) {
+ } else if (!poll.isClosed()) {
feedback.addError(messages.get("pollNotClosed"));
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-27 11:35:27 UTC (rev 3018)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-28 08:40:01 UTC (rev 3019)
@@ -18,18 +18,14 @@
import java.text.DateFormat;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventContext;
-import org.apache.tapestry5.Link;
-import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -47,7 +43,6 @@
import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.Vote;
-import org.chorem.pollen.entity.VoteImpl;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.service.ServiceUser;
import org.chorem.pollen.service.ServiceVote;
@@ -157,7 +152,7 @@
// poll = null;
// getPoll();
//
-// if (getPoll().getClosed()) {
+// if (getPoll().isClosed()) {
// addInfo(messages.get("pollClosed"));
// } else if (!isPollStarted()) {
// addInfo(messages.get("pollNotStarted"));
@@ -400,7 +395,7 @@
//// }
//
// public boolean isPollChoiceRunning() throws PollenBusinessException {
-// return getPoll().getChoiceAddAllowed() && isPollChoiceStarted();
+// return getPoll().isChoiceAddAllowed() && isPollChoiceStarted();
// }
//
// /**
@@ -606,7 +601,7 @@
// */
// @Deprecated
// public boolean isAccountFieldDisplayed() throws PollenBusinessException {
-// return !getPoll().getAnonymous() || isRestrictedPoll() || isGroupPoll();
+// return !getPoll().isAnonymous() || isRestrictedPoll() || isGroupPoll();
// }
public boolean getCanVote() {
@@ -614,7 +609,7 @@
if (poll.isFinished()) {
return false;
}
- if (poll.getPollType().isRestrictedOrGroup() || poll.getAnonymous()) {
+ if (poll.getPollType().isRestrictedOrGroup() || poll.isAnonymous()) {
return serviceVote.canVote(poll, pollAccount);
}
return true;
1
0
r3018 - in trunk/pollen-business/src: main/java/org/chorem/pollen/service main/xmi test/java/org/chorem/pollen test/java/org/chorem/pollen/service test/java/org/chorem/pollen/test test/resources
by fdesbois@users.chorem.org 27 May '10
by fdesbois@users.chorem.org 27 May '10
27 May '10
Author: fdesbois
Date: 2010-05-27 13:35:27 +0200 (Thu, 27 May 2010)
New Revision: 3018
Url: http://chorem.org/repositories/revision/pollen/3018
Log:
- Repair mistake in query test
- Implement canVote method + JUnit test for GROUP case
Added:
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-business/src/main/xmi/pollen.properties
trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
trunk/pollen-business/src/test/resources/log4j.properties
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-27 09:27:44 UTC (rev 3017)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-27 11:35:27 UTC (rev 3018)
@@ -1,16 +1,21 @@
package org.chorem.pollen.service;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.EntityQueryProperty;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
+import org.chorem.pollen.PollenUtils;
import org.chorem.pollen.bean.Filter;
+import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.PollAccountDAO;
import org.chorem.pollen.entity.PollAccountImpl;
+import org.chorem.pollen.entity.PollDAO;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.Vote;
import org.chorem.pollen.entity.VoteDAO;
@@ -18,6 +23,7 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaEntity;
import java.util.List;
@@ -29,6 +35,8 @@
*/
public class ServiceVoteImpl extends ServiceVoteAbstract {
+ private static final Log log = LogFactory.getLog(ServiceVoteImpl.class);
+
private PollenContext context;
public void setContext(PollenContext context) {
@@ -52,9 +60,98 @@
}
@Override
- protected boolean executeCanVote(TopiaContext transaction, Poll poll,
+ protected boolean executeCanVote(TopiaContext transaction,
+ Poll poll,
PollAccount participant) throws Exception {
- return false;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Poll started : " + poll.isStarted());
+ log.debug("Poll finished : " + poll.isFinished());
+ log.debug("Poll closed : " + poll.getClosed());
+ }
+ boolean result = true;
+ if (!poll.isRunning()) {
+ if (log.isInfoEnabled()) {
+ log.info("Poll is no longer running... Participant can't vote");
+ }
+ result = false;
+ } else if (poll.getPollType().isRestrictedOrGroup()) {
+ if (log.isInfoEnabled()) {
+ log.info("Poll is restricted... Participant need to be identified");
+ }
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ EntityQueryProperty participantProperty =
+ PollenUtils.getEntityQueryProperty("A");
+ EntityQueryProperty pollProperty =
+ PollenUtils.getEntityQueryProperty("P");
+ EntityQueryProperty groupProperty =
+ PollenUtils.getEntityQueryProperty("G");
+
+ TopiaQuery query = dao.createQuery(participantProperty.name()).
+ addFrom(Poll.class, pollProperty.name()).
+ addEquals(pollProperty.name(), poll);
+
+ // By default the parentCollection is pollAccount in poll
+ String parentCollectionProperty =
+ pollProperty.nameProperty(Poll.POLL_ACCOUNT);
+
+ if (poll.getPollType().isGroup()) {
+ // Add the group into the query
+ query.addFrom(PollAccount.class, groupProperty.name()).
+ // It's not really necessary, but better to be sure
+ addEquals(groupProperty.nameProperty(PollAccount.LIST),
+ Boolean.TRUE).
+ // Add link between the group and the poll
+ addInElements(groupProperty.name(), parentCollectionProperty);
+
+ // In case of group, the parentCollection is the child
+ // pollAccount from the group
+ parentCollectionProperty =
+ groupProperty.nameProperty(PollAccount.CHILD);
+ }
+
+ // Add link between the participant to find and his parent
+ query.addInElements(participantProperty.name(), parentCollectionProperty).
+ addEquals(participantProperty.name(), participant).
+ addWhere(pollProperty.nameProperty(Poll.CREATOR),
+ TopiaQuery.Op.NEQ,
+ participant
+ );
+
+// TopiaQuery query = dao.createQuery("participant").
+// addFrom(Poll.class, "poll").
+// addEquals("poll", poll);
+//
+// // By default the parentCollection is pollAccount in poll
+// String parentCollectionProperty =
+// TopiaQuery.getProperty("poll", Poll.POLL_ACCOUNT);
+//
+// if (poll.getPollType().isGroup()) {
+// query.addFrom(PollAccount.class, "group").
+// // It's not really necessary, but better to be sure
+// addEquals("group." + PollAccount.LIST, Boolean.TRUE).
+// addInElements("group", parentCollectionProperty);
+//
+// // In case of group, the parentCollection is the child
+// // pollAccount from the list
+// parentCollectionProperty =
+// TopiaQuery.getProperty("group", PollAccount.CHILD);
+// }
+//
+// // Add link between the Account to find and his parent
+// query.addInElements("participant", parentCollectionProperty).
+// addEquals("participant." + TopiaEntity.TOPIA_ID,
+// participant.getTopiaId());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Query : " + query);
+ }
+
+ result = dao.existByQuery(query);
+ }
+ return result;
}
@Override
Modified: trunk/pollen-business/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-business/src/main/xmi/pollen.properties 2010-05-27 09:27:44 UTC (rev 3017)
+++ trunk/pollen-business/src/main/xmi/pollen.properties 2010-05-27 11:35:27 UTC (rev 3018)
@@ -1,5 +1,7 @@
# Pr\u00e9cise l'ent\u00eate de l'ensemble des fichiers g\u00e9n\u00e9r\u00e9s
model.tagvalue.copyright=/* *##%\n Copyright (C) 2009 Pollen\n *##%*/
+# toString are particularly difficult to use because of lazy initialization
+model.tagvalue.notGenerateToString=true
#model.tagvalue.dbSchema=Pollen
model.tagvalue.java.lang.String=text
model.tagvalue.exceptionClass=org.chorem.pollen.PollenException
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-27 09:27:44 UTC (rev 3017)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-27 11:35:27 UTC (rev 3018)
@@ -84,7 +84,7 @@
Assert.assertEquals(result.fullQuery(),
"SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ FavoriteList.class.getName() + " L" +
- " WHERE P IN elements (L." + FavoriteList.FAVORITE_PARTICIPANT +
+ " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
") ORDER BY P." + FavoriteParticipant.NAME);
log.info("test2 : orderBy not set (default to topiaCreateDate desc)");
@@ -98,7 +98,7 @@
Assert.assertEquals(result.fullQuery(),
"SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ FavoriteList.class.getName() + " L" +
- " WHERE P IN elements (L." + FavoriteList.FAVORITE_PARTICIPANT +
+ " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
") ORDER BY P." + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
log.info("test3 : orderBy name and email desc");
@@ -113,7 +113,7 @@
Assert.assertEquals(result.fullQuery(),
"SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ FavoriteList.class.getName() + " L" +
- " WHERE P IN elements (L." + FavoriteList.FAVORITE_PARTICIPANT +
+ " WHERE P IN elements(L." + FavoriteList.FAVORITE_PARTICIPANT +
") ORDER BY P." + FavoriteParticipant.NAME + ", P." +
FavoriteParticipant.EMAIL + " desc");
Added: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java (rev 0)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-05-27 11:35:27 UTC (rev 3018)
@@ -0,0 +1,80 @@
+package org.chorem.pollen.service;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.PollenDAOHelper;
+import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.entity.PollAccount;
+import org.chorem.pollen.entity.PollAccountDAO;
+import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.test.AbstractServiceTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+
+import java.util.Iterator;
+
+/**
+ * Created: 27 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ServiceVoteImplTest extends AbstractServiceTest {
+
+ private static final Log log = LogFactory.getLog(ServiceVoteImplTest.class);
+
+ @Override
+ protected void init() throws Exception {
+ getServiceVote();
+ }
+
+ @Test
+ public void testCanVoteForGroupPoll()
+ throws PollenBusinessException, TopiaException {
+
+ /** PREPARE DATA **/
+ UserAccount user = createUser(false);
+
+ Poll pollCreated = createGroupPoll("Poll", user, 3, "Group1", "Group2");
+
+ PollAccount group1 = pollCreated.getPollAccount().iterator().next();
+ PollAccount existingParticipant = group1.getChild().iterator().next();
+
+ // Reload the poll to really be unconnected (no loading of PollAccount)
+ TopiaContext transaction = beginTransaction();
+ Poll poll = null;
+ try {
+ poll = PollenDAOHelper.getPollDAO(transaction).
+ findByTopiaId(pollCreated.getTopiaId());
+ transaction.commitTransaction();
+ } finally {
+ transaction.closeContext();
+ }
+
+ /** EXEC METHOD **/
+ log.info("test 1 : participant found and can vote");
+ boolean result = serviceVote.canVote(poll, existingParticipant);
+ Assert.assertTrue(result);
+
+ log.info("test 2 : poll creator can't vote");
+ result = serviceVote.canVote(poll, poll.getCreator());
+ Assert.assertFalse(result);
+
+ log.info("test 3 : existingParticipant can't vote, poll is closed");
+ poll.setClosed(true);
+
+ transaction = beginTransaction();
+ try {
+ PollenDAOHelper.getPollDAO(transaction).update(poll);
+ transaction.commitTransaction();
+ } finally {
+ transaction.closeContext();
+ }
+
+ result = serviceVote.canVote(poll, existingParticipant);
+ Assert.assertFalse(result);
+ }
+}
Property changes on: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-27 09:27:44 UTC (rev 3017)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-27 11:35:27 UTC (rev 3018)
@@ -1,25 +1,26 @@
package org.chorem.pollen.test;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenContextImpl;
import org.chorem.pollen.PollenDAOHelper;
+import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.FavoriteListDAO;
import org.chorem.pollen.entity.FavoriteParticipant;
import org.chorem.pollen.entity.FavoriteParticipantDAO;
+import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.entity.PollAccount;
+import org.chorem.pollen.entity.PollAccountDAO;
+import org.chorem.pollen.entity.PollDAO;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.UserAccountDAO;
import org.chorem.pollen.service.ServiceFavoriteImpl;
import org.chorem.pollen.service.ServicePollImpl;
import org.chorem.pollen.service.ServiceUserImpl;
+import org.chorem.pollen.service.ServiceVoteImpl;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
@@ -31,16 +32,23 @@
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.ApplicationConfig;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Properties;
+
/**
* TestManager
- *
+ * <p/>
* Created: 24 févr. 2010
*
* @author fdesbois
* @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
+ * <p/>
+ * Mise a jour: $Date$
+ * par : $Author$
*/
@Ignore
public abstract class AbstractServiceTest {
@@ -55,6 +63,8 @@
protected ServicePollImpl servicePoll;
+ protected ServiceVoteImpl serviceVote;
+
@Rule
public TestName rule = new TestName() {
@@ -97,7 +107,7 @@
// Set currentDate to 23/02/2010 for tests
Calendar calendar = new GregorianCalendar(2010, 1, 23, 0, 0, 0);
- ((PollenContextImpl)getContext()).setCurrentDate(calendar.getTime());
+ ((PollenContextImpl) getContext()).setCurrentDate(calendar.getTime());
}
@After
@@ -140,6 +150,14 @@
return servicePoll;
}
+ public ServiceVoteImpl getServiceVote() {
+ if (serviceVote == null) {
+ serviceVote = new ServiceVoteImpl();
+ serviceVote.setContext(getContext());
+ }
+ return serviceVote;
+ }
+
public TopiaContext beginTransaction() throws TopiaException {
return getContext().beginTransaction();
}
@@ -157,13 +175,9 @@
// }
/**
- * Create a user :<br />
- * <ul>
- * <li>login : homer</li>
- * <li>email : homer(a)simpson.us</li>
- * <li>password : wouhou</li>
- * </ul>
- * You can decide if this user is an admin using {@code admin} argument.
+ * Create a user :<br /> <ul> <li>login : homer</li> <li>email :
+ * homer(a)simpson.us</li> <li>password : wouhou</li> </ul> You can decide if
+ * this user is an admin using {@code admin} argument.
*
* @param admin flag to create the user as an admin
* @return the new UserAccount created
@@ -184,7 +198,7 @@
TopiaContext transaction = getContext().beginTransaction();
try {
UserAccountDAO dao =
- PollenDAOHelper.getUserAccountDAO(transaction);
+ PollenDAOHelper.getUserAccountDAO(transaction);
UserAccount findUser = dao.findByLogin(user.getLogin());
return findUser;
@@ -210,7 +224,7 @@
}
public FavoriteParticipant createFavoriteParticipant(String name,
- String email, FavoriteList list) throws TopiaException {
+ String email, FavoriteList list) throws TopiaException {
TopiaContext transaction = beginTransaction();
try {
FavoriteParticipantDAO dao =
@@ -243,4 +257,67 @@
}
}
+ protected Poll createPoll(TopiaContext transaction,
+ String title, UserAccount user, PollType type)
+ throws TopiaException {
+
+ PollAccountDAO accountDAO =
+ PollenDAOHelper.getPollAccountDAO(transaction);
+
+ PollAccount creator = accountDAO.create(context.createPollenUrlId());
+ creator.setName(user.getDisplayName());
+ creator.setEmail(user.getEmail());
+ creator.setUserAccount(user);
+ creator.setAdmin(true);
+
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(transaction);
+
+ Poll poll = pollDAO.create(context.createPollenUrlId());
+ poll.setCreator(creator);
+ poll.setTitle(title);
+ poll.setPollType(type);
+
+ return poll;
+ }
+
+ public Poll createGroupPoll(String title,
+ UserAccount user,
+ int nbParticipantsByGroup,
+ String... groupNames)
+ throws TopiaException {
+
+ TopiaContext transaction = beginTransaction();
+ try {
+
+ Poll poll = createPoll(transaction, title, user, PollType.GROUP);
+
+ PollAccountDAO accountDAO =
+ PollenDAOHelper.getPollAccountDAO(transaction);
+
+ for (String groupName : groupNames) {
+ PollAccount group = accountDAO.create(context.createPollenUrlId());
+ group.setName(groupName);
+ group.setList(true);
+
+ for (int i = 1; i <= nbParticipantsByGroup; i++) {
+ PollAccount participant =
+ accountDAO.create(context.createPollenUrlId());
+ participant.setName(groupName + "_participant" + i);
+ participant.setEmail(groupName + "_email" + i + "@domain.org");
+ participant.setWeight(1.);
+ group.addChild(participant);
+ }
+
+ poll.addPollAccount(group);
+ }
+
+ transaction.commitTransaction();
+
+ return poll;
+
+ } finally {
+ transaction.closeContext();
+ }
+ }
+
}
Modified: trunk/pollen-business/src/test/resources/log4j.properties
===================================================================
--- trunk/pollen-business/src/test/resources/log4j.properties 2010-05-27 09:27:44 UTC (rev 3017)
+++ trunk/pollen-business/src/test/resources/log4j.properties 2010-05-27 11:35:27 UTC (rev 3018)
@@ -8,7 +8,7 @@
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%p] %c{2} %m%n
-log4j.logger.org.chorem.pollen=info
+log4j.logger.org.chorem.pollen=debug
log4j.logger.org.chorem.pollen.business.PollenContextImpl=warn
log4j.logger.org.chorem.pollen.business.services.SendMail=warn
1
0
Author: fdesbois
Date: 2010-05-27 11:27:44 +0200 (Thu, 27 May 2010)
New Revision: 3017
Url: http://chorem.org/repositories/revision/pollen/3017
Log:
Reorganize doc + add business-rules
Added:
trunk/doc/ALMA-PFE-2009/
trunk/doc/ALMA-PFE-2009/Analyse.odt
trunk/doc/ALMA-PFE-2009/Architecture.odt
trunk/doc/ALMA-PFE-2009/Conception.odt
trunk/doc/ALMA-PFE-2009/Gestion projet.odt
trunk/doc/ALMA-PFE-2009/Infrastructure.odt
trunk/doc/ALMA-PFE-2009/pollen-slides.odp
trunk/doc/Stage-2009/
trunk/doc/Stage-2009/rapportRannou.odt
trunk/doc/business-rules.rst
Added: trunk/doc/ALMA-PFE-2009/Analyse.odt
===================================================================
(Binary files differ)
Property changes on: trunk/doc/ALMA-PFE-2009/Analyse.odt
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/ALMA-PFE-2009/Architecture.odt
===================================================================
(Binary files differ)
Property changes on: trunk/doc/ALMA-PFE-2009/Architecture.odt
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/ALMA-PFE-2009/Conception.odt
===================================================================
(Binary files differ)
Property changes on: trunk/doc/ALMA-PFE-2009/Conception.odt
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/ALMA-PFE-2009/Gestion projet.odt
===================================================================
(Binary files differ)
Property changes on: trunk/doc/ALMA-PFE-2009/Gestion projet.odt
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/ALMA-PFE-2009/Infrastructure.odt
===================================================================
(Binary files differ)
Property changes on: trunk/doc/ALMA-PFE-2009/Infrastructure.odt
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/ALMA-PFE-2009/pollen-slides.odp
===================================================================
(Binary files differ)
Property changes on: trunk/doc/ALMA-PFE-2009/pollen-slides.odp
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/Stage-2009/rapportRannou.odt
===================================================================
(Binary files differ)
Property changes on: trunk/doc/Stage-2009/rapportRannou.odt
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/doc/business-rules.rst
===================================================================
--- trunk/doc/business-rules.rst (rev 0)
+++ trunk/doc/business-rules.rst 2010-05-27 09:27:44 UTC (rev 3017)
@@ -0,0 +1,200 @@
+Règles métiers
+==============
+
+:Author: fdesbois <pollen-devel(a)codelutin.com>
+:Date: 2010-05-26
+:Version: 1.0
+
+Ce document a pour but de cataloguer l'ensemble des règles métiers de l'application Pollen.
+Ces règles dépendent principalement des options du sondage.
+
+Avant-propos
+------------
+
+Pollen fonctionne via des urls générés pour l'accès au sondage. Ces urls sont nécessaires lorsqu'une personne n'a pas de compte
+utilisateur. Une classe correspond à cette uri pour Pollen : PollUri. Elle contient à la fois l'uid (identifiant unique) du sondage et celui d'un compte sondage (PollAccount). Ce dernier peut correspondre au créateur du sondage ou à un votant.
+
+Options du sondage
+------------------
+
+- beginDate : date de début du sondage
+
+ * aucun vote possible avant cette date
+
+- endDate : date de fin du sondage
+
+ * aucun vote possible après cette date
+
+- maxChoiceNb : nombre de choix maximum par vote
+
+ * aucun vote possible avec plus de choix qu'indiqué par cette option.
+ * par défaut autant de choix sont possibles < nombre de choix du sondage
+ * option utilisé uniquement pour un dépouillement NORMAL (trop complexe pour CONDORCET, inutile pour POURCENTAGE et NUMBER)
+
+- closed : indique que le sondage est clos
+
+ * aucun vote possible
+ * aucune modification des votes existants possible
+ * aucune modification du sondage possible (choix, votants, options...)
+ * seul possibilité : lecture résultats et execution different algos de dépouillement si possible (dépend du type de dépouillement configuré dans le sondage)
+
+- choiceAddAllowed : indique que l'ajout de choix est permis par les votants uniquement
+
+ * la possibilité de voter dépend des dates du sondage et non celle des choix
+ * la permission d'ajout de choix est fortement correlé aux dates beginChoiceDate et endChoiceDate
+ * Note : attention au vote pendant l'ajout de choix : comportement bizarre sur certains dépouillement (voir Ano #139)
+
+- anonymousVoteAllowed : indique que le vote peut etre anonyme
+
+ * les champs name, email et userAccount ne sont pas persistés (restés à null)
+ * plus de notifications possibles par email
+
+- anonymous : indique que le sondage reste anonyme (choix des votes et nom des votants)
+
+ * idem que l'option précédent. Seule l'UI ne chargera pas les valeurs des votes
+
+- publicResults : indique que les résultats sont accessibles par n'importe qui
+
+ * accès a la page de résultats pour tout le monde
+ * si l'option n'est pas enregistré, les résultats ne sont accessibles que par le créateur du sondage : accès restreint à la page des résultats (uid du créateur nécessaire).
+ * Note : il n'y a pas de juste milieu entre le créateur et le visiteur, remarque seul un visiteur connaissant l'url du sondage pourra accéder aux résultats.
+
+- continuousResults : indique l'affichage en continu des résultats
+
+ * besoin de dépouillement à chaque vote
+ * les résultats sont obligatoirement publiques
+
+- voteCounting : type de dépouillement
+
+ * Dépouillement POURCENTAGE : somme des choix = 100% / possibilité de choix vide = 0
+ * Dépouillement NUMBER : uniquement nombre (entier ou non) / possibilité de choix vide = null
+ * Dépouillement CONDORCET : uniquement des nombres entiers / possibilité de choix vide = null
+ * Dépouillement NORMAL : uniquement des booléens (vrai/faux) / possibilité de choix vide = null
+
+- type : type de sondage
+
+ * Sondage restreint (RESTRICTED ou GROUP)
+
+ # accès du vote nécessitant un uid généré à la création du sondage
+ # possibilité de modifier/supprimer son vote
+ # email des votants obligatoires à la création du sondage
+ # liaison entre le votant et le compte utilisateur si connecté (au moment du vote)
+
+ * Sondage libre (FREE)
+
+ # accès du vote libre
+ # possibilité de modifier/supprimer son vote avec l'uid généré au moment du vote
+ # possibilité d'ajouter son email au moment du vote
+ # liaison entre le votant et le compte utilisateur si connecté (au moment du vote)
+
+- choiceType : type de choix (en attente)
+
+- preventRules : notifications par email (voir plus loin)
+
+- creator : Créateur du sondage (PollAccount)
+
+ * Sans compte utilisateur
+
+ # email non obligatoire
+ # envoie d'email si indiqué (au créateur et la/les liste(s) restreinte(s))
+
+ * Avec compte utilisateur
+
+ # même possibilités que sans compte
+ # accès aux listes de favoris pour les sondages restreints (RESTRICTED et GROUP)
+ # liaison physique entre le créateur (PollAccount) et l'utilisateur connecté (UserAccount)
+
+Validation du vote
+------------------
+
+- beginDate < now
+- endDate > now
+- closed = false
+- uid de vote autorisé (RESTRICTED/GROUP)
+- valeur des choix autorisé (dépend du type de dépouillement)
+- nombre de choix < maxChoiceNb
+
+Vote
+----
+
+- nom du votant
+- email du votant (non obligatoire) : uniquement si le votant est non connecté et sur un sondage FREE
+- anonymousVoteAllowed: option anonyme disponible
+
+Enregistrement du vote
+----------------------
+
+- anonymous/anonymousVoteAllowed : pas de sauvegarde nom/email/compte utilisateur
+- continuousResults : nécessite un depouillement
+- type = FREE : génération de l'uid (nécessaire pour modification du vote)
+- enregistrement flux RSS
+- envoie email si disponible (PollAccount ou UserAccount)
+
+Accès
+-----
+
+- Création du sondage : pollUri = null
+- Modification du sondage : pollUri = pollUid / creatorUid ou ADMIN
+- Suppression du sondage : pollUri = pollUid / creatorUid ou ADMIN
+
+- Ajout d'un vote : pollUri = pollUid / participantUid (RESTRICTED/GROUP) ou null (FREE)
+- Modification d'un vote : pollUri = pollUid / participantUid ou ADMIN
+- Suppression d'un vote : pollUri = pollUid / participantUid ou creatorUid ou ADMIN
+
+- Ajout d'un choix : même chose que pour l'ajout d'un vote
+- Suppression d'un choix : pollUri = pollUid / creatorUid ou ADMIN
+- Modification d'un choix : fait à partir de la modification du sondage
+
+- Ajout d'un commentaire : pollUri = pollUid / creatorUid ou participantUid ou null ?
+- Suppression d'un commentaire : pollUri = pollUid / creatorUid ou ADMIN
+
+- Voir résultats : (PUBLIC_RESULTS = true) pollUri = pollUid
+- Voir résultats : (PUBLIC_RESULTS = false) pollUri = pollUid / creatorUid ou ADMIN
+- Executer un dépouillement : pollUri = pollUid / creatorUid
+
+Notifications
+-------------
+
+Deux modes de notification indépendants : email et rss.
+
+- Création sondage : [email : createur / participants (RESTRICTED/GROUP)]
+
+- Modification sondage : [email : participants ?]
+
+- Gestion choix : [rss] [email : createur ? / participants ?]
+
+- Vote : [rss] [email : createur (configuration) / participant non connecté avec email (FREE)] --> Notifier
+
+- Avant fin du sondage (background) : [email : participants sans vote (RESTRICTED/GROUP)] --> Reminder
+
+- Fin du sondage : [rss] [email : createur / participants]
+
+- Execution premier dépouillement (PUBLIC_RESULTS && !CONTINUOUS_RESULTS) : [rss] [email : participants]
+
+- Commentaire : [rss] [email : createur ? / participants ?]
+
+Note :
+ Fusion possible entre fin du sondage et premier dépouillement pour l'envoie d'email aux participants
+
+Note :
+ Les cas avec des ? ne sont pas forcément utiles à cause du suivi rss
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Property changes on: trunk/doc/business-rules.rst
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r3016 - in trunk/pollen-business/src: main/java/org/chorem/pollen main/java/org/chorem/pollen/mail main/java/org/chorem/pollen/service main/xmi test/java/org/chorem/pollen/test
by fdesbois@users.chorem.org 27 May '10
by fdesbois@users.chorem.org 27 May '10
27 May '10
Author: fdesbois
Date: 2010-05-27 11:15:16 +0200 (Thu, 27 May 2010)
New Revision: 3016
Url: http://chorem.org/repositories/revision/pollen/3016
Log:
Refactor TopiaQuery method name from last change in ToPIA
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
trunk/pollen-business/src/main/java/org/chorem/pollen/mail/SendMail.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-05-26 10:08:22 UTC (rev 3015)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-05-27 09:15:16 UTC (rev 3016)
@@ -137,7 +137,7 @@
}
if (StringUtils.isNotEmpty(referenceId) && reference != null) {
- query.add(reference.namePropertyId(), referenceId);
+ query.addEquals(reference.namePropertyId(), referenceId);
}
}
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/mail/SendMail.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/mail/SendMail.java 2010-05-26 10:08:22 UTC (rev 3015)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/mail/SendMail.java 2010-05-27 09:15:16 UTC (rev 3016)
@@ -48,7 +48,7 @@
*
* For a mass mail sending to start, following files must be present:
* <ul>
- * <li>xxx.emails : CSV file ("email", "subject", "body")</li>
+ * <li>xxx.mail : CSV file ("email", "subject", "body")</li>
* <li>xxx.index : next index to manage ( inited at 0)</li>
* </ul>
*
@@ -182,7 +182,7 @@
// index contains next index to treat
FileUtils.writeStringToFile(indexFile, String.valueOf(currentIndex + 1));
- // wait 2 secondes between each mail to not
+ // wait 1 second between each mail to not
// load smtp server
try {
Thread.sleep(1000);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-26 10:08:22 UTC (rev 3015)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-27 09:15:16 UTC (rev 3016)
@@ -130,13 +130,13 @@
FavoriteList list = participant.getFavoriteList();
TopiaQuery query = dao.createQuery().
- add(FavoriteParticipant.FAVORITE_LIST, list).
- add(FavoriteParticipant.NAME, participant.getName()).
- add(FavoriteParticipant.EMAIL, participant.getEmail());
+ addEquals(FavoriteParticipant.FAVORITE_LIST, list).
+ addEquals(FavoriteParticipant.NAME, participant.getName()).
+ addEquals(FavoriteParticipant.EMAIL, participant.getEmail());
// Check only on entities different from the one in argument
if (StringUtils.isNotEmpty(participant.getId())) {
- query.add(TopiaEntity.TOPIA_ID, Op.NEQ, participant.getId());
+ query.addWhere(TopiaEntity.TOPIA_ID, Op.NEQ, participant.getId());
}
// existing participant found
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-26 10:08:22 UTC (rev 3015)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-27 09:15:16 UTC (rev 3016)
@@ -332,15 +332,18 @@
String creatorUidProperty =
TopiaQuery.getProperty(Poll.CREATOR, PollAccount.UID);
- int count = dao.createQuery().
- add(Poll.UID, pollUid).
- add(creatorUidProperty, accountUid).
- executeCount();
+ TopiaQuery query = dao.createQuery().
+ addEquals(Poll.UID, pollUid).
+ addEquals(creatorUidProperty, accountUid);
+
+
// Note a boolean admin exist in PollAccount, maybe
// find the account in lists
+
+ boolean result = dao.existByQuery(query);
- return count > 0;
+ return result;
}
@Override
@@ -351,7 +354,7 @@
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
TopiaQuery query = dao.createQuery().
- add(Poll.UID, pollUid).
+ addEquals(Poll.UID, pollUid).
addLoad(properties);
Poll result = dao.findByQuery(query);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java 2010-05-26 10:08:22 UTC (rev 3015)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java 2010-05-27 09:15:16 UTC (rev 3016)
@@ -155,7 +155,7 @@
if (query == null) {
query = dao.createQuery();
}
- query.add(UserAccount.EMAIL, StringUtils.lowerCase(email));
+ query.addEquals(UserAccount.EMAIL, StringUtils.lowerCase(email));
// existing user found
if (dao.existByQuery(query)) {
@@ -241,7 +241,7 @@
// the new email
// FIXME-fdesbois-20100510 : replace by using id directly
TopiaQuery query = dao.createQuery().
- add(UserAccount.LOGIN, Op.NEQ, user.getLogin());
+ addWhere(UserAccount.LOGIN, Op.NEQ, user.getLogin());
checkEmailNotExist(dao, user.getEmail(), query);
// Execute update
@@ -284,7 +284,7 @@
TopiaQuery query = dao.createQuery();
PollenUtils.prepareQuery(query, filter);
- int result = query.executeCount();
+ int result = dao.countByQuery(query);
return result;
}
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-26 10:08:22 UTC (rev 3015)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-27 09:15:16 UTC (rev 3016)
@@ -232,7 +232,7 @@
PollenDAOHelper.getFavoriteListDAO(transaction);
TopiaQuery query = dao.createQuery().
- add(TopiaEntity.TOPIA_ID, id).
+ addEquals(TopiaEntity.TOPIA_ID, id).
addLoad(propertiesLoad);
FavoriteList result = dao.findByQuery(query);
1
0