[richfaces-svn-commits] JBoss Rich Faces SVN: r13408 - in trunk/test-applications/realworld2: ear/src/main/application and 12 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Apr 7 11:51:38 EDT 2009


Author: amarkhel
Date: 2009-04-07 11:51:37 -0400 (Tue, 07 Apr 2009)
New Revision: 13408

Added:
   trunk/test-applications/realworld2/ear/src/main/application/jboss-app.xml
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/SessionListener.java
   trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/Upload/default/
   trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/Upload/default/noimage.jpg
   trunk/test-applications/realworld2/web/src/main/webapp/includes/index/footer.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/includes/index/header.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/includes/index/status.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/includes/index/workArea.xhtml
Removed:
   trunk/test-applications/realworld2/ear/src/main/jboss-app.xml
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/FlushStrategy.java
   trunk/test-applications/realworld2/ejb/src/main/resources/realworld.properties
Modified:
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java
   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/AlbumAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IShelfAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
   trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java
   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/UserAction.java
   trunk/test-applications/realworld2/ejb/src/main/resources/import.sql
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Controller.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/SlideshowManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/TreeManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ISearchOption.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ImageSearchHelper.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByAlbum.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByShelf.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByTag.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByUser.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/startup/CopyImageStuff.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ConfirmationPopupHelper.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageSizeHelper.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ErrorHandlerBean.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileUtils.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java
   trunk/test-applications/realworld2/web/src/main/webapp/includes/index/menu.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/includes/index/tree.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/layout/template.xhtml
Log:
Refactoring

Copied: trunk/test-applications/realworld2/ear/src/main/application/jboss-app.xml (from rev 13138, trunk/test-applications/realworld2/ear/src/main/jboss-app.xml)
===================================================================
--- trunk/test-applications/realworld2/ear/src/main/application/jboss-app.xml	                        (rev 0)
+++ trunk/test-applications/realworld2/ear/src/main/application/jboss-app.xml	2009-04-07 15:51:37 UTC (rev 13408)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!DOCTYPE jboss-app
+    PUBLIC "-//JBoss//DTD J2EE Application 4.2//EN"
+    "http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd">
+
+<jboss-app>
+   <loader-repository> 
+      seam.jboss.org:loader=realworld-ear-1.0-SNAPSHOT.ear
+   </loader-repository> 
+</jboss-app> 
\ No newline at end of file

Deleted: trunk/test-applications/realworld2/ear/src/main/jboss-app.xml
===================================================================
--- trunk/test-applications/realworld2/ear/src/main/jboss-app.xml	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ear/src/main/jboss-app.xml	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-  <!DOCTYPE jboss-app
-    PUBLIC "-//JBoss//DTD J2EE Application 4.2//EN"
-    "http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd">
-
-<jboss-app>
-   <loader-repository> 
-      seam.jboss.org:loader=realworld-ear-1.0-SNAPSHOT.ear
-   </loader-repository> 
-</jboss-app> 
\ No newline at end of file

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -49,7 +49,7 @@
 import org.jboss.seam.annotations.Scope;
 
 /**
- * Class for representing Album Entity EJB3 Entity Bean
+ * Class for representing Album Entity. EJB3 Entity Bean
  *
  * @author Andrey Markhel
  */
@@ -97,11 +97,21 @@
 
     // ********************** Accessor Methods ********************** //
 
-
+    /**
+     * Getter for property shelf
+     *
+     * @return Shelf object, that contains this album
+     */
     public Shelf getShelf() {
         return shelf;
     }
 
+    /**
+     * Setter for property shelf
+     *
+     * @param parent -
+     *             Shelf object
+     */
     public void setShelf(Shelf parent) {
         this.shelf = parent;
     }
@@ -128,7 +138,7 @@
      * Setter for property name
      *
      * @param name -
