def get_entities_by_id(program, project, entity_id_string): """ Retrieve existing GDC entities by ID. The return type of a :http:method:`get` on this endpoint is a JSON array containing JSON object elements, each corresponding to a provided ID. Return results are unordered. If any ID is not found in the database, a status code of 404 is returned with the missing IDs. Args: program (str): |program_id| project (str): |project_id| entity_id_string (str): A comma-separated list of ids specifying the entities to retrieve. :reqheader Content-Type: |reqheader_Content-Type| :reqheader Accept: |reqheader_Accept| :reqheader X-Auth-Token: |reqheader_X-Auth-Token| :resheader Content-Type: |resheader_Content-Type| :statuscode 200: Success. :statuscode 404: Entity not found. :statuscode 403: Unauthorized request. """ entity_ids = entity_id_string.split(',') with flask.current_app.db.session_scope(): nodes = flask.current_app.db.nodes().ids(entity_ids).all() entities = {n.node_id: n for n in nodes} missing_entities = set(entity_ids) - set(entities.keys()) if missing_entities: raise UserError('Not found: {}'.format(', '.join(missing_entities), code=404)) return flask.jsonify( {'entities': utils.create_entity_list(entities.values())})
def get_entities_by_id(program, project, entity_id_string): """ Retrieve existing GDC entities by ID. The return type of a :http:method:`get` on this endpoint is a JSON array containing JSON object elements, each corresponding to a provided ID. Return results are unordered. If any ID is not found in the database, a status code of 404 is returned with the missing IDs. Summary: Get entities by ID Tags: entity Args: program (str): |program_id| project (str): |project_id| entity_id_string (str): A comma-separated list of ids specifying the entities to retrieve. Responses: 200 (schema_entity_list): Success. 400: User error. 404: Entity not found. 403: Unauthorized request. :reqheader Content-Type: |reqheader_Content-Type| :reqheader Accept: |reqheader_Accept| :reqheader X-Auth-Token: |reqheader_X-Auth-Token| :resheader Content-Type: |resheader_Content-Type| """ entity_ids = entity_id_string.split(",") with flask.current_app.db.session_scope(): dictionary_nodes = flask.current_app.db.nodes().ids(entity_ids).props(project_id = program + "-" + project).all() project_nodes = flask.current_app.db.nodes(models.Project).ids(entity_ids).all() program_nodes = flask.current_app.db.nodes(models.Program).ids(entity_ids).all() nodes = [] nodes.extend(dictionary_nodes) nodes.extend(project_nodes) nodes.extend(program_nodes) auth.check_resource_access(program, project, nodes) entities = {n.node_id: n for n in nodes} missing_entities = set(entity_ids) - set(entities.keys()) if missing_entities: raise UserError( "Not found: {}".format(", ".join(missing_entities), code=404) ) return flask.jsonify({"entities": utils.create_entity_list(entities.values())})