[PATCH 2 of 2 eac V3] Add support for <functionRelation> in <cpfRelation>

Denis Laxalde denis.laxalde at logilab.fr
Fri Aug 9 16:11:07 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 db1a9540db1598fab4b038f9bc95219eeb8a6f12
> # Parent  8abcfe4e3ba441a6d5d5e5666b413961b8c22246
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r db1a9540db15
> Add support for <functionRelation> in <cpfRelation>
> 
> Create a new entity EACFunctionRelation similar to EACRessourceRelation.
> 
> diff -r 8abcfe4e3ba4 -r db1a9540db15 cubicweb_eac/dataimport.py
> --- a/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:36 2019 +0200
> +++ b/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -40,11 +40,11 @@
>  TYPE_MAPPING['human'] = u'person'
>  
>  ETYPES_ORDER_HINT = ('AgentKind', 'PhoneNumber', 'PostalAddress', 'AuthorityRecord',
> -                     'Convention', 'AgentPlace', 'Mandate', 'LegalStatus',
> -                     'History', 'HistoricalEvent', 'Structure', 'AgentFunction', 'Occupation',
> -                     'GeneralContext', 'AssociationRelation', 'ChronologicalRelation',
> -                     'HierarchicalRelation', 'EACResourceRelation', 'ExternalUri',
> -                     'EACSource', 'Activity')
> +                     'Convention', 'AgentPlace', 'Mandate',
> +                     'LegalStatus', 'History', 'HistoricalEvent', 'Structure', 'AgentFunction',
> +                     'Occupation', 'GeneralContext', 'AssociationRelation', 'ChronologicalRelation',
> +                     'HierarchicalRelation', 'EACResourceRelation', 'EACFunctionRelation',
> +                     'ExternalUri', 'EACSource', 'Activity')
>  
>  
>  class InvalidEAC(RuntimeError):
> @@ -773,7 +773,8 @@
>          if relations is None:
>              return
>          builders = (('eac:cpfRelation', self.build_relation),
> -                    ('eac:resourceRelation', self.build_resource_relation),)
> +                    ('eac:resourceRelation', self.build_resource_relation),
> +                    ('eac:functionRelation', self.build_function_relation),)
>          for xpath, builder in builders:
>              for elem in self._elem_findall(relations, xpath):
>                  for extentity in builder(elem):
> @@ -836,6 +837,39 @@
>          values.update(self.parse_tag_description(elem))
>          yield ExtEntity(etype, self._gen_extid(), values)
>  
> +    @add_xml_wrap_for('EACFunctionRelation')
> +    def build_function_relation(self, elem):
> +        """Build a relation between function entities
> +
> +        yield an ExternalUri object, and an EACFunctionRelation
> +        object that make the link between the ExternalUri and
> +        the AuthorityRecord object"""
> +        relationship = elem.attrib.get('functionRelationType')
> +        obj_uri = elem.attrib.get('{%(xlink)s}href' % self.namespaces)
> +        # Yield the ExternalUri object
> +        yield external_uri(obj_uri)
> +        values = self.parse_tag_description(elem)
> +        dates = self.parse_daterange(
> +            self._elem_find(elem, 'eac:dateRange'))
> +        if dates:
> +            values.update(dates)
> +        values.update({
> +            'r_type': set([text_type(relationship)]),

What happens if "relationship" is absent? I think this should be covered
in tests by having a functionRelation without this attribute.

Same about "href" attribute.

> +            'function_relation_function': set([text_type(obj_uri)]),
> +            'function_relation_agent': set([text_type(self.record.extid)]),
> +        })
> +        values.update(self.values_from_xpaths(
> +            elem,
> +            (('place_entry', 'eac:placeEntry'),
> +             ('relation_entry', 'eac:relationEntry'))))
> +        attrib = {k: v for (k, v) in dict(elem.attrib).items() if k not in {
> +            'functionRelationType',
> +            '{%(xlink)s}href' % self.namespaces
> +        }}
> +        if attrib:
> +            values.update({'attributes': set([text_type(attrib)])})
> +        yield ExtEntity('EACFunctionRelation', self._gen_extid(), values)
> +
>      @add_xml_wrap_for('EACResourceRelation')
>      def build_resource_relation(self, elem):
>          """Build a `EACResourceRelation` external entity (along with

> diff -r 8abcfe4e3ba4 -r db1a9540db15 cubicweb_eac/schema.py
> --- a/cubicweb_eac/schema.py	Tue Jul 30 17:31:36 2019 +0200
> +++ b/cubicweb_eac/schema.py	Tue Jul 30 17:31:37 2019 +0200
> @@ -371,6 +371,35 @@
>  
>  @xml_wrap
>  @dated_entity_type
> +class EACFunctionRelation(EntityType):
> +    """Represent a relation between an AuthorityRecord and a function"""
> +    r_type = String(internationalizable=True,
> +                    description=_('type of relation the function has '
> +                                  'with the Authority'))
> +    description = RichString(fulltextindexed=True)
> +    relation_entry = String(fulltextindexed=True)
> +    place_entry = String(fulltextindexed=True)
> +    attributes = String(fulltextindexed=True)
> +
> +
> +class function_relation_agent(RelationDefinition):
> +    subject = 'EACFunctionRelation'
> +    object = 'AuthorityRecord'
> +    cardinality = '1*'
> +    inlined = True
> +    composite = 'object'
> +    fulltext_container = 'object'
> +
> +
> +class function_relation_function(RelationDefinition):
> +    subject = 'EACFunctionRelation'
> +    object = 'ExternalUri'
> +    cardinality = '1*'

Like I said in the previous version, I think this should be "?*" because
we cannot assume on "href" attribute to be always present.

> +    inlined = True
> +
> +
> + at xml_wrap
> + at dated_entity_type
>  class EACResourceRelation(EntityType):
>      """Represent a relation between an AuthorityRecord and a remote resource in the
>      EAC-CPF model.



More information about the saem-devel mailing list