def executeGet(self):
     if self.servicename == "default":
         raise Exception("getlist operation can not be done for default service instance.")
     else:
         data = []
         servicedb = databaseManager.PgDB(self.serviceconf.connection['user'],
                                         self.serviceconf.connection['password'],
                                         self.serviceconf.connection['dbname'],
                                         self.serviceconf.connection['host'],
                                         self.serviceconf.connection['port']
         )
         proceduresList = utils.getProcedureNamesList(servicedb,self.servicename,observationType='virtual')
         for proc in proceduresList:
             elem = {}
             elem.update(proc)
             #elem["name"] = proc["name"]
             ops = utils.getObservedPropertiesFromProcedure(servicedb,self.servicename,proc["name"])
             if ops != None:
                 elem["observedproperties"] = [ {"name" : op["name"], "uom" : op["uom"]  } for op in ops ]
             else:
                 elem["observedproperties"] = []
             offs = utils.getOfferingsFromProcedure(servicedb,self.servicename,proc["name"])
             if offs != None:
                 elem["offerings"] = [ off["name"] for off in offs ]
             else:
                 elem["offerings"] = []
             data.append(elem)
         
         self.setData(data)
         self.setMessage("Procedures of service <%s> successfully retrived" % self.servicename)
Exemple #2
0
 def executeGet(self):
     if self.service == "default":
         raise Exception("offerings operation can not be done for 'default' service instance.")
     else:
         dbm = databaseManager.PgDB(self.serviceconf.connection['user'],
             self.serviceconf.connection['password'],
             self.serviceconf.connection['dbname'],
             self.serviceconf.connection['host'],
             self.serviceconf.connection['port']
         )
         data = []
         procs = utils.getProcedureNamesList(dbm,self.service,self.offering)
         for proc in procs:
             elem = {}
             elem["name"] = proc["name"]
             ops = utils.getObservedPropertiesFromProcedure(dbm,self.service,proc["name"])
             if ops != None:
                 elem["observedproperties"] = [ {"name" : op["name"], "uom" : op["uom"]  } for op in ops ]
             else:
                 elem["observedproperties"] = []
             offs = utils.getOfferingsFromProcedure(dbm,self.service,proc["name"])
             if offs != None:
                 elem["offerings"] = [ off["name"] for off in offs ]
             else:
                 elem["offerings"] = []
             data.append(elem)
         self.setData(data)
         self.setMessage("Offerings names of service <%s> successfully retrived" % self.service)
Exemple #3
0
    def executeGet(self):
        if self.servicename == "default":
            raise Exception("getlist operation can not be done for default service instance.")
        else:
            data = []
            servicedb = databaseManager.PgDB(self.serviceconf.connection['user'],
                                            self.serviceconf.connection['password'],
                                            self.serviceconf.connection['dbname'],
                                            self.serviceconf.connection['host'],
                                            self.serviceconf.connection['port']
            )
            proceduresList = utils.getProcedureNamesList(servicedb,self.servicename,observationType='virtual')
            for proc in proceduresList:
                elem = {}
                elem.update(proc)
                #elem["name"] = proc["name"]
                ops = utils.getObservedPropertiesFromProcedure(servicedb,self.servicename,proc["name"])
                if ops != None:
                    elem["observedproperties"] = [ {"name" : op["name"], "uom" : op["uom"]  } for op in ops ]
                else:
                    elem["observedproperties"] = []
                offs = utils.getOfferingsFromProcedure(servicedb,self.servicename,proc["name"])
                if offs != None:
                    elem["offerings"] = [ off["name"] for off in offs ]
                else:
                    elem["offerings"] = []
                data.append(elem)

            self.setData(data)
            self.setMessage("Procedures of service <%s> successfully retrived" % self.servicename)
Exemple #4
0
    def __getLastObservation(self, servicedb, procedureName):
        """
            request the last observation
        """
        opList = utils.getObservedPropertiesFromProcedure(
            servicedb, self.service, procedureName)
        name = ""

        for op in opList:
            name += op['name'] + ","

        offering = utils.getOfferingsFromProcedure(servicedb, self.service,
                                                   procedureName)

        # request the last observation of the procedure
        rparams = {
            "request": "GetObservation",
            "service": "SOS",
            "version": "1.0.0",
            "procedure": procedureName,
            "observedProperty": name,
            "responseFormat": "application/json",
            "offering": offering[0]['name']
        }

        import requests as requests

        headers = {}
        if 'HTTP_AUTHORIZATION' in self.waEnviron:
            headers['Authorization'] = self.waEnviron['HTTP_AUTHORIZATION']

        response = requests.get(self.serviceconf.serviceurl["url"],
                                params=rparams,
                                headers=headers)

        dataArray = response.json(
        )['ObservationCollection']['member'][0]['result']['DataArray']
        # Value field
        data = []
        if not len(dataArray['values']) == 0:
            # last vaue field
            lastValue = dataArray['values'][0]
            # op and uom fileds
            field = dataArray['field']
            for i in range(1, len(lastValue)):
                data.append({
                    "values": lastValue[i],
                    "op": field[i]['name'],
                    "uom": field[i]['uom']
                })

        return data
