Event refactoring
[aquarium] / src / main / scala / gr / grnet / aquarium / store / ResourceEventStore.scala
index 5d3ea4c..cbc9380 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -35,8 +35,8 @@
 
 package gr.grnet.aquarium.store
 
-import com.ckkloverdos.maybe.Maybe
-import gr.grnet.aquarium.logic.events.ResourceEvent
+import gr.grnet.aquarium.AquariumException
+import gr.grnet.aquarium.event.model.resource.ResourceEventModel
 
 /**
  * An abstraction for Aquarium `ResourceEvent` stores.
@@ -45,9 +45,17 @@ import gr.grnet.aquarium.logic.events.ResourceEvent
  * @author Georgios Gousios <gousiosg@gmail.com>.
  */
 trait ResourceEventStore {
-  def storeResourceEvent(event: ResourceEvent): Maybe[RecordID]
+  type ResourceEvent <: ResourceEventModel
 
-  def findResourceEventById(id: String): Maybe[ResourceEvent]
+  def createResourceEventFromOther(event: ResourceEventModel): ResourceEvent
+
+  def clearResourceEvents(): Unit = {
+    throw new AquariumException("Unsupported operation")
+  }
+
+  def insertResourceEvent(event: ResourceEventModel): ResourceEvent
+
+  def findResourceEventById(id: String): Option[ResourceEvent]
 
   def findResourceEventsByUserId(userId: String)(sortWith: Option[(ResourceEvent, ResourceEvent) => Boolean]): List[ResourceEvent]
 
@@ -57,4 +65,27 @@ trait ResourceEventStore {
    * The events are returned in ascending timestamp order.
    */
   def findResourceEventsByUserIdAfterTimestamp(userId: String, timestamp: Long): List[ResourceEvent]
+  
+  def findResourceEventHistory(userId: String, resName: String,
+                               instid: Option[String], upTo: Long) : List[ResourceEvent]
+
+  def findResourceEventsForReceivedPeriod(userId: String, startTimeMillis: Long, stopTimeMillis: Long): List[ResourceEvent]
+
+  /**
+   * Count and return the number of "out of sync" events for a billing month.
+   */
+  def countOutOfSyncEventsForBillingPeriod(userId: String, startMillis: Long, stopMillis: Long): Long
+
+  /**
+   * Finds all relevant resource events for the billing period.
+   * The relevant events are those:
+   * a) whose `occurredMillis` is within the given billing period or
+   * b) whose `receivedMillis` is within the given billing period.
+   *
+   * Order them by `occurredMillis`
+   * FIXME: implement
+   */
+  def findAllRelevantResourceEventsForBillingPeriod(userId: String,
+                                                    startMillis: Long,
+                                                    stopMillis: Long): List[ResourceEvent]
 }
\ No newline at end of file