[PATCH 4 of 5 saem_ref] [seda] Generate a qualified ARK identifier for archive unit related to a transfer

Denis Laxalde denis.laxalde at logilab.fr
Wed Apr 11 16:30:08 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1523442172 -7200
#      Wed Apr 11 12:22:52 2018 +0200
# Node ID acb40395ff4ce5f9896b92819bd27f183c4aecf2
# Parent  ffa768d7ef7f034ccf882c0e271924434fa504c2
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r acb40395ff4c
# EXP-Topic ark-for-archiveunit
[seda] Generate a qualified ARK identifier for archive unit related to a transfer

When a SEDAArchiveUnit is created or related to an archive transfer we
generated an ARK identifier for this entity that is qualified with
respect to the transfer's ARK identifier.

This is implemented through a subclass of
QualifiedARKIdentifierGenerator that is selected for SEDAArchiveUnit
entity type. This is similar to how Concept entities get their ARK from
their related ConceptScheme.

Note that we had to fix an "ark" attribute for the SEDAArchiveUnit
created in automatic views tests (test_saem_ref.py) because otherwise,
an ark would have been generated based on parent SEDAArchiveTransfer
entity which itself has a generated ark that does not match what's
expected to produce a qualified identifier (namely, it has a random
NAAN, which corresponds to no existing NAA and its NAME part would have
no prefix/suffix).

CONSEJIRA-431

diff --git a/cubicweb_saem_ref/entities/__init__.py b/cubicweb_saem_ref/entities/__init__.py
--- a/cubicweb_saem_ref/entities/__init__.py
+++ b/cubicweb_saem_ref/entities/__init__.py
@@ -102,6 +102,20 @@ class OUARKIdentifierGenerator(Qualified
         return self._cw.entity_from_eid(authority)
 
 
+class SEDAArchiveUnitARKIdentifierGenerator(QualifiedARKIdentifierGenerator):
+    __select__ = (
+        ARKIdentifierGeneratorMixin.__select__
+        & match_kwargs('seda_archive_unit')
+    )
+
+    @property
+    def parent_entity(self):
+        transfer = self.cw_extra_kwargs['seda_archive_unit']
+        if hasattr(transfer, 'eid'):
+            return transfer
+        return self._cw.entity_from_eid(transfer)
+
+
 class ArkNAALocator(EntityAdapter):
     """Adapter responsible to retrieve the proper ARK Name Assigning Authority depending on the
     entity type
diff --git a/test/test_saem_ref.py b/test/test_saem_ref.py
--- a/test/test_saem_ref.py
+++ b/test/test_saem_ref.py
@@ -153,7 +153,7 @@ class AutomaticWebTest(testlib.Automatic
 
     def post_populate(self, cnx):
         unit, alt, alt_seq = testutils.create_archive_unit(
-            cnx.find('SEDAArchiveTransfer').one())
+            cnx.find('SEDAArchiveTransfer').one(), ark=u'0/dummy')
         testutils.create_data_object(alt_seq)
 
         cnx.execute('SET L kind "preferred" WHERE NOT EXISTS (L label_of X, L kind "preferred")')
diff --git a/test/test_seda.py b/test/test_seda.py
--- a/test/test_seda.py
+++ b/test/test_seda.py
@@ -166,6 +166,9 @@ class CloneImportTC(CubicWebTC):
             imported_unit = rset.one()
             self.assertNotEqual(req.entity_from_eid(self.unit_eid).ark,
                                 imported_unit.ark)
+            # Make sure archive unit's ARK is qualified w.r.t. its parent
+            # archive transfer's ARK.
+            self.assertTrue(imported_unit.ark.startswith(ark), imported_unit)
 
 
 if __name__ == '__main__':
diff --git a/test/unittest_entities.py b/test/unittest_entities.py
--- a/test/unittest_entities.py
+++ b/test/unittest_entities.py
@@ -68,6 +68,17 @@ class ArkGeneratorTC(CubicWebTC):
             ark = generator.generate_ark()
             self._check_ark_matches_parent(ark, authority_ark)
 
+    def test_sedaarchiveunit(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = testutils.setup_profile(cnx, title=u'test')
+            cnx.commit()
+            transfer_ark = transfer.ark
+            what = str(transfer.ark_naa[0].what)
+            generator = self.vreg['adapters'].select(
+                'IARKGenerator', cnx, naa_what=what, seda_archive_unit=transfer)
+            ark = generator.generate_ark()
+            self._check_ark_matches_parent(ark, transfer_ark)
+
 
 if __name__ == '__main__':
     import unittest



More information about the saem-devel mailing list