diff --git a/odp/catalog/mims.py b/odp/catalog/mims.py index 79fe29a..0f7ea86 100644 --- a/odp/catalog/mims.py +++ b/odp/catalog/mims.py @@ -35,6 +35,7 @@ def evaluate_record( cannot_publish_reasons += ['not a MIMS collection'] def create_published_record(self, record_model: RecordModel) -> PublishedRecordModel: + """Create the published form of a record.""" published_record: PublishedSAEONRecordModel = super().create_published_record(record_model) # add related identifiers for published child records to @@ -74,6 +75,7 @@ def create_published_record(self, record_model: RecordModel) -> PublishedRecordM def _create_jsonld_metadata( self, published_record: PublishedSAEONRecordModel ) -> dict[str, Any]: + """Create a JSON-LD metadata dictionary, using the schema.org vocabulary.""" mims_catalog = Session.get(Catalog, self.catalog_id) datacite_metadata = self._get_metadata_dict(published_record, ODPMetadataSchema.SAEON_DATACITE4) @@ -110,23 +112,25 @@ def _create_jsonld_metadata( "url": url, } - if box := next( + # Create a GeoShape box from DataCite geoLocationBox, because currently + # we only use bounding boxes in our metadata. If in future we ever use + # geoLocationPolygons, then this code will need to be adapted. + if geolocation_box := next( (g.get('geoLocationBox') for g in datacite_metadata.get('geoLocations', ())), None ): - polygon = ( - f'{box["southBoundLatitude"]},{box["westBoundLongitude"]} ' - f'{box["southBoundLatitude"]},{box["eastBoundLongitude"]} ' - f'{box["northBoundLatitude"]},{box["eastBoundLongitude"]} ' - f'{box["northBoundLatitude"]},{box["westBoundLongitude"]} ' - f'{box["southBoundLatitude"]},{box["westBoundLongitude"]}' + box = ( + f'{geolocation_box["southBoundLatitude"]} ' + f'{geolocation_box["westBoundLongitude"]} ' + f'{geolocation_box["northBoundLatitude"]} ' + f'{geolocation_box["eastBoundLongitude"]}' ) jsonld_metadata |= { "spatialCoverage": { "@type": "Place", "geo": { "@type": "GeoShape", - "polygon": polygon + "box": box, }, }, } diff --git a/test/api/test_catalog.py b/test/api/test_catalog.py index 70469b0..722f9e6 100644 --- a/test/api/test_catalog.py +++ b/test/api/test_catalog.py @@ -213,8 +213,6 @@ def test_redirect_to( metadata_examples = { 'SAEON.DataCite4': datacite4_example(), 'SAEON.ISO19115': iso19115_example(), -} -metadata_examples |= { 'SchemaOrg.Dataset': { '@context': 'https://schema.org/', '@type': 'Dataset', @@ -229,7 +227,7 @@ def test_redirect_to( '@type': 'Place', 'geo': { '@type': 'GeoShape', - 'polygon': '-34.4,17.9 -34.4,18.3 -34.0,18.3 -34.0,17.9 -34.4,17.9' + 'box': '-34.4 17.9 -34.0 18.3', } } },