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
May 2010
- 2 participants
- 39 discussions
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
r3015 - trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll
by fdesbois@users.chorem.org 26 May '10
by fdesbois@users.chorem.org 26 May '10
26 May '10
Author: fdesbois
Date: 2010-05-26 12:08:22 +0200 (Wed, 26 May 2010)
New Revision: 3015
Url: http://chorem.org/repositories/revision/pollen/3015
Log:
Repare broken build
Modified:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
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-26 09:17:43 UTC (rev 3014)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-26 10:08:22 UTC (rev 3015)
@@ -586,7 +586,7 @@
// percentage : check total = 100
getPollAccount().setChoiceVote(getEditedVotes());
try {
- serviceVote.saveVote(getPollAccount());
+ serviceVote.saveVote(getPoll(), getPollAccount());
} catch (PollenBusinessException eee) {
// record error
}
1
0
Author: fdesbois
Date: 2010-05-26 11:17:43 +0200 (Wed, 26 May 2010)
New Revision: 3014
Url: http://chorem.org/repositories/revision/pollen/3014
Log:
- Use evo from ToPIA to extend DAO. (remove QueryBuilder, put temporarly methods in PollenUtils, maybe will be put in TopiaDAO)
- Resolve choice image in UI
Added:
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java
Removed:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java
trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.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/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/TopiaQueryBuilderTest.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -54,7 +54,7 @@
protected String propertyJoin;
/** class of the entity * */
- protected Class<? extends TopiaEntity> entityClass;
+ protected Class<?> entityClass;
/**
* Default constructor. mainAlias, propertyJoin and entityClass are null.
@@ -76,13 +76,13 @@
/**
* Constructor with mainAlias and entityClass.
*
+ * @param entityClass class of the entity corresponding to this
+ * EntityQueryProperty
* @param mainAlias alias of the entity corresponding to this
* EntityQueryProperty
- * @param entityClass class of the entity corresponding to this
- * EntityQueryProperty
*/
- public EntityQueryProperty(String mainAlias,
- Class<? extends TopiaEntity> entityClass) {
+ public EntityQueryProperty(Class<?> entityClass,
+ String mainAlias) {
this(mainAlias);
setEntityClass(entityClass);
}
@@ -112,7 +112,7 @@
* @param entityClass class of the entity corresponding to this
* EntityQueryProperty
*/
- public void setEntityClass(Class<? extends TopiaEntity> entityClass) {
+ public void setEntityClass(Class<?> entityClass) {
this.entityClass = entityClass;
}
@@ -176,7 +176,7 @@
*
* @return the entity class corresponding to this EntityQueryProperty.
*/
- public Class<? extends TopiaEntity> getEntityClass() {
+ public Class<?> getEntityClass() {
if (entityClass == null) {
throw new NullPointerException("entitClass is not set");
}
@@ -192,7 +192,7 @@
* provides it.
*/
public TopiaQuery newQuery() {
- return new TopiaQuery(getEntityClass(), name());
+ return new TopiaQuery((Class<? extends TopiaEntity>)getEntityClass(), name());
}
/**
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -123,7 +123,4 @@
*/
void closeTransaction(TopiaContext transaction);
- PollenQueryBuilder newQueryBuilder(TopiaQuery query);
-
-
} //PollenContext
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -391,13 +391,4 @@
return null;
}
- @Override
- public PollenQueryBuilder newQueryBuilder(TopiaQuery query) {
- PollenQueryBuilder builder = new PollenQueryBuilder();
- if (query != null) {
- builder.setQuery(query);
- }
- return builder;
- }
-
}
Deleted: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -1,79 +0,0 @@
-
-package org.chorem.pollen;
-
-import org.chorem.pollen.bean.Filter;
-import org.chorem.pollen.entity.FavoriteList;
-import org.chorem.pollen.entity.FavoriteParticipant;
-import org.chorem.pollen.entity.Poll;
-import org.chorem.pollen.entity.PollAccount;
-import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.persistence.TopiaDAO;
-
-/**
- * PollenQueryBuilder
- *
- * Created: 28 avr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class PollenQueryBuilder extends TopiaQueryBuilder {
-
- protected PollenQueryBuilder() {
- super();
- }
-
- public EntityQueryProperty getFavoriteListProperty(String alias) {
- return getEntityProperty(FavoriteList.class, alias);
- }
-
- public EntityQueryProperty getFavoriteParticipantProperty(
- String alias) {
- return getEntityProperty(FavoriteParticipant.class, alias);
- }
-
- public EntityQueryProperty getPollAccountProperty(
- String alias) {
- return getEntityProperty(PollAccount.class, alias);
- }
-
- public EntityQueryProperty getPollProperty(String alias) {
- return getEntityProperty(Poll.class, alias);
- }
-
- public TopiaQuery createQueryFindFavoriteParticipantsByFavoriteList(
- Filter filter) {
-
- EntityQueryProperty participantProperty =
- getFavoriteParticipantProperty("P");
-
- EntityQueryProperty listProperty =
- getFavoriteListProperty("L");
-
- listProperty.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT);
-
- createQueryFindElementsByCollection(
- participantProperty, listProperty, filter);
-
- return query;
- }
-
- public TopiaQuery createQueryFindVotesByPoll(Filter filter) {
-
- EntityQueryProperty accountProperty = getPollAccountProperty("A");
-
- EntityQueryProperty pollProperty = getPollProperty("P");
- pollProperty.setPropertyJoin(Poll.POLL_ACCOUNT);
-
- createQueryFindElementsByCollection(
- accountProperty, pollProperty, filter);
-
- query.addNotNull(accountProperty.nameProperty(PollAccount.VOTE_DATE));
-
- return query;
- }
-
-}
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -1,6 +1,15 @@
package org.chorem.pollen;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.bean.Filter;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
/**
* Created: 21 mai 2010
@@ -10,6 +19,8 @@
*/
public class PollenUtils {
+ private static final Log log = LogFactory.getLog(PollenUtils.class);
+
private static PollenContext context;
public static void setContext(PollenContext context) {
@@ -19,4 +30,114 @@
public static Date getCurrentDate() {
return context.getCurrentDate();
}
+
+ // TEMP METHOD
+ public static EntityQueryProperty getEntityQueryProperty(String alias) {
+ return new EntityQueryProperty(alias);
+ }
+
+ public static EntityQueryProperty getEntityQueryProperty(
+ Class<? extends TopiaEntity> entityClass, String alias) {
+ return new EntityQueryProperty(entityClass, alias);
+ }
+
+ /**
+ * Create a TopiaQuery to find all participants of a list with
+ * {@code filter} constraints (order, limit indexes, listId).
+ *
+ * @param filter used to add constraint in the query
+ * @param element
+ * @param collection
+ * @return the TopiaQuery created
+ * @see #prepareQuery(TopiaQuery, Filter, EntityQueryProperty)
+ */
+ public static TopiaQuery createQueryFindElementsByCollection(
+ EntityQueryProperty element,
+ EntityQueryProperty collection,
+ Filter filter) {
+
+ // Instanciate a new query based on element
+ TopiaQuery query = element.newQuery();
+
+ // Add the collection in the From of the query
+ query.addFrom((Class<? extends TopiaEntity>)collection.getEntityClass(),
+ collection.name());
+
+ // Add the link between the collection and the element
+ query.addInElements(element.name(), collection.namePropertyJoin());
+
+ if (filter != null) {
+ // Add constraints from filter, the collection is given to provide
+ // the name of its ID property.
+ prepareQuery(query, filter, collection);
+ }
+
+ return query;
+ }
+
+ /**
+ * 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)
+ */
+ public static void prepareQuery(TopiaQuery query, Filter filter) {
+ prepareQuery(query, filter, null);
+ }
+
+ /**
+ * Prepare a query with filter. The {@code reference} is used
+ * to retrieve the name of ID property in case of filter using referenceId.
+ * Need an existing query in builder.
+ *
+ * @param filter Filter to add in the query
+ * @param reference used to filter on referenceId
+ */
+ public static void prepareQuery(TopiaQuery query, Filter filter,
+ EntityQueryProperty reference) {
+
+ Integer startIndex = filter.getStartIndex();
+ Integer endIndex = filter.getEndIndex();
+ String orderBy = filter.getOrderBy();
+ String referenceId = filter.getReferenceId();
+
+ EntityQueryProperty mainProperty =
+ getEntityQueryProperty(query.getMainAlias());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Filter added to the query : " +
+ "startIndex = " + startIndex +
+ " _ endIndex = " + endIndex +
+ " _ orderBy = " + orderBy +
+ " _ referenceId = " + referenceId);
+ }
+
+ // Add limits. Only startIndex do nothing.
+ // startIndex + endIndex provides the limit
+ if (filter.getStartIndex() != null && endIndex != null) {
+ query.setLimit(startIndex, endIndex);
+
+ // endIndex only provides the maxResults wanted
+ } else if (endIndex != null) {
+ query.setMaxResults(endIndex);
+ }
+
+ // Add order to the main entity in the query, splitted by comma
+ if (orderBy != null) {
+ List<String> order = new ArrayList<String>();
+ for (String elmt : orderBy.split(",")) {
+ order.add(mainProperty.nameProperty(elmt.trim()));
+ }
+ query.addOrder(order.toArray(new String[order.size()]));
+
+ // Default order by creation date
+ } else {
+ query.addOrderDesc(mainProperty.namePropertyCreateDate());
+ }
+
+ if (StringUtils.isNotEmpty(referenceId) && reference != null) {
+ query.add(reference.namePropertyId(), referenceId);
+ }
+ }
}
Deleted: trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -1,158 +0,0 @@
-
-package org.chorem.pollen;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.bean.Filter;
-import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.persistence.TopiaDAO;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-/**
- * TopiaQueryBuilder is used to build a TopiaQuery. <br />
- * Convention rules :
- * <ul>
- * <li>method with prefix {@code prepare} will modify the current query</li>
- * <li>method with prefix {@code create} will instantiate a new query</li>
- * </ul>
- * <br />
- * To use directly {@code prepare} methods, you have to set the query using
- * {@link #setQuery(TopiaQuery)}.
- *
- * Created: 28 avr. 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- */
-public class TopiaQueryBuilder {
-
- private static final Log log = LogFactory.getLog(TopiaQueryBuilder.class);
-
- protected TopiaQuery query;
-
- protected TopiaQueryBuilder() {
- }
-
- public static TopiaQueryBuilder newInstance() {
- return new TopiaQueryBuilder();
- }
-
- public void setQuery(TopiaQuery query) {
- this.query = query;
- }
-
- public TopiaQuery getQuery() {
- return query;
- }
-
- public EntityQueryProperty getEntityProperty(String alias) {
- return new EntityQueryProperty(alias);
- }
-
- public EntityQueryProperty getEntityProperty(
- Class<? extends TopiaEntity> entityClass, String alias) {
- return new EntityQueryProperty(alias, entityClass);
- }
-
- public EntityQueryProperty getMainProperty() {
- return getEntityProperty(query.getMainAlias());
- }
-
- /**
- * Create a TopiaQuery to find all participants of a list with
- * {@code filter} constraints (order, limit indexes, listId).
- *
- * @param filter used to add constraint in the query
- * @param element
- * @param collection
- * @return the TopiaQuery created
- * @see #prepareQuery(Filter, EntityQueryProperty)
- */
- public TopiaQuery createQueryFindElementsByCollection(
- EntityQueryProperty element,
- EntityQueryProperty collection,
- Filter filter) {
-
- // Instanciate a new query based on element
- query = element.newQuery();
-
- // Add the collection in the From of the query
- query.addFrom(collection.getEntityClass(), collection.name());
-
- // Add the link between the collection and the element
- query.addInElements(element.name(), collection.namePropertyJoin());
-
- if (filter != null) {
- // Add constraints from filter, the collection is given to provide
- // the name of its ID property.
- prepareQuery(filter, collection);
- }
-
- return query;
- }
-
- /**
- * 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(Filter filter, EntityQueryProperty)
- */
- public void prepareQuery(Filter filter) {
- prepareQuery(filter, null);
- }
-
- /**
- * Prepare a query with filter. The {@code reference} is used
- * to retrieve the name of ID property in case of filter using referenceId.
- * Need an existing query in builder.
- *
- * @param filter Filter to add in the query
- * @param reference used to filter on referenceId
- */
- public void prepareQuery(Filter filter,
- EntityQueryProperty reference) {
-
- Integer startIndex = filter.getStartIndex();
- Integer endIndex = filter.getEndIndex();
- String orderBy = filter.getOrderBy();
- String referenceId = filter.getReferenceId();
-
- if (log.isDebugEnabled()) {
- log.debug("Filter added to the query : " +
- "startIndex = " + startIndex +
- " _ endIndex = " + endIndex +
- " _ orderBy = " + orderBy +
- " _ referenceId = " + referenceId);
- }
-
- // Add limits. Only startIndex do nothing.
- // startIndex + endIndex provides the limit
- if (filter.getStartIndex() != null && endIndex != null) {
- query.setLimit(startIndex, endIndex);
-
- // endIndex only provides the maxResults wanted
- } else if (endIndex != null) {
- query.setMaxResults(endIndex);
- }
-
- // Add order to the main entity in the query, splitted by comma
- if (orderBy != null) {
- List<String> order = new ArrayList<String>();
- for (String elmt : orderBy.split(",")) {
- order.add(getMainProperty().nameProperty(elmt.trim()));
- }
- query.addOrder(order.toArray(new String[order.size()]));
-
- // Default order by creation date
- } else {
- query.addOrderDesc(getMainProperty().namePropertyCreateDate());
- }
-
- if (StringUtils.isNotEmpty(referenceId) && reference != null) {
- query.add(reference.namePropertyId(), referenceId);
- }
- }
-}
Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.entity;
+
+import org.chorem.pollen.EntityQueryProperty;
+import org.chorem.pollen.PollenUtils;
+import org.chorem.pollen.bean.Filter;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+
+/**
+ * Created: 26 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class FavoriteParticipantDAOImpl<E extends FavoriteParticipant>
+ extends FavoriteParticipantDAOAbstract<E> {
+
+ @Override
+ public TopiaQuery createQueryFindAllByFavoriteList(Filter filter) {
+
+ EntityQueryProperty participantProperty =
+ PollenUtils.getEntityQueryProperty(FavoriteParticipant.class, "P");
+
+ EntityQueryProperty listProperty =
+ PollenUtils.getEntityQueryProperty(FavoriteList.class, "L");
+
+ listProperty.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT);
+
+ TopiaQuery query = PollenUtils.createQueryFindElementsByCollection(
+ participantProperty, listProperty, filter);
+
+ return query;
+ }
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -0,0 +1,35 @@
+package org.chorem.pollen.entity;
+
+import org.chorem.pollen.EntityQueryProperty;
+import org.chorem.pollen.PollenUtils;
+import org.chorem.pollen.bean.Filter;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+
+/**
+ * Created: 26 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class PollAccountDAOImpl<E extends PollAccount> extends PollAccountDAOAbstract<E> {
+
+ @Override
+ public TopiaQuery createQueryFindAllByPoll(Filter filter) {
+
+ EntityQueryProperty accountProperty =
+ PollenUtils.getEntityQueryProperty(PollAccount.class, "A");
+
+ EntityQueryProperty pollProperty =
+ PollenUtils.getEntityQueryProperty(Poll.class, "P");
+
+ pollProperty.setPropertyJoin(Poll.POLL_ACCOUNT);
+
+ TopiaQuery query = PollenUtils.createQueryFindElementsByCollection(
+ accountProperty, pollProperty, filter);
+
+ query.addNotNull(accountProperty.nameProperty(PollAccount.VOTE_DATE));
+
+ return query;
+ }
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -8,7 +8,6 @@
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
-import org.chorem.pollen.PollenQueryBuilder;
import org.chorem.pollen.bean.Filter;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.FavoriteListDAO;
@@ -244,14 +243,11 @@
protected Map<String, FavoriteParticipant> executeGetFavoriteParticipants(
TopiaContext transaction, Filter filter) throws TopiaException {
- PollenQueryBuilder builder = context.newQueryBuilder(null);
-
- TopiaQuery query =
- builder.createQueryFindFavoriteParticipantsByFavoriteList(filter);
-
FavoriteParticipantDAO dao =
PollenDAOHelper.getFavoriteParticipantDAO(transaction);
+ TopiaQuery query = dao.createQueryFindAllByFavoriteList(filter);
+
if (log.isDebugEnabled()) {
log.debug("Query : " + query);
}
@@ -268,12 +264,12 @@
protected int executeGetNbFavoriteParticipants(TopiaContext transaction,
Filter filter) throws TopiaException {
- PollenQueryBuilder builder = context.newQueryBuilder(null);
+ FavoriteParticipantDAO dao =
+ PollenDAOHelper.getFavoriteParticipantDAO(transaction);
- TopiaQuery query =
- builder.createQueryFindFavoriteParticipantsByFavoriteList(filter);
+ TopiaQuery query = dao.createQueryFindAllByFavoriteList(filter);
- int result = query.executeCount(transaction);
+ int result = dao.countByQuery(query);
return result;
}
}
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -7,8 +7,6 @@
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
-import org.chorem.pollen.PollenQueryBuilder;
-import org.chorem.pollen.TopiaQueryBuilder;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -12,6 +12,7 @@
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.entity.FavoriteList;
import org.chorem.pollen.entity.FavoriteListDAO;
@@ -19,8 +20,6 @@
import org.chorem.pollen.entity.FavoriteParticipant;
import org.chorem.pollen.entity.FavoriteParticipantDAO;
import org.chorem.pollen.entity.FavoriteParticipantImpl;
-import org.chorem.pollen.PollenQueryBuilder;
-import org.chorem.pollen.TopiaQueryBuilder;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.UserAccountDAO;
import org.chorem.pollen.entity.UserAccountImpl;
@@ -269,7 +268,7 @@
UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(transaction);
TopiaQuery query = dao.createQuery();
- context.newQueryBuilder(query).prepareQuery(filter);
+ PollenUtils.prepareQuery(query, filter);
Map<String, UserAccount> results = dao.findAllMappedByQuery(
query, UserAccount.LOGIN, String.class);
@@ -283,7 +282,7 @@
UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(transaction);
TopiaQuery query = dao.createQuery();
- context.newQueryBuilder(query).prepareQuery(filter);
+ PollenUtils.prepareQuery(query, filter);
int result = query.executeCount();
return result;
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -1,17 +1,20 @@
package org.chorem.pollen.service;
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.PollenQueryBuilder;
import org.chorem.pollen.bean.Filter;
+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.VoteDAO;
+import org.chorem.pollen.entity.VoteImpl;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
@@ -49,7 +52,8 @@
}
@Override
- protected boolean executeCanVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
+ protected boolean executeCanVote(TopiaContext transaction, Poll poll,
+ PollAccount participant) throws Exception {
return false;
}
@@ -69,15 +73,14 @@
Filter filter)
throws Exception {
- PollenQueryBuilder builder = context.newQueryBuilder(null);
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
- TopiaQuery query = builder.createQueryFindVotesByPoll(filter);
+ TopiaQuery query = dao.createQueryFindAllByPoll(filter);
- PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
-
query.addLoad(PollAccount.CHOICE_VOTE);
List<PollAccount> results = dao.findAllByQuery(query);
+
return results;
}
@@ -85,15 +88,44 @@
protected int executeGetNbVotes(TopiaContext transaction, Filter filter)
throws TopiaException {
- PollenQueryBuilder builder = context.newQueryBuilder(null);
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
- TopiaQuery query = builder.createQueryFindVotesByPoll(filter);
+ TopiaQuery query = dao.createQueryFindAllByPoll(filter);
- int result = query.executeCount(transaction);
+ int result = dao.countByQuery(query);
return result;
}
@Override
protected void executeDeleteVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
}
+
+ @Override
+ protected Vote executeGetNewVote(Choice choice) {
+ Vote result = new VoteImpl();
+ result.setChoice(choice);
+ return result;
+ }
+
+ @Override
+ protected void executeSaveVote(TopiaContext transaction, Poll poll,
+ PollAccount participant)
+ throws PollenBusinessException {
+
+ // 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
+
+ // NEED test :
+ // need existing poll with choices
+ // getNewPollAccount
+ // set some votes for poll choices
+ // saveVote
+
+
+
+ }
}
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-26 09:17:43 UTC (rev 3014)
@@ -79,11 +79,13 @@
pollen.error.serviceVote.deleteVote=
pollen.error.serviceVote.getNbVotes=
pollen.error.serviceVote.getNewPollAccount=
+pollen.error.serviceVote.getNewVote=
pollen.error.serviceVote.getPollAccount=
pollen.error.serviceVote.getVote=
pollen.error.serviceVote.getVotes=
pollen.error.serviceVote.getVotesByPoll=Unable to load votes from poll with uid \= %1$s
pollen.error.serviceVote.hasAlreadyVoted=Unable test vote existing for account with votingId \= %1$s and poll with uid \= %2$s
+pollen.error.serviceVote.saveVote=
pollen.exception.favorite_list_name_exist=
pollen.exception.favorite_participant_exist=
pollen.exception.favorite_participant_exist_without_email=
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-26 09:17:43 UTC (rev 3014)
@@ -78,11 +78,13 @@
pollen.error.serviceVote.deleteVote=
pollen.error.serviceVote.getNbVotes=
pollen.error.serviceVote.getNewPollAccount=
+pollen.error.serviceVote.getNewVote=
pollen.error.serviceVote.getPollAccount=
pollen.error.serviceVote.getVote=
pollen.error.serviceVote.getVotes=
pollen.error.serviceVote.getVotesByPoll=
pollen.error.serviceVote.hasAlreadyVoted=
+pollen.error.serviceVote.saveVote=
pollen.exception.favorite_list_name_exist=La liste %1$s existe d\u00E9j\u00E0 pour l'utilisateur %2$s
pollen.exception.load_configuration=La configuration n'a pas \u00E9t\u00E9 charg\u00E9e correctement \! Veuillez v\u00E9rifier le d\u00E9marrage de l'application.
pollen.exception.participant_doubloons=Les doublons de la liste %1$s ont \u00E9t\u00E9 ignor\u00E9s \: %2$s
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -34,24 +34,25 @@
filter.setEndIndex(40);
filter.setOrderBy(UserAccount.LOGIN);
- TopiaQueryBuilder builder = new TopiaQueryBuilder();
- builder.setQuery(new TopiaQuery(UserAccount.class));
- builder.prepareQuery(filter);
+// TopiaQueryBuilder builder = new TopiaQueryBuilder();
+// builder.setQuery(new TopiaQuery(UserAccount.class));
+ TopiaQuery query = new TopiaQuery(UserAccount.class);
+ PollenUtils.prepareQuery(query, filter);
- log.debug("Query : " + builder.getQuery());
+ log.debug("Query : " + query);
- Assert.assertEquals(builder.getQuery().fullQuery(),
+ Assert.assertEquals(query.fullQuery(),
"FROM " + UserAccount.class.getName() +
" ORDER BY " + UserAccount.LOGIN);
filter.setOrderBy(null);
- builder.setQuery(new TopiaQuery(UserAccount.class));
- builder.prepareQuery(filter);
+ query = new TopiaQuery(UserAccount.class);
+ PollenUtils.prepareQuery(query, filter);
- log.debug("Query : " + builder.getQuery());
+ log.debug("Query : " + query);
- Assert.assertEquals(builder.getQuery().fullQuery(),
+ Assert.assertEquals(query.fullQuery(),
"FROM " + UserAccount.class.getName() +
" ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
@@ -60,7 +61,7 @@
@Test
public void testCreateQueryFindElementsByCollection() throws IOException {
- TopiaQueryBuilder builder = new TopiaQueryBuilder();
+ //TopiaQueryBuilder builder = new TopiaQueryBuilder();
Filter filter = new Filter();
filter.setStartIndex(1);
@@ -68,14 +69,14 @@
filter.setOrderBy(FavoriteParticipant.NAME);
EntityQueryProperty participantPropertyProvider =
- builder.getEntityProperty(FavoriteParticipant.class, "P");
+ PollenUtils.getEntityQueryProperty(FavoriteParticipant.class, "P");
EntityQueryProperty listPropertyProvider =
- builder.getEntityProperty(FavoriteList.class, "L");
+ PollenUtils.getEntityQueryProperty(FavoriteList.class, "L");
listPropertyProvider.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT);
log.info("test1 : orderBy FavoriteParticipant name");
- TopiaQuery result = builder.createQueryFindElementsByCollection(
+ TopiaQuery result = PollenUtils.createQueryFindElementsByCollection(
participantPropertyProvider, listPropertyProvider, filter);
log.debug("Query : " + result);
@@ -89,7 +90,7 @@
log.info("test2 : orderBy not set (default to topiaCreateDate desc)");
filter.setOrderBy(null);
- result = builder.createQueryFindElementsByCollection(
+ result = PollenUtils.createQueryFindElementsByCollection(
participantPropertyProvider, listPropertyProvider, filter);
log.debug("Query : " + result);
@@ -104,7 +105,7 @@
String orderBy = FavoriteParticipant.NAME + ", " + FavoriteParticipant.EMAIL + " desc";
filter.setOrderBy(orderBy);
- result = builder.createQueryFindElementsByCollection(
+ result = PollenUtils.createQueryFindElementsByCollection(
participantPropertyProvider, listPropertyProvider, filter);
log.debug("Query : " + result);
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -1,5 +1,6 @@
package org.chorem.pollen.ui.components;
+import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.ClientElement;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
@@ -44,8 +45,11 @@
Link thumbLink = resources.createEventLink("showImage",
source.getImageFileName(), source.getImageDir(), true);
+ String alt = StringUtils.isNotEmpty(source.getDescription()) ?
+ source.getDescription() : source.getImageFileName();
+
writeLink(writer, link, "rel", "lightbox[pollChoiceImages]");
- writer.element("img", "src", thumbLink, "alt", source.getDescription());
+ writer.element("img", "src", thumbLink, "alt", alt);
writer.end();
writer.end();
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -52,6 +52,8 @@
protected String text;
+ protected Double voteValue;
+
public ChoiceField() {
}
@@ -272,4 +274,12 @@
public boolean isHidden() {
return choice.isHidden();
}
+
+ public void setVoteValue(Double voteValue) {
+ this.voteValue = voteValue;
+ }
+
+ public Double getVoteValue() {
+ return voteValue;
+ }
}
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-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-26 09:17:43 UTC (rev 3014)
@@ -22,6 +22,8 @@
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;
@@ -45,6 +47,7 @@
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;
@@ -496,6 +499,10 @@
manager.getProperty(PollenProperty.NB_VOTES_PER_PAGE));
}
+ public boolean isPagerNeeded() throws PollenBusinessException {
+ return getPagerRange() < getNbVotes();
+ }
+
public int getNbVotes() throws PollenBusinessException {
if (nbVotes == null) {
Filter filter = new Filter();
@@ -555,6 +562,36 @@
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 (vote == null) {
+ vote = serviceVote.getNewVote(choice.getChoice());
+ }
+ editedVotes.add(vote);
+ }
+ }
+ return editedVotes;
+ }
+
+ void onValidateFormFromVoteForm() {
+ // percentage : check total = 100
+ getPollAccount().setChoiceVote(getEditedVotes());
+ try {
+ serviceVote.saveVote(getPollAccount());
+ } catch (PollenBusinessException eee) {
+ // record error
+ }
+ }
+
// /**
// * Retourne vrai si le champs pollAccount doit apparaître.
// *
@@ -572,15 +609,8 @@
// return !getPoll().getAnonymous() || isRestrictedPoll() || isGroupPoll();
// }
- public void setChoiceValue(Integer value) {
-// getCurrentVote().setChoiceValue(choice.getId(), value);
- }
-
-// public Integer getChoiceValue() {
-// return getCurrentVote().getChoiceValue(choice.getId());
-// }
-
public boolean getCanVote() {
+ // FIXME-fdesbois-2010-05-25 : copy check treatment directly in service
if (poll.isFinished()) {
return false;
}
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-25 15:13:12 UTC (rev 3013)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-26 09:17:43 UTC (rev 3014)
@@ -44,12 +44,12 @@
<!-- Sondage -->
<!--<t:zone t:id="pollZone" t:show="show" t:update="show">-->
- <t:if t:test="poll.anonymous">
- <p>${format:vote-size=nbVotes}</p>
+ <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>
- <t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="nbVotes"
- t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>
+ <p>${format:vote-size=nbVotes}</p>
</p:else>
</t:if>
<t:form t:id="voteForm">
@@ -98,38 +98,38 @@
</th>
</tr>
</thead>
- <!--<t:if test="canVote">-->
- <!--<tfoot>-->
- <!--<tr>-->
+ <t:if test="canVote">
+ <tfoot>
+ <tr>
<!--<t:if test="accountFieldDisplayed">-->
- <!--<th id="voterName">-->
- <!--<input t:type="textfield" t:id="pollAccountName" value="pollAccount.votingId" t:validate="required"/>-->
- <!--</th>-->
+ <th id="voterName">
+ <input t:type="textfield" t:id="pollAccountName" value="pollAccount.name" t:validate="required"/>
+ </th>
<!--<p:else>-->
<!--<th></th>-->
<!--</p:else>-->
<!--</t:if>-->
- <!--<t:loop t:source="choices" t:value="choice" volatile="true">-->
- <!--<t:unless test="choice.hidden">-->
- <!--<th>-->
- <!--<t:if test="poll.voteCounting.normal">-->
- <!--<input t:type="checkbox" value="addChoice" />-->
- <!--</t:if>-->
- <!--<t:if test="poll.voteCounting.percentage">-->
- <!--<t:textField t:value="currentVote.getChoiceValues(choice.id)" size="3" t:validate="required, min=0, max=100"/>%-->
- <!--</t:if>-->
- <!--<t:if test="poll.voteCounting.condorcet">-->
- <!--<t:textField t:id="condorcetInput" t:value="choiceOfVote.value" size="3" t:nulls="zero" t:validate="min=0, max=99"/>-->
- <!--</t:if>-->
- <!--<t:if test="poll.voteCounting.number">-->
- <!--<t:textField t:value="addNumberVote" size="3" />-->
- <!--</t:if>-->
- <!--</th>-->
- <!--</t:unless>-->
- <!--</t:loop>-->
- <!--</tr>-->
- <!--</tfoot>-->
- <!--</t:if>-->
+ <t:loop t:source="editedVotes" t:value="editedVote" volatile="true">
+ <t:unless test="editedChoice.hidden">
+ <th>
+ <t:if test="poll.voteCountingType.normal">
+ <input t:type="checkbox" value="editedVote.voteValue" />
+ </t:if>
+ <t:if test="poll.voteCountingType.percentage">
+ <input t:type="textfield" value="editedVote.voteValue" size="3" t:validate="required, min=0, max=100"/>%
+ </t:if>
+ <t:if test="poll.voteCountingType.condorcet">
+ <input t:type="textfield" value="editedVote.voteValue" size="3" t:id="condorcetInput" t:nulls="zero" t:validate="min=0, max=99"/>
+ </t:if>
+ <t:if test="poll.voteCountingType.number">
+ <input t:type="textfield" value="editedVote.voteValue" size="3" />
+ </t:if>
+ </th>
+ </t:unless>
+ </t:loop>
+ </tr>
+ </tfoot>
+ </t:if>
<tbody>
<t:unless t:test="poll.anonymous">
<t:loop t:source="participants" t:value="participant" t:rowIndex="participantIndex" volatile="true">
1
0
25 May '10
Author: fdesbois
Date: 2010-05-25 17:13:12 +0200 (Tue, 25 May 2010)
New Revision: 3013
Url: http://chorem.org/repositories/revision/pollen/3013
Log:
Decompose choice part of the pollForm in components (problem with upload can't be used in zone)
Added:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceDateForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImageForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceTextForm.java
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceDateForm.tml
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceImageForm.tml
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceTextForm.tml
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
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/PollForm.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
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-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -9,7 +9,9 @@
import org.chorem.pollen.PollenException;
import org.chorem.pollen.PollenQueryBuilder;
import org.chorem.pollen.TopiaQueryBuilder;
+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.Comment;
@@ -68,6 +70,9 @@
@Override
protected Poll executeGetNewPoll(UserAccount user) {
Poll poll = new PollImpl();
+ poll.setChoiceType(ChoiceType.TEXT);
+ poll.setVoteCountingType(VoteCountingType.NORMAL);
+ poll.setPollType(PollType.FREE);
// Initialize creator as an admin for the poll
PollAccount creator = new PollAccountImpl();
creator.setAdmin(true);
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceDateForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceDateForm.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceDateForm.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -0,0 +1,39 @@
+package org.chorem.pollen.ui.components;
+
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.models.PollFormModel;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+/**
+ * Created: 25 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ChoiceDateForm {
+
+ @Inject
+ private Messages messages;
+
+ @Parameter(required = true)
+ private PollFormModel model;
+
+ @Property
+ private ChoiceField choice;
+
+ public List<ChoiceField> getChoices() {
+ return model.getChoices();
+ }
+
+ public DateFormat getDateFormat() {
+ return new SimpleDateFormat(messages.get("date-pattern"));
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceDateForm.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java 2010-05-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -47,6 +47,7 @@
writeLink(writer, link, "rel", "lightbox[pollChoiceImages]");
writer.element("img", "src", thumbLink, "alt", source.getDescription());
writer.end();
+ writer.end();
}
/**
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImageForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImageForm.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImageForm.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -0,0 +1,28 @@
+package org.chorem.pollen.ui.components;
+
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Property;
+import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.models.PollFormModel;
+
+import java.util.List;
+
+/**
+ * Created: 25 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ChoiceImageForm {
+
+ @Parameter(required = true)
+ private PollFormModel model;
+
+ @Property
+ private ChoiceField choice;
+
+ public List<ChoiceField> getChoices() {
+ return model.getChoices();
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImageForm.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceTextForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceTextForm.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceTextForm.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -0,0 +1,28 @@
+package org.chorem.pollen.ui.components;
+
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Property;
+import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.models.PollFormModel;
+
+import java.util.List;
+
+/**
+ * Created: 25 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ChoiceTextForm {
+
+ @Parameter(required = true)
+ private PollFormModel model;
+
+ @Property
+ private ChoiceField choice;
+
+ public List<ChoiceField> getChoices() {
+ return model.getChoices();
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceTextForm.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -223,7 +223,14 @@
name = String.valueOf(getDate().getTime());
break;
case IMAGE:
- name = serviceImage.saveImage(getImage(), getImageDir());
+ if (image == null) {
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Saving image... " + getImageFileName() +
+ " in directory " + imageDir);
+ }
+ name = serviceImage.saveImage(image, imageDir);
break;
case TEXT:
name = getText();
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-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -5,6 +5,7 @@
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;
import org.chorem.pollen.entity.ParticipantList;
@@ -141,9 +142,8 @@
if (choices == null) {
choices = new ArrayList<ChoiceField>();
if (createMode) {
- // Initialized to choice TEXT type
for (int i = 0; i < 4; i++) {
- choices.add(ChoiceField.getChoiceText());
+ choices.add(new ChoiceField(poll));
}
} else {
for (Choice current : poll.getChoice()) {
@@ -154,6 +154,12 @@
return choices;
}
+ public void setChoiceType(ChoiceType type) {
+ poll.setChoiceType(type);
+ // Reset choices
+ choices = null;
+ }
+
/**
* Change the poll type to {@code type}. The lists managment will depends on
* poll type. For a {@link PollType#RESTRICTED} poll, a new list will be
@@ -322,9 +328,15 @@
poll.clearChoice();
for (ChoiceField choiceField : getChoices()) {
choiceField.saveName(serviceImage);
+ if (logger.isDebugEnabled()) {
+ logger.debug("ChoiceField : " + choiceField.getName());
+ }
Choice choice = choiceField.getChoice();
if (StringUtils.isNotEmpty(choice.getName())) {
- poll.addChoice(choice);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Add choice to poll : " + choice.getName());
+ }
+ poll.addChoice(choice);
}
}
poll = servicePoll.createPoll(poll, getLists());
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-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-25 15:13:12 UTC (rev 3013)
@@ -1,5 +1,6 @@
package org.chorem.pollen.ui.pages.poll;
+import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
@@ -520,52 +521,52 @@
@Inject
private ServiceImage serviceImage;
- @InjectComponent
- private Zone choicesZone;
-
+// @InjectComponent
+// private Zone choicesZone;
+//
@Inject
- private Block choiceText;
+ private Block choiceTextBlock;
@Inject
- private Block choiceDate;
+ private Block choiceDateBlock;
@Inject
- private Block choiceImage;
+ private Block choiceImageBlock;
+//
+// @Property
+// private ChoiceField choice;
+//
+// @Property
+// private boolean refreshChoicesZone;
- @Property
- private ChoiceField choice;
-
- @Property
- private boolean refreshChoicesZone;
-
/**
* Get choices from poll if it exists or initialized 4 choices with the
* default type : TEXT.
*
* @return a list of ChoiceDTO
*/
- public List<ChoiceField> getChoices() throws PollenBusinessException {
- return getModel().getChoices();
- }
-
+// public List<ChoiceField> getChoices() throws PollenBusinessException {
+// return getModel().getChoices();
+// }
+//
public Block getChoiceTypeBlock() {
switch (getPoll().getChoiceType()) {
case DATE:
- return choiceDate;
+ return choiceDateBlock;
case IMAGE:
- return choiceImage;
+ return choiceImageBlock;
default:
- return choiceText;
+ return choiceTextBlock;
}
}
- @Log
- Object onChangeFromChoiceType(String value) {
- ChoiceType type = ChoiceType.valueOf(value);
- getPoll().setChoiceType(type);
- refreshChoicesZone = true;
- return choicesZone.getBody();
- }
+// @Log
+// Object onChangeFromChoiceType(String value) {
+// ChoiceType type = ChoiceType.valueOf(value);
+// getModel().setChoiceType(type);
+// refreshChoicesZone = true;
+// return choicesZone.getBody();
+// }
/** ********************** NAVIGATION/SUBMISSION ************************ */
@@ -601,21 +602,53 @@
@Log
void onSelected() {
refreshListsZone = false;
- refreshChoicesZone = false;
+// refreshChoicesZone = false;
}
+// /**
+// * ON_SELECTED:: Callback method for action on choiceStep submit buttons.
+// * Will change the view and display the choice formFragment of the pollForm.
+// * Note : maybe validations will be needed in this case (use edited flag).
+// */
+// @Log
+// void onSelectedFromChoiceStep(String choiceType) {
+// ChoiceType type = ChoiceType.valueOf(choiceType);
+// getModel().setChoiceType(type);
+// step = PollStep.CHOICES;
+// edited = true;
+// }
+
/**
- * ON_SELECTED:: Callback method for action on choiceStep submit button. Will
- * change the view and display the choice formFragment of the pollForm.
- * Note : maybe validations will be needed in this case (use edited flag).
+ * ON_SELECTED:: Callback method for action on choiceText submit button.
*/
@Log
- void onSelectedFromChoiceStep() {
+ void onSelectedFromChoiceText() {
+ getModel().setChoiceType(ChoiceType.TEXT);
step = PollStep.CHOICES;
edited = true;
}
/**
+ * ON_SELECTED:: Callback method for action on choiceDate submit button.
+ */
+ @Log
+ void onSelectedFromChoiceDate() {
+ getModel().setChoiceType(ChoiceType.DATE);
+ step = PollStep.CHOICES;
+ edited = true;
+ }
+
+ /**
+ * ON_SELECTED:: Callback method for action on choiceImage submit button.
+ */
+ @Log
+ void onSelectedFromChoiceImage() {
+ getModel().setChoiceType(ChoiceType.IMAGE);
+ step = PollStep.CHOICES;
+ edited = true;
+ }
+
+ /**
* ON_SELECTED:: Callback method for action on mainStep submit button. Will
* change the view and display the main formFragment of the pollForm.
* This is a previous action after being on choices.
@@ -632,13 +665,31 @@
public boolean isMainStep() {
return step.equals(PollStep.MAIN);
- }
+ }
+// @Log
+// Object onUploadException(FileUploadException ex) {
+// addError(ex.getMessage());
+// return this;
+// }
+
@Log
void onValidateForm() {
if (!edited) {
// Validate data
ErrorReport report = getModel().validate(messages);
+
+
+ if (logger.isDebugEnabled()) {
+ for (ChoiceField choiceField : getModel().getChoices()) {
+ logger.debug("Choice type : " + choiceField.getChoiceType());
+ logger.debug("Choice image : " + choiceField.getImage());
+ logger.debug("Choice text : " + choiceField.getText());
+ logger.debug("Choice date : " + choiceField.getDate());
+ }
+ }
+
+
// Record errors if report is not empty
if (report.hasErrors()) {
manager.recordFormErrors(componentSource, report, mainForm);
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-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-25 15:13:12 UTC (rev 3013)
@@ -93,7 +93,15 @@
groupName-label=Nom du groupe
participantEmail-regexp=^([a-zA-Z0-9_.+-])+(a)(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$
participantEmail-regexp-message=Adresse email invalide.
+date-pattern=dd/MM/yyyy HH:mm
+choiceImageField-label=Image
+choiceImageField-regexp=\\.(jpe?g|gif|png|JPE?G|GIF|PNG)$
+choiceImageField-regexp-message=L'image doit-\u00eatre au format JPG, GIF ou PNG.
+choiceDateField-label=Date et heure
+choiceDateField-regexp=\\d{2}\/\\d{2}\/\\d{4}( \\d{2}\\:\\d{2})?
+choiceDateField-regexp-message=La date doit-\u00eatre au format 31/12/2000 23:59.
+
# FORM:: user
firstName-label=Pr\u00e9nom
lastName-label=Nom
Added: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceDateForm.tml
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceDateForm.tml (rev 0)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceDateForm.tml 2010-05-25 15:13:12 UTC (rev 3013)
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<body xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
+ xmlns:p="tapestry:parameter">
+
+ <div id="p-pollForm-choices">
+ <fieldset>
+ <legend>
+ CHOICE_DATE
+ </legend>
+ <div t:type="loop" t:source="choices" t:value="choice"
+ t:volatile="true" class="clearfix">
+ <div class="fleft choiceName">
+ <label t:type="label" t:for="choiceDateField" />:
+ <input t:type="ck/dateTimeField"
+ t:id="choiceDateField"
+ value="choice.date" t:validate="regexp"
+ t:datePattern="message:date-pattern"
+ t:timePicker="true"
+ t:timePickerAdjacent="true" />
+ <label t:type="label" t:for="choiceDescription" />:
+ </div>
+ <div class="fleft">
+ <textarea t:type="textarea" cols="34" rows="1"
+ t:id="choiceDescription"
+ t:value="choice.description" />
+ </div>
+ </div>
+ </fieldset>
+ </div>
+</body>
\ No newline at end of file
Property changes on: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceDateForm.tml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceImageForm.tml
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceImageForm.tml (rev 0)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceImageForm.tml 2010-05-25 15:13:12 UTC (rev 3013)
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<body xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
+ xmlns:p="tapestry:parameter">
+
+ <div id="p-pollForm-choices">
+ <fieldset>
+ <legend>
+ CHOICE_IMAGE
+ </legend>
+ <div t:type="loop" t:source="choices" t:value="choice"
+ t:volatile="true" class="clearfix">
+ <div class="fleft choiceName">
+ <label t:type="label"
+ t:for="choiceImageField" />:
+ <input type="file" class="nameField"
+ t:type="upload" t:id="choiceImageField"
+ value="choice.image" />
+ <label t:type="label" t:for="choiceDescription" />:
+ </div>
+ <div class="fleft">
+ <textarea t:type="textarea" cols="34" rows="1"
+ t:id="choiceDescription"
+ t:value="choice.description" />
+ </div>
+ </div>
+ </fieldset>
+ </div>
+</body>
\ No newline at end of file
Property changes on: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceImageForm.tml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceTextForm.tml
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceTextForm.tml (rev 0)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceTextForm.tml 2010-05-25 15:13:12 UTC (rev 3013)
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<body xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
+ xmlns:p="tapestry:parameter">
+
+ <div id="p-pollForm-choices">
+ <fieldset>
+ <legend>
+ CHOICE_TEXT
+ </legend>
+ <div t:type="loop" t:source="choices" t:value="choice"
+ t:volatile="true" class="clearfix">
+ <div class="fleft choiceName">
+ <label t:type="label" t:for="choiceTextField" />:
+ <input type="text" class="nameField"
+ t:type="textfield" t:id="choiceTextField"
+ value="choice.text" />
+ <label t:type="label" t:for="choiceDescription" />:
+ </div>
+ <div class="fleft">
+ <textarea t:type="textarea" cols="34" rows="1"
+ t:id="choiceDescription"
+ t:value="choice.description" />
+ </div>
+ </div>
+ </fieldset>
+ </div>
+</body>
\ No newline at end of file
Property changes on: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/ChoiceTextForm.tml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-25 12:40:47 UTC (rev 3012)
+++ trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-25 15:13:12 UTC (rev 3013)
@@ -367,74 +367,36 @@
</t:if>
</div>
</fieldset>
- <p class="center">
- <input t:type="submit" t:id="choiceStep" value="CHOICE" />
- </p>
</div>
- </t:formFragment>
- <t:formFragment t:id="choiceFormFragment" t:visible="choiceStep">
-
- <!-- CHOICES -->
- <div id="p-pollForm-choices">
- <fieldset>
- <legend>
- <label t:type="label" t:for="choiceType" />:
- <select t:type="select" t:id="choiceType"
- t:value="poll.choiceType" t:validate="required"
- t:mixins="nuiton/zoneUpdater" t:event="change"
- t:zone="p-pollForm-choices-zone" />
- </legend>
- <t:zone t:id="choicesZone" id="p-pollForm-choices-zone">
- <t:subForm t:visible="refreshChoicesZone">
- <div t:type="loop" t:source="choices" t:value="choice"
- t:volatile="true" class="clearfix">
- <div class="fleft choiceName">
- <t:delegate t:to="choiceTypeBlock" />
- <t:block t:id="choiceText">
- <label t:type="label" t:for="choiceTextField" />:
- <input type="text" class="nameField"
- t:type="textfield" t:id="choiceTextField"
- value="choice.text" />
- </t:block>
- <t:block t:id="choiceDate">
- <label t:type="label" t:for="choiceDateField" />:
- <input t:type="ck/dateTimeField"
- t:id="choiceDateField"
- value="choice.date" t:validate="regexp"
- t:datePattern="message:date-pattern"
- t:timePicker="true"
- t:timePickerAdjacent="true" />
- </t:block>
- <t:block t:id="choiceImage">
- <label t:type="label"
- t:for="choiceImageField" />:
- <input type="file" class="nameField"
- t:type="upload" t:id="choiceImageField"
- value="choice.image"
- t:validate="regexp" />
- </t:block>
- <t:block t:id="choiceDisplay">
- ${choice.name}
- </t:block>
-
- <t:label t:for="choiceDescription" />
- :
- </div>
- <div class="fleft">
- <t:textarea cols="34" rows="1"
- t:id="choiceDescription"
- t:value="choice.description" />
- </div>
- </div>
- </t:subForm>
- </t:zone>
- </fieldset>
- </div>
<p class="center">
- <input t:type="submit" t:id="mainStep" value="PREVIOUS" />
- <input t:type="submit" t:id="save" value="SAVE" />
+ <input t:type="submit" t:id="choiceText" value="TEXT" />
+ <input t:type="submit" t:id="choiceDate" value="DATE" />
+ <input t:type="submit" t:id="choiceImage" value="IMAGE" />
</p>
</t:formFragment>
</form>
+ <t:if t:test="choiceStep">
+ <!--<t:zone id="p-pollForm-choiceZone">-->
+
+ <!--</t:zone>-->
+ <form t:type="form" t:id="choiceForm" action="tapestry">
+ <t:errors />
+ <!-- CHOICES - Formulaire différent car t:upload ne fonctionne pas en ajax -->
+ <t:delegate t:to="choiceTypeBlock" />
+ <t:block t:id="choiceTextBlock">
+ <t:choiceTextForm t:model="model" />
+ </t:block>
+ <t:block t:id="choiceDateBlock">
+ <t:choiceDateForm t:model="model" />
+ </t:block>
+ <t:block t:id="choiceImageBlock">
+ <t:choiceImageForm t:model="model" />
+ </t:block>
+ <p class="center">
+ <input t:type="submit" t:id="mainStep" value="PREVIOUS" />
+ <input t:type="submit" t:id="save" value="SAVE" />
+ </p>
+ </form>
+ </t:if>
</t:zone>
</html>
1
0
Author: fdesbois
Date: 2010-05-25 14:40:47 +0200 (Tue, 25 May 2010)
New Revision: 3012
Url: http://chorem.org/repositories/revision/pollen/3012
Log:
- Create component ChoiceImage (not tested)
- Vote page is ok to render from now
- Add test of name nullity on addChoice for saving new poll
Added:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
Removed:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/ChoiceImpl.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-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.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/ServiceImage.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -4,6 +4,7 @@
import org.chorem.pollen.bean.Filter;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.FavoriteParticipant;
+import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.entity.PollAccount;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaDAO;
@@ -34,11 +35,15 @@
return getEntityProperty(FavoriteParticipant.class, alias);
}
- public EntityQueryProperty getPollCreatorProperty(
+ public EntityQueryProperty getPollAccountProperty(
String alias) {
return getEntityProperty(PollAccount.class, alias);
}
+ public EntityQueryProperty getPollProperty(String alias) {
+ return getEntityProperty(Poll.class, alias);
+ }
+
public TopiaQuery createQueryFindFavoriteParticipantsByFavoriteList(
Filter filter) {
@@ -56,4 +61,19 @@
return query;
}
+ public TopiaQuery createQueryFindVotesByPoll(Filter filter) {
+
+ EntityQueryProperty accountProperty = getPollAccountProperty("A");
+
+ EntityQueryProperty pollProperty = getPollProperty("P");
+ pollProperty.setPropertyJoin(Poll.POLL_ACCOUNT);
+
+ createQueryFindElementsByCollection(
+ accountProperty, pollProperty, filter);
+
+ query.addNotNull(accountProperty.nameProperty(PollAccount.VOTE_DATE));
+
+ return query;
+ }
+
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/ChoiceImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/ChoiceImpl.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/ChoiceImpl.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -1,6 +1,7 @@
package org.chorem.pollen.entity;
+import org.apache.commons.lang.StringUtils;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.votecounting.business.NumberMethod;
@@ -30,13 +31,14 @@
}
@Override
- public boolean getHidden() {
- return getName().startsWith(NumberMethod.HIDDEN_PREFIX);
+ public boolean isHidden() {
+ return StringUtils.isNotEmpty(name) &&
+ name.startsWith(NumberMethod.HIDDEN_PREFIX);
}
@Override
public void setHidden(boolean hidden) {
- boolean previous = getHidden();
+ boolean previous = isHidden();
if (hidden && !previous) {
setName(NumberMethod.HIDDEN_PREFIX + name);
} else if (!hidden && previous) {
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-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -1,13 +1,20 @@
package org.chorem.pollen.service;
+import org.chorem.pollen.EntityQueryProperty;
import org.chorem.pollen.PollenContext;
+import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
+import org.chorem.pollen.PollenQueryBuilder;
+import org.chorem.pollen.bean.Filter;
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.VoteDAO;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
import java.util.List;
@@ -58,11 +65,35 @@
}
@Override
- protected List<PollAccount> executeGetVotes(TopiaContext transaction, Poll poll, int startIndex, int endIndex) throws Exception {
- return null;
+ protected List<PollAccount> executeGetVotes(TopiaContext transaction,
+ Filter filter)
+ throws Exception {
+
+ PollenQueryBuilder builder = context.newQueryBuilder(null);
+
+ TopiaQuery query = builder.createQueryFindVotesByPoll(filter);
+
+ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction);
+
+ query.addLoad(PollAccount.CHOICE_VOTE);
+
+ List<PollAccount> results = dao.findAllByQuery(query);
+ return results;
}
@Override
+ protected int executeGetNbVotes(TopiaContext transaction, Filter filter)
+ throws TopiaException {
+
+ PollenQueryBuilder builder = context.newQueryBuilder(null);
+
+ TopiaQuery query = builder.createQueryFindVotesByPoll(filter);
+
+ int result = query.executeCount(transaction);
+ return result;
+ }
+
+ @Override
protected void executeDeleteVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
}
}
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-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-25 12:40:47 UTC (rev 3012)
@@ -77,6 +77,7 @@
pollen.error.serviceUser.updateUser=
pollen.error.serviceVote.canVote=
pollen.error.serviceVote.deleteVote=
+pollen.error.serviceVote.getNbVotes=
pollen.error.serviceVote.getNewPollAccount=
pollen.error.serviceVote.getPollAccount=
pollen.error.serviceVote.getVote=
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-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-25 12:40:47 UTC (rev 3012)
@@ -76,6 +76,7 @@
pollen.error.serviceUser.updateUser=
pollen.error.serviceVote.canVote=
pollen.error.serviceVote.deleteVote=
+pollen.error.serviceVote.getNbVotes=
pollen.error.serviceVote.getNewPollAccount=
pollen.error.serviceVote.getPollAccount=
pollen.error.serviceVote.getVote=
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -218,8 +218,7 @@
public String getServerPath() {
if (serverPath == null) {
- serverPath = "http://" + request.getHeader("host") +
- request.getContextPath();
+ serverPath = "http://" + request.getHeader("host");
if (logger.isDebugEnabled()) {
logger.debug("URL : " + serverPath);
}
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -0,0 +1,66 @@
+package org.chorem.pollen.ui.components;
+
+import org.apache.tapestry5.ClientElement;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.StreamResponse;
+import org.apache.tapestry5.annotations.Log;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.corelib.base.AbstractLink;
+import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.services.ServiceImage;
+import org.slf4j.Logger;
+
+/**
+ * Created: 25 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+@SupportsInformalParameters
+public class ChoiceImage extends AbstractLink {
+
+ @Parameter(required = true)
+ private ChoiceField source;
+
+ @Inject
+ private Logger logger;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Inject
+ private ServiceImage serviceImage;
+
+ void beginRender(MarkupWriter writer) {
+
+ Link link = resources.createEventLink("showImage",
+ source.getImageFileName(), source.getImageDir(), false);
+
+ Link thumbLink = resources.createEventLink("showImage",
+ source.getImageFileName(), source.getImageDir(), true);
+
+ writeLink(writer, link, "rel", "lightbox[pollChoiceImages]");
+ writer.element("img", "src", thumbLink, "alt", source.getDescription());
+ writer.end();
+ }
+
+ /**
+ * Event for showing image.
+ *
+ * @param src of the image
+ * @param imageDir directory of the image
+ * @param thumb to show the thumb image or not
+ * @return the streamResponse to display
+ * @see ServiceImage#createImageStream(String, String, boolean)
+ */
+ @Log
+ public StreamResponse onShowImage(String src, String imageDir,
+ boolean thumb) {
+ return serviceImage.createImageStream(src, imageDir, thumb);
+ }
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ChoiceImage.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -93,7 +93,7 @@
* Instantiate a new choiceField for a Date ChoiceType.
*
* @return the ChoiceField which is date typed
- * @see #setDateType(java.lang.String)
+ * @see #setDateType()
*/
public static ChoiceField getChoiceDate() {
ChoiceField result = new ChoiceField();
@@ -131,7 +131,7 @@
* Change type of the choice to date type. The date type need a {@code
* pattern} to format the date when saving the choice.
*
- * @see #saveName()
+ * @see #saveName(ServiceImage)
*/
public void setDateType() {
setChoiceType(ChoiceType.DATE);
@@ -143,7 +143,7 @@
* of the choice as saving folder for the resulting image file.
*
* @param pollUId used as saving folder
- * @see #saveName()
+ * @see #saveName(ServiceImage)
*/
public void setImageType(String pollUId) {
setChoiceType(ChoiceType.IMAGE);
@@ -262,5 +262,7 @@
return getChoice().getChoiceType();
}
-
+ public boolean isHidden() {
+ return choice.isHidden();
+ }
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -1,6 +1,8 @@
package org.chorem.pollen.ui.data;
+import org.apache.commons.lang.StringUtils;
+
/**
* PollUri
*
@@ -64,4 +66,8 @@
return uri;
}
+ public boolean hasAccountUid() {
+ return StringUtils.isNotEmpty(accountUid);
+ }
+
}
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-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -322,7 +322,10 @@
poll.clearChoice();
for (ChoiceField choiceField : getChoices()) {
choiceField.saveName(serviceImage);
- poll.addChoice(choiceField.getChoice());
+ Choice choice = choiceField.getChoice();
+ if (StringUtils.isNotEmpty(choice.getName())) {
+ poll.addChoice(choice);
+ }
}
poll = servicePoll.createPoll(poll, getLists());
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -15,10 +15,7 @@
* Created: 23 avr. 2010
*
* @author fdesbois
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$
- * par : $Author$
+ * @version $Id$
*/
public class UserAccountDataSource extends AbstractMappedGridDataSource<String, UserAccount> {
@@ -33,7 +30,8 @@
@Override
protected Map<String, UserAccount> execute(int startIndex, int endIndex,
- SortConstraint orderBy) throws PollenException {
+ SortConstraint orderBy)
+ throws PollenException {
filter.setStartIndex(startIndex);
filter.setEndIndex(endIndex);
filter.setOrderBy(resolveOrderBy(orderBy));
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -1,61 +0,0 @@
-package org.chorem.pollen.ui.models;
-
-import org.chorem.pollen.PollenBusinessException;
-import org.chorem.pollen.entity.Poll;
-import org.chorem.pollen.entity.PollAccount;
-import org.chorem.pollen.entity.UserAccount;
-import org.chorem.pollen.service.ServicePoll;
-import org.chorem.pollen.service.ServiceVote;
-import org.chorem.pollen.ui.data.PollUri;
-
-/**
- * Created: 21 mai 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-public class VoteModel {
-
- protected Poll poll;
-
- protected PollAccount account;
-
- protected ServicePoll servicePoll;
-
- protected ServiceVote serviceVote;
-
- public VoteModel(ServicePoll servicePoll, ServiceVote serviceVote) {
- this.servicePoll = servicePoll;
- }
-
- public void init(PollUri uri)
- throws PollenBusinessException {
- poll = servicePoll.getPoll(uri.getPollUid());
- account = serviceVote.getPollAccount(uri.getAccountUid());
- }
-
- public Poll getPoll() {
- return poll;
- }
-
- public boolean isCreatorUser(UserAccount user) {
- return user.equals(poll.getCreator().getUserAccount());
- }
-
- public PollAccount getPollAccount() {
- if (account == null) {
- account = serviceVote.getNewPollAccount();
- }
- return account;
- }
-
- public boolean isAllowedToVote() {
- if (poll.isFinished()) {
- return false;
- }
- if (poll.getPollType().isRestrictedOrGroup() || poll.getAnonymous()) {
- return serviceVote.canVote(poll, account);
- }
- return true;
- }
-}
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-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -28,7 +28,6 @@
import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.StreamResponse;
-import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -36,17 +35,15 @@
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
-import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.chorem.pollen.PollenBusinessException;
-import org.chorem.pollen.PollenBusinessException.PollenExceptionType;
import org.chorem.pollen.PollenProperty;
+import org.chorem.pollen.bean.Filter;
import org.chorem.pollen.entity.Choice;
-import org.chorem.pollen.entity.Comment;
-import org.chorem.pollen.entity.CommentImpl;
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.ServicePoll;
import org.chorem.pollen.service.ServiceUser;
@@ -56,11 +53,10 @@
import org.chorem.pollen.ui.components.Pager;
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.data.EvenOdd;
import org.chorem.pollen.ui.data.PollUri;
-import org.chorem.pollen.ui.models.VoteModel;
import org.chorem.pollen.ui.services.PollenManager;
import org.chorem.pollen.ui.services.ServiceImage;
-import org.nuiton.web.tapestry5.components.FeedBack;
import org.slf4j.Logger;
/**
@@ -82,6 +78,14 @@
return border;
}
+ @Parameter(defaultPrefix = BindingConstants.MESSAGE, value = "title")
+ @Property
+ private String title;
+
+ @Property
+ private PollUri uri;
+
+ /** Services injected */
@Inject
private Logger logger;
@@ -89,22 +93,10 @@
private Messages messages;
@Inject
- private PollenManager manager;
+ private Locale currentLocale;
- @Property
- private PollUri uri;
-
- /** TEMP : Affichage des messages pour l'utilisateur */
-// @Component(id = "feedback")
-// private FeedBack feedback;
-
- @Parameter(defaultPrefix = BindingConstants.MESSAGE, value = "title")
- @Property
- private String title;
-
- /** Locale courante */
@Inject
- private Locale currentLocale;
+ private PollenManager manager;
@Inject
private ServicePoll servicePoll;
@@ -115,15 +107,13 @@
@Inject
private ServiceVote serviceVote;
- /** Compte du votant */
+ /** Page properties */
+ private Poll poll;
+
private PollAccount pollAccount;
- /** Format des dates */
private DateFormat dateFormat;
- @Persist
- private VoteModel model;
-
/**
* Address bar of the page. Display in Border layout component.
*
@@ -143,16 +133,15 @@
Object[] onPassivate() {
return new Object[]{uri, page};
}
-
@Log
void setupRender() {
if (uri == null) {
addFatal("Url null");
} else {
- model = null;
try {
- getModel().init(uri);
+ getPoll();
+ //pollAccount = serviceVote.getPollAccount(uri.getAccountUid());
} catch (PollenBusinessException eee) {
// Poll not found
String message = manager.getErrorMessage(logger, messages, eee);
@@ -183,12 +172,7 @@
// }
}
- public VoteModel getModel() {
- if (model != null) {
- model = new VoteModel(servicePoll, serviceVote);
- }
- return model;
- }
+ /************** POLL INFOS ************************************************/
/**
* DateFormat used in the page.
@@ -203,20 +187,33 @@
return dateFormat;
}
- public Poll getPoll() {
- return getModel().getPoll();
+ public Poll getPoll() throws PollenBusinessException {
+ if (poll == null) {
+ poll = servicePoll.getPoll(uri.getPollUid(), Poll.CHOICE);
+ }
+ return poll;
}
+ public PollAccount getCreator() throws PollenBusinessException {
+ return getPoll().getCreator();
+ }
+
/**
* Use a PollAccount to represent the current session user.
- * The existing account is used if accountUid is present in the uri.
- * Otherwise a new account is instanciate with user properties
- * (for vote name).
+ * The existing pollAccount is used if accountUid is present in the uri.
+ * Otherwise a new pollAccount is instanciate.
*
* @return
*/
- public PollAccount getPollAccount() throws PollenBusinessException {
- return getModel().getPollAccount();
+ public PollAccount getPollAccount() {
+ if (pollAccount == null) {
+ if (uri.hasAccountUid()) {
+ pollAccount = serviceVote.getPollAccount(uri.getAccountUid());
+ } else {
+ pollAccount = serviceVote.getNewPollAccount();
+ }
+ }
+ return pollAccount;
}
/**
@@ -226,63 +223,15 @@
* @throws PollenBusinessException
*/
public boolean isCreatorUser() throws PollenBusinessException {
- return isUserConnected() && getModel().isCreatorUser(getUserConnected());
+ UserAccount creatorAccount = poll.getCreator().getUserAccount();
+ return isUserConnected() && getUserConnected().equals(creatorAccount);
}
- /************** PAGER *****************************************************/
-
- @InjectComponent
- private Pager pager;
-
- private Integer page;
-
- @Persist
- private Integer nbVotesPerPage;
-
- public int getPage() {
- if (page == null) {
- page = pager.getFirstPage();
- }
- return page;
+ public String getHelpMessage() {
+ // Help message depends on voteCountingType
+ return "";
}
- @Log
- public void setPage(int page) {
- this.page = page;
- }
-
- /**
- * Get the number of votes to display per page from configuration.
- *
- * @return the number of votes to display per page
- */
- public int getNbVotesPerPage() {
- if (nbVotesPerPage == null) {
- nbVotesPerPage = getPagerRange();
- }
- return nbVotesPerPage;
- }
-
- public void setNbVotesPerPage(int nbVotesPerPage) {
- this.nbVotesPerPage = nbVotesPerPage;
- }
-
- public int getPagerRange() {
- return Integer.parseInt(
- manager.getProperty(PollenProperty.NB_VOTES_PER_PAGE));
- }
-
- public String getNoPagerText() throws PollenBusinessException {
- // FIXME : manage nbVotes in Poll
-
-// if (getPoll().getNbVotes() == 0) {
-// return messages.get("pollen.ui.vote.noVote");
-// }
-// return messages.format("pollen.ui.vote.noPager",
-// getPoll().getNbVotes());
- return "";
- }
-
/************** CHOICES ***************************************************/
private List<ChoiceField> choices;
@@ -298,24 +247,27 @@
@Inject
private Block choiceDate;
+//
+// private ChoiceField newChoice;
+//
+// @Inject
+// private Block newChoiceText;
+//
+// @Inject
+// private Block newChoiceImage;
+//
+// @Inject
+// private Block newChoiceDate;
- private ChoiceField newChoice;
-
@Inject
- private Block newChoiceText;
-
- @Inject
- private Block newChoiceImage;
-
- @Inject
- private Block newChoiceDate;
-
- @Inject
private ComponentResources resources;
@Inject
private ServiceImage serviceImage;
+ @Property
+ private EvenOdd evenOdd = new EvenOdd();
+
/**
* Get choices of the poll. The ChoiceDTO from poll will be converted
* to ChoiceField to easily managed different type of choice (image,
@@ -359,154 +311,229 @@
}
}
- /**
- * Image link to show the miniature (thumb) of current choice image.
- *
- * @return the image link for current choice image.
- */
- public Link getImageThumb() {
- return getImageLink(true);
- }
+// /**
+// * Image link to show the miniature (thumb) of current choice image.
+// *
+// * @return the image link for current choice image.
+// */
+// public Link getImageThumb() {
+// return getImageLink(true);
+// }
+//
+// /**
+// * Image link to show the normal (not thumb) image of current choice image.
+// *
+// * @return the image link for current choice image.
+// */
+// public Link getImageLink() {
+// return getImageLink(false);
+// }
+//
+// private Link getImageLink(boolean thumb) {
+// return resources.createEventLink("showImage",
+// choice.getImageFileName(), choice.getImageDir(), thumb);
+// }
+//
+// /**
+// * Event for showing image.
+// *
+// * @param src of the image
+// * @param imageDir directory of the image
+// * @param thumb to show the thumb image or not
+// * @return the streamResponse to display
+// * @see ServiceImage#createImageStream(String, String, boolean)
+// */
+// @Log
+// public StreamResponse onShowImage(String src, String imageDir,
+// boolean thumb) {
+// return serviceImage.createImageStream(src, imageDir, thumb);
+// }
+//
+// /**
+// * Delegator : Retrieve the newChoice to create a choice in the poll
+// * using the addChoice form.
+// *
+// * @return a ChoiceField to manage different choice type
+// * @throws PollenBusinessException
+// */
+// public ChoiceField getNewChoice() throws PollenBusinessException {
+// if (newChoice == null) {
+// newChoice = new ChoiceField(getPoll());
+//// switch (getPoll().getChoiceType()) {
+//// case DATE:
+//// newChoice = ChoiceField.getChoiceDate();
+//// break;
+//// case IMAGE:
+//// newChoice = ChoiceField.getChoiceImage(
+//// getPoll().getPollUid());
+//// break;
+//// case TEXT:
+//// default:
+//// newChoice = ChoiceField.getChoiceText();
+//// }
+// // Don't know what validate is
+//// newChoice.setValidate(true);
+// }
+// return newChoice;
+// }
+//
+// /**
+// * Retrieve the block to display for input choiceName depends on
+// * choice type.
+// *
+// * @return the block to display
+// * @throws PollenBusinessException
+// */
+//// public Block getNewChoiceBlock() throws PollenBusinessException {
+//// switch(getPoll().getChoiceType()) {
+//// case IMAGE:
+//// return newChoiceImage;
+//// case DATE:
+//// return newChoiceDate;
+//// case TEXT:
+//// default:
+//// return newChoiceText;
+//// }
+//// }
+//
+// public boolean isPollChoiceRunning() throws PollenBusinessException {
+// return getPoll().getChoiceAddAllowed() && isPollChoiceStarted();
+// }
+//
+// /**
+// * TODO : whithout DTO, this method can be place in PollEntity
+// *
+// * @return true if adding choice is started, false otherwise
+// * @throws PollenBusinessException
+// */
+// public boolean isPollChoiceStarted() throws PollenBusinessException {
+// Date now = new Date();
+// boolean started = getPoll().getBeginChoiceDate() == null
+// || getPoll().getBeginChoiceDate().before(now);
+// boolean ended = getPoll().getEndChoiceDate() != null
+// && getPoll().getEndChoiceDate().before(now);
+// return started && !ended;
+// }
+//
+// public boolean getCanDeleteChoice() throws PollenBusinessException {
+// return isPollChoiceRunning() && isCreatorUser();
+// }
+//
+// /**
+// * ACTION EVENT :: delete selected choice
+// */
+// void onActionFromDeleteChoice(String choiceId)
+// throws PollenBusinessException {
+// if (getCanDeleteChoice()) {
+//
+//// servicePoll.deleteChoice(getPoll(), choiceId);
+// // Reset choices (ChoiceField list) to retrieve the updated one
+// // from poll
+// choices = null;
+// }
+// }
+//
+// public boolean getCanAddChoice() throws PollenBusinessException {
+// return isPollChoiceRunning();
+// }
+//
+// /**
+// * SUCCESS EVENT :: add a new choice from addChoice form.
+// *
+// * @throws PollenBusinessException
+// */
+// void onSuccessFromAddChoice() throws PollenBusinessException {
+// if (getCanAddChoice()) {
+// // No validation done on choice with existing name
+// // Save name depends on choice type
+// newChoice.saveName(serviceImage);
+// //getPoll().addChoice(newChoice.getChoice());
+// }
+// }
- /**
- * Image link to show the normal (not thumb) image of current choice image.
- *
- * @return the image link for current choice image.
- */
- public Link getImageLink() {
- return getImageLink(false);
- }
+ /************** PAGER *****************************************************/
- private Link getImageLink(boolean thumb) {
- return resources.createEventLink("showImage",
- choice.getImageFileName(), choice.getImageDir(), thumb);
+ @InjectComponent
+ private Pager pager;
+
+ private Integer page;
+
+ @Persist
+ private Integer nbVotesPerPage;
+
+ private Integer nbVotes;
+
+ public int getPage() {
+ if (page == null) {
+ page = pager.getFirstPage();
+ }
+ return page;
}
- /**
- * Event for showing image.
- *
- * @param src of the image
- * @param imageDir directory of the image
- * @param thumb to show the thumb image or not
- * @return the streamResponse to display
- * @see ServiceImage#createImageStream(String, String, boolean)
- */
@Log
- public StreamResponse onShowImage(String src, String imageDir,
- boolean thumb) {
- return serviceImage.createImageStream(src, imageDir, thumb);
+ public void setPage(int page) {
+ this.page = page;
}
-
+
/**
- * Delegator : Retrieve the newChoice to create a choice in the poll
- * using the addChoice form.
+ * Get the number of votes to display per page from configuration.
*
- * @return a ChoiceField to manage different choice type
- * @throws PollenBusinessException
+ * @return the number of votes to display per page
*/
- public ChoiceField getNewChoice() throws PollenBusinessException {
- if (newChoice == null) {
- newChoice = new ChoiceField(getPoll());
-// switch (getPoll().getChoiceType()) {
-// case DATE:
-// newChoice = ChoiceField.getChoiceDate();
-// break;
-// case IMAGE:
-// newChoice = ChoiceField.getChoiceImage(
-// getPoll().getPollUid());
-// break;
-// case TEXT:
-// default:
-// newChoice = ChoiceField.getChoiceText();
-// }
- // Don't know what validate is
-// newChoice.setValidate(true);
+ public int getNbVotesPerPage() {
+ if (nbVotesPerPage == null) {
+ nbVotesPerPage = getPagerRange();
}
- return newChoice;
+ return nbVotesPerPage;
}
- /**
- * Retrieve the block to display for input choiceName depends on
- * choice type.
- *
- * @return the block to display
- * @throws PollenBusinessException
- */
-// public Block getNewChoiceBlock() throws PollenBusinessException {
-// switch(getPoll().getChoiceType()) {
-// case IMAGE:
-// return newChoiceImage;
-// case DATE:
-// return newChoiceDate;
-// case TEXT:
-// default:
-// return newChoiceText;
-// }
-// }
-
- public boolean isPollChoiceRunning() throws PollenBusinessException {
- return getPoll().getChoiceAddAllowed() && isPollChoiceStarted();
+ public void setNbVotesPerPage(int nbVotesPerPage) {
+ this.nbVotesPerPage = nbVotesPerPage;
}
- /**
- * TODO : whithout DTO, this method can be place in PollEntity
- *
- * @return true if adding choice is started, false otherwise
- * @throws PollenBusinessException
- */
- public boolean isPollChoiceStarted() throws PollenBusinessException {
- Date now = new Date();
- boolean started = getPoll().getBeginChoiceDate() == null
- || getPoll().getBeginChoiceDate().before(now);
- boolean ended = getPoll().getEndChoiceDate() != null
- && getPoll().getEndChoiceDate().before(now);
- return started && !ended;
+ public int getPagerRange() {
+ return Integer.parseInt(
+ manager.getProperty(PollenProperty.NB_VOTES_PER_PAGE));
}
- public boolean getCanDeleteChoice() throws PollenBusinessException {
- return isPollChoiceRunning() && isCreatorUser();
- }
-
- /**
- * ACTION EVENT :: delete selected choice
- */
- void onActionFromDeleteChoice(String choiceId)
- throws PollenBusinessException {
- if (getCanDeleteChoice()) {
-
-// servicePoll.deleteChoice(getPoll(), choiceId);
- // Reset choices (ChoiceField list) to retrieve the updated one
- // from poll
- choices = null;
+ public int getNbVotes() throws PollenBusinessException {
+ if (nbVotes == null) {
+ Filter filter = new Filter();
+ filter.setReference(getPoll());
+ nbVotes = serviceVote.getNbVotes(filter);
}
+ return nbVotes;
}
- public boolean getCanAddChoice() throws PollenBusinessException {
- return isPollChoiceRunning();
+ @Log
+ public Filter getVoteFilter() throws PollenBusinessException {
+ Filter filter = new Filter();
+ filter.setStartIndex(pager.getStartIndex());
+ filter.setEndIndex(pager.getEndIndex());
+ filter.setReference(getPoll());
+ return filter;
}
- /**
- * SUCCESS EVENT :: add a new choice from addChoice form.
- *
- * @throws PollenBusinessException
- */
- void onSuccessFromAddChoice() throws PollenBusinessException {
- if (getCanAddChoice()) {
- // No validation done on choice with existing name
- // Save name depends on choice type
- newChoice.saveName(serviceImage);
- //getPoll().addChoice(newChoice.getChoice());
- }
+ public String getNoPagerText() throws PollenBusinessException {
+ // FIXME : manage nbVotes in Poll
+
+// if (getPoll().getNbVotes() == 0) {
+// return messages.get("pollen.ui.vote.noVote");
+// }
+// return messages.format("pollen.ui.vote.noPager",
+// getPoll().getNbVotes());
+ return "";
}
/************** VOTES *****************************************************/
- private List<Vote> votes;
+ private List<PollAccount> participants;
@Property
- private int voteIndex;
+ private int participantIndex;
- private Vote currentVote;
+ @Property
+ private PollAccount participant;
/**
* Retrieve votes of the current poll from business module.
@@ -516,19 +543,16 @@
* @return the list of votes to display
* @throws PollenBusinessException
*/
- public List<Vote> getVotes() throws PollenBusinessException {
- if (votes == null) {
-// votes = servicePoll.getVotes(getPoll(),
-// pager.getStartIndex(), pager.getEndIndex());
+ public List<PollAccount> getParticipants() throws PollenBusinessException {
+ if (participants == null) {
+ participants = serviceVote.getVotes(getVoteFilter());
}
- return votes;
+ return participants;
}
- public Vote getCurrentVote() {
- if (currentVote == null) {
-// currentVote = serviceVote.getNewVote(getPollAccount());
- }
- return currentVote;
+ public Vote getVote() {
+ Vote vote = participant.getChoiceVote(choice.getChoice());
+ return vote;
}
// /**
@@ -557,11 +581,17 @@
// }
public boolean getCanVote() {
- return getModel().isAllowedToVote();
+ if (poll.isFinished()) {
+ return false;
+ }
+ if (poll.getPollType().isRestrictedOrGroup() || poll.getAnonymous()) {
+ return serviceVote.canVote(poll, pollAccount);
+ }
+ return true;
}
public boolean canEditVote() throws PollenBusinessException {
- // If the current account exist from uri and equals to the current vote
+ // If the current pollAccount exist from uri and equals to the current vote
// String newAccountId = getPollAccount().getId();
// if (newAccountId != null &&
// newAccountId.equals(vote.getPollAccountId())) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -1,8 +1,10 @@
package org.chorem.pollen.ui.services;
+import org.apache.tapestry5.Link;
import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.upload.services.UploadedFile;
+import org.chorem.pollen.ui.data.ChoiceField;
/**
* This service is used to manage images in pollen application.
@@ -59,5 +61,4 @@
* @return the filename of the saved file
*/
String saveImage(UploadedFile tmpfile, String filedir);
-
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-05-25 12:40:47 UTC (rev 3012)
@@ -13,11 +13,13 @@
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.apache.commons.lang.StringUtils;
+import org.apache.tapestry5.Link;
import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.services.Response;
import org.apache.tapestry5.upload.services.UploadedFile;
import org.chorem.pollen.PollenProperty;
import org.chorem.pollen.PollenContext;
+import org.chorem.pollen.ui.data.ChoiceField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-25 09:29:17 UTC (rev 3011)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-25 12:40:47 UTC (rev 3012)
@@ -3,7 +3,7 @@
<html t:type="border" t:addressBar="addressBar" t:pageLogo="literal:Vote" t:feedFilename="prop:uri.pollUid"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
- <t:if test="poll">
+
<h1 class="titleVote">${poll.title}</h1>
<!-- Informations sur le sondage -->
@@ -13,18 +13,18 @@
<legend>${message:about}</legend>
<div style="float: right">
<t:if test="poll.publicResults">
- <a t:type="pagelink" t:page="poll/Results" t:context="poll.pollUid">
+ <a t:type="pagelink" t:page="poll/Results" t:context="poll.uid">
<img src="${asset:context:img/count.png}" title="${message:results-help}" alt="${message:results}"/>
</a>
</t:if>
- <t:FeedContextLink t:id="feedContext" />
- <t:if test="feedFileExisting">
- <t:FileLink filename="${poll.pollUid}" type="literal:application/atom+xml" t:context="feedContext">
- <img src="${asset:context:img/feed.png}" title="Atom" alt="Atom"/>
- </t:FileLink>
- </t:if>
+ <!--<t:FeedContextLink t:id="feedContext" />-->
+ <!--<t:if test="feedFileExisting">-->
+ <!--<t:FileLink filename="${poll.pollUid}" type="literal:application/atom+xml" t:context="feedContext">-->
+ <!--<img src="${asset:context:img/feed.png}" title="Atom" alt="Atom"/>-->
+ <!--</t:FileLink>-->
+ <!--</t:if>-->
</div>
- <label>${message:creator-label}</label> ${poll.creatorName}
+ <label>${message:creator-label}</label> ${creator.name}
<br/>
<label>${message:beginDate-label}</label>
<t:output value="poll.beginDate" format="dateFormat"/>
@@ -32,7 +32,7 @@
<label>${message:endDate-label}</label>
<t:output value="poll.endDate" format="dateFormat"/>
<br/>
- <label>${message:pollType-label}</label> ${poll.voteCounting}
+ <label>${message:pollType-label}</label> ${poll.voteCountingType}
<span t:type="ck/Tooltip" title="${message:help}" value="${helpMessage}" effect="appear">
<img src="${asset:context:img/help.png}" alt="${message:help}"/>
</span>
@@ -41,50 +41,51 @@
<!--<t:if test="pollChoiceOrVoteStarted">-->
- <!--<!– Sondage –>-->
+ <!-- Sondage -->
- <!--<!–<t:zone t:id="pollZone" t:show="show" t:update="show">–>-->
- <!--<t:if t:test="poll.anonymous">-->
- <!--<p>${voteSizeMessage}</p>-->
+ <!--<t:zone t:id="pollZone" t:show="show" t:update="show">-->
+ <t:if t:test="poll.anonymous">
+ <p>${format:vote-size=nbVotes}</p>
<!--<t:feedback t:id="voteFeedback"/>-->
- <!--<p:else>-->
- <!--<t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="poll.nbVotes"-->
- <!--t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>-->
- <!--</p:else>-->
- <!--</t:if>-->
- <!--<t:form t:id="voteForm" t:zone="pollZone">-->
- <!--<table id="poll">-->
- <!--<thead>-->
- <!--<tr>-->
- <!--<t:if test="${AccountFieldDisplayed}">-->
- <!--<th style="width:200px;">${message:voterName}</th>-->
+ <p:else>
+ <t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="nbVotes"
+ t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>
+ </p:else>
+ </t:if>
+ <t:form t:id="voteForm">
+ <table id="poll">
+ <thead>
+ <tr>
+ <!--<t:if test="accountFieldDisplayed">-->
+ <th style="width:200px;">${message:voterName}</th>
<!--<p:else>-->
<!--<th></th>-->
<!--</p:else>-->
<!--</t:if>-->
- <!--<th t:type="loop" t:source="choices" t:value="choice" t:volatile="true">-->
- <!--<t:unless test="choice.hidden">-->
- <!--<!– Blocks for each choice type –>-->
- <!--<t:block t:id="choiceText">-->
- <!--<span class="desc">${choice.text}</span>-->
- <!--</t:block>-->
- <!--<t:block t:id="choiceImage">-->
+ <th t:type="loop" t:source="choices" t:value="choice" t:volatile="true">
+ <t:unless test="choice.hidden">
+ <!-- Blocks for each choice type -->
+ <t:block t:id="choiceText">
+ <span class="desc">${choice.text}</span>
+ </t:block>
+ <t:block t:id="choiceImage">
+ <t:choiceImage t:source="choice" />
<!--<a rel="lightbox[pollChoiceImages]" href="${imageLink}">-->
<!--<img src="${imageThumb}" alt="${choice.description}"/>-->
<!--</a>-->
- <!--</t:block>-->
- <!--<t:block t:id="choiceDate">-->
- <!--<t:output value="choice.date" format="dateFormat"/>-->
- <!--</t:block>-->
- <!--<!– Display choice with or whithout description –>-->
- <!--<t:if t:test="choice.description">-->
- <!--<span t:type="ck/Tooltip" t:value="choice.description" t:effect="blind">-->
- <!--<t:delegate to="choiceBlock" />-->
- <!--</span>-->
- <!--<p:else>-->
- <!--<t:delegate to="choiceBlock" />-->
- <!--</p:else>-->
- <!--</t:if>-->
+ </t:block>
+ <t:block t:id="choiceDate">
+ <t:output value="choice.date" format="dateFormat"/>
+ </t:block>
+ <!-- Display choice with or whithout description -->
+ <t:if t:test="choice.description">
+ <span t:type="ck/Tooltip" t:value="choice.description" t:effect="blind">
+ <t:delegate to="choiceBlock" />
+ </span>
+ <p:else>
+ <t:delegate to="choiceBlock" />
+ </p:else>
+ </t:if>
<!--<t:if test="canDeleteChoice">-->
<!--<!– Action to delete the choice –>-->
<!--<t:actionlink t:id="deleteChoice" context="choice.id"-->
@@ -93,10 +94,10 @@
<!--alt="message:pollen.ui.choice.delete.title"/>-->
<!--</t:actionlink>-->
<!--</t:if>-->
- <!--</t:unless>-->
- <!--</th>-->
- <!--</tr>-->
- <!--</thead>-->
+ </t:unless>
+ </th>
+ </tr>
+ </thead>
<!--<t:if test="canVote">-->
<!--<tfoot>-->
<!--<tr>-->
@@ -109,7 +110,7 @@
<!--</p:else>-->
<!--</t:if>-->
<!--<t:loop t:source="choices" t:value="choice" volatile="true">-->
- <!--<t:if test="!choice.hidden">-->
+ <!--<t:unless test="choice.hidden">-->
<!--<th>-->
<!--<t:if test="poll.voteCounting.normal">-->
<!--<input t:type="checkbox" value="addChoice" />-->
@@ -124,23 +125,23 @@
<!--<t:textField t:value="addNumberVote" size="3" />-->
<!--</t:if>-->
<!--</th>-->
- <!--</t:if>-->
+ <!--</t:unless>-->
<!--</t:loop>-->
<!--</tr>-->
<!--</tfoot>-->
<!--</t:if>-->
- <!--<tbody>-->
- <!--<t:unless t:test="poll.anonymous">-->
- <!--<t:loop t:source="votes" t:value="vote" t:rowIndex="voteIndex" volatile="true">-->
- <!--<tr>-->
- <!--<td class="${evenodd.next}">-->
- <!--<t:if test="${AccountFieldDisplayed}">-->
- <!--<t:unless test="${currentVoteAnonymous}">-->
- <!--${vote.name}-->
- <!--<p:else>-->
- <!--?-->
- <!--</p:else>-->
- <!--</t:unless>-->
+ <tbody>
+ <t:unless t:test="poll.anonymous">
+ <t:loop t:source="participants" t:value="participant" t:rowIndex="participantIndex" volatile="true">
+ <tr>
+ <td class="${evenodd.next}">
+ <!--<t:if test="accountFieldDisplayed">-->
+ <t:if test="participant.anonymous">
+ ?
+ <p:else>
+ ${participant.name}
+ </p:else>
+ </t:if>
<!--</t:if>-->
<!--<t:unless test="${poll.anonymous}">-->
<!--<t:if test="canEditVote()">-->
@@ -154,21 +155,24 @@
<!--</t:actionlink>-->
<!--</t:if>-->
<!--</t:unless>-->
- <!--</td>-->
- <!--<t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">-->
- <!--<t:unless t:test="choiceHidden">-->
+ </td>
+ <t:loop t:source="choices" t:value="choice" volatile="true">
+ <t:unless t:test="choice.hidden">
<!--${setCurrentVoteChoice()}-->
- <!--<t:if t:test="poll.anonymous">-->
- <!--<td class="anonymous">?</td>-->
- <!--<p:else>-->
- <!--<t:if test="isNormalVoteCounting()">-->
- <!--<t:if test="isChoiceInVote(currentVoteChoice)">-->
- <!--<td class="voted">OK</td>-->
- <!--<p:else>-->
- <!--<td class="notVoted"></td>-->
- <!--</p:else>-->
- <!--</t:if>-->
- <!--</t:if>-->
+ <t:if t:test="poll.anonymous">
+ <td class="anonymous">?</td>
+ <p:else>
+ <t:if test="vote">
+ <t:if test="poll.voteCountingType.normal">
+ <td class="voted">OK</td>
+ <p:else>
+ <td class="voted">${vote.voteValue}</td>
+ </p:else>
+ </t:if>
+ <p:else>
+ <td class="notVoted"></td>
+ </p:else>
+ </t:if>
<!--<t:if test="isPercentageVoteCounting()">-->
<!--<t:if test="isChoiceInVote(currentVoteChoice)">-->
<!--<td class="voted">${currentVoteChoice.value} %</td>-->
@@ -193,13 +197,13 @@
<!--</p:else>-->
<!--</t:if>-->
<!--</t:if>-->
- <!--</p:else>-->
- <!--</t:if>-->
- <!--</t:unless>-->
- <!--</t:loop>-->
- <!--</tr>-->
- <!--</t:loop>-->
- <!--</t:unless>-->
+ </p:else>
+ </t:if>
+ </t:unless>
+ </t:loop>
+ </tr>
+ </t:loop>
+ </t:unless>
<!--<t:if test="poll.continuousResults">-->
<!--<tr>-->
<!--<td>-->
@@ -212,11 +216,11 @@
<!--</t:loop>-->
<!--</tr>-->
<!--</t:if>-->
- <!--</tbody>-->
- <!--</table>-->
- <!--<div id="voteError">-->
- <!--<t:errors/>-->
- <!--</div>-->
+ </tbody>
+ </table>
+ <div id="voteError">
+ <t:errors/>
+ </div>
<!--<t:if test="poll.running">-->
<!--<div id="buttons">-->
<!--<t:if test="anonymousVoteDisplayed">-->
@@ -227,8 +231,9 @@
<!--<input t:id="submitVote" t:type="Submit" t:value="${message:submitVote}" />-->
<!--</div>-->
<!--</t:if>-->
- <!--</t:form>-->
- <!--<!–</t:zone>–>-->
+ </t:form>
+ <!--</t:zone>-->
+ <!--</t:if>-->
<!--<!– Ajout de choix –>-->
@@ -311,5 +316,5 @@
<!--</t:zone>-->
<!--</t:if>-->
- </t:if>
+
</html>
\ No newline at end of file
1
0