-     *             name of album
+     *             new name of album
      */
     public void setName(String name) {
         this.name = name;
@@ -147,12 +157,56 @@
      * Setter for property description
      *
      * @param description -
-     *                    description of album
+     *                    new description of album
      */
     public void setDescription(String description) {
         this.description = description;
     }
 
+    /**
+     * Getter for property images
+     *
+     * @return List if images, belongs to this album
+     */
+    public List<Image> getImages() {
+        return images;
+    }
+    
+    /**
+     * @return the date of creation
+     */
+    public Date getCreated() {
+        return created;
+    }
+
+    /**
+     * @param created - Date of creation of this album
+     */
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+    
+    /**
+     * @return List of unvisited images
+     */
+    public List<Image> getUnvisitedImages() {
+        return unvisitedImages;
+    }
+
+    /**
+     * @param unvisitedImages - List of unvisited images
+     */
+    public void setUnvisitedImages(List<Image> unvisitedImages) {
+        this.unvisitedImages = unvisitedImages;
+    }
+    
+    /**
+     * @param coveringImage - Image for covering album
+     */
+    public void setCoveringImage(Image coveringImage) {
+        this.coveringImage = coveringImage;
+    }
+    
     // ********************** Business Methods ********************** //
 
     /**
@@ -165,11 +219,13 @@
         if (image == null) {
             throw new IllegalArgumentException("Null image!");
         }if(this.getImages().contains(image)){
+        	//If album contain this image already
         	return;
         }
         if (image.getAlbum() != null && !this.equals(image.getAlbum())) {
+        	//Remove from previous album
         	image.getAlbum().removeImage(image);
-        }if(!image.isVisited()){
+        }if(!image.isVisited()){//Check, if user already seen this image
         	this.getShelf().getUnvisitedImages().add(image);
             this.getUnvisitedImages().add(image);
         }
@@ -188,6 +244,7 @@
             throw new IllegalArgumentException("Null image");
         }
         if(image.getAlbum().equals(this)){
+        	//Remove from unvisited images if needed
         	if(image.getAlbum().getUnvisitedImages().contains(image)){
         		image.getAlbum().getUnvisitedImages().remove(image);
         	}
@@ -210,14 +267,21 @@
         return this.getImages() != null ? this.getImages().size() : 0;
     }
 
+    /**
+     * Getter for property owner
+     *
+     * @return User object, owner of this album
+     */
     public User getOwner() {
         return getShelf()!=null ? getShelf().getOwner(): null;
     }
 
-    public List<Image> getImages() {
-        return images;
-    }
-
+    /**
+     * This method determine index of specified image in collection of images, belongs to this album.
+     * Used in slideshow etc...
+     *
+     * @return index of specified image
+     */
     public int getIndex(Image image) {
 		if(this.images.size() > 0){
 			return this.images.indexOf(image);
@@ -225,53 +289,52 @@
 		return -1;
     }
 
+    /**
+     * This method determine covering image of this album
+     *
+     * @return covering image
+     */
     public Image getCoveringImage() {
         if (coveringImage != null) {
             return coveringImage;
         }
-        if (images != null && images.size() > 0) {
-			//TODO nick - i suggest we use random images
+        if (!isEmpty()) {
+        	//If no image defined as covering
             coveringImage = images.get(0);
             return images.get(0);
         } else {
+        	//Album haven't images
             return null;
         }
     }
 
+    /**
+     * This method determine is album empty or not
+     *
+     */
     public boolean isEmpty() {
         return images == null || images.size() == 0;
     }
 
     /**
-     * @return the created
+     * @return count of unvisited images
      */
-    public Date getCreated() {
-        return created;
-    }
-
-    /**
-     * @param created the created to set
-     */
-    public void setCreated(Date created) {
-        this.created = created;
-    }
-
     public Long getCountUnvisitedImages() {
         return new Long(unvisitedImages.size());
     }
 
-
-    public List<Image> getUnvisitedImages() {
-        return unvisitedImages;
-    }
-
-    public void setUnvisitedImages(List<Image> unvisitedImages) {
-        this.unvisitedImages = unvisitedImages;
-    }
-
+    /** This method marks specified image as visited, if isSetVisited parameter is true. 
+     * If isSetVisited parameter is false(in case of copy images from one album to another),
+     * image not marked as visited.
+     * Undependently of isSetVisited parameter, removes image from collection of unvisitedImages.
+     * 
+     * @param image - image to mark visited
+     * @param isSetVisited - List of unvisited images
+     */
     public void visitImage(Image image, boolean isSetVisited) {
         if (unvisitedImages.contains(image)) {
             unvisitedImages.remove(image);
+            //Clean unvisitedImages of parent shelf
             if(this.getShelf().getUnvisitedImages().contains(image)){
             	this.getShelf().getUnvisitedImages().remove(image);
             }
@@ -279,10 +342,6 @@
         image.setVisited(isSetVisited);
     }
 
-    public void setCoveringImage(Image coveringImage) {
-        this.coveringImage = coveringImage;
-    }
-
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -40,6 +40,11 @@
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
+/**
+ * Class for representing Comment Entity. EJB3 Entity Bean
+ *
+ * @author Andrey Markhel
+ */
 
 @Entity
 @Name("comment")
@@ -72,6 +77,7 @@
     @Length(min = 2)
     private String message;
 
+    //---------------------------------------Getters, Setters
     public Long getId() {
         return id;
     }
@@ -108,7 +114,6 @@
         this.image = image;
     }
 
-
     public boolean equals(Object o) {
         if (this == o) return true;
         if (o == null || getClass() != o.getClass()) return false;

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -54,14 +54,33 @@
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Role;
 import org.jboss.seam.annotations.Scope;
 import org.richfaces.realworld.service.ActionTools;
 
 @NamedQueries({
     @NamedQuery(
-            name = "image-camera",
-            query = "select distinct i.cameraModel from Image i"
+            name = "album-unvisited",
+            query = "from Image i where i.album=:album and i.uploaded > :date"
+    ),
+    @NamedQuery(
+            name = "shelf-unvisited",
+            query = "from Image i where i.album.shelf = :shelf and i.uploaded > :date"
+    ),
+    @NamedQuery(
+            name = "tag-byName",
+            query = "from MetaTag m where m.tag =:tag"
+    ), 
+    @NamedQuery(
+            name = "tag-popular",
+            query = "select new MetaTag(m.id, m.tag) from MetaTag m join m.images img group by m.id, m.tag order by count(img) desc"
+    ), 
+    @NamedQuery(
+            name = "user-shelves",
+            query = "select distinct s from Shelf s where s.shared = true or s.owner = :user order by s.name"
+    ), 
+    @NamedQuery(
+            name = "tag-suggest",
+            query = "select m from MetaTag m where lower(m.tag) like :tag"
     )
         }
 )
@@ -91,6 +110,7 @@
     @NotEmpty
     @Length(min = 3)
     private String name;
+    
     @Transient
     //TODO nick - remove this
     private boolean covering;
@@ -124,7 +144,6 @@
 
     private int height;
 
-    //TODO nick - should be changed to int
     private double size;
 
     private int width;
@@ -200,126 +219,288 @@
         this.description = description;
     }
 
+    /**
+     * Getter for property path.
+     * Represent file-system structure, relative at uploadRoot dir(determined at startup, by default is system temp dir)
+     * Usually is user.GetLogin() + SLASH + image.getAlbum().getId() + SLASH + fileName,
+     * for example "amarkhel/15/coolPicture.jpg"
+     *
+     * @return relative path of image
+     */
     public String getPath() {
         return path;
     }
 
+    /**
+     * Setter for property path
+     *
+     * @param path - relative path to image
+     */
     public void setPath(String path) {
         this.path = path;
     }
 
+    /**
+     * Getter for property created
+     *
+     * @return date of creation of this image
+     */
     public Date getCreated() {
         return created;
     }
 
+    /**
+     * Setter for property created
+     *
+     * @param created - date of creation
+     */
     public void setCreated(Date created) {
         this.created = created;
     }
 
+    /**
+     * Getter for property album
+     *
+     * @return containing album
+     */
     public Album getAlbum() {
         return album;
     }
 
+    /**
+     * Setter for property album
+     *
+     * @param album - album, that will contain this image
+     */
     public void setAlbum(Album album) {
         this.album = album;
     }
 
-    //---------------------------Business methods
-
-    public void addComment(Comment comment) {
-        if (comment == null) {
-            throw new IllegalArgumentException("Null comment!");
-        }
-        if (comment.getImage() != null && !this.equals(comment.getImage())) {
-            comment.getImage().getComments().remove(comment);
-        }
-        comment.setImage(this);
-        comments.add(comment);
-    }
-
-    public void removeComment(Comment comment) {
-        if (comment == null) {
-            throw new IllegalArgumentException("Null comment");
-        }
-        if(comment.getImage().equals(this)){
-        	comment.setImage(null);
-            comments.remove(comment);
-        }else{
-        	throw new IllegalArgumentException("Comment not belongs to this image");
-        }
-    }
-
+    /**
+     * Getter for property comments
+     *
+     * @return collection of comments, belongs to that image
+     */
     public List<Comment> getComments() {
         return comments;
     }
 
+    /**
+     * Getter for property imageTags
+     *
+     * @return collection of MetaTags, associated to that image
+     */
     public List<MetaTag> getImageTags() {
         return imageTags;
     }
 
-    public void setImageTags(List<MetaTag> imageTags) {
-        this.imageTags = imageTags;
-    }
-
-    public String getMeta() {
-        final StringBuilder s = new StringBuilder();
-        for (MetaTag tag : this.imageTags) {
-            s.append(tag.getTag()).append(", ");
-        }
-		if (s.length() >= 2) {
-			s.delete(s.length() - 2, s.length());
-		}
-		return s.toString();
-    }
-
+    /**
+     * Setter for property meta
+     *
+     * @param meta - string representation of metatags, associated to image. Used at jsf page.
+     */
     public void setMeta(String meta) {
         this.meta = meta;
     }
 
-    public String getMetaString() {
-        return meta;
+    /**
+     * Getter for property meta 
+     * 
+     * @return string representation of metatags, associated to image. Used at jsf page.
+     */
+    public String getMetaString(){
+    	return meta;
     }
-
+    
+    /**
+     * Getter for property cameraModel
+     *
+     * @return model of camera
+     */
     public String getCameraModel() {
         return cameraModel;
     }
 
+    /**
+     * setter for property cameraModel
+     *
+     * @param cameraModel- model of camera
+     */
     public void setCameraModel(String cameraModel) {
         this.cameraModel = cameraModel;
     }
 
+    /**
+     * Getter for property height
+     *
+     * @return height of image
+     */
     public int getHeight() {
         return height;
     }
 
+    /**
+     * setter for property height
+     *
+     * @param height - height of image
+     */
     public void setHeight(int height) {
         this.height = height;
     }
 
+    /**
+     * Getter for property size
+     *
+     * @return size of image in KB
+     */
     public double getSize() {
         return size;
     }
 
+    /**
+     * setter for property size
+     *
+     * @param size - size of image in KB
+     */
     public void setSize(double size) {
         this.size = size;
     }
 
+    /**
+     * Getter for property width
+     *
+     * @return width of image
+     */
     public int getWidth() {
         return width;
     }
 
+    /**
+     * setter for property width
+     *
+     * @param width - width of image
+     */
     public void setWidth(int width) {
         this.width = width;
     }
 
+    /**
+     * Getter for property uploaded
+     *
+     * @return date of upload to site of this image
+     */
     public Date getUploaded() {
         return uploaded;
     }
 
+    /**
+     * setter for property uploaded
+     *
+     * @param uploaded - date of upload
+     */
     public void setUploaded(Date uploaded) {
         this.uploaded = uploaded;
     }
+    
+    /**
+     * Getter for property allowComments. If true, other user may comment this image.
+     *
+     * @return is other users may comment this image
+     */
+    public boolean isAllowComments() {
+        return allowComments;
+    }
 
+    /**
+     * @param allowComments the allowComments to set
+     */
+    public void setAllowComments(boolean allowComments) {
+        this.allowComments = allowComments;
+    }
+
+    /**
+     * 
+     * @return if this image is covering for containing album
+     */
+    public boolean isCovering() {
+        return this.equals(this.getAlbum().getCoveringImage());
+    }
+
+    /**
+     * 
+     * @param covering - determine if this image is covering for containing album
+     */
+    public void setCovering(boolean covering) {
+        this.covering = covering;
+    }
+    
+    /**
+     * Getter for property visited
+     *
+     * @return boolean value, that indicated is user visit this image already
+     */
+    public boolean isVisited() {
+		return visited;
+	}
+
+    /**
+     * Setter for property visited
+     *
+     * @param visited - boolean value, that indicated is user visit this image already
+     */
+	public void setVisited(boolean visited) {
+		this.visited = visited;
+	}
+	
+	/**
+     * Determine if this image should be marked as new(on jsf page, for example in tree)
+     *
+     * @return boolean value, that indicated is this image should be marked as new
+     */
+	public boolean isNew(){
+		if(!visited){
+			return this.getUploaded().after(ActionTools.getRecentlyDate());
+		}
+		return false;
+	}
+    
+    //---------------------------Business methods
+
+    /**
+     * Add comment to this image.
+     *
+     * @param comment - comment to add
+     */
+    public void addComment(Comment comment) {
+        if (comment == null) {
+            throw new IllegalArgumentException("Null comment!");
+        }
+        comment.setImage(this);
+        comments.add(comment);
+    }
+
+    /**
+     * Remove comment from list of comments, belongs to that image.
+     *
+     * @param comment - comment to delete
+     */
+    public void removeComment(Comment comment) {
+        if (comment == null) {
+            throw new IllegalArgumentException("Null comment");
+        }
+        if(comment.getImage().equals(this)){
+        	comment.setImage(null);
+            comments.remove(comment);
+        }else{
+        	throw new IllegalArgumentException("Comment not belongs to this image");
+        }
+    }
+
+    /**
+     * Add metatag to this image.
+     *
+     * @param metatag - metatag to add
+     */
     public void addMetaTag(MetaTag metatag) {
         if (metatag == null) {
             throw new IllegalArgumentException("Null metatag!");
@@ -330,6 +511,11 @@
         }
     }
 
+    /**
+     * Remove metatag from list of metatag, associated to that image.
+     *
+     * @param metatag - metatag to delete
+     */
     public void removeMetaTag(MetaTag metatag) {
         if (metatag == null) {
             throw new IllegalArgumentException("Null metatag!");
@@ -341,27 +527,10 @@
     }
 
     /**
-     * @return the allowComments
+     * Return MetaTag object by string representation
+     *
+     * @param s - string representation of metatag
      */
-    public boolean isAllowComments() {
-        return allowComments;
-    }
-
-    /**
-     * @param allowComments the allowComments to set
-     */
-    public void setAllowComments(boolean allowComments) {
-        this.allowComments = allowComments;
-    }
-
-    public boolean isCovering() {
-        return this.equals(this.getAlbum().getCoveringImage());
-    }
-
-    public void setCovering(boolean covering) {
-        this.covering = covering;
-    }
-
     public MetaTag getTagByName(String s) {
         for (MetaTag t : imageTags) {
             if (t.getTag().equals(s)) {
@@ -371,6 +540,22 @@
         return null;
     }
 
+    /**
+     * Return Comma separated tag value for presentation in view
+     *
+     */
+    public String getMeta() {
+        final StringBuilder s = new StringBuilder();
+        for (MetaTag tag : this.imageTags) {
+            s.append(tag.getTag()).append(", ");
+        }
+        //Remove ',' from end
+		if (s.length() >= 2) {
+			s.delete(s.length() - 2, s.length());
+		}
+		return s.toString();
+    }
+    
     public boolean equals(Object o) {
         if (this == o) return true;
         if (o == null || getClass() != o.getClass()) return false;
@@ -389,19 +574,4 @@
         result = 31 * result + (path != null ? path.hashCode() : 0);
         return result;
     }
-
-	public boolean isVisited() {
-		return visited;
-	}
-
-	public void setVisited(boolean visited) {
-		this.visited = visited;
-	}
-	
-	public boolean isNew(){
-		if(!visited){
-			return this.getUploaded().after(ActionTools.getRecentlyDate());
-		}
-		return false;
-	}
 }

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -39,10 +39,17 @@
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
 
+/**
+ * Class for representing MetaTag Entity
+ *  EJB3 Entity Bean
+ *
+ * @author Andrey Markhel
+ */
+
 @Entity
 @Name("metaTag")
 @Table(name = "metatags", uniqueConstraints = {
-		@UniqueConstraint(columnNames = "tag"),
+		@UniqueConstraint(columnNames = "tag")
 		})
 @Scope(ScopeType.EVENT)
 public class MetaTag implements Serializable {
@@ -65,16 +72,13 @@
 
     public MetaTag() {
     }
-
-    public MetaTag(Long id) {
-        this.id = id;
-    }
     
     public MetaTag(Long id, String tag) {
         this.id = id;
         this.tag = tag;
     }
 
+    //---------------------------------Getters, Setters..
     public Long getId() {
         return id;
     }

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,5 +1,30 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
 package org.richfaces.realworld.domain;
 
+/**
+ * Enumeration for representing gender of user
+ *
+ * @author Andrey Markhel
+ */
 public enum Sex {
     MALE("1"),
     FEMALE("0");

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -112,24 +112,107 @@
         this.description = description;
     }
 
+    /**
+     * Getter for property albums
+     *
+     * @return collection of albums, belongs to this shelf.
+     */
     public List<Album> getAlbums() {
         return albums;
     }
 
+    /**
+     * Getter for property owner
+     *
+     * @return user, that created this shelf
+     */
     public User getOwner() {
         return owner;
     }
 
+    /**
+     * Setter for property owner
+     *
+     * @param owner -owner of shelf
+     */
     public void setOwner(User owner) {
         this.owner = owner;
     }
 
+    /**
+     * Getter for property created
+     *
+     * @return date of creation of this shelf
+     */
+    public Date getCreated() {
+        return created;
+    }
+
+    /**
+     * Setter for property created
+     *
+     * @param created - date of creation
+     */
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+
+    /**
+     * Getter for property shared. If true - all users can view this shelfs and albums and images, contained in this shelf,
+     * otherwise this shelf can view only owner.
+     *
+     * @return shared
+     */
+    public boolean isShared() {
+        return shared;
+    }
+
+    /**
+     * Setter for property shared
+     *
+     * @param shared - determine is this shelf will be accessible by other users.
+     */
+    public void setShared(boolean shared) {
+        this.shared = shared;
+    }
+
+    /**
+     * @return count of unvisited images
+     */
+    public Long getCountUnvisitedImages() {
+        return new Long(unvisitedImages.size());
+    }
+
+    /**
+     * @return List of unvisited images
+     */
+    public List<Image> getUnvisitedImages() {
+        return unvisitedImages;
+    }
+
+    /**
+     * @param unvisitedImages - List of unvisited images
+     */
+    public void setUnvisitedImages(List<Image> unvisitedImages) {
+        this.unvisitedImages = unvisitedImages;
+    }
+    
+ // ********************** Business Methods ********************** //
+    
+    /**
+     * This method add album to collection of albums of current shelf
+     *
+     * @param album -
+     *              album to add
+     */
     public void addAlbum(Album album) {
         if (album == null)
             throw new IllegalArgumentException("Null album!");
         if (album.getShelf() != null && !album.getShelf().getAlbums().contains(this)){
-            album.getShelf().removeAlbum(album);
+            // remove from previous shelf
+        	album.getShelf().removeAlbum(album);
             album.setShelf(this);
+            //If album contain new or unvisited images, add to shelf unvisited images
             for(Image i : album.getImages()){
             	if(i.isNew()){
             		this.getUnvisitedImages().add(i);
@@ -139,10 +222,17 @@
         }	
     }
 
+    /**
+     * This method remove album from collection of albums of album
+     *
+     * @param album -
+     *              album to remove
+     */
     public void removeAlbum(Album album) {
         if (album == null)
             throw new IllegalArgumentException("Null album!");
         if(album.getShelf().equals(this)){
+        	//Remove from unvisitedImages if needed
         	for(Image i : album.getImages()){
         		album.visitImage(i, false);
         	}
@@ -153,10 +243,20 @@
         }
     }
 
+    /**
+     * This method return count of albums of current shelf
+     *
+     * @return count of albums of current shelf
+     */
     public int getCountAlbums() {
         return this.getAlbums() != null ? this.getAlbums().size() : 0;
     }
 
+    /**
+     * This method return count of images of current shelf
+     *
+     * @return count of images of this shelf
+     */
     public int getCountImages() {
         int result = 0;
         if (getCountAlbums() > 0) {
@@ -168,41 +268,11 @@
     }
 
     /**
-     * @return the created
+     * This method return first album of current shelf or null if shelf haven't albums.
+     *
+     * @return first album of shelf or null
      */
-    public Date getCreated() {
-        return created;
-    }
-
-    /**
-     * @param created the created to set
-     */
-    public void setCreated(Date created) {
-        this.created = created;
-    }
-
-    public boolean isShared() {
-        return shared;
-    }
-
-    public void setShared(boolean shared) {
-        this.shared = shared;
-    }
-
-    public Long getCountUnvisitedImages() {
-        return new Long(unvisitedImages.size());
-    }
-
-    public List<Image> getUnvisitedImages() {
-        return unvisitedImages;
-    }
-
-    public void setUnvisitedImages(List<Image> unvisitedImages) {
-        this.unvisitedImages = unvisitedImages;
-    }
-
     public Album getFirstAlbum() {
-		//TODO nick - use random album for cover?
         if (this.albums.size() > 0) {
             return this.albums.get(0);
         }
@@ -229,4 +299,4 @@
         result = 31 * result + (owner != null ? owner.hashCode() : 0);
         return result;
     }
-}
+}
\ No newline at end of file

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -39,16 +39,22 @@
 import javax.persistence.Transient;
 import javax.persistence.UniqueConstraint;
 
+import org.hibernate.validator.Email;
 import org.hibernate.validator.Length;
 import org.hibernate.validator.NotEmpty;
 import org.hibernate.validator.NotNull;
-import org.hibernate.validator.Pattern;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Role;
 import org.jboss.seam.annotations.Scope;
 
+/**
+ * Class for representing User Entity
+ *  EJB3 Entity Bean
+ *
+ * @author Andrey Markhel
+ */
+
 @NamedQueries({
     @NamedQuery(
         name = "user-login",
@@ -59,16 +65,39 @@
         query = "from User u where u.login = :login"
    ),
    @NamedQuery(
-	        name = "user-user",
-	        query = "from User u where u.login = :login"
+	    name = "user-sharedAlbums",
+	    query = "from Album a where a.shelf.owner=:user and a.shelf.shared=true"
+	   ),
+   @NamedQuery(
+		name = "user-sharedImages",
+		query = "from Image i where i.album.shelf.owner=:user and i.album.shelf.shared=true"
+		   ),
+   @NamedQuery(
+		name = "user-countAlbums",
+		query = "select count(a) from Album a where a.shelf.owner=:user"
+			   ),
+	@NamedQuery(
+		name = "user-countSharedAlbums",
+		query = "select count(a) from Album a where a.shelf.owner=:user and a.shelf.shared=true"
+				   ),
+	@NamedQuery(
+		name = "user-countImages",
+		query = "select count(i) from Image i where i.album.shelf.owner=:user"
+					   ),
+		@NamedQuery(
+		name = "user-countSharedImages",
+		query = "select count(i) from Image i where i.album.shelf.owner=:user and i.album.shelf.shared=true"
+						   ),
+   @NamedQuery(
+	    name = "user-user",
+	    query = "from User u where u.login = :login"
 	   )
 })
 
 @Entity
- at Scope(ScopeType.CONVERSATION)
+ at Scope(ScopeType.SESSION)
 @Name("user")
 @AutoCreate
- at Role(name="selectedUser", scope=ScopeType.CONVERSATION)
 @Table(name = "Users", uniqueConstraints = {
 		@UniqueConstraint(columnNames = "login"),
 		@UniqueConstraint(columnNames = "email")
@@ -100,8 +129,7 @@
 	@Column(length = 255, nullable = false)
     @NotNull
     @NotEmpty
-    //TODO nick - use e-mail validator
-    @Pattern(regex=".+ at .+\\.[a-z]+", message="Not valid e-mail")
+    @Email
 	private String email;
 	
 	@Column(length = 255, nullable = false)
@@ -121,10 +149,13 @@
 	
 	@NotNull
 	private Sex sex;
+	
 	@Transient
 	private Long countImages;
+	
 	@Transient
 	private Long countAlbums;
+	
 	private Boolean hasAvatar;
 	
 	@OneToMany(mappedBy = "owner", cascade = { CascadeType.ALL})
@@ -132,6 +163,7 @@
     @org.hibernate.annotations.OrderBy(clause = "NAME asc")
     private List<Shelf> shelfs = new ArrayList<Shelf>();
 
+	//----------------Getters, Setters
 	public String getFirstName() {
 		return firstName;
 	}
@@ -156,9 +188,12 @@
 		this.email = email;
 	}
 
-	public String getPasswordHash() { return passwordHash; }
+	public String getPasswordHash(){ 
+		return passwordHash; 
+	}
+	
 	public void setPasswordHash(String passwordHash) {
-	this.passwordHash = passwordHash;
+		this.passwordHash = passwordHash;
 	}
 	
 	public String getLogin() {
@@ -189,35 +224,22 @@
 		return id;
 	}
 	
-	//---------------------------Business methods
-    
-    public void addShelf(Shelf shelf) {
-        if (shelf == null) {
-            throw new IllegalArgumentException("Null shelf!");
-        }    
-        if(!shelfs.contains(shelf)){
-        	shelf.setOwner(this);
-            shelfs.add(shelf);
-        }
-    }
+	public Long getCountImages() {
+		return countImages;
+	}
 
-    public void removeShelf(Shelf shelf) {
-        if (shelf == null) {
-            throw new IllegalArgumentException("Null shelf");
-        }
-        if(shelf.getOwner().getLogin().equals(this.getLogin())){
-        	shelf.setOwner(null);
-            shelfs.remove(shelf);
-        }else{
-        	throw new IllegalArgumentException("Shelf not belongs to this user!");
-        }
-    }
+	public void setCountImages(Long countImages) {
+		this.countImages = countImages;
+	}
 
-    public void updateStatistics() {
-		countAlbums = null;
-		countImages = null;
+	public Long getCountAlbums() {
+		return countAlbums;
 	}
-    
+
+	public void setCountAlbums(Long countAlbums) {
+		this.countAlbums = countAlbums;
+	}
+	
 	public String getConfirmPassword() {
 		return confirmPassword;
 	}
@@ -234,10 +256,6 @@
 		this.shelfs = shelfs;
 	}
 	
-	public int getCountShelfs() {
-		return this.getShelfs() != null ? this.getShelfs().size() : 0;
-	}
-
 	public Sex getSex() {
 		return sex;
 	}
@@ -254,6 +272,66 @@
 		this.hasAvatar = hasAvatar;
 	}
 	
+	//---------------------------Business methods
+    
+	/**
+     * This method add shelf to collection of shelves, belongs to user
+     *
+     * @param shelf -
+     *              shelf to add
+     */
+    public void addShelf(Shelf shelf) {
+        if (shelf == null) {
+            throw new IllegalArgumentException("Null shelf!");
+        }    
+        if(!shelfs.contains(shelf)){
+        	shelf.setOwner(this);
+            shelfs.add(shelf);
+        }
+    }
+
+    /**
+     * This method remove shelf from collection of shelves, belongs to user
+     *
+     * @param shelf -
+     *              shelf to remove
+     */
+    public void removeShelf(Shelf shelf) {
+        if (shelf == null) {
+            throw new IllegalArgumentException("Null shelf");
+        }
+        if(shelf.getOwner().getLogin().equals(this.getLogin())){
+        	shelf.setOwner(null);
+            shelfs.remove(shelf);
+        }else{
+        	throw new IllegalArgumentException("Shelf not belongs to this user!");
+        }
+    }
+
+    /**
+     * This method set countAlbums and countImages to null.
+     * Used when user delete shelf, album or image and so on... to reset statistics.
+     * On next access to this properties, hit to database occur, to retrieve actual data.
+     */
+    public void updateStatistics() {
+		countAlbums = null;
+		countImages = null;
+	}
+	
+    /**
+     * This method return count of shelves, belongs to user
+     *
+     * @return count of of shelves, belongs to user
+     */
+	public int getCountShelfs() {
+		return this.getShelfs() != null ? this.getShelfs().size() : 0;
+	}
+	
+	/**
+     * This method return all albums, belongs to user
+     *
+     * @return albums, belongs to user
+     */
 	public List<Album> getAllAlbums(){
 		List<Album> albums = new ArrayList<Album>();
 		for(Shelf s:getShelfs()){
@@ -262,6 +340,11 @@
 		return albums;
 	}
 	
+	/**
+     * This method return all images, belongs to user
+     *
+     * @return images, belongs to user
+     */
 	public List<Image> getAllImages(){
 		List<Image> images = new ArrayList<Image>();
 		for(Shelf s:getShelfs()){
@@ -271,20 +354,4 @@
 		}
 		return images;
 	}
-
-	public Long getCountImages() {
-		return countImages;
-	}
-
-	public void setCountImages(Long countImages) {
-		this.countImages = countImages;
-	}
-
-	public Long getCountAlbums() {
-		return countAlbums;
-	}
-
-	public void setCountAlbums(Long countAlbums) {
-		this.countAlbums = countAlbums;
-	}
 }
\ No newline at end of file

Modified: 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	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ActionTools.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
 package org.richfaces.realworld.service;
 
 import java.util.Date;
@@ -4,12 +24,18 @@
 import java.util.Calendar;
 
 /**
+ * Utility class
  * @user: akolonitsky
  * Date: Apr 1, 2009
  */
 public class ActionTools {
 	private static final int RECENTLY_DAYS = 15;
 
+	/**
+     * This method return "recently date". Used to determine is image "is new"
+     *
+     * @return "recently date"
+     */
 	public static Date getRecentlyDate() {
 		final Calendar calendar = Calendar.getInstance();
 		calendar.add(Calendar.DAY_OF_YEAR, -RECENTLY_DAYS);

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -31,6 +31,12 @@
 import org.richfaces.realworld.domain.Album;
 import org.richfaces.realworld.domain.Image;
 
+/**
+ * Class for manipulating with album entity. Analogous to DAO pattern.
+ *  EJB3 Bean
+ *
+ * @author Andrey Markhel
+ */
 @Name("albumAction")
 @Stateless
 @AutoCreate
@@ -38,35 +44,48 @@
 
 	@In(value="entityManager")
 	EntityManager em;
-	
-	@In FlushStrategy flushStrategy;
 
+	/**
+     * Persist album entity to database
+     * @param album - album to add
+     */
 	public void addAlbum(Album album) {
 		em.persist(album);
+		//Add to shelf
 		album.getShelf().addAlbum(album);
-		if(flushStrategy.isDatabaseStoreStrategy()){
-			em.flush();
-		}
+		em.flush();
 	}
 	
+	/**
+     * Remove album entity from database
+     * @param album - album to delete
+     */
 	public void deleteAlbum(Album album){
-		if(album.getShelf()==null){
+		if(album.getShelf() == null){
 			return;
 		}
+		//Remove from previous shelf 
 		album.getShelf().removeAlbum(album);
 		em.remove(album);
-		if(flushStrategy.isDatabaseStoreStrategy()){
-			em.flush();
-		}
+		em.flush();
 	}
 	
+	/**
+     * Synchronize state of album entity with database
+     * @param album - album to Synchronize
+     */
 	public void editAlbum(Album album){
-		if(flushStrategy.isDatabaseStoreStrategy()){
-			em.flush();
-		}
+		em.flush();
 	}
 
+	/**
+     * Used to retrieve all unvisited images, belongs to specified album.
+     *
+     * @param album
+     * @return List of unvisited images
+     */
+	@SuppressWarnings("unchecked")
 	public List<Image> getUnvisitedImages(Album album){
-		return (List<Image>)em.createQuery("from Image i where i.album=:album and i.uploaded > :date").setParameter("album", album).setParameter("date", ActionTools.getRecentlyDate()).getResultList();
+		return (List<Image>)em.createNamedQuery(Constants.ALBUM_UNVISITED_QUERY).setParameter(Constants.ALBUM_PARAMETER, album).setParameter(Constants.DATE_PARAMETER, ActionTools.getRecentlyDate()).getResultList();
 	}
 }

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -20,11 +20,13 @@
  */
 package org.richfaces.realworld.service;
 
-//TODO nick - review constants and remove old ones
-//TODO nick - separate view and service layer constants
+/**
+ * Utility class. Group of constants
+ *
+ * @author Andrey Markhel
+ */
 public class Constants {
 
-	public static final String ERROR_ID = "mainform:error";
 	public static final String CLEAR_ERROR_EVENT = "clearErrorEvent";
 	public static final String ADD_ERROR_EVENT = "addErrorEvent";
 	
@@ -46,13 +48,45 @@
 	public static final int INITIAL_DELAY = 4000;
 	public static final int DELAY = 3000;
 
+	//Service -constants
 	public static final String USER_EXIST_QUERY = "user-exist";
 	public static final String USER_LOGIN_QUERY = "user-login";
-
 	public static final String LOGIN_PARAMETER = "login";
 	public static final String PASSWORD_PARAMETER = "password";
 	public static final String USERNAME_PARAMETER = "username";
-
+	public static final String USER_PARAMETER = "user";
+	public static final String USER_COUNT_SHARED_IMAGES_QUERY = "user-countSharedImages";
+	public static final String USER_COUNT_IMAGES_QUERY = "user-countImages";
+	public static final String USER_COUNT_SHARED_ALBUMS_QUERY = "user-countSharedAlbums";
+	public static final String USER_COUNT_ALBUMS_QUERY = "user-countAlbums";
+	public static final String USER_SHARED_IMAGES_QUERY = "user-sharedImages";
+	public static final String USER_SHARED_ALBUMS_QUERY = "user-sharedAlbums";
+	public static final String DATE_PARAMETER = "date";
+	public static final String ALBUM_PARAMETER = "album";
+	public static final String ALBUM_UNVISITED_QUERY = "album-unvisited";
+	public static final String COMMA = ",";
+	public static final int MAX_RESULTS = 20;
+	public static final String PERCENT = "%";
+	public static final String TAG_SUGGEST_QUERY = "tag-suggest";
+	public static final String TAG_POPULAR_QUERY = "tag-popular";
+	public static final String TAG_PARAMETER = "tag";
+	public static final String TAG_BY_NAME_QUERY = "tag-byName";
+	public static final String SEARCH_QUERY_SHARED_ADDON = " and sh.shared=true";
+	public static final String SEARCH_QUERY_MY_ADDON = " and sh.owner.login=:login";
+	public static final String SEARCH_SHELVES_QUERY = "from Shelf sh where lower(sh.name) like :name or lower(sh.description) like :name ";
+	public static final String SEARCH_METATAG_QUERY = "from MetaTag t where lower(t.tag) like :name";
+	public static final String SEARCH_USERS_QUERY = "select  u from User u where lower(u.login) like :name or lower(u.firstName) like :name or lower(u.secondName) like :name";
+	public static final String SEARCH_IMAGE_SHARED_ADDON = " and i.album.shelf.shared=:shared";
+	public static final String SEARCH_IMAGE_MY_ADDON = " and i.album.owner.login=:login";
+	public static final String SEARCH_IMAGE_QUERY = "from Image i where lower(i.name) like :name or lower(i.description) like :name or lower(i.cameraModel) like :name";
+	public static final String SHARED_PARAMETER = "shared";
+	public static final String NAME_PARAMETER = "name";
+	public static final String SEARCH_ALBUM_SHARED_ADDON = " and a.shelf.shared=:shared";
+	public static final String SEARCH_ALBUM_MY_ADDON = " and a.owner.login=:login";
+	public static final String SEARCH_ALBUM_QUERY = "from Album a where lower(a.name) like :name or lower(a.description) like :name";
+	public static final String USER_SHELVES_QUERY = "user-shelves";
+	public static final String SHELF_PARAMETER = "shelf";
+	public static final String SHELF_UNVISITED_QUERY = "shelf-unvisited";
 	private Constants(){
 		
 	}

Deleted: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/FlushStrategy.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/FlushStrategy.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/FlushStrategy.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,51 +0,0 @@
-package org.richfaces.realworld.service;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Properties;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
-
- at Name("flushStrategy")
- at Scope(ScopeType.APPLICATION)
- at Startup
-public class FlushStrategy {
-
-	public FlushStrategy(){
-		getStrategy();
-	}
-	private static String strategy;
-	
-	public String getStrategy() {
-		if(strategy == null){
-			try { InputStream in = this.getClass().getClassLoader()  
-				               .getResourceAsStream("realworld.properties");  
-			if(in != null){
-				Properties p = new Properties();
-				p.load(in);
-				strategy = p.getProperty("flushStrategy");
-			}else{
-				strategy = "database";
-			}
-			} catch (FileNotFoundException e) {
-				strategy = "database";
-			} catch (IOException e) {
-				strategy = "database";
-			}
-		}
-		return strategy;
-	}
-	
-	
-	//TODO nick - make this a static method
-	public boolean isDatabaseStoreStrategy(){
-		return getStrategy().equals("database");
-	}
-}

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -27,6 +27,12 @@
 import org.richfaces.realworld.domain.Album;
 import org.richfaces.realworld.domain.Image;
 
+/**
+ * Interface for manipulating with album entity
+ *
+ * @author Andrey Markhel
+ */
+
 @Local
 public interface IAlbumAction {
 

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -28,26 +28,29 @@
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.MetaTag;
 
+/**
+ * Interface for manipulating with image entity
+ *
+ * @author Andrey Markhel
+ */
+
 @Local
 public interface IImageAction {
 
-	//TODO nick - remove isFlushNeeded
+	public void deleteImage(Image image);
 
-	public abstract void deleteImage(Image image);
+	public void editImage(Image image);
 
-	public abstract void editImage(Image image);
-
-	public abstract void addImage(Image image);
+	public void addImage(Image image);
 	
 	public void deleteComment(Comment comment);
 	
 	public void addComment(Comment comment);
 
-	public abstract MetaTag getTagByName(String tag);
+	public MetaTag getTagByName(String tag);
 
-	//TODO nick - rename to getPopularTags() 
-	public abstract List<MetaTag> getPopularTags();
+	public List<MetaTag> getPopularTags();
 
-	public abstract List<MetaTag> getTagsLikeString(String suggest);
+	public List<MetaTag> getTagsLikeString(String suggest);
 
 }
\ No newline at end of file

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
 package org.richfaces.realworld.service;
 
 import java.util.List;
@@ -2,2 +22,4 @@
 
+import javax.ejb.Local;
+
 import org.richfaces.realworld.domain.Album;
@@ -8,6 +30,12 @@
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
 
+/**
+ * Interface for search actions
+ *
+ * @author Andrey Markhel
+ */
+ at Local
 public interface ISearchAction {
 	public List<Image> searchByImage(String query, boolean searchInMyAlbums, boolean searchInShared);
 	

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IShelfAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IShelfAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IShelfAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
 package org.richfaces.realworld.service;
 
 
@@ -8,6 +28,11 @@
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
+/**
+ * Interface for manipulating with shelf entity
+ *
+ * @author Andrey Markhel
+ */
 
 @Local
 public interface IShelfAction {

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -28,13 +28,18 @@
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.User;
 
+/**
+ * Interface for manipulating with user entity
+ *
+ * @author Andrey Markhel
+ */
+
 @Local
 public interface IUserAction {
 	public User login(String username, String password);
 	public void register(User user);
 	public boolean isUserExist(String login);
 	public User updateUser();
-	public User resetUser();
 	public Long countAlbums();
 	public Long countImages();
 	public Long countSharedImages(User u);

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -35,106 +35,146 @@
 import org.richfaces.realworld.domain.Comment;
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.MetaTag;
-
+/**
+ * Class for manipulating with image entity. Analogous to DAO pattern.
+ *  EJB3 Bean
+ *
+ * @author Andrey Markhel
+ */
 @Name("imageAction")
 @Stateless
 @AutoCreate
 public class ImageAction implements IImageAction {
 
-    @In(value = "entityManager")
+	@In(value = "entityManager")
     EntityManager em;
-    
-    @In FlushStrategy flushStrategy;
 
+    /**
+     * Remove image entity from database
+     *@param image - image to delete
+     */
     public void deleteImage(Image image) {
     	if(image.getAlbum().getCoveringImage().equals(image)){
     		image.getAlbum().setCoveringImage(null);
     	}
         image.getAlbum().removeImage(image);
         em.remove(image);
-        if (flushStrategy.isDatabaseStoreStrategy()) {
-            em.flush();
-        }
+        em.flush();
     }
 
+    /**
+     * Synchronize state of image entity with database
+     *@param image - image to Synchronize
+     */
     public void editImage(Image image) {
+    	//Create cash of metatags early associated with image
         List<MetaTag> removals = new ArrayList<MetaTag>(image.getImageTags());
-        String[] tokens = image.getMetaString().split(",");
+        
+        //Get string representation of current metatgs, associated with image and split them by comma
+        String[] tokens = image.getMetaString().split(Constants.COMMA);
+        
+        //Populate set of tokens - 'candidates to metatags'
         Set<String> toks = new HashSet<String>();
         for (String s : tokens) {
             toks.add(s.trim());
         }
+        
         for (String s : toks) {
+        	//Find metatag in early associated tags
         	MetaTag t = image.getTagByName(s);
             if (t != null) {
-                	//TODO nick - how about concurrent creation of meta tags with the same name?
+            	//If found - no work needed
                 removals.remove(t);
             } else {
+            	//Find metatag in database
             	t = getTagByName(s);
             		if(t != null){
+            			//If found simple add reference to it
             			image.addMetaTag(t);
             		}else{
+            			//Create new metatag
             			t = new MetaTag();
                         t.setTag(s);
                         image.addMetaTag(t);
+                        //Persist to database to prevent concurrent creation of other metatags with given name
+                        em.persist(t);
             		}
             	}
         }
+        
         for (MetaTag tag : removals) {
+        	//If metatag in that collection, we need remove them
             image.removeMetaTag(tag);
         }
+        //If this image is covering for album, break the reference
         if (image.isCovering()) {
             if (!image.equals(image.getAlbum().getCoveringImage())) {
                 image.getAlbum().setCoveringImage(image);
             }
         }
-        if (flushStrategy.isDatabaseStoreStrategy()) {
-        	try{
-        		em.flush();
-        	}catch(Exception e){
-        		editImage(image);
-        	}
-            
-        }
+        em.flush();
     }
 
+    /**
+     * Persist image entity to database
+     * @param image - image to add
+     */
     public void addImage(Image image) {
         em.persist(image);
         image.getAlbum().addImage(image);
-        if (flushStrategy.isDatabaseStoreStrategy()) {
-            em.flush();
-        }
+        em.flush();
     }
 
+    /**
+     * Remove comment from image
+     * @param comment - comment to remove
+     */
     public void deleteComment(Comment comment) {
         comment.getImage().removeComment(comment);
-        if (flushStrategy.isDatabaseStoreStrategy()) {
-            em.flush();
-        }
+        em.flush();
     }
 
+    /**
+     * Add comment from image
+     * @param comment - comment to add
+     */
     public void addComment(Comment comment) {
         comment.getImage().addComment(comment);
-        if (flushStrategy.isDatabaseStoreStrategy()) {
-            em.flush();
-        }
+        em.flush();
     }
 
+    /**
+     * Find metatag object by its string representation
+     * @param tag - string representation of metatag
+     * @return metatag object or null
+     */
     public MetaTag getTagByName(String tag) {
         MetaTag t;
         try {
-            t = (MetaTag) em.createQuery("from MetaTag m where m.tag =:tag").setParameter("tag", tag).getSingleResult();
+            t = (MetaTag) em.createNamedQuery(Constants.TAG_BY_NAME_QUERY).setParameter(Constants.TAG_PARAMETER, tag).getSingleResult();
         } catch (NoResultException nre) {
+        	//If not found
             return null;
         }
         return t;
     }
 
-    public List<MetaTag> getPopularTags() {
-        return em.createQuery("select new MetaTag(m.id, m.tag) from MetaTag m join m.images img group by m.id, m.tag order by count(img) desc").setMaxResults(20).getResultList();
+    /**
+     * Find most-popular metatags
+     * @return list of most-popular metatags
+     */
+    @SuppressWarnings("unchecked")
+	public List<MetaTag> getPopularTags() {
+        return em.createNamedQuery(Constants.TAG_POPULAR_QUERY).setMaxResults(Constants.MAX_RESULTS).getResultList();
     }
 
-    public List<MetaTag> getTagsLikeString(String suggest) {
-        return (List<MetaTag>) em.createQuery("select m from MetaTag m where lower(m.tag) like :tag").setParameter("tag", suggest + "%").getResultList();
+    /**
+     * Find List of metatags, similar to specified string. Used in autosuggect
+     * @param suggest - string to search
+     * @return list of most-popular metatags
+     */
+    @SuppressWarnings("unchecked")
+	public List<MetaTag> getTagsLikeString(String suggest) {
+        return (List<MetaTag>) em.createNamedQuery(Constants.TAG_SUGGEST_QUERY).setParameter(Constants.TAG_PARAMETER, suggest + Constants.PERCENT).getResultList();
     }
 }

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
 package org.richfaces.realworld.service;
 
 import java.util.List;
@@ -9,98 +29,164 @@
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Out;
 import org.richfaces.realworld.domain.Album;
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.MetaTag;
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
 
+/**
+ * Search Builder
+ *  EJB3 Bean
+ *
+ * @author Andrey Markhel
+ */
+
 @Name("searchAction")
 @Stateless
 @AutoCreate
 @SuppressWarnings("unchecked")
-//TODO add JavaDocs
 public class SearchAction implements ISearchAction {
 
 	@In(value="entityManager")
 	EntityManager em;
 	
-	@In @Out
+	@In
 	private User user;
 	
+	/**
+     * Return List of albums, founded by query
+     * Search albums by name and description(like)
+     * @param searchQuery - string to search
+     * @param searchInMyAlbums - determine is search will be making by only user's albums
+     * @param searchInShared - determine is search will be making in only shared albums
+     * @return list of founded albums
+     */
 	public List<Album> searchByAlbum(String searchQuery, boolean searchInMyAlbums, boolean searchInShared) {
-		StringBuilder b = new StringBuilder("from Album a where lower(a.name) like :name or lower(a.description) like :name");
+		StringBuilder b = new StringBuilder(Constants.SEARCH_ALBUM_QUERY);
+		//If we search in user's albums
 		if (searchInMyAlbums) {
-			b.append(" and a.owner.login=:login");
+			b.append(Constants.SEARCH_ALBUM_MY_ADDON);
 		}
+		//If we search only in shared albums
 		if(searchInShared){
-			b.append(" and a.shelf.shared=:shared");
+			b.append(Constants.SEARCH_ALBUM_SHARED_ADDON);
 		}
+		//Create query
 		Query query = em.createQuery(b.toString());
-		
-		query.setParameter("name", "%" + searchQuery.toLowerCase() + "%");
+		//Set search string
+		query.setParameter(Constants.NAME_PARAMETER, Constants.PERCENT + searchQuery.toLowerCase() + Constants.PERCENT);
+		//If we search only in shared albums
 		if(searchInShared){
-			query.setParameter("shared", searchInShared);
+			query.setParameter(Constants.SHARED_PARAMETER, searchInShared);
 		}
+		//If we search in user's albums
 		if (searchInMyAlbums) {
-			query.setParameter("login", user.getLogin());
+			query.setParameter(Constants.LOGIN_PARAMETER, user.getLogin());
 		}
+		//Get result
 		return query.getResultList();
 	}
 
+	/**
+     * Return List of images, founded by query
+     * Search images by name and description(like)
+     * @param searchQuery - string to search
+     * @param searchInMyAlbums - determine is search will be making by only user's images
+     * @param searchInShared - determine is search will be making in only shared images
+     * @return list of founded images
+     */
 	public List<Image> searchByImage(String searchQuery, boolean searchInMyAlbums, boolean searchInShared) {
-		StringBuilder b = new StringBuilder("from Image i where lower(i.name) like :name or lower(i.description) like :name or lower(i.cameraModel) like :name");
+		StringBuilder b = new StringBuilder(Constants.SEARCH_IMAGE_QUERY);
+		//If we search in user's images
 		if (searchInMyAlbums) {
-			b.append(" and i.album.owner.login=:login");
+			b.append(Constants.SEARCH_IMAGE_MY_ADDON);
 		}
+		//If we search only in shared images
 		if(searchInShared){
-			b.append(" and i.album.shelf.shared=:shared");
+			b.append(Constants.SEARCH_IMAGE_SHARED_ADDON);
 		}
+		//Create query
 		Query query = em.createQuery(b.toString());
-		
-		query.setParameter("name", "%" + searchQuery.toLowerCase() + "%");
+		//Set search string
+		query.setParameter(Constants.NAME_PARAMETER, Constants.PERCENT + searchQuery.toLowerCase() + Constants.PERCENT);
+		//If we search only in shared images
 		if(searchInShared){
-			query.setParameter("shared", searchInShared);
+			query.setParameter(Constants.SHARED_PARAMETER, searchInShared);
 		}
+		//If we search only in shared images
 		if (searchInMyAlbums) {
-			query.setParameter("login", user.getLogin());
+			query.setParameter(Constants.LOGIN_PARAMETER, user.getLogin());
 		}
+		//Get result
 		return query.getResultList();
 	}
 
+	/**
+     * Return List of users, founded by query
+     * Search users by login, firstname and secondname(like)
+     * @param searchQuery - string to search
+     * @param searchInMyAlbums - unused
+     * @param searchInShared - unused
+     * @return list of founded users
+     */
 	public List<User> searchByUsers(String searchQuery, boolean searchInMyAlbums, boolean searchInShared) {
-		StringBuilder b = new StringBuilder("select  u from User u where lower(u.login) like :name or lower(u.firstName) like :name or lower(u.secondName) like :name");
+		StringBuilder b = new StringBuilder(Constants.SEARCH_USERS_QUERY);
+		//Create query
 		Query query = em.createQuery(b.toString());
-		
-		query.setParameter("name", "%" + searchQuery.toLowerCase() + "%");
-		
+		//Set search string
+		query.setParameter(Constants.NAME_PARAMETER, Constants.PERCENT + searchQuery.toLowerCase() + Constants.PERCENT);
+		//Get result
 		return query.getResultList();
 	}
 
+	/**
+     * Return List of metatags, founded by query
+     * Search users by tagname(like)
+     * @param searchQuery - string to search
+     * @param searchInMyAlbums - unused
+     * @param searchInShared - unused
+     * @return list of founded metatags
+     */
 	public List<MetaTag> searchByTags(String searchQuery, boolean searchInMyAlbums, boolean searchInShared) {
-		StringBuilder b = new StringBuilder("from MetaTag t where lower(t.tag) like :name");
+		StringBuilder b = new StringBuilder(Constants.SEARCH_METATAG_QUERY);
+		//Create query
 		Query query = em.createQuery(b.toString());
-		
-		query.setParameter("name", "%" + searchQuery.toLowerCase() + "%");
+		//Set search string
+		query.setParameter(Constants.NAME_PARAMETER, Constants.PERCENT + searchQuery.toLowerCase() + Constants.PERCENT);
+		//Get result
 		return query.getResultList();
 	}
 
+	/**
+     * Return List of shelves, founded by query
+     * Search images by name and description(like)
+     * @param searchQuery - string to search
+     * @param searchInMyAlbums - determine is search will be making by only user's shelves
+     * @param searchInShared - determine is search will be making in only shared shelves
+     *	@return list of founded images
+     */
 	public List<Shelf> searchByShelfs(String searchQuery, boolean searchInMyAlbums,
 			boolean searchInShared) {
-		StringBuilder b = new StringBuilder("from Shelf sh where lower(sh.name) like :name or lower(sh.description) like :name ");
+		StringBuilder b = new StringBuilder(Constants.SEARCH_SHELVES_QUERY);
+		//If we search in user's shelves
 		if (searchInMyAlbums) {
-			b.append(" and sh.owner.login=:login");
+			b.append(Constants.SEARCH_QUERY_MY_ADDON);
 		}
+		//If we search only in shared shelves
 		if (searchInShared) {
-			b.append(" and sh.shared=true");
+			b.append(Constants.SEARCH_QUERY_SHARED_ADDON);
 		}
+		//Create query
 		Query query = em.createQuery(b.toString());
+		//If we search in user's shelves
 		if (searchInMyAlbums) {
-			query.setParameter("login", user.getLogin());
+			query.setParameter(Constants.LOGIN_PARAMETER, user.getLogin());
 		}
-		query.setParameter("name", "%" + searchQuery.toLowerCase() + "%");
+		//Set search string
+		query.setParameter(Constants.NAME_PARAMETER, Constants.PERCENT + searchQuery.toLowerCase() + Constants.PERCENT);
+		//Get result
 		return query.getResultList();
 	}
 
-}
+}
\ No newline at end of file

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-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -34,6 +34,13 @@
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
 
+/**
+ * Class for manipulating with shelf entity. Analogous to DAO pattern.
+ *  EJB3 Bean
+ *
+ * @author Andrey Markhel
+ */
+
 @Name("shelfAction")
 @Stateless
 @AutoCreate
@@ -42,47 +49,60 @@
 	@In(value = "entityManager")
 	private EntityManager em;
 
-	@In
-	private FlushStrategy flushStrategy;
+	@In @Out private User user;
 
-	@In
-	@Out
-	private User user;
-
+	/**
+     * Persist shelf entity to database
+     * @param shelf - shelf to add
+     */
 	public void addShelf(Shelf shelf) {
 		em.persist(shelf);
+		//Add reference to user
 		user.addShelf(shelf);
-		if (flushStrategy.isDatabaseStoreStrategy()) {
-			em.flush();
-		}
+		em.flush();
 	}
 
+	/**
+     * Remove shelf entity from database
+     * @param shelf - shelf to delete
+     */
 	public void deleteShelf(Shelf shelf) {
+		//Remove reference from user
 		user.removeShelf(shelf);
 		em.remove(shelf);
-		if (flushStrategy.isDatabaseStoreStrategy()) {
-			em.flush();
-		}
+		em.flush();
 	}
 
+	/**
+     * Synchronize state of shelf entity with database
+     * @param shelf - shelf to Synchronize
+     */
 	public void editShelf(Shelf shelf) {
-		if (flushStrategy.isDatabaseStoreStrategy()) {
-			em.flush();
-		}
+		em.flush();
 	}
 
+	/**
+     * Return list of shared shelfs and if user is logged all user's shelfs
+     * @param shelf - shelf to Synchronize
+     */
+	@SuppressWarnings("unchecked")
 	public List<Shelf> getShelfs(User user) {
-		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);
-
+		Query query = em.createNamedQuery(Constants.USER_SHELVES_QUERY);
+		//If user not-logged parameter will be set to null
+		query.setParameter(Constants.USER_PARAMETER, user.getId() == null ? null : user);
 		return query.getResultList();
 	}
 
+	/**
+     * Used to retrieve all unvisited images, belongs to specified shelf.
+     *
+     *@param shelf
+     *@return List of unvisited images
+     */
+	@SuppressWarnings("unchecked")
 	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", ActionTools.getRecentlyDate()).getResultList();
+		return (List<Image>) em.createNamedQuery(Constants.SHELF_UNVISITED_QUERY)
+				.setParameter(Constants.SHELF_PARAMETER, shelf)
+				.setParameter(Constants.DATE_PARAMETER, ActionTools.getRecentlyDate()).getResultList();
 	}
 }
\ No newline at end of file

Modified: trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -32,6 +32,13 @@
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.User;
 
+/**
+ * Class for manipulating with user entity. Analogous to DAO pattern.
+ *  EJB3 Bean
+ *
+ * @author Andrey Markhel
+ */
+
 @Name("userAction")
 @Stateless
 @AutoCreate
@@ -39,10 +46,15 @@
 
 	@In(value="entityManager")
 	EntityManager em;
-	@In FlushStrategy flushStrategy;
-	@In
-	private User user;
+	
+	@In private User user;
 
+	/**
+     * Login user. If succes return logged user, otherwise return null
+     * @param username - username
+     * @param password - password
+     * @return user if success
+     */
 	public User login(String username, String password) {
 		return (User)em.createNamedQuery(Constants.USER_LOGIN_QUERY)
 		.setParameter(Constants.USERNAME_PARAMETER, username)
@@ -50,55 +62,85 @@
 		.getSingleResult();
 	}
 
+	/**
+     * Persist user entity to database
+     * @param user - user to register
+     */
 	public void register(User user) {
 		em.persist(user);
-		if(flushStrategy.isDatabaseStoreStrategy()){
-			em.flush();
-		}
+		em.flush();
 	}
 	
+	/**
+     * Synchronize state of user entity with database
+     * @return user if success
+     */
 	public User updateUser() {
-		if(flushStrategy.isDatabaseStoreStrategy()){
-			em.flush();
-		}
+		em.flush();
 		return user;
 	}
 	
-	public User resetUser() {
-		em.refresh(user);
-		if(flushStrategy.isDatabaseStoreStrategy()){
-			em.flush();
-		}
-		return user;
-	}
-	
+	/**
+     * Check if user with specified login already exist
+     * @return is user with specified login already exist
+     */
 	public boolean isUserExist(String login) {
 		return em.createNamedQuery(Constants.USER_EXIST_QUERY)
 		.setParameter(Constants.LOGIN_PARAMETER, login)
 		.getResultList().size() != 0;
 	}
 	
+	/**
+     * Used to retrieve all shared albums, belongs to specified user.
+     * @param user
+     * @return list of shared albums of specified user
+     */
+	@SuppressWarnings("unchecked")
 	public List<Album> getSharedAlbums(User user){
-		return (List<Album>)em.createQuery("from Album a where a.shelf.owner=:user and a.shelf.shared=true").setParameter("user", user).getResultList();
+		return (List<Album>)em.createNamedQuery(Constants.USER_SHARED_ALBUMS_QUERY).setParameter(Constants.USER_PARAMETER, user).getResultList();
 	}
 	
+	/**
+     * Used to retrieve all shared images, belongs to specified user.
+     * @param user
+     * @return list of shared images of specified user
+     */
+	@SuppressWarnings("unchecked")
 	public List<Image> getSharedImages(User user){
-		return (List<Image>)em.createQuery("from Image i where i.album.shelf.owner=:user and i.album.shelf.shared=true").setParameter("user", user).getResultList();
+		return (List<Image>)em.createNamedQuery(Constants.USER_SHARED_IMAGES_QUERY).setParameter(Constants.USER_PARAMETER, user).getResultList();
 	}
 	
+	/**
+     * Used to retrieve count of all albums, belongs to specified user.
+     * @return count of all albums of current user
+     */
 	public Long countAlbums(){
-		return (Long)em.createQuery("select count(a) from Album a where a.shelf.owner=:user").setParameter("user", user).getSingleResult();
+		return (Long)em.createNamedQuery(Constants.USER_COUNT_ALBUMS_QUERY).setParameter(Constants.USER_PARAMETER, user).getSingleResult();
 	}
 	
+	/**
+     * Used to retrieve count of shared albums, belongs to specified user.
+     * @param user
+     * @return count of shared albums of specified user
+     */
 	public Long countSharedAlbums(User user){
-		return (Long)em.createQuery("select count(a) from Album a where a.shelf.owner=:user and a.shelf.shared=true").setParameter("user", user).getSingleResult();
+		return (Long)em.createNamedQuery(Constants.USER_COUNT_SHARED_ALBUMS_QUERY).setParameter(Constants.USER_PARAMETER, user).getSingleResult();
 	}
 	
+	/**
+     * Used to retrieve count of all images, belongs to specified user.
+     * @return count of all images of current user
+     */
 	public Long countImages(){
-		return (Long)em.createQuery("select count(i) from Image i where i.album.shelf.owner=:user").setParameter("user", user).getSingleResult();
+		return (Long)em.createNamedQuery(Constants.USER_COUNT_IMAGES_QUERY).setParameter(Constants.USER_PARAMETER, user).getSingleResult();
 	}
 	
+	/**
+     * Used to retrieve count shared images, belongs to specified user.
+     * @param user
+     * @return count of shared images of specified user
+     */
 	public Long countSharedImages(User user){
-		return (Long)em.createQuery("select count(i) from Image i where i.album.shelf.owner=:user and i.album.shelf.shared=true").setParameter("user", user).getSingleResult();
+		return (Long)em.createNamedQuery(Constants.USER_COUNT_SHARED_IMAGES_QUERY).setParameter(Constants.USER_PARAMETER, user).getSingleResult();
 	}
 }
\ No newline at end of file

Modified: trunk/test-applications/realworld2/ejb/src/main/resources/import.sql
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/resources/import.sql	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/resources/import.sql	2009-04-07 15:51:37 UTC (rev 13408)
@@ -80,7 +80,7 @@
 ---------------------------------------------------------------------
 -- ALBUM - Building
 ---------------------------------------------------------------------
-INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (1, 'Building', 'Building pictures',  2, '2009-12-18');
+INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (1, 'Building', 'Building pictures',  3, '2009-12-18');
 INSERT INTO metatags(metatag_id, tag) VALUES (1,  'Building');
 
 INSERT INTO images(image_id, name, path, description, created, album_id,  cameraModel, width, size, height, uploaded, allowComments) VALUES (16, '1.jpg', 'Viking/1/1.jpg', 'Building - 1.jpg image',  '2009-12-18', 1, 'Nikon D60', 1024, 1917, 768, '2009-12-01', true);
@@ -163,7 +163,7 @@
 ---------------------------------------------------------------------
 -- ALBUM - Coasts
 ---------------------------------------------------------------------
-INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (2, 'Coasts', 'Coasts pictures',  3, '2009-12-18');
+INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (2, 'Coasts', 'Coasts pictures',  4, '2009-12-18');
 INSERT INTO metatags(metatag_id, tag) VALUES (2,  'Coasts');
 
 INSERT INTO images(image_id, name, path, description, created, album_id,  cameraModel, width, size, height, uploaded, allowComments) VALUES (32, '203015.jpg', 'Noname/2/203015.jpg', 'Coasts - 203015.jpg image',  '2009-12-18', 2, 'Pentax Optio E40', 1024, 1917, 768, '2009-12-01', true);
@@ -232,7 +232,7 @@
 ---------------------------------------------------------------------
 -- ALBUM - Flora
 ---------------------------------------------------------------------
-INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (3, 'Flora', 'Flora pictures',  4, '2009-12-18');
+INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (3, 'Flora', 'Flora pictures',  2, '2009-12-18');
 INSERT INTO metatags(metatag_id, tag) VALUES (3,  'Flora');
 
 INSERT INTO images(image_id, name, path, description, created, album_id,  cameraModel, width, size, height, uploaded, allowComments) VALUES (48, '132000.jpg', 'amarkhel/3/132000.jpg', 'Flora - 132000.jpg image',  '2009-12-18', 3, 'BenQ DC E800', 1024, 1917, 768, '2009-12-01', true);
@@ -294,7 +294,7 @@
 ---------------------------------------------------------------------
 -- ALBUM - Ices
 ---------------------------------------------------------------------
-INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (4, 'Ices', 'Ices pictures',  1, '2009-12-18');
+INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (4, 'Ices', 'Ices pictures',  3, '2009-12-18');
 INSERT INTO metatags(metatag_id, tag) VALUES (4,  'Ices');
 
 INSERT INTO images(image_id, name, path, description, created, album_id,  cameraModel, width, size, height, uploaded, allowComments) VALUES (64, '184023.jpg', 'Viking/4/184023.jpg', 'Ices - 184023.jpg image',  '2009-12-18', 4, 'LG LDC-A310', 1024, 1917, 768, '2009-12-01', true);
@@ -390,7 +390,7 @@
 ---------------------------------------------------------------------
 -- ALBUM - Sport
 ---------------------------------------------------------------------
-INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (5, 'Sport', 'Sport pictures',  2, '2009-12-18');
+INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (5, 'Sport', 'Sport pictures',  4, '2009-12-18');
 INSERT INTO metatags(metatag_id, tag) VALUES (5,  'Sport');
 
 INSERT INTO images(image_id, name, path, description, created, album_id,  cameraModel, width, size, height, uploaded, allowComments) VALUES (85, '23048.jpg', 'Noname/5/23048.jpg', 'Sport - 23048.jpg image',  '2009-12-18', 5, 'Olympus Stylus mju 1040', 1024, 1917, 768, '2009-12-01', true);
@@ -461,7 +461,7 @@
 ---------------------------------------------------------------------
 -- ALBUM - Underwater
 ---------------------------------------------------------------------
-INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (6, 'Underwater', 'Underwater pictures',  3, '2009-12-18');
+INSERT INTO albums(album_id, name, description, shelf_id, created) VALUES (6, 'Underwater', 'Underwater pictures',  1, '2009-12-18');
 INSERT INTO metatags(metatag_id, tag) VALUES (6,  'Underwater');
 
 INSERT INTO images(image_id, name, path, description, created, album_id,  cameraModel, width, size, height, uploaded, allowComments) VALUES (101, '45000.jpg', 'amarkhel/6/45000.jpg', 'Underwater - 45000.jpg image',  '2009-12-18', 6, 'Konica Minolta', 1024, 1917, 768, '2009-12-01', true);

Deleted: trunk/test-applications/realworld2/ejb/src/main/resources/realworld.properties
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/resources/realworld.properties	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/ejb/src/main/resources/realworld.properties	2009-04-07 15:51:37 UTC (rev 13408)
@@ -1 +0,0 @@
-flushStrategy=database
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -22,7 +22,6 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import org.jboss.seam.ScopeType;
@@ -40,7 +39,6 @@
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
 import org.richfaces.realworld.service.Constants;
-import org.richfaces.realworld.service.FlushStrategy;
 import org.richfaces.realworld.service.IAlbumAction;
 
 @Name("albumManager")
@@ -68,7 +66,7 @@
 		validationSuccess = true;
 		albumAction.addAlbum(album);
 		fileManager.addDirectory(user.getLogin(), album.getId().toString());
-		model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getShelf().getOwner(), album.getShelf(), album, null);
+		model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getShelf().getOwner(), album.getShelf(), album, null, album.getImages());
 		model.setImages(new ArrayList<Image>());
 		Contexts.getConversationContext().set("album", null);
 		Events.instance().raiseEvent("albumAdded");
@@ -94,19 +92,16 @@
 	@Restrict("#{s:hasRole('admin')}")
 	public void editAlbum(Album album){
 		albumAction.editAlbum(album);
-		model.resetModel(NavigationEnum.ALBUM_PREVIEW, model.getSelectedUser(), model.getSelectedShelf(), album, null);
+		model.resetModel(NavigationEnum.ALBUM_PREVIEW, model.getSelectedUser(), model.getSelectedShelf(), album, null, album.getImages());
 		Events.instance().raiseEvent("albumEdited");
 	}
 	
 	@Restrict("#{s:hasRole('admin')}")
 	public void deleteAlbum(Album album){
-		//Update domain model
-		String string = album.getId().toString();
+		String albumName = album.getId().toString();
 		albumAction.deleteAlbum(album);
-		//TODO nick - should be deleteDirectory(album). And call file manager directly
-		deleteDirectory(string);
-		//TODO nick - why not call just model.setAlbum(null). More: is deleted album the ones currently selected in model?
-		model.resetModel(NavigationEnum.ALL_ALBUMS, model.getSelectedUser(), model.getSelectedShelf(), null, null);
+		fileManager.deleteDirectory(user.getLogin(), albumName);
+		model.resetModel(NavigationEnum.ALL_ALBUMS, model.getSelectedUser(), model.getSelectedShelf(), null, null, null);
 		Events.instance().raiseEvent("albumDeleted");
 		Events.instance().raiseEvent("clearTree");
 	}
@@ -117,10 +112,6 @@
 		}
 		return album.getUnvisitedImages();
 	}
-	
-	private void deleteDirectory(String albumName) {
-		fileManager.deleteDirectory(user.getLogin(), albumName);
-	}
 
 	public boolean isValidationSuccess() {
 		return validationSuccess;

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -45,8 +45,7 @@
 
 @Name("authenticator")
 @Scope(ScopeType.CONVERSATION)
-public class Authenticator implements Serializable
-{
+public class Authenticator implements Serializable{
 
 	@In ShelfManager shelfManager;
 	
@@ -81,8 +80,7 @@
 
 	public String login(){
 		if(identity.hasRole("admin")){
-			//TODO nick - return null
-			return "";
+			return null;
 		}
 		String password = credentials.getPassword();
 		String username = credentials.getUsername();
@@ -90,9 +88,7 @@
 		credentials.setPassword(password);
 		credentials.setUsername(username);
 		try {
-			identity.authenticate();
-			//TODO nick - maybe clearShelves() before trying to aunthenticate?
-			//shelfManager.clearShelfs();		
+			identity.authenticate();		
 		} catch (LoginException e) {
 			setLoginFailed(true);
 			credentials.clear();
@@ -108,7 +104,6 @@
     public boolean authenticate()
     {
     	if (wantLoginAnonymous()) {
-    		//TODO nick - remove another roles?
 			identity.addRole(Constants.GUEST_ROLE);
 			model.setMainArea(NavigationEnum.ANONYM);
 			return true;
@@ -118,7 +113,8 @@
 			user = userAction.login(credentials.getUsername(), passwordHolder.hash(credentials.getPassword()));
 			if (user != null) {
 				identity.addRole(Constants.ADMIN_ROLE);
-				model.resetModel(NavigationEnum.ALL_SHELFS, user, null, null, null);
+				model.resetModel(NavigationEnum.ALL_SHELFS, user, null, null, null, null);
+				setLoginFailed(false);
 				return true;
 			}
 		} catch (Exception nre) {
@@ -171,4 +167,4 @@
 	public void setLoginFailed(boolean loginFailed) {
 		this.loginFailed = loginFailed;
 	}
-}
+}
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Controller.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Controller.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Controller.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -25,10 +25,8 @@
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Synchronized;
 import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.core.Events;
 import org.richfaces.event.DataScrollerEvent;
@@ -60,17 +58,15 @@
 	private User user;
 
 	public void selectShelfs(){
-		//TODO nick - i think model should reset selected albums, etc. internally
-		model.resetModel(NavigationEnum.ALL_SHELFS, user, null, null, null);
+		model.resetModel(NavigationEnum.ALL_SHELFS, user, null, null, null, null);
 	}
 	
 	public void selectAlbums(){
-		model.resetModel(NavigationEnum.ALL_ALBUMS, user, null, null, null);
+		model.resetModel(NavigationEnum.ALL_ALBUMS, user, null, null, null, null);
 	}
 	
 	public void selectImages(){
-		model.resetModel(NavigationEnum.ALL_IMAGES, user, null, null, null);
-		model.setImages(user.getAllImages());
+		model.resetModel(NavigationEnum.ALL_IMAGES, user, null, null, null, user.getAllImages() );
 	}
 	
 	@Restrict("#{s:hasRole('admin')}")
@@ -79,12 +75,11 @@
 			pushEvent(Constants.ADD_ERROR_EVENT, HAVENT_ACCESS);
 			return;
 		}
-		model.resetModel(NavigationEnum.SHELF_EDIT, shelf.getOwner(), shelf, null, null);		
+		model.resetModel(NavigationEnum.SHELF_EDIT, shelf.getOwner(), shelf, null, null, null);		
 	}
 	
 	public void cancelEditShelf(Shelf shelf){
-		//TODO nick - unused "shelf" argument
-		model.setMainArea(NavigationEnum.SHELF_PREVIEW);
+		model.resetModel(NavigationEnum.SHELF_EDIT, shelf.getOwner(), shelf, null, null, null);		
 	}
 
 	public void showAlbum(Album album){
@@ -92,8 +87,7 @@
 			pushEvent(Constants.ADD_ERROR_EVENT, HAVENT_ACCESS);
 			return;
 		}
-		model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getOwner(), album.getShelf(), album, null);	
-		model.setImages(album.getImages());
+		model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getOwner(), album.getShelf(), album, null, album.getImages());	
 	}
 	
 	public void showImage(Image image){
@@ -101,9 +95,7 @@
 			pushEvent(Constants.ADD_ERROR_EVENT, HAVENT_ACCESS);
 			return;
 		}
-		model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, image.getAlbum().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), image);
-		//TODO nick - model should already has enough information to set up image index
-		model.setSelectedImageIndex(model.getSelectedAlbum().getIndex(model.getSelectedImage())+1);
+		model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, image.getAlbum().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), image, image.getAlbum().getImages());
 		image.getAlbum().visitImage(image, true);
 	}
 	
@@ -111,7 +103,7 @@
 		Integer index = e.getPage();
 		model.setSelectedImageIndex(index);
 		Image image = model.getSelectedAlbum().getImages().get(index - 1);
-		model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, image.getAlbum().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), image);
+		model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, image.getAlbum().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), image, image.getAlbum().getImages());
 		image.getAlbum().visitImage(image, true);
 	}
 	
