def pre_process_skeleton(): report_flavors = [] calls_in_order = [] javadoc_map = {} for acall in api_skeleton.CALLS: path = str(acall["path"]) assert path.startswith("/") #path = path[1:] pathparts = path[1:].split('/') pplen = len(pathparts) if (pplen == 6 and pathparts[pplen -1] == '' and pathparts[pplen -4] == "reports" and pathparts[pplen -3] == "minimal" and pathparts[pplen -2][0] != '{'): try: report_flavors.index(pathparts[pplen -2]) except ValueError: report_flavors.append(pathparts[pplen -2]) xml_style_url = add_to_apixml.skeleton_style_to_api_style(path) calls_in_order.append((acall.get("method").lower(), xml_style_url)) javadoc_map[(acall.get("method").lower(), xml_style_url)] = acall report_flavors_sn = [] for rfws in report_flavors: #print "rfws: " + rfws if rfws == "allergies": report_flavors_sn.append("allergy") elif rfws == "simple-clinical-notes": report_flavors_sn.append("simple") elif rfws[len(rfws) -1] == 's': report_flavors_sn.append(rfws[0:len(rfws) -1]) else: report_flavors_sn.append(rfws) #print "missing from skeleton: " + str((set(report_fields_sn.keys())) - set(report_flavors_sn)) #print "missing from reports/*.py: " + str((set(report_flavors_sn) - set(report_fields_sn.keys()))) return report_flavors_sn, calls_in_order, javadoc_map
def pre_process_skeleton(): report_flavors = [] calls_in_order = [] javadoc_map = {} for acall in api_skeleton.CALLS: path = str(acall["path"]) assert path.startswith("/") #path = path[1:] pathparts = path[1:].split('/') pplen = len(pathparts) if (pplen == 6 and pathparts[pplen - 1] == '' and pathparts[pplen - 4] == "reports" and pathparts[pplen - 3] == "minimal" and pathparts[pplen - 2][0] != '{'): try: report_flavors.index(pathparts[pplen - 2]) except ValueError: report_flavors.append(pathparts[pplen - 2]) xml_style_url = add_to_apixml.skeleton_style_to_api_style(path) calls_in_order.append((acall.get("method").lower(), xml_style_url)) javadoc_map[(acall.get("method").lower(), xml_style_url)] = acall report_flavors_sn = [] for rfws in report_flavors: #print "rfws: " + rfws if rfws == "allergies": report_flavors_sn.append("allergy") elif rfws == "simple-clinical-notes": report_flavors_sn.append("simple") elif rfws[len(rfws) - 1] == 's': report_flavors_sn.append(rfws[0:len(rfws) - 1]) else: report_flavors_sn.append(rfws) #print "missing from skeleton: " + str((set(report_fields_sn.keys())) - set(report_flavors_sn)) #print "missing from reports/*.py: " + str((set(report_flavors_sn) - set(report_fields_sn.keys()))) return report_flavors_sn, calls_in_order, javadoc_map
def process_calls(rest, pynames, report_flavors, resturls, rest_to_apinode, javadoc_map): reports_minimal_records = False reports_minimal_carenet = False access_doc_map = {} call_count = 0 method_count = 0 dfekvm = {} retexs = {} retdscs = {} okcount = 0 dividN = 0 #for acall in api_skeleton.CALLS: for resturl in resturls: apinode = rest_to_apinode.get(resturl) if not apinode: print("missing from api.xml: " + repr(resturl)) continue if len(apinode) < 1 or len(apinode) > 2: print(repr(resturl)) raise Exception apinode = apinode[0] call_count += 1 httpmeth = resturl[0].upper() assert httpmeth in ["GET", "PUT", "POST", "DELETE"] forjavadoc = javadoc_map.get(resturl) if not forjavadoc: print(resturl) raise Exception retex = forjavadoc["return_ex"] assert isinstance(retex, str) #retex = retex.strip()[:50] if retexs.has_key(retex): retexs[retex] = retexs[retex] +1 else: retexs[retex] = 1 retdsc = forjavadoc["return_desc"] assert isinstance(retdsc, str) # if retdsc.find("http:statuscode:`200` with a list of ") != -1: # print("retdsc found: " + retdsc) if retex == "<ok/>": okcount += 1 else: if retdsc.startswith(":http:statuscode:`200` with a list of ") or retdsc.startswith(":http:statuscode:`200`, with a list of "): retdsc = ":http:statuscode:`200` with a list of " if retdscs.has_key(retdsc): retdscs[retdsc] = retdscs[retdsc] +1 else: retdscs[retdsc] = 1 deprecated = forjavadoc["deprecated"] access_doc = forjavadoc["access_doc"] #path0 = acall["path"] #str(acall["path"]) #legged, response_form = api_skel_auxiliary.CALLS_AUX[(httpmeth,path0)] #legged = decide_oauth_legged(access_doc) # not used, just count occurrences in case the statistic is ever needed #adcount = access_doc_map.get(access_doc) #if adcount: # access_doc_map[access_doc] = adcount +1 #else: # access_doc_map[access_doc] = 1 #response_form = decide_response_form(retex, retdsc, httpmeth, path) #assert path0.startswith("/") #path = path0[1:] pathparts = forjavadoc.get("path")[1:].split('/') #pathparts = resturl[1][1:].split('/') # xml style print(repr(resturl) + " -- " + repr(pathparts)) #Unfortunately, this is actually the way the call is written into Indivo #Server. In future releases, we'll deprecate the call and replace it with the #correct one, but for now the documentation is actually accurate. -Dan #> "path":"/carenets/{CARENET_ID}/reports/minimal/vitals/{CATEGORY}" #> "path": "/records/{RECORD_ID}/reports/minimal/vitals/{CATEGORY}/" (reports_minimal_records, reports_minimal_carenet, redundant_report_minimal, first_report_minimal, audit_query) = combine_reports_minimal( reports_minimal_records, reports_minimal_carenet, pathparts) #api or skel # if redundant_report_minimal and not first of its kind if redundant_report_minimal: continue # first of its kind, process it but not next time elif first_report_minimal: #print("first_report_minimal: " + repr(pathparts)) pathparts[len(pathparts) -2] = "{REPORT_FLAVOR}" ############ #print("first_report_minimal: " + repr(pathparts)) method_name, params = make_method_name(pathparts, httpmeth) #print("after mmn: " + repr(params)) response_form = "" for child in apinode.childNodes: if child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "response": response_form = child.getAttribute("response_format") break oauth_legged = apinode.getElementsByTagName("oauth_legged") if len(oauth_legged) != 1: print(apinode.toxml()) raise Exception oauth_legged = oauth_legged[0] legged = [] if oauth_legged.getAttribute("two_legged"): legged.append(2) if oauth_legged.getAttribute("three_legged"): legged.append(3) skel_url_params0 = forjavadoc.get("url_params") skel_url_params_api = {} for skurpa in skel_url_params0: skel_url_params_api[add_to_apixml.skeleton_style_to_api_style(skurpa)] = skel_url_params0[skurpa] qopts_o = [] qopts_r = [] qopts = apinode.getElementsByTagName("query_opts") qopts_field = False if len(qopts): assert len(qopts) == 1 qopts = qopts[0].getElementsByTagName("qopt") for qopt in qopts: if qopt.getAttribute("field") == "field": qopts_field = True elif qopt.getAttribute("required") == "required": qopts_r.append(qopt.getAttribute("name")) else: qopts_o.append(qopt.getAttribute("name")) write_both(rest, pynames, javadoc( first_report_minimal, audit_query, qopts_o, params, # from pathparts, may be modified with REPORT_FLAVOR skel_url_params0, # skeleton style response_form, legged, apinode, #params, #url_params, forjavadoc, dividN) ) dividN += 1 # query_opts = acall["query_opts"] # qopts_r, qopts_o, qopts_field = categorize_query_options(query_opts, httpmeth) write_both(rest, pynames, " public Object ") rest.write(method_name) apicall = apinode.getElementsByTagName("call") assert len(apicall) == 1 apicall = apicall[0] pynames.write(apicall.getAttribute("name")) write_both(rest, pynames, "(\n ") #) url_params = forjavadoc["url_params"] params_from_url = get_params_from_url(forjavadoc) # skeleton style param names mthprms = method_params(qopts_r, qopts_o, params_from_url, skel_url_params0, qopts_field, legged, first_report_minimal, audit_query) #rest.write(mthprms) put_post_data = apinode.getElementsByTagName("put_post_data") assert len(put_post_data) <= 1 if len(put_post_data) == 1: put_post_data = put_post_data[0] put_post_data_form = put_post_data.getAttribute("format") else: put_post_data = None put_post_data_form = None if put_post_data: if mthprms: mthprms += ", " if put_post_data_form == "url_encoded": mthprms += "String body" else: mthprms += "Object body" if not put_post_data_form: # not known, caller must specify mthprms += ", String requestContentType" if not response_form: if mthprms: mthprms += ", " mthprms += "Object responseContentType" if mthprms: mthprms += ", " mthprms += "Map<String, Object> options" write_both(rest, pynames, mthprms) #============== write_both(rest, pynames, ') throws IndivoClientException {\n') if qopts_o: options_str1, options_str2 = process_query_opts(qopts_o, qopts_field, first_report_minimal, audit_query) write_both(rest, pynames, options_str1) write_both(rest, pynames, options_str2) if put_post_data_form == "url_encoded": post_data_keys = put_post_data.getElementsByTagName("key") if post_data_keys: allowedpdks = [] for pdk in post_data_keys: allowedpdks.append('"' + pdk.getAttribute("name") + '"') write_both(rest, pynames, (" checkQueryOptions(body, Arrays.asList(" + str(','.join(allowedpdks)) + "), null, null, \"url encoded param in body\");\n") ) write_both(rest, pynames, " Object fromRequest = clientRequest(\n ") write_both(rest, pynames, "\"" + httpmeth + "\", ") madeurl = make_url(pathparts) write_both(rest, pynames, madeurl) reqquer = request_query(qopts_r, qopts_o) write_both(rest, pynames, ", " + reqquer) if 3 in legged: write_both(rest, pynames, ", accessToken, accessTokenSecret") else: write_both(rest, pynames, ", null, null") if put_post_data: write_both(rest, pynames, ", body") if put_post_data_form: if put_post_data_form == "url_encoded": write_both(rest, pynames, ", \"application/x-www-form-urlencoded\"") elif put_post_data_form == "application/xml": write_both(rest, pynames, ", \"application/xml\"") elif put_post_data_form == "text/plain": write_both(rest, pynames, ", \"text/plain\"") else: raise Exception else: write_both(rest, pynames, ", requestContentType") # "URL_ENCODED", "PLAIN_TEXT" if response_form == "": write_both(rest, pynames, ", responseContentType") elif response_form == "XML": write_both(rest, pynames, ", \"application/xml\"") elif response_form == "JSON": write_both(rest, pynames, ", \"application/json\"") elif response_form == "URL_ENCODED": write_both(rest, pynames, ", \"application/x-www-form-urlencoded\"") elif response_form == "PLAIN_TEXT": write_both(rest, pynames, ", \"text/plain\"") else: print("response form: " + response_form) raise Exception write_both(rest, pynames, ", options);\n return fromRequest;\n") write_both(rest, pynames, " }\n\n") method_count += 1 return call_count, method_count
def process_calls(rest, pynames, report_flavors, resturls, rest_to_apinode, javadoc_map): reports_minimal_records = False reports_minimal_carenet = False access_doc_map = {} call_count = 0 method_count = 0 dfekvm = {} retexs = {} retdscs = {} okcount = 0 dividN = 0 #for acall in api_skeleton.CALLS: for resturl in resturls: apinode = rest_to_apinode.get(resturl) if not apinode: print("missing from api.xml: " + repr(resturl)) continue if len(apinode) < 1 or len(apinode) > 2: print(repr(resturl)) raise Exception apinode = apinode[0] call_count += 1 httpmeth = resturl[0].upper() assert httpmeth in ["GET", "PUT", "POST", "DELETE"] forjavadoc = javadoc_map.get(resturl) if not forjavadoc: print(resturl) raise Exception retex = forjavadoc["return_ex"] assert isinstance(retex, str) #retex = retex.strip()[:50] if retexs.has_key(retex): retexs[retex] = retexs[retex] + 1 else: retexs[retex] = 1 retdsc = forjavadoc["return_desc"] assert isinstance(retdsc, str) # if retdsc.find("http:statuscode:`200` with a list of ") != -1: # print("retdsc found: " + retdsc) if retex == "<ok/>": okcount += 1 else: if retdsc.startswith( ":http:statuscode:`200` with a list of " ) or retdsc.startswith(":http:statuscode:`200`, with a list of "): retdsc = ":http:statuscode:`200` with a list of " if retdscs.has_key(retdsc): retdscs[retdsc] = retdscs[retdsc] + 1 else: retdscs[retdsc] = 1 deprecated = forjavadoc["deprecated"] access_doc = forjavadoc["access_doc"] #path0 = acall["path"] #str(acall["path"]) #legged, response_form = api_skel_auxiliary.CALLS_AUX[(httpmeth,path0)] #legged = decide_oauth_legged(access_doc) # not used, just count occurrences in case the statistic is ever needed #adcount = access_doc_map.get(access_doc) #if adcount: # access_doc_map[access_doc] = adcount +1 #else: # access_doc_map[access_doc] = 1 #response_form = decide_response_form(retex, retdsc, httpmeth, path) #assert path0.startswith("/") #path = path0[1:] pathparts = forjavadoc.get("path")[1:].split('/') #pathparts = resturl[1][1:].split('/') # xml style print(repr(resturl) + " -- " + repr(pathparts)) #Unfortunately, this is actually the way the call is written into Indivo #Server. In future releases, we'll deprecate the call and replace it with the #correct one, but for now the documentation is actually accurate. -Dan #> "path":"/carenets/{CARENET_ID}/reports/minimal/vitals/{CATEGORY}" #> "path": "/records/{RECORD_ID}/reports/minimal/vitals/{CATEGORY}/" (reports_minimal_records, reports_minimal_carenet, redundant_report_minimal, first_report_minimal, audit_query) = combine_reports_minimal(reports_minimal_records, reports_minimal_carenet, pathparts) #api or skel # if redundant_report_minimal and not first of its kind if redundant_report_minimal: continue # first of its kind, process it but not next time elif first_report_minimal: #print("first_report_minimal: " + repr(pathparts)) pathparts[len(pathparts) - 2] = "{REPORT_FLAVOR}" ############ #print("first_report_minimal: " + repr(pathparts)) method_name, params = make_method_name(pathparts, httpmeth) #print("after mmn: " + repr(params)) response_form = "" for child in apinode.childNodes: if child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "response": response_form = child.getAttribute("response_format") break oauth_legged = apinode.getElementsByTagName("oauth_legged") if len(oauth_legged) != 1: print(apinode.toxml()) raise Exception oauth_legged = oauth_legged[0] legged = [] if oauth_legged.getAttribute("two_legged"): legged.append(2) if oauth_legged.getAttribute("three_legged"): legged.append(3) skel_url_params0 = forjavadoc.get("url_params") skel_url_params_api = {} for skurpa in skel_url_params0: skel_url_params_api[add_to_apixml.skeleton_style_to_api_style( skurpa)] = skel_url_params0[skurpa] qopts_o = [] qopts_r = [] qopts = apinode.getElementsByTagName("query_opts") qopts_field = False if len(qopts): assert len(qopts) == 1 qopts = qopts[0].getElementsByTagName("qopt") for qopt in qopts: if qopt.getAttribute("field") == "field": qopts_field = True elif qopt.getAttribute("required") == "required": qopts_r.append(qopt.getAttribute("name")) else: qopts_o.append(qopt.getAttribute("name")) write_both( rest, pynames, javadoc( first_report_minimal, audit_query, qopts_o, params, # from pathparts, may be modified with REPORT_FLAVOR skel_url_params0, # skeleton style response_form, legged, apinode, #params, #url_params, forjavadoc, dividN)) dividN += 1 # query_opts = acall["query_opts"] # qopts_r, qopts_o, qopts_field = categorize_query_options(query_opts, httpmeth) write_both(rest, pynames, " public Object ") rest.write(method_name) apicall = apinode.getElementsByTagName("call") assert len(apicall) == 1 apicall = apicall[0] pynames.write(apicall.getAttribute("name")) write_both(rest, pynames, "(\n ") #) url_params = forjavadoc["url_params"] params_from_url = get_params_from_url( forjavadoc) # skeleton style param names mthprms = method_params(qopts_r, qopts_o, params_from_url, skel_url_params0, qopts_field, legged, first_report_minimal, audit_query) #rest.write(mthprms) put_post_data = apinode.getElementsByTagName("put_post_data") assert len(put_post_data) <= 1 if len(put_post_data) == 1: put_post_data = put_post_data[0] put_post_data_form = put_post_data.getAttribute("format") else: put_post_data = None put_post_data_form = None if put_post_data: if mthprms: mthprms += ", " if put_post_data_form == "url_encoded": mthprms += "String body" else: mthprms += "Object body" if not put_post_data_form: # not known, caller must specify mthprms += ", String requestContentType" if not response_form: if mthprms: mthprms += ", " mthprms += "Object responseContentType" if mthprms: mthprms += ", " mthprms += "Map<String, Object> options" write_both(rest, pynames, mthprms) #============== write_both(rest, pynames, ') throws IndivoClientException {\n') if qopts_o: options_str1, options_str2 = process_query_opts( qopts_o, qopts_field, first_report_minimal, audit_query) write_both(rest, pynames, options_str1) write_both(rest, pynames, options_str2) if put_post_data_form == "url_encoded": post_data_keys = put_post_data.getElementsByTagName("key") if post_data_keys: allowedpdks = [] for pdk in post_data_keys: allowedpdks.append('"' + pdk.getAttribute("name") + '"') write_both( rest, pynames, (" checkQueryOptions(body, Arrays.asList(" + str(','.join(allowedpdks)) + "), null, null, \"url encoded param in body\");\n")) write_both( rest, pynames, " Object fromRequest = clientRequest(\n ") write_both(rest, pynames, "\"" + httpmeth + "\", ") madeurl = make_url(pathparts) write_both(rest, pynames, madeurl) reqquer = request_query(qopts_r, qopts_o) write_both(rest, pynames, ", " + reqquer) if 3 in legged: write_both(rest, pynames, ", accessToken, accessTokenSecret") else: write_both(rest, pynames, ", null, null") if put_post_data: write_both(rest, pynames, ", body") if put_post_data_form: if put_post_data_form == "url_encoded": write_both(rest, pynames, ", \"application/x-www-form-urlencoded\"") elif put_post_data_form == "application/xml": write_both(rest, pynames, ", \"application/xml\"") elif put_post_data_form == "text/plain": write_both(rest, pynames, ", \"text/plain\"") else: raise Exception else: write_both(rest, pynames, ", requestContentType") # "URL_ENCODED", "PLAIN_TEXT" if response_form == "": write_both(rest, pynames, ", responseContentType") elif response_form == "XML": write_both(rest, pynames, ", \"application/xml\"") elif response_form == "JSON": write_both(rest, pynames, ", \"application/json\"") elif response_form == "URL_ENCODED": write_both(rest, pynames, ", \"application/x-www-form-urlencoded\"") elif response_form == "PLAIN_TEXT": write_both(rest, pynames, ", \"text/plain\"") else: print("response form: " + response_form) raise Exception write_both(rest, pynames, ", options);\n return fromRequest;\n") write_both(rest, pynames, " }\n\n") method_count += 1 return call_count, method_count