Skip to content

Commit

Permalink
Include DMDID attributes in normative structMap
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed May 1, 2021
1 parent 7c636f2 commit 18d58b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion metsrw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

LOGGER = logging.getLogger(__name__)
LOGGER.addHandler(logging.NullHandler())
__version__ = "0.3.19"
__version__ = "0.3.20"

__all__ = [
"Agent",
Expand Down
3 changes: 1 addition & 2 deletions metsrw/fsentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ def serialize_structmap(self, recurse=True, normative=False):
if (not normative) and self.file_id():
etree.SubElement(el, utils.lxmlns("mets") + "fptr", FILEID=self.file_id())
if self.dmdids:
if (not normative) or (normative and self.is_empty_dir):
el.set("DMDID", " ".join(self.dmdids))
el.set("DMDID", " ".join(self.dmdids))
if self.mets_div_type.lower() == "directory" and self.admids:
el.set("ADMID", " ".join(self.admids))
if recurse and self._children:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_normative_structmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import metsrw
from metsrw.plugins.premisrw import PREMISObject, PREMIS_3_0_NAMESPACES, lxmlns

from lxml import etree


class TestNormativeStructMap(TestCase):
"""Test normative logical structmap class."""
Expand Down Expand Up @@ -71,6 +73,7 @@ def test_write_normative_structmap(self):
# Create the parent directory of the empty directory and give it a
# simple PREMIS object also.
f3 = metsrw.FSEntry("level3.txt", file_uuid=str(uuid.uuid4()))
f3.add_dmdsec(etree.Element("data"), "OTHER")
d2 = metsrw.FSEntry("dir2", type="Directory", children=[f3, d_empty])
d2_id = str(uuid.uuid4())
d2_premis_object = PREMISObject(identifier_value=d2_id)
Expand Down Expand Up @@ -157,3 +160,14 @@ def test_write_normative_structmap(self):
"{}type".format(lxmlns("xsi", premis_version="3.0"))
)
assert xsi_type == "premis:intellectualEntity"

# Expect that the file in the normative logical structmap includes the
# DMDID attribute.
dmdid = normative_structmap_el.find(exists_in_both_path, metsrw.NAMESPACES).get(
"DMDID"
)
assert dmdid.startswith("dmdSec_")
file_3_dmd_sec = doc.find(
'mets:dmdSec[@ID="{}"]'.format(dmdid), metsrw.NAMESPACES
)
assert file_3_dmd_sec is not None

0 comments on commit 18d58b8

Please sign in to comment.