Skip to content

Commit

Permalink
feat: Get Url and languages for_data_model
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalch committed Nov 15, 2023
1 parent 2117635 commit 014b089
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
13 changes: 5 additions & 8 deletions ckanext/geocat/utils/csw_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@

EMPTY_PUBLISHER = {'url': '', 'name': ''}

CHE_CONFORMS_TO = '//che:CHE_MD_Metadata/gmd:contentInfo/che:CHE_MD_FeatureCatalogueDescription/che:dataModel/che:PT_FreeURL/che:URLGroup/che:LocalisedURL/text()' # noqa


class GeoMetadataMapping(object):

Expand Down Expand Up @@ -427,9 +425,8 @@ def _map_dataset_rights(node, terms_of_use, default_rights):
return default_rights


def _map_dataset_conforms_to(node):
geocat_conforms_to = \
xpath_utils.xpath_get_all_values_for_node_and_path_list(
node=node,
path_list=CHE_CONFORMS_TO)
return geocat_conforms_to
def _map_dataset_conforms_to(node, dataset_dict):
conforms_to_url, conforms_to_language = \
xpath_utils.xpath_get_url_and_languages_for_data_model(
node=node)
return conforms_to_url
32 changes: 32 additions & 0 deletions ckanext/geocat/utils/xpath_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
'.//che:LocalisedURL/text()',
'.//gmd:URL/text()',
]

CHE_DATA_MODEL_NODE = './/gmd:contentInfo/che:CHE_MD_FeatureCatalogueDescription/che:dataModel/text()'
CONFORMS_TO_URL_PATH_LIST = [
'.//che:PT_FreeURL/che:URLGroup/che:LocalisedURL[@locale="#DE"]/text()',
'.//che:PT_FreeURL/che:URLGroup/che:LocalisedURLL[@locale="#FR"]/text()',
'.//che:PT_FreeURL/che:URLGroup/che:LocalisedURL[@locale="#EN"]/text()',
'.//che:PT_FreeURL/che:URLGroup/che:LocalisedURL[@locale="#IT"]/text()',
'.//che:PT_FreeURL/che:URLGroup/che:LocalisedURL/text()',
]

GMD_RESOURCE_NAME = './/gmd:name'
GMD_RESOURCE_DESCRIPTION = './/gmd:description'

Expand Down Expand Up @@ -162,6 +172,28 @@ def xpath_get_url_and_languages(node):
return url, languages


def xpath_get_url_and_languages_for_data_model(node):
languages = []

data_model_node = \
xpath_get_all_sub_nodes_for_node_and_path(
node=node, path=CHE_DATA_MODEL_NODE)

if data_model_node:
url, _ = xpath_get_first_of_values_from_path_list(
node=data_model_node,
path_list=CONFORMS_TO_URL_PATH_LIST)

for locale in LOCALES:
value_locale = \
node.xpath('.//che:LocalisedURL[@locale="#{}"]'
.format(locale) + '/text()',
namespaces=gmd_namespaces)
if value_locale:
languages.append(locale.lower())
return url, languages


def xpath_get_rights_dict_form_rights_node(node):
rights_dict = {'en': '', 'it': '', 'de': '', 'fr': ''}
try:
Expand Down

0 comments on commit 014b089

Please sign in to comment.