From 69d70685cfdea0ea6b6083d36f6fefd0be0741fe Mon Sep 17 00:00:00 2001 From: LV-426 Date: Mon, 27 Oct 2014 12:44:49 +0200 Subject: misc --- src-py/db_controller.py | 18 +++++++++--------- src-py/rhizi_api.py | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'src-py') diff --git a/src-py/db_controller.py b/src-py/db_controller.py index aa1e8450..f9656212 100644 --- a/src-py/db_controller.py +++ b/src-py/db_controller.py @@ -1,20 +1,19 @@ #!/usr/bin/python -import os import json -import re import logging +import os +import re import traceback +import urllib2 +from db_driver import DB_Driver_REST, DB_Driver_Base from model.graph import Attr_Diff from model.graph import Topo_Diff - -import urllib2 - -import neo4j_util as db_util -from neo4j_util import cfmt from neo4j_util import DB_result_set -from neo4j_util import Neo4JException +from neo4j_util import cfmt +import neo4j_util as db_util +from model.model import Link log = logging.getLogger('rhizi') @@ -183,7 +182,7 @@ class DBO_attr_diff_commit(DB_op): ret = {} for _, _, r_set in self: for row in r_set: - n_id, n = [v for v in row] # we expect a [n_id, n] array + n_id, n = [v for v in row] # we expect a [n_id, n] array ret[n_id] = n return ret @@ -234,6 +233,7 @@ class DBO_load_node_set_by_DB_id(DB_op): """ load a set of nodes whose DB id is in id_set + @param id_set: DB node id set @return: loaded node set or an empty set if no match was found """ super(DBO_load_node_set_by_DB_id, self).__init__() diff --git a/src-py/rhizi_api.py b/src-py/rhizi_api.py index c22df635..7a6a44e9 100644 --- a/src-py/rhizi_api.py +++ b/src-py/rhizi_api.py @@ -48,26 +48,42 @@ def __common_resp_handle(data=None, error=None): ret_data = __response_wrap(data, error) resp = jsonify(ret_data) + resp.headers['Access-Control-Allow-Origin'] = '*' + # more response processing return resp +def __common_exec(op, on_success=__common_resp_handle): + try: + op_ret = db_ctl.exec_op(op) + return on_success(op_ret) + except Exception as e: + return __common_resp_handle('exception raised: add_node_set') -@webapp.route("/load/node-set", methods=['POST']) +@webapp.route("/load/node-set-by-id", methods=['POST']) def load_node_set_by_id_attr(): """ + load node-set by ID attribute + @param id_set: list of node ids to match id attribute against - @return: a list containing a single node whose id attribute matches 'id' or + @return: a list of nodes whose id attribute matches 'id' or an empty list if the requested node is not found @raise exception: on error """ - id_set = request.get_json()['id_set'] + req_json = request.get_json() + id_set = req_json['id_set'] + __sanitize_input(id_set) return __load_node_set_by_id_attr_common(id_set) def __load_node_set_by_id_attr_common(id_set): - op = dbc.DBO_load_node_set_by_id_attribute(id_set) + """ + @param f_k: optional attribute filter key + @param f_vset: possible key values to match against + """ + op = dbc.DBO_match_node_set_by_id_attribute(id_set=id_set) try: n_set = db_ctl.exec_op(op) return __common_resp_handle(data=n_set) -- cgit v1.3.1