Exemple #5
0
    def executeGet(self):
        if self.servicename == "default":
            raise Exception("getlist operation can not be done for "
                            "default service instance.")
        else:
            data = []
            servicedb = databaseManager.PgDB(
                self.serviceconf.connection['user'],
                self.serviceconf.connection['password'],
                self.serviceconf.connection['dbname'],
                self.serviceconf.connection['host'],
                self.serviceconf.connection['port'])
            if self.waEnviron['parameters'] and (
                    'tzoffset' in self.waEnviron['parameters']):
                tzoffset = self.waEnviron['parameters']['tzoffset'][0]
                servicedb.setTimeTZ(tzoffset)

            proceduresList = utils.getProcedureNamesList(
                servicedb, self.servicename)

            for proc in proceduresList:
                elem = {}
                elem.update(proc)
                ops = utils.getObservedPropertiesFromProcedure(
                    servicedb, self.servicename, proc["name"])
                if ops is not None:
                    elem["observedproperties"] = [{
                        "name": op["name"],
                        "uom": op["uom"]
                    } for op in ops]

                else:
                    elem["observedproperties"] = []

                offs = utils.getOfferingsFromProcedure(servicedb,
                                                       self.servicename,
                                                       proc["name"])

                if offs is not None:
                    elem["offerings"] = [off["name"] for off in offs]

                else:
                    elem["offerings"] = []

                data.append(elem)

            self.setData(data)
            self.setMessage(
                "Procedures of service <%s> successfully retrived" %
                (self.servicename))
Exemple #6
0
    def __getLastObservation(self, servicedb, procedureName):
        """
            request the last observation
        """
        opList = utils.getObservedPropertiesFromProcedure(servicedb,self.service,procedureName)
        name = ""

        for op in opList:
            name += op['name'] + ","

        offering = utils.getOfferingsFromProcedure(servicedb,self.service,procedureName)

        # request the last observation of the procedure
        rparams = {
            "request": "GetObservation",
            "service": "SOS",
            "version": "1.0.0",
            "procedure": procedureName,
            "observedProperty": name,
            "responseFormat": "application/json",
            "offering": offering[0]['name']
        }

        import lib.requests as requests
        response = requests.get(
            self.serviceconf.serviceurl["url"],
            params=rparams
        )

        dataArray = response.json()['ObservationCollection']['member'][0]['result']['DataArray']
        # Value field
        data = []
        if not len(dataArray['values']) == 0:
            # last vaue field
            lastValue = dataArray['values'][0]
            # op and uom fileds
            field = dataArray['field']
            for i in range(1, len(lastValue)):
                data.append(
                    {
                        "values": lastValue[i],
                        "op": field[i]['name'],
                        "uom": field[i]['uom']
                    }
                )

        return data
