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
7 changes: 7 additions & 0 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ class Meta:
)


class GenericResource(ResourceBase):
remote = models.BooleanField(default=False)

#class GenericResourceManager(ResourceBaseManager):
# def __init__(self):
# models.Manager.__init__(self)

class LinkManager(models.Manager):
"""Helper class to access links grouped by type
"""
Expand Down
13 changes: 9 additions & 4 deletions geonode/catalogue/backends/pycsw_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# 'loglevel': 'DEBUG',
# 'logfile': '/tmp/pycsw.log',
# 'federatedcatalogues': 'http://geo.data.gov/geoportal/csw/discovery',
# 'pretty_print': 'true',
'pretty_print': 'true',
# 'domainquerytype': 'range',
'domaincounts': 'true',
'profiles': 'apiso,ebrim',
Expand Down Expand Up @@ -127,10 +127,10 @@ def _csw_local_dispatch(self, keywords=None, start=0, limit=10, bbox=None, ident
os.environ['QUERY_STRING'] = ''

# init pycsw
csw = server.Csw(config)
csw = server.Csw(config, version='2.0.2')

# fake HTTP method
csw.requesttype = 'POST'
csw.requesttype = 'GET'

# fake HTTP request parameters
if identifier is None: # it's a GetRecords request
Expand All @@ -139,6 +139,8 @@ def _csw_local_dispatch(self, keywords=None, start=0, limit=10, bbox=None, ident
formats.append(METADATA_FORMATS[f][0])

csw.kvp = {
'service': 'CSW',
'version': '2.0.2',
'elementsetname': 'full',
'typenames': formats,
'resulttype': 'results',
Expand All @@ -152,7 +154,10 @@ def _csw_local_dispatch(self, keywords=None, start=0, limit=10, bbox=None, ident
response = csw.getrecords()
else: # it's a GetRecordById request
csw.kvp = {
'id': [identifier],
'service': 'CSW',
'version': '2.0.2',
'request': 'GetRecordById',
'id': identifier,
'outputschema': 'http://www.isotc211.org/2005/gmd',
}
# FIXME(Ariel): Remove this try/except block when pycsw deals with
Expand Down
6 changes: 3 additions & 3 deletions geonode/catalogue/backends/pycsw_local_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'pycsw:Keywords': 'keyword_csv',
'pycsw:KeywordType': 'keywordstype',
'pycsw:Format': 'spatial_representation_type_string',
'pycsw:Source': 'source',
'pycsw:Source': 'csw_mdsource',
'pycsw:Date': 'date',
'pycsw:Modified': 'date',
'pycsw:Type': 'csw_type',
Expand Down Expand Up @@ -64,8 +64,8 @@
'pycsw:OperatesOnIdentifier': 'operatesonidentifier',
'pycsw:OperatesOnName': 'operatesoname',
'pycsw:Degree': 'degree',
'pycsw:AccessConstraints': 'accessconstraints',
'pycsw:OtherConstraints': 'otherconstraints',
'pycsw:AccessConstraints': 'restriction_code_type',
'pycsw:OtherConstraints': 'constraints_other',
'pycsw:Classification': 'classification',
'pycsw:ConditionApplyingToAccessAndUse': 'conditionapplyingtoaccessanduse',
'pycsw:Lineage': 'lineage',
Expand Down
6 changes: 6 additions & 0 deletions geonode/catalogue/templates/catalogue/csw-2.0.2-exception.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" language="en-US" version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="NoApplicationCode" locator="request">
<ows:ExceptionText>{{ exception_text }}</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
33 changes: 30 additions & 3 deletions geonode/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import json
import os
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.views.decorators.csrf import csrf_exempt
from pycsw import server
Expand All @@ -38,17 +38,44 @@ def csw_global_dispatch(request):
if settings.CATALOGUE['default']['ENGINE'] != 'geonode.catalogue.backends.pycsw_local':
return HttpResponseRedirect(settings.CATALOGUE['default']['URL'])

# TODO: add logic for authentication/authorization
#
# msg = None
#
# if any(word in request.body for word in ['Harvest ', 'Transaction ']):
# if not SOME_AUTHENTICATED_TEST:
# msg = 'Not authenticated'
# if not SOME_AUTHORIZATION_TEST:
# msg = 'Not authorized'
#
# if msg is not None:
# template = loader.get_template('catalogue/csw-2.0.2-exception.xml')
# context = RequestContext(request, {
# 'exception_text': msg
# })
# response = HttpResponseForbidden(template.render(context), content_type='application/xml')

mdict = dict(settings.PYCSW['CONFIGURATION'], **CONFIGURATION)

env = request.META.copy()
env.update({'local.app_root': os.path.dirname(__file__),
'REQUEST_URI': request.build_absolute_uri()})

csw = server.Csw(mdict, env)
csw = server.Csw(mdict, env, version='2.0.2')

content = csw.dispatch_wsgi()

return HttpResponse(content, content_type=csw.contenttype)
# pycsw 2.0 has an API break:
# pycsw < 2.0: content = xml_response
# pycsw >= 2.0: content = [http_status_code, content]
# deal with the API break
if isinstance(content, list): # pycsw 2.0+
content = content[1]

response = HttpResponse(content, content_type=csw.contenttype)

response['Access-Control-Allow-Origin'] = '*'
return response


@csrf_exempt
Expand Down
8 changes: 7 additions & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@
'contact_name': 'Organization Name',
'contact_email': 'Email Address',
'temp_extent': 'YYYY-MM-DD/YYYY-MM-DD',
},
'manager': {
# authentication/authorization is handled by Django
'transactions': 'true',
'allowed_ips': '*',
#'csw_harvest_pagesize=10',
}
}
}
Expand Down Expand Up @@ -932,4 +938,4 @@
}
baselayers = MAP_BASELAYERS
MAP_BASELAYERS = [LOCAL_GEOSERVER]
MAP_BASELAYERS.extend(baselayers)
MAP_BASELAYERS.extend(baselayers)