Removed bad imports of BillEntry and AbstractBillEntry
[aquarium] / src / main / scala / gr / grnet / aquarium / actor / service / user / UserActor.scala
index 6cdda83..065107d 100644 (file)
@@ -51,7 +51,6 @@ import gr.grnet.aquarium.actor.message.GetUserWalletResponse
 import gr.grnet.aquarium.actor.message.GetUserWalletResponseData
 import gr.grnet.aquarium.actor.message.config.AquariumPropertiesLoaded
 import gr.grnet.aquarium.actor.message.config.InitializeUserActorState
-import gr.grnet.aquarium.charging.bill.AbstractBillEntry
 import gr.grnet.aquarium.charging.state.{UserStateModel, UserAgreementHistoryModel, UserStateBootstrap}
 import gr.grnet.aquarium.computation.BillingMonthInfo
 import gr.grnet.aquarium.message.avro.gen.{IMEventMsg, ResourceEventMsg, UserStateMsg}
@@ -59,6 +58,8 @@ import gr.grnet.aquarium.message.avro.{ModelFactory, MessageFactory, MessageHelp
 import gr.grnet.aquarium.service.event.BalanceEvent
 import gr.grnet.aquarium.util.date.TimeHelpers
 import gr.grnet.aquarium.util.{LogHelpers, shortClassNameOf}
+import gr.grnet.aquarium.policy.{ResourceType, PolicyModel}
+import gr.grnet.aquarium.charging.bill.BillEntryMsg
 
 /**
  *
@@ -322,7 +323,7 @@ class UserActor extends ReflectiveRoleableActor {
     val eventMonth = eventBillingMonthInfo.month
 
     def computeBatch(): Unit = {
-      DEBUG("Going for out of sync charging")
+      DEBUG("Going for out of sync charging for %s", rcEvent.getOriginalID)
       this._userState = chargingService.replayMonthChargingUpTo(
         nowBillingMonthInfo,
         // Take into account that the event may be out-of-sync.
@@ -337,7 +338,7 @@ class UserActor extends ReflectiveRoleableActor {
     }
 
     def computeRealtime(): Unit = {
-      DEBUG("Going for in sync charging")
+      DEBUG("Going for in sync charging for %s", rcEvent.getOriginalID)
       chargingService.processResourceEvent(
         rcEvent,
         this._userState,
@@ -392,9 +393,18 @@ class UserActor extends ReflectiveRoleableActor {
   def onGetUserBillRequest(event: GetUserBillRequest): Unit = {
     try{
       val timeslot = event.timeslot
+      val resourceTypes = aquarium.policyStore.
+                          loadSortedPolicyModelsWithin(timeslot.from.getTime,
+                                                       timeslot.to.getTime).
+                          values.headOption match {
+          case None => Map[String,ResourceType]()
+          case Some(policy:PolicyModel) => policy.resourceTypesMap
+      }
       val state= if(haveUserState) Some(this._userState.msg) else None
-      val billEntry = AbstractBillEntry.fromWorkingUserState(timeslot,this._userID,state)
-      val billData = GetUserBillResponseData(this._userID,billEntry)
+      val billEntryMsg = BillEntryMsg.fromWorkingUserState(timeslot,this._userID,state,resourceTypes)
+      //val billEntryMsg = MessageFactory.createBillEntryMsg(billEntry)
+      //logger.debug("BILL ENTRY MSG: " + billEntryMsg.toString)
+      val billData = GetUserBillResponseData(this._userID,billEntryMsg)
       sender ! GetUserBillResponse(Right(billData))
     } catch {
       case e:Exception =>