Revision 4b8ff3e0 src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala

b/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala
136 136
      _imcounter += 1
137 137
      DEBUG("Replaying [%s/%s] %s", shortClassNameOf(imEvent), _imcounter, imEvent)
138 138

  
139
      if(_imcounter == 1 && !MessageHelpers.isIMEventCreate(imEvent)) {
139
      if(_imcounter == 1 && !MessageHelpers.isUserCreationIMEvent(imEvent)) {
140 140
        // The very first event must be a CREATE event. Otherwise we abort initialization.
141 141
        // This will normally happen during devops :)
142 142
        INFO("Ignoring first %s since it is not CREATE", shortClassNameOf(imEvent))
......
176 176
    )
177 177
  }
178 178

  
179
  private[this] def loadLastKnownUserStateAndUpdateAgreements(historyMsg: UserAgreementHistoryMsg) {
180
    val userID = historyMsg.getUserID
181
    val latestUserStateOpt = aquarium.userStateStore.findLatestUserState(userID)
182
    latestUserStateOpt match {
179
  private[this] def loadLastKnownUserStateAndUpdateAgreements() {
180
    val userID = this._userStateModel.userID
181
    aquarium.userStateStore.findLatestUserState(userID) match {
183 182
      case None ⇒
184 183
        // First user state ever
185 184
        saveFirstUserState(userID)
186 185

  
187 186
      case Some(latestUserState) ⇒
188 187
        this._userStateModel.updateUserStateMsg(latestUserState)
189
        this._userStateModel.updateUserAgreementHistoryMsg(historyMsg)
190 188
    }
191 189
  }
192 190

  
191
  private[this] def processResourceEventsAfterLastKnownUserState() {
192
    // Update the user state snapshot with fresh (ie not previously processed) events.
193

  
194
  }
195

  
196
  private[this] def makeUserStateMsgUpToDate() {
197
    loadLastKnownUserStateAndUpdateAgreements()
198
    processResourceEventsAfterLastKnownUserState()
199
  }
200

  
193 201
  private[this] def checkInitial(nextThing: () ⇒ Any = () ⇒ {}): Boolean = {
194 202
    if(!isInitial) {
195 203
      return false
......
198 206
    val (userCreated, imEventsCount) = createUserAgreementHistoryFromIMEvents(userID)
199 207

  
200 208
    if(userCreated) {
201
      loadLastKnownUserStateAndUpdateAgreements(this._userStateModel.userAgreementHistoryMsg)
209
      makeUserStateMsgUpToDate()
202 210
    }
203 211

  
204 212
    nextThing()
......
236 244
    this._userStateModel.insertUserAgreementMsgFromIMEvent(imEvent)
237 245
    this._imMsgCount += 1
238 246

  
239
    if(haveUserCreationEvent) {
240
      loadLastKnownUserStateAndUpdateAgreements(this._userStateModel.userAgreementHistoryMsg)
247
    if(MessageHelpers.isUserCreationIMEvent(imEvent)) {
248
      makeUserStateMsgUpToDate()
241 249
    }
242 250

  
243 251
    DEBUG("Agreements: %s", this._userStateModel.userAgreementHistoryMsg)

Also available in: Unified diff