def Transform(self, client, notification, callback): from activity import Activity from asset_id import AssetIdUniquifier def _DoUpdate(): self._LogUpdate(notification) if Version._mutate_items: notification.Update(client, partial(callback, notification)) else: callback(notification) def _OnQueryNewActivity(activity): if activity is None: logging.warning( 'notification does not have a valid activity_id: %s', notification) notification.update_seq = 0 self._LogUpdate(notification) _DoUpdate() else: _OnQueryActivity(activity) def _OnQueryActivity(activity): if activity is None: # Also migrate any notifications which are using the older activity id. timestamp, device_id, uniquifier = Activity.DeconstructActivityId( notification.activity_id) new_uniquifier = AssetIdUniquifier(uniquifier.client_id, notification.viewpoint_id) new_activity_id = Activity.ConstructActivityId( timestamp, device_id, new_uniquifier) Activity.Query(client, notification.viewpoint_id, new_activity_id, None, _OnQueryNewActivity, must_exist=False) return notification.activity_id = activity.activity_id notification.update_seq = activity.update_seq _DoUpdate() if notification.activity_id is None: callback(notification) else: Activity.Query(client, notification.viewpoint_id, notification.activity_id, None, _OnQueryActivity, must_exist=False)
def _OnQueryActivity(activity): if activity is None: # Also migrate any notifications which are using the older activity id. timestamp, device_id, uniquifier = Activity.DeconstructActivityId( notification.activity_id) new_uniquifier = AssetIdUniquifier(uniquifier.client_id, notification.viewpoint_id) new_activity_id = Activity.ConstructActivityId( timestamp, device_id, new_uniquifier) Activity.Query(client, notification.viewpoint_id, new_activity_id, None, _OnQueryNewActivity, must_exist=False) return notification.activity_id = activity.activity_id notification.update_seq = activity.update_seq _DoUpdate()