Skip to content
Browse files

Image Management Improvement

  • Loading branch information...
1 parent c75e814 commit 72505fbde09098b84e6226b90903a944f6b88343 @longkerdandy committed Jun 13, 2011
Showing with 1,361 additions and 1,100 deletions.
  1. BIN assembly/bundle/sanselan-0.97-incubator.jar
  2. +1 −1 assembly/pom.xml
  3. +15 −81 medialibrary.api/src/main/java/org/chii2/medialibrary/api/core/MediaLibraryService.java
  4. +13 −19 medialibrary.api/src/main/java/org/chii2/medialibrary/api/persistence/PersistenceService.java
  5. +109 −18 medialibrary.api/src/main/java/org/chii2/medialibrary/api/persistence/entity/Image.java
  6. +130 −46 medialibrary.api/src/main/java/org/chii2/medialibrary/api/persistence/entity/ImageFile.java
  7. +8 −2 medialibrary.api/src/main/java/org/chii2/medialibrary/api/provider/ImageInfoProviderService.java
  8. +7 −46 medialibrary.core/src/main/java/org/chii2/medialibrary/MediaLibraryServiceImpl.java
  9. +22 −82 medialibrary.core/src/main/java/org/chii2/medialibrary/event/ImageHandler.java
  10. +0 −5 medialibrary.core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
  11. +0 −275 ...icsmagickprovider/src/main/java/org/chii2/medialibrary/provider/graphicsmagick/ImageAnalyzer.java
  12. +0 −92 ...er/src/main/java/org/chii2/medialibrary/provider/graphicsmagick/ImageInfoProviderServiceImpl.java
  13. +62 −112 ...alibrary.persistence/src/main/java/org/chii2/medialibrary/persistence/PersistenceServiceImpl.java
  14. +133 −48 medialibrary.persistence/src/main/java/org/chii2/medialibrary/persistence/entity/ImageFileImpl.java
  15. +92 −18 medialibrary.persistence/src/main/java/org/chii2/medialibrary/persistence/entity/ImageImpl.java
  16. +2 −2 ...nfo/src/main/java/org/chii2/medialibrary/provider/mediainfo/MovieFileInfoProviderServiceImpl.java
  17. +17 −3 {medialibrary.graphicsmagickprovider → medialibrary.provider.sanselan}/pom.xml
  18. +121 −0 ...sanselan/src/main/java/org/chii2/medialibrary/provider/sanselan/ImageInfoProviderServiceImpl.java
  19. +300 −0 ...vider.sanselan/src/main/java/org/chii2/medialibrary/provider/sanselan/consumer/ImageAnalyzer.java
  20. +16 −4 ...ickprovider → medialibrary.provider.sanselan}/src/main/resources/OSGI-INF/blueprint/blueprint.xml
  21. +3 −3 medialibrary.shell/src/main/java/org/chii2/medialibrary/shell/command/MediaLibraryCommandImpl.java
  22. +6 −23 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/ContentManager.java
  23. +12 −0 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualPhotoItem.java
  24. +10 −2 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualPictureItem.java
  25. +98 −87 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/CommonContentManager.java
  26. +7 −52 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/PhotoItem.java
  27. +40 −0 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/PictureItem.java
  28. +6 −6 .../src/main/java/org/chii2/mediaserver/content/common/container/PicturesStorageFolderContainer.java
  29. +24 −4 mediaserver.core/src/main/java/org/chii2/mediaserver/content/xbox/XBoxContentManager.java
  30. +0 −8 mediaserver.core/src/test/java/org/chii2/mediaserver/content/ContentManagerTest.java
  31. +17 −7 mediaserver.http/src/main/java/org/chii2/mediaserver/http/bio/HttpHandler.java
  32. +8 −4 mediaserver.http/src/main/java/org/chii2/mediaserver/http/bio/RangeFileEntity.java
  33. +12 −3 pom.xml
  34. +23 −26 transcoder.api/src/main/java/org/chii2/transcoder/api/core/TranscoderService.java
  35. +29 −20 transcoder.core/src/main/java/org/chii2/transcoder/core/TranscoderServiceImpl.java
  36. +0 −1 transcoder.core/src/main/java/org/chii2/transcoder/core/dlna/codec/ImageType.java
  37. +18 −0 transcoder.core/src/main/java/org/chii2/transcoder/core/dlna/codec/MIME.java
