def executePut(self): """ Method for executing a POST requests that create a new SOS observed property """ if self.service == "default": raise Exception("observedproperties operation can not be done for default service instance.") elif self.observedproperty == None: raise Exception("destination observedproperty is not specified.") else: import json from walib import utils as ut servicedb = databaseManager.PgDB( self.serviceconf.connection["user"], self.serviceconf.connection["password"], self.serviceconf.connection["dbname"], self.serviceconf.connection["host"], self.serviceconf.connection["port"], ) sql = "SELECT id_opr FROM %s.observed_properties " % self.service sql += "WHERE def_opr = %s" par = (self.observedproperty,) row = servicedb.select(sql, par) if not row: raise Exception("Original observed property '%s' does not exist." % self.observedproperty) oid = row[0]["id_opr"] sql = "UPDATE %s.observed_properties " % self.service if not self.json["constraint"] or self.json["constraint"] == {}: sql += "SET name_opr = %s, def_opr = %s, desc_opr=%s, constr_opr=NULL " par = (self.json["name"], self.json["definition"], self.json["description"], oid) else: try: ut.validateJsonConstraint(self.json["constraint"]) except Exception as ex: raise Exception( "Constraint for observed property '%s' is not valid: %s" % (self.observedproperty, ex) ) sql += "SET name_opr = %s, def_opr = %s, desc_opr=%s, constr_opr=%s " par = ( self.json["name"], self.json["definition"], self.json["description"], json.dumps(self.json["constraint"]), oid, ) sql += "WHERE id_opr = %s" servicedb.execute(sql, par) self.setMessage("Update successfull")
def executePut(self): """ Method for executing a POST requests that create a new SOS observed property """ if self.service == "default": raise Exception( "observedproperties operation can not be done for default service instance." ) elif self.observedproperty == None: raise Exception("destination observedproperty is not specified.") else: import json from walib import utils as ut servicedb = databaseManager.PgDB( self.serviceconf.connection['user'], self.serviceconf.connection['password'], self.serviceconf.connection['dbname'], self.serviceconf.connection['host'], self.serviceconf.connection['port']) sql = "SELECT id_opr FROM %s.observed_properties " % self.service sql += "WHERE def_opr = %s" par = (self.observedproperty, ) row = servicedb.select(sql, par) if not row: raise Exception( "Original observed property '%s' does not exist." % self.observedproperty) oid = row[0]["id_opr"] sql = "UPDATE %s.observed_properties " % self.service if not self.json['constraint'] or self.json['constraint'] == {}: sql += "SET name_opr = %s, def_opr = %s, desc_opr=%s, constr_opr=NULL " par = (self.json['name'], self.json['definition'], self.json['description'], oid) else: try: ut.validateJsonConstraint(self.json['constraint']) except Exception as ex: raise Exception( "Constraint for observed property '%s' is not valid: %s" % (self.observedproperty, ex)) sql += "SET name_opr = %s, def_opr = %s, desc_opr=%s, constr_opr=%s " par = (self.json['name'], self.json['definition'], self.json['description'], json.dumps(self.json['constraint']), oid) sql += "WHERE id_opr = %s" servicedb.execute(sql, par) self.setMessage("Update successfull")
def executePost(self): """ Method for executing a POST requests that create a new SOS observed property """ if self.service == "default": raise Exception("observedproperties operation can not be done for default service instance.") else: import json from walib import utils as ut servicedb = databaseManager.PgDB( self.serviceconf.connection["user"], self.serviceconf.connection["password"], self.serviceconf.connection["dbname"], self.serviceconf.connection["host"], self.serviceconf.connection["port"], ) sql = "INSERT INTO %s.observed_properties(name_opr, def_opr, desc_opr, constr_opr)" % self.service if not self.json["constraint"] or self.json["constraint"] == {}: sql += " VALUES (%s, %s, %s, NULL);" par = (self.json["name"], self.json["definition"], self.json["description"]) else: try: ut.validateJsonConstraint(self.json["constraint"]) except Exception as ex: raise Exception( "Constraint for observed property '%s' is not valid: %s" % (self.observedproperty, ex) ) sql += " VALUES (%s, %s, %s, %s);" par = ( self.json["name"], self.json["definition"], self.json["description"], json.dumps(self.json["constraint"]), ) servicedb.execute(sql, par) self.setMessage("Insert successfull")
def executePost(self): """ Method for executing a POST requests that create a new SOS observed property """ if self.service == "default": raise Exception( "observedproperties operation can not be done for default service instance." ) else: import json from walib import utils as ut servicedb = databaseManager.PgDB( self.serviceconf.connection['user'], self.serviceconf.connection['password'], self.serviceconf.connection['dbname'], self.serviceconf.connection['host'], self.serviceconf.connection['port']) sql = "INSERT INTO %s.observed_properties(name_opr, def_opr, desc_opr, constr_opr)" % self.service if not self.json['constraint'] or self.json['constraint'] == {}: sql += " VALUES (%s, %s, %s, NULL);" par = (self.json['name'], self.json['definition'], self.json['description']) else: try: ut.validateJsonConstraint(self.json['constraint']) except Exception as ex: raise Exception( "Constraint for observed property '%s' is not valid: %s" % (self.observedproperty, ex)) sql += " VALUES (%s, %s, %s, %s);" par = (self.json['name'], self.json['definition'], self.json['description'], json.dumps(self.json['constraint'])) servicedb.execute(sql, par) self.setMessage("Insert successfull")
def toXML(self,indent=False): """ Return the SensorML that represent the self.data object as L{string} """ import sys ns = { 'xsi': "http://www.w3.org/2001/XMLSchema-instance" , 'sml': "http://www.opengis.net/sensorML/1.0.1", 'swe': "http://www.opengis.net/swe/1.0.1", 'xlink': "http://www.w3.org/1999/xlink", 'gml': 'http://www.opengis.net/gml' } #---map namespaces--- try: register_namespace = et.register_namespace for key in ns: register_namespace(key,ns[key]) except AttributeError: try: et._namespace_map.update(ns) for key in ns: et._namespace_map[ns[key]] = key except AttributeError: try: from xml.etree.ElementTree import _namespace_map except ImportError: try: from elementtree.ElementTree import _namespace_map except ImportError: print >> sys.stderr, ("Failed to import ElementTree from any known place") for key in ns: _namespace_map[ns[key]] = key root = et.Element("{%s}SensorML" % ns['sml']) root.attrib[ "{%s}schemaLocation" % ns['xsi'] ] = "http://www.opengis.net/sensorML/1.0.1 http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd" root.attrib["version"] = "1.0" member = et.SubElement(root, "{%s}member" % ns['sml'] ) system = et.SubElement(member, "{%s}System" % ns['sml'] ) system.attrib["{%s}id" % ns['gml'] ] = self.data["system_id"] #--- System Description system.append(et.Comment("System Description")) if ("keywords" in self.data) and (not self.data["description"]==""): desc = et.SubElement(system, "{%s}description" % ns['gml'] ) desc.text = self.data["description"] name = et.SubElement(system, "{%s}name" % ns['gml'] ) name.text = self.data["system"] #--- System Search Keywords if ("keywords" in self.data) and (not self.data["keywords"]==""): system.append(et.Comment("System Search Keywords")) keys = et.SubElement(system, "{%s}keywords" % ns['sml'] ) keylist = et.SubElement(keys, "{%s}KeywordList" % ns['sml'] ) for k in self.data["keywords"].split(","): key = et.SubElement(keylist, "{%s}keyword" % ns['sml'] ) key.text = k #--- System Identifiers if ("identification" in self.data) and (not self.data["identification"]==[]): system.append(et.Comment("System Identifiers")) identification = et.SubElement(system, "{%s}identification" % ns['sml'] ) IdentifierList = et.SubElement(identification, "{%s}IdentifierList" % ns['sml'] ) uniqueidPresent = False for i in self.data["identification"]: if i["definition"] == 'urn:ogc:def:identifier:OGC:uniqueID': uniqueidPresent = True identifier = et.SubElement(IdentifierList, "{%s}identifier" % ns['sml'] ) identifier.attrib["name"] = i["name"] term = et.SubElement(identifier, "{%s}Term" % ns['sml'] ) term.attrib["definition"] = i["definition"] value = et.SubElement(term, "{%s}value" % ns['sml']) value.text = i["value"] if not uniqueidPresent: raise Exception("self.data['identification']: 'uniqueID' is mandatory") #--- System Classifiers system.append(et.Comment("System Classifiers")) classification = et.SubElement(system, "{%s}classification" % ns['sml'] ) ClassifierList = et.SubElement(classification, "{%s}ClassifierList" % ns['sml']) for c in self.data["classification"]: classifier = et.SubElement(ClassifierList, "{%s}classifier" % ns['sml'] ) classifier.attrib["name"] = c["name"] term = et.SubElement(classifier, "{%s}Term" % ns['sml'] ) term.attrib["definition"] = c["definition"] value = et.SubElement(term, "{%s}value" % ns['sml'] ) value.text = c["value"] if c["name"]=="System Type": systype = True elif c["name"]=="Sensor Type": senstype = True if not systype == True and senstype == True: raise Exception("self.data['classification']: 'System Type' and 'Sensor Type' are mandatory") #--- System Characteristics if ("characteristics" in self.data) and ( not self.data["characteristics"] == ""): system.append(et.Comment("System Characteristics")) characteristics = et.SubElement(system, "{%s}characteristics" % ns['sml']) characteristics.attrib[ "{%s}href" % ns['xlink'] ] = self.data["characteristics"] #--- System Capabilities system.append(et.Comment("System Capabilities")) capabilities = et.SubElement(system, "{%s}capabilities" % ns['sml']) DataRecord = et.SubElement(capabilities, "{%s}DataRecord" % ns['swe']) stres = False atres = False for f in self.data["capabilities"]: field = et.SubElement(DataRecord, "{%s}field" % ns['swe']) field.attrib[ "name" ] =f["name"] Quantity = et.SubElement(field, "{%s}Quantity" % ns['swe']) Quantity.attrib[ "definition" ] =f["definition"] if "uom" in f and "value" in f : uom = et.SubElement(Quantity, "{%s}uom" % ns['swe']) uom.attrib[ "code" ] =f["uom"] value = et.SubElement(Quantity, "{%s}value" % ns['swe']) value.text =f["value"] if c["name"]=="Sampling time resolution": stres = True elif c["name"]=="Acquisition time resolution": atres = True if not stres == True and atres == True: raise Exception("self.data['capabilities']: 'Sampling time resolution' and 'Acquisition time resolution' are mandatory") #--- Relevant Contacts if ("contacts" in self.data) and (not self.data["contacts"] == []): system.append(et.Comment("Relevant Contacts")) for c in self.data["contacts"]: contact = et.SubElement(system, "{%s}contact" % ns['sml']) contact.attrib["{%s}role" % ns['xlink']] = c["role"] ResponsibleParty = et.SubElement(contact, "{%s}ResponsibleParty" % ns['sml']) if not c["individualName"] == "": individualName = et.SubElement(ResponsibleParty, "{%s}individualName" % ns['sml']) individualName.text = c["individualName"] organizationName = et.SubElement(ResponsibleParty, "{%s}organizationName" % ns['sml']) organizationName.text = c["organizationName"] phonetag = not c["voice"] == c["fax"] == "" addresstag = not c["deliveryPoint"] == c["city"] == c["administrativeArea"] == c["postalcode"] == c["country"] == c["email"] == "" onlineResourcetag = not c["web"] == "" if not phonetag == addresstag == onlineResourcetag == False: contactInfo = et.SubElement(ResponsibleParty, "{%s}contactInfo" % ns['sml']) if not phonetag==False: phone = et.SubElement(contactInfo, "{%s}phone" % ns['sml']) if not c["voice"] == "": voice = et.SubElement(phone, "{%s}voice" % ns['sml']) voice.text = c["voice"] if not c["fax"] == "": facsimile = et.SubElement(phone, "{%s}facsimile" % ns['sml']) facsimile.text = c["fax"] if not addresstag==False: address = et.SubElement(contactInfo, "{%s}address" % ns['sml']) if not c["deliveryPoint"] == "": deliveryPoint = et.SubElement(address, "{%s}deliveryPoint" % ns['sml']) deliveryPoint.text = c["deliveryPoint"] if not c["city"] == "": city = et.SubElement(address, "{%s}city" % ns['sml']) city.text = c["city"] if not c["administrativeArea"] == "": administrativeArea = et.SubElement(address, "{%s}administrativeArea" % ns['sml']) administrativeArea.text = c["administrativeArea"] if not c["postalcode"] == "": postalCode = et.SubElement(address, "{%s}postalCode" % ns['sml']) postalCode.text = c["postalcode"] if not c["country"] == "": country = et.SubElement(address, "{%s}country" % ns['sml']) country.text = c["country"] if not c["email"] == "": electronicMailAddress = et.SubElement(address, "{%s}electronicMailAddress" % ns['sml']) electronicMailAddress.text = c["email"] if not onlineResourcetag==False: onlineResource = et.SubElement(contactInfo, "{%s}onlineResource" % ns['sml']) onlineResource.attrib["{%s}href" % ns['xlink'] ] = c["web"] #--- System Documentation if ("documentation" in self.data) and (not self.data["documentation"] == []): system.append(et.Comment("System Documentation")) for d in self.data["documentation"]: documentation = et.SubElement(system, "{%s}documentation" % ns['sml']) Document = et.SubElement(documentation, "{%s}Document" % ns['sml']) description = et.SubElement(Document, "{%s}description" % ns['gml']) description.text = d["description"] if not d["date"]=="": date = et.SubElement(Document, "{%s}date" % ns['sml']) date.text = d["date"] if not d["format"]=="": format = et.SubElement(Document, "{%s}format" % ns['sml']) format.text = d["format"] onlineResource = et.SubElement(Document, "{%s}onlineResource" % ns['sml']) onlineResource.attrib["{%s}href" % ns['xlink'] ] = d["link"] #--- System Location system.append(et.Comment("System Location")) location = et.SubElement(system, "{%s}location" % ns['sml']) for item in self.data["classification"]: if item["name"] == "System Type": if item["value"].find("mobile")>0: location.attrib[ "{%s}role" % ns['xlink'] ] = "urn:ogc:def:dataType:x-istsos:1.0:lastPosition" Point = et.SubElement(location, "{%s}Point" % ns['gml']) if ut.valid_NCName(self.data["location"]["properties"]["name"]): Point.attrib[ "{%s}id" % ns['gml'] ] = self.data["location"]["properties"]["name"] else: raise Exception ("Invalid location name (gml:id only allows alphanumeric characters") Point.attrib[ "srsName" ] = "EPSG:"+str(self.data["location"]["crs"]["properties"]["name"]) coordinates = et.SubElement(Point, "{%s}coordinates" % ns['gml']) coordinates.text = ",".join([ str(a) for a in self.data["location"]["geometry"]["coordinates"] ]) #--- System Interfaces if ("interfaces" in self.data) and (not self.data["interfaces"]==""): system.append(et.Comment("System Interfaces")) interfaces = et.SubElement(system, "{%s}interfaces" % ns['sml']) InterfaceList = et.SubElement(interfaces, "{%s}InterfaceList" % ns['sml']) for i in self.data["interfaces"].split(","): interface = et.SubElement(InterfaceList, "{%s}interface" % ns['sml']) interface.attrib["name"] = i #--- System Inputs # Not yet supported in waAdmin !! if ("inputs" in self.data) and (not self.data["inputs"]==[]): system.append(et.Comment("System Inputs")) inputs = et.SubElement(system, "{%s}inputs" % ns['sml']) InputList = et.SubElement(inputs, "{%s}InputList" % ns['sml']) for inp in self.data["inputs"]: inputml = et.SubElement(InputList, "{%s}input" % ns['sml']) inputml.attrib["name"] = inp["name"] Quantity = et.SubElement(inputml, "{%s}Quantity" % ns['swe']) Quantity.attrib["definition"] = inp["definition"] if not inp["description"]=="": description = et.SubElement(Quantity, "{%s}description" % ns['gml']) description.text = inp["description"] #--- System Outputs timetag = False system.append(et.Comment("System Outputs")) outputs = et.SubElement(system, "{%s}outputs" % ns['sml']) OutputList = et.SubElement(outputs, "{%s}OutputList" % ns['sml']) output = et.SubElement(OutputList, "{%s}output" % ns['sml']) output.attrib["name"] = "output data" DataRecord = et.SubElement(output, "{%s}DataRecord" % ns['swe']) DataRecord.attrib["definition"] = "urn:ogc:def:dataType:x-istsos:1.0:timeSeries" oid = 0 for o in self.data["outputs"]: oid += 1 field = et.SubElement(DataRecord, "{%s}field" % ns['swe']) field.attrib["name"] = o["name"] if o["name"] == "Time": timetag = True item = et.SubElement(field, "{%s}Time" % ns['swe']) item.attrib["{%s}id" % ns['gml']] = "IDT_" + str(oid) item.attrib["definition"] = o["definition"] if not o["description"]=="": description = et.SubElement(item, "{%s}description" % ns['gml']) description.text = o["description"] uom = et.SubElement(item, "{%s}uom" % ns['swe']) uom.attrib["code"] = o["uom"] # The constraint object is not mandatory if "constraint" in o and o["constraint"]!={}: # and o["constraint"]["role"]!="" and o["constraint"]["role"]!=None: constraint = et.SubElement(item, "{%s}constraint" % ns['swe']) # Role attribute is not mandatory if "role" in o["constraint"] and o["constraint"]["role"]!="" and o["constraint"]["role"]!=None: constraint.attrib[ "{%s}role" % ns['xlink'] ] = o["constraint"]["role"] AllowedTimes = et.SubElement(constraint, "{%s}AllowedTimes" % ns['swe']) interval = et.SubElement(AllowedTimes, "{%s}interval" % ns['swe']) interval.text = " ".join([ str(a) for a in o["constraint"]["interval"] ]) else: item = et.SubElement(field, "{%s}Quantity" % ns['swe']) item.attrib["{%s}id" % ns['gml']] = "IDQ_" + str(oid) item.attrib["definition"] = o["definition"] if not o["description"]=="": description = et.SubElement(item, "{%s}description" % ns['gml']) description.text = o["description"] uom = et.SubElement(item, "{%s}uom" % ns['swe']) uom.attrib["code"] = o["uom"] # The constraint object is not mandatory if "constraint" in o and o["constraint"]!={}: # and o["constraint"]["role"]!="" and o["constraint"]["role"]!=None: print >> sys.stderr, o['constraint'] try: ut.validateJsonConstraint(o['constraint']) except Exception as ex: raise Exception("Constraint for observed property '%s' is not valid: %s" % (o["definition"],ex)) constraint = et.SubElement(item, "{%s}constraint" % ns['swe']) # Role attribute is not mandatory if "role" in o["constraint"] and o["constraint"]["role"]!="" and o["constraint"]["role"]!=None: constraint.attrib[ "{%s}role" % ns['xlink'] ]= o["constraint"]["role"] AllowedValues = et.SubElement(constraint, "{%s}AllowedValues" % ns['swe']) # Factory on constraint min/max/interval/valuelist if "interval" in o["constraint"]: interval = et.SubElement(AllowedValues, "{%s}interval" % ns['swe']) interval.text = " ".join([ str(a) for a in o["constraint"]["interval"] ]) elif "valueList" in o["constraint"]:#.has_key("valueList"): valueList = et.SubElement(AllowedValues, "{%s}valueList" % ns['swe']) valueList.text = " ".join([ str(a) for a in o["constraint"]["valueList"] ]) elif "min" in o["constraint"]:#.has_key("min"): amin = et.SubElement(AllowedValues, "{%s}min" % ns['swe']) amin.text = str(o["constraint"]["min"]) elif "max" in o["constraint"]:#.has_key("max"): amax = et.SubElement(AllowedValues, "{%s}max" % ns['swe']) amax.text = str(o["constraint"]["max"]) if timetag == False: raise Exception("self.data['outputs']: Time is mandatory") #--- System History if ("history" in self.data) and (not self.data["history"]==[]): system.append(et.Comment("System History")) history = et.SubElement(system, "{%s}history" % ns['sml']) EventList = et.SubElement(history, "{%s}EventList" % ns['sml']) for h in self.data["history"]: member = et.SubElement(EventList, "{%s}member" % ns['sml']) member.attrib["name"] = h["type"] Event = et.SubElement(member, "{%s}Event" % ns['sml']) date = et.SubElement(Event, "{%s}date" % ns['sml']) date.text = h["date"] if not h["description"]=="": description = et.SubElement(Event, "{%s}description" % ns['gml']) description.text = h["description"] contact = et.SubElement(Event, "{%s}contact" % ns['sml']) contact.attrib["{%s}href" % ns['xlink'] ] = h["reference"]["username"] contact.attrib["{%s}arcrole" % ns['xlink'] ] = h["reference"]["role"] return et.tostring(root, encoding="UTF-8")
def toXML(self, indent=False): """ Return the SensorML that represent the self.data object as L{string} """ import sys ns = { 'xsi': "http://www.w3.org/2001/XMLSchema-instance", 'sml': "http://www.opengis.net/sensorML/1.0.1", 'swe': "http://www.opengis.net/swe/1.0.1", 'xlink': "http://www.w3.org/1999/xlink", 'gml': 'http://www.opengis.net/gml' } #---map namespaces--- try: register_namespace = et.register_namespace for key in ns: register_namespace(key, ns[key]) except AttributeError: try: et._namespace_map.update(ns) for key in ns: et._namespace_map[ns[key]] = key except AttributeError: try: from xml.etree.ElementTree import _namespace_map except ImportError: try: from elementtree.ElementTree import _namespace_map except ImportError: print >> sys.stderr, ( "Failed to import ElementTree from any known place" ) for key in ns: _namespace_map[ns[key]] = key root = et.Element("{%s}SensorML" % ns['sml']) root.attrib["{%s}schemaLocation" % ns[ 'xsi']] = "http://www.opengis.net/sensorML/1.0.1 http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd" root.attrib["version"] = "1.0" member = et.SubElement(root, "{%s}member" % ns['sml']) system = et.SubElement(member, "{%s}System" % ns['sml']) system.attrib["{%s}id" % ns['gml']] = self.data["system_id"] #--- System Description system.append(et.Comment("System Description")) if ("keywords" in self.data) and (not self.data["description"] == ""): desc = et.SubElement(system, "{%s}description" % ns['gml']) desc.text = self.data["description"] name = et.SubElement(system, "{%s}name" % ns['gml']) name.text = self.data["system"] #--- System Search Keywords if ("keywords" in self.data) and (not self.data["keywords"] == ""): system.append(et.Comment("System Search Keywords")) keys = et.SubElement(system, "{%s}keywords" % ns['sml']) keylist = et.SubElement(keys, "{%s}KeywordList" % ns['sml']) for k in self.data["keywords"].split(","): key = et.SubElement(keylist, "{%s}keyword" % ns['sml']) key.text = k #--- System Identifiers if ("identification" in self.data) and (not self.data["identification"] == []): system.append(et.Comment("System Identifiers")) identification = et.SubElement(system, "{%s}identification" % ns['sml']) IdentifierList = et.SubElement(identification, "{%s}IdentifierList" % ns['sml']) uniqueidPresent = False for i in self.data["identification"]: if i["definition"] == 'urn:ogc:def:identifier:OGC:uniqueID': uniqueidPresent = True identifier = et.SubElement(IdentifierList, "{%s}identifier" % ns['sml']) identifier.attrib["name"] = i["name"] term = et.SubElement(identifier, "{%s}Term" % ns['sml']) term.attrib["definition"] = i["definition"] value = et.SubElement(term, "{%s}value" % ns['sml']) value.text = i["value"] if not uniqueidPresent: raise Exception( "self.data['identification']: 'uniqueID' is mandatory") #--- System Classifiers system.append(et.Comment("System Classifiers")) classification = et.SubElement(system, "{%s}classification" % ns['sml']) ClassifierList = et.SubElement(classification, "{%s}ClassifierList" % ns['sml']) for c in self.data["classification"]: classifier = et.SubElement(ClassifierList, "{%s}classifier" % ns['sml']) classifier.attrib["name"] = c["name"] term = et.SubElement(classifier, "{%s}Term" % ns['sml']) term.attrib["definition"] = c["definition"] value = et.SubElement(term, "{%s}value" % ns['sml']) value.text = c["value"] if c["name"] == "System Type": systype = True elif c["name"] == "Sensor Type": senstype = True if not systype == True and senstype == True: raise Exception( "self.data['classification']: 'System Type' and 'Sensor Type' are mandatory" ) #--- System Characteristics if ("characteristics" in self.data) and (not self.data["characteristics"] == ""): system.append(et.Comment("System Characteristics")) characteristics = et.SubElement(system, "{%s}characteristics" % ns['sml']) characteristics.attrib["{%s}href" % ns['xlink']] = self.data["characteristics"] #--- System Capabilities system.append(et.Comment("System Capabilities")) capabilities = et.SubElement(system, "{%s}capabilities" % ns['sml']) DataRecord = et.SubElement(capabilities, "{%s}DataRecord" % ns['swe']) stres = False atres = False for f in self.data["capabilities"]: field = et.SubElement(DataRecord, "{%s}field" % ns['swe']) field.attrib["name"] = f["name"] Quantity = et.SubElement(field, "{%s}Quantity" % ns['swe']) Quantity.attrib["definition"] = f["definition"] if "uom" in f and "value" in f: uom = et.SubElement(Quantity, "{%s}uom" % ns['swe']) uom.attrib["code"] = f["uom"] value = et.SubElement(Quantity, "{%s}value" % ns['swe']) value.text = f["value"] if c["name"] == "Sampling time resolution": stres = True elif c["name"] == "Acquisition time resolution": atres = True if not stres == True and atres == True: raise Exception( "self.data['capabilities']: 'Sampling time resolution' and 'Acquisition time resolution' are mandatory" ) #--- Relevant Contacts if ("contacts" in self.data) and (not self.data["contacts"] == []): system.append(et.Comment("Relevant Contacts")) for c in self.data["contacts"]: contact = et.SubElement(system, "{%s}contact" % ns['sml']) contact.attrib["{%s}role" % ns['xlink']] = c["role"] ResponsibleParty = et.SubElement( contact, "{%s}ResponsibleParty" % ns['sml']) if not c["individualName"] == "": individualName = et.SubElement( ResponsibleParty, "{%s}individualName" % ns['sml']) individualName.text = c["individualName"] organizationName = et.SubElement( ResponsibleParty, "{%s}organizationName" % ns['sml']) organizationName.text = c["organizationName"] phonetag = not c["voice"] == c["fax"] == "" addresstag = not c["deliveryPoint"] == c["city"] == c[ "administrativeArea"] == c["postalcode"] == c[ "country"] == c["email"] == "" onlineResourcetag = not c["web"] == "" if not phonetag == addresstag == onlineResourcetag == False: contactInfo = et.SubElement(ResponsibleParty, "{%s}contactInfo" % ns['sml']) if not phonetag == False: phone = et.SubElement(contactInfo, "{%s}phone" % ns['sml']) if not c["voice"] == "": voice = et.SubElement(phone, "{%s}voice" % ns['sml']) voice.text = c["voice"] if not c["fax"] == "": facsimile = et.SubElement( phone, "{%s}facsimile" % ns['sml']) facsimile.text = c["fax"] if not addresstag == False: address = et.SubElement(contactInfo, "{%s}address" % ns['sml']) if not c["deliveryPoint"] == "": deliveryPoint = et.SubElement( address, "{%s}deliveryPoint" % ns['sml']) deliveryPoint.text = c["deliveryPoint"] if not c["city"] == "": city = et.SubElement(address, "{%s}city" % ns['sml']) city.text = c["city"] if not c["administrativeArea"] == "": administrativeArea = et.SubElement( address, "{%s}administrativeArea" % ns['sml']) administrativeArea.text = c["administrativeArea"] if not c["postalcode"] == "": postalCode = et.SubElement( address, "{%s}postalCode" % ns['sml']) postalCode.text = c["postalcode"] if not c["country"] == "": country = et.SubElement(address, "{%s}country" % ns['sml']) country.text = c["country"] if not c["email"] == "": electronicMailAddress = et.SubElement( address, "{%s}electronicMailAddress" % ns['sml']) electronicMailAddress.text = c["email"] if not onlineResourcetag == False: onlineResource = et.SubElement( contactInfo, "{%s}onlineResource" % ns['sml']) onlineResource.attrib["{%s}href" % ns['xlink']] = c["web"] #--- System Documentation if ("documentation" in self.data) and (not self.data["documentation"] == []): system.append(et.Comment("System Documentation")) for d in self.data["documentation"]: documentation = et.SubElement(system, "{%s}documentation" % ns['sml']) Document = et.SubElement(documentation, "{%s}Document" % ns['sml']) description = et.SubElement(Document, "{%s}description" % ns['gml']) description.text = d["description"] if not d["date"] == "": date = et.SubElement(Document, "{%s}date" % ns['sml']) date.text = d["date"] if not d["format"] == "": format = et.SubElement(Document, "{%s}format" % ns['sml']) format.text = d["format"] onlineResource = et.SubElement( Document, "{%s}onlineResource" % ns['sml']) onlineResource.attrib["{%s}href" % ns['xlink']] = d["link"] #--- System Location system.append(et.Comment("System Location")) location = et.SubElement(system, "{%s}location" % ns['sml']) for item in self.data["classification"]: if item["name"] == "System Type": if item["value"].find("mobile") > 0: location.attrib["{%s}role" % ns[ 'xlink']] = "urn:ogc:def:dataType:x-istsos:1.0:lastPosition" Point = et.SubElement(location, "{%s}Point" % ns['gml']) if ut.valid_NCName(self.data["location"]["properties"]["name"]): Point.attrib[ "{%s}id" % ns['gml']] = self.data["location"]["properties"]["name"] else: raise Exception( "Invalid location name '%s' (gml:id only allows alphanumeric characters)" % self.data["location"]["properties"]["name"]) Point.attrib["srsName"] = "EPSG:" + str( self.data["location"]["crs"]["properties"]["name"]) coordinates = et.SubElement(Point, "{%s}coordinates" % ns['gml']) coordinates.text = ",".join( [str(a) for a in self.data["location"]["geometry"]["coordinates"]]) #--- System Interfaces if ("interfaces" in self.data) and (not self.data["interfaces"] == ""): system.append(et.Comment("System Interfaces")) interfaces = et.SubElement(system, "{%s}interfaces" % ns['sml']) InterfaceList = et.SubElement(interfaces, "{%s}InterfaceList" % ns['sml']) for i in self.data["interfaces"].split(","): interface = et.SubElement(InterfaceList, "{%s}interface" % ns['sml']) interface.attrib["name"] = i #--- System Inputs # Not yet supported in waAdmin !! if ("inputs" in self.data) and (not self.data["inputs"] == []): system.append(et.Comment("System Inputs")) inputs = et.SubElement(system, "{%s}inputs" % ns['sml']) InputList = et.SubElement(inputs, "{%s}InputList" % ns['sml']) for inp in self.data["inputs"]: inputml = et.SubElement(InputList, "{%s}input" % ns['sml']) inputml.attrib["name"] = inp["name"] Quantity = et.SubElement(inputml, "{%s}Quantity" % ns['swe']) Quantity.attrib["definition"] = inp["definition"] if not inp["description"] == "": description = et.SubElement(Quantity, "{%s}description" % ns['gml']) description.text = inp["description"] #--- System Outputs timetag = False system.append(et.Comment("System Outputs")) outputs = et.SubElement(system, "{%s}outputs" % ns['sml']) OutputList = et.SubElement(outputs, "{%s}OutputList" % ns['sml']) output = et.SubElement(OutputList, "{%s}output" % ns['sml']) output.attrib["name"] = "output data" DataRecord = et.SubElement(output, "{%s}DataRecord" % ns['swe']) DataRecord.attrib[ "definition"] = "urn:ogc:def:dataType:x-istsos:1.0:timeSeries" oid = 0 for o in self.data["outputs"]: oid += 1 field = et.SubElement(DataRecord, "{%s}field" % ns['swe']) field.attrib["name"] = o["name"] if o["name"] == "Time": timetag = True item = et.SubElement(field, "{%s}Time" % ns['swe']) item.attrib["{%s}id" % ns['gml']] = "IDT_" + str(oid) item.attrib["definition"] = o["definition"] if not o["description"] == "": description = et.SubElement(item, "{%s}description" % ns['gml']) description.text = o["description"] uom = et.SubElement(item, "{%s}uom" % ns['swe']) uom.attrib["code"] = o["uom"] # The constraint object is not mandatory if "constraint" in o and o[ "constraint"] != {}: # and o["constraint"]["role"]!="" and o["constraint"]["role"]!=None: constraint = et.SubElement(item, "{%s}constraint" % ns['swe']) # Role attribute is not mandatory if "role" in o["constraint"] and o["constraint"][ "role"] != "" and o["constraint"]["role"] != None: constraint.attrib[ "{%s}role" % ns['xlink']] = o["constraint"]["role"] AllowedTimes = et.SubElement( constraint, "{%s}AllowedTimes" % ns['swe']) interval = et.SubElement(AllowedTimes, "{%s}interval" % ns['swe']) interval.text = " ".join( [str(a) for a in o["constraint"]["interval"]]) else: item = et.SubElement(field, "{%s}Quantity" % ns['swe']) item.attrib["{%s}id" % ns['gml']] = "IDQ_" + str(oid) item.attrib["definition"] = o["definition"] if not o["description"] == "": description = et.SubElement(item, "{%s}description" % ns['gml']) description.text = o["description"] uom = et.SubElement(item, "{%s}uom" % ns['swe']) uom.attrib["code"] = o["uom"] # The constraint object is not mandatory if "constraint" in o and o[ "constraint"] != {}: # and o["constraint"]["role"]!="" and o["constraint"]["role"]!=None: #print >> sys.stderr, o['constraint'] try: ut.validateJsonConstraint(o['constraint']) except Exception as ex: raise Exception( "Constraint for observed property '%s' is not valid: %s" % (o["definition"], ex)) constraint = et.SubElement(item, "{%s}constraint" % ns['swe']) # Role attribute is not mandatory if "role" in o["constraint"] and o["constraint"][ "role"] != "" and o["constraint"]["role"] != None: constraint.attrib[ "{%s}role" % ns['xlink']] = o["constraint"]["role"] AllowedValues = et.SubElement( constraint, "{%s}AllowedValues" % ns['swe']) # Factory on constraint min/max/interval/valuelist if "interval" in o["constraint"]: interval = et.SubElement(AllowedValues, "{%s}interval" % ns['swe']) interval.text = " ".join( [str(a) for a in o["constraint"]["interval"]]) elif "valueList" in o[ "constraint"]: #.has_key("valueList"): valueList = et.SubElement(AllowedValues, "{%s}valueList" % ns['swe']) valueList.text = " ".join( [str(a) for a in o["constraint"]["valueList"]]) elif "min" in o["constraint"]: #.has_key("min"): amin = et.SubElement(AllowedValues, "{%s}min" % ns['swe']) amin.text = str(o["constraint"]["min"]) elif "max" in o["constraint"]: #.has_key("max"): amax = et.SubElement(AllowedValues, "{%s}max" % ns['swe']) amax.text = str(o["constraint"]["max"]) if timetag == False: raise Exception("self.data['outputs']: Time is mandatory") #--- System History if ("history" in self.data) and (not self.data["history"] == []): system.append(et.Comment("System History")) history = et.SubElement(system, "{%s}history" % ns['sml']) EventList = et.SubElement(history, "{%s}EventList" % ns['sml']) for h in self.data["history"]: member = et.SubElement(EventList, "{%s}member" % ns['sml']) member.attrib["name"] = h["type"] Event = et.SubElement(member, "{%s}Event" % ns['sml']) date = et.SubElement(Event, "{%s}date" % ns['sml']) date.text = h["date"] if not h["description"] == "": description = et.SubElement(Event, "{%s}description" % ns['gml']) description.text = h["description"] contact = et.SubElement(Event, "{%s}contact" % ns['sml']) contact.attrib["{%s}href" % ns['xlink']] = h["reference"]["username"] contact.attrib["{%s}arcrole" % ns['xlink']] = h["reference"]["role"] return et.tostring(root, encoding="UTF-8")