@@ -121,44 +113,41 @@
 			pushEvent(Constants.ADD_ERROR_EVENT, HAVENT_ACCESS);
 			return;
 		}
-		//TODO nick - resetModel?
-		model.setMainArea(NavigationEnum.ALBUM_IMAGE_EDIT);
+		model.resetModel(NavigationEnum.ALBUM_IMAGE_EDIT, image.getAlbum().getShelf().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), image, image.getAlbum().getImages());		
 	}
 	
 	@Restrict("#{s:hasRole('admin')}")
 	public void editUser(){
 		userManager.editUser();
-		model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage());
+		model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage(), model.getImages());
 	}
 	
 	public void cancelEditUser(){
 		userManager.cancelEditUser();
-		model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage());
+		model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage(), model.getImages());
 	}
 	
 	public void cancelEditImage(Image image){
-		//TODO nick - unused image argument
-		model.setMainArea(NavigationEnum.ALBUM_IMAGE_PREVIEW);
+		model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, image.getAlbum().getShelf().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), image, image.getAlbum().getImages() );		
 	}
 	
-	@Observer("resetModel")
+	/*@Observer("resetModel")
 	public void resetModel(){
 		if(user.getId() != null){
 			model.resetModel(NavigationEnum.ALL_SHELFS, user, null, null, null);
 		}else{
 			model.resetModel(NavigationEnum.ANONYM, user, null, null, null);
 		}
-	}
+	}*/
 	
 	public void showShelf(Shelf shelf){
-		model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null);
+		model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null, null);
 	}
 	
 	public boolean isUserImage(Image image){
 		if(image == null || image.getAlbum() == null || image.getAlbum().getOwner() == null){
 			return false;
 		}
-		//TODO nick - compare User objects?
 		return image.getAlbum().getOwner().getLogin().equals(user.getLogin());
 	}
 	
