[PATCH saem_ref] [seda] Do not use "container" relation when looking for archive unit parent

Denis Laxalde denis.laxalde at logilab.fr
Thu May 24 11:34:00 CEST 2018


Denis Laxalde a écrit :
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1526638668 -7200
> #      Fri May 18 12:17:48 2018 +0200
> # Node ID 410afc9b17875d0426033e641790feae9d662e02
> # Parent  9940c066c866babdca90d0fa9924adf5ac38446f
> # Available At http://hg.logilab.org/review/cubes/saem_ref
> #              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 410afc9b1787
> # EXP-Topic CONSEJIRA-491
> [seda] Do not use "container" relation when looking for archive unit parent

Self-applied this patch as customers are urging me for a fix.

> 
> We rework archive_unit_parent() function introduced in 2f47a5deb560 to
> avoid relying on "container" relation to find a parent to a
> SEDAArchiveUnit entity through which we can generate/locate ARK
> identifiers. Instead, we use the business SEDA model and walk relations
> until we get a parent archive unit or archive transfer. The function is
> also recursive now, which should make it able to handle nested archive
> units.
> 
> We add a regression test about cloning a SEDAArchiveTransfer with nested
> archive units; this test failed before changes in archive_unit_parent
> function.
> 
> Follow up on CONSEJIRA-491.
> 
> diff --git a/cubicweb_saem_ref/entities/__init__.py b/cubicweb_saem_ref/entities/__init__.py
> --- a/cubicweb_saem_ref/entities/__init__.py
> +++ b/cubicweb_saem_ref/entities/__init__.py
> @@ -103,16 +103,19 @@ class OUARKIdentifierGenerator(Qualified
>  
>  
>  def archive_unit_parent(parent):
> -    assert parent.cw_etype in (
> -        'SEDAArchiveTransfer',
> -        'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
> -    ), '{} should be target of seda_archive_unit relation'.format(parent)
> -    if parent.cw_etype == 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement':
> -        # XXX We use the "container" relation since there appears to be no
> -        # other way to get back the SEDAArchiveTransfer entity in case
> -        # this is not the target.
> -        parent = parent.container[0]
> -    return parent
> +    if parent.cw_etype == 'SEDAArchiveTransfer':
> +        return parent
> +    elif parent.cw_etype == 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement':
> +        alt = parent.reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management[0]
> +        au = alt.reverse_seda_alt_archive_unit_archive_unit_ref_id[0]
> +        assert au.cw_etype == 'SEDAArchiveUnit', au
> +        if au.seda_archive_unit:
> +            parent = au.seda_archive_unit[0]
> +            return archive_unit_parent(parent)
> +        else:
> +            return au
> +    else:
> +        raise ValueError('{} should be target of seda_archive_unit relation'.format(parent))
>  
>  
>  class SEDAArchiveUnitARKIdentifierGenerator(QualifiedARKIdentifierGenerator):
> diff --git a/test/test_seda.py b/test/test_seda.py
> --- a/test/test_seda.py
> +++ b/test/test_seda.py
> @@ -187,6 +187,32 @@ class CloneImportTC(CubicWebTC):
>              # unit.
>              self.assertTrue(unit.ark.startswith(parent.ark), unit.ark)
>  
> +    def test_clone_with_nested_archive_units(self):
> +        with self.admin_access.cnx() as cnx:
> +            transfer = cnx.entity_from_eid(self.transfer_eid)
> +            _, _, unit_alt_seq = testutils.create_archive_unit(
> +                transfer, cnx=cnx,
> +                ark_naa=None,
> +                user_cardinality=u'1',
> +                user_annotation=u'top-level')
> +            cnx.commit()
> +            assert transfer.reverse_seda_archive_unit
> +            testutils.create_archive_unit(
> +                unit_alt_seq, cnx=cnx,
> +                ark_naa=None,
> +                user_cardinality=u'1',
> +                user_annotation=u'nested')
> +            cnx.commit()
> +            rset = cnx.execute('Any X,Y WHERE X seda_archive_unit Y')
> +            self.assertEqual(len(rset), 2, rset)
> +            transfer.cw_adapt_to('IWorkflowable').fire_transition(u'publish')
> +            cnx.commit()
> +            testutils.setup_profile(cnx, title=u'Clone',
> +                                    new_version_of=transfer)
> +            cnx.commit()
> +            rset = cnx.execute('Any X,Y WHERE X seda_archive_unit Y')
> +            self.assertEqual(len(rset), 4, rset)
> +
>  
>  if __name__ == '__main__':
>      unittest.main()
> 



More information about the saem-devel mailing list