|
@ -19,7 +19,11 @@ object ImageService extends Logging { |
|
|
private def lookupImage(file:File):Image = { |
|
|
private def lookupImage(file:File):Image = { |
|
|
var image:Image = null |
|
|
var image:Image = null |
|
|
//get from memory cache if possible |
|
|
//get from memory cache if possible |
|
|
|
|
|
try { |
|
|
if (imageCache.isKeyInCache(file.getAbsolutePath)) image = imageCache.get(file.getAbsolutePath).getObjectValue.asInstanceOf[Image] |
|
|
if (imageCache.isKeyInCache(file.getAbsolutePath)) image = imageCache.get(file.getAbsolutePath).getObjectValue.asInstanceOf[Image] |
|
|
|
|
|
} catch { |
|
|
|
|
|
case npe:NullPointerException => error(s"Error grabbing \'${file.getAbsolutePath}\' from cache", npe) |
|
|
|
|
|
} |
|
|
//get from datastore if possible |
|
|
//get from datastore if possible |
|
|
image |
|
|
image |
|
|
} |
|
|
} |
|
@ -57,7 +61,7 @@ object ImageService extends Logging { |
|
|
def calculateThumbPath(md5:String):String = { |
|
|
def calculateThumbPath(md5:String):String = { |
|
|
//break the path down into 4 char parts |
|
|
//break the path down into 4 char parts |
|
|
val split:List[String] = md5.grouped(4).toList |
|
|
val split:List[String] = md5.grouped(4).toList |
|
|
var path:String = PropertiesService.get(PropertiesEnum.ThumbnailDirectory.toString) + "/" + PropertiesService.get(PropertiesEnum.ThumbnailSize.toString) + "/" |
|
|
|
|
|
|
|
|
var path:String = PropertiesService.get(PropertiesEnum.ThumbnailDirectory.toString) + PropertiesService.get(PropertiesEnum.ThumbnailSize.toString) + "/" |
|
|
for (seg <- split) path += seg + "/" |
|
|
for (seg <- split) path += seg + "/" |
|
|
try { |
|
|
try { |
|
|
val dir = new File(path) |
|
|
val dir = new File(path) |
|
@ -71,12 +75,20 @@ object ImageService extends Logging { |
|
|
|
|
|
|
|
|
def lookupThumbnailPath(md5:String):String = { |
|
|
def lookupThumbnailPath(md5:String):String = { |
|
|
var thumbPath:String = null |
|
|
var thumbPath:String = null |
|
|
|
|
|
if (md5 != null) { |
|
|
//get from memory cache if possible |
|
|
//get from memory cache if possible |
|
|
if (thumbnailCache.isKeyInCache(md5)) thumbPath = imageCache.get(md5).getObjectValue.asInstanceOf[String] |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
if (thumbnailCache.isKeyInCache(md5)) thumbPath = thumbnailCache.get(md5).getObjectValue.asInstanceOf[String] |
|
|
|
|
|
} catch { |
|
|
|
|
|
case npe:NullPointerException => error(s"Error grabbing \'$md5\' from cache. thumbPath: \'$thumbPath\'", npe) |
|
|
|
|
|
} |
|
|
//get from datastore if possible |
|
|
//get from datastore if possible |
|
|
//check for the actual file |
|
|
//check for the actual file |
|
|
val checkPath = calculateThumbPath(md5) |
|
|
val checkPath = calculateThumbPath(md5) |
|
|
if (new File(checkPath).exists) thumbPath = checkPath |
|
|
if (new File(checkPath).exists) thumbPath = checkPath |
|
|
|
|
|
} else { |
|
|
|
|
|
error("Null md5 passed in") |
|
|
|
|
|
} |
|
|
thumbPath |
|
|
thumbPath |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -97,6 +109,7 @@ object ImageService extends Logging { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def saveThumbnail(md5:String, thumbnailPath:String):String = { |
|
|
def saveThumbnail(md5:String, thumbnailPath:String):String = { |
|
|
|
|
|
if (md5 == null || thumbnailPath == null) error(s"Error trying to save a md5: $md5 path: $thumbnailPath") |
|
|
//save to cache |
|
|
//save to cache |
|
|
thumbnailCache.put(new Element(md5, thumbnailPath)) |
|
|
thumbnailCache.put(new Element(md5, thumbnailPath)) |
|
|
//save to datastore |
|
|
//save to datastore |
|
|