@@ -168,16 +157,11 @@
 			pushEvent(Constants.ADD_ERROR_EVENT, HAVENT_ACCESS);
 			return;
 		}
-		//TODO nick - resetModel?
-		model.setSelectedAlbum(album);
-		model.setImages(album.getImages());
-		model.setMainArea(NavigationEnum.ALBUM_EDIT);
+		model.resetModel(NavigationEnum.ALBUM_EDIT, album.getShelf().getOwner(), album.getShelf(), album, null, album.getImages());
 	}
 	
 	public void cancelEditAlbum(Album album){
-		//TODO nick - unused "album" argument
-		model.setMainArea(NavigationEnum.ALBUM_PREVIEW);
-		model.setImages(album.getImages());
+		model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getShelf().getOwner(), album.getShelf(), album, null, album.getImages());
 	}
 	
 	public void showFileUpload(){
@@ -185,25 +169,22 @@
 			Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, "You must create at least one shelf before creating album!");
 			return;
 		}
-		model.setMainArea(NavigationEnum.FILE_UPLOAD);
+		model.resetModel(NavigationEnum.FILE_UPLOAD, model.getSelectedUser(), model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage(), model.getImages());
 	}	
 	
 	public void showFileUpload(Album album){
-		model.setSelectedAlbum(album);
-		model.setMainArea(NavigationEnum.FILE_UPLOAD);
+		model.resetModel(NavigationEnum.FILE_UPLOAD, album.getShelf().getOwner(), album.getShelf(), album, null, album.getImages());
 	}
 	
 	public void showSharedAlbums(User user){
-		model.resetModel(NavigationEnum.USER_SHARED_ALBUMS, user, null, null, null);
+		model.resetModel(NavigationEnum.USER_SHARED_ALBUMS, user, null, null, null, userManager.getSharedImages(model.getSelectedUser()));
 	}
 	
 	public void showSharedImages(User user){
-		model.resetModel(NavigationEnum.USER_SHARED_IMAGES, user, null, null, null);
-		model.setImages(userManager.getSharedImages(model.getSelectedUser()));
+		model.resetModel(NavigationEnum.USER_SHARED_IMAGES, user, null, null, null, userManager.getSharedImages(model.getSelectedUser()));
 	}
 	
 	public boolean isUserShelf(Shelf shelf){
-		//TODO nick - compare User objects?
 		return shelf.getOwner()!=null && shelf.getOwner().getLogin().equals(user.getLogin());
 	}
 	
