[PATCH eac V2] Add some attribute to EACRessourceRelation

Denis Laxalde denis.laxalde at logilab.fr
Tue Aug 13 09:54:59 CEST 2019


Guillaume Vandevelde a écrit :
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1564500697 -7200
> #      Tue Jul 30 17:31:37 2019 +0200
> # Node ID 31b1bd472745ee67718afa1fb141aa626dc765bd
> # Parent  e0a1b6871316311ad9d774c0a5302e60c57d4591
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r 31b1bd472745
> Add some attribute to EACRessourceRelation
> 
> Add support for the <relationEntry> and xml attributes
> for EACResourceRelation
> 
> diff -r e0a1b6871316 -r 31b1bd472745 cubicweb_eac/dataimport.py
> --- a/cubicweb_eac/dataimport.py	Mon Aug 12 15:03:45 2019 +0200
> +++ b/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -879,7 +879,11 @@
>          """Build a `EACResourceRelation` external entity (along with
>          ExternalUri entities).
>          """
> -        obj_uri = elem.attrib.get('{%(xlink)s}href' % self.namespaces)
> +        obj_uri = None
> +        resource_role = None
> +        agent_role = None
> +        if elem.attrib.get('{%(xlink)s}href' % self.namespaces):
> +            obj_uri = elem.attrib.pop('{%(xlink)s}href' % self.namespaces)
>          if obj_uri is None:
>              self.import_log.record_warning(self._(
>                  'found a resourceRelation without any object (no xlink:href '
> @@ -890,16 +894,24 @@
>              'resource_relation_resource': set([obj_uri]),
>              'resource_relation_agent': set([self.record.extid]),
>          }
> -        resource_role = elem.attrib.get('{%(xlink)s}role' % self.namespaces)
> +        relation_entry = self._elem_find(elem, 'eac:relationEntry')
> +        if relation_entry is not None:
> +            values['relation_entry'] = set([text_type(relation_entry.text)])
> +        if elem.attrib.get('{%(xlink)s}role' % self.namespaces):
> +            resource_role = elem.attrib.pop('{%(xlink)s}role' % self.namespaces)

Why changing how "resource_role" is processed? This is unrelated to this
patch in any cases.

>          if resource_role:
>              values['resource_role'] = set([text_type(resource_role)])
> -        agent_role = elem.attrib.get('resourceRelationType')
> +        if elem.attrib.get('resourceRelationType'):
> +            agent_role = elem.attrib.pop('resourceRelationType')

Same here.

>          if agent_role:
>              values['agent_role'] = set([text_type(agent_role)])
>          dates = self.parse_daterange(self._elem_find(elem, 'eac:dateRange'))
>          if dates:
>              values.update(dates)
>          values.update(self.parse_tag_description(elem))
> +        attrib = sorted(dict(elem.attrib).items())
> +        if attrib:
> +            values.update({'attributes': set([text_type(attrib)])})

How about storing a JSON dump of "attrib" instead of a Python string
representation? I think it'd be nicer and ensure that the value is
always de-serializable. We can handle this step nicely with a property
on the entity class:

    class EACResourceRelation(AnyEntity):
        __regid__ = 'EACResourceRelation'

        @property
        def attributes(self):
            return json.loads(super(EACResourceRelation, self).attributes)


>          yield ExtEntity('EACResourceRelation', self._gen_extid(), values)
>  
>      @filter_none

> diff -r e0a1b6871316 -r 31b1bd472745 test/data/FRAD033_EAC_00001_simplified.xml
> --- a/test/data/FRAD033_EAC_00001_simplified.xml	Mon Aug 12 15:03:45 2019 +0200
> +++ b/test/data/FRAD033_EAC_00001_simplified.xml	Tue Jul 30 17:31:37 2019 +0200
> @@ -269,6 +269,7 @@
>            <fromDate>1673</fromDate>
>            <toDate>1963</toDate>
>          </dateRange>
> +	<relationEntry>Gironde. Conseil général. Direction de l'administration et de la sécurité juridique</relationEntry>
>        </resourceRelation>
>        <functionRelation
>  	  functionRelationType="performs"

Can you avoid introducing tabs in this file? This messes up with spaces.



More information about the saem-devel mailing list