diff --git a/AIPscan/Aggregator/database_helpers.py b/AIPscan/Aggregator/database_helpers.py index 69bf58c9..c18f830b 100644 --- a/AIPscan/Aggregator/database_helpers.py +++ b/AIPscan/Aggregator/database_helpers.py @@ -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 @@ -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) @@ -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() @@ -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 diff --git a/AIPscan/Reporter/templates/file.html b/AIPscan/Reporter/templates/file.html index 44128807..0329b48b 100644 --- a/AIPscan/Reporter/templates/file.html +++ b/AIPscan/Reporter/templates/file.html @@ -66,6 +66,17 @@

File: {{ file_.name }}

{{ file_.checksum_value }} + {% if file_.premis_object %} + + + PREMIS Object XML + + +
{% for line in premisxml: %}{{ line }}
+{% endfor %}
+ + + {% endif %} {% if preservation_file %} diff --git a/AIPscan/Reporter/views.py b/AIPscan/Reporter/views.py index eb476661..d4c99171 100644 --- a/AIPscan/Reporter/views.py +++ b/AIPscan/Reporter/views.py @@ -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, diff --git a/AIPscan/models.py b/AIPscan/models.py index 8404a453..21b4c82f 100644 --- a/AIPscan/models.py +++ b/AIPscan/models.py @@ -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( @@ -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, @@ -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 diff --git a/requirements/base.txt b/requirements/base.txt index 03b68923..36102e0e 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -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