Skip to content

Commit

Permalink
Add PREMIS Object XML to files
Browse files Browse the repository at this point in the history
Adds display of PREMIS object XML, if populated, when viewing files.
  • Loading branch information
tw4l authored and mcantelon committed Jan 17, 2023
1 parent d07b15c commit d7e9566
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
19 changes: 17 additions & 2 deletions AIPscan/Aggregator/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from celery.utils.log import get_task_logger
from lxml import etree

from AIPscan import db
from AIPscan.Aggregator import tasks
Expand Down Expand Up @@ -57,8 +58,7 @@ def _extract_event_detail(premis_event, file_id):


def _create_agent_type_id(identifier_type, identifier_value):
"""Create a key-pair string for the linking_type_value in the db.
"""
"""Create a key-pair string for the linking_type_value in the db."""
return "{}-{}".format(identifier_type, identifier_value)


Expand Down Expand Up @@ -306,6 +306,19 @@ def _add_normalization_date(file_id):
db.session.commit()


def _add_premis_object_xml(fs_entry, file_id):
"""Add string representation of PREMIS Object to File object."""
file_ = File.query.get(file_id)

if hasattr(fs_entry, "amdsecs"):
for ss in fs_entry.amdsecs[0].subsections:
if ss.contents.mdtype == fs_entry.PREMIS_OBJECT:
file_.premis_object = etree.tostring(
ss.contents.serialize(), pretty_print=True
)
db.session.commit()


def _get_original_file(related_uuid):
"""Get original file related to preservation derivative."""
return File.query.filter_by(uuid=related_uuid, file_type=FileType.original).first()
Expand Down Expand Up @@ -352,6 +365,8 @@ def create_file_object(file_type, fs_entry, aip_id):
if file_type == FileType.preservation:
_add_normalization_date(new_file.id)

_add_premis_object_xml(fs_entry, new_file.id)


def collect_mets_agents(mets):
"""Collect all of the unique agents in the METS file to write to the
Expand Down
11 changes: 11 additions & 0 deletions AIPscan/Reporter/templates/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ <h2 class="h3">File: {{ file_.name }}</h2>
{{ file_.checksum_value }}
</td>
</tr>
{% if file_.premis_object %}
<tr>
<td width=20%>
<strong>PREMIS Object XML</strong>
</td>
<td>
<pre>{% for line in premisxml: %}{{ line }}
{% endfor %}</pre>
</td>
</tr>
{% endif %}
{% if preservation_file %}
<tr>
<td width=20%>
Expand Down
1 change: 1 addition & 0 deletions AIPscan/Reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def view_file(file_id):
return render_template(
"file.html",
file_=file_,
premisxml=file_.premis_object.decode("utf-8").split("\\n"),
aip=aip,
events=events,
preservation_file=preservation_file,
Expand Down
3 changes: 3 additions & 0 deletions AIPscan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class File(db.Model):
format_version = db.Column(db.String(255))
checksum_type = db.Column(db.String(255))
checksum_value = db.Column(db.String(255), index=True)
premis_object = db.Column(db.Text())

original_file_id = db.Column(db.Integer(), db.ForeignKey("file.id"))
original_file = db.relationship(
Expand All @@ -405,6 +406,7 @@ def __init__(
checksum_value,
aip_id,
file_type=FileType.original,
premis_object=None,
format_version=None,
puid=None,
original_file_id=None,
Expand All @@ -420,6 +422,7 @@ def __init__(
self.format_version = format_version
self.checksum_type = checksum_type
self.checksum_value = checksum_value
self.premis_object = premis_object
self.original_file_id = original_file_id
self.aip_id = aip_id

Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Jinja2==2.11.3
kombu==4.6.10
lxml==4.6.5
MarkupSafe==1.1.1
metsrw==0.3.15
metsrw==0.3.22
natsort==7.0.1
pandas==1.1.4
plotly==5.7.0
Expand Down

0 comments on commit d7e9566

Please sign in to comment.