+ checkInitial()
+
+ haveUserState match {
+ case true ⇒
+ val realtimeMillis = TimeHelpers.nowMillis()
+ chargingService.calculateRealtimeUserState(
+ this._userStateModel,
+ aquarium.currentResourceMapping,
+ realtimeMillis
+ )
+
+ sender ! GetUserStateResponse(Right(this._userStateModel.userStateMsg))
+
+ case false ⇒
+ sender ! GetUserStateResponse(Left("No state for user %s [AQU-STA-0006]".format(event.userID)), 404)
+ }
+ }
+
+ def onGetUserWalletRequest(event: GetUserWalletRequest): Unit = {
+ checkInitial()
+
+ haveUserState match {
+ case true ⇒
+ DEBUG("haveWorkingUserState: %s", event)
+ val realtimeMillis = TimeHelpers.nowMillis()
+ chargingService.calculateRealtimeUserState(
+ this._userStateModel,
+ aquarium.currentResourceMapping,
+ realtimeMillis
+ )
+
+ sender ! GetUserWalletResponse(
+ Right(
+ GetUserWalletResponseData(
+ this.userID,
+ this._userStateModel.totalCredits,
+ MessageFactory.newWalletEntriesMsg(this._userStateModel.userStateMsg.getWalletEntries)
+ )))
+
+ case false ⇒
+ DEBUG("!haveWorkingUserState: %s", event)
+ haveAgreements match {
+ case true ⇒
+ DEBUG("haveAgreements: %s", event)
+ sender ! GetUserWalletResponse(
+ Right(
+ GetUserWalletResponseData(
+ this.userID,
+ Real.toMsgField(aquarium.initialUserBalance(this.unsafeUserCreationIMEventMsg.getRole, this.unsafeUserCreationIMEventMsg.getOccurredMillis)),
+ MessageFactory.newWalletEntriesMsg()
+ )))
+
+ case false ⇒
+ DEBUG("!haveUserCreationIMEvent: %s", event)
+ sender ! GetUserWalletResponse(Left("No wallet for user %s [AQU-WAL-00 8]".format(event.userID)), 404)
+ }
+ }
+ }
+
+ /**
+ * Initializes the actor's internal state.
+ *
+ * @param userID
+ */
+ def onSetUserActorUserID(userID: String) {
+ // Create the full agreement history from the original sources (IMEvents)
+ this._userStateModel = ModelFactory.newInitialUserStateModel(
+ userID,
+ Real(0),
+ TimeHelpers.nowMillis()
+ )
+
+ require(this._userStateModel.isInitial, "this._userStateModel.isInitial")