Add support for DB _id
authorChristos KK Loverdos <loverdos@gmail.com>
Fri, 16 Mar 2012 16:02:38 +0000 (18:02 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Fri, 16 Mar 2012 16:02:38 +0000 (18:02 +0200)
src/main/scala/gr/grnet/aquarium/user/UserState.scala

index b042eca..3b43fab 100644 (file)
@@ -130,7 +130,11 @@ case class UserState(
     rolesSnapshot: RolesSnapshot,
     ownedResourcesSnapshot: OwnedResourcesSnapshot,
     calculationReason: UserStateCalculationReason = NoSpecificCalculationReason,
-    totalEventsProcessedCounter: Long = 0L
+    totalEventsProcessedCounter: Long = 0L,
+    // The user state we used to compute this one. Normally the (cached)
+    // state at the beginning of the billing period.
+    parentUserStateId: Option[String] = None,
+    _id: String = ""
 ) extends JsonSupport {
 
   private[this] def _allSnapshots: List[Long] = {
@@ -147,6 +151,12 @@ case class UserState(
 
   def newestSnapshotTime: Long  = _allSnapshots max
 
+  def idOpt: Option[String] = _id match {
+    case null ⇒ None
+    case ""   ⇒ None
+    case _id  ⇒ Some(_id)
+  }
+
 //  def userCreationDate = new Date(userCreationMillis)
 //
 //  def userCreationFormatedDate = new MutableDateCalc(userCreationMillis).toString