[PATCH eac V3] Add some attribute to EACRessourceRelation

Frank Bessou frank.bessou at logilab.fr
Mon Aug 19 11:21:51 CEST 2019



On 13/08/2019 13:47, Guillaume Vandevelde wrote:
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1564500697 -7200
> #      Tue Jul 30 17:31:37 2019 +0200
> # Node ID 021982e0177f347d3aea638d9896960d8941962c
> # Parent  b01f855bcba82be73c00ae7463d02b7bcf08e56b
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r 021982e0177f
> Add some attribute to EACRessourceRelation
> 
> Add support for the <relationEntry> and xml attributes
> for EACResourceRelation
> 
> diff -r b01f855bcba8 -r 021982e0177f 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
> @@ -18,6 +18,7 @@
>   """
>   
>   from collections import deque
> +import json
>   import datetime
>   from functools import wraps, partial
>   import inspect
> @@ -886,6 +887,9 @@
>               'resource_relation_resource': set([obj_uri]),
>               'resource_relation_agent': set([self.record.extid]),
>           }
> +        relation_entry = self._elem_find(elem, 'eac:relationEntry')
> +        if relation_entry is not None:
> +            values['relation_entry'] = set([text_type(relation_entry.text)])
>           resource_role = elem.attrib.get('{%(xlink)s}role' % self.namespaces)
>           if resource_role:
>               values['resource_role'] = set([text_type(resource_role)])
> @@ -895,6 +899,9 @@
>           dates = self.parse_daterange(self._elem_find(elem, 'eac:dateRange'))
>           if dates:
>               values.update(dates)
> +        if elem.attrib:


If elem.attrib is not present entity.json_attrs will probably throw, you 
can either handle this in the json_attrs property or here by rejecting 
XML without elem.attrib (depending on business).


> +            attributes = json.dumps(dict(elem.attrib), sort_keys=True)
> +            values.update({'attributes': set([text_type(attributes)])})
>           values.update(self.parse_tag_description(elem))
>           yield ExtEntity('EACResourceRelation', self._gen_extid(), values)
>   
> diff -r b01f855bcba8 -r 021982e0177f cubicweb_eac/entities.py
> --- a/cubicweb_eac/entities.py	Mon Aug 12 15:03:45 2019 +0200
> +++ b/cubicweb_eac/entities.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -16,6 +16,8 @@
>   # with this program. If not, see <http://www.gnu.org/licenses/>.
>   """cubicweb-eac entity's classes"""
>   
> +import json
> +
>   from functools import wraps
>   
>   from six import text_type
> @@ -112,7 +114,10 @@
>   
>   class EACResourceRelation(AnyEntity):
>       __regid__ = 'EACResourceRelation'
> -    fetch_attrs, cw_fetch_order = fetch_config(('agent_role', 'resource_role', 'description'))
> +    fetch_attrs, cw_fetch_order = fetch_config(('agent_role',
> +                                                'attributes',
> +                                                'resource_role',
> +                                                'description'))
>   
>       @property
>       def record(self):
> @@ -122,6 +127,10 @@
>       def resource(self):
>           return self.resource_relation_resource[0]
>   
> +    @property
> +    def json_attrs(self):
> +        return json.loads(self.attributes)
> +
>       def dc_title(self):
>           agent_title = self.record.dc_title()
>           if self.agent_role:
> diff -r b01f855bcba8 -r 021982e0177f cubicweb_eac/migration/0.9.0_Any.py
> --- a/cubicweb_eac/migration/0.9.0_Any.py	Mon Aug 12 15:03:45 2019 +0200
> +++ b/cubicweb_eac/migration/0.9.0_Any.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -2,3 +2,5 @@
>   add_entity_type('HistoricalEvent')
>   add_entity_type('Convention')
>   add_entity_type('EACFunctionRelation')
> +add_attribute('EACResourceRelation', 'attributes')
> +add_attribute('EACResourceRelation', 'relation_entry')
> diff -r b01f855bcba8 -r 021982e0177f cubicweb_eac/schema.py
> --- a/cubicweb_eac/schema.py	Mon Aug 12 15:03:45 2019 +0200
> +++ b/cubicweb_eac/schema.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -404,11 +404,13 @@
>       """Represent a relation between an AuthorityRecord and a remote resource in the
>       EAC-CPF model.
>       """
> +    relation_entry = RichString(fulltextindexed=True)

Can you add a description ? :)

>       agent_role = String(description=_('type of relation the agent has to the resource'),
>                           internationalizable=True)
>       resource_role = String(description=_('type or nature of the remote resource'),
>                              internationalizable=True)
>       description = RichString(fulltextindexed=True)
> +    attributes = String(fulltextindexed=True)

Same here, it is not evident that this attribute represents the jsons 
representation of xml attributes.

>   
>   
>   class resource_relation_agent(RelationDefinition):
> diff -r b01f855bcba8 -r 021982e0177f 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"
> diff -r b01f855bcba8 -r 021982e0177f test/test_dataimport.py
> --- a/test/test_dataimport.py	Mon Aug 12 15:03:45 2019 +0200
> +++ b/test/test_dataimport.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -384,6 +384,16 @@
>                ),
>               ('EACResourceRelation', _gen_extid(),
>                {'agent_role': set([u'creatorOf']),
> +              'attributes': set([u'{"resourceRelationType": "creatorOf", '
> +                                 u'"{http://www.w3.org/1999/xlink}actuate": '
> +                                 u'"onRequest", "{http://www.w3.org/1999/xlin'
> +                                 u'k}href": "http://gael.gironde.fr/ead.html?i'
> +                                 u'd=FRAD033_IR_N", "{http://www.w3.org/1999/xl'
> +                                 u'ink}role": "Fonds d\'archives", "{http://www.'
> +                                 u'w3.org/1999/xlink}show": "new", "{http://www.w'
> +                                 u'3.org/1999/xlink}type": "simple"}']),
> +              'relation_entry': set([u'Gironde. Conseil g\xe9n\xe9ral. Direction de'
> +                                     u' l\'administration et de la s\xe9curit\xe9 juridique']),
>                 'resource_role': set([u'Fonds d\'archives']),
>                 'resource_relation_resource': set([
>                     'http://gael.gironde.fr/ead.html?id=FRAD033_IR_N']),
> @@ -756,6 +766,15 @@
>                            u'<he xmlns="urn:isbn:1-931666-33-4" xmlns:xlink="http'
>                            u'://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org'
>                            u'/2001/XMLSchema-instance">joe</he>')
> +        self.assertEqual(rrelation.json_attrs, {"resourceRelationType": "creatorOf",
> +                                                "{http://www.w3.org/1999/xlink}actuate":
> +                                                "onRequest",
> +                                                "{http://www.w3.org/1999/xlink}href":
> +                                                "http://gael.gironde.fr/ead.html?id=FRAD033_IR_N",
> +                                                "{http://www.w3.org/1999/xlink}role":
> +                                                "Fonds d'archives",
> +                                                "{http://www.w3.org/1999/xlink}show": "new",
> +                                                "{http://www.w3.org/1999/xlink}type": "simple"})
>           rset = cnx.find('EACFunctionRelation', r_type=u'performs')
>           func_relation = rset.one()
>           self.assertEqual(func_relation.attributes,
> 

-- 
Frank Bessou
Logilab         https://www.logilab.fr



More information about the saem-devel mailing list