Пример #1
0
def _map_dataset_temporals(node):
    geocat_temporal_start = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node,
            path=GMD_TEMPORAL_START)
    geocat_temporal_end = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node,
            path=GMD_TEMPORAL_END)
    return \
        ogdch_map_utils.map_temporals(
            geocat_temporal_start,
            geocat_temporal_end)
Пример #2
0
def _map_dataset_publisher(node, organization_slug):
    publisher_name_node, publisher_name_path = \
        xpath_utils.xpath_get_first_of_values_from_path_list(
            node=node,
            path_list=GMD_PUBLISHER,
            get=xpath_utils.XPATH_NODE)
    if publisher_name_node is None:
        return EMPTY_PUBLISHER
    publisher_name = \
        xpath_utils.xpath_get_one_value_from_geocat_multilanguage_node(
            publisher_name_node
        )
    if isinstance(publisher_name, list):
        publisher_name = publisher_name[0]
    if not publisher_name:
        return EMPTY_PUBLISHER
    geocat_publisher = {'name': publisher_name}
    publisher_url_path = publisher_name_path.replace(GMD_PUBLISHER_NAME, '')
    publisher_url_node = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node,
            publisher_url_path
        )
    publisher_url = xpath_utils.xpath_get_url_from_node(publisher_url_node)
    if publisher_url:
        geocat_publisher['url'] = publisher_url
    return ogdch_map_utils.map_to_ogdch_publisher(geocat_publisher,
                                                  organization_slug)
Пример #3
0
def _map_dataset_description(node):
    description_node = xpath_utils.xpath_get_single_sub_node_for_node_and_path(
        node=node, path=GMD_DESCRIPTION)
    if description_node is not None:
        return xpath_utils.xpath_get_language_dict_from_geocat_multilanguage_node(
            description_node)  # noqa
    return {'en': '', 'it': '', 'de': '', 'fr': ''}
Пример #4
0
def _map_dataset_identifier(node, organization_slug):
    geocat_identifier = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node, path=GMD_IDENTIFIER)
    if geocat_identifier:
        return ogdch_map_utils.map_geocat_to_ogdch_identifier(
            geocat_identifier, organization_slug)
Пример #5
0
def _map_dataset_spatial(node):
    geocat_spatial = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node,
            path=GMD_SPATIAL)
    if geocat_spatial:
        return geocat_spatial
    return ''
Пример #6
0
def _map_dataset_title(node):
    title_node = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node, path=GMD_TITLE)
    if title_node is not None:
        return xpath_utils.xpath_get_language_dict_from_geocat_multilanguage_node(
            title_node)  # noqa
    return {'en': '', 'it': '', 'de': '', 'fr': ''}
Пример #7
0
def _map_dataset_frequency(node):
    geocat_frequency = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node,
            path=GMD_ACCRUAL_PERIODICITY)
    if geocat_frequency:
        accrual_periodicity = ogdch_map_utils.map_frequency(geocat_frequency)
        if accrual_periodicity:
            return accrual_periodicity
    return ''
Пример #8
0
def _map_dataset_rights(node, terms_of_use, default_rights):
    rights_node = \
        xpath_utils.xpath_get_single_sub_node_for_node_and_path(
            node=node,
            path=GMD_RIGHTS)
    if rights_node is not None:
        geocat_rights_dict = \
            xpath_utils.xpath_get_rights_dict_form_rights_node(rights_node)
        if geocat_rights_dict:
            for lang, rights_value in geocat_rights_dict.items():
                rights_literal = Literal(rights_value, lang=lang)
                for rights_uri in terms_of_use.subjects(object=rights_literal):
                    for mapping_object in terms_of_use.objects(
                            predicate=SKOS.mappingRelation,
                            subject=rights_uri):  # noqa
                        ogdch_rights = str(mapping_object)
                        if ogdch_rights:
                            return ogdch_rights
    return default_rights
Пример #9
0
    def _map_resource_onto_dataset(self, dataset_dict, resource_node, rights):
        protocol = \
            xpath_utils.xpath_get_single_sub_node_for_node_and_path(
                node=resource_node, path=GMD_PROTOCOL)

        if not protocol\
                or protocol in self.excluded_protocols:
            return

        if protocol in ogdch_map_utils.get_landing_page_protocols():
            url_with_label = \
                xpath_utils.xpath_get_url_with_label(
                    resource_node)
            if url_with_label:
                if not dataset_dict.get('url'):
                    dataset_dict['url'] = url_with_label.get('url')
                else:
                    dataset_dict['relations'].append(url_with_label)
        elif protocol in ogdch_map_utils.get_additonal_relation_protocols():
            url_with_label = \
                xpath_utils.xpath_get_url_with_label(
                    resource_node)
            if url_with_label:
                dataset_dict['relations'].append(url_with_label)
        else:
            geocat_resource = \
                xpath_utils.xpath_get_distribution_from_distribution_node(
                    resource_node=resource_node,
                    protocol=protocol,
                )
            resource = ogdch_map_utils.map_resource(
                geocat_resource=geocat_resource,
                issued=dataset_dict['issued'],
                modified=dataset_dict['modified'],
                rights=rights,
            )
            dataset_dict['resources'].append(resource)
            for lang in resource.get('language', []):
                if lang not in dataset_dict['language']:
                    dataset_dict['language'].append(lang)
 def test_xpath_get_single_sub_node_for_node_and_path(self):
     path_identifier = './/gmd:fileIdentifier/gco:CharacterString/text()'
     data_identifier = '3143e92b-51fa-40ab-bcc0-fa389807e879'
     value = xpath_utils.xpath_get_single_sub_node_for_node_and_path(path=path_identifier, node=self.root)
     self.assertEqual(value, data_identifier)