@@ -211,29 +192,24 @@
 		if(album == null || album.getOwner() == null){
 			return false;
 		}
-		//TODO nick - compare User objects?
 		return album.getOwner().getLogin().equals(user.getLogin());
 	}
 	
 	public void showUser(User user){
-		model.resetModel(NavigationEnum.USER_PREFS, user, null, null, null);
+		model.resetModel(NavigationEnum.USER_PREFS, user, null, null, null, null);
 	}
 	
 	public void showUnvisitedImages(Shelf shelf){
-		model.resetModel(NavigationEnum.SHELF_UNVISITED, shelf.getOwner(), shelf, null, null);
-		model.setImages(shelfManager.getUnvisitedImages(shelf));
+		model.resetModel(NavigationEnum.SHELF_UNVISITED, shelf.getOwner(), shelf, null, null, shelfManager.getUnvisitedImages(shelf));
 	}
 	
 	public void showUnvisitedImages(Album album){
-		model.resetModel(NavigationEnum.ALBUM_UNVISITED, album.getShelf().getOwner(), album.getShelf(), album, null);
-		model.setImages(albumManager.getUnvisitedImages(album));
+		model.resetModel(NavigationEnum.ALBUM_UNVISITED, album.getShelf().getOwner(), album.getShelf(), album, null, albumManager.getUnvisitedImages(album));
 	}
 
 	public void showTag(MetaTag metatag){
-		//TODO nick - model.setMainArea()?
-		model.resetModel(NavigationEnum.TAGS, model.getSelectedUser(), model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage());
+		model.resetModel(NavigationEnum.TAGS, model.getSelectedUser(), model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage(), metatag.getImages());
 		model.setSelectedTag(metatag);
-		model.setImages(metatag.getImages());
 	}
 	
 	private boolean canViewShelf(Shelf shelf) {
@@ -256,8 +232,7 @@
 		if(selectedUser == null){
 			return false;
 		}
-		//TODO nick - equals()?
-		if(selectedUser == user){
+		if(selectedUser.getLogin().equals(user.getLogin())){
 			return true;
 		}
 		return false;

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -20,8 +20,6 @@
  */
 package org.richfaces.realworld.manager;
 
-import java.util.ArrayList;
-
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.security.Restrict;
@@ -34,7 +32,6 @@
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
 import org.richfaces.realworld.service.Constants;
-import org.richfaces.realworld.service.FlushStrategy;
 import org.richfaces.realworld.service.IAlbumAction;
 
 @Name("dndManager")
@@ -56,13 +53,15 @@
 				}
 				handleImage((Image)dragValue, (Album)dropValue);	
 		}else if(dragValue instanceof Album){
-			//TODO nick - check user
+			if(!((Shelf)dropValue).getOwner().getLogin().equals(user.getLogin())){
+				Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, "You can't add album to that shelf");
+				return;
+			}
 			handleAlbum((Album)dragValue, (Shelf)dropValue);
 		}
 	}
 
 	private void handleAlbum(Album dragValue, Shelf dropValue) {
-		//TODO nick - add check for the current shelf
 		dropValue.addAlbum(dragValue);
 		albumAction.editAlbum(dragValue);
 		Events.instance().raiseEvent("clearTree");
@@ -72,7 +71,7 @@
 		if(dragValue.getAlbum().equals(dropValue)){
 			return;
 		}
-		String newPath = getNewPathOfImage(dragValue, dropValue);
+		String newPath = generateNewPathOfImage(dragValue, dropValue);
 		dragValue.setPath(newPath);
 		dropValue.addImage(dragValue);
 		albumAction.editAlbum(dropValue);
@@ -80,13 +79,11 @@
 		
 	}
 
