scala-news-reader
rss/atom news reader in scala
git clone https://9o.is/git/scala-news-reader.git
ArticleSharedListField.scala
(1010B)
1 package com.joereader.model.field
2
3 import com.mongodb._
4 import net.liftweb._
5 import common._
6 import mongodb.record._
7 import field._
8 import net.liftmodules.mongoauth._
9
10 import com.joereader.model._
11
12 /**
13 * Mongo Field to store shared articles.
14 * Does not save article's content, just the guid.
15 */
16 class ArticleSharedListField[
17 OwnerType <: BsonRecord[OwnerType],
18 OwnerTypeUser <: User](rec: OwnerType, recUser: OwnerTypeUser)
19 extends MongoListField[OwnerType, ArticleShared](rec)
20 with MongoListFieldExtra[OwnerType, ArticleShared] {
21
22 import scala.collection.JavaConversions._
23
24 override def asDBObject: DBObject = {
25 val dbl = new BasicDBList
26 value.foreach { v => dbl.add(v.toString) }
27 dbl
28 }
29
30 override def setFromDBObject(dbo: DBObject): Box[List[ArticleShared]] =
31 setBox(Full(dbo.keySet.toList.map(k => {
32 val a = ArticleShared.fromString(dbo.get(k.toString).asInstanceOf[String])
33 new ArticleShared(a.bwu, a.entry, a.date, new BlogWriterUser(recUser))
34 })))
35 }