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

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Mar 14 10:58:13 CET 2017



Le 13/03/2017 à 08:54, Denis Laxalde a écrit :
> Sylvain Thenault a écrit :
>> # 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.
>
> So perhaps the seda cube should not define the relation unconditionally?

I don't know how to do this in a proper way: in the seda cube, we've no
idea about this relation, which is retrieved automatically by compound
graph discovery functions.

>
>> 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()
>>
>
> This new comment is wrongly located, isn't it?
yep

>
>> @@ -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
>> +
>
> So why is this hunk still here? I thought having 'Activity' in
> skipetypes would be enough? If not, this looks like a serious issue
> unless I missed something...
Opps, I forgot to remove that part of the patch.

>
>>      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')
>
> Unrelated.
>
>> 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'))
>
>
> I think all this is unrelated to the scope of this patch ("plug activies
> onto archive transfer"). It's just a side effect of skipping Activity
> entity type from compound structure_def, meaning that this change should
> be made into a standalone patch.
>
Moved in a previous cset.

Will sent a V2.

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list