Example #1
0
 private void setupCameraModel(Image image, Directory exifDirectory) {
   if (exifDirectory.containsTag(ExifDirectory.TAG_MODEL)) {
     String cameraModel = exifDirectory.getString(ExifDirectory.TAG_MODEL);
     image.setCameraModel(cameraModel);
   } else {
     image.setCameraModel("");
   }
 }
Example #2
0
 private void setupDimensions(Image image, Directory exifDirectory, Directory jpgDirectory) {
   try {
     if (exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH)
         && exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
       int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
       image.setWidth(width);
       int height = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
       image.setHeight(height);
     } else {
       if (jpgDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
         int width = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
         image.setWidth(width);
         int height = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
         image.setHeight(height);
       }
     }
   } catch (MetadataException e) {
     addError(image, Constants.IMAGE_SAVING_ERROR);
   }
 }
Example #3
0
 private Image constructImage(UploadItem item) {
   Image image = new Image();
   image.setUploaded(new Date());
   image.setDescription(item.getFileName());
   image.setName(item.getFileName());
   image.setSize(item.getFileSize());
   image.setPath(item.getFileName());
   image.setAllowComments(true);
   return image;
 }
Example #4
0
 /**
  * Listenet, that invoked during file upload process. Only registered users can upload images.
  *
  * @param event - event, indicated that file upload started
  */
 @Restrict("#{s:hasRole('admin')}")
 public void listener(UploadEvent event) {
   UploadItem item = event.getUploadItem();
   // Construct image from item
   Image image = constructImage(item);
   try {
     // Extract metadata(size, camera model etc..)
     extractMetadata(item, image);
   } catch (Exception e1) {
     addError(item, image, Constants.FILE_PROCESSING_ERROR);
     return;
   }
   image.setAlbum(model.getSelectedAlbum());
   if (image.getAlbum() == null) {
     addError(item, 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(item, image, Constants.IMAGE_SAVING_ERROR);
     return;
   }
   // Save to disk
   if (!fileManager.addImage(image.getFullPath(), item.getFile().getPath())) {
     addError(item, image, Constants.FILE_SAVE_ERROR);
     return;
   }
   // Prepare to show in UI
   fileWrapper.getFiles().add(image);
   Events.instance().raiseEvent(Constants.IMAGE_ADDED_EVENT, image);
   // Delete temporary file
   item.getFile().delete();
 }
Example #5
0
 private void setupCreatedDate(Image image, Directory exifDirectory) throws MetadataException {
   if (exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)) {
     Date time = exifDirectory.getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
     image.setCreated(time);
   }
 }
Example #6
0
 private String generateNewPath(Image image) throws PhotoAlbumException {
   String path = image.getPath().substring(0, image.getPath().lastIndexOf(Constants.DOT));
   Long countCopies = imageAction.getCountIdenticalImages(image.getAlbum(), path) + 1;
   String newPath = fileManager.transformPath(image.getPath(), "_" + countCopies);
   return newPath;
 }