Skip to content

Commit

Permalink
Demo MVP EaaSI integration with eaasi-uvi-client
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Mar 18, 2022
1 parent 2060130 commit 9e0b9ca
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- ES_HOSTS=elasticsearch:9200
- CELERY_BROKER_URL=redis://redis:6379
- SS_HOSTS=http://test:test@192.168.1.128:62081
- EAASI_HOST=https://eaas.archivematica.net
volumes:
- node_modules:/src/node_modules
- .:/src
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ django-modeltranslation==0.16.1
django-npm==1.0.0
djangorestframework==3.12.2
django-widget-tweaks==1.4.8
eaasi-uvi-client==0.1.0
elasticsearch==7.13.0
elasticsearch-dsl==7.3.0 # pyup: <8.0
envparse==0.2.0
Expand Down
4 changes: 4 additions & 0 deletions scope/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,7 @@
SS_HOSTS = env(
"SS_HOSTS", cast=list, subcast=str, postprocessor=ss_hosts_parser, default=[]
)

# EaaSI

EAASI_HOST = env("EAASI_HOST")
1 change: 1 addition & 0 deletions scope/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
url(r"^folder/(?P<pk>\d+)/delete/$", views.delete_dip, name="delete_dip"),
url(r"^folder/(?P<pk>\d+)/$", views.dip, name="dip"),
url(r"^folder/(?P<pk>\d+)/download$", views.download_dip, name="download_dip"),
url(r"^folder/(?P<pk>\d+)/recommend$", views.recommend_dip_environments, name="recommend_dip_environments"),
url(r"^object/(?P<pk>[-\w-]+)$", views.digital_file, name="digital_file"),
url(r"^new_folder/", views.new_dip, name="new_dip"),
url(r"^orphan_folders/", views.orphan_dips, name="orphan_dips"),
Expand Down
31 changes: 31 additions & 0 deletions scope/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.shortcuts import redirect
from django.shortcuts import render
from django.utils.translation import gettext as _
from eaasi_uvi_client import EaaSIUVIClient, ResultNotFound

from search.helpers import add_digital_file_aggs
from search.helpers import add_digital_file_filters
Expand Down Expand Up @@ -691,6 +692,36 @@ def download_dip(request, pk):
return response


@login_required(login_url="/login/")
def recommend_dip_environments(request, pk):
dip = get_object_or_404(DIP, pk=pk)
if not django_settings.EAASI_HOST:
raise RuntimeError("Configuration not found for EaaSI host.")
if dip.objectszip:
# TODO: Upload DIP so it's fetchable via URL by EaaSI server.
# For now, we fake it with DATA_URL.
# With a real DIP, how do we make sure that EaaSI is basing its
# recommendations on the actual digital objects, and not e.g. the METS?
DATA_URL = "https://github.com/tw4l/sample-data/blob/main/fmt-38.zip?raw=true"
eaas_client = EaaSIUVIClient(
base_url=django_settings.EAASI_HOST,
data_url=DATA_URL
)
try:
results = eaas_client.get_recommendations()
except (requests.ConnectionError, ResultNotFound) as err:
results = "Error fetching recommendations: {}".format(err)
return render(
request,
"dip_recommendations.html",
{
"dip": dip,
"api_results": results,
},
)
return redirect("dip", pk=pk)


@login_required(login_url="/login/")
def settings(request):
if not request.user.is_superuser:
Expand Down
1 change: 1 addition & 0 deletions templates/dip.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ <h2 class="mb-3">{% trans "Attachments" %}</h2>
</p>
<p>{% trans "By clicking on the button below you'll download all the digital files included in this folder." %}</p>
<a href="{% url 'download_dip' dip.pk %}" class="btn btn-primary">{% trans "Download DIP" %}</a>
<a href="{% url 'recommend_dip_environments' dip.pk %}" class="btn btn-primary">{% trans "Recommend emulation environments" %}</a>
</div>
</div>
</div>
Expand Down
26 changes: 26 additions & 0 deletions templates/dip_recommendations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends 'base.html' %}

{% load custom_tags %}
{% load i18n %}

{% block title %}
{% blocktrans %}Folder {{ dip }} - EaaSI UVI recommendations{% endblocktrans %}
{% endblock %}

{% block content %}
<ol class="breadcrumb">
{% trans "Untitled" as untitled %}
<li class="breadcrumb-item"><a href="{% url 'collections' %}">{% trans "Collections" %}</a></li>
<li class="breadcrumb-item"><a href="{% url 'collection' dip.collection.pk %}">{{ dip.collection.dc.title|default:untitled }}</a></li>
<li class="breadcrumb-item"><a href="{% url 'dip' dip.pk %}">{{ dip.dc.title|default:untitled }}</a></li>
<li class="breadcrumb-item active">{% trans "Emulation environment recommendations" %}</li>
</ol>
<div class="card mt-4">
<div class="card-header">
<h5 class="mb-0">{% trans "EaaSI UVI recommendations" %}</h5>
</div>
<div class="card-body">
<p>{{ api_results }}</p>
</div>
</div>
{% endblock %}

0 comments on commit 9e0b9ca

Please sign in to comment.