[PATCH 2 of 2 saem_ref V2] [seda] Plug activities onto archive transfer

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 10 17:21:17 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489081332 -3600
#      Thu Mar 09 18:42:12 2017 +0100
# Node ID b5a7f12013c6c5600a98e5afe97f25078c6ef4a8
# Parent  78e2fde8a4fa1268a91449e80701c1a42ed711df
[seda] Plug activities onto archive transfer

Related to extranet #3101354

Notice a container relation is added in the message catalog, this is because
this relation is added in post_build_callback of the seda cube. We actually
don't need, so don't bother adding migration for it.

diff --git a/cubicweb_saem_ref/entities/container.py b/cubicweb_saem_ref/entities/container.py
--- a/cubicweb_saem_ref/entities/container.py
+++ b/cubicweb_saem_ref/entities/container.py
@@ -13,14 +13,21 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem_ref "compound"-related functionalities."""
 
+from functools import partial
+
 from cubicweb_compound import structure_def
 from cubicweb_compound.entities import IContainer, IContained
 
+structure_def = partial(structure_def, skipetypes=('Activity',))
 
+
+# don't put Activity in a compound graph, it causes problem since it belongs to both
+# SEDAArchiveTransfer tree and to concept/authority record tree, which don't have the same
+# IContained implementation.
 def authority_record_container_def(schema):
     """Define container for AuthorityRecord"""
     return structure_def(schema, 'AuthorityRecord').items()
 
 
@@ -38,21 +45,30 @@ def concept_container_def(schema):
     """Define container for Concept"""
     return structure_def(schema, 'Concept').items()
 
 
 def registration_callback(vreg):
+    # don't define IContained class for Activity, because it cause problem since it belongs to
+    # both SEDAArchiveTransfer tree and to concept/authority record tree, which don't have the
+    # same IContained implementation. Since we do not actually need this adapter on Activity,
+    # simply skip it.
+    def skip_activity(container_def_iterator):
+        for etype, parent_relations in container_def_iterator:
+            if etype != 'Activity':
+                yield etype, parent_relations
+
     vreg.register(IContainer.build_class('Organization'))
     for etype, parent_relations in org_container_def(vreg.schema):
         IContained.register_class(vreg, etype, parent_relations)
     vreg.register(IContainer.build_class('AuthorityRecord'))
-    for etype, parent_relations in authority_record_container_def(vreg.schema):
+    for etype, parent_relations in skip_activity(authority_record_container_def(vreg.schema)):
         IContained.register_class(vreg, etype, parent_relations)
     vreg.register(IContainer.build_class('ConceptScheme'))
-    for etype, parent_relations in scheme_container_def(vreg.schema):
+    for etype, parent_relations in skip_activity(scheme_container_def(vreg.schema)):
         if etype == 'Concept':
             # XXX turn parent_relations to a list to ensure broader_concept is considered first
             parent_relations = list(parent_relations)
             parent_relations.insert(0, ('broader_concept', 'subject'))
         IContained.register_class(vreg, etype, parent_relations)
     vreg.register(IContainer.build_class('Concept'))
-    for etype, parent_relations in concept_container_def(vreg.schema):
+    for etype, parent_relations in skip_activity(concept_container_def(vreg.schema)):
         IContained.register_class(vreg, etype, parent_relations)
diff --git a/cubicweb_saem_ref/entities/rdf.py b/cubicweb_saem_ref/entities/rdf.py
--- a/cubicweb_saem_ref/entities/rdf.py
+++ b/cubicweb_saem_ref/entities/rdf.py
@@ -21,11 +21,11 @@ from cubes.skos import rdfio
 from cubes.skos.entities import AbstractRDFAdapter
 
 from .. import permanent_url
 
 
-def _register_agent_prov_mapping(reg):  # XXX move to the prov cube
+def _register_prov_mapping(reg):  # XXX move to the prov cube
     """Register RDF mapping for PROV-O entity types related to Agent.
     """
     reg.register_prefix('prov', 'http://www.w3.org/ns/prov#')
     # reg.register_etype_equivalence('Agent', 'prov:Agent')
     reg.register_etype_equivalence('Activity', 'prov:Activity')
diff --git a/cubicweb_saem_ref/i18n/en.po b/cubicweb_saem_ref/i18n/en.po
--- a/cubicweb_saem_ref/i18n/en.po
+++ b/cubicweb_saem_ref/i18n/en.po
@@ -447,10 +447,14 @@ msgstr "contact point of"
 
 msgctxt "Agent"
 msgid "contact_point_object"
 msgstr ""
 
+msgctxt "Activity"
+msgid "container"
+msgstr ""
+
 msgid "control"
 msgstr "control service"
 
 msgid "created"
 msgstr ""
@@ -657,10 +661,14 @@ msgstr ""
 
 msgctxt "ConceptScheme"
 msgid "generated_object"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "generated_object"
+msgstr ""
+
 msgid "latest update on"
 msgstr ""
 
 msgid "modified"
 msgstr ""
@@ -854,10 +862,14 @@ msgstr ""
 
 msgctxt "ConceptScheme"
 msgid "used_object"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "used_object"
+msgstr ""
+
 msgid "view"
 msgstr ""
 
 msgid "view this relation"
 msgstr ""
diff --git a/cubicweb_saem_ref/i18n/fr.po b/cubicweb_saem_ref/i18n/fr.po
--- a/cubicweb_saem_ref/i18n/fr.po
+++ b/cubicweb_saem_ref/i18n/fr.po
@@ -462,10 +462,14 @@ msgstr "point de contact de"
 
 msgctxt "Agent"
 msgid "contact_point_object"
 msgstr ""
 
+msgctxt "Activity"
+msgid "container"
+msgstr ""
+
 msgid "control"
 msgstr "service de contrôle"
 
 msgid "created"
 msgstr "création"
@@ -675,10 +679,14 @@ msgstr ""
 
 msgctxt "ConceptScheme"
 msgid "generated_object"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "generated_object"
+msgstr ""
+
 msgid "latest update on"
 msgstr "dernière mise à jour"
 
 msgid "modified"
 msgstr "modification"
@@ -879,10 +887,14 @@ msgstr ""
 
 msgctxt "ConceptScheme"
 msgid "used_object"
 msgstr ""
 
+msgctxt "SEDAArchiveTransfer"
+msgid "used_object"
+msgstr ""
+
 msgid "view"
 msgstr "voir"
 
 msgid "view this relation"
 msgstr "voir cette relation"
diff --git a/cubicweb_saem_ref/migration/0.15.0_Any.py b/cubicweb_saem_ref/migration/0.15.0_Any.py
new file mode 100644
--- /dev/null
+++ b/cubicweb_saem_ref/migration/0.15.0_Any.py
@@ -0,0 +1,2 @@
+add_relation_definition('Activity', 'generated', 'SEDAArchiveTransfer')
+add_relation_definition('Activity', 'used', 'SEDAArchiveTransfer')
diff --git a/cubicweb_saem_ref/schema.py b/cubicweb_saem_ref/schema.py
--- a/cubicweb_saem_ref/schema.py
+++ b/cubicweb_saem_ref/schema.py
@@ -282,16 +282,16 @@ class related_concept_scheme(RelationDef
     description = _('concept schemes used by the agent')
 
 
 class generated(RelationDefinition):
     subject = 'Activity'
-    object = ('Concept', 'ConceptScheme')
+    object = ('Concept', 'ConceptScheme', 'SEDAArchiveTransfer')
 
 
 class used(RelationDefinition):
     subject = 'Activity'
-    object = ('Concept', 'ConceptScheme')
+    object = ('Concept', 'ConceptScheme', 'SEDAArchiveTransfer')
 
 
 # ARK ##########################################################################
 
 class ark(RelationDefinition):
diff --git a/cubicweb_saem_ref/views/seda.py b/cubicweb_saem_ref/views/seda.py
--- a/cubicweb_saem_ref/views/seda.py
+++ b/cubicweb_saem_ref/views/seda.py
@@ -15,10 +15,11 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem-ref views related to SEDA"""
 
 from cubicweb.web.views import uicfg
 
