[PATCH eac v2] Add `identity` relations support in cpfrelations

Katia Saurfelt katia.saurfelt at logilab.fr
Mon Sep 2 15:31:53 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1565282746 -7200
#      Thu Aug 08 18:45:46 2019 +0200
# Node ID c02eb8b8c97d049e3482ceb704a7fc527006425f
# Parent  ddd96e4e7875bbd3f93c7fd6de2279b69be26206
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r c02eb8b8c97d
Add `identity` relations support in cpfrelations

diff --git a/cubicweb_eac/dataimport.py b/cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py
+++ b/cubicweb_eac/dataimport.py
@@ -47,7 +47,7 @@ ETYPES_ORDER_HINT = ('AgentKind', 'Phone
                      'AgentFunction', 'Occupation', 'GeneralContext', 'AssociationRelation',
                      'ChronologicalRelation', 'HierarchicalRelation', 'EACResourceRelation',
                      'EACFunctionRelation', 'ParallelNames', 'ExternalUri', 'EACSource',
-                     'Activity', 'EACOtherRecordId', 'NameEntry')
+                     'Activity', 'EACOtherRecordId', 'NameEntry', 'IdentityRelation')
 
 
 class InvalidEAC(RuntimeError):
@@ -915,13 +915,15 @@ class EACCPFImporter(object):
                     yield extentity
 
     @add_xml_wrap_for('AssociationRelation', 'ChronologicalRelation',
-                      'HierarchicalRelation')
+                      'HierarchicalRelation', 'IdentityRelation')
     @add_dates_for('AssociationRelation')
     @add_dates_for('ChronologicalRelation')
     @add_dates_for('HierarchicalRelation')
+    @add_dates_for('IdentityRelation')
     @add_place_entries_for('AssociationRelation')
     @add_place_entries_for('ChronologicalRelation')
     @add_place_entries_for('HierarchicalRelation')
+    @add_place_entries_for('IdentityRelation')
     def build_relation(self, elem):
         """Build a relation between records external entity (with proper type)."""
         relationship = elem.attrib.get('cpfRelationType')
@@ -952,6 +954,8 @@ class EACCPFImporter(object):
                                    'chronological_successor', 'chronological_predecessor'),
                 'associative': ('AssociationRelation',
                                 'association_to', 'association_from'),
+                'identity': ('IdentityRelation',
+                             'identity_to', 'identity_from'),
             }[relationship]
         except KeyError:
             self.import_log.record_warning(self._(
diff --git a/cubicweb_eac/entities.py b/cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py
+++ b/cubicweb_eac/entities.py
@@ -125,6 +125,18 @@ class HierarchicalRelation(_Relation):
         return self.hierarchical_child[0]
 
 
+class IdentityRelation(_Relation):
+    __regid__ = 'IdentityRelation'
+
+    @property
+    def subject(self):
+        return self.identity_from[0]
+
+    @property
+    def object(self):
+        return self.identity_to[0]
+
+
 class GeneralContext(AnyEntity):
     __regid__ = 'GeneralContext'
     fetch_attrs, cw_fetch_order = fetch_config(('content',))
diff --git a/cubicweb_eac/hooks.py b/cubicweb_eac/hooks.py
--- a/cubicweb_eac/hooks.py
+++ b/cubicweb_eac/hooks.py
@@ -42,6 +42,8 @@ class DeleteTernaryRelationsHook(hook.Ho
             'chronological_successor',
             'hierarchical_parent',
             'hierarchical_child',
+            'identity_from',
+            'identity_to'
         ):
             for relation in self.entity.related(rtype, role='object').entities():
                 if self._cw.deleted_in_transaction(relation.eid):
diff --git a/cubicweb_eac/migration/0.9.0_Any.py b/cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py
+++ b/cubicweb_eac/migration/0.9.0_Any.py
@@ -4,6 +4,7 @@ add_entity_type('ParallelNames')
 add_entity_type('EACFunctionRelation')
 add_entity_type('DateEntity')
 add_entity_type('PlaceEntry')
+add_entity_type('IdentityRelation')
 
 # Attributes to update
 add_attribute('EACResourceRelation', 'xml_attributes')
diff --git a/cubicweb_eac/schema.py b/cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py
+++ b/cubicweb_eac/schema.py
@@ -119,7 +119,7 @@ class date_relation(RelationDefinition):
                'ChronologicalRelation', 'AssociationRelation',
                'AgentFunction', 'EACFunctionRelation', 'LegalStatus',
                'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation',
-               'NameEntry')
+               'NameEntry', 'IdentityRelation')
     object = 'DateEntity'
     cardinality = '*1'
     composite = 'subject'
