Exemplo n.º 1
0
 def get_value(self, **kwargs):
     self.env.update(kwargs)
     sub_attributes = self.env.get("sub_attributes", [])
     value = []
     for xml_elem in loader.xpath(self.env["xml"], self._config):  # noqa
         sub_values = []
         kwargs["xml"] = xml_elem
         for sub in sub_attributes:
             sub_values.append(sub.get_value(**kwargs))
         value.append(sub_values)
     return value
Exemplo n.º 2
0
    def get_metadata(self, xml):
        dataset = GeocatDcatDatasetMetadata()
        dataset_meta = dataset.load(xml)

        # add media_type to dataset metadata
        dataset_meta['media_type'] = ''
        try:
            service_media_type = loader.xpath(xml, '//gmd:identificationInfo//srv:serviceType/gco:LocalName/text()')  # noqa
            dist_media_type = loader.xpath(xml, '//gmd:distributionInfo//gmd:distributionFormat//gmd:name//gco:CharacterString/text()')  # noqa

            if service_media_type:
                dataset_meta['media_type'] = service_media_type[0]
            if dist_media_type:
                dataset_meta['media_type'] = dist_media_type[0]
        except IndexError:
            pass

        distributions = []

        # handle downloads
        download_dist = GeocatDcatDownloadDistributionMetdata()
        for dist_xml in loader.xpath(xml, '//gmd:distributionInfo/gmd:MD_Distribution//gmd:transferOptions//gmd:CI_OnlineResource[.//gmd:protocol/gco:CharacterString/text() = "WWW:DOWNLOAD-1.0-http--download" or .//gmd:protocol/gco:CharacterString/text() = "WWW:DOWNLOAD-URL"]'):  # noqa
            dist = download_dist.get_metadata(dist_xml, dataset_meta)
            distributions.append(dist)

        # handle services
        service_dist = GeocatDcatServiceDistributionMetdata()
        for dist_xml in loader.xpath(xml, '//gmd:distributionInfo/gmd:MD_Distribution//gmd:transferOptions//gmd:CI_OnlineResource[.//gmd:protocol/gco:CharacterString/text() = "OGC:WMTS-http-get-capabilities" or .//gmd:protocol/gco:CharacterString/text() = "OGC:WMS-http-get-map" or .//gmd:protocol/gco:CharacterString/text() = "OGC:WMS-http-get-capabilities" or .//gmd:protocol/gco:CharacterString/text() = "OGC:WFS-http-get-capabilities"]'):  # noqa
            dist = service_dist.get_metadata(dist_xml, dataset_meta)
            distributions.append(dist)

        # handle service datasets
        service_dataset = GeocatDcatServiceDatasetMetadata()
        for dist_xml in loader.xpath(xml, '//gmd:identificationInfo//srv:containsOperations/srv:SV_OperationMetadata[.//srv:operationName//gco:CharacterString/text()]'):  # noqa
            dist = service_dataset.get_metadata(dist_xml, dataset_meta)
            distributions.append(dist)

        return distributions
Exemplo n.º 3
0
 def get_element(self, xml, xpath):
     return loader.xpath(xml, xpath)
Exemplo n.º 4
0
 def get_element(self, xml, xpath):
     result = loader.xpath(xml, xpath)
     if len(result) > 0:
         return result[0]
     return []