We don't need no users, let the mf burn. Burn, mf, burn
authorGeorgios Gousios <gousiosg@gmail.com>
Thu, 22 Dec 2011 11:55:05 +0000 (13:55 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Thu, 22 Dec 2011 11:55:49 +0000 (13:55 +0200)
src/main/scala/gr/grnet/aquarium/MasterConf.scala
src/main/scala/gr/grnet/aquarium/logic/events/AquariumEvent.scala
src/main/scala/gr/grnet/aquarium/logic/events/UserEvent.scala
src/main/scala/gr/grnet/aquarium/store/IMStore.scala [deleted file]
src/main/scala/gr/grnet/aquarium/store/StoreProvider.scala
src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala
src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStoreProvider.scala
src/test/scala/gr/grnet/aquarium/store/mongodb/IMStoreTest.scala [deleted file]

index c029d76..f522feb 100644 (file)
@@ -120,17 +120,6 @@ class MasterConf(val props: Props) extends Loggable {
     }
   }
 
-  private[this] lazy val _IMEventStoreM: Maybe[IMStore] = {
-    // If there is a specific `IMStore` implementation specified in the
-    // properties, then this implementation overrides the event store given by
-    // `IMProvider`.
-    props.get(Keys.im_eventstore_class) map { className ⇒
-      val instance = newInstance[IMStore](className)
-      logger.info("Overriding IMStore provisioning. Implementation given by: %s".format(instance.getClass))
-      instance
-    }
-  }
-
   private[this] lazy val _WalletEventStoreM: Maybe[WalletStore] = {
     // If there is a specific `IMStore` implementation specified in the
     // properties, then this implementation overrides the event store given by
@@ -190,13 +179,6 @@ class MasterConf(val props: Props) extends Loggable {
     }
   }
 