View
BIN assembly/bundle/sanselan-0.97-incubator.jar
Binary file not shown.
View
2 assembly/pom.xml
@@ -62,7 +62,7 @@
</dependency>
<dependency>
<groupId>org.chii2</groupId>
- <artifactId>chii2.medialibrary.graphicsmagickprovider</artifactId>
+ <artifactId>chii2.medialibrary.provider.sanselan</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
View
96 medialibrary.api/src/main/java/org/chii2/medialibrary/api/core/MediaLibraryService.java
@@ -1,6 +1,7 @@
package org.chii2.medialibrary.api.core;
import org.chii2.medialibrary.api.persistence.entity.Image;
+import org.chii2.medialibrary.api.persistence.entity.ImageFile;
import org.chii2.medialibrary.api.persistence.entity.Movie;
import java.util.List;
@@ -121,22 +122,6 @@
/**
* Get all the Images
*
- * @return Image List
- */
- public List<? extends Image> getImages();
-
- /**
- * Get all the Images
- *
- * @param firstResult First Result
- * @param maxResults Max Result
- * @return Image List
- */
- public List<? extends Image> getImages(int firstResult, int maxResults);
-
- /**
- * Get all the Images
- *
* @param firstResult First Result
* @param maxResults Max Result
* @param sorts Sort (by <field, sortType>, sort type maybe "asc" or "desc")
@@ -153,49 +138,18 @@
public Image getImageById(String id);
/**
- * Get all possible image records by image name
- *
- * @param imageName Image Name
- * @return Image List
- */
- public List<? extends Image> getImagesByName(String imageName);
-
- /**
- * Get image records by image name
- *
- * @param firstResult First Result
- * @param maxResults Max Result
- * @param imageName Image Name
- * @return Image List
- */
- public List<? extends Image> getImagesByName(String imageName, int firstResult, int maxResults);
-
- /**
- * Get image records by image name
+ * Get all possible image records by specific image field
+ * Add "file." before ImageFile field
*
+ * @param fieldName Field Name
+ * @param fieldValue Field Value
+ * @param strict Strict compare field value equal, else will use %fieldValue%
* @param firstResult First Result
* @param maxResults Max Result
* @param sorts Sort (by <field, sortType>, sort type maybe "asc" or "desc")
- * @param imageName Image Name
* @return Image List
*/
- public List<? extends Image> getImagesByName(String imageName, int firstResult, int maxResults, Map<String, String> sorts);
-
- /**
- * Get all image albums
- *
- * @return Image Albums
- */
- public List<String> getImageAlbums();
-
- /**
- * Get image albums from index with max limit
- *
- * @param firstResult First Result
- * @param maxResults Max Result
- * @return Image Albums
- */
- public List<String> getImageAlbums(int firstResult, int maxResults);
+ public List<? extends Image> getImagesByField(String fieldName, String fieldValue, boolean strict, int firstResult, int maxResults, Map<String, String> sorts);
/**
* Get image albums from index with max limit
@@ -214,34 +168,6 @@
*/
public long getImageAlbumsCount();
- /**
- * Get images by image album
- *
- * @param album Image Album
- * @return Images
- */
- public List<? extends Image> getImagesByAlbum(String album);
-
- /**
- * Get images by image album
- *
- * @param album Image Album
- * @param firstResult First Result
- * @param maxResults Max Result
- * @return Images
- */
- public List<? extends Image> getImagesByAlbum(String album, int firstResult, int maxResults);
-
- /**
- * Get images by image album
- *
- * @param album Image Album
- * @param firstResult First Result
- * @param maxResults Max Result
- * @param sorts Sort (by <field, sortType>, sort type maybe "asc" or "desc")
- * @return Images
- */
- public List<? extends Image> getImagesByAlbum(String album, int firstResult, int maxResults, Map<String, String> sorts);
/**
* Get count of images belong to specific album
@@ -250,4 +176,12 @@
* @return Count
*/
public long getImagesCountByAlbum(String album);
+
+ /**
+ * Get Image File by ID
+ *
+ * @param id Image File ID
+ * @return Image File
+ */
+ public ImageFile getImageFileById(String id);
}
View
32 ...alibrary.api/src/main/java/org/chii2/medialibrary/api/persistence/PersistenceService.java
@@ -120,15 +120,18 @@
public Image getImageById(String id);
/**
- * Get all possible image records by image name
+ * Get all possible image records by specific image field
+ * Add "file." before ImageFile field
*
- * @param imageName Image Name
+ * @param fieldName Field Name
+ * @param fieldValue Field Value
+ * @param strict Strict compare field value equal, else will use %fieldValue%
* @param firstResult First Result
* @param maxResults Max Result
* @param sorts Sort (by <field, sortType>, sort type maybe "asc" or "desc")
* @return Image List
*/
- public List<? extends Image> getImagesByName(String imageName, int firstResult, int maxResults, Map<String, String> sorts);
+ public List<? extends Image> getImagesByField(String fieldName, String fieldValue, boolean strict, int firstResult, int maxResults, Map<String, String> sorts);
/**
* Get image albums from index with max limit
@@ -148,17 +151,6 @@
public long getImageAlbumsCount();
/**
- * Get images by image album
- *
- * @param album Image Album
- * @param firstResult First Result
- * @param maxResults Max Result
- * @param sorts Sort (by <field, sortType>, sort type maybe "asc" or "desc")
- * @return Image Albums
- */
- public List<? extends Image> getImagesByAlbum(String album, int firstResult, int maxResults, Map<String, String> sorts);
-
- /**
* Get count of images belong to specific album
*
* @param album Image Album
@@ -167,11 +159,6 @@
public long getImagesCountByAlbum(String album);
/**
- * Delete all images in library
- */
- public void deleteAllImages();
-
- /**
* Get Image File by ID
*
* @param id Image File ID
@@ -180,6 +167,13 @@
public ImageFile getImageFileById(String id);
/**
+ * Delete all images in library
+ *
+ * @return the number of instances that were deleted
+ */
+ public int deleteImages();
+
+ /**
* Delete all Movie Information
*/
public void deleteMovieInfo();
View
127 medialibrary.api/src/main/java/org/chii2/medialibrary/api/persistence/entity/Image.java
@@ -22,6 +22,48 @@
public void setId(String id);
/**
+ * Get Image Title
+ *
+ * @return Title
+ */
+ public String getTitle();
+
+ /**
+ * Set Image Title
+ *
+ * @param title Title
+ */
+ public void setTitle(String title);
+
+ /**
+ * Get Image Album
+ *
+ * @return Album
+ */
+ public String getAlbum();
+
+ /**
+ * Set Image Album
+ *
+ * @param album Album
+ */
+ public void setAlbum(String album);
+
+ /**
+ * Get Image Rating
+ *
+ * @return Rating
+ */
+ public float getRating();
+
+ /**
+ * Set Image Rating
+ *
+ * @param rating Rating
+ */
+ public void setRating(float rating);
+
+ /**
* Get the Image File
*
* @return Image File
@@ -36,6 +78,13 @@
public void setFile(ImageFile imageFile);
/**
+ * Image is photo
+ *
+ * @return True if image is photo
+ */
+ public boolean isPhoto();
+
+ /**
* Get Image File Name
*
* @return File Name
@@ -54,7 +103,7 @@
*
* @return Absolute File Name (Including Path)
*/
- public String getAbsoluteName();
+ public String getAbsolutePath();
/**
* Get Image File Extension
@@ -64,20 +113,6 @@
public String getFileExtension();
/**
- * Get Image Title
- *
- * @return Title
- */
- public String getTitle();
-
- /**
- * Get Image Album
- *
- * @return Image Album
- */
- public String getAlbum();
-
- /**
* Get Image Type
*
* @return Type
@@ -141,16 +176,72 @@
public String getExposureTime();
/**
- * Get Image ISO Speed Ratings
+ * Get Image ISO
*
- * @return ISO Speed Ratings
+ * @return ISO
*/
- public int getISOSpeedRatings();
+ public int getISO();
/**
* Get Image Focal Length (mm)
*
* @return Focal Length
*/
public String getFocalLength();
+
+ /**
+ * Get Image User Comment
+ *
+ * @return User Comment
+ */
+ public String getUserComment();
+
+ /**
+ * Get Image Width DPI
+ *
+ * @return Width DPI
+ */
+ public int getWidthDPI();
+
+ /**
+ * Get Image Height DPI
+ *
+ * @return Height DPI
+ */
+ public int getHeightDPI();
+
+ /**
+ * Get Image MIME Type
+ *
+ * @return MIME Type
+ */
+ public String getMimeType();
+
+ /**
+ * Get Image Camera Company
+ *
+ * @return Camera Company
+ */
+ public String getCameraMaker();
+
+ /**
+ * Get Image F Number
+ *
+ * @return F Number
+ */
+ public String getFNumber();
+
+ /**
+ * Get Image Shutter Speed
+ *
+ * @return Shutter Speed
+ */
+ public String getShutterSpeed();
+
+ /**
+ * Get Image Flash
+ *
+ * @return Flash
+ */
+ public int getFlash();
}
View
176 medialibrary.api/src/main/java/org/chii2/medialibrary/api/persistence/entity/ImageFile.java
@@ -17,7 +17,7 @@
/**
* Set the id
*
- * @param id
+ * @param id ID
*/
public void setId(String id);
@@ -36,37 +36,37 @@
public void setFileName(String fileName);
/**
- * Get Image File Path (Directory)
+ * Get Image File Path (Parent Directory)
*
- * @return File Path (Directory)
+ * @return File Path (Parent Directory)
*/
public String getFilePath();
/**
- * Set Image File Path (Directory)
+ * Set Image File Path (Parent Directory)
*
- * @param filePath Movie File Path (Directory)
+ * @param filePath File Path (Parent Directory)
*/
public void setFilePath(String filePath);
/**
- * Get Image Absolute File Name (Including Path)
+ * Get Image Absolute File Path
*
- * @return Absolute File Name (Including Path)
+ * @return Absolute File Path
*/
- public String getAbsoluteName();
+ public String getAbsolutePath();
/**
- * Set Image Absolute File Name (Including Path)
+ * Set Image Absolute File Path
*
- * @param absoluteName Absolute File Name (Including Path)
+ * @param absolutePath Absolute File Path
*/
- public void setAbsoluteName(String absoluteName);
+ public void setAbsolutePath(String absolutePath);
/**
* Get Image File Extension
*
- * @return Movie File Extension
+ * @return File Extension
*/
public String getFileExtension();
@@ -78,34 +78,6 @@
public void setFileExtension(String fileExtension);
/**
- * Get Image Title
- *
- * @return Title
- */
- public String getTitle();
-
- /**
- * Set Image Title
- *
- * @param title Title
- */
- public void setTitle(String title);
-
- /**
- * Get Image Album
- *
- * @return Image Album
- */
- public String getAlbum();
-
- /**
- * Set Image Album
- *
- * @param album Image Album
- */
- public void setAlbum(String album);
-
- /**
* Get Image Type
*
* @return Type
@@ -232,18 +204,18 @@
public void setExposureTime(String exposureTime);
/**
- * Get Image ISO Speed Ratings
+ * Get Image ISO
*
- * @return ISO Speed Ratings
+ * @return ISO
*/
- public int getISOSpeedRatings();
+ public int getISO();
/**
- * Set Image ISO Speed Ratings
+ * Set Image ISO
*
- * @param isoSpeedRatings ISO Speed Ratings
+ * @param iso ISO
*/
- public void setISOSpeedRatings(int isoSpeedRatings);
+ public void setISO(int iso);
/**
* Get Image Focal Length (mm)
@@ -258,4 +230,116 @@
* @param focalLength Focal Length
*/
public void setFocalLength(String focalLength);
+
+ /**
+ * Get Image User Comment
+ *
+ * @return User Comment
+ */
+ public String getUserComment();
+
+ /**
+ * Set Image User Comment
+ *
+ * @param userComment User Comment
+ */
+ public void setUserComment(String userComment);
+
+ /**
+ * Get Image Width DPI
+ *
+ * @return Width DPI
+ */
+ public int getWidthDPI();
+
+ /**
+ * Set Image Width DPI
+ *
+ * @param widthDPI Width DPI
+ */
+ public void setWidthDPI(int widthDPI);
+
+ /**
+ * Get Image Height DPI
+ *
+ * @return Height DPI
+ */
+ public int getHeightDPI();
+
+ /**
+ * Set Image Height DPI
+ *
+ * @param heightDPI Height DPI
+ */
+ public void setHeightDPI(int heightDPI);
+
+ /**
+ * Get Image MIME Type
+ *
+ * @return MIME Type
+ */
+ public String getMimeType();
+
+ /**
+ * Set Image MIME Type
+ *
+ * @param mimeType MIME Type
+ */
+ public void setMimeType(String mimeType);
+
+ /**
+ * Get Image Camera Company
+ *
+ * @return Camera Company
+ */
+ public String getCameraMaker();
+
+ /**
+ * Set Image Camera Company
+ *
+ * @param cameraMaker Camera Company
+ */
+ public void setCameraMaker(String cameraMaker);
+
+ /**
+ * Get Image F Number
+ *
+ * @return F Number
+ */
+ public String getFNumber();
+
+ /**
+ * Set Image F Number
+ *
+ * @param fNumber F Number
+ */
+ public void setFNumber(String fNumber);
+
+ /**
+ * Get Image Shutter Speed
+ *
+ * @return Shutter Speed
+ */
+ public String getShutterSpeed();
+
+ /**
+ * Set Image Shutter Speed
+ *
+ * @param shutterSpeed Shutter Speed
+ */
+ public void setShutterSpeed(String shutterSpeed);
+
+ /**
+ * Get Image Flash
+ *
+ * @return Flash
+ */
+ public int getFlash();
+
+ /**
+ * Set Image Flash
+ *
+ * @param flash Flash
+ */
+ public void setFlash(int flash);
}
View
10 ...brary.api/src/main/java/org/chii2/medialibrary/api/provider/ImageInfoProviderService.java
@@ -8,14 +8,20 @@
*/
public interface ImageInfoProviderService {
+ // Event Topic for image information request
+ // This Event should contains a IMAGE_FILE_PROPERTY, which is a List of File
+ public final static String IMAGE_INFO_REQUEST_TOPIC = "org/chii2/medialibrary/provider/image/INFO_REQUEST";
// Event Topic for image information provided
+ // This Event should contains a IMAGE_INFO_PROPERTY, which is a List of Image
public final static String IMAGE_INFO_PROVIDED_TOPIC = "org/chii2/medialibrary/provider/image/INFO_PROVIDED";
// Event Topic for image information failed (with parse or fetch)
public final static String IMAGE_INFO_FAILED_TOPIC = "org/chii2/medialibrary/provider/image/INFO_FAILED";
- // Image file property key in the image info provided events, this should be the file list from the request
+ // Image file property key in the image info REQUEST & PROVIDED & FAIL events, this should be the file list from the request
public final static String IMAGE_FILE_PROPERTY = "image_file";
- // Image information property key in the image info provided events, this should be the image information result from provider
+ // Image information property key in the image info PROVIDED events, this should be the image information result from provider
public final static String IMAGE_INFO_PROPERTY = "image_info";
+ // Fail reason property key in the image info FAILED events
+ public final static String FAIL_MESSAGE_PROPERTY = "fail_msg";
/**
* Get the provider name
View
53 medialibrary.core/src/main/java/org/chii2/medialibrary/MediaLibraryServiceImpl.java
@@ -3,6 +3,7 @@
import org.chii2.medialibrary.api.core.MediaLibraryService;
import org.chii2.medialibrary.api.file.FileService;
import org.chii2.medialibrary.api.persistence.entity.Image;
+import org.chii2.medialibrary.api.persistence.entity.ImageFile;
import org.chii2.medialibrary.api.persistence.entity.Movie;
import org.chii2.medialibrary.api.persistence.PersistenceService;
import org.osgi.service.event.Event;
@@ -120,16 +121,6 @@ public long getMovieFilesCount() {
}
@Override
- public List<? extends Image> getImages() {
- return persistenceService.getImages(-1, -1, null);
- }
-
- @Override
- public List<? extends Image> getImages(int firstResult, int maxResults) {
- return persistenceService.getImages(firstResult, maxResults, null);
- }
-
- @Override
public List<? extends Image> getImages(int firstResult, int maxResults, Map<String, String> sorts) {
return persistenceService.getImages(firstResult, maxResults, sorts);
}
@@ -140,28 +131,8 @@ public Image getImageById(String id) {
}
@Override
- public List<? extends Image> getImagesByName(String imageName) {
- return persistenceService.getImagesByName(imageName, -1, -1, null);
- }
-
- @Override
- public List<? extends Image> getImagesByName(String imageName, int firstResult, int maxResults) {
- return persistenceService.getImagesByName(imageName, firstResult, maxResults, null);
- }
-
- @Override
- public List<? extends Image> getImagesByName(String imageName, int firstResult, int maxResults, Map<String, String> sorts) {
- return persistenceService.getImagesByName(imageName, firstResult, maxResults, sorts);
- }
-
- @Override
- public List<String> getImageAlbums() {
- return persistenceService.getImageAlbums(-1, -1, null);
- }
-
- @Override
- public List<String> getImageAlbums(int firstResult, int maxResults) {
- return persistenceService.getImageAlbums(firstResult, maxResults, null);
+ public List<? extends Image> getImagesByField(String fieldName, String fieldValue, boolean strict, int firstResult, int maxResults, Map<String, String> sorts) {
+ return persistenceService.getImagesByField(fieldName, fieldValue, strict, firstResult, maxResults, sorts);
}
@Override
@@ -175,23 +146,13 @@ public long getImageAlbumsCount() {
}
@Override
- public List<? extends Image> getImagesByAlbum(String album) {
- return persistenceService.getImagesByAlbum(album, -1, -1, null);
- }
-
- @Override
- public List<? extends Image> getImagesByAlbum(String album, int firstResult, int maxResults) {
- return persistenceService.getImagesByAlbum(album, firstResult, maxResults, null);
- }
-
- @Override
- public List<? extends Image> getImagesByAlbum(String album, int firstResult, int maxResults, Map<String, String> sorts) {
- return persistenceService.getImagesByAlbum(album, firstResult, maxResults, sorts);
+ public long getImagesCountByAlbum(String album) {
+ return persistenceService.getImagesCountByAlbum(album);
}
@Override
- public long getImagesCountByAlbum(String album) {
- return persistenceService.getImagesCountByAlbum(album);
+ public ImageFile getImageFileById(String id) {
+ return persistenceService.getImageFileById(id);
}
/**
View
104 medialibrary.core/src/main/java/org/chii2/medialibrary/event/ImageHandler.java
@@ -1,11 +1,9 @@
package org.chii2.medialibrary.event;
-import org.apache.commons.lang.StringUtils;
import org.chii2.medialibrary.api.file.FileService;
import org.chii2.medialibrary.api.persistence.PersistenceService;
import org.chii2.medialibrary.api.persistence.entity.Image;
import org.chii2.medialibrary.api.provider.ImageInfoProviderService;
-import org.chii2.util.ConfigUtils;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.event.Event;
@@ -17,6 +15,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Dictionary;
+import java.util.Hashtable;
import java.util.List;
/**
@@ -29,14 +28,8 @@
private EventAdmin eventAdmin;
// Injected Persistence Service
private PersistenceService persistenceService;
- // Injected list of Image Information Provider Service
- private List<ImageInfoProviderService> providerServices;
//Configuration FIle
private final static String CONFIG_FILE = "org.chii2.medialibrary.core";
- // Image provider configuration
- private final static String IMAGE_PROVIDER = "image.provider";
- // Preferred Image Information Provider, load from configuration file
- private String preferredProvider = "GraphicsMagick";
// Logger
private Logger logger = LoggerFactory.getLogger("org.chii2.medialibrary.event");
@@ -58,14 +51,6 @@ public void init() {
if (props == null || props.isEmpty()) {
logger.error("ImageHandler load configuration <{}> with error.", CONFIG_FILE);
} else {
- // Load preferred image information provider
- String provider = ConfigUtils.loadConfiguration(props, IMAGE_PROVIDER);
- if (StringUtils.isNotBlank(provider)) {
- preferredProvider = provider;
- logger.debug("ImageHandler configuration <{}> loaded.", IMAGE_PROVIDER);
- } else {
- logger.error("ImageHandler configuration <{}> is not valid.", IMAGE_PROVIDER);
- }
}
}
@@ -83,79 +68,44 @@ public void handleEvent(Event event) {
if (FileService.IMAGE_SCAN_PROVIDED_TOPIC.equals(event.getTopic())) {
// Get List of file names from event, this should be fine
@SuppressWarnings("unchecked")
- List<File> files = (List<File>) event.getProperty("files");
+ List<File> files = (List<File>) event.getProperty(FileService.FILE_PROPERTY);
logger.debug("Receive a image scan event with {} records.", files.size());
- doScanProcess(files);
+ this.postImageInfoRequestEvent(files);
} else if (ImageInfoProviderService.IMAGE_INFO_PROVIDED_TOPIC.equals(event.getTopic())) {
// Get List of Image Information from event, this should be fine
@SuppressWarnings("unchecked")
List<Image> images = (List<Image>) event.getProperty(ImageInfoProviderService.IMAGE_INFO_PROPERTY);
logger.debug("Receive a image information provided event with {} records.", images.size());
- doInfoProvidedProcess(images);
+ // Purge current images
+ persistenceService.deleteImages();
+ // Merge into DB
+ if (images != null) {
+ logger.info("Merge {} images into database", images.size());
+ for (Image image : images) {
+ persistenceService.merge(image);
+ }
+ }
} else if (ImageInfoProviderService.IMAGE_INFO_FAILED_TOPIC.equals(event.getTopic())) {
// Get List of file names from event, this should be fine
@SuppressWarnings("unchecked")
List<File> files = (List<File>) event.getProperty(ImageInfoProviderService.IMAGE_FILE_PROPERTY);
logger.debug("Receive a image information failed event with {} records.", files.size());
- doInfoFailedProcess(files);
- }
- }
-
- /**
- * Parse the scanned image files, (current implementation use GraphicsMagick to handle image metadata)
- * and sync to the database
- *
- * @param files Scanned Image Files
- */
- private void doScanProcess(List<File> files) {
- if (providerServices != null && !providerServices.isEmpty()) {
- // Whether provider match the preferred configuration
- boolean providerMatched = false;
- // Loop available providers
- for (ImageInfoProviderService provider : providerServices) {
- if (preferredProvider.equalsIgnoreCase(provider.getProviderName())) {
- // Matched
- // Purge current images
- persistenceService.deleteAllImages();
- // Use provider parse image information
- provider.getImageInformation(files);
- // Mark match found
- providerMatched = true;
- // Stop looping
- break;
- }
- }
- // If not matched
- if (!providerMatched) {
- logger.error("The image information provider {} is not present.", preferredProvider);
- }
- } else {
- // This won't happens
- logger.error("No Image Information provider available");
}
}
/**
- * Merge each image into database
+ * Send a image information request event
*
- * @param images Images
+ * @param files Files to be parsed
*/
- private void doInfoProvidedProcess(List<Image> images) {
- if (images != null && !images.isEmpty()) {
- logger.debug("Merge {} images into database", images.size());
- for (Image image : images) {
- persistenceService.merge(image);
- }
- }
- }
-
- /**
- * Image Information failed, do nothing atm
- *
- * @param files Image files
- */
- private void doInfoFailedProcess(List<File> files) {
- // Do nothing at the moment
+ private void postImageInfoRequestEvent(List<File> files) {
+ // Prepare properties
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(ImageInfoProviderService.IMAGE_FILE_PROPERTY, files);
+ // Send a event
+ Event event = new Event(ImageInfoProviderService.IMAGE_INFO_REQUEST_TOPIC, properties);
+ logger.debug("Send a image information request event with {} files.", files.size());
+ eventAdmin.postEvent(event);
}
/**
@@ -187,14 +137,4 @@ public void setEventAdmin(EventAdmin eventAdmin) {
public void setPersistenceService(PersistenceService persistenceService) {
this.persistenceService = persistenceService;
}
-
- /**
- * Inject Movie Information Provider Services
- *
- * @param providerServices Movie Information Provider Services
- */
- @SuppressWarnings("unused")
- public void setProviderServices(List<ImageInfoProviderService> providerServices) {
- this.providerServices = providerServices;
- }
}
View
5 medialibrary.core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -18,10 +18,6 @@
<reference id="movieFactoryManager"
interface="org.chii2.medialibrary.api.persistence.factory.MovieFactory"/>
- <!-- Chii2 Media Library Image Information Provider Service -->
- <reference-list id="imageProviderManager"
- interface="org.chii2.medialibrary.api.provider.ImageInfoProviderService"/>
-
<!-- Chii2 Media Library Core Bean -->
<bean id="medialibraryService" class="org.chii2.medialibrary.MediaLibraryServiceImpl"
init-method="init"
@@ -47,7 +43,6 @@
<property name="configAdmin" ref="configAdminService"/>
<property name="eventAdmin" ref="eventAdminService"/>
<property name="persistenceService" ref="persistenceManager"/>
- <property name="providerServices" ref="imageProviderManager"/>
</bean>
<!-- Chii2 Media Library Core Service -->
View
275 ...kprovider/src/main/java/org/chii2/medialibrary/provider/graphicsmagick/ImageAnalyzer.java
@@ -1,275 +0,0 @@
-package org.chii2.medialibrary.provider.graphicsmagick;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.math.NumberUtils;
-import org.chii2.medialibrary.api.persistence.entity.Image;
-import org.chii2.medialibrary.api.persistence.entity.ImageFile;
-import org.chii2.medialibrary.api.persistence.factory.ImageFactory;
-import org.chii2.medialibrary.api.provider.ImageInfoProviderService;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-/**
- * Image Metadata Analyzer based on GraphicsMagick
- */
-public class ImageAnalyzer implements Runnable {
-
- // Image Files
- private List<File> files;
- // EventAdmin
- private EventAdmin eventAdmin;
- // Image Factory
- private ImageFactory imageFactory;
- // Logger
- private Logger logger = LoggerFactory.getLogger("org.chii2.medialibrary.provider.graphicsmagick");
-
- /**
- * Constructor
- *
- * @param files Image Files
- * @param eventAdmin Event Admin
- * @param imageFactory Image Factory
- */
- public ImageAnalyzer(List<File> files, EventAdmin eventAdmin, ImageFactory imageFactory) {
- this.files = files;
- this.eventAdmin = eventAdmin;
- this.imageFactory = imageFactory;
- }
-
- @Override
- public void run() {
- // Prepare commands
- List<String> command = new ArrayList<String>();
- command.add("gm");
- command.add("-identify");
- command.add("-format");
- command.add("%i::%f::%e::%m::%b::%w::%h::%q::%r::%[EXIF:Model]::%[EXIF:DateTime]::%[EXIF:ExposureTime]::%[EXIF:ISOSpeedRatings]::%[EXIF:FocalLength]\\n");
-
- // Add image files
- for (File file : files) {
- command.add(file.getAbsolutePath());
- }
-
- try {
- // Result
- List<Image> images = new ArrayList<Image>();
- // Invoke GraphicMagick via command line interface
- Process process = new ProcessBuilder(command).start();
- BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
- String line;
- while ((line = output.readLine()) != null) {
- String[] result = line.split("::", 14);
- if (result.length == 14) {
- Image image = imageFactory.createImage();
- ImageFile imageFile = imageFactory.createImageFile();
- // Parse and fill image file information
- imageFile.setAbsoluteName(getString(result[0]));
- imageFile.setFileName(getString(result[1]));
- imageFile.setFileExtension(getString(result[2]));
- imageFile.setType(getString(result[3]));
- imageFile.setSize(getFileSize(result[0]));
- imageFile.setWidth(getInt(result[5]));
- imageFile.setHeight(getInt(result[6]));
- imageFile.setColorDepth(getInt(result[7]));
- imageFile.setColorType(getString(result[8]));
- imageFile.setCameraModel(getString(result[9]));
- imageFile.setDateTaken(getDate(result[10]));
- imageFile.setExposureTime(getString(result[11]));
- imageFile.setISOSpeedRatings(getInt(result[12]));
- imageFile.setFocalLength(getString(result[13]));
- imageFile.setFilePath(getFilePath(result[0]));
- imageFile.setTitle(getFileTitle(result[1]));
- imageFile.setAlbum(getFileAlbum(result[0]));
- // Add file
- image.setFile(imageFile);
- // Add to result
- images.add(image);
- }
- }
-
- // The process should be done now, but wait to be sure.
- // If current thread is interrupted, following actions will not be invoked
- process.waitFor();
-
- // raise event
- raiseImageInfoProvidedEvent(images);
- } catch (IOException e) {
- logger.error("A IO Exception occurred when parsing image information with GraphicMagick:{}.", e.getMessage());
- raiseImageInfoFailedEvent();
- } catch (InterruptedException e) {
- logger.debug("Thread has been interrupted, action canceled. <{}>", e.getMessage());
- }
- }
-
- /**
- * Raise a image information provided event
- *
- * @param images Image Information
- */
- private void raiseImageInfoProvidedEvent(List<Image> images) {
- // Prepare properties
- Dictionary<String, Object> properties = new Hashtable<String, Object>();
- properties.put(ImageInfoProviderService.IMAGE_FILE_PROPERTY, files);
- properties.put(ImageInfoProviderService.IMAGE_INFO_PROPERTY, images);
- // Send a event
- Event event = new Event(ImageInfoProviderService.IMAGE_INFO_PROVIDED_TOPIC, properties);
- logger.debug("Send a images information provided event.");
- eventAdmin.postEvent(event);
- }
-
- /**
- * Raise a image information failed event
- */
- private void raiseImageInfoFailedEvent() {
- // Prepare properties
- Dictionary<String, Object> properties = new Hashtable<String, Object>();
- properties.put(ImageInfoProviderService.IMAGE_FILE_PROPERTY, files);
- properties.put(ImageInfoProviderService.IMAGE_INFO_PROPERTY, new ArrayList<Image>());
- // Send a event
- Event event = new Event(ImageInfoProviderService.IMAGE_INFO_FAILED_TOPIC, properties);
- logger.debug("Send a images information failed event.");
- eventAdmin.postEvent(event);
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param s Input String
- * @return Converted String
- */
- private String getString(String s) {
- String result = StringUtils.trim(s);
- if (StringUtils.isEmpty(result)) {
- return null;
- } else if ("unknown".equalsIgnoreCase(result)) {
- return null;
- } else {
- return result;
- }
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param s Input String
- * @return Converted Long
- */
- private long getLong(String s) {
- String result = StringUtils.trim(s);
- if (StringUtils.isEmpty(result)) {
- return 0;
- } else if ("unknown".equalsIgnoreCase(result)) {
- return 0;
- } else {
- return NumberUtils.toLong(result);
- }
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param s Input String
- * @return Converted int
- */
- private int getInt(String s) {
- String result = StringUtils.trim(s);
- if (StringUtils.isEmpty(result)) {
- return 0;
- } else if ("unknown".equalsIgnoreCase(result)) {
- return 0;
- } else {
- return NumberUtils.toInt(result);
- }
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param s Input String
- * @return Converted Date
- */
- private Date getDate(String s) {
- String result = StringUtils.trim(s);
- if (StringUtils.isEmpty(result)) {
- return null;
- } else if ("unknown".equalsIgnoreCase(result)) {
- return null;
- } else {
- try {
- return new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").parse(result);
- } catch (ParseException e) {
- return null;
- }
- }
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param absoluteName Absolute file name
- * @return File path
- */
- private String getFilePath(String absoluteName) {
- File file = new File(absoluteName);
- return file.getParent();
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param absoluteName Absolute file name
- * @return File Parent Name
- */
- private String getFileAlbum(String absoluteName) {
- File file = new File(absoluteName);
- return file.getParentFile().getName();
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param fileName File name
- * @return Title
- */
- private String getFileTitle(String fileName) {
- if (fileName != null) {
- int index = fileName.lastIndexOf('.');
- if (index >= 0) {
- return fileName.substring(0, index);
- } else {
- return fileName;
- }
- } else {
- return null;
- }
- }
-
- /**
- * Convert the GraphicMagick output String to Image File information String
- *
- * @param absoluteName Absolute file name
- * @return File Size in bytes
- */
- private long getFileSize(String absoluteName) {
- File file = new File(absoluteName);
- if (file.exists()) {
- try {
- return file.length();
- } catch (SecurityException e) {
- return 0;
- }
- } else {
- return 0;
- }
- }
-}
View
92 ...ain/java/org/chii2/medialibrary/provider/graphicsmagick/ImageInfoProviderServiceImpl.java
@@ -1,92 +0,0 @@
-package org.chii2.medialibrary.provider.graphicsmagick;
-
-import org.chii2.medialibrary.api.persistence.factory.ImageFactory;
-import org.chii2.medialibrary.api.provider.ImageInfoProviderService;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.event.EventAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Image Information Provider, this provider use GraphicsMagick software to analyze/convert/format image files.
- */
-public class ImageInfoProviderServiceImpl implements ImageInfoProviderService {
- // Injected ConfigAdmin Service
- private ConfigurationAdmin configAdmin;
- // Injected EventAdmin service
- private EventAdmin eventAdmin;
- // Image Factory
- private ImageFactory imageFactory;
- // Logger
- private Logger logger = LoggerFactory.getLogger("org.chii2.medialibrary.provider.graphicsmagick");
-
- /**
- * Life Cycle Init
- */
- @SuppressWarnings("unused")
- public void init() {
- logger.debug("Chii2 Media Library GraphicsMagick Provider init.");
- }
-
- /**
- * Life Cycle Destroy
- */
- @SuppressWarnings("unused")
- public void destroy() {
- logger.debug("Chii2 Media Library GraphicsMagick Provider destroy.");
- }
-
- @Override
- public String getProviderName() {
- return "GraphicsMagick";
- }
-
- @Override
- public void getImageInformation(File imageFile) {
- List<File> fileList = new ArrayList<File>();
- fileList.add(imageFile);
- getImageInformation(fileList);
- }
-
- @Override
- public void getImageInformation(List<File> imageFiles) {
- logger.debug("Chii2 Media Library start a new GraphicsMagick Image Parser thread.");
- Thread imageParseThread = new Thread(new ImageAnalyzer(imageFiles, eventAdmin, imageFactory));
- imageParseThread.setDaemon(false);
- imageParseThread.start();
- }
-
- /**
- * Inject ConfigurationAdmin service
- *
- * @param configAdmin ConfigurationAdmin service
- */
- @SuppressWarnings("unused")
- public void setConfigAdmin(ConfigurationAdmin configAdmin) {
- this.configAdmin = configAdmin;
- }
-
- /**
- * Inject EventAdmin service
- *
- * @param eventAdmin EventAdmin service
- */
- @SuppressWarnings("unused")
- public void setEventAdmin(EventAdmin eventAdmin) {
- this.eventAdmin = eventAdmin;
- }
-
- /**
- * Inject ImageFactory service
- *
- * @param imageFactory ImageFactory service
- */
- @SuppressWarnings("unused")
- public void setImageFactory(ImageFactory imageFactory) {
- this.imageFactory = imageFactory;
- }
-}
View
174 ....persistence/src/main/java/org/chii2/medialibrary/persistence/PersistenceServiceImpl.java
@@ -7,7 +7,6 @@
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.*;
import java.util.ArrayList;
@@ -228,10 +227,20 @@ public long getMovieFilesCount() {
for (Map.Entry<String, String> entry : sorts.entrySet()) {
String field = entry.getKey();
String sortType = entry.getValue();
- if (field != null && sortType != null && sortType.equalsIgnoreCase("asc")) {
- orders.add(builder.asc(images.join("file").get(field)));
- } else if (field != null && sortType != null && sortType.equalsIgnoreCase("desc")) {
- orders.add(builder.desc(images.join("file").get(field)));
+ if (field != null && sortType != null) {
+ if (field.startsWith("file.")) {
+ if (sortType.equalsIgnoreCase("asc")) {
+ orders.add(builder.asc(images.join("files").get(field.substring(5))));
+ } else if (sortType.equalsIgnoreCase("desc")) {
+ orders.add(builder.desc(images.join("files").get(field.substring(5))));
+ }
+ } else {
+ if (sortType.equalsIgnoreCase("asc")) {
+ orders.add(builder.asc(images.get(field)));
+ } else if (sortType.equalsIgnoreCase("desc")) {
+ orders.add(builder.asc(images.get(field)));
+ }
+ }
}
}
selectQuery.orderBy(orders);
@@ -251,43 +260,49 @@ public long getMovieFilesCount() {
@Override
public Image getImageById(String id) {
- // From Query
- CriteriaQuery<ImageImpl> fromQuery = builder.createQuery(ImageImpl.class);
- Root<ImageImpl> images = fromQuery.from(ImageImpl.class);
- // Select Query
- CriteriaQuery<ImageImpl> selectQuery = fromQuery.select(images);
- // Where Query
- selectQuery.where(builder.equal(images.get("id"), id));
- // Final Query
- TypedQuery<ImageImpl> typedQuery = entityManager.createQuery(selectQuery);
- try {
- return typedQuery.getSingleResult();
- } catch (NoResultException e) {
- logger.debug("Try to get image <{}> but not exist.", id);
- return null;
- }
+ return entityManager.find(ImageImpl.class, id);
}
@Override
- public List<? extends Image> getImagesByName(String imageName, int firstResult, int maxResults, Map<String, String> sorts) {
+ public List<? extends Image> getImagesByField(String fieldName, String fieldValue, boolean strict, int firstResult, int maxResults, Map<String, String> sorts) {
// From Query
CriteriaQuery<ImageImpl> fromQuery = builder.createQuery(ImageImpl.class);
Root<ImageImpl> images = fromQuery.from(ImageImpl.class);
- Path<String> name = images.join("file").get("fileName");
+ Path<String> name;
+ if (fieldName.startsWith("file.")) {
+ name = images.join("file").get(fieldName.substring(5));
+ } else {
+ name = images.get(fieldName);
+ }
+
// Select Query
CriteriaQuery<ImageImpl> selectQuery = fromQuery.select(images);
// Where Query
- selectQuery.where(builder.like(builder.lower(name), "%" + imageName.toLowerCase() + "%"));
+ if (strict) {
+ selectQuery.where(builder.like(builder.lower(name), fieldValue.toLowerCase()));
+ } else {
+ selectQuery.where(builder.like(builder.lower(name), "%" + fieldValue.toLowerCase() + "%"));
+ }
// Order query
if (sorts != null) {
List<Order> orders = new ArrayList<Order>();
for (Map.Entry<String, String> entry : sorts.entrySet()) {
String field = entry.getKey();
String sortType = entry.getValue();
- if (field != null && sortType != null && sortType.equalsIgnoreCase("asc")) {
- orders.add(builder.asc(images.join("file").get(field)));
- } else if (field != null && sortType != null && sortType.equalsIgnoreCase("desc")) {
- orders.add(builder.desc(images.join("file").get(field)));
+ if (field != null && sortType != null) {
+ if (field.startsWith("file.")) {
+ if (sortType.equalsIgnoreCase("asc")) {
+ orders.add(builder.asc(images.join("files").get(field.substring(5))));
+ } else if (sortType.equalsIgnoreCase("desc")) {
+ orders.add(builder.desc(images.join("files").get(field.substring(5))));
+ }
+ } else {
+ if (sortType.equalsIgnoreCase("asc")) {
+ orders.add(builder.asc(images.get(field)));
+ } else if (sortType.equalsIgnoreCase("desc")) {
+ orders.add(builder.asc(images.get(field)));
+ }
+ }
}
}
selectQuery.orderBy(orders);
@@ -306,47 +321,26 @@ public Image getImageById(String id) {
}
@Override
- public void deleteAllImages() {
- // Delete all images
- entityManager.createNamedQuery("Image.deleteAll", ImageImpl.class).executeUpdate();
- }
-
- @Override
- public ImageFile getImageFileById(String id) {
- // From Query
- CriteriaQuery<ImageFileImpl> fromQuery = builder.createQuery(ImageFileImpl.class);
- Root<ImageFileImpl> imageFiles = fromQuery.from(ImageFileImpl.class);
- // Select Query
- CriteriaQuery<ImageFileImpl> selectQuery = fromQuery.select(imageFiles);
- // Where Query
- selectQuery.where(builder.equal(imageFiles.get("id"), id));
- // Final Query
- TypedQuery<ImageFileImpl> typedQuery = entityManager.createQuery(selectQuery);
- try {
- return typedQuery.getSingleResult();
- } catch (NoResultException e) {
- logger.debug("Try to get image file <{}> but not exist.", id);
- return null;
- }
- }
-
- @Override
public List<String> getImageAlbums(int firstResult, int maxResults, Map<String, String> sorts) {
// From Query
CriteriaQuery<String> fromQuery = builder.createQuery(String.class);
- Root<ImageFileImpl> imageFiles = fromQuery.from(ImageFileImpl.class);
+ Root<ImageImpl> images = fromQuery.from(ImageImpl.class);
// Select Query
- CriteriaQuery<String> selectQuery = fromQuery.multiselect(imageFiles.get("album"));
+ CriteriaQuery<String> selectQuery = fromQuery.multiselect(images.get("album"));
selectQuery.distinct(true);
if (sorts != null) {
List<Order> orders = new ArrayList<Order>();
for (Map.Entry<String, String> entry : sorts.entrySet()) {
String field = entry.getKey();
String sortType = entry.getValue();
- if (field != null && sortType != null && sortType.equalsIgnoreCase("asc")) {
- orders.add(builder.asc(imageFiles.get(field)));
- } else if (field != null && sortType != null && sortType.equalsIgnoreCase("desc")) {
- orders.add(builder.desc(imageFiles.get(field)));
+ if (field != null && sortType != null) {
+ if (field.equals("album")) {
+ if (sortType.equalsIgnoreCase("asc")) {
+ orders.add(builder.asc(images.get(field)));
+ } else if (sortType.equalsIgnoreCase("desc")) {
+ orders.add(builder.asc(images.get(field)));
+ }
+ }
}
}
selectQuery.orderBy(orders);
@@ -366,66 +360,22 @@ public ImageFile getImageFileById(String id) {
@Override
public long getImageAlbumsCount() {
- // From Query
- CriteriaQuery<Long> fromQuery = builder.createQuery(Long.class);
- Root<ImageFileImpl> imageFiles = fromQuery.from(ImageFileImpl.class);
- // Select Query
- CriteriaQuery<Long> selectQuery = fromQuery.select(builder.count(imageFiles));
- // Final Query
- TypedQuery<Long> typedQuery = entityManager.createQuery(selectQuery);
- return typedQuery.getSingleResult();
+ return entityManager.createQuery("SELECT COUNT(i) FROM IMAGE i", Long.class).getSingleResult();
}
@Override
- public List<? extends Image> getImagesByAlbum(String album, int firstResult, int maxResults, Map<String, String> sorts) {
- // From Query
- CriteriaQuery<ImageImpl> fromQuery = builder.createQuery(ImageImpl.class);
- Root<ImageImpl> images = fromQuery.from(ImageImpl.class);
- Path<String> albumField = images.join("file").get("album");
- // Select Query
- CriteriaQuery<ImageImpl> selectQuery = fromQuery.select(images);
- // Where Query
- selectQuery.where(builder.equal(albumField, album));
- // Order query
- if (sorts != null) {
- List<Order> orders = new ArrayList<Order>();
- for (Map.Entry<String, String> entry : sorts.entrySet()) {
- String field = entry.getKey();
- String sortType = entry.getValue();
- if (field != null && sortType != null && sortType.equalsIgnoreCase("asc")) {
- orders.add(builder.asc(images.join("file").get(field)));
- } else if (field != null && sortType != null && sortType.equalsIgnoreCase("desc")) {
- orders.add(builder.desc(images.join("file").get(field)));
- }
- }
- selectQuery.orderBy(orders);
- }
- // Final Query
- TypedQuery<ImageImpl> typedQuery = entityManager.createQuery(selectQuery);
- // First Result
- if (firstResult >= 0) {
- typedQuery = typedQuery.setFirstResult(firstResult);
- }
- // Max Results
- if (maxResults >= 0) {
- typedQuery = typedQuery.setMaxResults(maxResults);
- }
- return typedQuery.getResultList();
+ public long getImagesCountByAlbum(String album) {
+ return entityManager.createQuery("SELECT COUNT(i) FROM IMAGE i WHERE i.album = ?1", Long.class).setParameter(1, album).getSingleResult();
}
@Override
- public long getImagesCountByAlbum(String album) {
- // From Query
- CriteriaQuery<Long> fromQuery = builder.createQuery(Long.class);
- Root<ImageImpl> images = fromQuery.from(ImageImpl.class);
- Path<String> albumField = images.join("file").get("album");
- // Select Query
- CriteriaQuery<Long> selectQuery = fromQuery.select(builder.count(images));
- // Where Query
- selectQuery.where(builder.equal(albumField, album));
- // Final Query
- TypedQuery<Long> typedQuery = entityManager.createQuery(selectQuery);
- return typedQuery.getSingleResult();
+ public ImageFile getImageFileById(String id) {
+ return entityManager.find(ImageFileImpl.class, id);
+ }
+
+ @Override
+ public int deleteImages() {
+ return entityManager.createQuery("DELETE FROM IMAGE i").executeUpdate();
}
@Override
View
181 ...ry.persistence/src/main/java/org/chii2/medialibrary/persistence/entity/ImageFileImpl.java
@@ -22,26 +22,18 @@
@Column(name = "FILE_NAME")
private String fileName;
- // File Path
+ // File Parent Path
@Column(name = "FILE_PATH")
private String filePath;
- // Absolute File Name
- @Column(name = "ABSOLUTE_NAME")
- private String absoluteName;
+ // Absolute File Path
+ @Column(name = "ABSOLUTE_PATH")
+ private String absolutePath;
// File Extension
@Column(name = "FILE_EXTENSION")
private String fileExtension;
- // Image Title
- @Column(name = "TITLE")
- private String title;
-
- // Image Album
- @Column(name = "ALBUM")
- private String album;
-
// Image Type
@Column(name = "IMAGE_TYPE")
private String type;
@@ -58,6 +50,14 @@
@Column(name = "HEIGHT")
private int height;
+ // Image Width DPI
+ @Column(name = "WIDTH_DPI")
+ private int widthDPI;
+
+ // Image Height DPI
+ @Column(name = "HEIGHT_DPI")
+ private int heightDPI;
+
// Image Color Depth
@Column(name = "COLOR_DEPTH")
private int colorDepth;
@@ -66,6 +66,14 @@
@Column(name = "COLOR_TYPE")
private String colorType;
+ // Image MIME Type
+ @Column(name = "MIME_TYPE")
+ private String mimeType;
+
+ // Image Camera Company
+ @Column(name = "CAMERA_MAKER")
+ private String cameraMaker;
+
// Image Camera Model
@Column(name = "CAMERA_MODEL")
private String cameraModel;
@@ -79,14 +87,31 @@
@Column(name = "EXPOSURE_TIME")
private String exposureTime;
- // Image ISO Speed Ratings
- @Column(name = "ISO_SPEED_RATINGS")
- private int isoSpeedRatings;
+ // Image ISO
+ @Column(name = "ISO")
+ private int iso;
// Image Focal Length
@Column(name = "FOCAL_LENGTH")
private String focalLength;
+ // Image FNumber
+ @Column(name = "F_NUMBER")
+ private String fNumber;
+
+ // Image Shutter Speed
+ @Column(name = "SHUTTER_SPEED")
+ private String shutterSpeed;
+
+ // Image Flash
+ @Column(name = "FLASH")
+ private int flash;
+
+ // Image User Comment
+ // TODO: User should be able to modify the comment, and changes should be saved to physical file
+ @Column(name = "USER_COMMENT")
+ private String userComment;
+
/**
* Constructor
*/
@@ -125,13 +150,13 @@ public void setFilePath(String filePath) {
}
@Override
- public String getAbsoluteName() {
- return absoluteName;
+ public String getAbsolutePath() {
+ return absolutePath;
}
@Override
- public void setAbsoluteName(String absoluteName) {
- this.absoluteName = absoluteName;
+ public void setAbsolutePath(String absolutePath) {
+ this.absolutePath = absolutePath;
}
@Override
@@ -145,26 +170,6 @@ public void setFileExtension(String fileExtension) {
}
@Override
- public String getTitle() {
- return title;
- }
-
- @Override
- public void setTitle(String title) {
- this.title = title;
- }
-
- @Override
- public String getAlbum() {
- return album;
- }
-
- @Override
- public void setAlbum(String album) {
- this.album = album;
- }
-
- @Override
public String getType() {
return type;
}
@@ -200,11 +205,6 @@ public int getHeight() {
}
@Override
- public void setHeight(int height) {
- this.height = height;
- }
-
- @Override
public int getColorDepth() {
return colorDepth;
}
@@ -225,6 +225,11 @@ public void setColorType(String colorType) {
}
@Override
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ @Override
public String getCameraModel() {
return cameraModel;
}
@@ -255,13 +260,13 @@ public void setExposureTime(String exposureTime) {
}
@Override
- public int getISOSpeedRatings() {
- return isoSpeedRatings;
+ public int getISO() {
+ return iso;
}
@Override
- public void setISOSpeedRatings(int isoSpeedRatings) {
- this.isoSpeedRatings = isoSpeedRatings;
+ public void setISO(int iso) {
+ this.iso = iso;
}
@Override
@@ -273,4 +278,84 @@ public String getFocalLength() {
public void setFocalLength(String focalLength) {
this.focalLength = focalLength;
}
+
+ @Override
+ public String getUserComment() {
+ return userComment;
+ }
+
+ @Override
+ public void setUserComment(String userComment) {
+ this.userComment = userComment;
+ }
+
+ @Override
+ public int getWidthDPI() {
+ return widthDPI;
+ }
+
+ @Override
+ public void setWidthDPI(int widthDPI) {
+ this.widthDPI = widthDPI;
+ }
+
+ @Override
+ public int getHeightDPI() {
+ return heightDPI;
+ }
+
+ @Override
+ public void setHeightDPI(int heightDPI) {
+ this.heightDPI = heightDPI;
+ }
+
+ @Override
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ @Override
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+ @Override
+ public String getCameraMaker() {
+ return cameraMaker;
+ }
+
+ @Override
+ public void setCameraMaker(String cameraMaker) {
+ this.cameraMaker = cameraMaker;
+ }
+
+ @Override
+ public String getFNumber() {
+ return fNumber;
+ }
+
+ @Override
+ public void setFNumber(String fNumber) {
+ this.fNumber = fNumber;
+ }
+
+ @Override
+ public String getShutterSpeed() {
+ return shutterSpeed;
+ }
+
+ @Override
+ public void setShutterSpeed(String shutterSpeed) {
+ this.shutterSpeed = shutterSpeed;
+ }
+
+ @Override
+ public int getFlash() {
+ return flash;
+ }
+
+ @Override
+ public void setFlash(int flash) {
+ this.flash = flash;
+ }
}
View
110 ...ibrary.persistence/src/main/java/org/chii2/medialibrary/persistence/entity/ImageImpl.java
@@ -1,5 +1,6 @@
package org.chii2.medialibrary.persistence.entity;
+import org.apache.commons.lang.StringUtils;
import org.chii2.medialibrary.api.persistence.entity.Image;
import org.chii2.medialibrary.api.persistence.entity.ImageFile;
@@ -12,17 +13,25 @@
*/
@Entity(name = "IMAGE")
@Table(name = "IMAGE")
-@NamedQueries({
- @NamedQuery(name = "Image.deleteAll",
- query = "DELETE FROM IMAGE i")
-})
public class ImageImpl implements Image {
// ID (Primary Key) in UUID format
@Id
@Column(name = "ID")
private String id;
+ // Image Title
+ @Column(name = "TITLE")
+ private String title;
+
+ // Image Album
+ @Column(name = "ALBUM")
+ private String album;
+
+ // Image Rating
+ @Column(name = "Rating")
+ private float rating;
+
// Image File
@OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
private ImageFileImpl file;
@@ -45,6 +54,36 @@ public void setId(String id) {
}
@Override
+ public String getTitle() {
+ return title;
+ }
+
+ @Override
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @Override
+ public String getAlbum() {
+ return album;
+ }
+
+ @Override
+ public void setAlbum(String album) {
+ this.album = album;
+ }
+
+ @Override
+ public float getRating() {
+ return rating;
+ }
+
+ @Override
+ public void setRating(float rating) {
+ this.rating = rating;
+ }
+
+ @Override
public ImageFile getFile() {
return file;
}
@@ -57,6 +96,11 @@ public void setFile(ImageFile imageFile) {
}
@Override
+ public boolean isPhoto() {
+ return StringUtils.isNotBlank(this.getCameraModel()) || StringUtils.isNotBlank(this.getCameraMaker());
+ }
+
+ @Override
public String getFileName() {
return file.getFileName();
}
@@ -67,8 +111,8 @@ public String getFilePath() {
}
@Override
- public String getAbsoluteName() {
- return file.getAbsoluteName();
+ public String getAbsolutePath() {
+ return file.getAbsolutePath();
}
@Override
@@ -77,16 +121,6 @@ public String getFileExtension() {
}
@Override
- public String getTitle() {
- return file.getTitle();
- }
-
- @Override
- public String getAlbum() {
- return file.getAlbum();
- }
-
- @Override
public String getType() {
return file.getType();
}
@@ -132,12 +166,52 @@ public String getExposureTime() {
}
@Override
- public int getISOSpeedRatings() {
- return file.getISOSpeedRatings();
+ public int getISO() {
+ return file.getISO();
}
@Override
public String getFocalLength() {
return file.getFocalLength();
}
+
+ @Override
+ public String getUserComment() {
+ return file.getUserComment();
+ }
+
+ @Override
+ public int getWidthDPI() {
+ return file.getWidthDPI();
+ }
+
+ @Override
+ public int getHeightDPI() {
+ return file.getHeightDPI();
+ }
+
+ @Override
+ public String getMimeType() {
+ return file.getMimeType();
+ }
+
+ @Override
+ public String getCameraMaker() {
+ return file.getCameraMaker();
+ }
+
+ @Override
+ public String getFNumber() {
+ return file.getFNumber();
+ }
+
+ @Override
+ public String getShutterSpeed() {
+ return file.getShutterSpeed();
+ }
+
+ @Override
+ public int getFlash() {
+ return file.getFlash();
+ }
}
View
4 ...main/java/org/chii2/medialibrary/provider/mediainfo/MovieFileInfoProviderServiceImpl.java
@@ -156,7 +156,7 @@ public void init() {
}
/**
- * Life Cycle Init
+ * Life Cycle Destroy
*/
@SuppressWarnings("unused")
public void destroy() {
@@ -187,7 +187,7 @@ public String getProviderName() {
public void getMovieFileInformation(File movieFile) {
List<File> fileList = new ArrayList<File>();
fileList.add(movieFile);
- getMovieFileInformation(fileList);
+ this.getMovieFileInformation(fileList);
}
@Override
View
20 medialibrary.graphicsmagickprovider/pom.xml → medialibrary.provider.sanselan/pom.xml
@@ -9,10 +9,10 @@
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>chii2.medialibrary.graphicsmagickprovider</artifactId>
+ <artifactId>chii2.medialibrary.provider.sanselan</artifactId>
<packaging>bundle</packaging>
- <name>Chii2 Media Library GraphicsMagick Provider</name>
+ <name>Chii2 Media Library Sanselan Provider</name>
<url>http://www.chii2.org</url>
<dependencies>
@@ -37,9 +37,23 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sanselan</groupId>
+ <artifactId>sanselan</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -49,7 +63,7 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <Export-Package>org.chii2.medialibrary.provider.graphicsmagick</Export-Package>
+ <Export-Package>org.chii2.medialibrary.provider.sanselan</Export-Package>
</instructions>
</configuration>
</plugin>
View
121 .../src/main/java/org/chii2/medialibrary/provider/sanselan/ImageInfoProviderServiceImpl.java
@@ -0,0 +1,121 @@
+package org.chii2.medialibrary.provider.sanselan;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.chii2.medialibrary.api.persistence.factory.ImageFactory;
+import org.chii2.medialibrary.api.provider.ImageInfoProviderService;
+import org.chii2.medialibrary.provider.sanselan.consumer.ImageAnalyzer;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Image Information Provider Service based on Sanselan
+ */
+public class ImageInfoProviderServiceImpl implements ImageInfoProviderService, EventHandler {
+ // Request queue
+ protected BlockingQueue<List<File>> queue;
+ // Injected ConfigAdmin Service
+ private ConfigurationAdmin configAdmin;
+ // Injected EventAdmin service
+ private EventAdmin eventAdmin;
+ // Image Factory
+ private ImageFactory imageFactory;
+ // Logger
+ private Logger logger = LoggerFactory.getLogger("org.chii2.medialibrary.provider.sanselan");
+
+ /**
+ * Life Cycle Init
+ */
+ @SuppressWarnings("unused")
+ public void init() {
+ logger.debug("Sanselan Provider (Image Information) init.");
+ // Init queue
+ this.queue = new LinkedBlockingQueue<List<File>>();
+ // Start Image Analyzer
+ Thread thread = new Thread(new ImageAnalyzer(this.queue, this.eventAdmin, this.imageFactory));
+ thread.setDaemon(false);
+ thread.start();
+ }
+
+ /**
+ * Life Cycle Destroy
+ */
+ @SuppressWarnings("unused")
+ public void destroy() {
+ logger.debug("Sanselan Provider (Image Information) destroy.");
+ }
+
+ @Override
+ public String getProviderName() {
+ return "Sanselan";
+ }
+
+ @Override
+ public void getImageInformation(File imageFile) {
+ List<File> fileList = new ArrayList<File>();
+ fileList.add(imageFile);
+ this.getImageInformation(fileList);
+ }
+
+ @Override
+ public void getImageInformation(List<File> imageFiles) {
+ try {
+ this.queue.put(imageFiles);
+