Ejemplo n.º 1
0
 def soap_GetVariableInfo(self, ps):
     """
     implementation of the "GetVariableInfo" operation
     """
     try:
         rsp = WaterOneFlow.soap_GetVariableInfo(self,ps)
         request = self.request
         variableCodeArray = map(str, request.get_element_variable().split(":"))
         #if pass in empty string, show info of all variables
         variablesNode = variables()
         #for the variable list
         variableList = []
         if variableCodeArray == [""]:
             for key in variable_Dictionary.keys():
                 #notice here the protocol of function generateVariableTypeNodeString
                 variableList.append(generateVariableTypeNodeString(key,variable_Dictionary[key]))
         elif not variableCodeArray[0].upper()=="CBI"  or not variable_Dictionary.has_key(variableCodeArray[1]) \
                 or len(variableCodeArray) != 2:
             fault = Fault(Fault.Client, "Illegal variableCode", actor="variableCode", detail="variable code \"%s\" is illegal/not found" % ":".join(variableCodeArray))
             raise fault
         elif variable_Dictionary.has_key(variableCodeArray[1]):
             variableList.append(generateVariableTypeNodeString(variableCodeArray[1],variable_Dictionary[variableCodeArray[1]]))
         #here, to decide if queryInfo required 
         variablesNode.set_variable(variableList)
         variableResponseNode = VariablesResponseType()
         variableResponseNode.set_variables(variablesNode)     
         #actual xml string
         variableResponseString = cStringIO.StringIO()
         #                                
         variableResponseNode.export(variableResponseString, 0, \
                                  namespacedef_=' '.join(['xmlns:gml="http://www.opengis.net/gml"',
                                                'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"',
                                                'xmlns:xlink="http://www.w3.org/1999/xlink"',
                                                'xmlns:wtr="http://www.cuahsi.org/waterML/"',
                                                'xmlns:xsd="http://www.w3.org/2001/XMLSchema"',
                                                'xmlns="http://www.cuahsi.org/waterML/1.0/"']))
         rsp.set_element_GetVariableInfoResult(variableResponseString.getvalue())
     #here, how to generate a fault!!!           
     except Exception, e:
         import traceback
         traceback.print_exc(file=sys.stdout) 
         if isinstance(e,Fault):
             detail = None
             if e.detail is not None: 
                 detail = Detail()
                 detail.any = e.detail            
             rsp = FaultType(e.code, e.string, e.actor, detail)
Ejemplo n.º 2
0
 def soap_GetVariableInfoObject(self, ps):
     """
     implementation of the "GetVariableInfo" operation
     """
     try:
         #this code is just for deploying on apache
         #httpReq = kw['request']
         rsp = WaterOneFlow.soap_GetVariableInfoObject(self,ps)
         request = self.request            
         variableCodeArray = map(str, request.get_element_variable().split(":"))
         variableResponseNode=rsp.new_variablesResponse()
         variablesNode = variableResponseNode.new_variables()
         variableList = []             
         if variableCodeArray == [""]:
             for key in variable_Dictionary.keys():
                 variableNode = variablesNode.new_variable()
                 variableList.append(generateVariableTypeNode(variableNode,key,variable_Dictionary[key]))
         elif not variableCodeArray[0].upper()=="CBI"  or not variable_Dictionary.has_key(variableCodeArray[1]) \
                 or len(variableCodeArray) != 2:
             fault = Fault(Fault.Client, "Illegal variableCode", actor="variableCode", detail="variable code \"%s\" is illegal/not found" % ":".join(variableCodeArray))
             raise fault
         elif variable_Dictionary.has_key(variableCodeArray[1]):
             variableNode = variablesNode.new_variable()
             variableList.append(generateVariableTypeNode(variableNode,variableCodeArray[1],variable_Dictionary[variableCodeArray[1]]))
         variablesNode.set_element_variable(variableList)
         variableResponseNode.set_element_variables(variablesNode)
         rsp.set_element_variablesResponse(variableResponseNode)
     #here, how to generate a fault!!!           
     except Exception, e:
         import traceback
         traceback.print_exc(file=sys.stdout) 
         if isinstance(e,Fault):
             detail = None
             if e.detail is not None: 
                 detail = Detail()
                 detail.any = e.detail            
             rsp = FaultType(e.code, e.string, e.actor, detail)
