Always calculate wallet entries
authorChristos KK Loverdos <loverdos@gmail.com>
Mon, 18 Jun 2012 13:06:44 +0000 (16:06 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Mon, 18 Jun 2012 13:06:44 +0000 (16:06 +0300)
src/main/scala/gr/grnet/aquarium/computation/UserStateComputations.scala
src/main/scala/gr/grnet/aquarium/computation/reason/UserStateChangeReason.scala

index 85ade99..4c7bf28 100644 (file)
@@ -35,8 +35,8 @@
 
 package gr.grnet.aquarium.computation
 
-import scala.collection.mutable
 import gr.grnet.aquarium.util.{ContextualLogger, Loggable}
+import gr.grnet.aquarium.util.shortClassNameOf
 import gr.grnet.aquarium.util.date.{TimeHelpers, MutableDateCalc}
 import gr.grnet.aquarium.logic.accounting.dsl.DSLResourcesMap
 import gr.grnet.aquarium.computation.state.parts._
@@ -211,7 +211,7 @@ final class UserStateComputations(_aquarium: => Aquarium) extends Loggable {
       case Some(dslResource) ⇒
         val costPolicy = dslResource.costPolicy
         clog.debug("%s for %s", costPolicy, dslResource)
-        val isBillable = costPolicy.isBillableEventBasedOnValue(theValue)
+        val isBillable = costPolicy.isBillableEvent(currentResourceEvent)
         if(!isBillable) {
           // The resource event is not billable
           clog.debug("Ignoring not billable %s", currentResourceEventDebugInfo)
@@ -295,30 +295,26 @@ final class UserStateComputations(_aquarium: => Aquarium) extends Loggable {
             val newCreditsDiff = fullChargeslots.map(_.computedCredits.get).sum
             val newCredits = oldCredits - newCreditsDiff
 
-            if(stateChangeReason.shouldStoreCalculatedWalletEntries) {
-              val newWalletEntry = NewWalletEntry(
-                userStateWorker.userID,
-                newCreditsDiff,
-                oldCredits,
-                newCredits,
-                TimeHelpers.nowMillis(),
-                referenceTimeslot,
-                billingMonthInfo.year,
-                billingMonthInfo.month,
-                if(havePreviousResourceEvent)
-                  List(currentResourceEvent, previousResourceEventOpt1.get)
-                else
-                  List(currentResourceEvent),
-                fullChargeslots,
-                dslResource,
-                currentResourceEvent.isSynthetic
-              )
-              clog.debug("New %s", newWalletEntry)
-
-              walletEntryRecorder.apply(newWalletEntry)
-            } else {
-              clog.debug("newCreditsDiff = %s, newCredits = %s", newCreditsDiff, newCredits)
-            }
+            val newWalletEntry = NewWalletEntry(
+              userStateWorker.userID,
+              newCreditsDiff,
+              oldCredits,
+              newCredits,
+              TimeHelpers.nowMillis(),
+              referenceTimeslot,
+              billingMonthInfo.year,
+              billingMonthInfo.month,
+              if(havePreviousResourceEvent)
+                List(currentResourceEvent, previousResourceEventOpt1.get)
+              else
+                List(currentResourceEvent),
+              fullChargeslots,
+              dslResource,
+              currentResourceEvent.isSynthetic
+            )
+            clog.debug("%s = %s", shortClassNameOf(newWalletEntry), newWalletEntry)
+
+            walletEntryRecorder.apply(newWalletEntry)
 
             _workingUserState = _workingUserState.copy(
               totalCredits = newCredits,
index 47b87fc..41d399a 100644 (file)
@@ -73,8 +73,8 @@ case class UserStateChangeReason(
 //  def shouldStoreUserState: Boolean =
 //     booleanFromDetails(UserStateChangeReason.Names.shouldStoreUserState, false)
 
-  def shouldStoreCalculatedWalletEntries: Boolean =
-    booleanFromDetails(UserStateChangeReason.Names.shouldStoreCalculatedWalletEntries, false)
+//  def shouldStoreCalculatedWalletEntries: Boolean =
+//    booleanFromDetails(UserStateChangeReason.Names.shouldStoreCalculatedWalletEntries, false)
 
   def calculateCreditsForImplicitlyTerminated: Boolean =
     booleanFromDetails(UserStateChangeReason.Names.calculateCreditsForImplicitlyTerminated, false)
@@ -99,8 +99,8 @@ object UserStateChangeReason {
     final val imEvent = "imEvent"
     final val forWhenMillis = "forWhenMillis"
 
-    final val shouldStoreUserState = "shouldStoreUserState"
-    final val shouldStoreCalculatedWalletEntries = "shouldStoreCalculatedWalletEntries"
+//    final val shouldStoreUserState = "shouldStoreUserState"
+//    final val shouldStoreCalculatedWalletEntries = "shouldStoreCalculatedWalletEntries"
     final val calculateCreditsForImplicitlyTerminated = "calculateCreditsForImplicitlyTerminated"
   }
 }
@@ -190,7 +190,7 @@ object MonthlyBillingCalculation {
       Map(
         UserStateChangeReason.Names.name -> name,
 //        UserStateChangeReason.Names.shouldStoreUserState -> true,
-        UserStateChangeReason.Names.shouldStoreCalculatedWalletEntries -> true.toString,
+//        UserStateChangeReason.Names.shouldStoreCalculatedWalletEntries -> true.toString,
         UserStateChangeReason.Names.calculateCreditsForImplicitlyTerminated -> true.toString
       ),
       Some(billingMongthInfo),