[PATCH eac V2] Add some attribute to EACRessourceRelation

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Mon Aug 12 17:34:22 CEST 2019


# 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)
         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')
         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)])})
         yield ExtEntity('EACResourceRelation', self._gen_extid(), values)
 
     @filter_none
diff -r e0a1b6871316 -r 31b1bd472745 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 e0a1b6871316 -r 31b1bd472745 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)
     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)
 
 
 class resource_relation_agent(RelationDefinition):
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"
diff -r e0a1b6871316 -r 31b1bd472745 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,11 @@
              ),
             ('EACResourceRelation', _gen_extid(),
              {'agent_role': set([u'creatorOf']),
+              'attributes': set([u"[('{http://www.w3.org/1999/xlink}actuate', 'onRequest'),"
+                                 u" ('{http://www.w3.org/1999/xlink}show', 'new'), ('{http"
+                                 u"://www.w3.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']),


More information about the saem-devel mailing list