Author: amarkhel
Date: 2009-03-27 07:34:00 -0400 (Fri, 27 Mar 2009)
New Revision: 13249
Removed:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FlushStrategy.java
Modified:
trunk/test-applications/realworld2/web/META-INF/MANIFEST.MF
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/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/ui/FileUploadBean.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/webapp/WEB-INF/components.xml
trunk/test-applications/realworld2/web/src/main/webapp/includes/album/albumsList.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/fileUploader.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/image/imageEditInfo.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/albumsResult.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/userPrefs.xhtml
Log:
Modified: trunk/test-applications/realworld2/web/META-INF/MANIFEST.MF
===================================================================
--- trunk/test-applications/realworld2/web/META-INF/MANIFEST.MF 2009-03-27 10:44:18 UTC
(rev 13248)
+++ trunk/test-applications/realworld2/web/META-INF/MANIFEST.MF 2009-03-27 11:34:00 UTC
(rev 13249)
@@ -2,7 +2,8 @@
Class-Path: avalon-framework-4.1.3.jar commons-beanutils-1.7.0.jar com
mons-digester-2.0.jar commons-logging-1.1.jar jboss-seam-debug-2.1.0.
SP1.jar jboss-seam-jul-2.1.0.SP1.jar jboss-seam-remoting-2.1.0.SP1.ja
- r jboss-seam-ui-2.1.0.SP1.jar jsf-facelets-1.1.14.jar junit-3.8.jar l
- og4j-1.2.14.jar logkit-1.0.1.jar metadata-extractor-2.4.0-beta1.jar r
- ichfaces-impl-3.3.1-SNAPSHOT.jar richfaces-ui-3.3.1-SNAPSHOT.jar
+ r jboss-seam-ui-2.1.0.SP1.jar jhighlight-1.0.jar jsf-facelets-1.1.14.
+ jar junit-3.8.jar log4j-1.2.14.jar logkit-1.0.1.jar metadata-extracto
+ r-2.4.0-beta1.jar richfaces-impl-3.3.1-SNAPSHOT.jar richfaces-ui-3.3.
+ 1-SNAPSHOT.jar
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -33,8 +33,8 @@
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Shelf;
import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.FlushStrategy;
import org.richfaces.realworld.service.IAlbumAction;
-import org.richfaces.realworld.util.FlushStrategy;
@Name("albumManager")
@Scope(ScopeType.CONVERSATION)
@@ -44,7 +44,6 @@
private static final long serialVersionUID = 2631634926126857691L;
private String oncomplete = ";";
- @In FlushStrategy flushStrategy;
@In private IAlbumAction albumAction;
@In(create=true, required=true) @Out
@@ -61,7 +60,7 @@
facesMessages.add("Shelf must be not-null", null);
return;
}
- albumAction.addAlbum(album, flushStrategy.isDatabaseStoreStrategy());
+ albumAction.addAlbum(album);
addDirectory();
model.resetModel(model.getMainArea(), model.getSelectedUser(),
model.getSelectedShelf(), album, null);
Events.instance().raiseEvent("albumAdded");
@@ -75,7 +74,7 @@
}
public void editAlbum(Album album){
- albumAction.editAlbum(album, flushStrategy.isDatabaseStoreStrategy());
+ albumAction.editAlbum(album);
model.resetModel(NavigationEnum.ALBUM_PREVIEW, model.getSelectedUser(),
model.getSelectedShelf(), album, null);
Events.instance().raiseEvent("albumEdited");
}
@@ -83,7 +82,7 @@
public void deleteAlbum(Album album){
//Update domain model
String string = album.getId().toString();
- albumAction.deleteAlbum(album, flushStrategy.isDatabaseStoreStrategy());
+ albumAction.deleteAlbum(album);
deleteDirectory(string);
model.resetModel(NavigationEnum.ALL_ALBUMS, model.getSelectedUser(),
model.getSelectedShelf(), null, null);
Events.instance().raiseEvent("albumDeleted");
@@ -91,8 +90,7 @@
}
public Long getCountUnvisitedImages(Album album){
- if(album.getCountUnvisitedImages() == null){
- album.setCountUnvisitedImages(albumAction.getCountUnvisitedImages(album));
+ if(album.getCountUnvisitedImages() == 0){
album.setUnvisitedImages(albumAction.getUnvisitedImages(album));
}
return album.getCountUnvisitedImages();
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -31,6 +31,7 @@
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.web.RequestParameter;
+import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Conversation;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
@@ -62,6 +63,7 @@
@In Identity identity;
+ @Out(required=false) User user;
@In Credentials credentials;
@In FacesMessages facesMessages;
@@ -73,7 +75,7 @@
@In FileManager fileManager;
- @In(create=true) @Out Model model;
+ @In @Out Model model;
public String login(){
if(identity.hasRole("admin")){
@@ -98,12 +100,11 @@
{
if (wantLoginAnonymous()) {
identity.addRole(Constants.GUEST_ROLE);
- userAction.loginAnonymous();
model.setMainArea(NavigationEnum.ANONYM);
return true;
}
try {
- User user = userAction.login(credentials.getUsername(),
passwordHolder.hash(credentials.getPassword()));
+ 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);
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Controller.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -151,19 +151,15 @@
model.resetModel(NavigationEnum.USER_SHARED_IMAGES, user, null, null, null);
}
- public boolean isAccessToAlbumGranted(Album album){
- return album.getOwner().equals(user) || album.getShelf().isShared();
- }
-
public boolean isUserShelf(Shelf shelf){
- return shelf.getOwner()!=null &&
shelf.getOwner().getId().equals(user.getId());
+ return shelf.getOwner()!=null &&
shelf.getOwner().getLogin().equals(user.getLogin());
}
public boolean isUserAlbum(Album album){
if(album == null || album.getOwner() == null){
return false;
}
- return album.getOwner().equals(user);
+ return album.getOwner().getLogin().equals(user.getLogin());
}
public void showUser(User user){
@@ -175,7 +171,7 @@
}
public void showUnvisitedImages(Album album){
- model.resetModel(NavigationEnum.ALBUM_UNVISITED, album.getOwner(), album.getShelf(),
album, null);
+ model.resetModel(NavigationEnum.ALBUM_UNVISITED, album.getShelf().getOwner(),
album.getShelf(), album, null);
}
public void showTag(MetaTag metatag){
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -31,8 +31,8 @@
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;
-import org.richfaces.realworld.util.FlushStrategy;
@Name("dndManager")
public class DnDManager implements DropListener {
@@ -40,7 +40,6 @@
@In User user;
@In FileManager fileManager;
@In IAlbumAction albumAction;
- @In FlushStrategy flushStrategy;
public void processDrop(DropEvent dropEvent) {
Dropzone dropzone = (Dropzone) dropEvent.getComponent();
@@ -57,31 +56,10 @@
}
}
- /*private void addTreeToRerender() {
- try {
- FacesContext fc = FacesContext.getCurrentInstance();
- AjaxContext ac = AjaxContext.getCurrentInstance();
- UIComponent destTree = fc.getViewRoot().findComponent(Constants.TREE_ID);
- ac.addComponentToAjaxRender(destTree);
- } catch (Exception e) {
- System.err.print(e.getMessage());
- }
- }*/
-
private void handleAlbum(Album dragValue, Shelf dropValue) {
- if(dragValue.getShelf() != null ){
- if(dragValue.getShelf().equals(dropValue)){
- //Parent album contain this album
- return;
- }else{
- dropValue.addAlbum(dragValue);
- if(flushStrategy.isDatabaseStoreStrategy()){
- albumAction.flush();
- }
- Events.instance().raiseEvent("clearTree");
- }
- }
- //addTreeToRerender();
+ dropValue.addAlbum(dragValue);
+ albumAction.editAlbum(dragValue);
+ Events.instance().raiseEvent("clearTree");
}
private void handleImage(Image dragValue, Album dropValue) {
@@ -91,9 +69,7 @@
String newPath = getNewPathOfImage(dragValue, dropValue);
dragValue.setPath(newPath);
dropValue.addImage(dragValue);
- if(flushStrategy.isDatabaseStoreStrategy()){
- albumAction.flush();
- }
+ albumAction.editAlbum(dropValue);
}
private String getNewPathOfImage(Image dragValue, Album dropValue) {
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -26,6 +26,7 @@
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.service.Constants;
import javax.imageio.ImageIO;
@@ -231,16 +232,61 @@
file.mkdirs();
}
- public boolean addImage(String fileName, String tempFilePath) {
- createDirectoryIfNotExist(fileName);
- writeFile(fileName, tempFilePath, _SMALL80, 80, true);
- writeFile(fileName, tempFilePath, _SMALL120, 120, true);
- writeFile(fileName, tempFilePath, _SMALL160, 160, true);
- writeFile(fileName, tempFilePath, _MINI, 150, true);
- writeFile(fileName, tempFilePath, _MEDIUM, 600, true);
- return true;
- }
+ public boolean saveAvatar(String path, User user) {
+ return writeFile("/" + user.getLogin() +
+ "/avatar.jpg", path, "", 80, true);
+ }
+ public void renameImage(String fileNameOld, String fileNameNew) {
+ createDirectoryIfNotExist(fileNameNew);
+ renameImage(getFileByPath(fileNameNew), getFileByPath(fileNameOld));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _MEDIUM)),
+ getFileByPath(transformPath(fileNameOld, _MEDIUM)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL80)),
+ getFileByPath(transformPath(fileNameOld, _SMALL80)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL120)),
+ getFileByPath(transformPath(fileNameOld, _SMALL120)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL160)),
+ getFileByPath(transformPath(fileNameOld, _SMALL160)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL200)),
+ getFileByPath(transformPath(fileNameOld, _SMALL200)));
+ }
+
+
+ public void deleteImage(String fileName) {
+ deleteImage(getFileByPath(fileName));
+ deleteImage(getFileByPath(transformPath(fileName, _MEDIUM)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL80)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL120)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL160)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL200)));
+ }
+
+ public boolean addImage(String fileName, String tempFilePath) {
+ createDirectoryIfNotExist(fileName);
+ if(!writeFile(fileName, tempFilePath, _SMALL80, 80, true)){
+ return false;
+ }
+ if(!writeFile(fileName, tempFilePath, _SMALL120, 120, true)){
+ return false;
+ }
+ if(!writeFile(fileName, tempFilePath, _SMALL160, 160, true)){
+ return false;
+ }
+ if(!writeFile(fileName, tempFilePath, _SMALL200, 200, true)){
+ return false;
+ }
+ if(!writeFile(fileName, tempFilePath, _MEDIUM, 600, true)){
+ return false;
+ }
+ return true;
+ }
+
public static BufferedImage bitmapToImage(String data, String format) throws
IOException {
final InputStream inb = new FileInputStream(data);
final ImageReader rdr = ImageIO.getImageReadersByFormatName(format).next();
@@ -332,13 +378,12 @@
return ret;
}
- public void writeFile(String newFileName, String fileName, String pattern, int size,
boolean includeUploadRoot) {
+ public boolean writeFile(String newFileName, String fileName, String pattern, int
size, boolean includeUploadRoot) {
BufferedImage bsrc = null;
try {
bsrc = bitmapToImage(fileName, "JPG");
} catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ return false;
}
final int i = bsrc.getWidth() > bsrc.getHeight() ? bsrc.getWidth() :
bsrc.getHeight();
final double d = ((double) size) / i;
@@ -349,9 +394,9 @@
try {
imageToBitmap(bdest, dest, "JPG");
} catch (IOException ex) {
- // TODO Auto-generated catch block
- ex.printStackTrace();
+ return false;
}
+ return true;
}
public String transformPath(String target, String substitute) {
@@ -360,15 +405,6 @@
return begin + substitute + end;
}
- public void deleteImage(String fileName) {
- deleteImage(getFileByPath(fileName));
- deleteImage(getFileByPath(transformPath(fileName, _MINI)));
- deleteImage(getFileByPath(transformPath(fileName, _MEDIUM)));
- deleteImage(getFileByPath(transformPath(fileName, _SMALL80)));
- deleteImage(getFileByPath(transformPath(fileName, _SMALL120)));
- deleteImage(getFileByPath(transformPath(fileName, _SMALL160)));
- }
-
private void deleteImage(File file) {
if (file.exists()) {
file.delete();
@@ -380,26 +416,6 @@
return path.substring(i);
}
- public void renameImage(String fileNameOld, String fileNameNew) {
- createDirectoryIfNotExist(fileNameNew);
- renameImage(getFileByPath(fileNameNew), getFileByPath(fileNameOld));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _MINI)),
- getFileByPath(transformPath(fileNameOld, _MINI)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _MEDIUM)),
- getFileByPath(transformPath(fileNameOld, _MEDIUM)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _SMALL80)),
- getFileByPath(transformPath(fileNameOld, _SMALL80)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _SMALL120)),
- getFileByPath(transformPath(fileNameOld, _SMALL120)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _SMALL160)),
- getFileByPath(transformPath(fileNameOld, _SMALL160)));
- }
-
private void renameImage(File fileNew, File fileOld) {
if (fileNew.exists()) {
fileNew.delete();
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -36,9 +36,9 @@
import org.richfaces.realworld.domain.MetaTag;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.service.Constants;
+import org.richfaces.realworld.service.FlushStrategy;
import org.richfaces.realworld.service.IImageAction;
import org.richfaces.realworld.util.DirectLinkHelper;
-import org.richfaces.realworld.util.FlushStrategy;
@Name("imageManager")
@Scope(ScopeType.CONVERSATION)
@@ -47,9 +47,6 @@
@In
IImageAction imageAction;
-
- @In
- FlushStrategy flushStrategy;
@In
FileManager fileManager;
@@ -60,26 +57,23 @@
@In
private User user;
- @In
- private DirectLinkHelper directLink;
-
public void deleteImage(Image image) {
String imagePath = image.getPath();
model.resetModel(NavigationEnum.ALBUM_PREVIEW, image.getAlbum().getOwner(),
image.getAlbum().getShelf(), image.getAlbum(), null);
- imageAction.deleteImage(image, flushStrategy.isDatabaseStoreStrategy());
+ imageAction.deleteImage(image);
fileManager.deleteImage(imagePath);
Events.instance().raiseEvent("imageDeleted");
}
public void editImage(Image image) {
- imageAction.editImage(image, flushStrategy.isDatabaseStoreStrategy());
+ imageAction.editImage(image);
Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,
NavigationEnum.ALBUM_IMAGE_PREVIEW);
Events.instance().raiseEvent("imageEdited");
}
@Observer(Constants.ADD_IMAGE_EVENT)
public void addImage(Image image) {
- imageAction.addImage(image, flushStrategy.isDatabaseStoreStrategy());
+ imageAction.addImage(image);
model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW, model.getSelectedUser(),
model.getSelectedShelf(), image.getAlbum(), image);
Events.instance().raiseEvent("imageAdded");
}
@@ -97,20 +91,16 @@
comment.setImage(image);
comment.setDate(new Date());
comment.setMessage(message);
- imageAction.addComment(comment, flushStrategy.isDatabaseStoreStrategy());
+ imageAction.addComment(comment);
Events.instance().raiseEvent(Constants.CLEAR_EDITOR_EVENT, "");
}
public void deleteComment(Comment comment) {
- imageAction.deleteComment(comment, flushStrategy.isDatabaseStoreStrategy());
+ imageAction.deleteComment(comment);
}
- public String getImageDirectLink(Image image) {
- return directLink.getDirectImageLink(image.getId());
- }
-
public List<MetaTag> popularTags() {
- return imageAction.popularTags();
+ return imageAction.getPopularTags();
}
public List<MetaTag> autoComplete(Object suggest) {
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -16,15 +16,13 @@
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;
-import org.richfaces.realworld.util.FlushStrategy;
@Name("registerManager")
@Scope(ScopeType.CONVERSATION)
public class RegistrationManager {
-
- @In FlushStrategy flushStrategy;
@In("#{messages['user.exist']}") private String
USER_WITH_THIS_LOGIN_ALREADY_EXIST;
@@ -47,7 +45,7 @@
return "";
}
user.setPasswordHash(passwordHolder.hash(user.getPassword()));
- userAction.register(user, flushStrategy.isDatabaseStoreStrategy());
+ userAction.register(user);
return "index";
}
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -36,8 +36,8 @@
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Shelf;
import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.FlushStrategy;
import org.richfaces.realworld.service.IShelfAction;
-import org.richfaces.realworld.util.FlushStrategy;
@Name("shelfManager")
@Scope(ScopeType.CONVERSATION)
@@ -56,9 +56,6 @@
private String oncomplete = ";";
- @In
- FlushStrategy flushStrategy;
-
@In @Out
Model model;
@@ -71,7 +68,7 @@
}
public void addShelf(Shelf shelf) {
- shelfAction.addShelf(shelf, flushStrategy.isDatabaseStoreStrategy());
+ shelfAction.addShelf(shelf);
model.resetModel(model.getMainArea(), model.getSelectedUser(), shelf, null,
null);
setOncomplete();
Events.instance().raiseEvent("clearTree");
@@ -82,7 +79,7 @@
}
public void editShelf(Shelf shelf) {
- shelfAction.editShelf(shelf, flushStrategy.isDatabaseStoreStrategy());
+ shelfAction.editShelf(shelf);
model.resetModel(NavigationEnum.SHELF_PREVIEW, model.getSelectedUser(), shelf,
null, null);
}
@@ -92,7 +89,7 @@
for (Album a : shelf.getAlbums()) {
directoriesToDelete.add(user.getLogin() + "/" + a.getId());
}
- shelfAction.deleteShelf(shelf, flushStrategy.isDatabaseStoreStrategy());
+ shelfAction.deleteShelf(shelf);
deleteDirectories(directoriesToDelete);
model.resetModel(NavigationEnum.ALL_SHELFS, model.getSelectedUser(), null, null,
null);
Events.instance().raiseEvent("clearTree");
@@ -127,8 +124,7 @@
}
public Long getCountUnvisitedImages(Shelf shelf) {
- if (shelf.getCountUnvisitedImages() == null) {
- shelf.setCountUnvisitedImages(shelfAction.getCountUnvisitedImages(shelf));
+ if (shelf.getCountUnvisitedImages() == 0) {
shelf.setUnvisitedImages(shelfAction.getUnvisitedImages(shelf));
}
return shelf.getCountUnvisitedImages();
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -23,6 +23,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Date;
@@ -41,8 +42,8 @@
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 org.richfaces.realworld.util.FlushStrategy;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
@@ -67,7 +68,6 @@
private String FILE_SAVE_ERROR;
@In IImageAction imageAction;
- @In FlushStrategy flushStrategy;
@In @Out
FileWrapper fileWrapper;
@@ -85,7 +85,6 @@
public synchronized void listener(UploadEvent event) throws Exception {
UploadItem item = event.getUploadItem();
Image image = constructImage(item);
- //fileManager.writeFile(item.getFile().getPath(), item.getFile().getPath(),
"_mini", 100, false);
try {
extractMetadata(item, image);
} catch (JpegProcessingException e1) {
@@ -102,15 +101,20 @@
}
String newPath = "/" +model.getSelectedAlbum().getOwner().getLogin() +
"/" + model.getSelectedAlbum().getId() + "/" +item.getFileName();
image.setPath(newPath);
- fileWrapper.getFiles().add(0, image);
+
//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, new
Exception(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, flushStrategy.isDatabaseStoreStrategy());
+ imageAction.addImage(image);
Events.instance().raiseEvent("imageAdded");
item.getFile().delete();
+ image.getAlbum().getUnvisitedImages().add(image);
+ image.getAlbum().getShelf().getUnvisitedImages().add(image);
}
private Image constructImage(UploadItem item) {
@@ -124,7 +128,7 @@
}
private void extractMetadata(UploadItem item, Image image)
- throws JpegProcessingException, MetadataException, FileNotFoundException {
+ throws JpegProcessingException, MetadataException, IOException {
InputStream in = new FileInputStream(item.getFile());
//TODO nick - close "in"?
Metadata metadata = JpegMetadataReader.readMetadata(in);
@@ -133,6 +137,7 @@
setupCameraModel(image, exifDirectory);
setupDimensions(image, exifDirectory, jpgDirectory);
setupCreatedDate(image, exifDirectory);
+ in.close();
}
private void setupCreatedDate(Image image, Directory exifDirectory)
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -3,9 +3,7 @@
*/
package org.richfaces.realworld.ui;
-import java.awt.image.BufferedImage;
import java.io.File;
-import java.io.IOException;
import javax.faces.model.SelectItem;
@@ -21,9 +19,10 @@
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.manager.FileManager;
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.IUserAction;
-import org.richfaces.realworld.util.FlushStrategy;
/**
* @author Andrey Markavtsov
@@ -34,12 +33,9 @@
public class UserPrefsHelper {
@In IUserAction userAction;
-
@In FileManager fileManager;
- @In FlushStrategy flushStrategy;
- //TODO nick - not used anywhere
- @In(create=true) @Out Model model;
- @In User user;
+ @In @Out Model model;
+ @In @Out User user;
Boolean avatarModalOpened = false;
@@ -54,31 +50,27 @@
public void uploadAvatar(UploadEvent event) {
UploadItem item = event.getUploadItem();
avatarData = item.getFile();
- //TODO nick - persist user?
- user.setHasAvatar(true);
}
//TODO nick - are we saving current user?
- public void saveUser(User user){
+ public void saveUser(){
if (avatarData != null) {
- try {
- BufferedImage image = fileManager.bitmapToImage(avatarData.getPath(),"JPG"
);
- //TODO nick - use fileManager methods to access user image
- fileManager.imageToBitmap(image, fileManager.getUploadRoot().getCanonicalPath()+
"/" + user.getLogin() +
- "/avatar.jpg", "JPG");
- } catch (IOException e) {
+ if(!fileManager.saveAvatar(avatarData.getPath(), user)){
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception("File IO
Error"));
+ return;
}
avatarData.delete();
avatarData = null;
user.setHasAvatar(true);
}
- userAction.updateUser(user, flushStrategy.isDatabaseStoreStrategy());
+ user = userAction.updateUser();
+ model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(),
model.getSelectedAlbum(), model.getSelectedImage());
}
public void cancel() {
- //TODO nick - restore value of user.hasAvatar?
+ user = userAction.resetUser();
avatarData = null;
+ model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(),
model.getSelectedAlbum(), model.getSelectedImage());
}
public SelectItem [] getSexs () {
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-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -85,7 +85,7 @@
id=imageId;
}
- public String getDirectImageLink(Long id) {
+ public String getDirectImageLink(Image image) {
if (imageDirectLinkPrefix == null) {
FacesContext context = FacesContext.getCurrentInstance();
if (context == null) {
@@ -109,6 +109,6 @@
}
}
}
- return imageDirectLinkPrefix + id;
+ return imageDirectLinkPrefix + image.getId();
}
}
\ No newline at end of file
Deleted:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FlushStrategy.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FlushStrategy.java 2009-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FlushStrategy.java 2009-03-27
11:34:00 UTC (rev 13249)
@@ -1,42 +0,0 @@
-package org.richfaces.realworld.util;
-
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.AutoCreate;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-
-@Name("flushStrategy")
-(a)Scope(ScopeType.APPLICATION)
-@AutoCreate
-public class FlushStrategy {
-
- private String strategy;
-
- public String getStrategy() {
- if(strategy == null){
- FacesContext fc = FacesContext.getCurrentInstance();
- if (fc != null) {
- String initParameter = fc.getExternalContext().getInitParameter(
- "storeStrategy");
- if(initParameter.equals("conversation") ||
initParameter.equals("database")){
- strategy = initParameter;
- }else{
- throw new RuntimeException("Wrong storeStrategy context parameter. It should be
'conversation' or 'database'");
- }
-
- }
- }
- return strategy;
- }
-
- public void setStrategy(String strategy) {
- this.strategy = strategy;
- }
-
- //TODO nick - make this a static method
- public boolean isDatabaseStoreStrategy(){
- return getStrategy().equals("database");
- }
-}
Modified: trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/components.xml
===================================================================
---
trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/components.xml 2009-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/components.xml 2009-03-27
11:34:00 UTC (rev 13249)
@@ -21,8 +21,6 @@
http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-2.1.0.xsd">
<core:init transaction-management-enabled="false" debug="true"
jndi-pattern="@jndiPattern@"/>
- <web:context-filter url-pattern="/picture/*"/>
- <web:character-encoding-filter encoding="UTF-8"
override-client="true" url-pattern="*.seam"/>
<core:manager concurrent-request-timeout="20000"
conversation-timeout="120000"
conversation-id-parameter="cid"
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/album/albumsList.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/fileUploader.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/image/imageEditInfo.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/albumsResult.xhtml
===================================================================
---
trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/albumsResult.xhtml 2009-03-27
10:44:18 UTC (rev 13248)
+++
trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/albumsResult.xhtml 2009-03-27
11:34:00 UTC (rev 13249)
@@ -10,7 +10,7 @@
<h:panelGrid cellpadding="0">
<h:panelGroup>
<a4j:commandLink
- rendered="#{controller.isAccessToAlbumGranted(album)}"
+ rendered="#{controller.isUserAlbum(album)}"
actionListener="#{controller.showAlbum(album)}"
reRender="mainArea, tree">
<a4j:mediaOutput rendered="#{!album.isEmpty()}" id="img"
element="img"
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/userPrefs.xhtml
===================================================================
(Binary files differ)