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 view(entityset_id): """Return the entityset with id `entityset_id`. --- get: summary: Fetch an entityset parameters: - description: The entityset id. in: path name: entityset_id required: true schema: type: string example: 3a0d91ece2dce88ad3259594c7b642485235a048 responses: '200': content: application/json: schema: $ref: '#/components/schemas/EntitySet' description: OK tags: - EntitySet """ entityset = get_entityset(entityset_id, request.authz.READ) return EntitySetSerializer.jsonify(entityset)
def view(entityset_id): """Return the entityset with ID `entityset_id`. --- get: summary: Fetch an entityset parameters: - description: The entityset id. in: path name: entityset_id required: true schema: type: string example: 3a0d91ece2dce88ad3259594c7b642485235a048 responses: '200': content: application/json: schema: $ref: '#/components/schemas/EntitySet' description: OK tags: - EntitySet """ entityset = get_entityset(entityset_id, request.authz.READ) if entityset.type == EntitySet.PROFILE: return redirect(url_for("profile_api.view", profile_id=entityset_id)) data = entityset.to_dict() data["shallow"] = False return EntitySetSerializer.jsonify(data)
def index(): """Returns a list of entitysets for the role --- get: summary: List entitysets parameters: - description: The collection id. in: query name: 'filter:collection_id' required: true schema: minimum: 1 type: integer - description: The type of the entity set in: query name: 'filter:type' required: false schema: type: string - description: Quert string for searches in: query name: 'prefix' required: false schema: type: string responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/EntitySet' description: OK tags: - EntitySet """ parser = QueryParser(request.args, request.authz) types = parser.filters.get("type") q = EntitySet.by_authz(request.authz, types=types, prefix=parser.prefix) q = q.order_by(EntitySet.updated_at.desc()) collection_ids = ensure_list(parser.filters.get("collection_id")) if len(collection_ids): q = q.filter(EntitySet.collection_id.in_(collection_ids)) result = DatabaseQueryResult(request, q, parser=parser) return EntitySetSerializer.jsonify_result(result)
def entitysets(entity_id): """Returns a list of entitysets which the entity has references in --- get: summary: Shows EntitySets which reference the given entity description: >- Search for all entitysets which reference the given entity. The entity sets can be filtered based on it's collection id, label, type or the judgement of the entity within the set. parameters: - in: path name: entity_id required: true schema: type: string - in: query name: 'filter:type' description: Restrict to a EntitySets of a particular type required: false schema: items: type: string type: array - in: query name: 'filter:label' description: Restrict to a EntitySets with a particular label required: false schema: items: type: string type: array - in: query name: 'filter:judgement' description: Restrict to a specific profile judgement required: false schema: items: type: string type: array - in: query name: 'filter:collection_id' description: Restrict to entity sets within particular collections schema: items: type: string type: array responses: '200': content: application/json: schema: type: array items: $ref: '#/components/schemas/EntitySet' description: OK tags: - Entity - Profile """ entity = get_index_entity(entity_id, request.authz.READ) parser = QueryParser(request.args, request.authz) collection_ids = [ cid for cid in parser.filters.get("collection_id", []) if request.authz.can(cid, request.authz.READ) ] judgements = parser.filters.get("judgement") labels = parser.filters.get("label") types = parser.filters.get("type") if judgements is not None: judgements = list(map(Judgement, judgements)) if not collection_ids: collection_ids = request.authz.collections(request.authz.READ) entitysets = EntitySet.by_entity_id( entity["id"], collection_ids=collection_ids, judgements=judgements, types=types, labels=labels, ) result = DatabaseQueryResult(request, entitysets, parser=parser) return EntitySetSerializer.jsonify_result(result)