Skip to content

Commit

Permalink
fix the custom datalink semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
kimakan committed Dec 19, 2023
1 parent 2886e85 commit 10b6b5b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 25 deletions.
7 changes: 4 additions & 3 deletions daiquiri/core/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,11 @@
}

SETTINGS_EXPORT = [
'LOGIN_URL',
'LOGOUT_URL',
'ACCOUNT_LOGOUT_ON_GET',
'AUTH_WORKFLOW',
'AUTH_TERMS_OF_USE',
'SITE_PUBLISHER',
'LOGIN_URL',
'LOGOUT_URL',
'METADATA_COLUMN_PERMISSIONS',
'QUERY_DROPDOWN_FUNCTIONS',
'QUERY_DROPDOWNS',
Expand All @@ -223,6 +222,8 @@
'QUERY_DOWNLOADS',
'QUERY_DOWNLOAD_FORMATS',
'QUERY_UPLOAD',
'SITE_PUBLISHER',
'SITE_URL',
'STATS_RESOURCE_TYPES'
]

Expand Down
38 changes: 17 additions & 21 deletions daiquiri/datalink/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,34 @@ def get_datalink_rows(self, identifiers, **kwargs):
'''Get the list of datalink entries for the provided identifiers (incl. table- and dynamic- datalink)
'''


# get the datalink entries from Datalink Table and metadata (Table and Schema)
field_names = [field['name'] for field in DATALINK_FIELDS]
rows = list(Datalink.objects.filter(ID__in=identifiers).values_list(*field_names))
static_datalink_rows = list(Datalink.objects.filter(ID__in=identifiers).values())

# get the dynamic datalink entries
dyn_datalink_rows = self.get_dyn_datalink_links(identifiers)
datalink_rows = static_datalink_rows + dyn_datalink_rows


# create a full URI for the custom semantics
for row in datalink_rows:
if row['semantics'] in settings.DATALINK_CUSTOM_SEMANTICS:
row['semantics'] = settings.SITE_URL + reverse('datalink:datalink-semantics') + row['semantics']

field_names = [field['name'] for field in DATALINK_FIELDS]

try:
dyn_rows = [(
link['ID'],
link['access_url'],
link['service_def'],
link['error_message'],
link['description'],
link['semantics'],
link['content_type'],
link['content_length']) for link in self.get_dyn_datalink_links(identifiers)
]

# in case of malformation give some hints to the developper
rows = [[link[key] for key in field_names] for link in datalink_rows]
except KeyError as e:
class_name = str(self.__class__)
raise KeyError(f"The key '{e.args[0]}' is missing in one of the dictionaries returned by {class_name}.get_dyn_datalink_links(id)")

# otherwise just raise
raise KeyError(f"The key '{e.args[0]}' is missing in one of the dictionaries returned by {class_name}.get_dyn_datalink_links(id) or in the Datalnk model.")
except Exception as e:
raise e

rows = rows + dyn_rows

# check for missing IDs and return error message
for identifier in identifiers:
if not any(filter(lambda row: row[0] == identifier, rows)):
rows.append((identifier, None, None, 'NotFoundFault: {}'.format(identifier), None, None, None, None))
if not any(filter(lambda row: row[0] == identifier, rows)):
rows.append((identifier, None, None, 'NotFoundFault: {}'.format(identifier), None, None, None, None))

return rows

Expand Down
4 changes: 4 additions & 0 deletions daiquiri/datalink/settings.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
DATALINK_ADAPTER = 'daiquiri.datalink.adapter.DefaultDatalinkAdapter'
DATALINK_TABLES = []

DATALINK_CUSTOM_SEMANTICS = {
"#doi": "The access_url points to the Digital Object Identifier (DOI) of the object.",
}
31 changes: 31 additions & 0 deletions daiquiri/datalink/templates/datalink/datalink-semantics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends 'core/wide.html' %}
{% load i18n %}

{% block wide %}

<h1>The extension to the Datalink-core dictionary</h1>

<table class="table table-condensed table-striped">

<thead>
<tr>
<td><b>Term</b></td>
<td><b>Description</b></td>
</tr>
</thead>

<tbody>

{% for semantics, description in custom_semantics.items %}
<tr>

<td>{{ settings.SITE_URL }}{% url 'datalink:datalink-semantics' %}{{ semantics }}</td>
<td>{{ description }}</td>
</tr>

{% endfor %}

</tbody>

</table>
{% endblock %}
3 changes: 2 additions & 1 deletion daiquiri/datalink/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.urls import include, path, re_path
from django.views.generic import TemplateView

from .views import availability, capabilities, datalink
from .views import availability, capabilities, datalink, datalink_semantics
from .viewsets import SyncDatalinkJobViewSet

app_name = 'datalink'
Expand All @@ -12,6 +12,7 @@

urlpatterns = [
path('', TemplateView.as_view(template_name='datalink/root.html'), name='root'),
path('semantics', datalink_semantics, name='datalink-semantics'),
path('<path:ID>/', datalink, name='datalink'),
path('availability', availability, name='availability'),
path('capabilities', capabilities, name='capabilities'),
Expand Down
5 changes: 5 additions & 0 deletions daiquiri/datalink/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
from daiquiri.core.renderers.vosi import AvailabilityRenderer, CapabilitiesRenderer

from .adapter import DatalinkAdapter
from .settings import DATALINK_CUSTOM_SEMANTICS
from .vo import get_availability, get_capabilities


def datalink(request, ID):
adapter = DatalinkAdapter()
context = adapter.get_context_data(request, ID=ID)
context['custom_semantics'] = DATALINK_CUSTOM_SEMANTICS
return render(request, 'datalink/datalink.html', context)

def datalink_semantics(request):
context = { 'custom_semantics': DATALINK_CUSTOM_SEMANTICS }
return render(request, 'datalink/datalink-semantics.html', context)

def availability(request):
return HttpResponse(AvailabilityRenderer().render(get_availability()), content_type="application/xml")
Expand Down

0 comments on commit 10b6b5b

Please sign in to comment.