PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/scala/com/theintelligentbook/ibmodel/mongo/Presentation.scala

https://bitbucket.org/wbillingsley/ibmongo-2012-old-version-duct-tape-not-maintained
Scala | 71 lines | 43 code | 20 blank | 8 comment | 0 complexity | c6ed058d35e9315bed9768988faed2ed MD5 | raw file
  1. package com.theintelligentbook.ibmodel.mongo
  2. import com.mongodb.casbah.Imports._
  3. import java.util.Date
  4. import com.novus.salat._
  5. import com.novus.salat.global._
  6. import com.novus.salat.dao.SalatDAO
  7. import com.wbillingsley.handy._
  8. import com.novus.salat.annotations._
  9. /**
  10. *
  11. * @param _id
  12. * @param ce
  13. * @param book A presentation always belongs to a book
  14. * @param protect A presentation always has an associated ContentEntry (to record the name, topics, etc)
  15. * @param entries
  16. */
  17. case class Presentation (
  18. _id:ObjectId = new ObjectId(),
  19. @Key("ce") _ce:Option[ObjectId] = None,
  20. @Key("book") _book:Option[ObjectId] = None,
  21. var protect:Boolean = false,
  22. @Key("entries") var _entries:Seq[ObjectId] = Seq.empty[ObjectId]
  23. ) extends HasObjectId {
  24. def id = _id
  25. def book = Ref.fromOptionId(classOf[Book], _book)
  26. def ce = Ref.fromOptionId(classOf[ContentEntry], _ce)
  27. def entries = new RefManyById(classOf[ContentEntry], _entries)
  28. def entries_=(l:RefManyById[ContentEntry, _]) {
  29. _entries = l.getIds
  30. }
  31. def start = entries.first
  32. }
  33. object PresentationDAO extends AbstractDAO[Presentation]("presentation") {
  34. def presentationsContainingEntry(entry:Ref[ContentEntry]) = {
  35. val idOpt = entry.getId
  36. val result = idOpt map { oid =>
  37. val ccSeq = sdao.find(MongoDBObject("entries" -> oid))
  38. ccSeq.toSeq
  39. }
  40. result.getOrElse(Seq.empty[Presentation])
  41. }
  42. def newPresentation(book:Ref[Book], ce:Ref[ContentEntry]) = {
  43. val p = new Presentation(_book = book.getId, _ce = ce.getId)
  44. DAO.cache(RefById(classOf[Presentation], p.id), RefItself(p))
  45. p
  46. }
  47. def save(p:Presentation) {
  48. DAO.cache(RefById(classOf[Presentation], p.id), RefItself(p))
  49. sdao.save(p)
  50. }
  51. }