-	private String getNewPathOfImage(Image dragValue, Album dropValue) {
+	private String generateNewPathOfImage(Image dragValue, Album dropValue) {
 		String fileNameOld = dragValue.getPath();
-		//TODO nick - is "/" correct for windows?
-		int lastIndexOf = dragValue.getPath().lastIndexOf("/");
+		int lastIndexOf = dragValue.getPath().lastIndexOf(Constants.SLASH);
 		String prevPathEnd = dragValue.getPath().substring(lastIndexOf);
-		//TODO nick - file manager should handle naming!!!
-		String fileNameNew = user.getLogin()+"/"+dropValue.getId()+"/"+prevPathEnd;
+		String fileNameNew = user.getLogin()+Constants.SLASH+dropValue.getId()+Constants.SLASH+prevPathEnd;
 		fileManager.renameImage(fileNameOld, fileNameNew);
 		return fileNameNew;
 	}

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -20,36 +20,32 @@
  */
 package org.richfaces.realworld.manager;
 
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.AutoCreate;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.security.Restrict;
-import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.service.Constants;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.ImageWriter;
-import javax.imageio.stream.ImageInputStream;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
 import java.awt.Transparency;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.zip.ZipEntry;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
 
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageInputStream;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.security.Restrict;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.Constants;
+
 @Name("fileManager")
 @Scope(ScopeType.APPLICATION)
 @AutoCreate

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -31,7 +31,6 @@
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.security.Restrict;
@@ -66,11 +65,8 @@
 
     @Restrict("#{s:hasRole('admin')}")
     public void deleteImage(Image image) {
-    	//TODO nick - should we check image owner?
         String imagePath = image.getPath();
-        model.resetModel(NavigationEnum.ALBUM_PREVIEW, image.getAlbum().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), null);
-        
-        //TODO nick - imageAction can call file manager itself
+        model.resetModel(NavigationEnum.ALBUM_PREVIEW, image.getAlbum().getOwner(), image.getAlbum().getShelf(), image.getAlbum(), null, image.getAlbum().getImages());
         imageAction.deleteImage(image);
         fileManager.deleteImage(imagePath);
         Events.instance().raiseEvent("imageDeleted");
@@ -84,15 +80,6 @@
     }
 
     @Restrict("#{s:hasRole('admin')}")
