*/
def contains(t: Timeslot) : Boolean = this.start <= t.start && this.end >= t.end
- private[dsl] def weakIncludes(t: Date) : Boolean = start < t.getTime && t.getTime < end
+ def weakIncludes(t: Date) : Boolean = start < t.getTime && t.getTime < end
def weakOverlaps(t: Timeslot) : Boolean =
contains(t) || t.contains(this) || this.weakIncludes(t.from) || this.weakIncludes(t.to)
/**
* Check whether this timeslot contains the provided time instant.
*/
- private[dsl] def includes(t: Date) : Boolean = start <= t.getTime && t.getTime <= end
+ def includes(t: Date) : Boolean = start <= t.getTime && t.getTime <= end
/**
import gr.grnet.aquarium.policy.{PolicyModel, StdPolicy}
import collection.immutable.SortedMap
import gr.grnet.aquarium.logic.accounting.dsl.Timeslot
+import collection.immutable
+import java.util.Date
/**
* An implementation of various stores that persists parts in memory.
}
def loadValidPolicyAt(atMillis: Long): Option[Policy] = {
- throw new UnsupportedOperationException
+ var d = new Date(atMillis)
+ /* sort in reverse order and return the first that includes this date*/
+ _policies.sortWith({(x,y)=> y.validFrom < x.validFrom}).collectFirst({
+ case t if(t.validityTimespan.toTimeslot.includes(d)) => t
+ })
}
+ private def emptyMap = immutable.SortedMap[Timeslot,Policy]()
+
def loadAndSortPoliciesWithin(fromMillis: Long, toMillis: Long): SortedMap[Timeslot, Policy] = {
- throw new UnsupportedOperationException
+ val range = Timeslot(fromMillis,toMillis)
+ _policies.foldLeft (emptyMap) { (map,p) =>
+ if(range.overlaps(p.validityTimespan.toTimeslot))
+ map + ((p.validityTimespan.toTimeslot,p))
+ else
+ map
+ }
}
}
import gr.grnet.aquarium.{Aquarium, AquariumException}
import collection.immutable.SortedMap
import gr.grnet.aquarium.logic.accounting.dsl.Timeslot
+import collection.immutable
+import java.util.Date
/**
* Mongodb implementation of the various aquarium stores.
//+PolicyStore
- def loadPoliciesAfter(after: Long): List[Policy] = {
- // FIXME implement
- throw new UnsupportedOperationException
- }
-
-
- def findPolicyByID(id: String) = {
- // FIXME implement
- throw new UnsupportedOperationException
- }
-
/**
* Store an accounting policy.
*/
MongoDBStore.insertObject(dbPolicy, policies, MongoDBStore.jsonSupportToDBObject)
}
+ private def emptyMap = immutable.SortedMap[Timeslot,Policy]()
+
def loadValidPolicyAt(atMillis: Long): Option[Policy] = {
+ /*var d = new Date(atMillis)
+ /* sort in reverse order and return the first that includes this date*/
+ policies.sortWith({(x,y)=> y.validFrom < x.validFrom}).collectFirst({
+ case t if(t.validityTimespan.toTimeslot.includes(d)) => t
+ })*/
throw new UnsupportedOperationException
}
def loadAndSortPoliciesWithin(fromMillis: Long, toMillis: Long): SortedMap[Timeslot, Policy] = {
+
throw new UnsupportedOperationException
}
//-PolicyStore