+from cubicweb_seda.views import archivetransfer
 from cubicweb_seda.views.simplified import simplified_afs, simplified_pvs
 
 
 # primary view configuration #######################################################################
 
@@ -44,5 +45,8 @@ simplified_pvs.tag_object_of(('*', 'use_
 simplified_afs.tag_object_of(('*', 'use_profile', '*'), 'main', 'hidden')
 
 simplified_pvs.tag_attribute(('SEDABinaryDataObject', 'filename'), 'hidden')
 simplified_afs.tag_attribute(('SEDABinaryDataObject', 'filename'), 'main', 'hidden')
 afs.tag_attribute(('SEDABinaryDataObject', 'filename'), 'main', 'hidden')
+
+
+archivetransfer.ArchiveTransferTabbedPrimaryView.tabs.append('saem.lifecycle_tab')
diff --git a/test/unittest_entities_container.py b/test/unittest_entities_container.py
--- a/test/unittest_entities_container.py
+++ b/test/unittest_entities_container.py
@@ -32,12 +32,11 @@ class ContainerTC(CubicWebTC):
     def test_authorityrecord_container(self):
         # line below should be copied from entities.container.registration_callback
         container_def = container.authority_record_container_def(self.schema)
         container_def = dict(sort_container(container_def))
         self.assertEqual(container_def,
-                         {'Activity': [('generated', 'subject'), ('used', 'subject')],
-                          'AgentFunction': [('function_agent', 'subject')],
+                         {'AgentFunction': [('function_agent', 'subject')],
                           'AgentPlace': [('place_agent', 'subject')],
                           'Citation': [('has_citation', 'object')],
                           'EACOtherRecordId': [('eac_other_record_id_of', 'subject')],
                           'EACResourceRelation': [('resource_relation_agent', 'subject')],
                           'EACSource': [('source_agent', 'subject')],
@@ -56,23 +55,21 @@ class ContainerTC(CubicWebTC):
     def test_scheme_container(self):
         # line below should be copied from entities.container.registration_callback
         container_def = container.scheme_container_def(self.schema)
         container_def = dict(sort_container(container_def))
         self.assertEqual(container_def,
-                         {'Activity': [('generated', 'subject'), ('used', 'subject')],
-                          'Concept': [('in_scheme', 'subject')]})
+                         {'Concept': [('in_scheme', 'subject')]})
         entity = self.vreg['etypes'].etype_class('ConceptScheme')(self)
         self.assertIsNotNone(entity.cw_adapt_to('IContainer'))
         self.assertIsNone(entity.cw_adapt_to('IContained'))
 
     def test_concept_container(self):
         # line below should be copied from entities.container.registration_callback
         container_def = container.concept_container_def(self.schema)
         container_def = dict(sort_container(container_def))
         self.assertEqual(container_def,
-                         {'Activity': [('generated', 'subject'), ('used', 'subject')],
-                          'Label': [('label_of', 'subject')]})
+                         {'Label': [('label_of', 'subject')]})
         entity = self.vreg['etypes'].etype_class('Concept')(self)
         self.assertIsNotNone(entity.cw_adapt_to('IContainer'))
         # Concept is both container and contained :
         self.assertIsNotNone(entity.cw_adapt_to('IContained'))
 
diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py
--- a/test/unittest_hooks.py
+++ b/test/unittest_hooks.py
@@ -473,10 +473,20 @@ class EntityLifeCycleTC(CubicWebTC):
             rset = cnx.execute('Activity X ORDERBY X DESC WHERE X type "modify", X used %(x)s',
                                {'x': scheme.eid})
             self.assertEqual(len(rset), 2)
             self.assertEqual(rset.get_entity(0, 0).description, 'added in_scheme_object')
 
+    def test_archive_transfer_create_update(self):
+        with self.new_access(u'bob').cnx() as cnx:
+            transfer = testutils.setup_profile(cnx)
+            cnx.commit()
+            self._check_create(cnx, transfer.eid, 'created sedaarchivetransfer')
+            transfer.cw_set(title=u'123')
+            cnx.commit()
+            self._check_modification(cnx, transfer.eid,
+                                     'modified title')
+
 
 class SEDAArchiveTransferHooksTC(CubicWebTC):
 
     def test_profile_deprecated(self):
         """Test hook deprecating a SEDA Profile upon successor publication."""


More information about the saem-devel mailing list