Author: Alex.Kolonitsky
Date: 2009-04-01 09:53:35 -0400 (Wed, 01 Apr 2009)
New Revision: 13342
Added:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ActionTools.java
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java
Log:
Add recently date
Added:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ActionTools.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ActionTools.java
(rev 0)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ActionTools.java 2009-04-01
13:53:35 UTC (rev 13342)
@@ -0,0 +1,18 @@
+package org.richfaces.realworld.service;
+
+import java.util.Date;
+import java.util.Calendar;
+
+/**
+ * @user: akolonitsky
+ * Date: Apr 1, 2009
+ */
+public class ActionTools {
+ private static final int RECENTLY_DAYS = 15;
+
+ public static Date getRecentlyDate() {
+ final Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_YEAR, -RECENTLY_DAYS);
+ return calendar.getTime();
+ }
+}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java 2009-04-01
13:48:25 UTC (rev 13341)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java 2009-04-01
13:53:35 UTC (rev 13342)
@@ -26,9 +26,11 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
+import javax.persistence.Query;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
@@ -43,55 +45,50 @@
@AutoCreate
public class ShelfAction implements IShelfAction {
- @In(value="entityManager")
- EntityManager em;
- @In FlushStrategy flushStrategy;
- @In @Out
+ @In(value = "entityManager")
+ private EntityManager em;
+
+ @In
+ private FlushStrategy flushStrategy;
+
+ @In
+ @Out
private User user;
public void addShelf(Shelf shelf) {
em.persist(shelf);
user.addShelf(shelf);
- if(flushStrategy.isDatabaseStoreStrategy()){
+ if (flushStrategy.isDatabaseStoreStrategy()) {
em.flush();
}
}
-
- public void deleteShelf(Shelf shelf){
+
+ public void deleteShelf(Shelf shelf) {
user.removeShelf(shelf);
em.remove(shelf);
- if(flushStrategy.isDatabaseStoreStrategy()){
+ if (flushStrategy.isDatabaseStoreStrategy()) {
em.flush();
}
}
-
- public void editShelf(Shelf shelf){
- if(flushStrategy.isDatabaseStoreStrategy()){
+
+ public void editShelf(Shelf shelf) {
+ if (flushStrategy.isDatabaseStoreStrategy()) {
em.flush();
}
}
-
+
public List<Shelf> getShelfs(User user) {
- //TODO nick - preserve shelves ordering? Maybe use TreeSet with Comparator?
- Set<Shelf> sh = new HashSet<Shelf>();
- List<Shelf> shelfs = em.createQuery("from Shelf s where
s.shared=true")
- .getResultList();
- sh.addAll(shelfs);
- sh.addAll(user.getShelfs());
- shelfs.clear();
- shelfs.addAll(sh);
- return shelfs;
+ final Query query = em.createQuery(
+ "select distinct s from Shelf s where s.shared = true or s.owner = :user order by
s.name");
+ query.setParameter("user", user.getId() == null ? null : user);
+
+ return query.getResultList();
}
- public List<Image> getUnvisitedImages(Shelf shelf){
+ public List<Image> getUnvisitedImages(Shelf shelf) {
//TODO nick - use data from user
- return (List<Image>)em.createQuery("from Image i where i.album.shelf=:shelf
and i.uploaded > :date").setParameter("shelf",
shelf).setParameter("date", getDate()).getResultList();
+ return (List<Image>) em.createQuery("from Image i where i.album.shelf =
:shelf and i.uploaded > :date")
+ .setParameter("shelf", shelf)
+ .setParameter("date", ActionTools.getRecentlyDate()).getResultList();
}
-
- private Date getDate() {
- //TODO nick - copy-pasted from AlbumAction, see TODOs there
- Calendar c = Calendar.getInstance();
- c.add(Calendar.DAY_OF_YEAR, -15);
- return c.getTime();
- }
-}
+}
\ No newline at end of file
Show replies by date