-    //TODO nick - Constants.ADD_IMAGE_EVENT is not used anywhere else
-    @Observer(Constants.ADD_IMAGE_EVENT)
-    public void addImage(Image image) {
-        imageAction.addImage(image);
-        model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, model.getSelectedUser(), model.getSelectedShelf(), image.getAlbum(), image);
-        Events.instance().raiseEvent("imageAdded");
-    }
-
-    @Restrict("#{s:hasRole('admin')}")
     public void addComment(Image image, String message) {
         if (null == user.getLogin()) {
             Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, "For vote on this picture you must login");

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -22,7 +22,7 @@
 public class Model implements Serializable{
 
 	private static final long serialVersionUID = -1767281809514660171L;
-	private Integer selectedImageIndex = 1;
+	private Integer selectedImageIndex = 0;
 	
 	private Image selectedImage;
 
@@ -38,12 +38,14 @@
 	
 	private List<Image> images;
 	
-	public void resetModel(NavigationEnum mainArea, User selectedUser, Shelf selectedShelf, Album selectedAlbum, Image selectedImage){
+	public void resetModel(NavigationEnum mainArea, User selectedUser, Shelf selectedShelf, Album selectedAlbum, Image selectedImage, List<Image> images){
 		this.setMainArea(mainArea);
 		this.setSelectedAlbum(selectedAlbum);
 		this.setSelectedImage(selectedImage);
 		this.setSelectedShelf(selectedShelf);
 		this.setSelectedUser(selectedUser);
+		this.images = images;
+		this.setSelectedImageIndex(this.getSelectedAlbum().getIndex(this.getSelectedImage())+1);
 	}
 	
 	@Observer(Constants.UPDATE_MAIN_AREA_EVENT)

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -18,7 +18,6 @@
 import org.jboss.seam.security.Identity;
 import org.richfaces.realworld.domain.User;
 import org.richfaces.realworld.service.Constants;
-import org.richfaces.realworld.service.FlushStrategy;
 import org.richfaces.realworld.service.IUserAction;
 import org.richfaces.realworld.ui.PasswordHolder;
 

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -38,7 +38,6 @@
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.service.FlushStrategy;
 import org.richfaces.realworld.service.IShelfAction;
 
 @Name("shelfManager")
@@ -72,7 +71,7 @@
     public void addShelf(Shelf shelf) {
     	validationSuccess = true;
         shelfAction.addShelf(shelf);
-        model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null);
+        model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null, null);
         Events.instance().raiseEvent("clearTree");
     }
 
@@ -83,7 +82,7 @@
     @Restrict("#{s:hasRole('admin')}")
     public void editShelf(Shelf shelf) {
         shelfAction.editShelf(shelf);
-        model.resetModel(NavigationEnum.SHELF_PREVIEW, model.getSelectedUser(), shelf, null, null);
+        model.resetModel(NavigationEnum.SHELF_PREVIEW, model.getSelectedUser(), shelf, null, null, null);
     }
 
     @Restrict("#{s:hasRole('admin')}")
@@ -95,7 +94,7 @@
         }
         shelfAction.deleteShelf(shelf);
         deleteDirectories(directoriesToDelete);
-        model.resetModel(NavigationEnum.ALL_SHELFS, model.getSelectedUser(), null, null, null);
+        model.resetModel(NavigationEnum.ALL_SHELFS, model.getSelectedUser(), null, null, null, null);
         Events.instance().raiseEvent("shelfDeleted");
         Events.instance().raiseEvent("clearTree");
     }

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/SlideshowManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/SlideshowManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/SlideshowManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -21,7 +21,6 @@
 package org.richfaces.realworld.manager;
 
 import java.io.Serializable;
-import java.util.List;
 
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.In;
@@ -116,7 +115,6 @@
 		if(slideshowIndex == model.getImages().size() - 1){
 			slideshowIndex = -1;
 		}
-		//TODO nick - this will start slideshow from the 2nd image (slideshowIndex == 1)
 		slideshowIndex++;
 		selectedImage = model.getImages().get(slideshowIndex);
 		this.selectedImage.getAlbum().visitImage(selectedImage, true);

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/TreeManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/TreeManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/TreeManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -8,9 +8,6 @@
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
 import org.richfaces.component.UITree;
-import org.richfaces.realworld.domain.Album;
-import org.richfaces.realworld.domain.Shelf;
-import org.richfaces.realworld.domain.User;
 
 @Name("treeManager")
 @Scope(ScopeType.EVENT)
@@ -22,25 +19,9 @@
 	@SuppressWarnings("unchecked")
 	public Boolean adviseNodeSelected(UITree tree) {
 		Object currentNode = tree.getRowData();
-		//TODO nick - cast not neccessary: if currentNode.equals(model.getSelectedAlbum() || ...)
-		if (currentNode instanceof Album) {
-			boolean selected = currentNode == model.getSelectedAlbum();
-			return selected;
-		}else if(currentNode instanceof Shelf){
-			return currentNode == model.getSelectedShelf() && model.getSelectedAlbum() == null;
+		if(currentNode.equals(model.getSelectedAlbum()) || currentNode.equals(model.getSelectedShelf())){
+			return true;
 		}
 		return null;
 	}
-
-	@SuppressWarnings("unchecked")
-	public Boolean adviseNodeOpened(UITree tree) {
-		Object currentNode = tree.getRowData();
-		if (currentNode instanceof Album) {
-			boolean selected = currentNode == model.getSelectedAlbum();
-			return selected;
-		}else if(currentNode instanceof Shelf){
-			return currentNode == model.getSelectedShelf();
-		}
-		return null;
-	}
 }

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/UserManager.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/UserManager.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -31,7 +31,6 @@
 import org.jboss.seam.annotations.Observer;
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.core.Events;
 import org.richfaces.realworld.domain.Album;
 import org.richfaces.realworld.domain.Image;
@@ -46,7 +45,7 @@
 	
 	private static final long serialVersionUID = 6027103521084558931L;
 	
-	@In(scope=ScopeType.CONVERSATION) @Out(scope=ScopeType.CONVERSATION) private User user;
+	@In(scope=ScopeType.SESSION) @Out(scope=ScopeType.SESSION) private User user;
 	@In FileManager fileManager;
 	@In(required=false, scope=ScopeType.CONVERSATION) @Out(required=false, scope=ScopeType.CONVERSATION) private File avatarData;
 	@In private IUserAction userAction;

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ISearchOption.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ISearchOption.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ISearchOption.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -3,7 +3,6 @@
  */
 package org.richfaces.realworld.search;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import org.richfaces.realworld.service.ISearchAction;

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ImageSearchHelper.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ImageSearchHelper.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/ImageSearchHelper.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -72,7 +72,6 @@
 		while (it.hasNext()) {
 			ISearchOption option = it.next();
 			if (option.getSelected()) {
-				//TODO nick - use search(keyword)
 				option.search(searchAction, selectedKeyword , seachInMyAlbums, searchInShared);
 			}
 		}

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByAlbum.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByAlbum.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByAlbum.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -6,7 +6,6 @@
 import java.util.Map;
 
 import org.richfaces.realworld.domain.Album;
-import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.service.ISearchAction;
 
 

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByShelf.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByShelf.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByShelf.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -6,7 +6,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.Shelf;
 import org.richfaces.realworld.service.ISearchAction;
 

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByTag.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByTag.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByTag.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -6,8 +6,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.richfaces.realworld.domain.Album;
-import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.domain.MetaTag;
 import org.richfaces.realworld.service.ISearchAction;
 

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByUser.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByUser.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/search/SearchOptionByUser.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -6,8 +6,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.domain.MetaTag;
 import org.richfaces.realworld.domain.User;
 import org.richfaces.realworld.service.ISearchAction;
 

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/startup/CopyImageStuff.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/startup/CopyImageStuff.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/startup/CopyImageStuff.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -53,11 +53,9 @@
 	
 	@Destroy
 	public void destroy()throws IOException {
-		//TODO nick - delete even data is stored in DB?
 		FileUtils.deleteDirectory(uploadRoot);
 	}
 	
-	
 	void resolveImageFolder() {
 		//TODO nick - what this cast is for?
 		URLClassLoader loader = (URLClassLoader)getClass().getClassLoader();
@@ -103,11 +101,8 @@
 		}
 	}
 	
-	
 	void copyImages()throws IOException {
 		FileUtils.copyDirectory(new File(imageSrc), uploadRoot);
 	}
 
-	
-
-}
+}
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ConfirmationPopupHelper.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ConfirmationPopupHelper.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ConfirmationPopupHelper.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -105,4 +105,4 @@
 		imageManager.deleteImage(this.image);
 	}
 	
-}
+}
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -53,4 +53,4 @@
 		this.liveUpdatesEnabled = liveUpdatesEnabled;
 	}	
 	
-}
+}
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -22,7 +22,6 @@
 package org.richfaces.realworld.ui;
 
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
@@ -39,15 +38,11 @@
 import org.richfaces.model.UploadItem;
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.manager.FileManager;
-import org.richfaces.realworld.manager.ImageManager;
 import org.richfaces.realworld.manager.Model;
-import org.richfaces.realworld.manager.NavigationEnum;
 import org.richfaces.realworld.service.Constants;
-import org.richfaces.realworld.service.FlushStrategy;
 import org.richfaces.realworld.service.IImageAction;
 
 import com.drew.imaging.jpeg.JpegMetadataReader;
-import com.drew.imaging.jpeg.JpegProcessingException;
 import com.drew.metadata.Directory;
 import com.drew.metadata.Metadata;
 import com.drew.metadata.MetadataException;
@@ -74,44 +69,32 @@
 
 	@In Model model;
 	@In private FileManager fileManager;
-
-	@In("#{messages['samplename']}")
-	private String SAMPLE_NAME;
-
-	@In("#{messages['sampledesc']}")
-	private String SAMPLE_DESCRIPTION;
 	
 	private static final long serialVersionUID = 4969087557225414955L;
 
 	@Restrict("#{s:hasRole('admin')}")
-	public synchronized void listener(UploadEvent event) throws Exception {
+	public void listener(UploadEvent event) throws Exception {
 		UploadItem item = event.getUploadItem();
 		Image image = constructImage(item);
 		try {
 			extractMetadata(item, image);
-		} catch (JpegProcessingException e1) {
+		} catch (Exception e1) {
 			Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, FILE_PROCESSING_ERROR);
 			return;
-		} catch (MetadataException me) {
-			Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, FILE_PROCESSING_ERROR);
-			return;
 		}
 		image.setAlbum(model.getSelectedAlbum());
 		if(model.getSelectedAlbum() == null){
 			Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, "Please specify album to download");
 			return;
 		}
-		String newPath = "/" +model.getSelectedAlbum().getOwner().getLogin() + "/" + model.getSelectedAlbum().getId() + "/" +item.getFileName();
+		String newPath = Constants.SLASH + model.getSelectedAlbum().getOwner().getLogin() + Constants.SLASH + model.getSelectedAlbum().getId() + Constants.SLASH +item.getFileName();
 		image.setPath(newPath);
-		
-		//TODO nick - file manager should be protected from another users accessing images of another people
 		if(!fileManager.addImage(newPath, item.getFile().getPath())){
 			Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, FILE_SAVE_ERROR);
 			item.getFile().delete();
 			return;
 		}
 		fileWrapper.getFiles().add(0, image);
-		//TODO nick - what's the point of storing image if image file save failed?
 		imageAction.addImage(image);
 		Events.instance().raiseEvent("imageAdded");
 		item.getFile().delete();
@@ -120,7 +103,7 @@
 	private Image constructImage(UploadItem item) {
 		Image image = new Image();
 		image.setUploaded(new Date());
-		image.setDescription(SAMPLE_DESCRIPTION);
+		image.setDescription(item.getFileName());
 		image.setName(item.getFileName());
 		image.setSize(item.getFileSize());
 		image.setAllowComments(true);
@@ -128,16 +111,21 @@
 	}
 	
 	private void extractMetadata(UploadItem item, Image image)
-			throws JpegProcessingException, MetadataException, IOException {
-		InputStream in = new FileInputStream(item.getFile());
-		//TODO nick - close "in"?
+			throws RuntimeException, IOException {
+		InputStream in =null;
+		try{
+		in = new FileInputStream(item.getFile());
 		Metadata metadata = JpegMetadataReader.readMetadata(in);
 		Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
 		Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
 		setupCameraModel(image, exifDirectory);
 		setupDimensions(image, exifDirectory, jpgDirectory);
 		setupCreatedDate(image, exifDirectory);
-		in.close();
+		}catch(Exception e){
+			throw new RuntimeException();
+		}finally{
+			in.close();
+		}
 	}
 
 	private void setupCreatedDate(Image image, Directory exifDirectory)

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageSizeHelper.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageSizeHelper.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageSizeHelper.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -17,7 +17,6 @@
 
 	static final int DEFAULT_VALUE = 120;
 
-	//TODO nick - why not use dimension.x?
 	int value = DEFAULT_VALUE;
 
 	public static enum ImageDimension {
@@ -39,10 +38,8 @@
 			this.x = x;
 			this.bgStyle = String.format(IMAGE_BG_STYLE, x + 20);
 			cssClass = CSS_CLASS + x;
-			//TODO nick - what if x == 160?
 			imageBgSrc = String.format(IMAGE_BG, (x == 160) ? 200 : x);
 			filePostfix = FILE_POSTFIX + x;
-
 		}
 
 		public int getX() {
@@ -72,8 +69,6 @@
 					return all[i];
 				}
 			}
