Author: fdesbois Date: 2010-06-02 23:38:06 +0200 (Wed, 02 Jun 2010) New Revision: 3027 Url: http://chorem.org/repositories/revision/pollen/3027 Log: Use addFetch method from TopiaQuery Added: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryHelper.java Removed: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.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/xmi/pollen.zargo trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -13,18 +13,13 @@ import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; import org.nuiton.i18n.init.DefaultI18nInitializer; import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.StringUtil; -import org.nuiton.util.beans.BinderBuilder; /** * PollenContext @@ -121,7 +116,7 @@ // Set context in PollenProperty enum to use easily method // getValue() on PollenProperty PollenProperty.setContext(this); - PollenUtils.setContext(this); + PollenQueryHelper.setContext(this); createSuperAdmin(serviceUser); // Copied: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryHelper.java (from rev 3025, trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java) =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryHelper.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryHelper.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -0,0 +1,129 @@ +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.chorem.pollen.entity.PollAccount; +import org.chorem.pollen.entity.Vote; +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 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class PollenQueryHelper { + + public static final String ALIAS_POLL = "P"; + + public static final String ALIAS_POLL_PARTICIPANT = "A"; + + public static final String ALIAS_POLL_LIST = "PL"; + + public static final String ALIAS_FAVORITE_PARTICIPANT = "FP"; + + public static final String ALIAS_FAVORITE_LIST = "FL"; + + public static final String PROPERTY_CHOICE_VOTE = + TopiaQuery.getProperty(PollAccount.CHOICE_VOTE, Vote.CHOICE); + + private static final Log log = LogFactory.getLog(PollenQueryHelper.class); + + private static PollenContext context; + + public static void setContext(PollenContext context) { + PollenQueryHelper.context = context; + } + + public static Date getCurrentDate() { + return context.getCurrentDate(); + } + + public static TopiaQuery createQuery(Class<?> entityClass, String alias) { + return new TopiaQuery((Class<? extends TopiaEntity>)entityClass, alias); + } + + public static void prepareQuery(TopiaQuery query, + Filter filter) { + prepareQuery(query, filter, null, null); + } + + /** + * Prepare a query with filter : adding startIndex and endIndex as limit + * and orderBy if defined. Need an existing query in builder. + * + * @param filter Filter to add in the query + * @see #prepareQuery(TopiaQuery, Filter, String, String) + */ + public static void prepareQuery(TopiaQuery query, + Filter filter, + String mainAlias) { + prepareQuery(query, filter, mainAlias, null); + } + + public static void prepareQuery(TopiaQuery query, + Filter filter, + String mainAlias, + String referenceAlias) { + if (mainAlias == null) { + mainAlias = query.getMainAlias(); + } + + 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(",")) { + String property = + TopiaQuery.getProperty(mainAlias, elmt.trim()); + order.add(property); + } + query.addOrder(order.toArray(new String[order.size()])); + + // Default order by creation date + } else { + query.addOrderDesc(getPropertyCreateDate(mainAlias)); + } + + if (StringUtils.isNotEmpty(referenceId) && referenceAlias != null) { + query.addEquals(getPropertyId(referenceAlias), referenceId); + } + } + + public static String getPropertyId(String alias) { + return TopiaQuery.getProperty(alias, TopiaEntity.TOPIA_ID); + } + + public static String getPropertyCreateDate(String alias) { + return TopiaQuery.getProperty(alias, TopiaEntity.TOPIA_CREATE_DATE); + } +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -1,151 +0,0 @@ -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 - * - * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ - */ -public class PollenUtils { - - private static final Log log = LogFactory.getLog(PollenUtils.class); - - private static PollenContext context; - - public static void setContext(PollenContext context) { - PollenUtils.context = context; - } - - 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, String, 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, null, collection); - } - - return query; - } - - public static void prepareQuery(TopiaQuery query, Filter filter) { - prepareQuery(query, filter, null, null); - } - - /** - * Prepare a query with filter : adding startIndex and endIndex as limit - * and orderBy if defined. Need an existing query in builder. - * - * @param filter Filter to add in the query - * @see #prepareQuery(TopiaQuery, Filter, String, EntityQueryProperty) - */ - public static void prepareQuery(TopiaQuery query, Filter filter, String mainAlias) { - prepareQuery(query, filter, mainAlias, 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, - String mainAlias, - EntityQueryProperty reference) { - - Integer startIndex = filter.getStartIndex(); - Integer endIndex = filter.getEndIndex(); - String orderBy = filter.getOrderBy(); - String referenceId = filter.getReferenceId(); - - if (mainAlias == null) { - mainAlias = query.getMainAlias(); - } - EntityQueryProperty mainProperty = - getEntityQueryProperty(mainAlias); - - 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.addEquals(reference.namePropertyId(), referenceId); - } - } -} Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantDAOImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -1,16 +1,15 @@ package org.chorem.pollen.entity; -import org.chorem.pollen.EntityQueryProperty; -import org.chorem.pollen.PollenUtils; +import org.chorem.pollen.PollenQueryHelper; import org.chorem.pollen.bean.Filter; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; /** * Created: 26 mai 2010 * * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ + * @version $Id: FavoriteParticipantDAOImpl.java 3014 2010-05-26 09:17:43Z + * fdesbois $ */ public class FavoriteParticipantDAOImpl<E extends FavoriteParticipant> extends FavoriteParticipantDAOAbstract<E> { @@ -18,17 +17,17 @@ @Override public TopiaQuery createQueryFindAllByFavoriteList(Filter filter) { - EntityQueryProperty participantProperty = - PollenUtils.getEntityQueryProperty(FavoriteParticipant.class, "P"); + String participantAlias = PollenQueryHelper.ALIAS_POLL_PARTICIPANT; + String listAlias = PollenQueryHelper.ALIAS_POLL_LIST; + String listParticipantProperty = + TopiaQuery.getProperty(listAlias, FavoriteList.FAVORITE_PARTICIPANT); - EntityQueryProperty listProperty = - PollenUtils.getEntityQueryProperty(FavoriteList.class, "L"); + TopiaQuery query = new TopiaQuery(FavoriteList.class, listAlias). + setSelect(participantAlias). + addJoin(listParticipantProperty, participantAlias, false); - listProperty.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT); + PollenQueryHelper.prepareQuery(query, filter, listAlias, participantAlias); - TopiaQuery query = PollenUtils.createQueryFindElementsByCollection( - participantProperty, listProperty, filter); - return query; } } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountDAOImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -1,9 +1,7 @@ package org.chorem.pollen.entity; -import org.chorem.pollen.EntityQueryProperty; -import org.chorem.pollen.PollenUtils; +import org.chorem.pollen.PollenQueryHelper; import org.chorem.pollen.bean.Filter; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; /** @@ -17,11 +15,11 @@ @Override public TopiaQuery createQueryFindAllByPoll(Filter filter) { - String pollAlias = "P"; + String pollAlias = PollenQueryHelper.ALIAS_POLL; String pollAccountProperty = TopiaQuery.getProperty(pollAlias, Poll.POLL_ACCOUNT); - String participantAlias = "A"; + String participantAlias = PollenQueryHelper.ALIAS_POLL_PARTICIPANT; String participantVoteDateProperty = TopiaQuery.getProperty(participantAlias, PollAccount.VOTE_DATE); @@ -31,8 +29,36 @@ addJoin(pollAccountProperty, participantAlias, false). addNotNull(participantVoteDateProperty); - PollenUtils.prepareQuery(query, filter, participantAlias); + PollenQueryHelper.prepareQuery(query, filter, participantAlias); return query; } + + @Override + public TopiaQuery createQueryFindAllParticipantsByPoll(Poll poll) { + + String pollAlias = PollenQueryHelper.ALIAS_POLL; + String pollAccountProperty = + TopiaQuery.getProperty(pollAlias, Poll.POLL_ACCOUNT); + + String listAlias = PollenQueryHelper.ALIAS_POLL_LIST; + String listChildProperty = + TopiaQuery.getProperty(listAlias, PollAccount.CHILD); + + String participantAlias = PollenQueryHelper.ALIAS_POLL_PARTICIPANT; + + TopiaQuery query = new TopiaQuery(Poll.class, pollAlias). + setSelect(participantAlias). + addEquals(pollAlias, poll); + + // Manage join depends on pollType + if (poll.getPollType().isGroup()) { + query.addJoin(pollAccountProperty, listAlias, false). + addJoin(listChildProperty, participantAlias, false); + } else { + query.addJoin(pollAccountProperty, participantAlias, false); + } + + return query; + } } 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-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -1,7 +1,7 @@ package org.chorem.pollen.entity; -import org.chorem.pollen.PollenUtils; +import org.chorem.pollen.PollenQueryHelper; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; @@ -67,13 +67,13 @@ @Override public boolean isStarted() { - Date now = PollenUtils.getCurrentDate(); + Date now = PollenQueryHelper.getCurrentDate(); return getBeginDate() == null || getBeginDate().before(now); } @Override public boolean isFinished() { - Date now = PollenUtils.getCurrentDate(); + Date now = PollenQueryHelper.getCurrentDate(); return getEndDate() != null && getEndDate().before(now); } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -3,13 +3,11 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.EntityQueryProperty; import org.chorem.pollen.PollenBinderHelper; import org.chorem.pollen.PollenBusinessException; import org.chorem.pollen.PollenContext; import org.chorem.pollen.PollenDAOHelper; import org.chorem.pollen.PollenException; -import org.chorem.pollen.PollenUtils; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; @@ -32,8 +30,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -295,7 +291,7 @@ @Override protected Map<PollAccount, Poll> executeGetPollsByUser(TopiaContext transaction, - UserAccount user) + UserAccount user) throws TopiaException { PollDAO dao = PollenDAOHelper.getPollDAO(transaction); @@ -346,7 +342,7 @@ // // preparePollResults(transaction, queryGroups, polls); - // ALGO 2 with one query and ordered + // ALGO 2 with one query and ordered TopiaQuery query = dao.createQuery(pollAlias). addDistinct(). addSelect(participantAlias). @@ -357,13 +353,13 @@ StringBuilder orBuilder = new StringBuilder(participantAlias). // IN poll.pollAccount (NORMAL) - append(" IN (").append(listAlias).append(')'). + append(" IN (").append(listAlias).append(')'). append(" OR ").append(participantAlias). // IN poll.pollAccount.child (GROUP) - append(" IN elements(").append(listChildProperty).append(')'). + append(" IN elements(").append(listChildProperty).append(')'). append(" OR ").append(participantAlias). // = poll.creator (CREATOR) - append(" = ").append(pollCreatorProperty); + append(" = ").append(pollCreatorProperty); query.addWhere(orBuilder.toString()); @@ -381,8 +377,8 @@ List<Object[]> queryResults = transaction.findByQuery(query); for (Object[] row : queryResults) { - Poll poll = (Poll)row[0]; - PollAccount account = (PollAccount)row[1]; + Poll poll = (Poll) row[0]; + PollAccount account = (PollAccount) row[1]; log.debug("account : " + account.getUid() + " : " + account.getName() + " list(" + account.isList() + ")" + @@ -422,7 +418,7 @@ PollDAO dao = PollenDAOHelper.getPollDAO(transaction); // No need alias managment so, no need of queryBuilder -// PollenQueryBuilder builder = context.newQueryBuilder(dao); +// Prop builder = context.newQueryBuilder(dao); // // EntityQueryProperty creatorProperty = // builder.getPollCreatorProperty(Poll.CREATOR); @@ -433,19 +429,18 @@ // executeCount(); String creatorUidProperty = - TopiaQuery.getProperty(Poll.CREATOR, PollAccount.UID); + TopiaQuery.getProperty(Poll.CREATOR, PollAccount.UID); - TopiaQuery query = dao.createQuery(). - addEquals(Poll.UID, pollUid). - addEquals(creatorUidProperty, accountUid); + 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 result; } @@ -461,7 +456,7 @@ // addEquals(Poll.UID, pollUid); TopiaQuery query = dao.createQuery(). - addFetch(properties); + addFetch(properties); String pollUidProperty = TopiaQuery.getProperty(query.getMainAlias(), Poll.UID); 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-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -12,24 +12,16 @@ import org.chorem.pollen.PollenContext; import org.chorem.pollen.PollenDAOHelper; import org.chorem.pollen.PollenException; -import org.chorem.pollen.PollenUtils; +import org.chorem.pollen.PollenQueryHelper; import org.chorem.pollen.bean.Filter; -import org.chorem.pollen.entity.FavoriteList; -import org.chorem.pollen.entity.FavoriteListDAO; -import org.chorem.pollen.entity.FavoriteListImpl; -import org.chorem.pollen.entity.FavoriteParticipant; -import org.chorem.pollen.entity.FavoriteParticipantDAO; -import org.chorem.pollen.entity.FavoriteParticipantImpl; import org.chorem.pollen.entity.UserAccount; import org.chorem.pollen.entity.UserAccountDAO; import org.chorem.pollen.entity.UserAccountImpl; -import org.nuiton.i18n.I18n; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.Binder; /** * ServiceUserImpl @@ -268,7 +260,7 @@ UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(transaction); TopiaQuery query = dao.createQuery(); - PollenUtils.prepareQuery(query, filter); + PollenQueryHelper.prepareQuery(query, filter); Map<String, UserAccount> results = dao.findAllMappedByQuery( query, UserAccount.LOGIN, String.class); @@ -282,7 +274,7 @@ UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(transaction); TopiaQuery query = dao.createQuery(); - PollenUtils.prepareQuery(query, filter); + PollenQueryHelper.prepareQuery(query, filter); int result = dao.countByQuery(query); 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-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -3,13 +3,12 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.EntityQueryProperty; import org.chorem.pollen.PollenBinderHelper; import org.chorem.pollen.PollenBusinessException; import org.chorem.pollen.PollenContext; import org.chorem.pollen.PollenDAOHelper; import org.chorem.pollen.PollenException; -import org.chorem.pollen.PollenUtils; +import org.chorem.pollen.PollenQueryHelper; import org.chorem.pollen.bean.Filter; import org.chorem.pollen.entity.Choice; import org.chorem.pollen.entity.Poll; @@ -71,7 +70,7 @@ */ protected void copyPollAccount(PollAccount source, PollAccount destination) { // Uid is the naturalId, don't copy it - String[] excludes = new String[] {PollAccount.UID}; + String[] excludes = new String[]{PollAccount.UID}; // Exclude properties for anonymous account if (source.isAnonymous()) { @@ -120,22 +119,16 @@ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); - EntityQueryProperty participantProperty = - PollenUtils.getEntityQueryProperty(PollAccount.class, "A"); - EntityQueryProperty pollProperty = - PollenUtils.getEntityQueryProperty(Poll.class, "P"); - EntityQueryProperty groupProperty = - PollenUtils.getEntityQueryProperty(PollAccount.class, "G"); + TopiaQuery query = dao.createQueryFindAllParticipantsByPoll(poll); - TopiaQuery query = createQueryFindParticipantByPoll( - participantProperty, groupProperty, pollProperty, poll); + String participantAlias = PollenQueryHelper.ALIAS_POLL_PARTICIPANT; - query.addEquals(participantProperty.name(), participant). - addWhere(pollProperty.nameProperty(Poll.CREATOR), - TopiaQuery.Op.NEQ, - participant - ); + String pollCreatorProperty = + TopiaQuery.getProperty(PollenQueryHelper.ALIAS_POLL, Poll.CREATOR); + query.addEquals(participantAlias, participant). + addWhere(pollCreatorProperty, TopiaQuery.Op.NEQ, participant); + if (log.isDebugEnabled()) { log.debug("Query : " + query); } @@ -145,39 +138,6 @@ return result; } - protected TopiaQuery createQueryFindParticipantByPoll(EntityQueryProperty participantProperty, - EntityQueryProperty groupProperty, - EntityQueryProperty pollProperty, - Poll poll) { - TopiaQuery query = participantProperty.newQuery(). - addFrom(Poll.class, pollProperty.name()). - addEquals(pollProperty.name(), poll); - - // By default the parentCollection is pollAccount in poll - String parentCollectionProperty = - pollProperty.nameProperty(Poll.POLL_ACCOUNT); - - if (poll.getPollType().isGroup()) { - // Add the group into the query - query.addFrom(PollAccount.class, groupProperty.name()). - // It's not really necessary, but better to be sure - addEquals(groupProperty.nameProperty(PollAccount.LIST), - Boolean.TRUE). - // Add link between the group and the poll - addInElements(groupProperty.name(), parentCollectionProperty); - - // In case of group, the parentCollection is the child - // pollAccount from the group - parentCollectionProperty = - groupProperty.nameProperty(PollAccount.CHILD); - } - - // Add link between the participant to find and his parent - query.addInElements(participantProperty.name(), parentCollectionProperty); - - return query; - } - @Override protected PollAccount executeGetNewPollAccount(UserAccount user) { PollAccount account = new PollAccountImpl(); @@ -208,9 +168,14 @@ PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); TopiaQuery query = dao.createQueryFindAllByPoll(filter); - - //query.addLoad(PollAccount.CHOICE_VOTE); + String participantChoiceProperty = + TopiaQuery.getProperty(PollenQueryHelper.ALIAS_POLL_PARTICIPANT, + PollAccount.CHOICE_VOTE, + Vote.CHOICE); + + query.addDistinct().addFetch(participantChoiceProperty); + List<PollAccount> results = dao.findAllByQuery(query); if (log.isDebugEnabled()) { @@ -288,7 +253,7 @@ } @Override - protected String executeSaveVote(TopiaContext transaction, Poll poll, + protected PollAccount executeSaveVote(TopiaContext transaction, Poll poll, PollAccount participant) throws TopiaException, PollenBusinessException { @@ -305,7 +270,7 @@ // set some votes for poll choices // saveVote - String result = null; + PollAccount result = null; if (executeCanVote(transaction, poll, participant)) { PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); @@ -340,7 +305,7 @@ dao.update(participantToSave); - result = participantToSave.getUid(); + result = participantToSave; // TODO-fdesbois-2010-05-27 : execute vote counting if poll.isContinuousResults() @@ -359,23 +324,17 @@ PollAccount participant) throws PollenBusinessException, TopiaException { - EntityQueryProperty participantProperty = - PollenUtils.getEntityQueryProperty(PollAccount.class, "A"); - EntityQueryProperty pollProperty = - PollenUtils.getEntityQueryProperty(Poll.class, "P"); - EntityQueryProperty groupProperty = - PollenUtils.getEntityQueryProperty(PollAccount.class, "G"); + TopiaQuery query = dao.createQueryFindAllParticipantsByPoll(poll); - TopiaQuery query = createQueryFindParticipantByPoll( - participantProperty, groupProperty, pollProperty, poll); + String participantAlias = PollenQueryHelper.ALIAS_POLL_PARTICIPANT; - query.addEquals(participantProperty.nameProperty(PollAccount.NAME), - participant.getName()); + String participantNameProperty = + TopiaQuery.getProperty(participantAlias, PollAccount.NAME); + query.addEquals(participantNameProperty, participant.getName()); + if (StringUtils.isNotEmpty(participant.getTopiaId())) { - query.addWhere(participantProperty.namePropertyId(), - TopiaQuery.Op.NEQ, - participant.getTopiaId()); + query.addWhere(participantAlias, TopiaQuery.Op.NEQ, participant); } if (dao.existByQuery(query)) { Modified: trunk/pollen-business/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/PollenUtilsTest.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -37,7 +37,7 @@ // TopiaQueryBuilder builder = new TopiaQueryBuilder(); // builder.setQuery(new TopiaQuery(UserAccount.class)); TopiaQuery query = new TopiaQuery(UserAccount.class); - PollenUtils.prepareQuery(query, filter); + PollenQueryHelper.prepareQuery(query, filter); log.debug("Query : " + query); @@ -48,7 +48,7 @@ filter.setOrderBy(null); query = new TopiaQuery(UserAccount.class); - PollenUtils.prepareQuery(query, filter); + PollenQueryHelper.prepareQuery(query, filter); log.debug("Query : " + query); @@ -58,65 +58,65 @@ } - @Test - public void testCreateQueryFindElementsByCollection() throws IOException { +// @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 = +// PollenQueryHelper.getEntityQueryProperty(FavoriteParticipant.class, "P"); +// +// EntityQueryProperty listPropertyProvider = +// PollenQueryHelper.getEntityQueryProperty(FavoriteList.class, "L"); +// listPropertyProvider.setPropertyJoin(FavoriteList.FAVORITE_PARTICIPANT); +// +// log.info("test1 : orderBy FavoriteParticipant name"); +// TopiaQuery result = PollenQueryHelper.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 = PollenQueryHelper.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 = PollenQueryHelper.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"); +// +// } - //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/ServicePollImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -357,7 +357,7 @@ } @Test - public void testFetchOnGetter() throws TopiaException, PollenBusinessException { + public void testFetchOnGetter() throws Exception, PollenBusinessException { poll = createFreePoll("POLL2", user, VoteCountingType.NORMAL); List<Choice> choices = 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-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServiceVoteImplTest.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -4,6 +4,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.pollen.PollenBusinessException; import org.chorem.pollen.PollenDAOHelper; +import org.chorem.pollen.PollenQueryHelper; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.entity.Choice; @@ -21,6 +22,7 @@ import org.junit.Test; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; import java.util.ArrayList; import java.util.Collection; @@ -38,6 +40,7 @@ private static final Log log = LogFactory.getLog(ServiceVoteImplTest.class); + protected UserAccount user; @Override @@ -49,7 +52,7 @@ @Test public void testCanVoteForGroupPoll() - throws PollenBusinessException, TopiaException { + throws Exception, TopiaException { /** PREPARE DATA **/ @@ -86,7 +89,7 @@ } @Test - public void testSaveVoteForFreePoll() throws PollenBusinessException, TopiaException { + public void testSaveVoteForFreePoll() throws Exception, TopiaException { /** PREPARE DATA **/ Poll pollCreated = createFreePoll("Poll", user, VoteCountingType.NORMAL); List<Choice> choices = @@ -120,58 +123,67 @@ log.info("test 1 : new participant with 2 votes with value to 1"); - String uid = serviceVote.saveVote(poll, participant); + PollAccount accountSaved = serviceVote.saveVote(poll, participant); - TopiaContext transaction = beginTransaction(); - try { +// TopiaContext transaction = beginTransaction(); +// try { +// +// PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); +// +// PollAccount accountFound = dao.findByNaturalId(accountSaved.getUid()); +// +// 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(); +// } - PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); + PollAccount accountFound = loadEntity(accountSaved, + PollenQueryHelper.PROPERTY_CHOICE_VOTE); - 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(); + 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")); + log.info("test 2 : anonymous participant"); participant.setAnonymous(true); participant.setName("participant2"); - uid = serviceVote.saveVote(poll, participant); - transaction = beginTransaction(); - try { + accountSaved = serviceVote.saveVote(poll, participant); - PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); + // Check + accountFound = loadEntity(accountSaved); // Need USER_ACCOUNT ? - PollAccount accountFound = dao.findByNaturalId(uid); - Assert.assertTrue(accountFound.isAnonymous()); - Assert.assertNull(accountFound.getName()); - Assert.assertNull(accountFound.getUserAccount()); - Assert.assertNull(accountFound.getEmail()); + 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()); + // 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); + loadEntity(participant, PollenQueryHelper.PROPERTY_CHOICE_VOTE); for (Vote vote : participantExist.getChoiceVote()) { // Update choice 1 with value 0 -> will be deleted @@ -185,33 +197,26 @@ vote2.setVoteValue(1); // TRUE participantExist.addChoiceVote(vote2); - uid = serviceVote.saveVote(poll, participantExist); + accountSaved = serviceVote.saveVote(poll, participantExist); - transaction = beginTransaction(); - try { + // Check + accountFound = loadEntity(accountSaved, + PollenQueryHelper.PROPERTY_CHOICE_VOTE); - 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(); + Assert.assertEquals(context.getCurrentDate(), accountFound.getVoteDate()); + Assert.assertEquals(2, accountFound.getChoiceVote().size()); + choicesExist.clear(); + for (Vote curr : accountFound.getChoiceVote()) { + choicesExist.add(curr.getChoice().getName()); } + + Assert.assertTrue(choicesExist.contains("choice2")); + Assert.assertTrue(choicesExist.contains("choice3")); } @Test public void testDeleteVoteForFreePoll() - throws TopiaException, PollenBusinessException { + throws Exception, PollenBusinessException { /** PREPARE DATA */ Poll pollCreated = createFreePoll("Poll", user, VoteCountingType.NORMAL); @@ -232,37 +237,27 @@ 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); + PollAccount account = serviceVote.saveVote(pollCreated, participant); - account = dao.findByNaturalId(uid); - votes = account.getChoiceVote(); + account = loadEntity(account, PollenQueryHelper.PROPERTY_CHOICE_VOTE); - } finally { - transaction.closeContext(); - } - Poll poll = loadEntity(pollCreated); /** EXEC METHOD */ serviceVote.deleteVote(poll, account); - transaction = beginTransaction(); + TopiaContext transaction = beginTransaction(); try { PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); // Check account are correctly deleted - account = dao.findByNaturalId(uid); - Assert.assertNull(account); + PollAccount accountFound = dao.findByNaturalId(account.getUid()); + Assert.assertNull(accountFound); VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction); // Check all votes are not in database anymore - for (Vote vote : votes) { + for (Vote vote : account.getChoiceVote()) { Vote voteFound = voteDAO.findByTopiaId(vote.getTopiaId()); Assert.assertNull(voteFound); } @@ -280,7 +275,7 @@ @Test public void testDeleteVoteForGroupPoll() - throws TopiaException, PollenBusinessException { + throws Exception, PollenBusinessException { /** PREPARE DATA */ Poll pollCreated = createGroupPoll("Poll", user, @@ -300,39 +295,30 @@ 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); + PollAccount account = + serviceVote.saveVote(pollCreated, existingParticipant); - account = dao.findByNaturalId(uid); - votes = account.getChoiceVote(); + account = loadEntity(account, PollenQueryHelper.PROPERTY_CHOICE_VOTE); - } finally { - transaction.closeContext(); - } - Poll poll = loadEntity(pollCreated); /** EXEC METHOD */ serviceVote.deleteVote(poll, account); - transaction = beginTransaction(); + TopiaContext transaction = beginTransaction(); try { PollAccountDAO dao = PollenDAOHelper.getPollAccountDAO(transaction); // Check account are correctly deleted - account = dao.findByNaturalId(uid); + account = dao.findByNaturalId(account.getUid()); 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) { + for (Vote vote : account.getChoiceVote()) { Vote voteFound = voteDAO.findByTopiaId(vote.getTopiaId()); Assert.assertNull(voteFound); } @@ -343,4 +329,6 @@ } + + } Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -1,5 +1,6 @@ package org.chorem.pollen.test; +import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.PollenBusinessException; @@ -40,6 +41,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.util.Calendar; import java.util.Collection; import java.util.Date; @@ -372,14 +374,20 @@ } } - public <E extends TopiaEntity> E loadEntity(E source, String... properties) - throws TopiaException { - + public <E extends TopiaEntity> E loadEntity(E source, + String... propertiesToLoad) + throws Exception { + TopiaContext transaction = beginTransaction(); try { TopiaQuery query = new TopiaQuery(source.getClass()); - query.addLoad(properties). - addEquals(TopiaEntity.TOPIA_ID, source.getTopiaId()). + + query.addFetch(propertiesToLoad); + + String mainIdProperty = + TopiaQuery.getProperty(query.getMainAlias(), TopiaEntity.TOPIA_ID); + + query.addEquals(mainIdProperty, source.getTopiaId()). setMaxResults(1); E result = (E)query.executeToEntity(transaction, source.getClass()); @@ -388,7 +396,7 @@ return result; } - throw new NullPointerException("nothing to find... from " + + throw new NullPointerException("nothing to find... from id = " + source.getTopiaId()); } finally { transaction.closeContext(); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-06-02 20:21:08 UTC (rev 3026) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-06-02 21:38:06 UTC (rev 3027) @@ -659,8 +659,8 @@ boolean linkWithUser = linkUserConnected(); // Execute the save - String uid = serviceVote.saveVote(getPoll(), getPollAccount()); - getPollAccount().setUid(uid); + pollAccount = serviceVote.saveVote(getPoll(), getPollAccount()); + //getPollAccount().setUid(uid); if (linkWithUser) { voteFeedback.addInfo("Votre vote a été lié à votre compte utilisateur.");