def create(): """ --- post: summary: Create an entity in a collection description: >- Create an entity in a collection with a given schema and a set of given properties in the database. This is not the API you want to be using to load bulk data, but only for interactive entity manipulation in the UI. Always use the `bulk` API or for loading source datasets, no exceptions. requestBody: content: application/json: schema: $ref: '#/components/schemas/EntityCreate' responses: '200': description: Resturns the created entity content: application/json: schema: $ref: '#/components/schemas/Entity' tags: - Entity """ data = parse_request('EntityCreate') collection = get_nested_collection(data, request.authz.WRITE) data.pop('id', None) validate = get_flag('validate', default=False) entity_id = upsert_entity(data, collection, sync=True, validate=validate) tag_request(entity_id=entity_id, collection_id=str(collection.id)) entity = get_index_entity(entity_id, request.authz.READ) return EntitySerializer.jsonify(entity)
def create(): """Create an entityset. --- post: summary: Create an entityset requestBody: content: application/json: schema: $ref: '#/components/schemas/EntitySetCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/EntitySet' description: OK tags: - EntitySet """ data = parse_request("EntitySetCreate") collection = get_nested_collection(data, request.authz.WRITE) entityset = create_entityset(collection, data, request.authz) db.session.commit() return EntitySetSerializer.jsonify(entityset)
def create(): """Create a diagram. --- post: summary: Create a diagram requestBody: content: application/json: schema: $ref: '#/components/schemas/DiagramCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Diagram' description: OK tags: - Diagram """ data = parse_request('DiagramCreate') collection = get_nested_collection(data, request.authz.WRITE) old_to_new_id_map = {} entity_ids = [] for entity in data.pop('entities', []): old_id = entity.get('id') new_id = upsert_entity(entity, collection, sync=True) old_to_new_id_map[old_id] = new_id entity_ids.append(new_id) data['entities'] = entity_ids layout = data.get('layout', {}) data['layout'] = replace_layout_ids(layout, old_to_new_id_map) diagram = Diagram.create(data, collection, request.authz.id) db.session.commit() return DiagramSerializer.jsonify(diagram)
def update(entity_id): """ --- post: summary: Update an entity description: > Update the entity with id `entity_id`. This only applies to entities which are backed by a database row, i.e. not any entities resulting from a mapping or bulk load. parameters: - in: path name: entity_id required: true schema: type: string format: entity_id - in: query name: sign description: Sign entity IDs referenced in nested properties. required: false schema: type: boolean requestBody: content: application/json: schema: $ref: '#/components/schemas/EntityUpdate' responses: '200': description: OK content: application/json: schema: $ref: '#/components/schemas/Entity' tags: - Entity """ data = parse_request("EntityUpdate") try: entity = get_index_entity(entity_id, request.authz.WRITE) require(check_write_entity(entity, request.authz)) collection = get_db_collection(entity.get("collection_id"), request.authz.WRITE) except NotFound: collection = get_nested_collection(data, request.authz.WRITE) tag_request(collection_id=collection.id) data["id"] = entity_id if get_flag("validate", default=False): validate_entity(data) entity_id = upsert_entity( data, collection, authz=request.authz, sync=get_flag("sync", default=True), sign=get_flag("sign", default=False), job_id=get_session_id(), ) db.session.commit() return view(entity_id)
def create(): """ --- post: summary: Create an entity in a collection description: >- Create an entity in a collection with a given schema and a set of given properties in the database. This is not the API you want to be using to load bulk data, but only for interactive entity manipulation in the UI. Always use the `bulk` API or for loading source datasets, no exceptions. parameters: - in: query name: sign description: Sign entity IDs referenced in nested properties. required: false schema: type: boolean requestBody: content: application/json: schema: $ref: '#/components/schemas/EntityCreate' responses: '200': description: Resturns the created entity content: application/json: schema: $ref: '#/components/schemas/Entity' tags: - Entity """ data = parse_request("EntityCreate") collection = get_nested_collection(data, request.authz.WRITE) data.pop("id", None) if get_flag("validate", default=False): validate_entity(data) entity_id = upsert_entity( data, collection, authz=request.authz, sync=True, sign=get_flag("sign", default=False), job_id=get_session_id(), ) db.session.commit() tag_request(entity_id=entity_id, collection_id=collection.id) entity = get_index_entity(entity_id, request.authz.READ) return EntitySerializer.jsonify(entity)
def update(entity_id): """ --- post: summary: Update an entity description: > Update the entity with id `entity_id`. This only applies to entities which are backed by a database row, i.e. not any entities resulting from a mapping or bulk load. parameters: - in: path name: entity_id required: true schema: type: string format: entity_id requestBody: content: application/json: schema: $ref: '#/components/schemas/EntityUpdate' responses: '200': description: OK content: application/json: schema: $ref: '#/components/schemas/Entity' tags: - Entity """ data = parse_request('EntityUpdate') try: entity = get_index_entity(entity_id, request.authz.WRITE) collection = get_db_collection(entity.get('collection_id'), request.authz.WRITE) except NotFound: collection = get_nested_collection(data, request.authz.WRITE) tag_request(collection_id=collection.id) data['id'] = entity_id sync = get_flag('sync', default=True) validate = get_flag('validate', default=False) entity_id = upsert_entity(data, collection, validate=validate, sync=sync) db.session.commit() entity = get_index_entity(entity_id, request.authz.READ) return EntitySerializer.jsonify(entity)
def create(): """Create a diagram. --- post: summary: Create a diagram requestBody: content: application/json: schema: $ref: '#/components/schemas/DiagramCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Diagram' description: OK tags: - Diagram """ data = parse_request('DiagramCreate') collection = get_nested_collection(data, request.authz.WRITE) diagram = create_diagram(collection, data, request.authz) return DiagramSerializer.jsonify(diagram)