Creating folders is now working.
authorErik Brakkee <erik@brakkee.org>
Wed, 25 Sep 2013 21:31:17 +0000 (23:31 +0200)
committerErik Brakkee <erik@brakkee.org>
Wed, 25 Sep 2013 21:31:17 +0000 (23:31 +0200)
Fixed problem with CachedObject in the utilities library.

pom.xml
src/main/java/org/wamblee/photos/model/authorization/AuthorizedAlbum.java
src/main/java/org/wamblee/photos/model/filesystem/FileSystemAlbum.java
src/main/java/org/wamblee/photos/wicket/AlbumPanel.html
src/main/java/org/wamblee/photos/wicket/AlbumPanel.java

diff --git a/pom.xml b/pom.xml
index dc1ba4a42022ed8ad012de869922823b7e6b88d0..6546fc18c90986e269e914e7039b03c067667714 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
     <properties>
         <wicket.version>1.4.9</wicket.version>
         <jetty.version>6.1.4</jetty.version>
-        <utils.version>0.6</utils.version>
+        <utils.version>0.8-SNAPSHOT</utils.version>
     </properties>
 
     <!--
index f76fd09a1730005ef7364522f47a002f2e96d653..b59aafeb9a0d13650dd09d49b6b09307114e2dd1 100644 (file)
@@ -66,8 +66,7 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album {
             @PhotoCache Cache<String, ArrayList<PhotoEntry>> aCache, HttpSession aSession) {
         super(aAlbum);
         _authorizer = aService;
-        _authorizedEntries = new CachedObject<String, ArrayList<PhotoEntry>>(aCache,
-                "session:" + aSession.getId() + "/" + aAlbum.getPath(),
+        _authorizedEntries = new CachedObject<>(aCache, "session:" + aSession.getId() + "/" + aAlbum.getPath(),
                 new CachedObject.Computation<String, ArrayList<PhotoEntry>>() {
                     public ArrayList<PhotoEntry> getObject(String aObjectKey) {
                         return AuthorizedAlbum.this.compute();
@@ -83,7 +82,7 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album {
      */
     private synchronized ArrayList<PhotoEntry> compute() {
         LOGGER.info("Refreshing cache " + getPath());
-        ArrayList<PhotoEntry> result = new ArrayList<PhotoEntry>();
+        ArrayList<PhotoEntry> result = new ArrayList<>();
         for (int i = 0; i < decorated().size(); i++) {
             PhotoEntry entry = decorated().getEntry(i);
             if (_authorizer.isAllowed(entry, new ReadOperation())) {
@@ -182,13 +181,11 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album {
      *      java.io.InputStream)
      */
     public void addImage(String aId, InputStream aImage) throws IOException {
-        _authorizer.check(this, new WriteOperation());
-        int oldsize = _authorizedEntries.get().size();
-        _authorizedEntries.invalidate();
-        decorated().addImage(aId, aImage);
-        int newsize = _authorizedEntries.get().size();
-        if (newsize != oldsize + 1) {
-            throw new RuntimeException("cache was not refreshed property");
+        try {
+            _authorizer.check(this, new WriteOperation());
+            decorated().addImage(aId, aImage);
+        } finally {
+            _authorizedEntries.invalidate();
         }
     }
 
@@ -198,9 +195,12 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album {
      * @see org.wamblee.photos.model.Album#addAlbum(java.lang.String)
      */
     public void addAlbum(String aId) throws IOException {
-        _authorizer.check(this, new WriteOperation());
-        _authorizedEntries.invalidate();
-        decorated().addAlbum(aId);
+        try {
+            _authorizer.check(this, new WriteOperation());
+            decorated().addAlbum(aId);
+        } finally {
+            _authorizedEntries.invalidate();
+        }
     }
 
     /*
@@ -209,10 +209,14 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album {
      * @see org.wamblee.photos.model.Album#removeEntry(java.lang.String)
      */
     public void removeEntry(String aId) throws IOException {
-        // Check whether deletion is allowed.
-        PhotoEntry entry = _authorizer.check(decorated().getEntry("/" + aId), new DeleteOperation());
-        _authorizedEntries.invalidate();
-        decorated().removeEntry(aId);
+        try {
+            // Check whether deletion is allowed.
+            PhotoEntry entry = _authorizer.check(decorated().getEntry("/" + aId), new DeleteOperation());
+            _authorizedEntries.invalidate();
+            decorated().removeEntry(aId);
+        } finally {
+            _authorizedEntries.invalidate();
+        }
     }
 
     public Photo findPhotoBefore(String aId) {
index fcf4695311ae4e1ea4a03e0f6a0abe37ea31e530..011381bf04cc04fa5293c12b6b92d0f6d3f0aeb7 100644 (file)
@@ -496,28 +496,32 @@ public class FileSystemAlbum implements Album {
      * @see org.wamblee.photos.database.Album#addAlbum(java.lang.String)
      */
     public void addAlbum(String aId) throws IOException {
-        PhotoEntry entry = find(aId);
-        if (entry != null) {
-            throw new IOException("Entry already exists in album " + getId() +
-                    " : " + aId);
-        }
-        // Entry not yet found. Try to create it.
-        File albumDir = new File(_dir, aId);
-        if (!albumDir.mkdir()) {
-            throw new IOException("Could not create album: " + aId);
-        }
-        File photosDir = new File(albumDir, PHOTOS_DIR);
-        if (!photosDir.mkdir()) {
-            throw new IOException("Could  not create photo storage dir: " + photosDir.getPath());
-        }
-        File thumbnailsDir = new File(albumDir, THUMBNAILS_DIR);
-        if (!thumbnailsDir.mkdir()) {
-            throw new IOException("Coul dnot create thumbnails storage dir: " + thumbnailsDir.getPath());
+        try {
+            PhotoEntry entry = find(aId);
+            if (entry != null) {
+                throw new IOException("Entry already exists in album " + getId() +
+                        " : " + aId);
+            }
+            // Entry not yet found. Try to create it.
+            File albumDir = new File(_dir, aId);
+            if (!albumDir.mkdir()) {
+                throw new IOException("Could not create album: " + aId);
+            }
+            File photosDir = new File(albumDir, PHOTOS_DIR);
+            if (!photosDir.mkdir()) {
+                throw new IOException("Could  not create photo storage dir: " + photosDir.getPath());
+            }
+            File thumbnailsDir = new File(albumDir, THUMBNAILS_DIR);
+            if (!thumbnailsDir.mkdir()) {
+                throw new IOException("Coul dnot create thumbnails storage dir: " + thumbnailsDir.getPath());
+            }
+            String newPath = _path + "/" + aId;
+            newPath = newPath.replaceAll("//", "/");
+            FileSystemAlbum album = new FileSystemAlbum(albumDir, newPath, _entries.getCache());
+            addEntry(album);
+        } finally {
+            _entries.invalidate();
         }
-        String newPath = _path + "/" + aId;
-        newPath = newPath.replaceAll("//", "/");
-        FileSystemAlbum album = new FileSystemAlbum(albumDir, newPath, _entries.getCache());
-        addEntry(album);
     }
 
     /*
@@ -526,16 +530,20 @@ public class FileSystemAlbum implements Album {
      * @see org.wamblee.photos.database.Album#removeAlbum(java.lang.String)
      */
     public void removeEntry(String aId) throws IOException {
-        PhotoEntry entry = find(aId);
-        if (entry == null) {
-            throw new IOException("Entry " + aId + " not found.");
-        }
-        if (entry instanceof FileSystemAlbum) {
-            // album.
-            removeAlbum((FileSystemAlbum) entry);
-        } else {
-            // regular photo
-            removePhoto(entry);
+        try {
+            PhotoEntry entry = find(aId);
+            if (entry == null) {
+                throw new IOException("Entry " + aId + " not found.");
+            }
+            if (entry instanceof FileSystemAlbum) {
+                // album.
+                removeAlbum((FileSystemAlbum) entry);
+            } else {
+                // regular photo
+                removePhoto(entry);
+            }
+        } finally {
+            _entries.invalidate();
         }
     }
 
index 0786ab4b853aa0255144353199e9c14045b70486..c6e0d9f88a29ad22cccefdb7f178c965061ab8a5 100644 (file)
@@ -50,6 +50,7 @@
     </div>
     <div id="upload">
         <span wicket:id="uploadPanel"/>
+        <span wicket:id="createFolderPanel"/>
     </div>
 </wicket:panel>
 
index 71ea87c1a1c0f2edb028f9efca06a570e8a2ddc6..a84c8703c03588acd761df6271146e12e513883d 100644 (file)
@@ -247,8 +247,10 @@ public class AlbumPanel extends Panel {
         // upload panel
         if (path.equals("/")) {
             add(new WebMarkupContainer("uploadPanel"));
+            add(new WebMarkupContainer("createFolderPanel"));
         } else {
             add(new UploadPanel("uploadPanel", path));
+            add(new CreateFolderPanel("createFolderPanel", path));
         }
     }