Example #1
0
    def create_get_variable_info_response(self, varArg=None):

        if (varArg is None or varArg == ''):
            variableResultArr = self.dao.get_all_variables()
        else:
            varCodesArr = varArg.split(',')
            varCodesArr = [self.get_variable_code(v) for v in varCodesArr]
            variableResultArr = self.dao.get_variables_by_codes(varCodesArr)

        variableInfoResponse = WaterML.VariablesResponseType()

        # TODO: Should queryInfo be in thois response?  Suds doesn't
        # like when it is.  If it should be in the response, then the
        # WSDL needs to be updated

        queryInfo = WaterML.QueryInfoType()
        criteria = WaterML.criteriaType(MethodCalled='GetVariableInfo')
        if varArg is not None:
            pType_var = WaterML.parameterType(name='variable', value=varArg)
            criteria.add_parameter(pType_var)
        queryInfo.set_criteria(criteria)
        queryInfoNote = WaterML.NoteType('Web Service')
        queryInfo.add_note(queryInfoNote)
        # queryInfo.set_extension('')
        variableInfoResponse.set_queryInfo(queryInfo)

        variables = WaterML.variablesType()
        for variableResult in variableResultArr:
            v = self.create_variable_element(variableResult)
            variables.add_variable(v)
        variableInfoResponse.set_variables(variables)
        return variableInfoResponse
Example #2
0
    def create_get_variable_info_response(self, varArg=None):

        # Flavio:
        # Creates in variableResultArr an array of Variable objects,
        # corresponding to an array of variables in varCodesArr
        # or all variables if no array
        if (varArg is None or varArg == ''):
            variableResultArr = self.dao.get_all_variables()
        else:
            varCodesArr = varArg.split(',')
            varCodesArr = [self.get_variable_code(v) for v in varCodesArr]
            variableResultArr = self.dao.get_variables_by_codes(varCodesArr)

        # Flavio: Creates a VariablesResponseType object (variableInfoResponse)
        variableInfoResponse = WaterML.VariablesResponseType()

        # TODO: Should queryInfo be in thois response?  Suds doesn't
        # like when it is.  If it should be in the response, then the
        # WSDL needs to be updated

        # Flavio: Creates a QueryInfoType object (queryInfo)
        queryInfo = WaterML.QueryInfoType()
        # Flavio: creates a criteriaType object (criteria) with GetVariableInfo as
        #         MethodCalled; if not None, adds varArg as a variable parameter
        #         sets the criteria of queryInfo to criteria
        #         and sets the queryInfo of variableInfoResponse to queryInfo
        criteria = WaterML.criteriaType(MethodCalled='GetVariableInfo')
        if varArg is not None:
            pType_var = WaterML.parameterType(name='variable', value=varArg)
            criteria.add_parameter(pType_var)
        queryInfo.set_criteria(criteria)
        queryInfoNote = WaterML.NoteType('Web Service')
        queryInfo.add_note(queryInfoNote)
        logging.debug('create_get_variable_info_response: queryInfo created')
        # queryInfo.set_extension('')
        variableInfoResponse.set_queryInfo(queryInfo)

        # Flavio: creates a variablesType element (variables)
        #         adds to it every variable in variableResultArr,
        #         sets it to variableInfoResponse and returns
        #         variableInfoResponse
        variables = WaterML.variablesType()
        for v in variableResultArr:
            logging.debug('VariableID: {!s}, VariableCode: {!s}, '.format(
                v.VariableID, v.VariableCode) +
                          'VariableName: {!s}, VariableUnitsID: {!s}, '.format(
                              v.VariableName, v.VariableUnitsID) +
                          'SampleMedium: {!s}, ValueType: {!s}, '.format(
                              v.SampleMedium, v.ValueType) +
                          'IsRegular: {!s}, TimeSupport: {!s}, '.format(
                              v.IsRegular, v.TimeSupport) +
                          'TimeUnitsID: {!s}, DataType: {!s}, '.format(
                              v.TimeUnitsID, v.DataType) +
                          'GeneralCategory: {!s}, NoDataValue: {!s}'.format(
                              v.GeneralCategory, v.NoDataValue))
        for variableResult in variableResultArr:
            v = self.create_variable_element(variableResult)
            logging.debug(
                'create_get_variable_info_response: variable {!s} created'.
                format(variableResult.VariableCode))
            variables.add_variable(v)
        logging.debug('create_get_variable_info_response: variables created')
        variableInfoResponse.set_variables(variables)
        return variableInfoResponse