+ // If we already have a userID but it does not match the incoming userID, then this is an internal error
+ if(_havePartialState && (this._userID != imEvent.userID)) {
+ throw new AquariumException("Got userID = %s but already have userID = %s".format(imEvent.userID, this._userID))
+ }
+
+ // If we get an IMEvent without having a user state, then we query for the latest user state.
+ if(!_haveFullState) {
+ val userStateOpt = _configurator.userStateStore.findLatestUserStateByUserID(this._userID)
+ this._userState = userStateOpt match {
+ case Some(userState) ⇒
+ userState
+
+ case None ⇒
+ val initialAgreementName = _getAgreementNameForNewUser(imEvent)
+ val initialUserState = DefaultUserStateComputations.createInitialUserState(
+ this._userID,
+ imEvent.occurredMillis,
+ imEvent.isActive,
+ 0.0,
+ List(imEvent.role),
+ initialAgreementName)
+
+ DEBUG("Got initial state")
+ initialUserState
+ }
+ }
+
+ if(imEvent.isModifyUser && this._userState.isInitial) {
+ INFO("Got a '%s' but have not received '%s' yet", imEvent.eventType, IMEventModel.EventTypeNames.create)
+ return
+ }
+
+ if(imEvent.isCreateUser && !this._userState.isInitial) {
+ INFO("Got a '%s' but my state is not initial", imEvent.eventType)
+ return
+ }
+
+ this._userState = this._userState.modifyFromIMEvent(imEvent, now)
+