Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions geonode/catalogue/backends/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,37 @@
from geonode.catalogue.backends.base import BaseCatalogueBackend
from geonode.metadata.manager import metadata_manager


logger = logging.getLogger(__name__)

TIMEOUT = 10

METADATA_FORMATS = {
"Atom": ("atom:entry", "http://www.w3.org/2005/Atom"),
"DIF": ("dif:DIF", "http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/"),
"Dublin Core": ("csw:Record", "http://www.opengis.net/cat/csw/2.0.2"),
"ebRIM": ("rim:RegistryObject", "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0"),
"FGDC": ("fgdc:metadata", "http://www.opengis.net/cat/csw/csdgm"),
"ISO": ("gmd:MD_Metadata", "http://www.isotc211.org/2005/gmd"),
"ISO19115-3_2018": ("mdb:MD_Metadata", "http://standards.iso.org/iso/19115/-3/mdb/2.0")
}


class Catalogue(CatalogueServiceWeb):
class DefaultMetadataFormatMixin:
@property
def default_format(self):
return settings.CATALOGUE_DEFAULT_FORMAT

@property
def default_root_node(self):
return METADATA_FORMATS[settings.CATALOGUE_DEFAULT_FORMAT][0]

@property
def default_schema(self):
return METADATA_FORMATS[settings.CATALOGUE_DEFAULT_FORMAT][1]


class Catalogue(CatalogueServiceWeb, DefaultMetadataFormatMixin):
def __init__(self, *args, **kwargs):
self.url = kwargs["URL"]
self.user = None
Expand Down Expand Up @@ -180,7 +197,7 @@ def search(self, keywords, startposition, maxrecords, bbox):
constraints=dataset_query_like + bbox_query,
startposition=startposition,
maxrecords=maxrecords,
outputschema="http://www.isotc211.org/2005/gmd",
outputschema=self.default_schema,
esn="full",
)

Expand Down Expand Up @@ -226,7 +243,7 @@ def metadatarecord2dict(self, rec):
# construct the link to the Catalogue metadata record (not
# self-indexed)
result["metadata_links"] = [
("text/xml", "ISO", self.url_for_uuid(rec.identifier, "http://www.isotc211.org/2005/gmd"))
("text/xml", self.default_format, self.url_for_uuid(rec.identifier, self.default_schema))
]

return result
Expand Down Expand Up @@ -255,7 +272,7 @@ def extract_links(self, rec):
return links


class CatalogueBackend(BaseCatalogueBackend):
class CatalogueBackend(BaseCatalogueBackend, DefaultMetadataFormatMixin):
def __init__(self, *args, **kwargs):
self.catalogue = Catalogue(*args, **kwargs)

Expand Down Expand Up @@ -302,6 +319,6 @@ def create_record(self, item):
record = self.catalogue.get_by_uuid(item.uuid)
if record is None:
md_link = self.catalogue.create_from_dataset(item)
item.metadata_links = [("text/xml", "ISO", md_link)]
item.metadata_links = [("text/xml", self.default_format, md_link)]
else:
self.catalogue.update_dataset(item)
5 changes: 2 additions & 3 deletions geonode/catalogue/backends/pycsw_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
#
#########################################################################

from geonode.catalogue.backends.generic import CatalogueBackend as GenericCatalogueBackend

from geonode.catalogue.backends.generic import CatalogueBackend as GenericCatalogueBackend, METADATA_FORMATS

class CatalogueBackend(GenericCatalogueBackend):
"""pycsw HTTP CSW backend"""

def __init__(self, *args, **kwargs):
"""initialize pycsw HTTP CSW backend"""
GenericCatalogueBackend.__init__(CatalogueBackend, self, *args, **kwargs)
self.catalogue.formats = ["Atom", "DIF", "Dublin Core", "ebRIM", "FGDC", "ISO"]
self.catalogue.formats = list(METADATA_FORMATS.keys())
20 changes: 14 additions & 6 deletions geonode/catalogue/backends/pycsw_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@
import os
from owslib.etree import etree as dlxml
from django.conf import settings
from owslib.iso import MD_Metadata
from pycsw import server
from geonode.catalogue.backends.generic import CatalogueBackend as GenericCatalogueBackend
from geonode.catalogue.backends.generic import METADATA_FORMATS
from shapely.errors import ShapelyError