Exemple #7
0
    def executeGet(self):
        if self.service == "default":
            raise Exception("getlist operation can not be done for "
                            "default service instance.")

        else:
            try:
                data = {"type": "FeatureCollection", "features": []}

                servicedb = databaseManager.PgDB(
                    self.serviceconf.connection['user'],
                    self.serviceconf.connection['password'],
                    self.serviceconf.connection['dbname'],
                    self.serviceconf.connection['host'],
                    self.serviceconf.connection['port'])

                proceduresList = utils.getProcedureNamesList(
                    servicedb,
                    self.service,
                    offering=self.offering,
                    procedure=self.procedure)

                for proc in proceduresList:
                    if proc['samplingTime']['beginposition'] == '':
                        headers = {}
                        if 'HTTP_AUTHORIZATION' in self.waEnviron:
                            headers['Authorization'] = (
                                self.waEnviron['HTTP_AUTHORIZATION'])

                        res = requests.get(self.serviceconf.serviceurl["url"],
                                           params={
                                               "request":
                                               "DescribeSensor",
                                               "procedure":
                                               proc['name'],
                                               "outputFormat":
                                               ("text/xml;"
                                                "subtype=\"sensorML/1.0.1\""),
                                               "service":
                                               "SOS",
                                               "version":
                                               "1.0.0"
                                           },
                                           headers=headers)
                        smlobj = procedure.Procedure()
                        try:
                            smlobj.loadXML(res.content)
                        except Exception as e:
                            print >> sys.stderr, "\n\nSML: %s\n\n" % (
                                res.content)
                            raise Exception(
                                "Error loading DescribeSensor of '%s' "
                                "[STATUS CODE: %s]: %s" %
                                (proc['name'], res.status_code, e))

                        ret = {}
                        ret.update(smlobj.data)

                        if 'constraint' in ret['outputs'][0]:
                            proc['samplingTime']['beginposition'] = (
                                ret['outputs'][0]['constraint']['interval'][0])

                            proc['samplingTime']['endposition'] = (
                                ret['outputs'][0]['constraint']['interval'][1])
                        else:
                            proc['samplingTime']['beginposition'] = ''
                            proc['samplingTime']['endposition'] = ''

                    elem = {}
                    elem.update(proc)
                    ops = utils.getObservedPropertiesFromProcedure(
                        servicedb, self.service, proc["name"])
                    if ops is not None:
                        if self.observedProperty:
                            elem["observedproperties"] = []
                            opPresent = False
                            for op in ops:
                                if self.observedProperty == op["def"]:
                                    opPresent = True
                                elem["observedproperties"].append({
                                    "name":
                                    op["name"],
                                    "def":
                                    op["def"],
                                    "uom":
                                    op["uom"]
                                })
                            if not opPresent:
                                continue

                        else:
                            elem["observedproperties"] = [{
                                "name": op["name"],
                                "def": op["def"],
                                "uom": op["uom"]
                            } for op in ops]

                    else:
                        elem["observedproperties"] = []

                    offs = utils.getOfferingsFromProcedure(
                        servicedb, self.service, proc["name"])
                    if offs is not None:
                        elem["offerings"] = [off["name"] for off in offs]

                    else:
                        elem["offerings"] = []

                    geom = utils.getGeoJSONFromProcedure(
                        servicedb, self.service, proc["name"], self.epsg)
                    if geom is None:
                        continue

                    data["features"].append({
                        "type": "Feature",
                        "geometry": geom,
                        "properties": elem
                    })

                self.setData(data)
            except Exception as e:
                self.setMessage("%s" % e)
Exemple #8
0
    def executeGet(self):
        if self.service == "default":
            raise Exception("getlist operation can not be done for default service instance.")
        else:
            try:
                data = {
                    "type": "FeatureCollection",
                    "features": []
                }
                
                servicedb = databaseManager.PgDB(self.serviceconf.connection['user'],
                                                self.serviceconf.connection['password'],
                                                self.serviceconf.connection['dbname'],
                                                self.serviceconf.connection['host'],
                                                self.serviceconf.connection['port']
                )

                proceduresList = utils.getProcedureNamesList(servicedb,self.service)
                for proc in proceduresList:
                    
                    
                    if proc['samplingTime']['beginposition'] == '':
                        print >> sys.stderr, proc['name']
                        import lib.requests as requests
                        res = requests.get(
                            self.serviceconf.serviceurl["url"],
                            params={
                                "request": "DescribeSensor",
                                "procedure": proc['name'],
                                "outputFormat": "text/xml;subtype=\"sensorML/1.0.1\"",
                                "service": "SOS",
                                "version": "1.0.0"
                            }
                        )

                        smlobj = procedure.Procedure()
                        try:
                            smlobj.loadXML(res.content)
                        except Exception as e:
                            print >> sys.stderr, "\n\nSML: %s\n\n" % res.content
                            raise Exception("Error loading DescribeSensor of '%s' [STATUS CODE: %s]: %s" % (proc['name'],res.status_code,e))
                        ret = {}
                        ret.update(smlobj.data)    

                        proc['samplingTime']['beginposition'] = ret['outputs'][0]['constraint']['interval'][0]
                        proc['samplingTime']['endposition'] = ret['outputs'][0]['constraint']['interval'][1]
                        #print >> sys.stderr, ret['outputs'][0]['constraint']['interval']                    
                    
                    elem = {}
                    elem.update(proc)
                    #elem["name"] = proc["name"]
                    ops = utils.getObservedPropertiesFromProcedure(servicedb,self.service,proc["name"])
                    if ops != None:
                        elem["observedproperties"] = [ {"name" : op["name"], "def" : op["def"], "uom" : op["uom"]  } for op in ops ]
                    else:
                        elem["observedproperties"] = []
                    offs = utils.getOfferingsFromProcedure(servicedb,self.service,proc["name"])
                    if offs != None:
                        elem["offerings"] = [ off["name"] for off in offs ]
                    else:
                        elem["offerings"] = []


                    geom = utils.getGeoJSONFromProcedure(servicedb, self.service,proc["name"], self.epsg)
                    if geom == None:
                        continue

                    data["features"].append({
                        "type": "Feature",
                        "geometry": geom,
                        "properties": elem
                    })

                self.setData(data)
            except Exception as e:
                self.setMessage("%s" % e)