def __decode_dimension_names()

in collection_manager/collection_manager/entities/Collection.py [0:0]


    def __decode_dimension_names(dimension_names_dict):
        """
        - Validating both `variable` and `variables` are not part of the dictionary
        - if it has `variable`, converting it to single element list
        - if it has `variables`, keeping it as a list while renmaing the key to `variable`
        """
        if 'variable' in dimension_names_dict and 'variables' in dimension_names_dict:
            raise RuntimeError('both variable and variables present in dimensionNames. Only one is allowed')
        new_dimension_names = [(k, v) for k, v in dimension_names_dict.items() if k not in ['variable', 'variables']]
        if 'variable' in dimension_names_dict:
            if not isinstance(dimension_names_dict['variable'], str):
                raise RuntimeError(f'variable in dimensionNames must be string type. value: {dimension_names_dict["variable"]}')
            new_dimension_names.append(('variable', json.dumps(dimension_names_dict['variable'])))
            return new_dimension_names
        if 'variables' in dimension_names_dict:
            if not isinstance(dimension_names_dict['variables'], list):
                raise RuntimeError(f'variable in dimensionNames must be list type. value: {dimension_names_dict["variables"]}')
            new_dimension_names.append(('variable', json.dumps(dimension_names_dict['variables'])))
            return new_dimension_names