/app/processors/ThumbnailDeletionProcessor.scala

https://github.com/delving/dos · Scala · 49 lines · 26 code · 4 blank · 19 comment · 3 complexity · c31d07f50259b173194cfd20b7501c9e MD5 · raw file

  1. /*
  2. * Copyright 2011 Delving B.V.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package processors
  17. import controllers.dos._
  18. import models.dos.Task
  19. import java.io.File
  20. import controllers.dos.Thumbnail
  21. import org.bson.types.ObjectId
  22. import com.mongodb.casbah.commons.MongoDBObject
  23. /**
  24. *
  25. * @author Manuel Bernhardt <bernhardt.manuel@gmail.com>
  26. */
  27. object ThumbnailDeletionProcessor extends Processor with Thumbnail {
  28. def process(task: Task, processorParams: Map[String, AnyRef]) {
  29. if (!task.params.contains(controllers.dos.COLLECTION_IDENTIFIER_FIELD) || !task.params.contains(controllers.dos.ORGANIZATION_IDENTIFIER_FIELD)) {
  30. error(task, "No spec or organisation provided")
  31. } else {
  32. info(task, "Starting to delete thumbnails for directory " + task.path)
  33. val thumbs = fileStore.find(MongoDBObject(ORIGIN_PATH_FIELD -> task.path.r, COLLECTION_IDENTIFIER_FIELD -> task.params(COLLECTION_IDENTIFIER_FIELD).toString, ORGANIZATION_IDENTIFIER_FIELD -> task.params(ORGANIZATION_IDENTIFIER_FIELD).toString))
  34. Task.setTotalItems(task, thumbs.size)
  35. thumbs foreach {
  36. t => {
  37. val origin = t.get(ORIGIN_PATH_FIELD).toString
  38. info(task, "Removing thumbnails for image " + origin, Some(origin))
  39. Task.incrementProcessedItems(task, 1)
  40. fileStore.remove(t.getId.asInstanceOf[ObjectId])
  41. }
  42. }
  43. }
  44. }
  45. }