Fixed problem with CachedObject in the utilities library.
<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>
<!--
@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();
*/
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())) {
* 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();
}
}
* @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();
+ }
}
/*
* @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) {
* @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);
}
/*
* @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();
}
}
</div>
<div id="upload">
<span wicket:id="uploadPanel"/>
+ <span wicket:id="createFolderPanel"/>
</div>
</wicket: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));
}
}