def append_to_objects(self, entity_id, project_id, objects: KeyIndexedCollection, key_id_map: KeyIdMap): tag_name_id_map = self.get_name_to_id_map(project_id) tags_to_add = [] tags_keys = [] for object in objects: obj_id = key_id_map.get_object_id(object.key()) if obj_id is None: raise RuntimeError( "Can not add tags to object: OBJECT_ID not found for key {}" .format(object.key())) tags_json, cur_tags_keys = self._tags_to_json( object.tags, tag_name_id_map=tag_name_id_map) for tag in tags_json: tag[ApiField.OBJECT_ID] = obj_id tags_to_add.append(tag) tags_keys.extend(cur_tags_keys) if len(tags_keys) != len(tags_to_add): raise RuntimeError("SDK error: len(tags_keys) != len(tags_to_add)") if len(tags_keys) == 0: return ids = self.append_to_objects_json(entity_id, tags_to_add) KeyIdMap.add_tags_to(key_id_map, tags_keys, ids)
def append_to_entity(self, entity_id, project_id, tags: KeyIndexedCollection, key_id_map: KeyIdMap = None): if len(tags) == 0: return [] tags_json, tags_keys = self._tags_to_json(tags, project_id=project_id) ids = self._append_json(entity_id, tags_json) KeyIdMap.add_tags_to(key_id_map, tags_keys, ids) return ids