-  def IMStore = {
-    _IMEventStoreM match {
-      case Just(es) ⇒ es
-      case _        ⇒ storeProvider.imStore
-    }
-  }
-
   def WalletStore = {
     _WalletEventStoreM match {
       case Just(es) ⇒ es
index d42eaa2..ce4a5b7 100644 (file)
 package gr.grnet.aquarium
 package logic.events
 
-import util.shortClassNameOf
 
 import util.json.JsonSupport
 import util.xml.XmlSupport
+import util.{Loggable, shortClassNameOf}
 
 /**
  * Generic base class for all Aquarium events
@@ -49,7 +49,7 @@ import util.xml.XmlSupport
  */
 
 abstract class AquariumEvent(val id: String, val timestamp: Long)
-  extends JsonSupport with XmlSupport {
+  extends JsonSupport with XmlSupport with Loggable {
 
   def validate: Boolean
 
index 5551c44..5f23c69 100644 (file)
@@ -3,6 +3,7 @@ package gr.grnet.aquarium.logic.events
 import gr.grnet.aquarium.util.json.JsonHelpers
 import net.liftweb.json.{Extraction, parse => parseJson}
 import gr.grnet.aquarium.MasterConf._
+import com.ckkloverdos.maybe.{Failed, NoVal, Just}
 
 /**
  * Represents an incoming user event.
@@ -25,6 +26,10 @@ case class UserEvent(
   assert(state.equalsIgnoreCase("ACTIVE") ||
     state.equalsIgnoreCase("SUSPENDED"))
 
+  if (eventType == 1)
+    if(!state.equalsIgnoreCase("ACTIVE"))
+      assert(false)
+
   /**
    * Validate this event according to the following rules:
    *
@@ -40,31 +45,19 @@ case class UserEvent(
    */
   def validate: Boolean = {
 
-    if (eventType == 1) {
-      if (MasterConf.IMStore.userExists(userId))
-        return false
-
-      if (!state.equalsIgnoreCase("ACTIVE")) return false
-      return true
-    }
-
-    // All user events are of type 2 (modify) from hereon
-    val oldEvent = MasterConf.IMStore.findLastUserEvent(this.userId)
-
-    oldEvent match {
-      case Some(x) =>
-        x.state match {
-          case y if (y.equalsIgnoreCase("SUSPENDED")) => this.state match {
-            case z if (z.equalsIgnoreCase("ACTIVE")) =>  //OK
-            case _ => return false
-          }
-          case y if (y.equalsIgnoreCase("ACTIVE")) =>  this.state match {
-            case z if (z.equalsIgnoreCase("SUSPENDED")) =>
-              if (x.eventType == 2) return false
-            case _ => return false
-          }
+    MasterConf.userStore.findUserStateByUserId(userId) match {
+      case Just(x) =>
+        if (eventType == 1){
+          logger.warn("User to create exists: IMEvent".format(this.toJson));
+          return false
+        }
+      case NoVal =>
+        if (eventType != 2){
+          logger.warn("Inexistent user to modify. IMEvent:".format(this.toJson))
+          return false
         }
-      case None => return false
+      case Failed(x,y) =>
+        logger.warn("Error retrieving user state: %s".format(x))
     }
 
     true
diff --git a/src/main/scala/gr/grnet/aquarium/store/IMStore.scala b/src/main/scala/gr/grnet/aquarium/store/IMStore.scala
deleted file mode 100644 (file)
index cf6440b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2011 GRNET S.A. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- *   1. Redistributions of source code must retain the above
- *      copyright notice, this list of conditions and the following
- *      disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above
- *      copyright notice, this list of conditions and the following
- *      disclaimer in the documentation and/or other materials
- *      provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and
- * documentation are those of the authors and should not be
- * interpreted as representing official policies, either expressed
- * or implied, of GRNET S.A.
- */
-
-package gr.grnet.aquarium.store
-
-import com.ckkloverdos.maybe.Maybe
-import gr.grnet.aquarium.logic.events.{UserEvent, AquariumEvent}
-
-/**
- * A store for IM events
- *
- * @author Georgios Gousios <gousiosg@gmail.com>
- */
-trait IMStore {
-
-  def storeUserEvent(event: UserEvent): Maybe[RecordID]
-
-  def findUserEventById[A <: UserEvent](id: String): Option[A]
-
-  def findUserEventsByUserId[A <: UserEvent](userId: String)(sortWith: Option[(A, A) => Boolean]): List[A]
-
-  def findLastUserEvent(userId: String): Option[UserEvent]
-
-  def userExists(userId: String): Boolean
-}
\ No newline at end of file
index 62af1a6..3862310 100644 (file)
@@ -43,6 +43,5 @@ package gr.grnet.aquarium.store
 trait StoreProvider {
   def userStore: UserStore
   def eventStore: EventStore
-  def imStore: IMStore
   def walletStore: WalletStore
 }
\ No newline at end of file
index 6be0ced..422f3f3 100644 (file)
@@ -59,8 +59,7 @@ class MongoDBStore(
     val database: String,
     val username: String,
     val password: String)
-  extends EventStore with UserStore
-  with IMStore with WalletStore with Loggable {
+  extends EventStore with UserStore with WalletStore with Loggable {
 
   private[store] lazy val events: DBCollection = getCollection(MongoDBStore.EVENTS_COLLECTION)
   private[store] lazy val users: DBCollection = getCollection(MongoDBStore.USERS_COLLECTION)
@@ -226,24 +225,6 @@ class MongoDBStore(
   }
   //-UserStore
 
-  //+IMStore
-  def storeUserEvent(event: UserEvent): Maybe[RecordID] = _store(event, imevents)
-
-  def findUserEventById[A <: UserEvent](id: String): Option[A] = _findById(id, imevents)
-
-  def findUserEventsByUserId[A <: UserEvent](userId: String)(sortWith: Option[(A, A) => Boolean]): List[A] = {
-    val q = new BasicDBObject()
-    q.put("userId", userId)
-
-    _query(q, imevents)(sortWith)
-  }
-
-  def findLastUserEvent(userId: String) =
-    findUserEventsByUserId(userId)(Some(_sortByTimestampDesc)).headOption
-
-  def userExists(userId: String) = false //TODO: Write me
-  //-IMStore
-
   //+WalletStore
   def store(entry: WalletEntry): Maybe[RecordID] = _store(entry, wallets)
 
index 80530ae..e072f8b 100644 (file)
@@ -54,7 +54,6 @@ class MongoDBStoreProvider extends StoreProvider with Configurable {
 
   private[this] var _eventStore: EventStore = _
   private[this] var _userStore: UserStore = _
-  private[this] var _imStore: IMStore = _
   private[this] var _walletStore: WalletStore = _
 
   def configure(props: Props) = {
@@ -72,7 +71,6 @@ class MongoDBStoreProvider extends StoreProvider with Configurable {
       val mongoStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
       this._eventStore = mongoStore
       this._userStore  = mongoStore
-      this._imStore  = mongoStore
       this._walletStore  = mongoStore
     } catch {
       case e: MongoException =>
@@ -84,7 +82,5 @@ class MongoDBStoreProvider extends StoreProvider with Configurable {
 
   def eventStore = _eventStore
 
-  def imStore = _imStore
-
   def walletStore = _walletStore
 }
\ No newline at end of file
diff --git a/src/test/scala/gr/grnet/aquarium/store/mongodb/IMStoreTest.scala b/src/test/scala/gr/grnet/aquarium/store/mongodb/IMStoreTest.scala
deleted file mode 100644 (file)
index 65da937..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-package gr.grnet.aquarium.store.mongodb
-
-import gr.grnet.aquarium.util.{RandomEventGenerator, TestMethods}
-import gr.grnet.aquarium.MasterConf._
-import org.junit.Assume._
-import gr.grnet.aquarium.LogicTestsAssumptions
-import org.junit.{After, Test}
-
-/**
- *
- * @author Georgios Gousios <gousiosg@gmail.com>
- */
-class IMStoreTest extends TestMethods with RandomEventGenerator {
-
-  @Test
-  def testStoreEvent() = {
-    assumeTrue(LogicTestsAssumptions.EnableStoreTests)
-
-    val event = nextUserEvent()
-    val store = MasterConf.IMStore
-    val result = store.storeUserEvent(event)
-
-    assert(result.isJust)
-  }
-
-  @Test
-  def testfindUserEventById() = {
-
-  }
-
-  @After
-  def after() = {
-    val a = getMongo
-
-    val col = a.mongo.getDB(
-      MasterConf.get(Keys.persistence_db)).getCollection(
-        MongoDBStore.IM_EVENTS_COLLECTION)
-
-    val res = col.find
-    while (res.hasNext)
-      col.remove(res.next)
-  }
-
-  private def getMongo = MasterConf.IMStore.asInstanceOf[MongoDBStore]
-}
\ No newline at end of file