Ejemplo n.º 3
0
 def soap_GetValuesObject(self, ps):
     """
     implementation of the "GetValues" operation
     """
     try:
         #this code is just for deploying on apache
         #httpReq = kw['request']
         rsp = WaterOneFlow.soap_GetValuesObject(self,ps)
         request = self.request 
         #get input variable
         siteCodeUnicodeStr = request.get_element_location()
         variableCodeUnicodStr = request.get_element_variable()
         startDate = request.get_element_startDate()
         endDate = request.get_element_endDate()
         #construct/renew the siteInfo_site_dictionary.
         #currently, renew it every 14 days (subject to change)?
         if(len(siteInfo_site_dictionary.keys())==1 or 
                 datetime.now() >= siteInfo_site_dictionary["__modTime"] + timedelta(days=14)):
             #here has a possible race condition, so a lock is placed
             semaphore = open('/home/txhis/CBIService/semaphore/semaphore.file', "w")
             lock(semaphore, LOCK_EX)
             treeIter = getIterator(centralRegUrl)
             #save the srs information in dictionary
             buildSiteInfo_siteDictionary(treeIter,siteInfo_site_dictionary)
             siteInfo_site_dictionary["__modTime"]=datetime.now()
             #close semaphore, release the lock file. (otherwise deadlock will be possible)
             semaphore.close()
         #some basic error checking
         #validity of siteCode:
         siteCodeArray = map(str,siteCodeUnicodeStr.split(":"))
         if  len(siteCodeArray) < 2 or\
                 not siteInfo_site_dictionary.has_key(siteCodeArray[1]) or \
                 not siteCodeArray[0].upper() == "CBI":
             fault = Fault(Fault.Client, "Illegal SiteCode", actor="SiteCode", detail="site code \"%s\" is illegal/not found" % ":".join(siteCodeArray))
             raise fault
         #check validity of variableCode
         variableCodeArray = map(str, variableCodeUnicodStr.split(":"))
         if  len(variableCodeArray) < 2 or\
                 not variable_Dictionary.has_key(variableCodeArray[1]) or \
                 not variableCodeArray[0].upper() == "CBI":
             fault = Fault(Fault.Client, "Illegal VariableCode", actor="Variable", detail="variable code \"%s\" is illegal/not found" % ":".join(variableCodeArray))
             raise fault
         #preprocessing passing-in time
         if startDate == "":
             startDate = (datetime.now()-timedelta(years=float(100))).isoformat()
         if endDate == "":
             endDate = datetime.now().isoformat()              
         #time format validation
         try:
             time.strptime(startDate,"%Y-%m-%d")
             time.strptime(endDate,"%Y-%m-%d")
         except:
             fault = Fault(Fault.Client, "Illegal start/end Date", actor="startDate/endDate", \
                               detail="The format of starDate/endDate string is illegal, please use format 'YYYY-MM-DDTHH:MM:S'(CST timezone) error startDate: %s   erro endDate: %s " %(startDate,endDate))
             raise fault
         ##################################################################################################################################################
         #timeSeries type
         timeSeriesResponseNode = rsp.new_timeSeriesResponse()
         #generate return XML info
         queryInfoNode = timeSeriesResponseNode.new_queryInfo()
         #here, set creation time in ZULU zone
         #get the UTC time for now
         nowTime = datetime.now()+ timedelta(hours=float(6))
         strNowTime = "".join(["T".join(str(nowTime)[:str(nowTime).index(".")].split()),"Z"])
         queryInfoNode.set_element_creationTime(strNowTime)
         queryInfoNode.set_element_queryURL(getCBIURLqueryString(siteCodeArray[1],variableCodeArray[1],startDate,endDate))
         #criteria Node
         criteriaNode = queryInfoNode.new_criteria()
         criteriaNode.set_element_locationParam(":".join(siteCodeArray))
         criteriaNode.set_element_variableParam(":".join(variableCodeArray))
         #time parameter
         timeParamNode = criteriaNode.new_timeParam()
         timeParamNode.set_element_beginDateTime(startDate)
         timeParamNode.set_element_endDateTime(endDate)
         criteriaNode.set_element_timeParam(timeParamNode)
         queryInfoNode.set_criteria(criteriaNode)
         timeSeriesResponseNode.set_element_queryInfo(queryInfoNode)
         #time series node
         timeSeriesNode = timeSeriesResponseNode.new_timeSeries()
         #.......................................................
         rsp.set_element_timeSeriesResponse(timeSeriesResponseNode)
     except Exception, e:
         import traceback
         traceback.print_exc(file=sys.stdout) 
         if isinstance(e,Fault):
             detail = None
             if e.detail is not None: 
                 detail = Detail()
                 detail.any = e.detail            
             rsp = FaultType(e.code, e.string, e.actor, detail)
