// Construct image from item
uploadFile(new FileHandler(file), model.getSelectedAlbum());
}
public void uploadFile(FileHandler fileHandler, Album album) {
Image image = constructImage(fileHandler);
try {
// Extract metadata(size, camera model etc..)
extractMetadata(fileHandler, image);
} catch (Exception e1) {
addError(fileHandler, image, Constants.FILE_PROCESSING_ERROR);
return;
}
image.setAlbum(album);
if (image.getAlbum() == null) {
addError(fileHandler, image, Constants.NO_ALBUM_TO_DOWNLOAD_ERROR);
return;
}
try {
// Check if image with given name already exist
if (imageAction.isImageWithThisPathExist(image.getAlbum(), image.getPath())) {
// If exist generate new path for image
String newPath = generateNewPath(image);
image.setPath(newPath);
image.setName(newPath);
}
// Save to database
imageAction.addImage(image);
} catch (Exception e) {
addError(fileHandler, image, Constants.IMAGE_SAVING_ERROR);
return;
}
try {
// Save to disk
if (!fileManager.addImage(image.getFullPath(), fileHandler)) {
addError(fileHandler, image, Constants.FILE_SAVE_ERROR);
return;
}
} catch (IOException ioe) {
log.log(Level.INFO, "error", ioe);