[PATCH saem_ref] [seda] Use ARK identifier as xml:id attribute in SEDA profiles export

Denis Laxalde denis.laxalde at logilab.fr
Mon Jun 25 10:49:12 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1529915404 -7200
#      Mon Jun 25 10:30:04 2018 +0200
# Node ID 05c0737d59b992a8ba04bc1363faca26e207e3a1
# Parent  843401ef51a58cbd6b99c1d37c81f803b8d78bcb
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 05c0737d59b9
# EXP-Topic CONSEJIRA-510
[seda] Use ARK identifier as xml:id attribute in SEDA profiles export

We add a version of IXmlId adapter for entity type supporting the "ark"
attribute and use this identifier as xml:id attribute in SEDA profiles
export. This concerns the "<xsd:element name="Contains">" element
present with a profile contains archive units in particular, hence the
added unit tests.

CONSEJIRA-510.

diff --git a/cubicweb_saem_ref/entities/seda.py b/cubicweb_saem_ref/entities/seda.py
--- a/cubicweb_saem_ref/entities/seda.py
+++ b/cubicweb_saem_ref/entities/seda.py
@@ -17,11 +17,18 @@
 
 from logilab.common.decorators import monkeypatch
 
-from cubicweb.predicates import is_instance, is_in_state
+from cubicweb.predicates import (
+    is_instance,
+    is_in_state,
+    score_entity,
+)
 
 from cubes.oaipmh import MetadataFormat
 from cubes.oaipmh.entities import OAISetSpec
-from cubicweb_seda.entities import SEDAArchiveTransferIClonableAdapter
+from cubicweb_seda.entities import (
+    XmlIdAdapter,
+    SEDAArchiveTransferIClonableAdapter,
+)
 from cubicweb_seda.entities.custom import (
     SEDAArchiveTransfer,
     SEDAArchiveUnit,
@@ -208,6 +215,17 @@ class OAISEDA2RNGExportView(OAISEDAExpor
     __regid__ = 'saem.oai.seda.2.0-rng'
 
 
+class SAEMXmlIdAdapter(XmlIdAdapter):
+    """IXmlId adapter using ARK identifiers."""
+    __select__ = (
+        XmlIdAdapter.__select__
+        & score_entity(lambda x: x.ark is not None)
+    )
+
+    def id(self):
+        return u'ark:/{}'.format(self.entity.ark)
+
+
 def registration_callback(vreg):
     vreg.register_and_replace(SAEMSEDAArchiveTransferIClonableAdapter,
                               SEDAArchiveTransferIClonableAdapter)
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -2,3 +2,4 @@ mock
 psycopg2
 pytest
 webtest
+http://hg.logilab.org/review/cubes/seda/archive/a89f3018c9e3.tar.bz2#egg=cubicweb-seda
diff --git a/test/test_seda.py b/test/test_seda.py
--- a/test/test_seda.py
+++ b/test/test_seda.py
@@ -104,6 +104,19 @@ class SEDAExportTC(CubicWebTC):
             for xml in self.iter_seda_xsd(transfer):
                 self.assertIn('ark:/' + record.ark, xml)
 
+    def test_xmlid_contains_ark(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = testutils.seda_transfer(cnx)
+            au = testutils.create_archive_unit(transfer)[0]
+            cnx.commit()
+            adapter = transfer.cw_adapt_to('SEDA-0.2.xsd')
+            root = adapter.dump_etree()
+        results = root.xpath('//*[@name="Contains"]')
+        self.assertEqual(len(results), 1)
+        tag = results[0]
+        xmlid = tag.attrib['{http://www.w3.org/XML/1998/namespace}id']
+        self.assertEqual(xmlid, u'ark:/' + au.ark)
+
     def test_TransferringAgencyArchiveIdentifier_present_rng02(self):
         with self.admin_access.cnx() as cnx:
             transfer = testutils.seda_transfer(cnx)



More information about the saem-devel mailing list