[PATCH 7 of 9 seda] [entities] Backport cloning feature for archive transfer

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Mar 1 12:31:49 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 b7f58caefba12c946120aff0c874778f1a4a34b5
# Parent  8791e9be0af427439f0b1fbbed41b001ad8c99c8
[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
@@ -141,17 +141,26 @@ def rule_type_from_etype(etype):
 
 class DirectLinkIContained(IContained):
     """IContained implementation using a relation that link every contained entities to its parent
     container.
     """
+    __abstract__ = True
+
     @property
     def container(self):
         """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 +190,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
@@ -3814,17 +3814,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
@@ -3828,17 +3828,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
new file mode 100644
--- /dev/null
+++ b/cubicweb_seda/migration/0.8.0_Any.py
@@ -0,0 +1,1 @@
+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,31 @@ 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',
+                                         seda_message_digest_algorithm_code_list_version=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.seda_message_digest_algorithm_code_list_version[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