Skip to content

Commit

Permalink
Add METS download link to AIP page. (#46)
Browse files Browse the repository at this point in the history
Adds a METS download link to the AIP detail page.
  • Loading branch information
mcantelon committed Sep 8, 2023
1 parent a315d91 commit 43c2144
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AIPscan/Reporter/templates/aip.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
Originals: {{ original_file_count }}
<br>
Preservation copies: {{ preservation_file_count }}
<br>
<a href="{{ url_for('reporter.download_mets', aip_id=aip.id) }}">Download METS</a>
</div>

<h3>Original files</h3>
Expand Down
26 changes: 25 additions & 1 deletion AIPscan/Reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from datetime import datetime

from flask import jsonify, make_response, render_template, request, session
from flask import jsonify, make_response, render_template, request, session, Response
import requests

from AIPscan.models import (
AIP,
Expand Down Expand Up @@ -38,6 +39,7 @@
sort_puids,
)
from AIPscan.Reporter.helpers import get_premis_xml_lines
from AIPscan.Aggregator.task_helpers import get_mets_url


def _get_storage_service(storage_service_id):
Expand Down Expand Up @@ -272,3 +274,25 @@ def update_dates():
req = request.get_json()
session["end_date"] = request.json.get("end_date")
return make_response(jsonify(req), 200)


@reporter.route("/download_mets/<aip_id>", methods=["GET"])
def download_mets(aip_id):
aip = AIP.query.get(aip_id)
storage_service = StorageService.query.get(aip.storage_service_id)

Check warning on line 282 in AIPscan/Reporter/views.py

View check run for this annotation

Codecov / codecov/patch

AIPscan/Reporter/views.py#L281-L282

Added lines #L281 - L282 were not covered by tests

api_url = {

Check warning on line 284 in AIPscan/Reporter/views.py

View check run for this annotation

Codecov / codecov/patch

AIPscan/Reporter/views.py#L284

Added line #L284 was not covered by tests
"baseUrl": storage_service.url,
"userName": storage_service.user_name,
"apiKey": storage_service.api_key,
}

mets_response = requests.get(

Check warning on line 290 in AIPscan/Reporter/views.py

View check run for this annotation

Codecov / codecov/patch

AIPscan/Reporter/views.py#L290

Added line #L290 was not covered by tests
get_mets_url(api_url, aip.uuid, f"{aip.transfer_name}-{aip.uuid}/data/METS.{aip.uuid}.xml")
)

headers = {

Check warning on line 294 in AIPscan/Reporter/views.py

View check run for this annotation

Codecov / codecov/patch

AIPscan/Reporter/views.py#L294

Added line #L294 was not covered by tests
"Content-Disposition": f'attachment; filename="METS-{aip.uuid}.xml"',
"Content-length": len(mets_response.content)
}
return Response(mets_response.content, mets_response.status_code, headers)

Check warning on line 298 in AIPscan/Reporter/views.py

View check run for this annotation

Codecov / codecov/patch

AIPscan/Reporter/views.py#L298

Added line #L298 was not covered by tests

0 comments on commit 43c2144

Please sign in to comment.