コード例 #1
0
ファイル: atom.py プロジェクト: dkuerner/pycsw
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''

        typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])

        if esn == 'full' and typename == 'atom:entry':
            # dump record as is and exit
            return etree.fromstring(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':  # transform csw:Record -> atom:entry model mappings
            util.transform_mappings(queryables, self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('atom:entry', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s %s?service=CSW&version=2.0.2&request=DescribeRecord&typename=atom:entry' % (self.namespaces['atom'], self.url)

        # author
        val = util.getqattr(result, queryables['atom:author']['dbcol'])
         
        if val:
            etree.SubElement(node, util.nspath_eval('atom:author', self.namespaces)).text = util.getqattr(result, queryables['atom:author']['dbcol'])

        # category
        val = util.getqattr(result, queryables['atom:category']['dbcol'])

        if val:
            for kw in val.split(','):
                etree.SubElement(node, util.nspath_eval('atom:category', self.namespaces)).text = kw


        for qval in ['contributor', 'id']:
            val = util.getqattr(result, queryables['atom:%s' % qval]['dbcol'])
            if val:
                etree.SubElement(node, util.nspath_eval('atom:%s' % qval, self.namespaces)).text = util.getqattr(result, queryables['atom:%s' % qval]['dbcol'])

        rlinks = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Links'])
        if rlinks:
            for link in rlinks.split('^'):
                linkset = link.split(',')
           
                url2 = etree.SubElement(node, util.nspath_eval('atom:link', self.namespaces), href=linkset[-1], type=linkset[2], title=linkset[1])

        etree.SubElement(node, util.nspath_eval('atom:link', self.namespaces), href='%s?service=CSW&version=2.0.2&request=GetRepositoryItem&id=%s' % (self.url, util.getqattr(result, queryables['atom:id']['dbcol'])))

        for qval in ['published', 'rights', 'source', 'summary', 'title', 'updated']:
            val = util.getqattr(result, queryables['atom:%s' % qval]['dbcol'])
            if val:
                etree.SubElement(node, util.nspath_eval('atom:%s' % qval, self.namespaces)).text = util.getqattr(result, queryables['atom:%s' % qval]['dbcol'])

        # bbox extent
        val = util.getqattr(result, queryables['georss:where']['dbcol'])
        bboxel = write_extent(val, self.context.namespaces)
        if bboxel is not None:
            node.append(bboxel)

        return node
コード例 #2
0
ファイル: ebrim.py プロジェクト: amercader/pycsw
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''

        identifier = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Identifier'])
        typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])

        if esn == 'full' and typename == 'rim:RegistryObject':
            # dump record as is and exit
            return etree.fromstring(util.getqattr(result, queryables['pycsw:XML']['dbcol']))

        if typename == 'csw:Record':  # transform csw:Record -> rim:RegistryObject model mappings
            util.transform_mappings(queryables, self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('rim:ExtrinsicObject', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s %s/csw/2.0.2/profiles/ebrim/1.0/csw-ebrim.xsd' % (self.namespaces['wrs'], self.ogc_schemas_base)

        node.attrib['id'] = identifier
        node.attrib['lid'] = identifier
        node.attrib['objectType'] = str(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Type']))
        node.attrib['status'] = 'urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted'

        etree.SubElement(node, util.nspath_eval('rim:VersionInfo', self.namespaces), versionName='')

        if esn == 'summary':
            etree.SubElement(node, util.nspath_eval('rim:ExternalIdentifier', self.namespaces), value=identifier, identificationScheme='foo', registryObject=str(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Relation'])), id=identifier)

            name = etree.SubElement(node, util.nspath_eval('rim:Name', self.namespaces))
            etree.SubElement(name, util.nspath_eval('rim:LocalizedString', self.namespaces), value=unicode(util.getqattr(result, queryables['pycsw:Title']['dbcol'])))

            description = etree.SubElement(node, util.nspath_eval('rim:Description', self.namespaces))
            etree.SubElement(description, util.nspath_eval('rim:LocalizedString', self.namespaces), value=unicode(util.getqattr(result, queryables['pycsw:Abstract']['dbcol'])))

            val = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:BoundingBox'])
            bboxel = server.write_boundingbox(val)

            if bboxel is not None:
                bboxslot = etree.SubElement(node, util.nspath_eval('rim:Slot', self.namespaces),
                slotType='urn:ogc:def:dataType:ISO-19107:2003:GM_Envelope')

                valuelist = etree.SubElement(bboxslot, util.nspath_eval('rim:ValueList', self.namespaces))
                value = etree.SubElement(valuelist, util.nspath_eval('rim:Value', self.namespaces))
                value.append(bboxel)

            rkeywords = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Keywords'])
            if rkeywords is not None:
                subjectslot = etree.SubElement(node, util.nspath_eval('rim:Slot', self.namespaces),
                name='http://purl.org/dc/elements/1.1/subject')
                valuelist = etree.SubElement(subjectslot, util.nspath_eval('rim:ValueList', self.namespaces))
                for keyword in rkeywords.split(','):
                    etree.SubElement(valuelist,
                    util.nspath_eval('rim:Value', self.namespaces)).text = keyword

        return node
コード例 #3
0
ファイル: ebrim.py プロジェクト: drwelby/pycsw
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''

        identifier = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Identifier'])
        typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])

        if esn == 'full' and typename == 'rim:RegistryObject':
            # dump record as is and exit
            return etree.fromstring(util.getqattr(result, queryables['pycsw:XML']['dbcol']))

        if typename == 'csw:Record':  # transform csw:Record -> rim:RegistryObject model mappings
            util.transform_mappings(queryables, self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('rim:ExtrinsicObject', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s %s/csw/2.0.2/profiles/ebrim/1.0/csw-ebrim.xsd' % (self.namespaces['wrs'], self.ogc_schemas_base)

        node.attrib['id'] = identifier
        node.attrib['lid'] = identifier
        node.attrib['objectType'] = str(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Type']))
        node.attrib['status'] = 'urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted'

        etree.SubElement(node, util.nspath_eval('rim:VersionInfo', self.namespaces), versionName='')

        if esn == 'summary':
            etree.SubElement(node, util.nspath_eval('rim:ExternalIdentifier', self.namespaces), value=identifier, identificationScheme='foo', registryObject=str(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Relation'])), id=identifier)

            name = etree.SubElement(node, util.nspath_eval('rim:Name', self.namespaces))
            etree.SubElement(name, util.nspath_eval('rim:LocalizedString', self.namespaces), value=unicode(util.getqattr(result, queryables['pycsw:Title']['dbcol'])))

            description = etree.SubElement(node, util.nspath_eval('rim:Description', self.namespaces))
            etree.SubElement(description, util.nspath_eval('rim:LocalizedString', self.namespaces), value=unicode(util.getqattr(result, queryables['pycsw:Abstract']['dbcol'])))

            val = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:BoundingBox'])
            bboxel = server.write_boundingbox(val)

            if bboxel is not None:
                bboxslot = etree.SubElement(node, util.nspath_eval('rim:Slot', self.namespaces),
                slotType='urn:ogc:def:dataType:ISO-19107:2003:GM_Envelope')

                valuelist = etree.SubElement(bboxslot, util.nspath_eval('rim:ValueList', self.namespaces))
                value = etree.SubElement(valuelist, util.nspath_eval('rim:Value', self.namespaces))
                value.append(bboxel)

            rkeywords = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Keywords'])
            if rkeywords is not None:
                subjectslot = etree.SubElement(node, util.nspath_eval('rim:Slot', self.namespaces),
                name='http://purl.org/dc/elements/1.1/subject')
                valuelist = etree.SubElement(subjectslot, util.nspath_eval('rim:ValueList', self.namespaces))
                for keyword in rkeywords.split(','):
                    etree.SubElement(valuelist,
                    util.nspath_eval('rim:Value', self.namespaces)).text = keyword

        return node
コード例 #4
0
ファイル: dif.py プロジェクト: dkuerner/pycsw
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''

        typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])

        if esn == 'full' and typename == 'dif:DIF':
            # dump record as is and exit
            return etree.fromstring(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':  # transform csw:Record -> dif:DIF model mappings
            util.transform_mappings(queryables, self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('dif:DIF', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif.xsd' % self.namespace

        # identifier
        etree.SubElement(node, util.nspath_eval('dif:Entry_ID', self.namespaces)).text = util.getqattr(result, queryables['dif:Identifier']['dbcol'])

        # title
        val = util.getqattr(result, queryables['dif:Entry_Title']['dbcol'])
        if not val:
            val = ''
        etree.SubElement(node, util.nspath_eval('dif:Entry_Title', self.namespaces)).text = val

        # citation
        citation = etree.SubElement(node, util.nspath_eval('dif:Data_Set_Citation', self.namespaces))

        # creator
        val = util.getqattr(result, queryables['dif:Dataset_Creator']['dbcol'])
        etree.SubElement(citation, util.nspath_eval('dif:Dataset_Creator', self.namespaces)).text = val

        # date
        val = util.getqattr(result, queryables['dif:Dataset_Release_Date']['dbcol'])
        etree.SubElement(citation, util.nspath_eval('dif:Dataset_Release_Date', self.namespaces)).text = val

        # publisher
        val = util.getqattr(result, queryables['dif:Dataset_Publisher']['dbcol'])
        etree.SubElement(citation, util.nspath_eval('dif:Dataset_Publisher', self.namespaces)).text = val

        # format
        val = util.getqattr(result, queryables['dif:Data_Presentation_Form']['dbcol'])
        etree.SubElement(citation, util.nspath_eval('dif:Data_Presentation_Form', self.namespaces)).text = val

        # iso topic category
        val = util.getqattr(result, queryables['dif:ISO_Topic_Category']['dbcol'])
        etree.SubElement(node, util.nspath_eval('dif:ISO_Topic_Category', self.namespaces)).text = val

        # keywords
        val = util.getqattr(result, queryables['dif:Keyword']['dbcol'])

        if val:
            for kw in val.split(','):
                etree.SubElement(node, util.nspath_eval('dif:Keyword', self.namespaces)).text = kw

        # temporal
        temporal = etree.SubElement(node, util.nspath_eval('dif:Temporal_Coverage', self.namespaces))
        val = util.getqattr(result, queryables['dif:Start_Date']['dbcol'])
        val2 = util.getqattr(result, queryables['dif:Stop_Date']['dbcol'])
        etree.SubElement(temporal, util.nspath_eval('dif:Start_Date', self.namespaces)).text = val 
        etree.SubElement(temporal, util.nspath_eval('dif:End_Date', self.namespaces)).text = val2

        # bbox extent
        val = util.getqattr(result, queryables['dif:Spatial_Coverage']['dbcol'])
        bboxel = write_extent(val, self.namespaces)
        if bboxel is not None:
            node.append(bboxel)

        # access constraints
        val = util.getqattr(result, queryables['dif:Access_Constraints']['dbcol'])
        etree.SubElement(node, util.nspath_eval('dif:Access_Constraints', self.namespaces)).text = val

        # language
        val = util.getqattr(result, queryables['dif:Data_Set_Language']['dbcol'])
        etree.SubElement(node, util.nspath_eval('dif:Data_Set_Language', self.namespaces)).text = val

        # contributor
        val = util.getqattr(result, queryables['dif:Originating_Center']['dbcol'])
        etree.SubElement(node, util.nspath_eval('dif:Originating_Center', self.namespaces)).text = val

        # abstract
        val = util.getqattr(result, queryables['dif:Summary']['dbcol'])
        if not val:
            val = ''
        etree.SubElement(node, util.nspath_eval('dif:Summary', self.namespaces)).text = val

        # date 
        val = util.getqattr(result, queryables['dif:DIF_Creation_Date']['dbcol'])
        etree.SubElement(node, util.nspath_eval('dif:DIF_Creation_Date', self.namespaces)).text = val

        # URL
        val = util.getqattr(result, queryables['dif:Related_URL']['dbcol'])
        url = etree.SubElement(node, util.nspath_eval('dif:Related_URL', self.namespaces))
        etree.SubElement(url, util.nspath_eval('dif:URL', self.namespaces)).text = val

        rlinks = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Links'])
        if rlinks:
            for link in rlinks.split('^'):
                linkset = link.split(',')
           
                url2 = etree.SubElement(node, util.nspath_eval('dif:Related_URL', self.namespaces))

                urltype = etree.SubElement(url2, util.nspath_eval('dif:URL_Content_Type', self.namespaces))
                etree.SubElement(urltype, util.nspath_eval('dif:Type', self.namespaces)).text = linkset[2]

                etree.SubElement(url2, util.nspath_eval('dif:URL', self.namespaces)).text = linkset[-1]
                etree.SubElement(url2, util.nspath_eval('dif:Description', self.namespaces)).text = linkset[1]

        etree.SubElement(node, util.nspath_eval('dif:Metadata_Name', self.namespaces)).text = 'CEOS IDN DIF'
        etree.SubElement(node, util.nspath_eval('dif:Metadata_Version', self.namespaces)).text = '9.7'

        return node
コード例 #5
0
ファイル: apiso.py プロジェクト: dkuerner/pycsw
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''
        typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])
        if (esn == 'full' and typename == 'gmd:MD_Metadata'):
            # dump record as is and exit
            return etree.fromstring(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':  # transform csw:Record -> gmd:MD_Metadata model mappings
            util.transform_mappings(queryables, self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('gmd:MD_Metadata', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s %s/csw/2.0.2/profiles/apiso/1.0.0/apiso.xsd' % (self.namespace, self.ogc_schemas_base)

        # identifier
        idval = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Identifier'])

        identifier = etree.SubElement(node, util.nspath_eval('gmd:fileIdentifier', self.namespaces))
        etree.SubElement(identifier, util.nspath_eval('gco:CharacterString', self.namespaces)).text = idval

        if esn in ['summary', 'full']:
            # language
            val = util.getqattr(result, queryables['apiso:Language']['dbcol'])

            lang = etree.SubElement(node, util.nspath_eval('gmd:language', self.namespaces))
            etree.SubElement(lang, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

        # hierarchyLevel
        mtype = util.getqattr(result, queryables['apiso:Type']['dbcol']) or None

        if mtype is not None: 
            hierarchy = etree.SubElement(node, util.nspath_eval('gmd:hierarchyLevel', self.namespaces))
            hierarchy.append(_write_codelist_element('gmd:MD_ScopeCode', mtype, self.namespaces))

        if esn in ['summary', 'full']:
            # contact
            val = util.getqattr(result, queryables['apiso:OrganisationName']['dbcol'])
            contact = etree.SubElement(node, util.nspath_eval('gmd:contact', self.namespaces))
            if val:
                CI_resp = etree.SubElement(contact, util.nspath_eval('gmd:CI_ResponsibleParty', self.namespaces))
                org_name = etree.SubElement(CI_resp, util.nspath_eval('gmd:organisationName', self.namespaces))
                etree.SubElement(org_name, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

            # date
            val = util.getqattr(result, queryables['apiso:Modified']['dbcol'])
            date = etree.SubElement(node, util.nspath_eval('gmd:dateStamp', self.namespaces))
            if val and val.find('T') != -1:
                dateel = 'gco:DateTime'
            else:
                dateel = 'gco:Date'
            etree.SubElement(date, util.nspath_eval(dateel, self.namespaces)).text = val

            metadatastandardname = 'ISO19115'
            metadatastandardversion = '2003/Cor.1:2006'

            if mtype == 'service':
                metadatastandardname = 'ISO19119'
                metadatastandardversion = '2005/PDAM 1'

            # metadata standard name
            standard = etree.SubElement(node, util.nspath_eval('gmd:metadataStandardName', self.namespaces))
            etree.SubElement(standard, util.nspath_eval('gco:CharacterString', self.namespaces)).text = metadatastandardname

            # metadata standard version
            standardver = etree.SubElement(node, util.nspath_eval('gmd:metadataStandardVersion', self.namespaces))
            etree.SubElement(standardver, util.nspath_eval('gco:CharacterString', self.namespaces)).text = metadatastandardversion

        # title
        val = util.getqattr(result, queryables['apiso:Title']['dbcol']) or ''
        identification = etree.SubElement(node, util.nspath_eval('gmd:identificationInfo', self.namespaces))

        if mtype == 'service':
           restagname = 'srv:SV_ServiceIdentification'
        else:
           restagname = 'gmd:MD_DataIdentification'
          
        resident = etree.SubElement(identification, util.nspath_eval(restagname, self.namespaces), id=idval)
        tmp2 = etree.SubElement(resident, util.nspath_eval('gmd:citation', self.namespaces))
        tmp3 = etree.SubElement(tmp2, util.nspath_eval('gmd:CI_Citation', self.namespaces))
        tmp4 = etree.SubElement(tmp3, util.nspath_eval('gmd:title', self.namespaces))
        etree.SubElement(tmp4, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

        # creation date
        val = util.getqattr(result, queryables['apiso:CreationDate']['dbcol'])
        if val is not None:
            tmp3.append(_write_date(val, 'creation', self.namespaces))
        # publication date
        val = util.getqattr(result, queryables['apiso:PublicationDate']['dbcol'])
        if val is not None:
            tmp3.append(_write_date(val, 'publication', self.namespaces))
        # revision date
        val = util.getqattr(result, queryables['apiso:RevisionDate']['dbcol']) or util.getqattr(result, queryables['apiso:Modified']['dbcol'])
        if val is not None:
            tmp3.append(_write_date(val, 'revision', self.namespaces))

        if esn in ['summary', 'full']:
            # abstract
            val = util.getqattr(result, queryables['apiso:Abstract']['dbcol']) or ''
            tmp = etree.SubElement(resident, util.nspath_eval('gmd:abstract', self.namespaces))
            etree.SubElement(tmp, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

            # spatial resolution
            val = util.getqattr(result, queryables['apiso:Denominator']['dbcol'])
            if val:
                tmp = etree.SubElement(resident, util.nspath_eval('gmd:spatialResolution', self.namespaces))
                tmp2 = etree.SubElement(tmp, util.nspath_eval('gmd:MD_Resolution', self.namespaces))
                tmp3 = etree.SubElement(tmp2, util.nspath_eval('gmd:equivalentScale', self.namespaces))
                tmp4 = etree.SubElement(tmp3, util.nspath_eval('gmd:MD_RepresentativeFraction', self.namespaces))
                tmp5 = etree.SubElement(tmp4, util.nspath_eval('gmd:denominator', self.namespaces))
                etree.SubElement(tmp5, util.nspath_eval('gco:Integer', self.namespaces)).text = str(val)

            # resource language
            val = util.getqattr(result, queryables['apiso:ResourceLanguage']['dbcol'])
            tmp = etree.SubElement(resident, util.nspath_eval('gmd:language', self.namespaces))
            etree.SubElement(tmp, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

            # topic category
            val = util.getqattr(result, queryables['apiso:TopicCategory']['dbcol'])
            if val:
                for v in val.split(','):
                    tmp = etree.SubElement(resident, util.nspath_eval('gmd:topicCategory', self.namespaces))
                    etree.SubElement(tmp, util.nspath_eval('gmd:MD_TopicCategoryCode', self.namespaces)).text = val

        # bbox extent
        val = util.getqattr(result, queryables['apiso:BoundingBox']['dbcol'])
        bboxel = write_extent(val, self.namespaces)
        if bboxel is not None and mtype != 'service':
            resident.append(bboxel)

        # service identification

        if mtype == 'service':
            # service type
            # service type version
            val = util.getqattr(result, queryables['apiso:ServiceType']['dbcol'])
            val2 = util.getqattr(result, queryables['apiso:ServiceTypeVersion']['dbcol'])
            if val is not None:
                tmp = etree.SubElement(resident, util.nspath_eval('srv:serviceType', self.namespaces))
                etree.SubElement(tmp, util.nspath_eval('gco:LocalName', self.namespaces)).text = val
                tmp = etree.SubElement(resident, util.nspath_eval('srv:serviceTypeVersion', self.namespaces))
                etree.SubElement(tmp, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val2

            if bboxel is not None:
                bboxel.tag = util.nspath_eval('srv:extent', self.namespaces)
                resident.append(bboxel)

            val = util.getqattr(result, queryables['apiso:CouplingType']['dbcol'])
            if val is not None:
                couplingtype = etree.SubElement(resident, util.nspath_eval('srv:couplingType', self.namespaces))
                etree.SubElement(couplingtype, util.nspath_eval('srv:SV_CouplingType', self.namespaces), codeListValue=val, codeList='%s#SV_CouplingType' % CODELIST).text = val

            if esn in ['summary', 'full']:
                # all service resources as coupled resources
                coupledresources = util.getqattr(result, queryables['apiso:OperatesOn']['dbcol'])
                operations = util.getqattr(result, queryables['apiso:Operation']['dbcol'])

                if coupledresources:
                    for val2 in coupledresources.split(','):
                        coupledres = etree.SubElement(resident, util.nspath_eval('srv:coupledResource', self.namespaces))
                        svcoupledres = etree.SubElement(coupledres, util.nspath_eval('srv:SV_CoupledResource', self.namespaces))
                        opname = etree.SubElement(svcoupledres, util.nspath_eval('srv:operationName', self.namespaces))
                        etree.SubElement(opname, util.nspath_eval('gco:CharacterString', self.namespaces)).text = _get_resource_opname(operations)
                        sid = etree.SubElement(svcoupledres, util.nspath_eval('srv:identifier', self.namespaces))
                        etree.SubElement(sid, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val2

                # service operations
                if operations:
                    for i in operations.split(','):
                        oper = etree.SubElement(resident, util.nspath_eval('srv:containsOperations', self.namespaces))
                        tmp = etree.SubElement(oper, util.nspath_eval('srv:SV_OperationMetadata', self.namespaces))

                        tmp2 = etree.SubElement(tmp, util.nspath_eval('srv:operationName', self.namespaces))
                        etree.SubElement(tmp2, util.nspath_eval('gco:CharacterString', self.namespaces)).text = i

                        tmp3 = etree.SubElement(tmp, util.nspath_eval('srv:DCP', self.namespaces))
                        etree.SubElement(tmp3, util.nspath_eval('srv:DCPList', self.namespaces), codeList='%s#DCPList' % CODELIST, codeListValue='HTTPGet').text = 'HTTPGet' 

                        tmp4 = etree.SubElement(tmp, util.nspath_eval('srv:DCP', self.namespaces))
                        etree.SubElement(tmp4, util.nspath_eval('srv:DCPList', self.namespaces), codeList='%s#DCPList' % CODELIST, codeListValue='HTTPPost').text = 'HTTPPost' 

                        connectpoint = etree.SubElement(tmp, util.nspath_eval('srv:connectPoint', self.namespaces))
                        onlineres = etree.SubElement(connectpoint, util.nspath_eval('gmd:CI_OnlineResource', self.namespaces))
                        linkage = etree.SubElement(onlineres, util.nspath_eval('gmd:linkage', self.namespaces))
                        etree.SubElement(linkage, util.nspath_eval('gmd:URL', self.namespaces)).text = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Source'])

                # operates on resource(s)
                if coupledresources:
                    for i in coupledresources.split(','):
                        etree.SubElement(resident, util.nspath_eval('srv:operatesOn', self.namespaces), uuidref=i)

        rlinks = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Links'])

        if rlinks:
            distinfo = etree.SubElement(node, util.nspath_eval('gmd:distributionInfo', self.namespaces))
            distinfo2 = etree.SubElement(distinfo, util.nspath_eval('gmd:MD_Distribution', self.namespaces))
            transopts = etree.SubElement(distinfo2, util.nspath_eval('gmd:transferOptions', self.namespaces))
            dtransopts = etree.SubElement(transopts, util.nspath_eval('gmd:MD_DigitalTransferOptions', self.namespaces))

            for link in rlinks.split('^'):
                linkset = link.split(',')
                online = etree.SubElement(dtransopts, util.nspath_eval('gmd:onLine', self.namespaces))
                online2 = etree.SubElement(online, util.nspath_eval('gmd:CI_OnlineResource', self.namespaces))

                linkage = etree.SubElement(online2, util.nspath_eval('gmd:linkage', self.namespaces))
                etree.SubElement(linkage, util.nspath_eval('gmd:URL', self.namespaces)).text = linkset[-1]

                protocol = etree.SubElement(online2, util.nspath_eval('gmd:protocol', self.namespaces))
                etree.SubElement(protocol, util.nspath_eval('gco:CharacterString', self.namespaces)).text = linkset[2]

                name = etree.SubElement(online2, util.nspath_eval('gmd:name', self.namespaces))
                etree.SubElement(name, util.nspath_eval('gco:CharacterString', self.namespaces)).text = linkset[0]

                desc = etree.SubElement(online2, util.nspath_eval('gmd:description', self.namespaces))
                etree.SubElement(desc, util.nspath_eval('gco:CharacterString', self.namespaces)).text = linkset[1]

        return node
コード例 #6
0
ファイル: fgdc.py プロジェクト: fototo/pycsw
    def write_record(self, recobj, esn, outputschema, queryables):
        """ Return csw:SearchResults child as lxml.etree.Element """
        typename = util.getqattr(recobj, self.context.md_core_model["mappings"]["pycsw:Typename"])
        if esn == "full" and typename == "fgdc:metadata":
            # dump record as is and exit
            return etree.fromstring(util.getqattr(recobj, self.context.md_core_model["mappings"]["pycsw:XML"]))

        if typename == "csw:Record":
            # transform csw:Record -> fgdc:metadata model mappings
            util.transform_mappings(queryables, self.repository["mappings"]["csw:Record"])

        node = etree.Element("metadata")
        node.attrib[
            util.nspath_eval("xsi:noNamespaceSchemaLocation", self.context.namespaces)
        ] = "http://www.fgdc.gov/metadata/fgdc-std-001-1998.xsd"

        idinfo = etree.SubElement(node, "idinfo")
        # identifier
        etree.SubElement(idinfo, "datasetid").text = util.getqattr(recobj, queryables["fgdc:Identifier"]["dbcol"])

        citation = etree.SubElement(idinfo, "citation")
        citeinfo = etree.SubElement(citation, "citeinfo")

        # title
        val = util.getqattr(recobj, queryables["fgdc:Title"]["dbcol"])
        etree.SubElement(citeinfo, "title").text = val

        # publisher
        publinfo = etree.SubElement(citeinfo, "publinfo")
        val = util.getqattr(recobj, queryables["fgdc:Publisher"]["dbcol"]) or ""
        etree.SubElement(publinfo, "publish").text = val

        # origin
        val = util.getqattr(recobj, queryables["fgdc:Origin"]["dbcol"]) or ""
        etree.SubElement(citeinfo, "origin").text = val

        # keywords
        val = util.getqattr(recobj, queryables["fgdc:ThemeKeywords"]["dbcol"])
        if val:
            keywords = etree.SubElement(idinfo, "keywords")
            theme = etree.SubElement(keywords, "theme")
            for v in val.split(","):
                etree.SubElement(theme, "themekey").text = v

        # accessconstraints
        val = util.getqattr(recobj, queryables["fgdc:AccessConstraints"]["dbcol"]) or ""
        etree.SubElement(idinfo, "accconst").text = val

        # abstract
        descript = etree.SubElement(idinfo, "descript")
        val = util.getqattr(recobj, queryables["fgdc:Abstract"]["dbcol"]) or ""
        etree.SubElement(descript, "abstract").text = val

        # time
        datebegin = util.getqattr(recobj, queryables["fgdc:BeginDate"]["dbcol"])
        dateend = util.getqattr(recobj, queryables["fgdc:EndDate"]["dbcol"])
        if all([datebegin, dateend]):
            timeperd = etree.SubElement(idinfo, "timeperd")
            timeinfo = etree.SubElement(timeperd, "timeinfo")
            rngdates = etree.SubElement(timeinfo, "timeinfo")
            begdate = etree.SubElement(rngdates, "begdate").text = datebegin
            enddate = etree.SubElement(rngdates, "enddate").text = dateend

        # bbox extent
        val = util.getqattr(recobj, queryables["fgdc:Envelope"]["dbcol"])
        bboxel = write_extent(val)
        if bboxel is not None:
            idinfo.append(bboxel)

        # contributor
        val = util.getqattr(recobj, queryables["fgdc:Contributor"]["dbcol"]) or ""
        etree.SubElement(idinfo, "datacred").text = val

        # direct
        spdoinfo = etree.SubElement(idinfo, "spdoinfo")
        val = util.getqattr(recobj, queryables["fgdc:Type"]["dbcol"]) or ""
        etree.SubElement(spdoinfo, "direct").text = val

        # formname
        distinfo = etree.SubElement(node, "distinfo")
        stdorder = etree.SubElement(distinfo, "stdorder")
        digform = etree.SubElement(stdorder, "digform")
        digtinfo = etree.SubElement(digform, "digtinfo")
        val = util.getqattr(recobj, queryables["fgdc:Format"]["dbcol"]) or ""
        etree.SubElement(digtinfo, "formname").text = val
        etree.SubElement(citeinfo, "geoform").text = val

        # source
        lineage = etree.SubElement(node, "lineage")
        srcinfo = etree.SubElement(lineage, "srcinfo")
        srccite = etree.SubElement(srcinfo, "srccite")
        sciteinfo = etree.SubElement(srccite, "citeinfo")
        val = util.getqattr(recobj, queryables["fgdc:Source"]["dbcol"]) or ""
        etree.SubElement(sciteinfo, "title").text = val

        val = util.getqattr(recobj, queryables["fgdc:Relation"]["dbcol"]) or ""
        etree.SubElement(citeinfo, "onlink").text = val

        # links
        rlinks = util.getqattr(recobj, self.context.md_core_model["mappings"]["pycsw:Links"])
        if rlinks:
            for link in rlinks.split("^"):
                linkset = link.split(",")
                etree.SubElement(citeinfo, "onlink", type=linkset[2]).text = linkset[-1]

        # metd
        metainfo = etree.SubElement(node, "metainfo")
        val = util.getqattr(recobj, queryables["fgdc:Modified"]["dbcol"]) or ""
        etree.SubElement(metainfo, "metd").text = val

        return node
コード例 #7
0
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''

        typename = util.getqattr(
            result, self.context.md_core_model['mappings']['pycsw:Typename'])

        if esn == 'full' and typename == 'atom:entry':
            # dump record as is and exit
            return etree.fromstring(
                util.getqattr(
                    result,
                    self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':  # transform csw:Record -> atom:entry model mappings
            util.transform_mappings(queryables,
                                    self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('atom:entry', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s %s?service=CSW&version=2.0.2&request=DescribeRecord&typename=atom:entry' % (self.namespaces['atom'], self.url)

        # author
        val = util.getqattr(result, queryables['atom:author']['dbcol'])

        if val:
            etree.SubElement(
                node, util.nspath_eval('atom:author',
                                       self.namespaces)).text = util.getqattr(
                                           result,
                                           queryables['atom:author']['dbcol'])

        # category
        val = util.getqattr(result, queryables['atom:category']['dbcol'])

        if val:
            for kw in val.split(','):
                etree.SubElement(
                    node, util.nspath_eval('atom:category',
                                           self.namespaces)).text = kw

        for qval in ['contributor', 'id']:
            val = util.getqattr(result, queryables['atom:%s' % qval]['dbcol'])
            if val:
                etree.SubElement(
                    node,
                    util.nspath_eval('atom:%s' % qval,
                                     self.namespaces)).text = util.getqattr(
                                         result,
                                         queryables['atom:%s' % qval]['dbcol'])

        rlinks = util.getqattr(
            result, self.context.md_core_model['mappings']['pycsw:Links'])
        if rlinks:
            for link in rlinks.split('^'):
                linkset = link.split(',')

                url2 = etree.SubElement(node,
                                        util.nspath_eval(
                                            'atom:link', self.namespaces),
                                        href=linkset[-1],
                                        type=linkset[2],
                                        title=linkset[1])

        etree.SubElement(
            node,
            util.nspath_eval('atom:link', self.namespaces),
            href='%s?service=CSW&version=2.0.2&request=GetRepositoryItem&id=%s'
            %
            (self.url, util.getqattr(result, queryables['atom:id']['dbcol'])))

        for qval in [
                'published', 'rights', 'source', 'summary', 'title', 'updated'
        ]:
            val = util.getqattr(result, queryables['atom:%s' % qval]['dbcol'])
            if val:
                etree.SubElement(
                    node,
                    util.nspath_eval('atom:%s' % qval,
                                     self.namespaces)).text = util.getqattr(
                                         result,
                                         queryables['atom:%s' % qval]['dbcol'])

        # bbox extent
        val = util.getqattr(result, queryables['georss:where']['dbcol'])
        bboxel = write_extent(val, self.context.namespaces)
        if bboxel is not None:
            node.append(bboxel)

        return node
コード例 #8
0
ファイル: fgdc.py プロジェクト: drwelby/pycsw
    def write_record(self, recobj, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''
        typename = util.getqattr(
            recobj, self.context.md_core_model['mappings']['pycsw:Typename'])
        if esn == 'full' and typename == 'fgdc:metadata':
            # dump record as is and exit
            return etree.fromstring(
                util.getqattr(
                    recobj,
                    self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':
            # transform csw:Record -> fgdc:metadata model mappings
            util.transform_mappings(queryables,
                                    self.repository['mappings']['csw:Record'])

        node = etree.Element('metadata')
        node.attrib[util.nspath_eval('xsi:noNamespaceSchemaLocation', self.context.namespaces)] = \
        'http://www.fgdc.gov/metadata/fgdc-std-001-1998.xsd'

        idinfo = etree.SubElement(node, 'idinfo')
        # identifier
        etree.SubElement(idinfo, 'datasetid').text = util.getqattr(
            recobj, queryables['fgdc:Identifier']['dbcol'])

        citation = etree.SubElement(idinfo, 'citation')
        citeinfo = etree.SubElement(citation, 'citeinfo')

        # title
        val = util.getqattr(recobj, queryables['fgdc:Title']['dbcol'])
        etree.SubElement(citeinfo, 'title').text = val

        # publisher
        publinfo = etree.SubElement(citeinfo, 'publinfo')
        val = util.getqattr(recobj,
                            queryables['fgdc:Publisher']['dbcol']) or ''
        etree.SubElement(publinfo, 'publish').text = val

        # origin
        val = util.getqattr(recobj, queryables['fgdc:Origin']['dbcol']) or ''
        etree.SubElement(citeinfo, 'origin').text = val

        # keywords
        val = util.getqattr(recobj, queryables['fgdc:ThemeKeywords']['dbcol'])
        if val:
            keywords = etree.SubElement(idinfo, 'keywords')
            theme = etree.SubElement(keywords, 'theme')
            for v in val.split(','):
                etree.SubElement(theme, 'themekey').text = v

        # accessconstraints
        val = util.getqattr(
            recobj, queryables['fgdc:AccessConstraints']['dbcol']) or ''
        etree.SubElement(idinfo, 'accconst').text = val

        # abstract
        descript = etree.SubElement(idinfo, 'descript')
        val = util.getqattr(recobj, queryables['fgdc:Abstract']['dbcol']) or ''
        etree.SubElement(descript, 'abstract').text = val

        # time
        datebegin = util.getqattr(recobj,
                                  queryables['fgdc:BeginDate']['dbcol'])
        dateend = util.getqattr(recobj, queryables['fgdc:EndDate']['dbcol'])
        if all([datebegin, dateend]):
            timeperd = etree.SubElement(idinfo, 'timeperd')
            timeinfo = etree.SubElement(timeperd, 'timeinfo')
            rngdates = etree.SubElement(timeinfo, 'timeinfo')
            begdate = etree.SubElement(rngdates, 'begdate').text = datebegin
            enddate = etree.SubElement(rngdates, 'enddate').text = dateend

        # bbox extent
        val = util.getqattr(recobj, queryables['fgdc:Envelope']['dbcol'])
        bboxel = write_extent(val)
        if bboxel is not None:
            idinfo.append(bboxel)

        # contributor
        val = util.getqattr(recobj,
                            queryables['fgdc:Contributor']['dbcol']) or ''
        etree.SubElement(idinfo, 'datacred').text = val

        # direct
        spdoinfo = etree.SubElement(idinfo, 'spdoinfo')
        val = util.getqattr(recobj, queryables['fgdc:Type']['dbcol']) or ''
        etree.SubElement(spdoinfo, 'direct').text = val

        # formname
        distinfo = etree.SubElement(node, 'distinfo')
        stdorder = etree.SubElement(distinfo, 'stdorder')
        digform = etree.SubElement(stdorder, 'digform')
        digtinfo = etree.SubElement(digform, 'digtinfo')
        val = util.getqattr(recobj, queryables['fgdc:Format']['dbcol']) or ''
        etree.SubElement(digtinfo, 'formname').text = val
        etree.SubElement(citeinfo, 'geoform').text = val

        # source
        lineage = etree.SubElement(node, 'lineage')
        srcinfo = etree.SubElement(lineage, 'srcinfo')
        srccite = etree.SubElement(srcinfo, 'srccite')
        sciteinfo = etree.SubElement(srccite, 'citeinfo')
        val = util.getqattr(recobj, queryables['fgdc:Source']['dbcol']) or ''
        etree.SubElement(sciteinfo, 'title').text = val

        val = util.getqattr(recobj, queryables['fgdc:Relation']['dbcol']) or ''
        etree.SubElement(citeinfo, 'onlink').text = val

        # links
        rlinks = util.getqattr(
            recobj, self.context.md_core_model['mappings']['pycsw:Links'])
        if rlinks:
            for link in rlinks.split('^'):
                linkset = link.split(',')
                etree.SubElement(citeinfo, 'onlink',
                                 type=linkset[2]).text = linkset[-1]

        # metd
        metainfo = etree.SubElement(node, 'metainfo')
        val = util.getqattr(recobj, queryables['fgdc:Modified']['dbcol']) or ''
        etree.SubElement(metainfo, 'metd').text = val

        return node
コード例 #9
0
ファイル: apiso.py プロジェクト: jiwalker-usgs/pycsw
    def write_record(self, result, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''
        typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])
        if (esn == 'full' and typename == 'gmd:MD_Metadata'):
            # dump record as is and exit
            return etree.fromstring(util.getqattr(result, self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':  # transform csw:Record -> gmd:MD_Metadata model mappings
            util.transform_mappings(queryables, self.repository['mappings']['csw:Record'])

        node = etree.Element(util.nspath_eval('gmd:MD_Metadata', self.namespaces))
        node.attrib[util.nspath_eval('xsi:schemaLocation', self.context.namespaces)] = \
        '%s %s/csw/2.0.2/profiles/apiso/1.0.0/apiso.xsd' % (self.namespace, self.ogc_schemas_base)

        # identifier
        idval = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Identifier'])

        identifier = etree.SubElement(node, util.nspath_eval('gmd:fileIdentifier', self.namespaces))
        etree.SubElement(identifier, util.nspath_eval('gco:CharacterString', self.namespaces)).text = idval

        if esn in ['summary', 'full']:
            # language
            val = util.getqattr(result, queryables['apiso:Language']['dbcol'])

            lang = etree.SubElement(node, util.nspath_eval('gmd:language', self.namespaces))
            etree.SubElement(lang, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

        # hierarchyLevel
        mtype = util.getqattr(result, queryables['apiso:Type']['dbcol']) or None

        if mtype is not None: 
            hierarchy = etree.SubElement(node, util.nspath_eval('gmd:hierarchyLevel', self.namespaces))
            hierarchy.append(_write_codelist_element('gmd:MD_ScopeCode', mtype, self.namespaces))

        if esn in ['summary', 'full']:
            # contact
            val = util.getqattr(result, queryables['apiso:OrganisationName']['dbcol'])
            contact = etree.SubElement(node, util.nspath_eval('gmd:contact', self.namespaces))
            if val:
                CI_resp = etree.SubElement(contact, util.nspath_eval('gmd:CI_ResponsibleParty', self.namespaces))
                org_name = etree.SubElement(CI_resp, util.nspath_eval('gmd:organisationName', self.namespaces))
                etree.SubElement(org_name, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

            # date
            val = util.getqattr(result, queryables['apiso:Modified']['dbcol'])
            date = etree.SubElement(node, util.nspath_eval('gmd:dateStamp', self.namespaces))
            if val and val.find('T') != -1:
                dateel = 'gco:DateTime'
            else:
                dateel = 'gco:Date'
            etree.SubElement(date, util.nspath_eval(dateel, self.namespaces)).text = val

            metadatastandardname = 'ISO19115'
            metadatastandardversion = '2003/Cor.1:2006'

            if mtype == 'service':
                metadatastandardname = 'ISO19119'
                metadatastandardversion = '2005/PDAM 1'

            # metadata standard name
            standard = etree.SubElement(node, util.nspath_eval('gmd:metadataStandardName', self.namespaces))
            etree.SubElement(standard, util.nspath_eval('gco:CharacterString', self.namespaces)).text = metadatastandardname

            # metadata standard version
            standardver = etree.SubElement(node, util.nspath_eval('gmd:metadataStandardVersion', self.namespaces))
            etree.SubElement(standardver, util.nspath_eval('gco:CharacterString', self.namespaces)).text = metadatastandardversion

        # title
        val = util.getqattr(result, queryables['apiso:Title']['dbcol']) or ''
        identification = etree.SubElement(node, util.nspath_eval('gmd:identificationInfo', self.namespaces))

        if mtype == 'service':
           restagname = 'srv:SV_ServiceIdentification'
        else:
           restagname = 'gmd:MD_DataIdentification'
          
        resident = etree.SubElement(identification, util.nspath_eval(restagname, self.namespaces), id=idval)
        tmp2 = etree.SubElement(resident, util.nspath_eval('gmd:citation', self.namespaces))
        tmp3 = etree.SubElement(tmp2, util.nspath_eval('gmd:CI_Citation', self.namespaces))
        tmp4 = etree.SubElement(tmp3, util.nspath_eval('gmd:title', self.namespaces))
        etree.SubElement(tmp4, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

        # creation date
        val = util.getqattr(result, queryables['apiso:CreationDate']['dbcol'])
        if val is not None:
            tmp3.append(_write_date(val, 'creation', self.namespaces))
        # publication date
        val = util.getqattr(result, queryables['apiso:PublicationDate']['dbcol'])
        if val is not None:
            tmp3.append(_write_date(val, 'publication', self.namespaces))
        # revision date
        val = util.getqattr(result, queryables['apiso:RevisionDate']['dbcol']) or util.getqattr(result, queryables['apiso:Modified']['dbcol'])
        if val is not None:
            tmp3.append(_write_date(val, 'revision', self.namespaces))

        if esn in ['summary', 'full']:
            # abstract
            val = util.getqattr(result, queryables['apiso:Abstract']['dbcol']) or ''
            tmp = etree.SubElement(resident, util.nspath_eval('gmd:abstract', self.namespaces))
            etree.SubElement(tmp, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

            # keywords
            kw = util.getqattr(result, queryables['apiso:Subject']['dbcol'])
            if kw is not None:
                md_keywords = etree.SubElement(resident, util.nspath_eval('gmd:descriptiveKeywords', self.namespaces))
                md_keywords.append(write_keywords(kw, self.namespaces))

            # spatial resolution
            val = util.getqattr(result, queryables['apiso:Denominator']['dbcol'])
            if val:
                tmp = etree.SubElement(resident, util.nspath_eval('gmd:spatialResolution', self.namespaces))
                tmp2 = etree.SubElement(tmp, util.nspath_eval('gmd:MD_Resolution', self.namespaces))
                tmp3 = etree.SubElement(tmp2, util.nspath_eval('gmd:equivalentScale', self.namespaces))
                tmp4 = etree.SubElement(tmp3, util.nspath_eval('gmd:MD_RepresentativeFraction', self.namespaces))
                tmp5 = etree.SubElement(tmp4, util.nspath_eval('gmd:denominator', self.namespaces))
                etree.SubElement(tmp5, util.nspath_eval('gco:Integer', self.namespaces)).text = str(val)

            # resource language
            val = util.getqattr(result, queryables['apiso:ResourceLanguage']['dbcol'])
            tmp = etree.SubElement(resident, util.nspath_eval('gmd:language', self.namespaces))
            etree.SubElement(tmp, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val

            # topic category
            val = util.getqattr(result, queryables['apiso:TopicCategory']['dbcol'])
            if val:
                for v in val.split(','):
                    tmp = etree.SubElement(resident, util.nspath_eval('gmd:topicCategory', self.namespaces))
                    etree.SubElement(tmp, util.nspath_eval('gmd:MD_TopicCategoryCode', self.namespaces)).text = val

        # bbox extent
        val = util.getqattr(result, queryables['apiso:BoundingBox']['dbcol'])
        bboxel = write_extent(val, self.namespaces)
        if bboxel is not None and mtype != 'service':
            resident.append(bboxel)

        # service identification

        if mtype == 'service':
            # service type
            # service type version
            val = util.getqattr(result, queryables['apiso:ServiceType']['dbcol'])
            val2 = util.getqattr(result, queryables['apiso:ServiceTypeVersion']['dbcol'])
            if val is not None:
                tmp = etree.SubElement(resident, util.nspath_eval('srv:serviceType', self.namespaces))
                etree.SubElement(tmp, util.nspath_eval('gco:LocalName', self.namespaces)).text = val
                tmp = etree.SubElement(resident, util.nspath_eval('srv:serviceTypeVersion', self.namespaces))
                etree.SubElement(tmp, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val2

            kw = util.getqattr(result, queryables['apiso:Subject']['dbcol'])
            if kw is not None:
                srv_keywords = etree.SubElement(resident, util.nspath_eval('srv:keywords', self.namespaces))
                srv_keywords.append(write_keywords(kw, self.namespaces))
                 
            if bboxel is not None:
                bboxel.tag = util.nspath_eval('srv:extent', self.namespaces)
                resident.append(bboxel)

            val = util.getqattr(result, queryables['apiso:CouplingType']['dbcol'])
            if val is not None:
                couplingtype = etree.SubElement(resident, util.nspath_eval('srv:couplingType', self.namespaces))
                etree.SubElement(couplingtype, util.nspath_eval('srv:SV_CouplingType', self.namespaces), codeListValue=val, codeList='%s#SV_CouplingType' % CODELIST).text = val

            if esn in ['summary', 'full']:
                # all service resources as coupled resources
                coupledresources = util.getqattr(result, queryables['apiso:OperatesOn']['dbcol'])
                operations = util.getqattr(result, queryables['apiso:Operation']['dbcol'])

                if coupledresources:
                    for val2 in coupledresources.split(','):
                        coupledres = etree.SubElement(resident, util.nspath_eval('srv:coupledResource', self.namespaces))
                        svcoupledres = etree.SubElement(coupledres, util.nspath_eval('srv:SV_CoupledResource', self.namespaces))
                        opname = etree.SubElement(svcoupledres, util.nspath_eval('srv:operationName', self.namespaces))
                        etree.SubElement(opname, util.nspath_eval('gco:CharacterString', self.namespaces)).text = _get_resource_opname(operations)
                        sid = etree.SubElement(svcoupledres, util.nspath_eval('srv:identifier', self.namespaces))
                        etree.SubElement(sid, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val2

                # service operations
                if operations:
                    for i in operations.split(','):
                        oper = etree.SubElement(resident, util.nspath_eval('srv:containsOperations', self.namespaces))
                        tmp = etree.SubElement(oper, util.nspath_eval('srv:SV_OperationMetadata', self.namespaces))

                        tmp2 = etree.SubElement(tmp, util.nspath_eval('srv:operationName', self.namespaces))
                        etree.SubElement(tmp2, util.nspath_eval('gco:CharacterString', self.namespaces)).text = i

                        tmp3 = etree.SubElement(tmp, util.nspath_eval('srv:DCP', self.namespaces))
                        etree.SubElement(tmp3, util.nspath_eval('srv:DCPList', self.namespaces), codeList='%s#DCPList' % CODELIST, codeListValue='HTTPGet').text = 'HTTPGet' 

                        tmp4 = etree.SubElement(tmp, util.nspath_eval('srv:DCP', self.namespaces))
                        etree.SubElement(tmp4, util.nspath_eval('srv:DCPList', self.namespaces), codeList='%s#DCPList' % CODELIST, codeListValue='HTTPPost').text = 'HTTPPost' 

                        connectpoint = etree.SubElement(tmp, util.nspath_eval('srv:connectPoint', self.namespaces))
                        onlineres = etree.SubElement(connectpoint, util.nspath_eval('gmd:CI_OnlineResource', self.namespaces))
                        linkage = etree.SubElement(onlineres, util.nspath_eval('gmd:linkage', self.namespaces))
                        etree.SubElement(linkage, util.nspath_eval('gmd:URL', self.namespaces)).text = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Source'])

                # operates on resource(s)
                if coupledresources:
                    for i in coupledresources.split(','):
                        operates_on = etree.SubElement(resident, util.nspath_eval('srv:operatesOn', self.namespaces), uuidref=i)
                        operates_on.attrib[util.nspath_eval('xlink:href', self.namespaces)] = '%sservice=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&id=%s-%s' % (util.bind_url(self.url), idval, i)

        rlinks = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Links'])

        if rlinks:
            distinfo = etree.SubElement(node, util.nspath_eval('gmd:distributionInfo', self.namespaces))
            distinfo2 = etree.SubElement(distinfo, util.nspath_eval('gmd:MD_Distribution', self.namespaces))
            transopts = etree.SubElement(distinfo2, util.nspath_eval('gmd:transferOptions', self.namespaces))
            dtransopts = etree.SubElement(transopts, util.nspath_eval('gmd:MD_DigitalTransferOptions', self.namespaces))

            for link in rlinks.split('^'):
                linkset = link.split(',')
                online = etree.SubElement(dtransopts, util.nspath_eval('gmd:onLine', self.namespaces))
                online2 = etree.SubElement(online, util.nspath_eval('gmd:CI_OnlineResource', self.namespaces))

                linkage = etree.SubElement(online2, util.nspath_eval('gmd:linkage', self.namespaces))
                etree.SubElement(linkage, util.nspath_eval('gmd:URL', self.namespaces)).text = linkset[-1]

                protocol = etree.SubElement(online2, util.nspath_eval('gmd:protocol', self.namespaces))
                etree.SubElement(protocol, util.nspath_eval('gco:CharacterString', self.namespaces)).text = linkset[2]

                name = etree.SubElement(online2, util.nspath_eval('gmd:name', self.namespaces))
                etree.SubElement(name, util.nspath_eval('gco:CharacterString', self.namespaces)).text = linkset[0]

                desc = etree.SubElement(online2, util.nspath_eval('gmd:description', self.namespaces))
                etree.SubElement(desc, util.nspath_eval('gco:CharacterString', self.namespaces)).text = linkset[1]

        return node
コード例 #10
0
ファイル: fgdc.py プロジェクト: arkadijs/pycsw
    def write_record(self, recobj, esn, outputschema, queryables):
        ''' Return csw:SearchResults child as lxml.etree.Element '''
        typename = util.getqattr(recobj, self.context.md_core_model['mappings']['pycsw:Typename'])
        if esn == 'full' and typename == 'fgdc:metadata':
            # dump record as is and exit
            return etree.fromstring(util.getqattr(recobj, self.context.md_core_model['mappings']['pycsw:XML']))

        if typename == 'csw:Record':
            # transform csw:Record -> fgdc:metadata model mappings
            util.transform_mappings(queryables,
            self.repository['mappings']['csw:Record'])

        node = etree.Element('metadata')
        node.attrib[util.nspath_eval('xsi:noNamespaceSchemaLocation', self.context.namespaces)] = \
        'http://www.fgdc.gov/metadata/fgdc-std-001-1998.xsd'

        idinfo = etree.SubElement(node, 'idinfo')
        # identifier
        etree.SubElement(idinfo, 'datasetid').text = util.getqattr(recobj, queryables['fgdc:Identifier']['dbcol'])

        citation = etree.SubElement(idinfo, 'citation')
        citeinfo = etree.SubElement(citation, 'citeinfo')

        # title
        val = util.getqattr(recobj, queryables['fgdc:Title']['dbcol'])
        etree.SubElement(citeinfo, 'title').text = val

        # publisher
        publinfo = etree.SubElement(citeinfo, 'publinfo')
        val = util.getqattr(recobj, queryables['fgdc:Publisher']['dbcol']) or ''
        etree.SubElement(publinfo, 'publish').text = val

        # origin
        val = util.getqattr(recobj, queryables['fgdc:Origin']['dbcol']) or ''
        etree.SubElement(citeinfo, 'origin').text = val

        # keywords
        val = util.getqattr(recobj, queryables['fgdc:ThemeKeywords']['dbcol'])
        if val:
            keywords = etree.SubElement(idinfo, 'keywords')
            theme = etree.SubElement(keywords, 'theme')
            for v in val.split(','):
                etree.SubElement(theme, 'themekey').text = v

        # accessconstraints
        val = util.getqattr(recobj, queryables['fgdc:AccessConstraints']['dbcol']) or ''
        etree.SubElement(idinfo, 'accconst').text = val

        # abstract
        descript = etree.SubElement(idinfo, 'descript')
        val = util.getqattr(recobj, queryables['fgdc:Abstract']['dbcol']) or ''
        etree.SubElement(descript, 'abstract').text = val

        # time
        datebegin = util.getqattr(recobj, queryables['fgdc:BeginDate']['dbcol'])
        dateend = util.getqattr(recobj, queryables['fgdc:EndDate']['dbcol'])
        if all([datebegin, dateend]):
            timeperd = etree.SubElement(idinfo, 'timeperd')
            timeinfo = etree.SubElement(timeperd, 'timeinfo')
            rngdates = etree.SubElement(timeinfo, 'timeinfo')
            begdate = etree.SubElement(rngdates, 'begdate').text = datebegin
            enddate = etree.SubElement(rngdates, 'enddate').text = dateend

        # bbox extent
        val = util.getqattr(recobj, queryables['fgdc:Envelope']['dbcol'])
        bboxel = write_extent(val)
        if bboxel is not None:
            idinfo.append(bboxel)

        # contributor
        val = util.getqattr(recobj, queryables['fgdc:Contributor']['dbcol']) or ''
        etree.SubElement(idinfo, 'datacred').text = val

        # direct
        spdoinfo = etree.SubElement(idinfo, 'spdoinfo')
        val = util.getqattr(recobj, queryables['fgdc:Type']['dbcol']) or ''
        etree.SubElement(spdoinfo, 'direct').text = val

        # formname
        distinfo = etree.SubElement(node, 'distinfo')
        stdorder = etree.SubElement(distinfo, 'stdorder')
        digform = etree.SubElement(stdorder, 'digform')
        digtinfo = etree.SubElement(digform, 'digtinfo')
        val = util.getqattr(recobj, queryables['fgdc:Format']['dbcol']) or ''
        etree.SubElement(digtinfo, 'formname').text = val
        etree.SubElement(citeinfo, 'geoform').text = val

        # source
        lineage = etree.SubElement(node, 'lineage')
        srcinfo = etree.SubElement(lineage, 'srcinfo')
        srccite = etree.SubElement(srcinfo, 'srccite')
        sciteinfo = etree.SubElement(srccite, 'citeinfo')
        val = util.getqattr(recobj, queryables['fgdc:Source']['dbcol']) or ''
        etree.SubElement(sciteinfo, 'title').text = val

        val = util.getqattr(recobj, queryables['fgdc:Relation']['dbcol']) or ''
        etree.SubElement(citeinfo, 'onlink').text = val

        # links
        rlinks = util.getqattr(recobj, self.context.md_core_model['mappings']['pycsw:Links'])
        if rlinks:
            for link in rlinks.split('^'):
                linkset = link.split(',')
                etree.SubElement(citeinfo, 'onlink', type=linkset[2]).text = linkset[-1]

        # metd
        metainfo = etree.SubElement(node, 'metainfo')
        val = util.getqattr(recobj, queryables['fgdc:Modified']['dbcol']) or ''
        etree.SubElement(metainfo, 'metd').text = val

        return node