[PATCH seda] [hook] Don't check for unhandled cardinality on the seda_binary_data_object relation

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Oct 11 14:48:39 CEST 2017



On 11/10/2017 14:08, Philippe Pepiot wrote:
> On 10/11/2017 11:01 AM, Sylvain Thenault wrote:
>> # HG changeset patch
>> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
>> # Date 1507706643 -7200
>> #      Wed Oct 11 09:24:03 2017 +0200
>> # Node ID 9aabd94b1dbf4360a2bf3665ada199934051e2f1
>> # Parent  ba6a36fa1ce7e3c3c4cd5e14de7a84e251798030
>> # Available At https://hg.logilab.org/review/cubes/seda
>> #              hg pull https://hg.logilab.org/review/cubes/seda -r 9aabd94b1dbf
>> [hook] Don't check for unhandled cardinality on the seda_binary_data_object relation
>>
>> in case the profile is a simplified profile. This is because this relation is
>> there because of the SEDA 2 underlying model, where all data objects are below
>> the transfer node, but it is not used in SEDA 0.2 and 1.0, where data
>> objects are dispatched under the archive units tree. So we don't want to prevent
>> having several data objects with cardinality != 1 at different level of the
>> tree.
>>
>> Closes extranet #37372358
>>
>> diff --git a/cubicweb_seda/hooks.py b/cubicweb_seda/hooks.py
>> --- a/cubicweb_seda/hooks.py
>> +++ b/cubicweb_seda/hooks.py
>> @@ -1,6 +1,6 @@
>> -# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
>> +# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
>>  # contact http://www.logilab.fr -- mailto:contact at logilab.fr
>>  #
>>  # This program is free software: you can redistribute it and/or modify it under
>>  # the terms of the GNU Lesser General Public License as published by the Free
>>  # Software Foundation, either version 2.1 of the License, or (at your option)
>> @@ -412,11 +412,11 @@ class UpdatedCardinalityCheckedEntityHoo
>>          rtype, role = icontained.parent_relation()
>>          CheckChildrenUnhandledCardinalityOp.get_instance(self._cw).add_data(
>>              (parent.eid, rtype, self.entity.eid))
>>  
>>  
>> -class CheckChildrenUnhandledCardinalityOp(hook.DataOperationMixIn, hook.Operation):
>> +class CheckChildrenUnhandledCardinalityOp(hook.DataOperationMixIn, hook.LateOperation):
>>      """Check we don't run into the case of an with more than one child through a
>>      same relation with `user_cardinality != '1'` (otherwise it won't be
>>      validable by RelaxNG validator like Jing).
>>  
>>      Expect (parent_eid, rtype, error_entity_eid) to be added into the data container:
>> @@ -426,15 +426,37 @@ class CheckChildrenUnhandledCardinalityO
>>      * name of the relation to retrieve its children (expected to be an object
>>        relation),
>>  
>>      * eid of the entity on which the `ValidationError` will be raised in case of
>>        error.
>> +
>> +    This is a late operation since it has to be executed once the 'container' relation is set.
>>      """
>>  
>>      def precommit_event(self):
>>          for parent_eid, rtype, added_entity_eid in self.get_data():
>>              parent = self.cnx.entity_from_eid(parent_eid)
>> +            if rtype == 'seda_binary_data_object':
>> +                if parent.cw_etype == 'SEDAArchiveTransfer':
>> +                    container = parent
>> +                else:
>> +                    if not parent.container:
>> +                        # we may have to clear the container cache if the parent has
>> +                        # been added in the same transaction
>> +                        parent.cw_clear_relation_cache('container', 'subject')
>> +                    container = parent.cw_adapt_to('IContained').container
>> +                if container.cw_etype != 'SEDAArchiveTransfer':
>> +                    # component archive unit, don't check the relation, it will
>> +                    # be checked upon import of the component into a transfer
>> +                    continue
>> +                # if the container is a simplified profile, allow to have several
>> +                # entities with cardinality != 1 under the seda_binary_data_object
>> +                # because data objects are all linked to the transfer through this
>> +                # relation, but this is only relevant for SEDA 2 export and we don't
>> +                # want to prevent this in profiles for SEDA 0.2 and 1.0 export.
>> +                if container.simplified_profile and rtype == 'seda_binary_data_object':
>> +                    continue
> rtype == 'seda_binary_data_object' is already satisfied in upper condition.
>

fixed in 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