def rest_info(self, insert_row_data, operation_id, ary_result): """ [概要] ITA RestAPI selectメゾット [引数] insert_row_data: dict operation_id: int ary_result: list """ logger.logic_log( 'LOSI00001', 'trace_id: %s, operation_id: %s' % (self.trace_id, operation_id)) # サ事開用設定 proxies = { "http": None, "https": None, } keystr = self.user + ':' + self.password access_key_id = base64.encodestring( keystr.encode('utf8')).decode("ascii").replace('\n', '') url = "{}://{}:{}/default/menu/07_rest_api_ver1.php?no={}".format( self.protocol, self.host, self.portno, self.menu_id) headers = { 'host': '%s:%s' % (self.host, self.portno), 'Content-Type': 'application/json', 'Authorization': access_key_id } headers['X-Command'] = 'INFO' content = json.dumps(insert_row_data) try: response = requests.post(url, headers=headers, timeout=30, verify=False, data=content.encode('utf-8'), proxies=proxies) json_string = json.dumps(response.json(), ensure_ascii=False, indent=4, separators=(',', ': ')) logger.logic_log('LOSI01300', json_string) ary_result['status'] = response.status_code ary_result['response'] = json.loads(json_string) logger.logic_log('LOSI00002', 'trace_id: %s, return: True' % self.trace_id) return True except requests.exceptions.RequestException as ex: ary_result['status'] = '-1' back_trace = ActionDriverCommonModules.back_trace() ary_result['response'] = back_trace + '\nhttp header\n' + str( headers) logger.system_log('LOSM01304', self.trace_id, ex) logger.logic_log('LOSI00002', 'trace_id: %s, return: False' % self.trace_id) return False except Exception as ex: ary_result['status'] = '-1' back_trace = ActionDriverCommonModules.back_trace() ary_result['response'] = back_trace + '\nresponse.status_code:' + \ str(response.status_code) + '\nresponse.text\n' + response.text logger.system_log('LOSM01301', self.trace_id, traceback.format_exc()) logger.logic_log('LOSI00002', 'trace_id: %s, return: False' % self.trace_id) return False
def rest_symphony_execute(self, symphony_class_no, operation_id, list_symphony_instance_id, ary_result, resp_id, exe_order): """ [概要] ITA RestAPI Symphony実行メゾット """ logger.logic_log( 'LOSI00001', 'trace_id: %s, symphony_class_no: %s, operation_id: %s, list_symphony_instance_id: %s' % (self.trace_id, symphony_class_no, operation_id, list_symphony_instance_id)) # サ事開用設定 proxies = { "http": None, "https": None, } keystr = self.user + ':' + self.password access_key_id = base64.encodestring( keystr.encode('utf8')).decode("ascii").replace('\n', '') url = "{}://{}:{}/default/menu/07_rest_api_ver1.php?no={}".format( self.protocol, self.host, self.portno, self.menu_id) logger.system_log('LOSI01000', url, self.trace_id) headers = { 'host': '%s:%s' % (self.host, self.portno), 'Content-Type': 'application/json', 'Authorization': access_key_id } # X-Command headers['X-Command'] = 'EXECUTE' # SymphonyクラスIDとオペレーションを設定 ary_execute = {} ary_execute['SYMPHONY_CLASS_NO'] = symphony_class_no ary_execute['OPERATION_ID'] = operation_id str_para_json_encoded = json.dumps(ary_execute) try: response = requests.post( url, headers=headers, timeout=30, verify=False, data=str_para_json_encoded.encode('utf-8'), proxies=proxies) ary_result['status'] = response.status_code ary_result['text'] = response.text try: json_string = json.dumps(response.json(), ensure_ascii=False, separators=(',', ': ')) ary_result['response'] = json.loads(json_string) if ary_result['status'] != 200: ary_result['response'] = json_string logger.system_log('LOSM01300', self.trace_id, ary_execute['SYMPHONY_CLASS_NO'], ary_execute['OPERATION_ID'], ary_result['status'], ary_result['text']) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) ActionDriverCommonModules.SaveActionLog( resp_id, exe_order, self.trace_id, 'MOSJA01030') return False if ary_result['response']['status'] != 'SUCCEED': ary_result['response'] = json_string logger.logic_log('LOSM01300', self.trace_id, ary_execute['SYMPHONY_CLASS_NO'], ary_execute['OPERATION_ID'], ary_result['status'], ary_result['text']) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) ActionDriverCommonModules.SaveActionLog( resp_id, exe_order, self.trace_id, 'MOSJA01029') return False list_symphony_instance_id.append( ary_result['response']['resultdata'] ['SYMPHONY_INSTANCE_ID']) except Exception as ex: ary_result['status'] = '-1' back_trace = ActionDriverCommonModules.back_trace() ary_result['response'] = back_trace + '\nresponse.status_code:' + \ str(response.status_code) + '\nresponse.text\n' + response.text logger.system_log('LOSM01301', self.trace_id, traceback.format_exc()) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) ActionDriverCommonModules.SaveActionLog( resp_id, exe_order, self.trace_id, 'MOSJA01031') return False except Exception as ex: ary_result['status'] = '-1' back_trace = ActionDriverCommonModules.back_trace() ary_result['response'] = back_trace + '\nhttp header\n' + str( headers) logger.system_log('LOSM01301', self.trace_id, traceback.format_exc()) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) ActionDriverCommonModules.SaveActionLog(resp_id, exe_order, self.trace_id, 'MOSJA01032') return False logger.logic_log('LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'True')) ActionDriverCommonModules.SaveActionLog(resp_id, exe_order, self.trace_id, 'MOSJA01028') return True
def rest_select(self, aryfilter, ary_result): """ [概要] ITA RestAPI selectメゾット """ logger.logic_log( 'LOSI00001', 'trace_id: %s, aryfilter: %s' % (self.trace_id, aryfilter)) # サ事開用設定 proxies = { "http": None, "https": None, } keystr = self.user + ':' + self.password access_key_id = base64.encodestring( keystr.encode('utf8')).decode("ascii").replace('\n', '') url = "{}://{}:{}/default/menu/07_rest_api_ver1.php?no={}".format( self.protocol, self.host, self.portno, self.menu_id) logger.system_log('LOSI01000', url, self.trace_id) headers = { 'host': '%s:%s' % (self.host, self.portno), 'Content-Type': 'application/json', 'Authorization': access_key_id } # X-Command headers['X-Command'] = 'FILTER' # aryFilterの条件に合致するレコードを取得する str_para_json_encoded = json.dumps(aryfilter) try: response = requests.post( url, headers=headers, timeout=30, verify=False, data=str_para_json_encoded.encode('utf-8'), proxies=proxies) ary_result['status'] = response.status_code ary_result['text'] = response.text try: json_string = json.dumps(response.json(), ensure_ascii=False, separators=(',', ': ')) ary_result['response'] = json.loads(json_string) if ary_result['status'] != 200: ary_result['response'] = json_string logger.system_log('LOSM01303', self.trace_id, ary_result['status'], ary_result['response']) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) return False except Exception as ex: ary_result['status'] = '-1' back_trace = ActionDriverCommonModules.back_trace() ary_result['response'] = back_trace + '\nresponse.status_code:' + \ str(response.status_code) + '\nresponse.text\n' + response.text logger.system_log('LOSM01301', self.trace_id, traceback.format_exc()) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) return False except Exception as ex: ary_result['status'] = '-1' back_trace = ActionDriverCommonModules.back_trace() ary_result['response'] = back_trace + '\nhttp header\n' + str( headers) logger.system_log('LOSM01301', self.trace_id, traceback.format_exc()) logger.logic_log( 'LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'False')) return False logger.logic_log('LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, 'True')) return True