diff --git a/wis2box-management/wis2box/data_mappings.py b/wis2box-management/wis2box/data_mappings.py index 6f4deab5..c4782226 100644 --- a/wis2box-management/wis2box/data_mappings.py +++ b/wis2box-management/wis2box/data_mappings.py @@ -63,10 +63,13 @@ def get_data_mappings() -> dict: continue if 'data_mappings' not in record['wis2box']: continue - key = record['wis2box']['topic_hierarchy'] value = record['wis2box']['data_mappings'] - value['metadata_id'] = record['id'] - data_mappings[key] = value + if 'wmo:topicHierarchy' not in record['properties']: + LOGGER.error(f'No topic hierarchy for {record["id"]}') + continue + value['topic_hierarchy'] = record['properties']['wmo:topicHierarchy'] + metadata_id = record['id'] + data_mappings[metadata_id] = value except Exception as err: msg = f'Issue loading data mappings: {err}' LOGGER.error(msg) diff --git a/wis2box-management/wis2box/dataset.py b/wis2box-management/wis2box/dataset.py index fbf82460..90a7de7d 100644 --- a/wis2box-management/wis2box/dataset.py +++ b/wis2box-management/wis2box/dataset.py @@ -25,17 +25,51 @@ from wis2box import cli_helpers from wis2box.data import add_collection +from wis2box.data_mappings import get_data_mappings from wis2box.metadata.discovery import publish, unpublish LOGGER = logging.getLogger(__name__) +class Dataset: + def __init__(self, path: Union[Path, str]) -> None: + self.path = str(path) + self.dotpath = None + self.dirpath = None + + self.metadata_id = None + self.topic_hierarchy = None + + # determine if path matches a metadata_id + for metadata_id, data_mappings in get_data_mappings().items(): + if metadata_id in self.path: + self.metadata_id = metadata_id + self.topic_hierarchy = data_mappings['topic_hierarchy'] + + if self.metadata_id is None: + # otherwise directory represents topic_hierarchy + if not self.path.startswith('origin/a/wis2'): + self.topic_hierarchy = f'origin/a/wis2/{self.path}' + else: + self.topic_hierarchy = self.path + for metadata_id, data_mappings in get_data_mappings().items(): + if self.topic_hierarchy == data_mappings['topic_hierarchy']: + self.metadata_id = metadata_id + + if '/' in self.path: + LOGGER.debug('Transforming from directory to dotted path') + self.dirpath = self.path + self.dotpath = self.path.replace('/', '.') + elif '.' in self.path: + LOGGER.debug('Transforming from dotted to directory path') + self.dotpath = self.path + self.dirpath = self.path.replace('.', '/') + @click.group() def dataset(): """Dataset workflow""" pass - @click.command('publish') @click.pass_context @cli_helpers.ARGUMENT_FILEPATH