match settings.CATALOGUE_DEFAULT_FORMAT:
case "ISO":
from owslib.iso import MD_Metadata
case "ISO19115-3_2018":
from owslib.iso3 import MD_Metadata
case _:
raise ValueError(f"Unsuported metadata format: {settings.CATALOGUE_DEFAULT_FORMAT}")


true_value = "true"
false_value = "false"
if settings.DATABASES["default"]["ENGINE"].endswith(
Expand Down Expand Up @@ -66,7 +74,7 @@
class CatalogueBackend(GenericCatalogueBackend):
def __init__(self, *args, **kwargs):
GenericCatalogueBackend.__init__(CatalogueBackend, self, *args, **kwargs)
self.catalogue.formats = ["Atom", "DIF", "Dublin Core", "ebRIM", "FGDC", "ISO"]
self.catalogue.formats = list(METADATA_FORMATS.keys())
self.catalogue.local = True

def remove_record(self, uuid):
Expand All @@ -80,7 +88,7 @@ def get_record(self, uuid):
if len(results) < 1:
return None

result = dlxml.fromstring(results).find("{http://www.isotc211.org/2005/gmd}MD_Metadata")
result = dlxml.fromstring(results).find("{%s}MD_Metadata" % self.default_schema)

if result is None:
return None
Expand All @@ -103,7 +111,7 @@ def search_records(self, keywords, start, limit, bbox):
e = dlxml.fromstring(lresults)

self.catalogue.records = [
MD_Metadata(x) for x in e.findall("//{http://www.isotc211.org/2005/gmd}MD_Metadata")
MD_Metadata(x) for x in e.findall("//{%s}MD_Metadata" % self.default_schema)
]

# build results into JSON for API
Expand Down Expand Up @@ -150,7 +158,7 @@ def _csw_local_dispatch(self, keywords=None, start=0, limit=10, bbox=None, ident
"typenames": formats,
"resulttype": "results",
"constraintlanguage": "CQL_TEXT",
"outputschema": "http://www.isotc211.org/2005/gmd",
"outputschema": self.default_schema,
"constraint": None,
"startposition": start,
"maxrecords": limit,
Expand All @@ -162,7 +170,7 @@ def _csw_local_dispatch(self, keywords=None, start=0, limit=10, bbox=None, ident
"version": "2.0.2",
"request": "GetRecordById",
"id": identifier,
"outputschema": "http://www.isotc211.org/2005/gmd",
"outputschema": self.default_schema,
}
# FIXME(Ariel): Remove this try/except block when pycsw deals with
# empty geometry fields better.
Expand Down
8 changes: 7 additions & 1 deletion geonode/catalogue/backends/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from geonode.catalogue.views import csw_global_dispatch
from django.test import TestCase
from django.conf import settings
from urllib.parse import urlencode

from .generic import METADATA_FORMATS


SCHEMA = urlencode(METADATA_FORMATS[settings.CATALOGUE_DEFAULT_FORMAT][1])

pycsw_settings = settings.PYCSW.copy()
pycsw_settings_all = settings.PYCSW.copy()
Expand Down Expand Up @@ -50,7 +56,7 @@ def test_if_pycsw_filter_is_set_should_return_all_datasets_map_doc(self):
def __request_factory():
factory = RequestFactory()
url = "http://localhost:8000/catalogue/csw?request=GetRecords"
url += "&service=CSW&version=2.0.2&outputschema=http%3A%2F%2Fwww.isotc211.org%2F2005%2Fgmd"
url += f"&service=CSW&version=2.0.2&outputschema={SCHEMA}"
url += "&elementsetname=brief&typenames=csw:Record&resultType=results"
request = factory.get(url)

Expand Down
8 changes: 7 additions & 1 deletion geonode/catalogue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ def catalogue_post_save(instance, sender, **kwargs):
LOGGER.exception(e)
csw_anytext = ""

resources.update(metadata_xml=md_doc, csw_wkt_geometry=instance.geographic_bounding_box, csw_anytext=csw_anytext)
resources.update(
csw_typename=catalogue.default_root_node,
csw_schema=catalogue.default_schema,
metadata_xml=md_doc,
csw_wkt_geometry=instance.geographic_bounding_box,
csw_anytext=csw_anytext
)


if "geonode.catalogue" in settings.INSTALLED_APPS:
Expand Down
Loading
Loading