Ejemplo n.º 4
0
 def soap_GetValues(self,ps):
     """
     implementation of the "GetValues" operation
     """
     try:
         #this code is just for deploying on apache
         #httpReq = kw['request']
         rsp = WaterOneFlow.soap_GetValues(self,ps)
         request = self.request 
         #get input variable
         siteCodeUnicodeStr = request.get_element_location()
         variableCodeUnicodStr = request.get_element_variable()
         startDate = request.get_element_startDate()
         endDate = request.get_element_endDate()
         #construct/renew the siteInfo_site_dictionary.
         #currently, renew it every 14 days (subject to change)?
         if(len(siteInfo_site_dictionary.keys())==1 or 
                 datetime.now() >= siteInfo_site_dictionary["__modTime"] + timedelta(days=14)):
             #here has a possible race condition, so a lock is placed
             semaphore = open('/home/txhis/CBIService/semaphore/semaphore.file', "w")
             lock(semaphore, LOCK_EX)
             treeIter = getIterator(centralRegUrl)
             #save the srs information in dictionary
             buildSiteInfo_siteDictionary(treeIter,siteInfo_site_dictionary)
             siteInfo_site_dictionary["__modTime"]=datetime.now()
             #close semaphore, release the lock file. (otherwise deadlock will be possible)
             semaphore.close()
         #some basic error checking
         #validity of siteCode:
         siteCodeArray = map(str,siteCodeUnicodeStr.split(":"))
         if  len(siteCodeArray) < 2 or\
                 not siteInfo_site_dictionary.has_key(siteCodeArray[1]) or \
                 not siteCodeArray[0].upper() == "CBI":
             fault = Fault(Fault.Client, "Illegal SiteCode", actor="SiteCode", detail="site code \"%s\" is illegal/not found" % ":".join(siteCodeArray))
             raise fault
         #check validity of variableCode
         variableCodeArray = map(str, variableCodeUnicodStr.split(":"))
         if  len(variableCodeArray) < 2 or\
                 not variable_Dictionary.has_key(variableCodeArray[1]) or \
                 not variableCodeArray[0].upper() == "CBI":
             fault = Fault(Fault.Client, "Illegal VariableCode", actor="Variable", detail="variable code \"%s\" is illegal/not found" % ":".join(variableCodeArray))
             raise fault
         #preprocessing passing-in time
         if startDate == "":
             startDate = (datetime.now()-timedelta(years=float(100))).__str__()
         if endDate == "":
             endDate = datetime.now().__str__()              
         #time format validation
         try:
             time.strptime(startDate,"%Y-%m-%d")
             time.strptime(endDate,"%Y-%m-%d")
         except:
             fault = Fault(Fault.Client, "Illegal start/end Date", actor="startDate/endDate", \
                               detail="The format of starDate/endDate string is illegal, please use format 'YYYY-MM-DD HH:MM:S'(CST timezone) error startDate: %s   erro endDate: %s " %(startDate,endDate))
             raise fault
         ##################################################################################################################################################
         #timeSeries type
         timeSeriesResponseNode = TimeSeriesResponseType()
         #generate return XML info
         queryInfoNode = QueryInfoType()
         #here, set creation time in ZULU zone
         #get the UTC time for now
         nowTime = datetime.now()+ timedelta(hours=float(6))
         strNowTime = "".join(["T".join(str(nowTime)[:str(nowTime).index(".")].split()),"Z"])
         queryInfoNode.set_creationTime(strNowTime)
         queryInfoNode.set_queryURL(getCBIURLqueryString(siteCodeArray[1],variableCodeArray[1],startDate,endDate))
         #criteria Node
         criteriaNode = criteria()
         criteriaNode.set_locationParam(":".join(siteCodeArray))
         criteriaNode.set_variableParam(":".join(variableCodeArray))
         #time parameter
         timeParamNode = timeParam()
         timeParamNode.set_beginDateTime(startDate)
         timeParamNode.set_endDateTime(endDate)
         criteriaNode.set_timeParam(timeParamNode)
         queryInfoNode.set_criteria(criteriaNode)
         timeSeriesResponseNode.set_queryInfo(queryInfoNode)
         #time series node
         timeSeriesNode = TimeSeriesType()
         SourceInfoType.subclass = SiteInfoType
         sourceInfoNode = SourceInfoType.factory()
         sourceInfoNode.set_siteName(siteInfo_site_dictionary[siteCodeArray[1]][0].strip())
         #get any of the xmlNode
         xmlNode = siteInfo_site_dictionary[siteCodeArray[1]][1][0]
         #set site code
         siteCodeNode = siteCode()
         siteCodeNode.set_network("CBI")
         siteCodeNode.set_siteID(xmlNode[4].text.split(":")[0])
         siteCodeNode.setValueOf_(xmlNode[4].text.split(":")[0])
         sourceInfoNode.set_siteCode([siteCodeNode])
         ##
         timeZoneInfoNode = timeZoneInfo()
         timeZoneInfoNode.set_defaultTimeZone("CST")
         timeZoneInfoNode.set_daylightSavingsTimeZone("Unkown")
         sourceInfoNode.set_timeZoneInfo(timeZoneInfoNode)
         #set geolocation
         geoLocationNode = geoLocation()
         #set inner geoglocation
         GeogLocationType.subclass=LatLonPointType
         innerGeoLocationNode = GeogLocationType.factory()
         innerGeoLocationNode.set_srs(siteInfo_site_dictionary['srs'])
         innerGeoLocationNode.set_latitude(xmlNode[5][0][0].text.split()[0])
         innerGeoLocationNode.set_longitude(xmlNode[5][0][0].text.split()[1])
         geoLocationNode.set_geogLocation(innerGeoLocationNode)
         #set node here         
         sourceInfoNode.set_geoLocation(geoLocationNode)
         sourceInfoNode.set_verticalDatum(xmlNode[7].text)
         #countyNote = NoteType(title='County',valueOf_=':'.join(["CBI","Coastal Water Data"]))
         stateNote = NoteType(title='State',valueOf_='Texas')
         commentNote = NoteType(title='Comment',valueOf_=xmlNode[15].text)
         sourceInfoNode.set_note([stateNote,commentNote])
         timeSeriesNode.set_sourceInfo(sourceInfoNode)
         ###################################################
         #variable node
         variableNode = generateVariableTypeNodeString(variableCodeArray[1],variable_Dictionary[variableCodeArray[1]])
         timeSeriesNode.set_variable(variableNode)
         #values node
         try:
             valuesNode=generateSeriesValueList(siteCodeArray[1],variableCodeArray[1],startDate,endDate)
             timeSeriesNode.set_values(valuesNode)
         except:
             fault = Fault(Fault.Client, "Bad requirement", actor="input_parameters", \
                               detail="Invalid input parameters.Please chek the input parameters: (sitecode, variablecode, startdate, enddate)")
             raise fault
         #################           
         timeSeriesResponseNode.set_timeSeries(timeSeriesNode) 
         #actual xml string
         timeSeriesResponseString = cStringIO.StringIO()
         #export the xml string                                 
         timeSeriesResponseNode.export(timeSeriesResponseString, 0, \
                                  namespacedef_=' '.join(['xmlns:gml="http://www.opengis.net/gml"',
                                                'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"',
                                                'xmlns:xlink="http://www.w3.org/1999/xlink"',
                                                'xmlns:wtr="http://www.cuahsi.org/waterML/"',
                                                'xmlns:xsd="http://www.w3.org/2001/XMLSchema"',
                                                'xmlns="http://www.cuahsi.org/waterML/1.0/"']))
         print timeSeriesResponseString.getvalue()
         rsp.set_element_GetValuesResult(timeSeriesResponseString.getvalue())                                      
     #here, how to generate a fault!!!           
     except Exception, e:
         import traceback
         traceback.print_exc(file=sys.stdout) 
         if isinstance(e,Fault):
             detail = None
             if e.detail is not None: 
                 detail = Detail()
                 detail.any = e.detail            
             rsp = FaultType(e.code, e.string, e.actor, detail)