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
June 2010
- 2 participants
- 15 discussions
Author: fdesbois
Date: 2010-06-02 22:21:08 +0200 (Wed, 02 Jun 2010)
New Revision: 3026
Url: http://chorem.org/repositories/revision/pollen/3026
Log:
clean doc files
Removed:
trunk/doc/Analyse.odt
trunk/doc/Architecture.odt
trunk/doc/Conception.odt
trunk/doc/Gestion projet.odt
trunk/doc/Infrastructure.odt
trunk/doc/images/
trunk/doc/pollen-slides.odp
trunk/doc/rapportRannou.odt
Deleted: trunk/doc/Analyse.odt
===================================================================
(Binary files differ)
Deleted: trunk/doc/Architecture.odt
===================================================================
(Binary files differ)
Deleted: trunk/doc/Conception.odt
===================================================================
(Binary files differ)
Deleted: trunk/doc/Gestion projet.odt
===================================================================
(Binary files differ)
Deleted: trunk/doc/Infrastructure.odt
===================================================================
(Binary files differ)
Deleted: trunk/doc/pollen-slides.odp
===================================================================
(Binary files differ)
Deleted: trunk/doc/rapportRannou.odt
===================================================================
(Binary files differ)
1
0
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