[PATCH 07 of 10 seda] [entities] Backport cloning feature for archive transfer

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Mar 7 15:25:44 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488367053 -3600
#      Wed Mar 01 12:17:33 2017 +0100
# Node ID ac52b0997d893fba1922835ec965abead71671f0
# Parent  015cf72e71c9c2ed1da5fd775627d8858e6b80ab
[entities] Backport cloning feature for archive transfer

diff --git a/cubicweb_seda/entities/__init__.py b/cubicweb_seda/entities/__init__.py
--- a/cubicweb_seda/entities/__init__.py
+++ b/cubicweb_seda/entities/__init__.py
@@ -148,10 +148,17 @@ class DirectLinkIContained(IContained):
         """Return the container to which this entity belongs, or None."""
         container = self.entity.related('container', entities=True)
         return container and container[0] or None
 
 
+class SEDAArchiveTransferIClonableAdapter(IClonableAdapter):
+    """Cloning adapter for SEDA profiles."""
+    __select__ = is_instance('SEDAArchiveTransfer')
+    rtype = 'clone_of'
+    skiprtypes = ()
+
+
 class SEDAArchiveUnitIClonableAdapter(IClonableAdapter):
     """Cloning adapter for SEDA components."""
     __select__ = is_instance('SEDAArchiveUnit')
     rtype = 'clone_of'
     skiprtypes = ()
@@ -181,11 +188,11 @@ class SEDAArchiveUnitIClonableAdapter(IC
                 }[data_object.cw_etype]
                 clones[data_object].cw_set(**{rtype: transfer})
 
 
 def registration_callback(vreg):
-    vreg.register(SEDAArchiveUnitIClonableAdapter)
+    vreg.register_all(globals().values(), __name__)
     vreg.register(IContainer.build_class('SEDAArchiveTransfer'))
     vreg.register(IContainer.build_class('SEDAArchiveUnit'))  # archive unit may also be a container
     for etype, parent_relations in sorted(seda_profile_container_def(vreg.schema)):
         cls = DirectLinkIContained.build_class(etype, parent_relations)
         assert cls
diff --git a/cubicweb_seda/i18n/en.po b/cubicweb_seda/i18n/en.po
--- a/cubicweb_seda/i18n/en.po
+++ b/cubicweb_seda/i18n/en.po
@@ -3918,17 +3918,25 @@ msgid "classification_owner"
 msgstr ""
 
 msgid "clone_of"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of"
 msgstr ""
 
 msgid "clone_of_object"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of_object"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of_object"
 msgstr ""
 
 msgctxt "SEDAComment"
diff --git a/cubicweb_seda/i18n/fr.po b/cubicweb_seda/i18n/fr.po
--- a/cubicweb_seda/i18n/fr.po
+++ b/cubicweb_seda/i18n/fr.po
@@ -3932,17 +3932,25 @@ msgid "classification_owner"
 msgstr ""
 
 msgid "clone_of"
 msgstr "source"
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of"
 msgstr ""
 
 msgid "clone_of_object"
 msgstr "copies"
 
+msgctxt "SEDAArchiveTransfer"
+msgid "clone_of_object"
+msgstr ""
+
 msgctxt "SEDAArchiveUnit"
 msgid "clone_of_object"
 msgstr ""
 
 msgctxt "SEDAComment"
diff --git a/cubicweb_seda/migration/0.8.0_Any.py b/cubicweb_seda/migration/0.8.0_Any.py
--- a/cubicweb_seda/migration/0.8.0_Any.py
+++ b/cubicweb_seda/migration/0.8.0_Any.py
@@ -24,5 +24,6 @@ for etype in ('SEDArestrictionRuleIdRef'
 lcsv_files = [file_def for file_def in LCSV_FILES
               if file_def[-1] in ('legal_status.csv', 'digest_algorithms.csv', 'dissemination.csv')]
 import_seda_schemes(cnx, lcsv_files=lcsv_files)
 
 drop_relation_type('seda_reply_code_list_version')
+add_relation_definition('SEDAArchiveTransfer', 'clone_of', 'SEDAArchiveTransfer')
diff --git a/cubicweb_seda/schema/__init__.py b/cubicweb_seda/schema/__init__.py
--- a/cubicweb_seda/schema/__init__.py
+++ b/cubicweb_seda/schema/__init__.py
@@ -88,11 +88,20 @@ class container(RelationType):
     __permissions__ = {'add': (), 'delete': (), 'read': ()}
     cardinality = '1*'
     inlined = False
 
 
-class clone_of(RelationDefinition):
+class clone_of_archive_transfer(RelationDefinition):
+    name = 'clone_of'
+    subject = 'SEDAArchiveTransfer'
+    object = 'SEDAArchiveTransfer'
+    cardinality = '?*'
+    inlined = True
+
+
+class clone_of_archive_unit(RelationDefinition):
+    name = 'clone_of'
     subject = 'SEDAArchiveUnit'
     object = 'SEDAArchiveUnit'
     cardinality = '?*'
     inlined = True
 
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -112,10 +112,34 @@ class ContainerTC(CubicWebTC):
                           .seda_data_object_reference_id[0])
             self.assertEqual(cloned_bdo.container[0].eid, transfer.eid)
             cloned_bdo.cw_clear_all_caches()
             self.assertEqual(cloned_bdo.seda_binary_data_object[0].eid, transfer.eid)
 
+    def test_archive_transfer_clone(self):
+        """Functional test for SEDA profile cloning."""
+        with self.admin_access.repo_cnx() as cnx:
+            scheme = cnx.create_entity('ConceptScheme', title=u'Algorithms')
+            concept = scheme.add_concept(u'md5')
+            transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
+            cnx.create_entity('SEDAMessageDigestAlgorithmCodeListVersion',
+                              seda_message_digest_algorithm_code_list_version_from=transfer,
+                              seda_message_digest_algorithm_code_list_version_to=scheme)
+            unit, unit_alt, unit_alt_seq = create_archive_unit(
+                transfer, cnx=cnx, title=u'hello')
+            create_data_object(transfer, seda_algorithm=concept)
+            cnx.commit()
+
+            clone = cnx.create_entity('SEDAArchiveTransfer', title=u'Clone', clone_of=transfer)
+            cnx.commit()
+
+            self.assertEqual((clone.reverse_seda_message_digest_algorithm_code_list_version_from[0].
+                             seda_message_digest_algorithm_code_list_version_to[0].eid),
+                             scheme.eid)
+            seq = clone.archive_units[0]. first_level_choice.content_sequence
+            self.assertEqual(seq.title.title, 'hello')
+            self.assertEqual(transfer.binary_data_objects[0].seda_algorithm[0].eid, concept.eid)
+
 
 class FakeEntity(object):
     cw_etype = 'Whatever'
 
     def __init__(self, _cw):


More information about the saem-devel mailing list