def sensormlproxy(request): # if SkRegistration.objects.get_current() is None: # return json_response(errors='You must register the GET-IT before save a Metadata', # status=500) service = settings.RITMARE['MDSERVICE'] + 'postMetadata' headers = { # 'api_key': get_key(), 'Content-Type': 'application/xml' } r = requests.post(service, data=request.raw_post_data, headers=headers, verify=False) if r.status_code == 200: sensorml = r.text # get fileid ediml = etree.fromstring(request.raw_post_data) fileid = ediml.find('fileId').text headers = { 'Accept': 'application/xml', 'Content-Type': 'application/xml', 'Authorization': "%s" % settings.SOS_SERVER['default']['TRANSACTIONAL_AUTHORIZATION_TOKEN'] } settings.SOS_SERVER['default']['LOCATION'] sos_response = requests.post( settings.SOS_SERVER['default']['LOCATION'] + '/pox', data=sensorml.encode('utf8'), headers=headers, verify=False ) if sos_response.status_code == 200: tr = etree.fromstring(sos_response.content) if tr.tag == nspath_eval("ows110:ExceptionReport", namespaces): return json_response(exception=sos_response.text.encode('utf8'), status=500) # save sensorml & edi xml sensor = Sensor(fileid=fileid) sensor.sensorml = sensorml sensor.ediml = request.raw_post_data sensor.save() return json_response(body={'success':True,'redirect': reverse('osk_browse')}) else: return json_response(exception=sos_response.text.encode('utf8'), status=500) return json_response(errors='Cannot create SensorML', status=500)
def sensormlproxy(request): # if SkRegistration.objects.get_current() is None: # return json_response(errors='You must register the GET-IT before save a Metadata', # status=500) service = settings.RITMARE['MDSERVICE'] + 'postMetadata' headers = { # 'api_key': get_key(), 'Content-Type': 'application/xml' } r = requests.post(service, data=request.raw_post_data, headers=headers, verify=False) if r.status_code == 200: sensorml = r.text # get fileid ediml = etree.fromstring(request.raw_post_data) fileid = ediml.find('fileId').text headers = { 'Accept': 'application/xml', 'Content-Type': 'application/xml', 'Authorization': "%s" % settings.SOS_SERVER['default']['TRANSACTIONAL_AUTHORIZATION_TOKEN'] } settings.SOS_SERVER['default']['LOCATION'] sos_response = requests.post( settings.SOS_SERVER['default']['LOCATION'] + '/pox', data=sensorml.encode('utf8'), headers=headers, verify=False) if sos_response.status_code == 200: tr = etree.fromstring(sos_response.content) if tr.tag == nspath_eval("ows110:ExceptionReport", namespaces): return json_response( exception=sos_response.text.encode('utf8'), status=500) # save sensorml & edi xml sensor = Sensor(fileid=fileid) sensor.sensorml = sensorml sensor.ediml = request.raw_post_data sensor.save() return json_response(body={ 'success': True, 'redirect': reverse('osk_browse') }) else: return json_response(exception=sos_response.text.encode('utf8'), status=500) return json_response(errors='Cannot create SensorML', status=500)
def ediproxy_importmd(request): # if SkRegistration.objects.get_current() is None: # return json_response(errors='You must register the GET-IT before save a Metadata', # status=500) insertsensor = request.POST.get('generatedXml').encode('utf8') ediml = request.POST.get('ediml').encode('utf8') edimlid = request.POST.get('edimlid') headers = { 'Accept': 'application/xml', 'Content-Type': 'application/xml', 'Authorization': "%s" % settings.SOS_SERVER['default']['TRANSACTIONAL_AUTHORIZATION_TOKEN'] } sos_response = requests.post( settings.SOS_SERVER['default']['LOCATION'] + '/pox', data=insertsensor, headers=headers, verify=False ) if sos_response.status_code == 200: tr = etree.fromstring(sos_response.content) if tr.tag == nspath_eval("ows110:ExceptionReport", namespaces): return json_response(exception=sos_response.text.encode('utf8'), status=500) # save sensorml & edi xml _ediml = etree.fromstring(ediml) fileid = _ediml.find('fileId').text sensor = Sensor(fileid=fileid) sensor.sensorml = insertsensor sensor.ediml = ediml sensor.save() return json_response(body={'success':True,'redirect': reverse('osk_browse')}) else: return json_response(exception=sos_response.text.encode('utf8'), status=500)
def ediproxy_importmd(request): # if SkRegistration.objects.get_current() is None: # return json_response(errors='You must register the GET-IT before save a Metadata', # status=500) generatedXml = request.POST.get('generatedXml') if not generatedXml: return json_response(exception="No sensor data has been found", status=500) insertsensor = request.POST.get('generatedXml').encode('utf8') ediml = request.POST.get('ediml').encode('utf8') edimlid = request.POST.get('edimlid') headers = { 'Accept': 'application/xml', 'Content-Type': 'application/xml', 'Authorization': f"{settings.SOS_SERVER['default']['TRANSACTIONAL_AUTHORIZATION_TOKEN']}" } sos_response = requests.post( f"{settings.SOS_SERVER['default']['LOCATION']}/pox", data=insertsensor, headers=headers, verify=False) if sos_response.status_code == 200: _content = sos_response.content tr = etree.fromstring(_content) if tr.tag == nspath_eval("ows110:ExceptionReport", namespaces): return json_response(exception=sos_response.text.encode('utf8'), status=500) # save sensorml & edi xml _ediml = etree.fromstring(ediml) fileid = _ediml.find('fileId').text sensor = Sensor(fileid=fileid) sensor.sensorml = insertsensor sensor.ediml = ediml sensor.save() return json_response(body={ 'success': True, 'redirect': reverse('osk_browse') }) else: return json_response(exception=sos_response.text.encode('utf8'), status=500)