[PATCH 3 of 3 saem_ref] [seda] Insert an empty TransferringAgencyArchiveIdentifier element in rng 0.2 and XSD exports

Denis Laxalde denis.laxalde at logilab.fr
Wed Mar 21 12:07:52 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1521629098 -3600
#      Wed Mar 21 11:44:58 2018 +0100
# Node ID 542ff3e015e0be6094fef00dee658eaf7c3cb7e7
# Parent  1493be198e6ea62a2dd653f01085464c7383c9fd
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 542ff3e015e0
# EXP-Topic seda-TransferringAgencyArchiveIdentifier
[seda] Insert an empty TransferringAgencyArchiveIdentifier element in rng 0.2 and XSD exports

We insert an empty tag named TransferringAgencyArchiveIdentifier in RNG
0.2 and XSD exports of SEDA profiles as long as they have an archive
unit. The tag has a fixed "value" and default values for other
attributes. This is meant for downstream consumption by GED-SAS and
Asalae which would insert an actual identifier in this element.

We implement this as a monkeypatch just like any other customization of
SEDA export mechanism in SAEM-Ref (apparently, this is to avoid
duplication induced by having to implement twice the same logic for SEDA
1 and SEDA 0.2).

(CONSEJIRA-445)

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
@@ -55,6 +55,24 @@ def agency_id(self, agency):
     return None if agency.agency is None else 'ark:/' + agency.agency.ark
 
 
+orig_xsd_transferring_agency_archive_identifier = \
+    SEDA1XSDExport.xsd_transferring_agency_archive_identifier
+
+
+ at monkeypatch(SEDA1XSDExport)
+def xsd_transferring_agency_archive_identifier(self, parent, content_entity, tag_name):
+    if content_entity.transferring_agency_archive_unit_identifier:
+        # XXX should not happen since we hide the field (views/seda.py).
+        return orig_xsd_transferring_agency_archive_identifier(
+            self, parent, content_entity, tag_name)
+    # Insert an element with a "fixed value" (empty) that should be overridden
+    # by downstream consumers.
+    self.element_schema(
+        parent, tag_name, 'qdt:ArchiveIDType',
+        fixed_value='',
+        xsd_attributes=self.xsd_attributes_scheme())
+
+
 class SAEMSEDAArchiveTransferIClonableAdapter(SEDAArchiveTransferIClonableAdapter):
     __select__ = SEDAArchiveTransferIClonableAdapter.__select__ & is_in_state('published')
     rtype = 'new_version_of'
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,34 @@ class SEDAExportTC(CubicWebTC):
             for xml in self.iter_seda_xsd(transfer):
                 self.assertIn('ark:/' + record.ark, xml)
 
+    def test_TransferringAgencyArchiveIdentifier_present_rng02(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = testutils.seda_transfer(cnx)
+            testutils.create_archive_unit(transfer)
+            cnx.commit()
+            adapter = transfer.cw_adapt_to('SEDA-0.2.rng')
+            root = adapter.dump_etree()
+            # We expect a rng:element with
+            # name=TransferringAgencyArchiveIdentifier,
+            results = root.xpath('//*[@name="TransferringAgencyArchiveIdentifier"]')
+            self.assertEqual(len(results), 1)
+            tag = results[0]
+            # containing an empty rng:value tag.
+            value = tag.find('rng:value', namespaces=root.nsmap)
+            self.assertEqual(value.text, '')
+
+    def test_TransferringAgencyArchiveIdentifier_present_xsd(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = testutils.seda_transfer(cnx)
+            testutils.create_archive_unit(transfer)
+            cnx.commit()
+            adapter = transfer.cw_adapt_to('SEDA-0.2.xsd')
+            root = adapter.dump_etree()
+            # We expect a rng:element with
+            # name=TransferringAgencyArchiveIdentifier,
+            results = root.xpath('//*[@name="TransferringAgencyArchiveIdentifier"]')
+            self.assertEqual(len(results), 1)
+
 
 class CloneImportTC(CubicWebTC):
     """Tests for cubicweb-seda's seda.doimport controller, making sure it



More information about the saem-devel mailing list