From bfc2265eb2efdf8201edb4dae25c1f75fff2ec70 Mon Sep 17 00:00:00 2001 From: LV-426 Date: Mon, 30 Mar 2015 19:07:54 +0300 Subject: rz_api: refactoring REST api calls to rz_api_rest --- src/server/rz_api_rest.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/server/rz_api_rest.py') diff --git a/src/server/rz_api_rest.py b/src/server/rz_api_rest.py index e1788586..658327e5 100644 --- a/src/server/rz_api_rest.py +++ b/src/server/rz_api_rest.py @@ -58,15 +58,84 @@ class Req_Context(): ret['rzdoc_id'] = rzdoc_id return ret +def __load_node_set_by_id_attr_common(id_set): + """ + @param f_k: optional attribute filter key + @param f_vset: possible key values to match against + """ + op = DBO_match_node_set_by_id_attribute(id_set=id_set) + try: + n_set = db_ctl.exec_op(op) + return common_resp_handle__success(data=n_set) + except Exception as e: + log.exception(e) + return common_resp_handle__client_error(error='unable to load node with ids: {0}'.format(id_set)) + +def diff_commit__set(): + """ + commit a diff set + """ def sanitize_input(req): + diff_set_dict = req.get_json()['diff_set'] + topo_diff_dict = diff_set_dict['__diff_set_topo'][0] + topo_diff = Topo_Diff.from_json_dict(topo_diff_dict) + + sanitize_input__topo_diff(topo_diff) + return topo_diff; + + topo_diff = sanitize_input(request) + + op = DBO_diff_commit__topo(topo_diff) + + assert False + +def load_link_set_by_link_ptr_set(): + def deserialize_param_set(param_json): + l_ptr_set_raw = param_json['link_ptr_set'] + __sanitize_input(l_ptr_set_raw) + l_ptr_set = [] + for lptr_dict in l_ptr_set_raw: + src_id = lptr_dict.get('__src_id') + dst_id = lptr_dict.get('__dst_id') + l_ptr_set += [Link.Link_Ptr(src_id=src_id, dst_id=dst_id) ] + return l_ptr_set + l_ptr_set = deserialize_param_set(request.get_json()) + + op = DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) + + assert False + +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 of nodes whose id attribute matches 'id' or + an empty list if the requested node is not found + @raise exception: on error + """ + 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 match_node_set_by_attr_filter_map(attr_filter_map): + """ + @param attr_filter_map + + @return: a set of node DB id's + """ + op = DBO_match_node_id_set(attr_filter_map) + assert False @common_rest_req_exception_handler def diff_commit__topo(): -- cgit v1.3.1