}
}
- 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
}
}
- def IMStore = {
- _IMEventStoreM match {
- case Just(es) ⇒ es
- case _ ⇒ storeProvider.imStore
- }
- }
-
def WalletStore = {
_WalletEventStoreM match {
case Just(es) ⇒ es
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
*/
abstract class AquariumEvent(val id: String, val timestamp: Long)
- extends JsonSupport with XmlSupport {
+ extends JsonSupport with XmlSupport with Loggable {
def validate: Boolean
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.
assert(state.equalsIgnoreCase("ACTIVE") ||
state.equalsIgnoreCase("SUSPENDED"))
+ if (eventType == 1)
+ if(!state.equalsIgnoreCase("ACTIVE"))
+ assert(false)
+
/**
* Validate this event according to the following rules:
*
*/
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
+++ /dev/null
-/*
- * 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
trait StoreProvider {
def userStore: UserStore
def eventStore: EventStore
- def imStore: IMStore
def walletStore: WalletStore
}
\ No newline at end of file
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)
}
//-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)
private[this] var _eventStore: EventStore = _
private[this] var _userStore: UserStore = _
- private[this] var _imStore: IMStore = _
private[this] var _walletStore: WalletStore = _
def configure(props: Props) = {
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 =>
def eventStore = _eventStore
- def imStore = _imStore
-
def walletStore = _walletStore
}
\ No newline at end of file
+++ /dev/null
-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