Author: fdesbois Date: 2010-06-03 19:28:59 +0200 (Thu, 03 Jun 2010) New Revision: 3029 Url: http://chorem.org/repositories/revision/pollen/3029 Log: Missing new classes from previous commit Added: trunk/pollen-business/src/main/java/org/chorem/pollen/bean/EntityFilter.java trunk/pollen-business/src/main/java/org/chorem/pollen/bean/UserPollImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollDAOImpl.java Added: trunk/pollen-business/src/main/java/org/chorem/pollen/bean/EntityFilter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/bean/EntityFilter.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/bean/EntityFilter.java 2010-06-03 17:28:59 UTC (rev 3029) @@ -0,0 +1,126 @@ +package org.chorem.pollen.bean; + +import org.apache.commons.lang.StringUtils; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaId; + +import java.beans.PropertyChangeListener; + +/** + * Created: 3 juin 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public interface EntityFilter { + + public static final String PROPERTY_START_INDEX = "startIndex"; + + public static final String PROPERTY_END_INDEX = "endIndex"; + + public static final String PROPERTY_ORDER_BY = "orderBy"; + + public static final String PROPERTY_REFERENCE_ID = "referenceId"; + + public static final String PROPERTY_REFERENCE_PROPERTY = "referenceProperty"; + + /** + * Get the value of startIndex + * + * @return the value of startIndex + */ + public Integer getStartIndex(); + + /** + * Set the value of startIndex + * + * @param startIndex new value of startIndex + */ + public void setStartIndex(Integer startIndex); + + /** + * Get the value of orderBy + * + * @return the value of orderBy + */ + public String getOrderBy(); + + /** + * Set the value of orderBy + * + * @param orderBy new value of orderBy + */ + public void setOrderBy(String orderBy); + + /** + * Get the value of endIndex + * + * @return the value of endIndex + */ + public Integer getEndIndex(); + + /** + * Set the value of endIndex + * + * @param endIndex new value of endIndex + */ + public void setEndIndex(Integer endIndex); + + /** + * Get the value of referenceId + * + * @return the value of referenceId + */ + public String getReferenceId(); + + /** + * Set the value of referenceId + * + * @param referenceId + */ + public void setReferenceId(String referenceId); + + /** + * Set the value of referenceId from {@code entity} + * + * @param entity + */ + public void setReference(Object entity) throws IllegalArgumentException; + + /** + * Used to check if the filter contains a reference. + * + * @return true if the filter contains a reference + */ + public boolean hasReference(); + + /** + * Get the value of referenceProperty + * + * @return the value of referenceProperty + */ + public String getReferenceProperty(); + + /** + * Set the value of referenceProperty + * + * @param referenceProperty + */ + public void setReferenceProperty(String referenceProperty); + + /** + * Add PropertyChangeListener. + * + * @param listener + */ + public void addPropertyChangeListener(PropertyChangeListener listener); + + /** + * Remove PropertyChangeListener. + * + * @param listener + */ + public void removePropertyChangeListener(PropertyChangeListener listener); + +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/bean/EntityFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-business/src/main/java/org/chorem/pollen/bean/UserPollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/bean/UserPollImpl.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/bean/UserPollImpl.java 2010-06-03 17:28:59 UTC (rev 3029) @@ -0,0 +1,51 @@ +package org.chorem.pollen.bean; + +import org.chorem.pollen.entity.PollAccount; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created: 3 juin 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class UserPollImpl extends UserPoll { + + protected Boolean creator; + + @Override + public boolean isCreator() { + // Lazy initialization of creator boolean + if (creator == null) { + for (PollAccount account : accounts) { + if (account.equals(poll.getCreator())) { + creator = true; + break; + } + } + } + return creator; + } + + @Override + public String getPollUid() { + return poll.getUid(); + } + + @Override + public List<PollAccount> getAccounts() { + if (accounts == null) { + accounts = new ArrayList<PollAccount>(); + } + return accounts; + } + + @Override + public boolean addAccount(PollAccount account) { + boolean result = getAccounts().add(account); + return result; + } + +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/bean/UserPollImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollDAOImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollDAOImpl.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollDAOImpl.java 2010-06-03 17:28:59 UTC (rev 3029) @@ -0,0 +1,65 @@ +package org.chorem.pollen.entity; + +import org.chorem.pollen.PollenQueryHelper; +import org.chorem.pollen.bean.EntityFilter; +import org.chorem.pollen.bean.TopiaFilter; +import org.nuiton.topia.framework.TopiaQuery; + +/** + * Created: 3 juin 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class PollDAOImpl<E extends Poll> extends PollDAOAbstract<E> { + + @Override + public TopiaQuery createQueryFindAllByUser(EntityFilter input) + throws IllegalArgumentException { + + TopiaFilter filter = (TopiaFilter)input; + + // Filter reference is not always necessary but only used on UserAccount + filter.checkReference(UserAccount.class, false); + + String pollAlias = PollenQueryHelper.ALIAS_POLL; + String pollCreatorProperty = + TopiaQuery.getProperty(pollAlias, Poll.PROPERTY_CREATOR); + String pollAccountProperty = + TopiaQuery.getProperty(pollAlias, Poll.PROPERTY_POLL_ACCOUNT); + + // Property names for participant + String participantAlias = PollenQueryHelper.ALIAS_POLL_PARTICIPANT; + String participantUserProperty = + TopiaQuery.getProperty(participantAlias, + PollAccount.PROPERTY_USER_ACCOUNT); + + // Property names for participant list + String listAlias = PollenQueryHelper.ALIAS_POLL_LIST; + String listChildProperty = + TopiaQuery.getProperty(listAlias, PollAccount.PROPERTY_CHILD); + + TopiaQuery query = createQuery(pollAlias). + addDistinct(). + addLeftJoin(pollAccountProperty, listAlias, false). + addFrom(PollAccount.class, participantAlias); + + StringBuilder orBuilder = new StringBuilder(participantAlias). + // IN poll.pollAccount (NORMAL) + append(" IN (").append(listAlias).append(')'). + append(" OR ").append(participantAlias). + // IN poll.pollAccount.child (GROUP) + append(" IN elements(").append(listChildProperty).append(')'). + append(" OR ").append(participantAlias). + // = poll.creator (CREATOR) + append(" = ").append(pollCreatorProperty); + + query.addWhere(orBuilder.toString()); + + // participantUser is the reference to filter on if necessary + filter.setReferenceProperty(participantUserProperty); + filter.applyOnQuery(query); + + return query; + } +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollDAOImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL