Create an entity set. This will create or update any entities that already exist in the entityset and sign their IDs into the collection.
(collection, data, authz)
| 19 | |
| 20 | |
| 21 | def create_entityset(collection, data, authz): |
| 22 | """Create an entity set. This will create or update any entities |
| 23 | that already exist in the entityset and sign their IDs into the collection. |
| 24 | """ |
| 25 | old_to_new_id_map = {} |
| 26 | entity_ids = [] |
| 27 | for entity in data.pop("entities", []): |
| 28 | old_id = entity.get("id") |
| 29 | new_id = upsert_entity(entity, collection, sign=True, sync=True) |
| 30 | old_to_new_id_map[old_id] = new_id |
| 31 | entity_ids.append(new_id) |
| 32 | layout = data.get("layout", {}) |
| 33 | data["layout"] = replace_layout_ids(layout, old_to_new_id_map) |
| 34 | entityset = EntitySet.create(data, collection, authz) |
| 35 | for entity_id in entity_ids: |
| 36 | save_entityset_item(entityset, collection, entity_id) |
| 37 | publish( |
| 38 | Events.CREATE_ENTITYSET, |
| 39 | params={"collection": collection, "entityset": entityset}, |
| 40 | channels=[collection, authz.role], |
| 41 | actor_id=authz.id, |
| 42 | ) |
| 43 | return entityset |
| 44 | |
| 45 | |
| 46 | def save_entityset_item(entityset, collection, entity_id, **data): |
no test coverage detected