X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fwamblee%2Fphotos%2Fmodel%2Fauthorization%2FAuthorizedAlbum.java;h=b59aafeb9a0d13650dd09d49b6b09307114e2dd1;hb=HEAD;hp=f76fd09a1730005ef7364522f47a002f2e96d653;hpb=387bef406fe4b276473d4063c4d227fce6ff2e11;p=photos diff --git a/src/main/java/org/wamblee/photos/model/authorization/AuthorizedAlbum.java b/src/main/java/org/wamblee/photos/model/authorization/AuthorizedAlbum.java index f76fd09..b59aafe 100644 --- a/src/main/java/org/wamblee/photos/model/authorization/AuthorizedAlbum.java +++ b/src/main/java/org/wamblee/photos/model/authorization/AuthorizedAlbum.java @@ -66,8 +66,7 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album { @PhotoCache Cache> aCache, HttpSession aSession) { super(aAlbum); _authorizer = aService; - _authorizedEntries = new CachedObject>(aCache, - "session:" + aSession.getId() + "/" + aAlbum.getPath(), + _authorizedEntries = new CachedObject<>(aCache, "session:" + aSession.getId() + "/" + aAlbum.getPath(), new CachedObject.Computation>() { public ArrayList getObject(String aObjectKey) { return AuthorizedAlbum.this.compute(); @@ -83,7 +82,7 @@ public class AuthorizedAlbum extends AuthorizedPhotoEntry implements Album { */ private synchronized ArrayList compute() { LOGGER.info("Refreshing cache " + getPath()); - ArrayList result = new ArrayList(); + ArrayList 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) {