Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 3196 discussions
r3606 - trunk/pollen-services/src/main/java/org/chorem/pollen/services
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 16:04:23 +0200 (Mon, 13 Aug 2012)
New Revision: 3606
Url: http://chorem.org/repositories/revision/pollen/3606
Log:
can create service from other services
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-08-13 14:03:06 UTC (rev 3605)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-08-13 14:04:23 UTC (rev 3606)
@@ -124,6 +124,11 @@
return result;
}
+ public <E extends PollenService> E newService(Class<E> serviceClass) {
+ E service = serviceContext.newService(serviceClass);
+ return service;
+ }
+
protected <T extends TopiaEntity, D extends TopiaDAO<? super T>> T newInstance(D dao) {
try {
return (T) dao.newInstance();
@@ -149,7 +154,6 @@
throw new PollenTechnicalException("Could not create entity ", e);
}
}
-
protected <T extends TopiaEntity, D extends TopiaDAO<? super T>> T createWithProperties(D dao, Object... properties) {
try {
return (T) dao.create(properties);
@@ -157,6 +161,7 @@
throw new PollenTechnicalException("Could not create entity ", e);
}
}
+
protected <T extends TopiaEntity, D extends TopiaDAO<? super T>> T update(D dao, T entity) {
try {
return (T) dao.update(entity);
@@ -177,11 +182,6 @@
return serviceContext.getConfiguration();
}
- protected <E extends PollenService> E newService(Class<E> serviceClass) {
- E service = serviceContext.newService(serviceClass);
- return service;
- }
-
protected void commitTransaction(String errorMessage) {
try {
getTransaction().commitTransaction();
1
0
r3605 - trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 16:03:06 +0200 (Mon, 13 Aug 2012)
New Revision: 3605
Url: http://chorem.org/repositories/revision/pollen/3605
Log:
make PollenSession Serializable
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-08-13 14:02:08 UTC (rev 3604)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-08-13 14:03:06 UTC (rev 3605)
@@ -32,6 +32,7 @@
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -42,7 +43,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.3
*/
-public class PollenSession {
+public class PollenSession implements Serializable {
/** Logger. */
private static final Log log = LogFactory.getLog(PollenSession.class);
@@ -56,6 +57,8 @@
public static final String SESSION_TOKEN_WARNINGS = "warnings";
+ private static final long serialVersionUID = -1L;
+
public static PollenSession get(ServletRequest servletRequest) {
HttpSession httpSession = ((HttpServletRequest) servletRequest).getSession(true);
PollenSession pollenSession = (PollenSession) httpSession.getAttribute(SESSION_PARAMETER);
@@ -90,7 +93,7 @@
private UserAccount userAccount;
/** To push dynamic data which should be consumed in a page scope. */
- private Map<String, Object> dynamicData;
+ private Map<String, Serializable> dynamicData;
public UserAccount getUserAccount() {
return userAccount;
@@ -100,20 +103,40 @@
this.userAccount = userAccount;
}
- public <T> T getDynamicData(String token) {
- Object result = getDynamicData().get(token);
+ public <T extends Serializable> T getDynamicData(String token) {
+ Serializable result = getDynamicData().get(token);
return (T) result;
}
- public <T> T consumeDynamicData(String token) {
- Object result = getDynamicData().get(token);
+ public <T extends Serializable> List<T> getDynamicListData(String token) {
+ Serializable result = getDynamicData().get(token);
+ return (List<T>) result;
+ }
+
+ public <T extends Serializable> T consumeDynamicData(String token) {
+ T result = getDynamicData(token);
if (result != null) {
removeDynamicData(token);
}
- return (T) result;
+ return result;
}
- public void putDynamicData(String token, Object data) {
+ public <T extends Serializable> List<T> consumeDynamicListData(String token) {
+ List<T> result = getDynamicListData(token);
+ if (result != null) {
+ removeDynamicData(token);
+ }
+ return result;
+ }
+
+ public <T extends Serializable> void putDynamicListData(String token, List<T> data) {
+ getDynamicData().put(token, (Serializable) data);
+ if (log.isDebugEnabled()) {
+ log.debug("Dynamic attributes size : " + getDynamicData().size());
+ }
+ }
+
+ public void putDynamicData(String token, Serializable data) {
getDynamicData().put(token, data);
if (log.isDebugEnabled()) {
log.debug("Dynamic attributes size : " + getDynamicData().size());
@@ -136,7 +159,7 @@
}
}
- protected Map<String, Object> getDynamicData() {
+ protected Map<String, Serializable> getDynamicData() {
if (dynamicData == null) {
dynamicData = Maps.newHashMap();
}
@@ -144,20 +167,20 @@
}
public void addMessage(String messageScope, String message) {
- List<String> messages = getDynamicData(messageScope);
+ List<String> messages = getDynamicListData(messageScope);
if (messages == null) {
messages = Lists.newArrayList(message);
- putDynamicData(messageScope, messages);
+ putDynamicListData(messageScope, messages);
} else {
messages.add(message);
}
}
public void removeDynamicDataWithPrefix(String prefix) {
- Iterator<Map.Entry<String, Object>> itr =
+ Iterator<Map.Entry<String, Serializable>> itr =
getDynamicData().entrySet().iterator();
while (itr.hasNext()) {
- Map.Entry<String, Object> entry = itr.next();
+ Map.Entry<String, Serializable> entry = itr.next();
if (entry.getKey().startsWith(prefix)) {
itr.remove();
}
1
0
r3604 - in trunk/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll java/org/chorem/pollen/ui/actions/user webapp/WEB-INF/jsp/user
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 16:02:08 +0200 (Mon, 13 Aug 2012)
New Revision: 3604
Url: http://chorem.org/repositories/revision/pollen/3604
Log:
fixes #767: Can not attach poll when pollId contains have some trim spaces (+ move this action to user package + stop using inheritance for nothing :()
Added:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java
Removed:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java
Modified:
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp
Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java 2012-08-13 13:08:27 UTC (rev 3603)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java 2012-08-13 14:02:08 UTC (rev 3604)
@@ -1,93 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (struts2)
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.UserAccount;
-import org.chorem.pollen.services.exceptions.PollNotFoundException;
-import org.chorem.pollen.ui.actions.PageSkin;
-
-/**
- * To attach a anonymous poll to a connected user account.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4
- */
-public class AttachPoll extends AbstractPollUriIdAction {
-
- private static final long serialVersionUID = 1L;
-
- public AttachPoll() {
- super(PageSkin.EDITION);
- }
-
- @Override
- public String execute() throws Exception {
-
- String pollId = getPollId();
-
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPollService().getExistingPollByPollId(pollId);
-
- UserAccount userAccount = getPollenSession().getUserAccount();
-
- getPollService().attachPoll(poll, userAccount);
-
- addFlashMessage(_("pollen.information.poll.attached", poll.getTitle()));
-
- return SUCCESS;
- }
-
- @Override
- public void validate() {
-
- if (StringUtils.isEmpty(getPollId())) {
- addFieldError("uriId", _("pollen.error.pollId.empty"));
- } else {
-
- String pollId = getPollId();
-
- try {
-
- // check that poll exists
- Poll poll = getPollService().getExistingPollByPollId(pollId);
-
- // check that poll is not yet attached to another user account
-
- UserAccount userAccount = poll.getCreator().getUserAccount();
- if (userAccount != null) {
-
- addFieldError("uriId",
- _("pollen.error.pollAlreadyAttached"));
- }
- } catch (PollNotFoundException e) {
-
- addFieldError("uriId", _("pollen.error.pollNotFound"));
- }
-
- }
- }
-}
Copied: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java (from rev 3589, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AttachPoll.java)
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java (rev 0)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java 2012-08-13 14:02:08 UTC (rev 3604)
@@ -0,0 +1,115 @@
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.user;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+import org.chorem.pollen.ui.actions.PageSkin;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * To attach a anonymous poll to a connected user account.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4
+ */
+public class AttachPoll extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(AttachPoll.class);
+
+ /**
+ * Id of the poll to attach to the connected user account.
+ *
+ * @since 1.4.5
+ */
+ private String pollId;
+
+ public AttachPoll() {
+ super(PageSkin.EDITION);
+ }
+
+ public String getPollId() {
+ return pollId == null ? null : pollId.trim();
+ }
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ String id = getPollId();
+
+ UserAccount userAccount = getPollenUserAccount();
+
+ Poll poll = getPollService().getExistingPollByPollId(id);
+
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Will attach poll %s to user %s",
+ id, userAccount.getEmail()));
+ }
+
+ getPollService().attachPoll(id, userAccount);
+
+ addFlashMessage(_("pollen.information.poll.attached", poll.getTitle()));
+
+ return SUCCESS;
+ }
+
+ @Override
+ public void validate() {
+
+ String id = getPollId();
+
+ if (StringUtils.isBlank(id)) {
+ addFieldError("pollId", _("pollen.error.pollId.empty"));
+ } else {
+
+ try {
+
+ // check that poll exists
+ Poll poll = getPollService().getExistingPollByPollId(id);
+
+ // check that poll is not yet attached to another user account
+
+ UserAccount userAccount = poll.getCreator().getUserAccount();
+ if (userAccount != null) {
+
+ addFieldError("pollId", _("pollen.error.pollAlreadyAttached"));
+ }
+ } catch (PollNotFoundException e) {
+
+ addFieldError("pollId", _("pollen.error.pollNotFound"));
+ }
+
+ }
+ }
+}
Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/AttachPoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp 2012-08-13 13:08:27 UTC (rev 3603)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp 2012-08-13 14:02:08 UTC (rev 3604)
@@ -73,7 +73,7 @@
title='%{getText("pollen.common.createDate")}'/>
<sjg:gridColumn name="addingChoices" sortable="false"
title='%{getText("pollen.common.addingChoices")}'/>
- <sjg:gridColumn name="beginDate" width="100"
+ <sjg:gridColumn name="beginDate" width="100"
title='%{getText("pollen.common.beginDate")}'/>
<sjg:gridColumn name="endDate" width="100"
title='%{getText("pollen.common.endDate")}'/>
@@ -91,10 +91,9 @@
<s:form namespace="/user" method="POST">
- <s:textfield key="uriId" label='%{getText("pollen.common.pollId")}'
- required="true" size="80" value='%{pollId}'
- tooltip='%{getText("poll.help.pollId")}'
- tooltipIconPath="/img/tooltip.png"/>
+ <s:textfield key="pollId" label='%{getText("pollen.common.pollId")}'
+ required="true" size="80" tooltipIconPath="/img/tooltip.png"
+ tooltip='%{getText("poll.help.pollId")}'/>
<br/>
<s:submit action="attachPoll" key="pollen.action.attachPoll"/>
1
0
r3603 - in trunk/pollen-persistence/src: main/java/org/chorem/pollen/business/persistence test/java/org/chorem/pollen/business/persistence
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 15:08:27 +0200 (Mon, 13 Aug 2012)
New Revision: 3603
Url: http://chorem.org/repositories/revision/pollen/3603
Log:
refs #746: Improve security model (let's have a unique request to find voter account, and anohter one to have a restricted voter)
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-08-13 13:07:02 UTC (rev 3602)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-08-13 13:08:27 UTC (rev 3603)
@@ -23,6 +23,8 @@
package org.chorem.pollen.business.persistence;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -32,140 +34,117 @@
public class PollAccountDAOImpl<E extends PollAccount> extends PollAccountDAOAbstract<E> {
/**
- * Get a restricted poll account for a given poll
- * ( using his {@code pollId} ) using the
- * {@link PollAccount#getAccountId()} of the pollAccount.
+ * Get a restricted poll account for a given poll (by his {@link Poll#getPollId()})
+ * using the {@link PollAccount#getAccountId()} of the pollAccount
+ * and/or the {@link PollAccount#getEmail()}.
+ * <p/>
+ * <strong>Note:</strong> {@code accountId} and {@code user} can not
+ * be null at the same time.
*
* @param pollId pollId of the poll
* @param accountId the accountId of the pollAccount to find
+ * @param user the connected user account to test
* @return the found pollAccount, or {@code null} if not foud
* @throws TopiaException if any db pb
*/
- public E findRestrictedPollAccountByAccountId(String pollId,
- String accountId) throws TopiaException {
+ public E findRestrictedPollAccount(String pollId,
+ String accountId,
+ UserAccount user) throws TopiaException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(accountId);
+ Preconditions.checkArgument(StringUtils.isNotBlank(pollId));
+ Preconditions.checkArgument(StringUtils.isNotBlank(accountId) ||
+ user != null);
-// TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
-// addFrom(Poll.class, "poll").
-// setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
-// addWhere("poll." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId).
-// addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_ACCOUNT_ID, TopiaQuery.Op.EQ, accountId).
-// addInElements("p", "poll." + Poll.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST);
-// E result = findByQuery(query);
-
String hql = "SELECT p.pollAccount FROM PersonToListImpl p, PollImpl poll WHERE " +
"poll.pollId = :pollId AND " +
- "p.pollAccount.accountId = :accountId AND " +
- "p in elements (poll.votingList.pollAccountPersonToList)";
+ "p in elements (poll.votingList.pollAccountPersonToList) AND ";
- E result = PollenPersistenceUtil.findUnique(
- this, hql, "pollId", pollId, "accountId", accountId);
- return result;
- }
- /**
- * Get a restricted poll account for a given poll
- * ( using his {@code pollId} ) using the
- * {@link PollAccount#getEmail()} of the pollAccount.
- *
- * @param pollId pollId of the poll
- * @param email the email of the pollAccount to find
- * @return the found pollAccount, or {@code null} if not found
- * @throws TopiaException if any db pb
- */
- public E findRestrictedPollAccountByEmail(String pollId,
- String email) throws TopiaException {
+ boolean withAccountId = StringUtils.isNotBlank(accountId);
+ boolean withEmail = user != null;
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(email);
+ List<String> params = Lists.newArrayList("pollId", pollId);
-// TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
-// addFrom(Poll.class, "poll").
-// setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
-// addWhere("poll." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId).
-// addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_EMAIL, TopiaQuery.Op.EQ, email).
-// addInElements("p", "poll." + Poll.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST);
-// E result = findByQuery(query);
+ if (withAccountId && withEmail) {
- String hql = "SELECT p.pollAccount FROM PersonToListImpl p, PollImpl poll WHERE " +
- "poll.pollId = :pollId AND " +
- "p.pollAccount.email = :email AND " +
- "p in elements (poll.votingList.pollAccountPersonToList)";
+ // try with both email or accountId
+ params.add("accountId");
+ params.add(accountId);
+ params.add("email");
+ params.add(user.getEmail());
+ hql += "(p.pollAccount.accountId = :accountId OR p.pollAccount.email = :email)";
+ } else if (withAccountId) {
- E result = PollenPersistenceUtil.findUnique(
- this, hql, "pollId", pollId, "email", email);
+ // try only with accountId
+ params.add("accountId");
+ params.add(accountId);
+ hql += "p.pollAccount.accountId = :accountId";
+ } else {
+
+ // try only with email
+ params.add("email");
+ params.add(user.getEmail());
+ hql += "p.pollAccount.email = :email";
+ }
+
+ E result = PollenPersistenceUtil.findUnique(this, hql, params.toArray());
return result;
}
/**
* Get the pollAccount of a voter for a given {@code pollId} using his
- * {@code accountId}.
+ * {@code accountId} or {@code user}.
+ * <p/>
+ * <strong>Note:</strong> {@code accountId} and {@code user} can not
+ * be null at the same time.
*
* @param pollId the poll where to seek
* @param accountId the account id to test
+ * @param user the connected user account to test
* @return the found pollAccount, or {@code null} if not found
* @throws TopiaException if any db pb
*/
- public E findVoterPollAccountByAccountId(String pollId,
- String accountId) throws TopiaException {
+ public E findVoterPollAccount(String pollId,
+ String accountId,
+ UserAccount user) throws TopiaException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(accountId);
+ Preconditions.checkArgument(StringUtils.isNotBlank(pollId));
+ Preconditions.checkArgument(StringUtils.isNotBlank(accountId) ||
+ user != null);
-// TopiaQuery query = createQuery("e")
-// .addFrom(Poll.class, "p")
-// .addFrom(Vote.class, "v")
-// .addEquals("p." + Poll.PROPERTY_POLL_ID, pollId)
-// .addInElements("v", "p." + Poll.PROPERTY_VOTE)
-// .addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
-// .addEquals("e." + PollAccount.PROPERTY_ACCOUNT_ID, accountId);
-// PollAccount result = findByQuery(query);
-
String hql = "SELECT e FROM PollAccountImpl e, PollImpl p, VoteImpl v WHERE " +
"p.pollId = :pollId AND " +
"v in elements (p.vote) AND " +
- "e = v.pollAccount AND " +
- "e.accountId = :accountId";
+ "e = v.pollAccount AND ";
- E result = PollenPersistenceUtil.findUnique(
- this, hql, "pollId", pollId, "accountId", accountId);
- return result;
- }
+ boolean withAccountId = StringUtils.isNotBlank(accountId);
+ boolean withEmail = user != null;
- /**
- * Get the pollAccount of a voter for a given {@code pollId} using his
- * {@code user}.
- *
- * @param pollId the poll id where to seek
- * @param user the user account to test
- * @return the found pollAccount, or {@code null} if not found
- * @throws TopiaException if any db pb
- */
- public E findVoterPollAccountByUserAccount(String pollId,
- UserAccount user) throws TopiaException {
+ List<Object> params = Lists.<Object>newArrayList("pollId", pollId);
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(user);
+ if (withAccountId && withEmail) {
-// TopiaQuery query = createQuery("e")
-// .addFrom(Poll.class, "p")
-// .addFrom(Vote.class, "v")
-// .addEquals("p." + Poll.PROPERTY_POLL_ID, pollId)
-// .addInElements("v", "p." + Poll.PROPERTY_VOTE)
-// .addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
-// .addEquals("e." + PollAccount.PROPERTY_USER_ACCOUNT, user);
-// PollAccount result = findByQuery(query);
+ // try with both email or accountId
+ params.add("accountId");
+ params.add(accountId);
+ params.add("user");
+ params.add(user);
+ hql += "(e.accountId = :accountId OR e.userAccount = :user)";
+ } else if (withAccountId) {
- String hql = "SELECT e FROM PollAccountImpl e, PollImpl p, VoteImpl v WHERE " +
- "p.pollId = :pollId AND " +
- "v in elements (p.vote) AND " +
- "e = v.pollAccount AND " +
- "e.userAccount = :user";
+ // try only with accountId
+ params.add("accountId");
+ params.add(accountId);
+ hql += "e.accountId = :accountId";
+ } else {
- E result = PollenPersistenceUtil.findUnique(
- this, hql, "pollId", pollId, "user", user);
+ // try only with email
+ params.add("user");
+ params.add(user);
+ hql += "e.userAccount = :user";
+ }
+
+ E result = PollenPersistenceUtil.findUnique(this, hql, params.toArray());
return result;
}
@@ -217,23 +196,23 @@
"e.email = :email";
boolean result;
String pollAccountId = pollAccount.getTopiaId();
- if (pollAccountId == null) {
- // no check necessary, it's a new pollAccount
+ List<Object> params = Lists.<Object>newArrayList(
+ "person", personListToUpdate,
+ "email", pollAccount.getEmail());
- result = PollenPersistenceUtil.exists(
- this, hql,
- "person", personListToUpdate,
- "email", pollAccount.getEmail());
- } else {
+ if (StringUtils.isNotBlank(pollAccountId)) {
+
+ // check also by account topiaId
+
hql += " AND e.topiaId = :topiaId";
- result = PollenPersistenceUtil.exists(
- this, hql,
- "person", personListToUpdate,
- "email", pollAccount.getEmail(),
- "topiaId", pollAccountId);
+ params.add("topiaId");
+ params.add(pollAccountId);
+
}
+
+ result = PollenPersistenceUtil.exists(this, hql, params.toArray());
return result;
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java 2012-08-13 13:07:02 UTC (rev 3602)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java 2012-08-13 13:08:27 UTC (rev 3603)
@@ -57,20 +57,13 @@
String accountEmail3 = "email3";
@Test
- public void findVoterPollAccountByAccountId() throws Exception {
+ public void findVoterPollAccount() throws Exception {
if (log.isWarnEnabled()) {
- log.warn("Missing PollAccountDAOImpl#findVoterPollAccountByAccountId request test!");
+ log.warn("Missing PollAccountDAOImpl#findVoterPollAccount request test!");
}
}
@Test
- public void findVoterPollAccountByUserAccount() throws Exception {
- if (log.isWarnEnabled()) {
- log.warn("Missing PollAccountDAOImpl#findVoterPollAccountByUserAccount request test!");
- }
- }
-
- @Test
public void findFavoriteListUsers() throws TopiaException {
if (log.isWarnEnabled()) {
log.warn("Missing PollAccountDAOImpl#findFavoriteListUsers request test!");
@@ -84,8 +77,9 @@
}
}
+
@Test
- public void findRestrictedPollAccountByAccountId() throws Exception {
+ public void findRestrictedPollAccount() throws Exception {
TopiaContext tx = beginTransaction();
@@ -94,6 +88,11 @@
VotingListDAO votingListDAO = PollenDAOHelper.getVotingListDAO(tx);
PersonToListDAO personToListDAO = PollenDAOHelper.getPersonToListDAO(tx);
+ UserAccount userAccount = new UserAccountImpl(accountEmail);
+ UserAccount userAccount2 = new UserAccountImpl(accountEmail2);
+ UserAccount userAccount3 = new UserAccountImpl(accountEmail3);
+ UserAccount userAccountFake = new UserAccountImpl("HumFAKE!");
+
PollAccount pollAccount = pollAccountDAO.create(
PollAccount.PROPERTY_ACCOUNT_ID, accountId,
PollAccount.PROPERTY_EMAIL, accountEmail);
@@ -130,113 +129,80 @@
pollAccount2.addVotingListPersonToList(personToList2);
pollAccount3.addVotingListPersonToList(personToList3);
- PollAccount restrictedPollAccount =
- pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, accountId);
+ PollAccount restrictedPollAccount;
- Assert.assertNotNull(restrictedPollAccount);
- Assert.assertEquals(accountId, restrictedPollAccount.getAccountId());
- Assert.assertNotNull(restrictedPollAccount.getVotingListPersonToList());
- Assert.assertTrue(restrictedPollAccount.getVotingListPersonToList().contains(personToList));
+ // -- PollAccount -- //
- PollAccount restrictedPollAccount2 =
- pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, accountId2);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId, null);
+ assertRestrictedAccount(restrictedPollAccount, accountId, null, personToList);
- Assert.assertNotNull(restrictedPollAccount2);
- Assert.assertEquals(accountId2, restrictedPollAccount2.getAccountId());
- Assert.assertNotNull(restrictedPollAccount2.getVotingListPersonToList());
- Assert.assertFalse(restrictedPollAccount2.getVotingListPersonToList().contains(personToList));
- Assert.assertTrue(restrictedPollAccount2.getVotingListPersonToList().contains(personToList2));
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId, userAccountFake);
+ assertRestrictedAccount(restrictedPollAccount, accountId, null, personToList);
- PollAccount restrictedPollAccount3 =
- pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, accountId3);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, null, userAccount);
+ assertRestrictedAccount(restrictedPollAccount, null, userAccount, personToList);
- Assert.assertNotNull(restrictedPollAccount3);
- Assert.assertEquals(accountId3, restrictedPollAccount3.getAccountId());
- Assert.assertNotNull(restrictedPollAccount3.getVotingListPersonToList());
- Assert.assertFalse(restrictedPollAccount3.getVotingListPersonToList().contains(personToList));
- Assert.assertTrue(restrictedPollAccount3.getVotingListPersonToList().contains(personToList3));
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, "HummFAKE", userAccount);
+ assertRestrictedAccount(restrictedPollAccount, null, userAccount, personToList);
- PollAccount restrictedPollAccount4 =
- pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, System.nanoTime() + "--");
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId, userAccount);
+ assertRestrictedAccount(restrictedPollAccount, accountId, userAccount, personToList);
- Assert.assertNull(restrictedPollAccount4);
- }
+ // -- PollAccount2 -- //
- @Test
- public void findRestrictedPollAccountByEmail() throws Exception {
- TopiaContext tx = beginTransaction();
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId2, null);
- PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
- PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx);
- VotingListDAO votingListDAO = PollenDAOHelper.getVotingListDAO(tx);
- PersonToListDAO personToListDAO = PollenDAOHelper.getPersonToListDAO(tx);
+ assertRestrictedAccount(restrictedPollAccount, accountId2, null, personToList2);
- PollAccount pollAccount = pollAccountDAO.create(
- PollAccount.PROPERTY_ACCOUNT_ID, accountId,
- PollAccount.PROPERTY_EMAIL, accountEmail);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId2, userAccountFake);
+ assertRestrictedAccount(restrictedPollAccount, accountId2, null, personToList2);
- PollAccount pollAccount2 = pollAccountDAO.create(
- PollAccount.PROPERTY_ACCOUNT_ID, accountId2,
- PollAccount.PROPERTY_EMAIL, accountEmail2);
- PollAccount pollAccount3 = pollAccountDAO.create(
- PollAccount.PROPERTY_ACCOUNT_ID, accountId3,
- PollAccount.PROPERTY_EMAIL, accountEmail3);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, null, userAccount2);
+ assertRestrictedAccount(restrictedPollAccount, null, userAccount2, personToList2);
- Poll poll = pollDAO.create(Poll.PROPERTY_POLL_ID, pollId);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, "HUMFake!", userAccount2);
+ assertRestrictedAccount(restrictedPollAccount, null, userAccount2, personToList2);
- VotingList votingList = votingListDAO.create();
- poll.addVotingList(votingList);
- VotingList votingList2 = votingListDAO.create();
- poll.addVotingList(votingList2);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId2, userAccount2);
+ assertRestrictedAccount(restrictedPollAccount, accountId2, userAccount2, personToList2);
- PersonToList personToList = personToListDAO.create(
- PersonToList.PROPERTY_POLL_ACCOUNT, pollAccount,
- PersonToList.PROPERTY_VOTING_LIST, votingList
- );
+ // -- PollAccount3-- //
- PersonToList personToList2 = personToListDAO.create(
- PersonToList.PROPERTY_POLL_ACCOUNT, pollAccount2,
- PersonToList.PROPERTY_VOTING_LIST, votingList
- );
- PersonToList personToList3 = personToListDAO.create(
- PersonToList.PROPERTY_POLL_ACCOUNT, pollAccount3,
- PersonToList.PROPERTY_VOTING_LIST, votingList2
- );
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId3, null);
+ assertRestrictedAccount(restrictedPollAccount, accountId3, null, personToList3);
- pollAccount.addVotingListPersonToList(personToList);
- pollAccount2.addVotingListPersonToList(personToList2);
- pollAccount3.addVotingListPersonToList(personToList3);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId3, userAccountFake);
+ assertRestrictedAccount(restrictedPollAccount, accountId3, null, personToList3);
- PollAccount restrictedPollAccount =
- pollAccountDAO.findRestrictedPollAccountByEmail(pollId, accountEmail);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, null, userAccount3);
+ assertRestrictedAccount(restrictedPollAccount, null, userAccount3, personToList3);
- Assert.assertNotNull(restrictedPollAccount);
- Assert.assertEquals(accountId, restrictedPollAccount.getAccountId());
- Assert.assertNotNull(restrictedPollAccount.getVotingListPersonToList());
- Assert.assertTrue(restrictedPollAccount.getVotingListPersonToList().contains(personToList));
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, "HUMFake!", userAccount3);
+ assertRestrictedAccount(restrictedPollAccount, null, userAccount3, personToList3);
- PollAccount restrictedPollAccount2 =
- pollAccountDAO.findRestrictedPollAccountByEmail(pollId, accountEmail2);
+ restrictedPollAccount = pollAccountDAO.findRestrictedPollAccount(pollId, accountId3, userAccount3);
+ assertRestrictedAccount(restrictedPollAccount, accountId3, userAccount3, personToList3);
- Assert.assertNotNull(restrictedPollAccount2);
- Assert.assertEquals(accountId2, restrictedPollAccount2.getAccountId());
- Assert.assertNotNull(restrictedPollAccount2.getVotingListPersonToList());
- Assert.assertFalse(restrictedPollAccount2.getVotingListPersonToList().contains(personToList));
- Assert.assertTrue(restrictedPollAccount2.getVotingListPersonToList().contains(personToList2));
+ restrictedPollAccount =
+ pollAccountDAO.findRestrictedPollAccount(pollId, System.nanoTime() + "--", null);
- PollAccount restrictedPollAccount3 =
- pollAccountDAO.findRestrictedPollAccountByEmail(pollId, accountEmail3);
-
- Assert.assertNotNull(restrictedPollAccount3);
- Assert.assertEquals(accountId3, restrictedPollAccount3.getAccountId());
- Assert.assertNotNull(restrictedPollAccount3.getVotingListPersonToList());
- Assert.assertFalse(restrictedPollAccount3.getVotingListPersonToList().contains(personToList));
- Assert.assertTrue(restrictedPollAccount3.getVotingListPersonToList().contains(personToList3));
-
- PollAccount restrictedPollAccount4 =
- pollAccountDAO.findRestrictedPollAccountByEmail(pollId, System.nanoTime() + "--");
-
- Assert.assertNull(restrictedPollAccount4);
+ Assert.assertNull(restrictedPollAccount);
}
+ protected void assertRestrictedAccount(PollAccount restrictedPollAccount,
+ String accountId,
+ UserAccount useraccount,
+ PersonToList personToList) {
+ Assert.assertNotNull(restrictedPollAccount);
+ if (accountId != null) {
+ Assert.assertEquals(accountId,
+ restrictedPollAccount.getAccountId());
+ }
+ if (useraccount != null) {
+ Assert.assertEquals(useraccount.getEmail(),
+ restrictedPollAccount.getEmail());
+ }
+ Assert.assertNotNull(restrictedPollAccount.getVotingListPersonToList());
+ Assert.assertTrue(restrictedPollAccount.getVotingListPersonToList().contains(personToList));
+ }
}
1
0
r3602 - trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 15:07:02 +0200 (Mon, 13 Aug 2012)
New Revision: 3602
Url: http://chorem.org/repositories/revision/pollen/3602
Log:
add a nice constructor
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountImpl.java
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountImpl.java 2012-08-13 10:11:34 UTC (rev 3601)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountImpl.java 2012-08-13 13:07:02 UTC (rev 3602)
@@ -28,6 +28,13 @@
private static final long serialVersionUID = 1L;
+ public UserAccountImpl() {
+ }
+
+ public UserAccountImpl(String email) {
+ setEmail(email);
+ }
+
@Override
public String getDisplayName() {
String result = "";
1
0
r3601 - trunk/pollen-services/src/main/java/org/chorem/pollen
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 12:11:34 +0200 (Mon, 13 Aug 2012)
New Revision: 3601
Url: http://chorem.org/repositories/revision/pollen/3601
Log:
refs #746: Improve security model (more methods to instanciate a security context)
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java 2012-08-13 10:10:10 UTC (rev 3600)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java 2012-08-13 10:11:34 UTC (rev 3601)
@@ -23,6 +23,7 @@
*/
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
import org.apache.commons.collections.CollectionUtils;
import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.bean.PollUrl;
@@ -31,6 +32,7 @@
import org.chorem.pollen.services.impl.SecurityService;
import java.io.Serializable;
+import java.util.Collections;
import java.util.Set;
/**
@@ -72,10 +74,27 @@
protected Set<PollenUserSecurityRole> userRoles;
public static PollenUserSecurityContext newContext(UserAccount userAccount, PollUri pollUri) {
+ return newContext(userAccount, pollUri, null);
+ }
+
+ public static PollenUserSecurityContext newContext(UserAccount userAccount,
+ String pollId,
+ String accountId,
+ Poll poll) {
+ return newContext(userAccount,
+ PollUri.newPollUri(pollId, accountId),
+ poll);
+ }
+
+ public static PollenUserSecurityContext newContext(UserAccount userAccount,
+ PollUri pollUri,
+ Poll poll) {
PollenUserSecurityContext result = new PollenUserSecurityContext(
- userAccount,
- pollUri
+ userAccount, pollUri
);
+ if (poll != null) {
+ result.setPoll(poll);
+ }
return result;
}
@@ -97,21 +116,27 @@
}
public boolean isCreator() {
- return userRoles.contains(PollenUserSecurityRole.CREATOR);
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.CREATOR);
}
public boolean isVoter() {
- return userRoles.contains(PollenUserSecurityRole.VOTER);
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.VOTER);
}
public boolean isRestrictedVoter() {
- return userRoles.contains(PollenUserSecurityRole.RESTRICTED_VOTER);
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.RESTRICTED_VOTER);
}
public boolean hasNoRole() {
return CollectionUtils.isEmpty(userRoles);
}
+ public Set<PollenUserSecurityRole> getUserRoles() {
+ return CollectionUtils.isEmpty(userRoles) ?
+ Collections.<PollenUserSecurityRole>emptySet() :
+ ImmutableSet.copyOf(userRoles);
+ }
+
public UserAccount getUserAccount() {
return userAccount;
}
1
0
r3600 - trunk/pollen-services/src/main/java/org/chorem/pollen/bean
by tchemit@users.chorem.org 13 Aug '12
by tchemit@users.chorem.org 13 Aug '12
13 Aug '12
Author: tchemit
Date: 2012-08-13 12:10:10 +0200 (Mon, 13 Aug 2012)
New Revision: 3600
Url: http://chorem.org/repositories/revision/pollen/3600
Log:
remove unused bean
Removed:
trunk/pollen-services/src/main/java/org/chorem/pollen/bean/UserPoll.java
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/bean/UserPoll.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/bean/UserPoll.java 2012-08-12 14:07:52 UTC (rev 3599)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/UserPoll.java 2012-08-13 10:10:10 UTC (rev 3600)
@@ -1,126 +0,0 @@
-/*
- * #%L
- * Pollen :: Services
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.bean;
-
-
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.PollAccount;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-public class UserPoll implements Serializable {
-
- private static final long serialVersionUID = 7293352208965578801L;
-
- public static final String PROPERTY_POLL = "poll";
-
- public static final String PROPERTY_ACCOUNTS = "accounts";
-
- public static final String PROPERTY_CREATOR = "creator";
-
- protected Boolean creator;
-
- protected Poll poll;
-
- protected List<PollAccount> accounts;
-
- protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
-
- public boolean isCreator() {
- // Lazy initialization of creator boolean
- if (creator == null) {
- for (PollAccount account : accounts) {
- if (account.equals(poll.getCreator())) {
- creator = true;
- break;
- }
- }
- if (creator == null) {
- creator = false;
- }
- }
- return creator;
- }
-
- public String getPollUid() {
- return poll.getPollId();
- }
-
- public List<PollAccount> getAccounts() {
- if (accounts == null) {
- accounts = new ArrayList<PollAccount>();
- }
- return accounts;
- }
-
- public boolean addAccount(PollAccount account) {
- boolean result = getAccounts().add(account);
- return result;
- }
-
- public Poll getPoll() {
- return poll;
- }
-
- public void setPoll(Poll poll) {
- Poll oldValue = getPoll();
- this.poll = poll;
- firePropertyChange(PROPERTY_POLL, oldValue, poll);
- }
-
-
- public void setAccounts(List<PollAccount> accounts) {
- List<PollAccount> oldValue = getAccounts();
- this.accounts = accounts;
- firePropertyChange(PROPERTY_ACCOUNTS, oldValue, accounts);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- protected void firePropertyChange(String propertyName, Object newValue) {
- firePropertyChange(propertyName, null, newValue);
- }
-
-} //UserPoll
1
0
r3599 - in trunk: pollen-persistence/src/main/java/org/chorem/pollen pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-persistence/src/test/java/org/chorem/pollen/business/persistence pollen-services/src/main/java/org/chorem/pollen/services/impl
by tchemit@users.chorem.org 12 Aug '12
by tchemit@users.chorem.org 12 Aug '12
12 Aug '12
Author: tchemit
Date: 2012-08-12 16:07:52 +0200 (Sun, 12 Aug 2012)
New Revision: 3599
Url: http://chorem.org/repositories/revision/pollen/3599
Log:
fixes #642: Review persistence module
- no more TopiaQuery (at last...)
- improve dao code (using the PollenPersistenceUtil)
- renam efor dao method (getXXX becomes findXXX)
- review tests
Added:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenPersistenceUtil.java
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenIOUtil.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/AbstractDAOTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenIOUtil.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenIOUtil.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenIOUtil.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -22,17 +22,10 @@
*/
package org.chorem.pollen;
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
-import org.nuiton.util.PagerUtil;
import java.io.File;
-import java.util.List;
/**
* Some utils IO methods.
@@ -48,7 +41,9 @@
protected PollenIOUtil() {
}
- public static File getTestSpecificDirectory(Class<?> klass, String methodName, long timestamp) {
+ public static File getTestSpecificDirectory(Class<?> klass,
+ String methodName,
+ long timestamp) {
// Trying to look for the temporary folder to store data for the test
String tempDirPath = System.getProperty("java.io.tmpdir");
if (tempDirPath == null) {
@@ -70,31 +65,4 @@
return databaseFile;
}
- public static <E> List<E> findByPager(TopiaContext tx,
- String hql,
- TopiaFilterPagerUtil.FilterPagerBean pager,
- Object... params) throws TopiaException {
- Preconditions.checkNotNull(pager);
-
- if (StringUtils.isNotBlank(pager.getSortColumn())) {
- hql += " ORDER BY " + pager.getSortColumn();
- if (!pager.isSortAscendant()) {
- hql += " DESC";
- }
- }
- List<E> result = tx.find(hql,
- pager.getRecordStartIndex(),
- pager.getRecordEndIndex() - 1, params);
- return result;
- }
-
- public static void computeAndAddRecordsToPager(
- TopiaContext tx,
- String countHql,
- TopiaFilterPagerUtil.FilterPagerBean pager,
- Object... params) throws TopiaException {
- long records = (Long) tx.findUnique(countHql, params);
- pager.setRecords((int) records);
- PagerUtil.computeRecordIndexesAndPagesNumber(pager);
- }
}
Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenPersistenceUtil.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenPersistenceUtil.java (rev 0)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenPersistenceUtil.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -0,0 +1,149 @@
+package org.chorem.pollen;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.util.PagerUtil;
+
+import java.util.List;
+
+/**
+ * Useful method around persistence.
+ * <p/>
+ * <strong>Note:</strong> Some of these methods should be pushed back to
+ * ToPIA dao.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class PollenPersistenceUtil {
+
+ public static boolean exists(TopiaDAO dao,
+ String hql,
+ Object... params) throws TopiaException {
+ long count = count(dao, hql, params);
+ return count > 0;
+ }
+
+ public static long count(TopiaDAO<?> dao,
+ String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkArgument(hql.startsWith("SELECT COUNT("));
+
+ return findUnique(dao, Long.class, hql, params);
+ }
+
+ public static <R extends TopiaEntity> R findUnique(TopiaDAO<R> dao,
+ String hql,
+ Object... params) throws TopiaException {
+ return findUnique(dao, dao.getEntityClass(), hql, params);
+ }
+
+ public static <R, V extends TopiaEntity> R findUnique(TopiaDAO<V> dao,
+ Class<R> type,
+ String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(dao);
+ Preconditions.checkNotNull(type);
+ Preconditions.checkNotNull(hql);
+
+ Object unique = dao.getContext().findUnique(hql, params);
+ Preconditions.checkState(unique == null ||
+ type.isAssignableFrom(unique.getClass()));
+ return (R) unique;
+ }
+
+ public static <R extends TopiaEntity> List<R> findAll(TopiaDAO<R> dao,
+ String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(dao);
+ return findAll(dao, dao.getEntityClass(), hql, params);
+ }
+
+ public static <R, V extends TopiaEntity> List<R> findAll(TopiaDAO<V> dao,
+ Class<R> type,
+ String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(dao);
+ Preconditions.checkNotNull(type);
+ Preconditions.checkNotNull(hql);
+
+ List<R> result = dao.getContext().findAll(hql, params);
+ return result;
+ }
+
+ public static <R extends TopiaEntity> List<R> findAllWithBound(TopiaDAO<R> dao,
+ String hql,
+ int startIndex,
+ int endIndex,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(dao);
+ Preconditions.checkNotNull(hql);
+
+ List<R> result = dao.getContext().find(hql, startIndex, endIndex, params);
+ return result;
+ }
+
+ public static <R extends TopiaEntity> List<R> findByPager(TopiaDAO<R> dao,
+ String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException {
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(hql);
+
+ if (StringUtils.isNotBlank(pager.getSortColumn())) {
+ hql += " ORDER BY " + pager.getSortColumn();
+ if (!pager.isSortAscendant()) {
+ hql += " DESC";
+ }
+ }
+ List<R> result = findAllWithBound(dao,
+ hql,
+ pager.getRecordStartIndex(),
+ pager.getRecordEndIndex() - 1,
+ params);
+ return result;
+ }
+
+ public static void computeAndAddRecordsToPager(TopiaDAO<?> dao,
+ String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException {
+
+ long records = count(dao, hql, params);
+
+ pager.setRecords((int) records);
+ PagerUtil.computeRecordIndexesAndPagesNumber(pager);
+ }
+}
Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenPersistenceUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -23,7 +23,7 @@
package org.chorem.pollen.business.persistence;
import com.google.common.base.Preconditions;
-import org.chorem.pollen.PollenIOUtil;
+import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -31,31 +31,35 @@
public class CommentDAOImpl<E extends Comment> extends CommentDAOAbstract<E> {
- public List<E> getComments(TopiaFilterPagerUtil.FilterPagerBean pager,
- String pollId) throws TopiaException {
+ public List<E> findComments(TopiaFilterPagerUtil.FilterPagerBean pager,
+ String pollId) throws TopiaException {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(pollId);
- String countHql = "SELECT COUNT(e) FROM CommentImpl e, PollImpl p WHERE p.pollId = :pollId AND e IN ELEMENTS(p.comment)";
- PollenIOUtil.computeAndAddRecordsToPager(getContext(), countHql, pager,
- "pollId", pollId);
+ String countHql = "SELECT COUNT(e) FROM CommentImpl e, PollImpl p WHERE" +
+ " p.pollId = :pollId AND e IN ELEMENTS(p.comment)";
- String hql = "SELECT e FROM CommentImpl e, PollImpl p WHERE p.pollId = :pollId AND e IN ELEMENTS(p.comment)";
- List<E> result = PollenIOUtil.findByPager(getContext(), hql, pager,
- "pollId", pollId);
+ PollenPersistenceUtil.computeAndAddRecordsToPager(
+ this, countHql, pager, "pollId", pollId);
+
+ String hql = "SELECT e FROM CommentImpl e, PollImpl p WHERE " +
+ "p.pollId = :pollId AND e IN ELEMENTS(p.comment)";
+
+ List<E> result = PollenPersistenceUtil.findByPager(
+ this, hql, pager, "pollId", pollId);
return result;
-
}
- public List<E> getAllComments(String pollId) throws TopiaException {
+ public List<E> findAllComments(String pollId) throws TopiaException {
Preconditions.checkNotNull(pollId);
- String hql = "SELECT e FROM CommentImpl e, PollImpl p WHERE p.pollId = :pollId AND e IN ELEMENTS(p.comment)";
- List<E> result = getContext().findAll(hql, "pollId", pollId);
+ String hql = "SELECT e FROM CommentImpl e, PollImpl p WHERE " +
+ "p.pollId = :pollId AND e IN ELEMENTS(p.comment)";
+
+ List<E> result = PollenPersistenceUtil.findAll(
+ this, hql, "pollId", pollId);
return result;
-
}
-
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -24,7 +24,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.PollenIOUtil;
+import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -32,27 +32,33 @@
public class PersonListDAOImpl<E extends PersonList> extends PersonListDAOAbstract<E> {
- public List<E> getFavoriteLists(UserAccount user,
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> findFavoriteLists(UserAccount user,
+ TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(user);
Preconditions.checkNotNull(pager);
- String countHql = "SELECT COUNT(*) FROM PersonListImpl WHERE owner = :owner";
- PollenIOUtil.computeAndAddRecordsToPager(getContext(), countHql, pager,
- "owner", user);
+ String countHql = "SELECT COUNT(*) FROM PersonListImpl WHERE " +
+ "owner = :owner";
+ PollenPersistenceUtil.computeAndAddRecordsToPager(
+ this, countHql, pager, "owner", user);
+
String hql = "FROM PersonListImpl e WHERE e.owner = :owner";
- List<E> result = PollenIOUtil.findByPager(getContext(), hql, pager,
- "owner", user);
+
+ List<E> result = PollenPersistenceUtil.findByPager(
+ this, hql, pager, "owner", user);
return result;
}
- public List<E> getFavoriteLists(UserAccount user) throws TopiaException {
+ public List<E> findAllFavoriteLists(UserAccount user) throws TopiaException {
Preconditions.checkNotNull(user);
+
String hql = "FROM PersonListImpl WHERE owner = :owner";
- List<E> result = getContext().findAll(hql, "owner", user);
+
+ List<E> result = PollenPersistenceUtil.findAll(
+ this, hql, "owner", user);
return result;
}
@@ -61,15 +67,14 @@
Preconditions.checkNotNull(user);
Preconditions.checkNotNull(name);
-
- // can't accept favorite list without name
Preconditions.checkArgument(StringUtils.isNotEmpty(name));
- // check list does not already exists
+ String hql = "SELECT COUNT(*) FROM PersonListImpl WHERE " +
+ "owner = :owner AND name = :name";
- String hql = "SELECT COUNT(*) FROM PersonListImpl WHERE owner = :owner AND name = :name";
- long count = (Long) getContext().findUnique(hql, "owner", user, "name", name);
- return count > 0;
+ boolean result = PollenPersistenceUtil.exists(
+ this, hql, "owner", user, "name", name);
+ return result;
}
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -23,8 +23,8 @@
package org.chorem.pollen.business.persistence;
import com.google.common.base.Preconditions;
+import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
import java.util.List;
@@ -41,19 +41,27 @@
* @return the found pollAccount, or {@code null} if not foud
* @throws TopiaException if any db pb
*/
- public E getRestrictedPollAccountByAccountId(String pollId,
- String accountId) throws TopiaException {
+ public E findRestrictedPollAccountByAccountId(String pollId,
+ String accountId) throws TopiaException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(accountId);
- TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
- addFrom(Poll.class, "poll").
- setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
- addWhere("poll." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId).
- addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_ACCOUNT_ID, TopiaQuery.Op.EQ, accountId).
- addInElements("p", "poll." + Poll.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST);
- E result = findByQuery(query);
+// TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
+// addFrom(Poll.class, "poll").
+// setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
+// addWhere("poll." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId).
+// addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_ACCOUNT_ID, TopiaQuery.Op.EQ, accountId).
+// addInElements("p", "poll." + Poll.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST);
+// E result = findByQuery(query);
+
+ String hql = "SELECT p.pollAccount FROM PersonToListImpl p, PollImpl poll WHERE " +
+ "poll.pollId = :pollId AND " +
+ "p.pollAccount.accountId = :accountId AND " +
+ "p in elements (poll.votingList.pollAccountPersonToList)";
+
+ E result = PollenPersistenceUtil.findUnique(
+ this, hql, "pollId", pollId, "accountId", accountId);
return result;
}
@@ -67,19 +75,27 @@
* @return the found pollAccount, or {@code null} if not found
* @throws TopiaException if any db pb
*/
- public E getRestrictedPollAccountByEmail(String pollId,
- String email) throws TopiaException {
+ public E findRestrictedPollAccountByEmail(String pollId,
+ String email) throws TopiaException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(email);
- TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
- addFrom(Poll.class, "poll").
- setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
- addWhere("poll." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId).
- addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_EMAIL, TopiaQuery.Op.EQ, email).
- addInElements("p", "poll." + Poll.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST);
- E result = findByQuery(query);
+// TopiaQuery query = new TopiaQuery(PersonToList.class, "p").
+// addFrom(Poll.class, "poll").
+// setSelect("p." + PersonToList.PROPERTY_POLL_ACCOUNT).
+// addWhere("poll." + Poll.PROPERTY_POLL_ID, TopiaQuery.Op.EQ, pollId).
+// addWhere("p." + PersonToList.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_EMAIL, TopiaQuery.Op.EQ, email).
+// addInElements("p", "poll." + Poll.PROPERTY_VOTING_LIST + "." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST);
+// E result = findByQuery(query);
+
+ String hql = "SELECT p.pollAccount FROM PersonToListImpl p, PollImpl poll WHERE " +
+ "poll.pollId = :pollId AND " +
+ "p.pollAccount.email = :email AND " +
+ "p in elements (poll.votingList.pollAccountPersonToList)";
+
+ E result = PollenPersistenceUtil.findUnique(
+ this, hql, "pollId", pollId, "email", email);
return result;
}
@@ -92,20 +108,29 @@
* @return the found pollAccount, or {@code null} if not found
* @throws TopiaException if any db pb
*/
- public PollAccount getVoterPollAccountByAccountId(String pollId,
- String accountId) throws TopiaException {
+ public E findVoterPollAccountByAccountId(String pollId,
+ String accountId) throws TopiaException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(accountId);
- TopiaQuery query = createQuery("e")
- .addFrom(Poll.class, "p")
- .addFrom(Vote.class, "v")
- .addEquals("p." + Poll.PROPERTY_POLL_ID, pollId)
- .addInElements("v", "p." + Poll.PROPERTY_VOTE)
- .addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
- .addEquals("e." + PollAccount.PROPERTY_ACCOUNT_ID, accountId);
- PollAccount result = findByQuery(query);
+// TopiaQuery query = createQuery("e")
+// .addFrom(Poll.class, "p")
+// .addFrom(Vote.class, "v")
+// .addEquals("p." + Poll.PROPERTY_POLL_ID, pollId)
+// .addInElements("v", "p." + Poll.PROPERTY_VOTE)
+// .addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
+// .addEquals("e." + PollAccount.PROPERTY_ACCOUNT_ID, accountId);
+// PollAccount result = findByQuery(query);
+
+ String hql = "SELECT e FROM PollAccountImpl e, PollImpl p, VoteImpl v WHERE " +
+ "p.pollId = :pollId AND " +
+ "v in elements (p.vote) AND " +
+ "e = v.pollAccount AND " +
+ "e.accountId = :accountId";
+
+ E result = PollenPersistenceUtil.findUnique(
+ this, hql, "pollId", pollId, "accountId", accountId);
return result;
}
@@ -118,25 +143,34 @@
* @return the found pollAccount, or {@code null} if not found
* @throws TopiaException if any db pb
*/
- public PollAccount getVoterPollAccountByUserAccount(String pollId,
- UserAccount user) throws TopiaException {
+ public E findVoterPollAccountByUserAccount(String pollId,
+ UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(user);
- TopiaQuery query = createQuery("e")
- .addFrom(Poll.class, "p")
- .addFrom(Vote.class, "v")
- .addEquals("p." + Poll.PROPERTY_POLL_ID, pollId)
- .addInElements("v", "p." + Poll.PROPERTY_VOTE)
- .addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
- .addEquals("e." + PollAccount.PROPERTY_USER_ACCOUNT, user);
- PollAccount result = findByQuery(query);
+// TopiaQuery query = createQuery("e")
+// .addFrom(Poll.class, "p")
+// .addFrom(Vote.class, "v")
+// .addEquals("p." + Poll.PROPERTY_POLL_ID, pollId)
+// .addInElements("v", "p." + Poll.PROPERTY_VOTE)
+// .addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
+// .addEquals("e." + PollAccount.PROPERTY_USER_ACCOUNT, user);
+// PollAccount result = findByQuery(query);
+
+ String hql = "SELECT e FROM PollAccountImpl e, PollImpl p, VoteImpl v WHERE " +
+ "p.pollId = :pollId AND " +
+ "v in elements (p.vote) AND " +
+ "e = v.pollAccount AND " +
+ "e.userAccount = :user";
+
+ E result = PollenPersistenceUtil.findUnique(
+ this, hql, "pollId", pollId, "user", user);
return result;
}
- public List<E> getFavoriteListUsers(PersonList favoriteList,
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> findFavoriteListUsers(PersonList favoriteList,
+ TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(favoriteList);
Preconditions.checkNotNull(pager);
@@ -144,11 +178,16 @@
int records = favoriteList.sizePollAccount();
pager.setRecords(records);
- TopiaQuery query = createQuery("e");
- TopiaFilterPagerUtil.addPagerToQuery(query, pager);
- query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, favoriteList);
+// TopiaQuery query = createQuery("e");
+// TopiaFilterPagerUtil.addPagerToQuery(query, pager);
+// query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, favoriteList);
+//
+// List<E> result = findAllByQuery(query);
- List<E> result = findAllByQuery(query);
+ String hql = "FROM PollAccountImpl e WHERE e.personList = :owner";
+
+ List<E> result = PollenPersistenceUtil.findByPager(
+ this, hql, pager, "owner", favoriteList);
return result;
}
@@ -158,20 +197,43 @@
Preconditions.checkNotNull(personListToUpdate);
Preconditions.checkNotNull(pollAccount);
- // check there is other poll account in this list with same id
- TopiaQuery query = createQuery("e");
- query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
- query.addWhere("e." + PollAccount.PROPERTY_EMAIL, TopiaQuery.Op.EQ, pollAccount.getEmail());
+// // check there is other poll account in this list with same id
+// TopiaQuery query = createQuery("e");
+// query.addWhere("e." + PollAccount.PROPERTY_PERSON_LIST, TopiaQuery.Op.EQ, personListToUpdate);
+// query.addWhere("e." + PollAccount.PROPERTY_EMAIL, TopiaQuery.Op.EQ, pollAccount.getEmail());
+//
+// String pollAccountId = pollAccount.getTopiaId();
+// if (pollAccountId == null) {
+// // no check necessary, it's a new pollAccount
+//
+// } else {
+// query.addWhere("e." + PollAccount.TOPIA_ID, TopiaQuery.Op.NEQ, pollAccountId);
+// }
+//
+// boolean result = existByQuery(query);
+ String hql = "FROM PollAccountImpl e WHERE " +
+ "e.personList = :person AND " +
+ "e.email = :email";
+ boolean result;
String pollAccountId = pollAccount.getTopiaId();
if (pollAccountId == null) {
+
// no check necessary, it's a new pollAccount
+ result = PollenPersistenceUtil.exists(
+ this, hql,
+ "person", personListToUpdate,
+ "email", pollAccount.getEmail());
} else {
- query.addWhere("e." + PollAccount.TOPIA_ID, TopiaQuery.Op.NEQ, pollAccountId);
+ hql += " AND e.topiaId = :topiaId";
+
+ result = PollenPersistenceUtil.exists(
+ this, hql,
+ "person", personListToUpdate,
+ "email", pollAccount.getEmail(),
+ "topiaId", pollAccountId);
}
-
- boolean result = existByQuery(query);
return result;
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -27,7 +27,7 @@
import com.google.common.collect.Maps;
import org.apache.commons.lang3.tuple.Pair;
import org.chorem.pollen.PollenFunctions;
-import org.chorem.pollen.PollenIOUtil;
+import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -37,37 +37,42 @@
public class PollDAOImpl<E extends Poll> extends PollDAOAbstract<E> {
- public List<E> getPolls(
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> getPolls(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(pager);
String countHql = "SELECT COUNT(*) FROM PollImpl";
- PollenIOUtil.computeAndAddRecordsToPager(getContext(), countHql, pager);
+
+ PollenPersistenceUtil.computeAndAddRecordsToPager(
+ this, countHql, pager);
+
String hql = "FROM PollImpl";
- List<E> result = PollenIOUtil.findByPager(getContext(), hql, pager);
+
+ List<E> result = PollenPersistenceUtil.findByPager(this, hql, pager);
return result;
}
- public List<E> getCreatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
- UserAccount user) throws TopiaException {
+ public List<E> findCreatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
String countHql = "SELECT COUNT(*) FROM PollImpl " +
"WHERE creator.userAccount = :user";
- PollenIOUtil.computeAndAddRecordsToPager(getContext(), countHql, pager,
- "user", user);
+
+ PollenPersistenceUtil.computeAndAddRecordsToPager(
+ this, countHql, pager, "user", user);
+
String hql = "FROM PollImpl WHERE creator.userAccount = :user";
- List<E> result = PollenIOUtil.findByPager(getContext(), hql, pager,
- "user", user);
+
+ List<E> result = PollenPersistenceUtil.findByPager(
+ this, hql, pager, "user", user);
return result;
}
- public List<Pair<Poll, PollAccount>> getInvitedPolls(
- TopiaFilterPagerUtil.FilterPagerBean pager,
- UserAccount user) throws TopiaException {
+ public List<Pair<Poll, PollAccount>> findInvitedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
@@ -81,9 +86,8 @@
return result;
}
- public List<Pair<Poll, PollAccount>> getParticipatedPolls(
- TopiaFilterPagerUtil.FilterPagerBean pager,
- UserAccount user) throws TopiaException {
+ public List<Pair<Poll, PollAccount>> findParticipatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
@@ -91,24 +95,30 @@
String hql = "SELECT p, v.pollAccount FROM VoteImpl v, PollImpl p " +
"WHERE v IN ELEMENTS(p.vote) " +
"AND v.pollAccount.userAccount = :user";
+
List<Pair<Poll, PollAccount>> result = findAllWithPollAccounts(
hql, pager, "user", user);
return result;
}
- public List<E> getRunningPolls(Date currentTime) throws TopiaException {
+ public List<E> findRunningPolls(Date currentTime) throws TopiaException {
- String hql = "FROM PollImpl WHERE (endDate IS NULL OR endDate > :currentTime) AND (beginDate IS NULL OR beginDate < :currentTime)";
- List<E> results = getContext().findAll(hql, "currentTime", currentTime);
+ String hql = "FROM PollImpl WHERE " +
+ "(endDate IS NULL OR endDate > :currentTime) AND " +
+ "(beginDate IS NULL OR beginDate < :currentTime)";
+
+ List<E> results = PollenPersistenceUtil.findAll(
+ this, hql, "currentTime", currentTime);
return results;
}
- protected List<Pair<Poll, PollAccount>> findAllWithPollAccounts(
- String hql,
- TopiaFilterPagerUtil.FilterPagerBean pager, Object... params)
+ protected List<Pair<Poll, PollAccount>> findAllWithPollAccounts(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager, Object... params)
throws TopiaException {
- List<Object[]> queryResults = getContext().findAll(hql, params);
+ List<Object[]> queryResults = PollenPersistenceUtil.findAll(
+ this, Object[].class, hql, params);
+
Map<Poll, PollAccount> mapResult = Maps.newLinkedHashMap();
for (Object[] row : queryResults) {
Poll poll = (Poll) row[0];
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -24,7 +24,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.PollenIOUtil;
+import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -39,23 +39,27 @@
// In case of email change, check if an other user has not already
// the new email
// FIXME-fdesbois-20100510 : replace by using id directly
- String hql = "SELECT COUNT(*) FROM UserAccountImpl WHERE login = :login AND email = :email";
- long count = (Long) getContext().findUnique(
- hql,
+ String hql = "SELECT COUNT(*) FROM UserAccountImpl WHERE " +
+ "login = :login AND email = :email";
+
+ boolean result = PollenPersistenceUtil.exists(
+ this, hql,
"login", user.getLogin(),
"email", StringUtils.lowerCase(user.getEmail()));
- return count > 0;
+ return result;
}
- public List<E> getUsers(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> findUsers(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(pager);
String countHql = "SELECT COUNT(*) FROM UserAccountImpl";
- PollenIOUtil.computeAndAddRecordsToPager(getContext(), countHql, pager);
+ PollenPersistenceUtil.computeAndAddRecordsToPager(this, countHql, pager);
+
String hql = "FROM UserAccountImpl";
- List<E> result = PollenIOUtil.findByPager(getContext(), hql, pager);
+
+ List<E> result = PollenPersistenceUtil.findByPager(this, hql, pager);
return result;
}
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -24,7 +24,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import org.chorem.pollen.PollenIOUtil;
+import org.chorem.pollen.PollenPersistenceUtil;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -32,7 +32,7 @@
public class VoteDAOImpl<E extends Vote> extends VoteDAOAbstract<E> {
- public List<E> getAllVotes(Poll poll) throws TopiaException {
+ public List<E> findAllVotes(Poll poll) throws TopiaException {
Preconditions.checkNotNull(poll);
List<E> results;
@@ -43,14 +43,18 @@
results = Lists.newArrayList();
} else {
- String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE p = :p AND e IN ELEMENTS(p.vote) ORDER BY e.topiaCreateDate DESC";
- results = getContext().findAll(hql, "p", poll);
+ String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE " +
+ "p = :p AND " +
+ "e IN ELEMENTS(p.vote) " +
+ "ORDER BY e.topiaCreateDate DESC";
+
+ results = PollenPersistenceUtil.findAll(this, hql, "p", poll);
}
return results;
}
- public List<E> getVotesByPoll(Poll poll,
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> findAllVotesByPoll(Poll poll,
+ TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(poll);
Preconditions.checkNotNull(pager);
@@ -63,33 +67,41 @@
results = Lists.newArrayList();
} else {
- String countHql = "SELECT COUNT(e) FROM VoteImpl e, PollImpl p WHERE p = :p AND e IN ELEMENTS(p.vote)";
+ String countHql = "SELECT COUNT(e) FROM " +
+ "VoteImpl e, PollImpl p WHERE " +
+ "p = :p AND e IN ELEMENTS(p.vote)";
- PollenIOUtil.computeAndAddRecordsToPager(getContext(),
- countHql, pager,
- "p", poll);
+ PollenPersistenceUtil.computeAndAddRecordsToPager(
+ this, countHql, pager, "p", poll);
- String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE p = :p AND e IN ELEMENTS(p.vote) ORDER BY e.topiaCreateDate DESC";
+ String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE " +
+ "p = :p AND " +
+ "e IN ELEMENTS(p.vote) " +
+ "ORDER BY e.topiaCreateDate DESC";
-
- results = PollenIOUtil.findByPager(getContext(), hql, pager,
- "p", poll);
+ results = PollenPersistenceUtil.findByPager(
+ this, hql, pager, "p", poll);
}
return results;
}
public boolean hasAlreadyVoted(Poll poll, String votingId) throws TopiaException {
- // Test using a count(*) on votes
- String hql = "SELECT COUNT(*) FROM VoteImpl e, PollImpl p WHERE p = :p AND e in elements(p.vote) AND e.pollAccount.votingId = :v";
- Long nb = (Long) getContext().findUnique(hql, "p", poll, "v", votingId);
- return nb == 1;
+ String hql = "SELECT COUNT(*) FROM VoteImpl e, PollImpl p WHERE " +
+ "p = :p AND " +
+ "e in elements(p.vote) AND " +
+ "e.pollAccount.votingId = :v";
+
+ boolean result = PollenPersistenceUtil.exists(
+ this, hql, "p", poll, "v", votingId);
+ return result;
}
- public Vote findByAccountId(String accountId) throws TopiaException {
+ public E findByAccountId(String accountId) throws TopiaException {
String hql = "FROM VoteImpl e WHERE e.pollAccount.accountId = :a";
- Vote result = (Vote) getContext().findUnique(hql, "a", accountId);
+
+ E result = PollenPersistenceUtil.findUnique(this, hql, "a", accountId);
return result;
}
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/AbstractDAOTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/AbstractDAOTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/AbstractDAOTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -87,8 +87,8 @@
testBasedir,
"/" + CONFIGURATION_PATH
);
- if (log.isInfoEnabled()) {
- log.info("Starts db " +
+ if (log.isDebugEnabled()) {
+ log.debug("Starts db " +
((TopiaContextImplementor) rootCtxt).getConfig().get(TopiaContextFactory.CONFIG_URL));
}
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -39,7 +39,7 @@
public class CommentDAOImplTest extends AbstractDAOTest {
@Test
- public void getComments() throws Exception {
+ public void findComments() throws Exception {
TopiaContext tx = beginTransaction();
CommentDAO dao = PollenDAOHelper.getCommentDAO(tx);
@@ -58,7 +58,7 @@
pager.setPageSize(5);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(true);
- actual = dao.getComments(pager, pollId1);
+ actual = dao.findComments(pager, pollId1);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -70,7 +70,7 @@
pager.setPageIndex(2);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(true);
- actual = dao.getComments(pager, pollId1);
+ actual = dao.findComments(pager, pollId1);
Assert.assertNotNull(actual);
Assert.assertEquals(4, actual.size());
for (int i = 0; i < 4; i++) {
@@ -81,7 +81,7 @@
pager.setPageSize(5);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(false);
- actual = dao.getComments(pager, pollId1);
+ actual = dao.findComments(pager, pollId1);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -92,15 +92,14 @@
pager.setPageSize(5);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(false);
- actual = dao.getComments(pager, pollId1 + "-");
+ actual = dao.findComments(pager, pollId1 + "-");
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
@Test
- public void getAllComments() throws Exception {
+ public void findAllComments() throws Exception {
-
TopiaContext tx = beginTransaction();
CommentDAO dao = PollenDAOHelper.getCommentDAO(tx);
PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
@@ -115,11 +114,11 @@
tx.commitTransaction();
List<Comment> actual;
- actual = dao.getAllComments(pollId1);
+ actual = dao.findAllComments(pollId1);
Assert.assertNotNull(actual);
Assert.assertEquals(9, actual.size());
- actual = dao.getAllComments(pollId1 + "-");
+ actual = dao.findAllComments(pollId1 + "-");
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -39,7 +39,7 @@
public class PersonListDAOImplTest extends AbstractDAOTest {
@Test
- public void getAllFavoriteLists() throws Exception {
+ public void findAllFavoriteLists() throws Exception {
TopiaContext tx = beginTransaction();
PersonListDAO dao = PollenDAOHelper.getPersonListDAO(tx);
@@ -57,17 +57,17 @@
tx.commitTransaction();
List<PersonList> actual;
- actual = dao.getFavoriteLists(userAccount1);
+ actual = dao.findAllFavoriteLists(userAccount1);
Assert.assertNotNull(actual);
Assert.assertEquals(9, actual.size());
- actual = dao.getFavoriteLists(userAccount2);
+ actual = dao.findAllFavoriteLists(userAccount2);
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
@Test
- public void getFavoriteLists() throws Exception {
+ public void findFavoriteLists() throws Exception {
TopiaContext tx = beginTransaction();
PersonListDAO dao = PollenDAOHelper.getPersonListDAO(tx);
@@ -92,7 +92,7 @@
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(true);
- actual = dao.getFavoriteLists(userAccount1, pager);
+ actual = dao.findFavoriteLists(userAccount1, pager);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -104,7 +104,7 @@
pager.setPageIndex(2);
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(true);
- actual = dao.getFavoriteLists(userAccount1, pager);
+ actual = dao.findFavoriteLists(userAccount1, pager);
Assert.assertNotNull(actual);
Assert.assertEquals(4, actual.size());
for (int i = 0; i < 4; i++) {
@@ -115,7 +115,7 @@
pager.setPageSize(5);
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(false);
- actual = dao.getFavoriteLists(userAccount1, pager);
+ actual = dao.findFavoriteLists(userAccount1, pager);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -127,7 +127,7 @@
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(false);
- actual = dao.getFavoriteLists(userAccount2, pager);
+ actual = dao.findFavoriteLists(userAccount2, pager);
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollAccountDAOImplTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -42,8 +42,51 @@
private static final Log log =
LogFactory.getLog(PollAccountDAOImplTest.class);
+ String pollId = "pollId";
+
+ String accountId = "accountId";
+
+ String accountId2 = "accountId2";
+
+ String accountId3 = "accountId3";
+
+ String accountEmail = "email";
+
+ String accountEmail2 = "email2";
+
+ String accountEmail3 = "email3";
+
@Test
- public void getRestrictedPollAccount() throws Exception {
+ public void findVoterPollAccountByAccountId() throws Exception {
+ if (log.isWarnEnabled()) {
+ log.warn("Missing PollAccountDAOImpl#findVoterPollAccountByAccountId request test!");
+ }
+ }
+
+ @Test
+ public void findVoterPollAccountByUserAccount() throws Exception {
+ if (log.isWarnEnabled()) {
+ log.warn("Missing PollAccountDAOImpl#findVoterPollAccountByUserAccount request test!");
+ }
+ }
+
+ @Test
+ public void findFavoriteListUsers() throws TopiaException {
+ if (log.isWarnEnabled()) {
+ log.warn("Missing PollAccountDAOImpl#findFavoriteListUsers request test!");
+ }
+ }
+
+ @Test
+ public void isPollAccountExists() throws TopiaException {
+ if (log.isWarnEnabled()) {
+ log.warn("Missing PollAccountDAOImpl#isPollAccountExists request test!");
+ }
+ }
+
+ @Test
+ public void findRestrictedPollAccountByAccountId() throws Exception {
+
TopiaContext tx = beginTransaction();
PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
@@ -51,18 +94,16 @@
VotingListDAO votingListDAO = PollenDAOHelper.getVotingListDAO(tx);
PersonToListDAO personToListDAO = PollenDAOHelper.getPersonToListDAO(tx);
- String pollId = "pollId";
- String accountId = "accountId";
- String accountId2 = "accountId2";
- String accountId3 = "accountId3";
-
PollAccount pollAccount = pollAccountDAO.create(
- PollAccount.PROPERTY_ACCOUNT_ID, accountId);
+ PollAccount.PROPERTY_ACCOUNT_ID, accountId,
+ PollAccount.PROPERTY_EMAIL, accountEmail);
PollAccount pollAccount2 = pollAccountDAO.create(
- PollAccount.PROPERTY_ACCOUNT_ID, accountId2);
+ PollAccount.PROPERTY_ACCOUNT_ID, accountId2,
+ PollAccount.PROPERTY_EMAIL, accountEmail2);
PollAccount pollAccount3 = pollAccountDAO.create(
- PollAccount.PROPERTY_ACCOUNT_ID, accountId3);
+ PollAccount.PROPERTY_ACCOUNT_ID, accountId3,
+ PollAccount.PROPERTY_EMAIL, accountEmail3);
Poll poll = pollDAO.create(Poll.PROPERTY_POLL_ID, pollId);
@@ -90,7 +131,7 @@
pollAccount3.addVotingListPersonToList(personToList3);
PollAccount restrictedPollAccount =
- pollAccountDAO.getRestrictedPollAccountByAccountId(pollId, accountId);
+ pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, accountId);
Assert.assertNotNull(restrictedPollAccount);
Assert.assertEquals(accountId, restrictedPollAccount.getAccountId());
@@ -98,7 +139,7 @@
Assert.assertTrue(restrictedPollAccount.getVotingListPersonToList().contains(personToList));
PollAccount restrictedPollAccount2 =
- pollAccountDAO.getRestrictedPollAccountByAccountId(pollId, accountId2);
+ pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, accountId2);
Assert.assertNotNull(restrictedPollAccount2);
Assert.assertEquals(accountId2, restrictedPollAccount2.getAccountId());
@@ -107,7 +148,7 @@
Assert.assertTrue(restrictedPollAccount2.getVotingListPersonToList().contains(personToList2));
PollAccount restrictedPollAccount3 =
- pollAccountDAO.getRestrictedPollAccountByAccountId(pollId, accountId3);
+ pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, accountId3);
Assert.assertNotNull(restrictedPollAccount3);
Assert.assertEquals(accountId3, restrictedPollAccount3.getAccountId());
@@ -116,36 +157,86 @@
Assert.assertTrue(restrictedPollAccount3.getVotingListPersonToList().contains(personToList3));
PollAccount restrictedPollAccount4 =
- pollAccountDAO.getRestrictedPollAccountByAccountId(pollId, System.nanoTime() + "--");
+ pollAccountDAO.findRestrictedPollAccountByAccountId(pollId, System.nanoTime() + "--");
Assert.assertNull(restrictedPollAccount4);
}
@Test
- public void getFavoriteListUsers() throws TopiaException {
- if (log.isInfoEnabled()) {
- log.info("TODO");
- }
- }
+ public void findRestrictedPollAccountByEmail() throws Exception {
+ TopiaContext tx = beginTransaction();
- @Test
- public void isPollAccountExists() throws TopiaException {
- if (log.isInfoEnabled()) {
- log.info("TODO");
- }
- }
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
+ PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx);
+ VotingListDAO votingListDAO = PollenDAOHelper.getVotingListDAO(tx);
+ PersonToListDAO personToListDAO = PollenDAOHelper.getPersonToListDAO(tx);
- @Test
- public void findByPollVoteUser() throws TopiaException {
- if (log.isInfoEnabled()) {
- log.info("TODO");
- }
+ PollAccount pollAccount = pollAccountDAO.create(
+ PollAccount.PROPERTY_ACCOUNT_ID, accountId,
+ PollAccount.PROPERTY_EMAIL, accountEmail);
+
+ PollAccount pollAccount2 = pollAccountDAO.create(
+ PollAccount.PROPERTY_ACCOUNT_ID, accountId2,
+ PollAccount.PROPERTY_EMAIL, accountEmail2);
+ PollAccount pollAccount3 = pollAccountDAO.create(
+ PollAccount.PROPERTY_ACCOUNT_ID, accountId3,
+ PollAccount.PROPERTY_EMAIL, accountEmail3);
+
+ Poll poll = pollDAO.create(Poll.PROPERTY_POLL_ID, pollId);
+
+ VotingList votingList = votingListDAO.create();
+ poll.addVotingList(votingList);
+ VotingList votingList2 = votingListDAO.create();
+ poll.addVotingList(votingList2);
+
+ PersonToList personToList = personToListDAO.create(
+ PersonToList.PROPERTY_POLL_ACCOUNT, pollAccount,
+ PersonToList.PROPERTY_VOTING_LIST, votingList
+ );
+
+ PersonToList personToList2 = personToListDAO.create(
+ PersonToList.PROPERTY_POLL_ACCOUNT, pollAccount2,
+ PersonToList.PROPERTY_VOTING_LIST, votingList
+ );
+ PersonToList personToList3 = personToListDAO.create(
+ PersonToList.PROPERTY_POLL_ACCOUNT, pollAccount3,
+ PersonToList.PROPERTY_VOTING_LIST, votingList2
+ );
+
+ pollAccount.addVotingListPersonToList(personToList);
+ pollAccount2.addVotingListPersonToList(personToList2);
+ pollAccount3.addVotingListPersonToList(personToList3);
+
+ PollAccount restrictedPollAccount =
+ pollAccountDAO.findRestrictedPollAccountByEmail(pollId, accountEmail);
+
+ Assert.assertNotNull(restrictedPollAccount);
+ Assert.assertEquals(accountId, restrictedPollAccount.getAccountId());
+ Assert.assertNotNull(restrictedPollAccount.getVotingListPersonToList());
+ Assert.assertTrue(restrictedPollAccount.getVotingListPersonToList().contains(personToList));
+
+ PollAccount restrictedPollAccount2 =
+ pollAccountDAO.findRestrictedPollAccountByEmail(pollId, accountEmail2);
+
+ Assert.assertNotNull(restrictedPollAccount2);
+ Assert.assertEquals(accountId2, restrictedPollAccount2.getAccountId());
+ Assert.assertNotNull(restrictedPollAccount2.getVotingListPersonToList());
+ Assert.assertFalse(restrictedPollAccount2.getVotingListPersonToList().contains(personToList));
+ Assert.assertTrue(restrictedPollAccount2.getVotingListPersonToList().contains(personToList2));
+
+ PollAccount restrictedPollAccount3 =
+ pollAccountDAO.findRestrictedPollAccountByEmail(pollId, accountEmail3);
+
+ Assert.assertNotNull(restrictedPollAccount3);
+ Assert.assertEquals(accountId3, restrictedPollAccount3.getAccountId());
+ Assert.assertNotNull(restrictedPollAccount3.getVotingListPersonToList());
+ Assert.assertFalse(restrictedPollAccount3.getVotingListPersonToList().contains(personToList));
+ Assert.assertTrue(restrictedPollAccount3.getVotingListPersonToList().contains(personToList3));
+
+ PollAccount restrictedPollAccount4 =
+ pollAccountDAO.findRestrictedPollAccountByEmail(pollId, System.nanoTime() + "--");
+
+ Assert.assertNull(restrictedPollAccount4);
}
- @Test
- public void existsByPollVoteAccountId() throws TopiaException {
- if (log.isInfoEnabled()) {
- log.info("TODO");
- }
- }
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -47,8 +47,16 @@
private static final Log log = LogFactory.getLog(PollDAOImplTest.class);
@Test
- public void getPolls() throws Exception {
+ public void findInvitedPolls() throws Exception {
+ if (log.isWarnEnabled()) {
+ log.warn("Missing PollDAOImpl#findInvitedPolls request test!");
+ }
+ }
+
+ @Test
+ public void findPolls() throws Exception {
+
TopiaContext tx = beginTransaction();
PollDAO dao = PollenDAOHelper.getPollDAO(tx);
@@ -108,7 +116,7 @@
}
@Test
- public void getCreatedPolls() throws Exception {
+ public void findCreatedPolls() throws Exception {
TopiaContext tx = beginTransaction();
PollDAO dao = PollenDAOHelper.getPollDAO(tx);
@@ -134,7 +142,7 @@
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(true);
- actual = dao.getCreatedPolls(pager, userAccount1);
+ actual = dao.findCreatedPolls(pager, userAccount1);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -146,7 +154,7 @@
pager.setPageIndex(2);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(true);
- actual = dao.getCreatedPolls(pager, userAccount1);
+ actual = dao.findCreatedPolls(pager, userAccount1);
Assert.assertNotNull(actual);
Assert.assertEquals(4, actual.size());
for (int i = 0; i < 4; i++) {
@@ -157,7 +165,7 @@
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(false);
- actual = dao.getCreatedPolls(pager, userAccount1);
+ actual = dao.findCreatedPolls(pager, userAccount1);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -168,27 +176,17 @@
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(false);
- actual = dao.getCreatedPolls(pager, userAccount2);
+ actual = dao.findCreatedPolls(pager, userAccount2);
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
@Test
- public void getInvitedPolls() throws Exception {
+ public void findParticipatedPolls() throws Exception {
TopiaContext tx = beginTransaction();
PollDAO dao = PollenDAOHelper.getPollDAO(tx);
- if (log.isInfoEnabled()) {
- log.info("TODO");
- }
- }
-
- @Test
- public void getParticipatedPolls() throws Exception {
-
- TopiaContext tx = beginTransaction();
- PollDAO dao = PollenDAOHelper.getPollDAO(tx);
VoteDAO voteDao = PollenDAOHelper.getVoteDAO(tx);
PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx);
UserAccountDAO userAccountDAO = PollenDAOHelper.getUserAccountDAO(tx);
@@ -216,7 +214,7 @@
pager = TopiaFilterPagerUtil.newFilterPagerBean();
pager.setPageSize(5);
- actual = dao.getParticipatedPolls(pager, userAccount1);
+ actual = dao.findParticipatedPolls(pager, userAccount1);
Assert.assertNotNull(actual);
Assert.assertEquals(2, actual.size());
Assert.assertEquals(poll0, actual.get(0).getLeft());
@@ -224,13 +222,13 @@
Assert.assertEquals(poll1, actual.get(1).getLeft());
Assert.assertEquals(pollAccount1, actual.get(1).getRight());
- actual = dao.getParticipatedPolls(pager, userAccount2);
+ actual = dao.findParticipatedPolls(pager, userAccount2);
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
@Test
- public void getRunningPolls() throws Exception {
+ public void findRunningPolls() throws Exception {
TopiaContext tx = beginTransaction();
PollDAO dao = PollenDAOHelper.getPollDAO(tx);
@@ -259,7 +257,7 @@
List<Poll> actual;
- actual = dao.getRunningPolls(now);
+ actual = dao.findRunningPolls(now);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
Assert.assertEquals(poll0, actual.get(0));
@@ -269,13 +267,13 @@
Assert.assertEquals(poll5, actual.get(4));
- actual = dao.getRunningPolls(lastYearNow);
+ actual = dao.findRunningPolls(lastYearNow);
Assert.assertNotNull(actual);
Assert.assertEquals(2, actual.size());
Assert.assertEquals(poll0, actual.get(0));
Assert.assertEquals(poll5, actual.get(1));
- actual = dao.getRunningPolls(nextMonthNow);
+ actual = dao.findRunningPolls(nextMonthNow);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
Assert.assertEquals(poll0, actual.get(0));
@@ -284,7 +282,7 @@
Assert.assertEquals(poll3, actual.get(3));
Assert.assertEquals(poll5, actual.get(4));
- actual = dao.getRunningPolls(nextYearNow);
+ actual = dao.findRunningPolls(nextYearNow);
Assert.assertNotNull(actual);
Assert.assertEquals(3, actual.size());
Assert.assertEquals(poll0, actual.get(0));
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -45,7 +45,8 @@
UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(tx);
for (int i = 0; i < 20; i++) {
- dao.create(UserAccount.PROPERTY_LOGIN, "login" + i, UserAccount.PROPERTY_EMAIL, "email" + i);
+ dao.create(UserAccount.PROPERTY_LOGIN, "login" + i,
+ UserAccount.PROPERTY_EMAIL, "email" + i);
}
tx.commitTransaction();
@@ -78,14 +79,15 @@
}
@Test
- public void getUsers() throws Exception {
+ public void findUsers() throws Exception {
TopiaContext tx = beginTransaction();
UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(tx);
for (int i = 0; i < 9; i++) {
- dao.create(UserAccount.PROPERTY_LOGIN, "login" + i, UserAccount.PROPERTY_EMAIL, "email" + i);
+ dao.create(UserAccount.PROPERTY_LOGIN, "login" + i,
+ UserAccount.PROPERTY_EMAIL, "email" + i);
}
tx.commitTransaction();
@@ -97,7 +99,7 @@
pager.setPageSize(5);
pager.setSortColumn(UserAccount.PROPERTY_LOGIN);
pager.setSortAscendant(true);
- actual = dao.getUsers(pager);
+ actual = dao.findUsers(pager);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
@@ -109,7 +111,7 @@
pager.setPageIndex(2);
pager.setSortColumn(UserAccount.PROPERTY_LOGIN);
pager.setSortAscendant(true);
- actual = dao.getUsers(pager);
+ actual = dao.findUsers(pager);
Assert.assertNotNull(actual);
Assert.assertEquals(4, actual.size());
for (int i = 0; i < 4; i++) {
@@ -120,13 +122,11 @@
pager.setPageSize(5);
pager.setSortColumn(UserAccount.PROPERTY_LOGIN);
pager.setSortAscendant(false);
- actual = dao.getUsers(pager);
+ actual = dao.findUsers(pager);
Assert.assertNotNull(actual);
Assert.assertEquals(5, actual.size());
for (int i = 0; i < 5; i++) {
Assert.assertEquals("login" + (8 - i), actual.get(i).getLogin());
}
-
-
}
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -40,7 +40,7 @@
public class VoteDAOImplTest extends AbstractDAOTest {
@Test
- public void getAllVotes() throws Exception {
+ public void findAllVotes() throws Exception {
TopiaContext tx = beginTransaction();
@@ -65,7 +65,7 @@
List<Vote> actual;
- actual = voteDAO.getAllVotes(poll1);
+ actual = voteDAO.findAllVotes(poll1);
Assert.assertNotNull(actual);
Assert.assertEquals(2, actual.size());
@@ -73,16 +73,15 @@
Assert.assertEquals(vote1, actual.get(1));
Assert.assertFalse(actual.contains(vote3));
- actual = voteDAO.getAllVotes(poll2);
+ actual = voteDAO.findAllVotes(poll2);
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
}
@Test
- public void getVotesByPoll() throws Exception {
+ public void findAllVotesByPoll() throws Exception {
-
TopiaContext tx = beginTransaction();
VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(tx);
@@ -108,7 +107,7 @@
TopiaFilterPagerUtil.FilterPagerBean pager =
TopiaFilterPagerUtil.newFilterPagerBean();
pager.setPageSize(10);
- actual = voteDAO.getVotesByPoll(poll1, pager);
+ actual = voteDAO.findAllVotesByPoll(poll1, pager);
Assert.assertNotNull(actual);
Assert.assertEquals(2, actual.size());
@@ -118,7 +117,7 @@
pager = TopiaFilterPagerUtil.newFilterPagerBean();
pager.setPageSize(10);
- actual = voteDAO.getVotesByPoll(poll2, pager);
+ actual = voteDAO.findAllVotesByPoll(poll2, pager);
Assert.assertNotNull(actual);
Assert.assertTrue(actual.isEmpty());
@@ -127,7 +126,6 @@
@Test
public void hasAlreadyVoted() throws Exception {
-
TopiaContext tx = beginTransaction();
VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(tx);
@@ -207,7 +205,5 @@
actual = voteDAO.findByAccountId(accountId2);
Assert.assertNotNull(actual);
Assert.assertEquals(vote2, actual);
-
-
}
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -79,7 +79,7 @@
try {
PersonListDAO dao = getDAO(PersonList.class);
- List<PersonList> result = dao.getFavoriteLists(user, pager);
+ List<PersonList> result = dao.findFavoriteLists(user, pager);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
@@ -92,7 +92,7 @@
try {
PersonListDAO dao = getDAO(PersonList.class);
- List<PersonList> result = dao.getFavoriteLists(user);
+ List<PersonList> result = dao.findAllFavoriteLists(user);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
@@ -136,7 +136,7 @@
try {
PollAccountDAO dao = getDAO(PollAccount.class);
- List<PollAccount> result = dao.getFavoriteListUsers(favoriteList, pager);
+ List<PollAccount> result = dao.findFavoriteListUsers(favoriteList, pager);
return result;
} catch (TopiaException e) {
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -153,7 +153,7 @@
try {
CommentDAO dao = getDAO(Comment.class);
- List<Comment> result = dao.getComments(pager, pollId);
+ List<Comment> result = dao.findComments(pager, pollId);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not obtain comments", e);
@@ -166,7 +166,7 @@
try {
CommentDAO dao = getDAO(Comment.class);
- List<Comment> result = dao.getAllComments(pollId);
+ List<Comment> result = dao.findAllComments(pollId);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not obtain comments", e);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -336,7 +336,7 @@
Preconditions.checkNotNull(user);
try {
PollDAO dao = getDAO(Poll.class);
- List<Poll> result = dao.getCreatedPolls(pager, user);
+ List<Poll> result = dao.findCreatedPolls(pager, user);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not obtain created polls", e);
@@ -358,7 +358,7 @@
try {
PollDAO pollDao = getDAO(Poll.class);
List<Pair<Poll, PollAccount>> result =
- pollDao.getInvitedPolls(pager, userToUse);
+ pollDao.findInvitedPolls(pager, userToUse);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not obtain invited polls", e);
@@ -381,7 +381,7 @@
try {
PollDAO pollDao = getDAO(Poll.class);
List<Pair<Poll, PollAccount>> result =
- pollDao.getParticipatedPolls(pager, userToUse);
+ pollDao.findParticipatedPolls(pager, userToUse);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException(
@@ -393,7 +393,7 @@
try {
PollDAO dao = getDAO(Poll.class);
- List<Poll> results = dao.getRunningPolls(currentTime);
+ List<Poll> results = dao.findRunningPolls(currentTime);
return results;
} catch (TopiaException e) {
throw new PollenTechnicalException(
@@ -460,7 +460,7 @@
try {
pollAccountLoaded =
- dao.getVoterPollAccountByAccountId(poll.getPollId(), accountId);
+ dao.findVoterPollAccountByAccountId(poll.getPollId(), accountId);
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
@@ -476,7 +476,7 @@
// try to find pollAccount from the list of voters
try {
pollAccountLoaded =
- dao.getVoterPollAccountByUserAccount(
+ dao.findVoterPollAccountByUserAccount(
poll.getPollId(), userAccount);
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
@@ -487,7 +487,7 @@
try {
pollAccountLoaded =
- dao.getRestrictedPollAccountByEmail(
+ dao.findRestrictedPollAccountByEmail(
poll.getPollId(), userAccount.getEmail());
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -423,7 +423,7 @@
private boolean isVoterAccountId(PollAccountDAO dao, PollUri uri) {
try {
- PollAccount pollAccount = dao.getVoterPollAccountByAccountId(
+ PollAccount pollAccount = dao.findVoterPollAccountByAccountId(
uri.getPollId(), uri.getAccountId());
return pollAccount != null;
@@ -438,7 +438,7 @@
UserAccount userAccount) {
try {
- PollAccount pollAccount = dao.getVoterPollAccountByUserAccount(
+ PollAccount pollAccount = dao.findVoterPollAccountByUserAccount(
pollId, userAccount);
return pollAccount != null;
@@ -453,8 +453,8 @@
try {
PollAccount result =
- dao.getRestrictedPollAccountByAccountId(uri.getPollId(),
- uri.getAccountId());
+ dao.findRestrictedPollAccountByAccountId(uri.getPollId(),
+ uri.getAccountId());
return result != null;
@@ -471,7 +471,7 @@
try {
PollAccount result =
- dao.getRestrictedPollAccountByEmail(pollId, userAccount.getEmail());
+ dao.findRestrictedPollAccountByEmail(pollId, userAccount.getEmail());
return result != null;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -266,7 +266,7 @@
try {
UserAccountDAO dao = getDAO(UserAccount.class);
- List<UserAccount> result = dao.getUsers(pager);
+ List<UserAccount> result = dao.findUsers(pager);
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-08-12 14:06:32 UTC (rev 3598)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-08-12 14:07:52 UTC (rev 3599)
@@ -356,7 +356,7 @@
public List<Vote> getAllVotes(Poll poll) {
try {
VoteDAO dao = getDAO(Vote.class);
- List<Vote> results = dao.getAllVotes(poll);
+ List<Vote> results = dao.findAllVotes(poll);
return results;
} catch (TopiaException e) {
@@ -368,7 +368,7 @@
TopiaFilterPagerUtil.FilterPagerBean pager) {
try {
VoteDAO dao = getDAO(Vote.class);
- List<Vote> results = dao.getVotesByPoll(poll, pager);
+ List<Vote> results = dao.findAllVotesByPoll(poll, pager);
return results;
} catch (TopiaException e) {
1
0
r3598 - trunk/pollen-services/src/main/java/org/chorem/pollen
by tchemit@users.chorem.org 12 Aug '12
by tchemit@users.chorem.org 12 Aug '12
12 Aug '12
Author: tchemit
Date: 2012-08-12 16:06:32 +0200 (Sun, 12 Aug 2012)
New Revision: 3598
Url: http://chorem.org/repositories/revision/pollen/3598
Log:
add missing license header + svn properties
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java 2012-08-12 14:02:01 UTC (rev 3597)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java 2012-08-12 14:06:32 UTC (rev 3598)
@@ -1,4 +1,26 @@
package org.chorem.pollen;
+/*
+ * #%L
+ * Pollen :: Services
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
import com.google.common.base.Preconditions;
import org.apache.commons.collections.CollectionUtils;
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/PollenUserSecurityContext.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
1
0
r3597 - in trunk: pollen-persistence/src/test/resources pollen-services/src/test/resources pollen-ui-struts2/src/test/resources
by tchemit@users.chorem.org 12 Aug '12
by tchemit@users.chorem.org 12 Aug '12
12 Aug '12
Author: tchemit
Date: 2012-08-12 16:02:01 +0200 (Sun, 12 Aug 2012)
New Revision: 3597
Url: http://chorem.org/repositories/revision/pollen/3597
Log:
improve log for tests
Modified:
trunk/pollen-persistence/src/test/resources/log4j.properties
trunk/pollen-services/src/test/resources/log4j.properties
trunk/pollen-ui-struts2/src/test/resources/log4j.properties
Modified: trunk/pollen-persistence/src/test/resources/log4j.properties
===================================================================
--- trunk/pollen-persistence/src/test/resources/log4j.properties 2012-08-12 11:57:21 UTC (rev 3596)
+++ trunk/pollen-persistence/src/test/resources/log4j.properties 2012-08-12 14:02:01 UTC (rev 3597)
@@ -27,6 +27,6 @@
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%p] %c %m%n
+log4j.appender.A1.layout.ConversionPattern=[%p] %c %m%n
log4j.logger.org.chorem.pollen=INFO
Modified: trunk/pollen-services/src/test/resources/log4j.properties
===================================================================
--- trunk/pollen-services/src/test/resources/log4j.properties 2012-08-12 11:57:21 UTC (rev 3596)
+++ trunk/pollen-services/src/test/resources/log4j.properties 2012-08-12 14:02:01 UTC (rev 3597)
@@ -27,6 +27,6 @@
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%p] %c %m%n
+log4j.appender.A1.layout.ConversionPattern=[%p] %c %m%n
log4j.logger.org.chorem.pollen=INFO
Modified: trunk/pollen-ui-struts2/src/test/resources/log4j.properties
===================================================================
--- trunk/pollen-ui-struts2/src/test/resources/log4j.properties 2012-08-12 11:57:21 UTC (rev 3596)
+++ trunk/pollen-ui-struts2/src/test/resources/log4j.properties 2012-08-12 14:02:01 UTC (rev 3597)
@@ -24,7 +24,7 @@
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
-log4j.appender.console.layout.ConversionPattern=%d [%p] %c %m%n
+log4j.appender.console.layout.ConversionPattern=[%p] %c %m%n
log4j.logger.org.chorem.pollen=INFO
log4j.logger.org.chorem.pollen.ui.PollenShiroIsAdministratorFilter=DEBUG
1
0