+ private[this] def isInitial = this._userStateModel.isInitial
+
+ /**
+ * Creates the agreement history from all the stored IMEvents.
+ *
+ * @return (`true` iff there was a user CREATE event, the number of events processed)
+ */
+ private[this] def createUserAgreementHistoryFromIMEvents(userID: String): (Boolean, Int) = {
+ DEBUG("createUserAgreementHistoryFromStoredIMEvents()")
+ assert(haveUserState, "haveUserState")
+
+
+ var _imcounter = 0
+
+ val hadCreateEvent = aquarium.imEventStore.foreachIMEventInOccurrenceOrder(userID) { imEvent ⇒
+ _imcounter += 1
+ DEBUG("Replaying [%s/%s] %s", shortClassNameOf(imEvent), _imcounter, imEvent)
+
+ if(_imcounter == 1 && !MessageHelpers.isUserCreationIMEvent(imEvent)) {
+ // The very first event must be a CREATE event. Otherwise we abort initialization.
+ // This will normally happen during devops :)
+ INFO("Ignoring first %s since it is not CREATE", shortClassNameOf(imEvent))
+ false
+ }
+ else {
+ val effectiveFromMillis = imEvent.getOccurredMillis
+ val role = imEvent.getRole
+ // calling unsafe just for the side-effect
+ assert(
+ aquarium.unsafeFullPriceTableForRoleAt(role, effectiveFromMillis) ne null,
+ "aquarium.unsafeFullPriceTableForRoleAt(%s, %s) ne null".format(role, effectiveFromMillis)
+ )
+
+ this._userStateModel.insertUserAgreementMsgFromIMEvent(imEvent)
+ true
+ }