@@ -137,7 +137,8 @@ class place_entry_relation(RelationDefin
     subject = ('HierarchicalRelation', 'HistoricalEvent',
                'ChronologicalRelation', 'AssociationRelation',
                'AgentFunction', 'EACFunctionRelation', 'LegalStatus',
-               'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation')
+               'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation',
+               'IdentityRelation')
     object = 'PlaceEntry'
     cardinality = '*1'
     composite = 'subject'
@@ -261,6 +262,21 @@ class _agent_relation(RelationDefinition
 
 
 @xml_wrap
+class IdentityRelation(EntityType):
+    """Identity relation between authority records"""
+    entry = String()
+    description = RichString()
+
+
+class identity_from(_agent_relation):
+    subject = 'IdentityRelation'
+
+
+class identity_to(_agent_relation):
+    subject = 'IdentityRelation'
+
+
+ at xml_wrap
 class AssociationRelation(EntityType):
     """Association relation between authority records"""
     entry = String()
diff --git a/test/data/FRAD033_EAC_00001_simplified.xml b/test/data/FRAD033_EAC_00001_simplified.xml
--- a/test/data/FRAD033_EAC_00001_simplified.xml
+++ b/test/data/FRAD033_EAC_00001_simplified.xml
@@ -338,6 +338,14 @@
           <objectXMLWrap><gloups>hips</gloups></objectXMLWrap>
       </cpfRelation>
 
+      <cpfRelation cpfRelationType="identity" xlink:href="/dev/null" xlink:type="simple">
+          <relationEntry>Trash</relationEntry>
+          <dateRange>
+              <fromDate standardDate="2042">2042</fromDate>
+          </dateRange>
+          <objectXMLWrap><gloups>hips</gloups></objectXMLWrap>
+	</cpfRelation>
+
       <cpfRelation cpfRelationType="associative" xlink:href="agent-x" xlink:type="simple"></cpfRelation>
       <resourceRelation resourceRelationType="creatorOf"
         xmlns:xlink="http://www.w3.org/1999/xlink" 
diff --git a/test/test_dataimport.py b/test/test_dataimport.py
--- a/test/test_dataimport.py
+++ b/test/test_dataimport.py
@@ -466,6 +466,18 @@ class EACXMLParserTC(unittest.TestCase):
              {'start_date': set([datetime.date(2042, 1, 1)])
               },
              ),
+            ('IdentityRelation', _gen_extid(),
+             {'date_relation': ['55'],
+              'entry': [u'Trash'],
+              'identity_from': ['authorityrecord-FRAD033_EAC_00001'],
+              'identity_to': ['/dev/null'],
+              'xml_wrap': set([u'<gloups xmlns="urn:isbn:1-931666-33-4" '
+                               u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+                               u'xmlns:xlink="http://www.w3.org/1999/xlink">hips</gloups>'])}
+            ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': [datetime.date(2042, 1, 1)]}
+            ),
             ('AssociationRelation', _gen_extid(),
              {'association_from': set(['authorityrecord-FRAD033_EAC_00001']),
               'association_to': set(['agent-x']),
@@ -473,7 +485,7 @@ class EACXMLParserTC(unittest.TestCase):
              ),
             ('EACResourceRelation', _gen_extid(),
              {'agent_role': set([u'creatorOf']),
-              'date_relation': set(['56']),
+              'date_relation': set(['58']),
               'xml_attributes': set([u'{"{http://www.w3.org/1999/xlink}actuate": "onRequest", '
                                      u'"{http://www.w3.org/1999/xlink}show": "new", '
                                      u'"{http://www.w3.org/1999/xlink}type": "simple"}']),
@@ -535,7 +547,7 @@ class EACXMLParserTC(unittest.TestCase):
                                   'and abolishment of schools.\n\t  </p>']),
               'r_type': set([u'controls']),
               'description_format': set([u'text/html']),
-              'date_relation': set(['59']),
+              'date_relation': set(['61']),
               'relation_entry': set([u'Establishment and abolishment\n\tof schools\n\t']),
               'xml_attributes': set([u'{}'])
               },



More information about the saem-devel mailing list