diff --git a/src/datadoc/backend/datadoc_metadata.py b/src/datadoc/backend/datadoc_metadata.py index 6f394800..9b372142 100644 --- a/src/datadoc/backend/datadoc_metadata.py +++ b/src/datadoc/backend/datadoc_metadata.py @@ -24,6 +24,8 @@ from datadoc.enums import Assessment from datadoc.enums import DataSetState from datadoc.enums import DataSetStatus +from datadoc.enums import LanguageStringType +from datadoc.enums import LanguageStringTypeItem from datadoc.frontend.fields.display_dataset import ( OBLIGATORY_DATASET_METADATA_IDENTIFIERS, ) @@ -81,7 +83,6 @@ def _open_path(path: str) -> pathlib.Path | CloudPath: if path.startswith(GSPath.cloud_prefix): client = GSClient(credentials=AuthClient.fetch_google_credentials()) return GSPath(path, client=client) - return pathlib.Path(path) def _set_variable_uuid(self) -> None: @@ -97,7 +98,6 @@ def extract_metadata_from_files(self) -> None: """ if self.metadata_document is not None and self.metadata_document.exists(): self.extract_metadata_from_existing_document(self.metadata_document) - if ( self.dataset_path is not None and self.dataset == model.Dataset() @@ -112,9 +112,7 @@ def extract_metadata_from_files(self) -> None: v.variable_role = model.VariableRole.MEASURE if v.direct_person_identifying is None: v.direct_person_identifying = False - self._set_variable_uuid() - if not self.dataset.id: self.dataset.id = uuid.uuid4() self.variables_lookup = {v.short_name: v for v in self.variables} @@ -169,11 +167,9 @@ def extract_metadata_from_dataset( """ self.ds_schema: DatasetParser = DatasetParser.for_file(dataset) dapla_dataset_path_info = DaplaDatasetPathInfo(dataset) - subject_field = self._statistic_subject_mapping.get_secondary_subject( dapla_dataset_path_info.statistic_short_name, ) - self.dataset = model.Dataset( short_name=dapla_dataset_path_info.dataset_short_name, dataset_state=dapla_dataset_path_info.dataset_state, @@ -187,6 +183,7 @@ def extract_metadata_from_dataset( file_path=str(self.dataset_path), metadata_created_by=user_info.get_user_info_for_current_platform().short_email, subject_field=subject_field, + spatial_coverage_description=self.set_default_spatial_coverage_description(), ) self.variables = self.ds_schema.get_fields() @@ -263,3 +260,14 @@ def percent_complete(self) -> int: ], ) return calculate_percentage(num_set_fields, num_all_fields) + + def set_default_spatial_coverage_description(self) -> LanguageStringType: + """Returns the default value 'Norge'.""" + return LanguageStringType( + [ + LanguageStringTypeItem( + languageCode="nb", + languageText="Norge", + ), + ], + ) diff --git a/tests/backend/test_datadoc_metadata.py b/tests/backend/test_datadoc_metadata.py index f93ad209..4efb6197 100644 --- a/tests/backend/test_datadoc_metadata.py +++ b/tests/backend/test_datadoc_metadata.py @@ -432,3 +432,9 @@ def test_existing_metadata_variables_valid_id( post_write_id: list = [v["id"] for v in json.load(f)["datadoc"]["variables"]] assert pre_open_id == post_write_id + + +def test_default_spatial_coverage_description(metadata: DataDocMetadata): + metadata.extract_metadata_from_dataset(TEST_PARQUET_FILEPATH) + language_strings = metadata.dataset.spatial_coverage_description + assert language_strings.root[0].languageText == "Norge" # type: ignore [union-attr, index]