[PATCH 2 of 2 saem_ref V2] [hook] export EAC ARK on AuthorityRecordId

Denis Laxalde denis.laxalde at logilab.fr
Fri Feb 24 16:08:41 CET 2017


Philippe Pepiot a écrit :
> # HG changeset patch
> # User Philippe Pepiot <philippe.pepiot at logilab.fr>
> # Date 1487946737 -3600
> #      Fri Feb 24 15:32:17 2017 +0100
> # Node ID bfa49acea3f1b7271ec74f85d85c1d1cba253d66
> # Parent  5b36edccfd6eab8e7cf78107a779335654ec4a91
> # Available At https://hg.logilab.org/review/cubes/saem_ref
> #              hg pull https://hg.logilab.org/review/cubes/saem_ref -r bfa49acea3f1
> # Tested at: https://jenkins.logilab.org/job/cubicweb-saem_ref/101/
> [hook] export EAC ARK on AuthorityRecordId
>
> Copy (eventually) created recordId to otherRecordId and set recordId to ARK
> (thus export ARK in a <recordId /> field).
>
> Do this in hooks as well as in dataimport machinery which use MassiveStore and
> doesn't trigger hooks.

Is the hook necessary after all? Since the "record_id" field is hidden
from the web UI there's no way someone can insert one unless using
something else than the web ui and dataimport, in which case I'm not
sure this kind of override is desirable...


> diff --git a/cubicweb_saem_ref/sobjects/__init__.py b/cubicweb_saem_ref/sobjects/__init__.py
> --- a/cubicweb_saem_ref/sobjects/__init__.py
> +++ b/cubicweb_saem_ref/sobjects/__init__.py
> @@ -19,6 +19,7 @@ from six.moves import map as imap
>
>  from cubicweb.predicates import match_user_groups, match_kwargs
>  from cubicweb.server import Service
> +from cubicweb.dataimport.importer import ExtEntity
>  from cubicweb.dataimport.stores import MetadataGenerator
>
>  from cubicweb_eac import sobjects as eac
> @@ -56,7 +57,8 @@ class SAEMMetadataGenerator(MetadataGene
>      def entity_attrs(self, etype):
>          entity_attrs = super(SAEMMetadataGenerator, self).entity_attrs(etype)
>          if etype in ('ConceptScheme', 'Concept', 'AuthorityRecord', 'Agent'):
> -            entity_attrs.insert(0, 'ark')  # insert before cwuri
> +            # insert before cwuri
> +            entity_attrs = ['ark', 'record_id'] + entity_attrs
>          return entity_attrs
>
>      def gen_ark(self, etype, eid, attrs):
> @@ -66,6 +68,9 @@ class SAEMMetadataGenerator(MetadataGene
>          # implementation
>          return attrs['ark']
>
> +    def gen_record_id(self, etype, eid, attrs):
> +        return attrs['ark']
> +
>
>  class EACImportService(eac.EACImportService):
>      """Service to import an AuthorityRecord from an EAC XML file - overriden from the EAC cube to
> @@ -99,7 +104,21 @@ class EACImportService(eac.EACImportServ
>                  extentity.values['authority'] = set([self._authority.cwuri])
>              return extentity
>
> -        return imap(set_authority_or_naa, extentities)
> +        def move_record_id(extentities):
> +            for extentity in extentities:
> +                if (extentity.etype == 'AuthorityRecord'
> +                        and 'record_id' in extentity.values):
> +                    yield ExtEntity(etype='EACOtherRecordId',
> +                                    extid='EACOtherRecordId-{0}'.format(extentity.extid),
> +                                    values={
> +                                        'value': extentity.values.pop('record_id'),
> +                                        'eac_other_record_id_of': set([extentity.extid]),
> +                                    })

I think you can drop etype and extid as kwargs as they are mandatory
arguments. This would things more readable.

> +                yield extentity
> +
> +        extentities = imap(set_authority_or_naa, extentities)
> +        extentities = move_record_id(extentities)
> +        return extentities
>
>
>  class AllocateArk(Service):



More information about the saem-devel mailing list