WIP: ResourceEvent-related refactorings
[aquarium] / src / main / scala / gr / grnet / aquarium / store / ResourceEventStore.scala
index 4f58488..4eb6016 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
@@ -36,7 +36,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.resource.ResourceEventModel
 
 /**
  * An abstraction for Aquarium `ResourceEvent` stores.
@@ -45,9 +46,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]
 
@@ -62,19 +71,22 @@ trait ResourceEventStore {
                                instid: Option[String], upTo: Long) : List[ResourceEvent]
 
   def findResourceEventsForReceivedPeriod(userId: String, startTimeMillis: Long, stopTimeMillis: Long): List[ResourceEvent]
-  
-  def countOutOfSyncEventsForBillingMonth(userId: String, yearOfBillingMonth: Int, billingMonth: Int): Maybe[Long]
+
+  /**
+   * 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 and
+   * 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] =
-    findResourceEventsForReceivedPeriod(userId, startMillis, stopMillis)
+                                                    stopMillis: Long): List[ResourceEvent]
 }
\ No newline at end of file