-			
-			//TODO nick - does enum really have 120th value?
 			return values()[DEFAULT_VALUE];
 		}
 	};
@@ -92,5 +87,4 @@
 		currentDimension = ImageDimension.getInstance(value);
 		this.value = currentDimension.x;
 	}
-
-}
+}
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -16,8 +16,6 @@
 import org.richfaces.event.UploadEvent;
 import org.richfaces.model.UploadItem;
 import org.richfaces.realworld.domain.Sex;
-import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.manager.Model;
 import org.richfaces.realworld.service.IUserAction;
 
 /**

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -10,13 +10,17 @@
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.security.Credentials;
 import org.jboss.seam.security.Identity;
 import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.service.Constants;
 
 @Name("directLink")
 @Scope(ScopeType.EVENT)
 @AutoCreate
 public class DirectLinkHelper {
+	private static final String DEFAULT_PICTURE = "default/noimage.jpg";
+
 	@In(value="entityManager")
 	protected EntityManager em;
 	
@@ -24,16 +28,17 @@
 	
 	@In Identity identity;
 	
-	public synchronized void paintImage(OutputStream out, Object data)
+	@In Credentials credentials;
+	
+	public void paintImage(OutputStream out, Object data)
 			throws IOException, RealworldException {
-		Long id=Long.valueOf(data.toString());
+		Long id = Long.valueOf(data.toString());
 		Image im = em.find(Image.class, id);
 		if(im == null || im.getAlbum() == null || im.getAlbum().getShelf() == null){
-			imageLoader.paintImage(out, "default/noimage.jpg");
+			imageLoader.paintImage(out, DEFAULT_PICTURE);
 			return;
 		}
-		//TODO nick - '&&' so only admins can see their own unshared images?
-		if(im.getAlbum().getShelf().isShared() || (identity.hasRole("admin") && im.getAlbum().getOwner().getLogin().equals(identity.getUsername()))){
+		if(im.getAlbum().getShelf().isShared() || (identity.hasRole(Constants.ADMIN_ROLE) && im.getAlbum().getOwner().getLogin().equals(credentials.getUsername()))){
 			imageLoader.paintImage(out, im.getPath());
 		}else{
 			return;

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ErrorHandlerBean.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ErrorHandlerBean.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ErrorHandlerBean.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -23,9 +23,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.context.AjaxContext;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.Name;
@@ -54,10 +51,6 @@
 	
 	@Observer(Constants.ADD_ERROR_EVENT)
 	public void addToErrors(String e){
-		FacesContext context = FacesContext.getCurrentInstance();
-		AjaxContext ac = AjaxContext.getCurrentInstance(context);
-		//TODO nick - should add to AjaxContext#getAjaxAreasToRender()
-		ac.addRenderedArea(Constants.ERROR_ID);
 		errors.add(e);
 	}
 }

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileUtils.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileUtils.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileUtils.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -3,198 +3,50 @@
 import java.io.*;
 import java.util.zip.*;
 
-
-/**
- * Command line program to copy a file to another directory.
- *
- * @author Marco Schmidt
- */
-
-//TODO nick - COPYRIGHT!!!
 public class FileUtils {
-    // constant values for the override option
-    public static final int OVERWRITE_ALWAYS = 1;
-    public static final int OVERWRITE_NEVER = 2;
-    public static final int OVERWRITE_ASK = 3;
 
-    // program options initialized to default values
     private static final int BUFFER_SIZE = 4 * 1024;
     private static final boolean CLOCK = true;
-    private static final boolean COPY_ORIGINAL_TIMESTAMP = true;
     private static final boolean VERIFY = true;
-    private static final int OVERRIDE = OVERWRITE_ASK;
 
-    public static Long copyFile(File srcFile, File destFile) throws IOException {
+    public static void copyFile(File srcFile, File destFile) throws IOException {
         if (!srcFile.getPath().toLowerCase().endsWith("jpg") && !srcFile.getPath().toLowerCase().endsWith("jpeg")) {
-            //TODO nick - should be return null
-            return -1L;
+            return;
         }
         final InputStream in = new FileInputStream(srcFile);
         final OutputStream out = new FileOutputStream(destFile);
-        long millis = System.currentTimeMillis();
-        CRC32 checksum;
-        if (VERIFY) {
-            checksum = new CRC32();
-            checksum.reset();
-        }
-        final byte[] buffer = new byte[BUFFER_SIZE];
-        int bytesRead = in.read(buffer);
-        while (bytesRead >= 0) {
+        try{
+            long millis = System.currentTimeMillis();
+            CRC32 checksum;
             if (VERIFY) {
-                checksum.update(buffer, 0, bytesRead);
+                checksum = new CRC32();
+                checksum.reset();
             }
-            out.write(buffer, 0, bytesRead);
-            bytesRead = in.read(buffer);
-        }
-
-        //TODO nick - this should be in finally block
-        out.close();
-        in.close();
-        if (CLOCK) {
-            millis = System.currentTimeMillis() - millis;
-            System.out.println("Copy file '" + srcFile.getPath() + "' on " + millis / 1000L + " second(s)");
-        }
-        if (VERIFY) {
-            return checksum.getValue();
-        } else {
-            return null;
-        }
-    }
-
-    public static Long createChecksum(File file) throws IOException {
-        long millis = System.currentTimeMillis();
-        final InputStream in = new FileInputStream(file);
-        final CRC32 checksum = new CRC32();
-        checksum.reset();
-        final byte[] buffer = new byte[BUFFER_SIZE];
-        int bytesRead = in.read(buffer);
-        while (bytesRead >= 0) {
-            checksum.update(buffer, 0, bytesRead);
-            bytesRead = in.read(buffer);
-        }
-        in.close();
-        if (CLOCK) {
-            millis = System.currentTimeMillis() - millis;
-            System.out.println("Checksum for file '" + file.getPath() + "' created on " + millis / 1000L + " second(s)");
-        }
-        return checksum.getValue();
-    }
-
-    /**
-     * Determine if data is to be copied to given file. Take into consideration
-     * override option and ask user in case file exists and override option is
-     * ask.
-     *
-     * @param file File object for potential destination file
-     * @return true if data is to be copied to file, false if not
-     */
-    public static boolean doCopy(File file) {
-        final boolean exists = file.exists();
-        if (OVERRIDE == OVERWRITE_ALWAYS || !exists) {
-            return true;
-        } else if (OVERRIDE == OVERWRITE_NEVER) {
-            return false;
-        } else if (OVERRIDE == OVERWRITE_ASK) {
-            return readYesNoFromStandardInput("File exists. Overwrite (y/n)?");
-        } else {
-            throw new InternalError("Program error. Invalid "
-                    + "value for override: " + OVERRIDE);
-        }
-    }
-
-    public static void main(String[] args) throws IOException {
-        // make sure there are exactly two arguments
-        if (args.length != 2) {
-            System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
-            System.exit(1);
-        }
-        // make sure the source file is indeed a readable file
-        final File srcFile = new File(args[0]);
-        if (!srcFile.isFile() || !srcFile.canRead()) {
-            System.err.println("Not a readable file: " + srcFile.getName());
-            System.exit(1);
-        }
-        // make sure the second argument is a directory
-        final File destDir = new File(args[1]);
-        if (!destDir.isDirectory()) {
-            System.err.println("Not a directory: " + destDir.getName());
-            System.exit(1);
-        }
-        // create File object for destination file
-        final File destFile = new File(destDir, srcFile.getName());
-
-        // check if copying is desired given overwrite option
-        if (!doCopy(destFile)) {
-            return;
-        }
-
-        // copy file, optionally creating a checksum
-        final Long checksumSrc = copyFile(srcFile, destFile);
-
-        // copy timestamp of last modification
-        if (COPY_ORIGINAL_TIMESTAMP) {
-            if (!destFile.setLastModified(srcFile.lastModified())) {
-                System.err.println("Error: Could not set timestamp of copied file.");
-            }
-        }
-
-        // optionally verify file
-        if (VERIFY) {
-            System.out.print("Verifying destination file...");
-            final Long checksumDest = createChecksum(destFile);
-            if (checksumSrc.equals(checksumDest)) {
-                System.out.println(" OK, files are equal.");
-            } else {
-                System.out.println(" Error: Checksums differ.");
-            }
-        }
-    }
-
-    /**
-     * Print a message to standard output and read lines from standard input
-     * until yes or no (y or n) is entered.
-     *
-     * @param message informative text to be answered by user
-     * @return user answer, true for yes, false for no.
-     */
-    public static boolean readYesNoFromStandardInput(String message) {
-        System.out.println(message);
-        final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
-
-        try {
-            Boolean answer = null;
-
-            String line = in.readLine();
-            while (line != null) {
-                line = line.toLowerCase();
-                if ("y".equals(line) || "yes".equals(line)) {
-                    answer = Boolean.TRUE;
-                    break;
-                } else if ("n".equals(line) || "no".equals(line)) {
-                    answer = Boolean.FALSE;
-                    break;
-                } else {
-                    System.out.println("Could not understand answer (\"" + line
-                            + "\"). Please use y for yes or n for no.");
+            final byte[] buffer = new byte[BUFFER_SIZE];
+            int bytesRead = in.read(buffer);
+            while (bytesRead >= 0) {
+                if (VERIFY) {
+                    checksum.update(buffer, 0, bytesRead);
                 }
-
-                line = in.readLine();
+                out.write(buffer, 0, bytesRead);
+                bytesRead = in.read(buffer);
             }
-            if (answer == null) {
-                throw new IOException("Unexpected end of input from stdin.");
+            if (CLOCK) {
+                millis = System.currentTimeMillis() - millis;
+                System.out.println("Copy file '" + srcFile.getPath() + "' on " + millis / 1000L + " second(s)");
             }
+        }catch(IOException e){
+        	throw e;
+        }finally{
+        	out.close();
             in.close();
-            return answer;
-        } catch (IOException ioe) {
-            throw new InternalError(
-                    "Cannot read from stdin or write to stdout.");
         }
+        
     }
 
     public static void copyDirectory(File srcDir, File dstDir)
             throws IOException {
 
-        //TODO nick - skip hidden/system directories
         if (".svn".equals(srcDir.getName())) {
             return;
         }
@@ -212,12 +64,15 @@
         }
     }
 
-    public static void deleteDirectory(File dir) throws IOException {
+    public static void deleteDirectory(File dir){
         if (dir.isDirectory()) {
             if (dir.exists()) {
                 for (File child : dir.listFiles()) {
-                    //TODO nick - add try/finally so that deletion continues if something failed
-                    deleteDirectory(child);
+                	try{
+                		deleteDirectory(child);
+                	}catch(Exception e){
+                		continue;
+                	}
                 }
             }
 
@@ -230,5 +85,4 @@
         }
         dir.delete();
     }
-
 }
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java	2009-04-07 14:06:39 UTC (rev 13407)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -20,32 +20,21 @@
  */
 package org.richfaces.realworld.util;
 
-import java.awt.image.BufferedImage;
-import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Serializable;
-import java.util.Iterator;
 
 import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.ImageWriter;
 import javax.imageio.stream.ImageInputStream;
 import javax.imageio.stream.ImageOutputStream;
 
-import org.apache.commons.collections.BufferUtils;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.core.Events;
 import org.richfaces.realworld.manager.FileManager;
-import org.richfaces.realworld.service.Constants;
 
 @Name("imageLoader")
 @Scope(ScopeType.EVENT)
@@ -56,11 +45,7 @@
 
     @In
     FileManager fileManager;
-    @In("#{messages['file_processing_error']}")
-    private String FILE_PROCESSING_ERROR;
 
-    //TODO nick - synchronized would make this a bottleneck, especially considering that this method
-    //			  consumes plenty of CPU time
     public void paintImage(OutputStream out, Object data) throws IOException {
         if (null == data) {
             return;
@@ -88,10 +73,6 @@
 				inputStream.close();
 			}
                	
-        }else{
-        	Events.instance().raiseEvent("stopSlideshow");
-        	Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, "Images was deleted. Sorry");
-        	Events.instance().raiseEvent("resetModel");
         }
     }
 }

Added: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/SessionListener.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/SessionListener.java	                        (rev 0)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/SessionListener.java	2009-04-07 15:51:37 UTC (rev 13408)
@@ -0,0 +1,35 @@
+package org.richfaces.realworld.util;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.annotations.Transactional;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.manager.FileManager;
+
+ at Scope(ScopeType.SESSION)
+ at Name("sessionListener")
+ at Startup
+public class SessionListener {
+
+	@In(required=false) User user;
+	@In(value="entityManager")
+	EntityManager em;
+	@In FileManager fileManager;
+	
+	@Destroy @Transactional @Observer("org.jboss.seam.sessionExpired")
+	public void onDestroy(){
+		if(user.getId() != null && user.getId() > 3){
+			user = em.merge(user);
+			em.remove(user);
+			em.flush();
+			fileManager.deleteDirectory(user.getLogin());
+		}
+	}
+}


Property changes on: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/SessionListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Author Id Revision Date
Name: svn:eol-style
   + native

Added: trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/Upload/default/noimage.jpg
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/Upload/default/noimage.jpg
___________________________________________________________________
Name: svn:mime-type
   + image/jpeg

Added: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/footer.xhtml
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/footer.xhtml
___________________________________________________________________
Name: svn:mime-type
   + application/xhtml+xml

Added: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/header.xhtml
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/header.xhtml
___________________________________________________________________
Name: svn:mime-type
   + application/xhtml+xml

Modified: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/menu.xhtml
===================================================================
(Binary files differ)

Added: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/status.xhtml
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/status.xhtml
___________________________________________________________________
Name: svn:mime-type
   + application/xhtml+xml

Modified: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/tree.xhtml
===================================================================
(Binary files differ)

Added: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/workArea.xhtml
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/realworld2/web/src/main/webapp/includes/index/workArea.xhtml
___________________________________________________________________
Name: svn:mime-type
   + application/xhtml+xml

Modified: trunk/test-applications/realworld2/web/src/main/webapp/layout/template.xhtml
===================================================================
(Binary files differ)




More information about the richfaces-svn-commits mailing list