[PATCH eac V2] Add DateEntity for representing dates

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Wed Aug 21 16:26:55 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1564142170 -7200
#      Fri Jul 26 13:56:10 2019 +0200
# Node ID 3b9957c5d256f06baf506d50bfcfecfec9865cb0
# Parent  64b8b0772995c366eb26e4f652bb6b433ad269db
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 3b9957c5d256
Add DateEntity for representing dates

Add a date entity to represent <date>, <dateRange> and <dateSet> as
childs of other objects.

diff -r 64b8b0772995 -r 3b9957c5d256 cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Fri Jul 26 13:56:10 2019 +0200
@@ -176,6 +176,8 @@
 
 add_citations_for = partial(add_child_for, relation='has_citation', builder='build_citation')
 add_events_for = partial(add_child_for, relation='has_event', builder='build_event')
+add_dates_for = partial(add_child_for, relation='date_relation',
+                        builder='build_date_entry')
 
 
 def require_tag(tagname):
@@ -415,6 +417,25 @@
         for name_entry in name_entries:
             yield self.build_name_entry(name_entry)
 
+    def extract_dates_from(self, elem, tag):
+        for date in self.find_nested(elem, 'eac:date', tag):
+            yield ExtEntity('DateEntity', self._gen_extid(),
+                            {'start_date': set([self.parse_date(date)]),
+                             'end_date': set([self.parse_date(date)])})
+        for date_range in self.find_nested(elem, 'eac:dateRange', tag):
+            yield ExtEntity('DateEntity', self._gen_extid(), self.parse_daterange(date_range))
+
+    @filter_empty
+    @filter_none
+    @elem_maybe_none
+    def build_date_entry(self, elem):
+        """Build DateEntitys linked to a parent entity"""
+        for extentity in self.extract_dates_from(elem, 'eac:useDates'):
+            yield extentity
+        for date_set in self._elem_findall(elem, 'eac:dateSet'):
+            for extentity in self.extract_dates_from(date_set, 'eac:dateSet'):
+                yield extentity
+
     @filter_none
     def parse_description(self, description):
         """Parse the `description` tag and yield external entities, possibly
@@ -546,6 +567,7 @@
     @relate_to_record_through('LegalStatus', 'legal_status_agent')
     @filter_empty
     @add_citations_for('LegalStatus')
+    @add_dates_for('LegalStatus')
     @equivalent_concept('eac:term', 'LegalStatus')
     def build_legal_status(self, elem, **kwargs):
         """Build a `LegalStatus` external entity.
@@ -556,19 +578,13 @@
         term = self._elem_find(elem, 'eac:term')
         if term is not None and term.text:
             values['term'] = set([text_type(term.text)])
-        dateelem = self._elem_find(elem, 'eac:dateRange')
-        dates = self.parse_daterange(dateelem)
-        if dates:
-            values.update(dates)
-        legalstatus = ExtEntity('LegalStatus', self._gen_extid(), values)
-        if dateelem is not None:
-            self.record_visited(dateelem, legalstatus)
-        yield legalstatus
+        yield ExtEntity('LegalStatus', self._gen_extid(), values)
 
     @elem_maybe_none
     @relate_to_record_through('Mandate', 'mandate_agent')
     @filter_empty
     @add_citations_for('Mandate')
+    @add_dates_for('Mandate')
     @equivalent_concept('eac:term', 'Mandate')
     def build_mandate(self, elem, **kwargs):
         """Build a `Mandate` external entity.
@@ -579,10 +595,6 @@
         term = self._elem_find(elem, 'eac:term')
         if term is not None and term.text:
             values['term'] = set([text_type(term.text)])
-        dateelem = self._elem_find(elem, 'eac:dateRange')
-        dates = self.parse_daterange(dateelem)
-        if dates:
-            values.update(dates)
         yield ExtEntity('Mandate', self._gen_extid(), values)
 
     @elem_maybe_none
@@ -620,6 +632,7 @@
                 values['abstract'] = set([text_type(abstract.text)])
             yield ExtEntity('History', self._gen_extid(), values)
 
+    @add_dates_for('HistoricalEvent')
     @filter_none
     @filter_empty
     @elem_maybe_none
@@ -629,18 +642,10 @@
         if citems is not None:
             for citem in citems:
                 values = {}
-                date = self._elem_find(citem, 'eac:date')
-                date_range = self._elem_find(citem, 'eac:dateRange')
                 event = self._elem_find(citem, 'eac:event')
                 if event is not None and event.text:
                     values['event'] = set([text_type(event.text)])
-                    if date is None and date_range is not None:
-                        date_range = self.parse_daterange(date_range)
-                        values.update(date_range)
-                    elif date is not None:
-                        values.update({'start_date': set([self.parse_date(date)]),
-                                       'end_date': set([self.parse_date(date)])})
-                    yield ExtEntity('HistoricalEvent', self._gen_extid(), values)
+                yield ExtEntity('HistoricalEvent', self._gen_extid(), values)
 
     @elem_maybe_none
     @relate_to_record_through('Structure', 'structure_agent')
@@ -655,6 +660,7 @@
     @relate_to_record_through('AgentPlace', 'place_agent')
     @filter_empty
     @add_citations_for('AgentPlace')
+    @add_dates_for('AgentPlace')
     @equivalent_concept('eac:placeEntry', 'AgentPlace')
     def build_place(self, elem):
         """Build a AgentPlace external entity"""
@@ -686,6 +692,7 @@
     @relate_to_record_through('AgentFunction', 'function_agent')
     @filter_empty
     @add_citations_for('AgentFunction')
+    @add_dates_for('AgentFunction')
     @equivalent_concept('eac:term', 'AgentFunction')
     def build_function(self, elem):
         """Build a `AgentFunction`s external entities"""
@@ -698,6 +705,7 @@
     @relate_to_record_through('Occupation', 'occupation_agent')
     @filter_empty
     @add_citations_for('Occupation')
+    @add_dates_for('Occupation')
     @equivalent_concept('eac:term', 'Occupation')
     def build_occupation(self, elem):
         """Build a `Occupation`s external entities"""
@@ -705,10 +713,6 @@
         term = self._elem_find(elem, 'eac:term')
         if term is not None:
             values['term'] = set([text_type(term.text)])
-        dateelem = self._elem_find(elem, 'eac:dateRange')
-        dates = self.parse_daterange(dateelem)
-        if dates:
-            values.update(dates)
         yield ExtEntity('Occupation', self._gen_extid(), values)
 
     @relate_to_record_through('GeneralContext', 'general_context_of')
@@ -792,6 +796,9 @@
 
     @add_xml_wrap_for('AssociationRelation', 'ChronologicalRelation',
                       'HierarchicalRelation')
+    @add_dates_for('AssociationRelation')
+    @add_dates_for('ChronologicalRelation')
+    @add_dates_for('HierarchicalRelation')
     def build_relation(self, elem):
         """Build a relation between records external entity (with proper type)."""
         relationship = elem.attrib.get('cpfRelationType')
@@ -840,13 +847,10 @@
         rentry = self._elem_find(elem, 'eac:relationEntry')
         if rentry is not None and rentry.text.strip():
             values['entry'] = set([text_type(rentry.text)])
-        dates = self.parse_daterange(
-            self._elem_find(elem, 'eac:dateRange'))
-        if dates:
-            values.update(dates)
         values.update(self.parse_tag_description(elem))
         yield ExtEntity(etype, self._gen_extid(), values)
 
+    @add_dates_for('EACFunctionRelation')
     @add_xml_wrap_for('EACFunctionRelation')
     def build_function_relation(self, elem):
         """Build a relation between function entities
@@ -862,10 +866,6 @@
             yield external_uri(obj_uri)
             values.update(
                 {'function_relation_function': set([text_type(obj_uri)])})
-        dates = self.parse_daterange(
-            self._elem_find(elem, 'eac:dateRange'))
-        if dates:
-            values.update(dates)
         if relationship:
             values.update({'r_type': set([text_type(relationship)])})
         values.update({
@@ -882,6 +882,7 @@
         values.update({'xml_attributes': set([text_type(attributes)])})
         yield ExtEntity('EACFunctionRelation', self._gen_extid(), values)
 
+    @add_dates_for('EACResourceRelation')
     @add_xml_wrap_for('EACResourceRelation')
     def build_resource_relation(self, elem):
         """Build a `EACResourceRelation` external entity (along with
@@ -907,9 +908,6 @@
         agent_role = elem.attrib.pop('resourceRelationType', None)
         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)
         if elem.attrib:
             attributes = json.dumps(dict(elem.attrib), sort_keys=True)
         else:
diff -r 64b8b0772995 -r 3b9957c5d256 cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/entities.py	Fri Jul 26 13:56:10 2019 +0200
@@ -33,6 +33,21 @@
 from cubicweb_eac import TYPE_MAPPING, ADDRESS_MAPPING, MAINTENANCETYPE_MAPPING
 
 
+class DateRelationMixin(object):
+
+    @property
+    def start_date(self):
+        if self.date_relation:
+            if len(self.date_relation) > 0:
+                return self.date_relation[0].start_date
+
+    @property
+    def end_date(self):
+        if self.date_relation:
+            if len(self.date_relation) > 0:
+                return self.date_relation[0].end_date
+
+
 class AuthorityRecord(AnyEntity):
     __regid__ = 'AuthorityRecord'
     fetch_attrs, cw_fetch_order = fetch_config(('agent_kind',))
@@ -68,7 +83,7 @@
     fetch_attrs, cw_fetch_order = fetch_config(('name',))
 
 
-class _Relation(AnyEntity):
+class _Relation(DateRelationMixin, AnyEntity):
     __abstract__ = True
 
     def dc_description(self):
@@ -119,7 +134,7 @@
         return json.loads(self.xml_attributes)
 
 
-class EACResourceRelation(AnyEntity, JsonAttrsMixin):
+class EACResourceRelation(DateRelationMixin, AnyEntity, JsonAttrsMixin):
     __regid__ = 'EACResourceRelation'
     fetch_attrs, cw_fetch_order = fetch_config(('agent_role',
                                                 'xml_attributes',
@@ -146,7 +161,7 @@
                  'to': resource_title})
 
 
-class EACFunctionRelation(AnyEntity, JsonAttrsMixin):
+class EACFunctionRelation(DateRelationMixin, AnyEntity, JsonAttrsMixin):
     __regid__ = 'EACFunctionRelation'
     fetch_attrs, cw_fetch_order = fetch_config(('r_type',
                                                 'description',
@@ -178,12 +193,12 @@
         return self.equivalent_concept and self.equivalent_concept[0] or None
 
 
-class AgentPlace(SameAsMixIn, AnyEntity):
+class AgentPlace(DateRelationMixin, SameAsMixIn, AnyEntity):
     __regid__ = 'AgentPlace'
     fetch_attrs, cw_fetch_order = fetch_config(('name', 'role'))
 
 
-class AgentFunction(SameAsMixIn, AnyEntity):
+class AgentFunction(DateRelationMixin, SameAsMixIn, AnyEntity):
     __regid__ = 'AgentFunction'
     fetch_attrs, cw_fetch_order = fetch_config(('name', 'description'))
 
@@ -193,16 +208,16 @@
     fetch_attrs, cw_fetch_order = fetch_config(('uri', 'note'))
 
 
-class Mandate(SameAsMixIn, AnyEntity):
+class Mandate(DateRelationMixin, SameAsMixIn, AnyEntity):
     __regid__ = 'Mandate'
     fetch_attrs, cw_fetch_order = fetch_config(('term', 'description'))
 
 
-class LegalStatus(SameAsMixIn, AnyEntity):
+class LegalStatus(DateRelationMixin, SameAsMixIn, AnyEntity):
     __regid__ = 'LegalStatus'
 
 
-class Occupation(SameAsMixIn, AnyEntity):
+class Occupation(DateRelationMixin, SameAsMixIn, AnyEntity):
     __regid__ = 'Occupation'
     fetch_attrs, cw_fetch_order = fetch_config(('term', 'description'))
 
@@ -217,7 +232,7 @@
     fetch_attrs, cw_fetch_order = fetch_config(('local_type', 'value'))
 
 
-class HistoricalEvent(AnyEntity):
+class HistoricalEvent(AnyEntity, DateRelationMixin):
     __regid__ = 'HistoricalEvent'
     fetch_attrs, cw_fetch_order = fetch_config(('event',))
 
diff -r 64b8b0772995 -r 3b9957c5d256 cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Fri Jul 26 13:56:10 2019 +0200
@@ -1,6 +1,7 @@
 add_entity_type('HistoricalEvent')
 add_entity_type('Convention')
 add_entity_type('EACFunctionRelation')
+add_entity_type('DateEntity')
 
 # Attributes to update
 add_attribute('EACResourceRelation', 'xml_attributes')
@@ -13,3 +14,11 @@
                'script_code'):
     add_attribute('NameEntry', attrib)
 
+for etype in ('AssociationRelation', 'ChronologicalRelation',
+              'HierarchicalRelation', 'Mandate', 'LegalStatus',
+              'HistoricalEvent', 'Occupation', 'EACFunctionRelation',
+              'EACResourceRelation'):
+    drop_attribute(etype, 'start_date')
+    drop_attribute(etype, 'end_date')
+
+add_relation_type('date_relation')
diff -r 64b8b0772995 -r 3b9957c5d256 cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/schema.py	Fri Jul 26 13:56:10 2019 +0200
@@ -31,17 +31,6 @@
     addressbook.PostalAddress.get_relation(attrname).cardinality = '?1'
 
 
-def dated_entity_type(cls):
-    """Class decorator adding `start_date` and `end_date` attribute to an
-    EntityType.
-    """
-    cls.add_relation(Date(constraints=[BoundaryConstraint(
-        '<=', Attribute('end_date'), msg=_('start date must be less than end date'))]),
-        name='start_date')
-    cls.add_relation(Date(), name='end_date')
-    return cls
-
-
 def xml_wrap(cls):
     """Class decorator adding an `xml_wrap` attribute to an EntityType."""
     desc = _('XML elements not contained in EAC-CPF namespace')
@@ -53,8 +42,10 @@
                              indexed=True, fulltextindexed=True), name='agent')
 
 
- at dated_entity_type
 class AuthorityRecord(EntityType):
+    start_date = Date(constraints=[BoundaryConstraint(
+        '<=', Attribute('end_date'), msg=_('start date must be less than end date'))])
+    end_date = Date()
     record_id = String(indexed=True)
     isni = String(unique=True,
                   description=_('International Standard Name Identifier'))
@@ -90,6 +81,17 @@
     inlined = True
 
 
+class date_relation(RelationDefinition):
+    subject = ('HierarchicalRelation', 'HistoricalEvent',
+               'ChronologicalRelation', 'AssociationRelation',
+               'AgentFunction', 'EACFunctionRelation', 'LegalStatus',
+               'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation')
+    object = 'DateEntity'
+    cardinality = '*1'
+    composite = 'subject'
+    fulltext_container = 'subject'
+
+
 class EACOtherRecordId(EntityType):
     value = String(required=True, fulltextindexed=True, indexed=True)
     local_type = String(indexed=True)
@@ -207,7 +209,6 @@
 
 
 @xml_wrap
- at dated_entity_type
 class AssociationRelation(EntityType):
     """Association relation between authority records"""
     entry = String()
@@ -223,7 +224,6 @@
 
 
 @xml_wrap
- at dated_entity_type
 class ChronologicalRelation(EntityType):
     """Chronological relation between authority records"""
     entry = String()
@@ -239,7 +239,6 @@
 
 
 @xml_wrap
- at dated_entity_type
 class HierarchicalRelation(EntityType):
     """Hierarchical relation between authority records"""
     entry = String()
@@ -264,14 +263,12 @@
     object = 'AuthorityRecord'
 
 
- at dated_entity_type
 class Mandate(EntityType):
     """Reference text coming from an authority"""
     term = String(fulltextindexed=True)
     description = RichString(fulltextindexed=True)
 
 
- at dated_entity_type
 class LegalStatus(EntityType):
     """Information relative to the legal status of an authority"""
     term = String(fulltextindexed=True)
@@ -290,7 +287,6 @@
     text = RichString(fulltextindexed=True)
 
 
- at dated_entity_type
 class HistoricalEvent(EntityType):
     """Events linked to an History object"""
     event = RichString(fulltextindexed=True)
@@ -310,7 +306,6 @@
     description = RichString(fulltextindexed=True)
 
 
- at dated_entity_type
 class Occupation(EntityType):
     term = String(fulltextindexed=True)
     description = RichString(fulltextindexed=True)
@@ -382,7 +377,6 @@
 
 
 @xml_wrap
- at dated_entity_type
 class EACFunctionRelation(EntityType):
     """Represent a relation between an AuthorityRecord and a function"""
     r_type = String(internationalizable=True,
@@ -411,7 +405,6 @@
 
 
 @xml_wrap
- at dated_entity_type
 class EACResourceRelation(EntityType):
     """Represent a relation between an AuthorityRecord and a remote resource in the
     EAC-CPF model.
@@ -444,6 +437,14 @@
     inlined = True
 
 
+class DateEntity(EntityType):
+    """Represent either a date tag or a dateRange tag
+    for the representation of dateSets"""
+    start_date = Date(constraints=[BoundaryConstraint(
+        '<=', Attribute('end_date'), msg=_('start date must be less than end date'))])
+    end_date = Date()
+
+
 @xml_wrap
 class EACSource(EntityType):
     """A source used to establish the description of an AuthorityRecord"""
diff -r 64b8b0772995 -r 3b9957c5d256 test/test_dataimport.py
--- a/test/test_dataimport.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/test/test_dataimport.py	Fri Jul 26 13:56:10 2019 +0200
@@ -84,7 +84,7 @@
         return importer.external_entities()
 
     def test_parse_FRAD033_EAC_00001(self):
-        _gen_extid = map(str, (x for x in count() if x != 2)).next
+        _gen_extid = map(str, (x for x in count() if x not in (2, 25))).next
         expected = [
             ('AuthorityRecord', 'FRAD033_EAC_00001',
              {'isni': set([u'22330001300016']),
@@ -217,13 +217,17 @@
              ),
             ('LegalStatus', _gen_extid(),
              {'term': set([u'Collectivité territoriale']),
-              'start_date': set([datetime.date(1234, 1, 1)]),
-              'end_date': set([datetime.date(3000, 1, 1)]),
+              'date_relation': set(['18']),
               'description': set([u'Description du statut']),
               'description_format': set([u'text/plain']),
               'legal_status_agent': set(['FRAD033_EAC_00001']),
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1234, 1, 1)]),
+              'end_date': set([datetime.date(3000, 1, 1)])
+              },
+             ),
             ('Mandate', _gen_extid(),
              {'term': set([u'1. Constitutions françaises']),
               'description': set([u'Description du mandat']),
@@ -242,8 +246,8 @@
               ]),
               'text_format': set([u'text/html']),
               'history_agent': set(['FRAD033_EAC_00001']),
-              'has_citation': set(['20', '21']),
-              'has_event': set(['22', '23']),
+              'has_citation': set(['21', '22']),
+              'has_event': set(['24', '23']),
               },
              ),
             ('Citation', _gen_extid(),
@@ -257,14 +261,12 @@
              {'event': [u'Left Mer and moved to the mainland.\n\t      '
                         u'Worked at various jobs including canecutter\n\t      '
                         u'and railway labourer.\n\t      '],
-              'end_date': set([datetime.date(1957, 1, 1)]),
-              'start_date': set([datetime.date(1957, 1, 1)])}
+              },
              ),
             ('HistoricalEvent', _gen_extid(),
              {'event': set([u'Union representative, Townsville-\n\t      '
                             u'Mount Isa rail construction project.\n\t      ']),
-              'end_date': set([datetime.date(1961, 1, 1)]),
-              'start_date': set([datetime.date(1960, 1, 1)])}
+              },
              ),
             ('Structure', _gen_extid(),
              {'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
@@ -306,15 +308,19 @@
              ),
             ('Occupation', _gen_extid(),
              {'term': set([u'Réunioniste']),
-              'start_date': set([datetime.date(1987, 1, 1)]),
-              'end_date': set([datetime.date(2099, 1, 1)]),
+              'date_relation': set(['31']),
               'description': set([u'Organisation des réunions ...']),
               'description_format': set([u'text/plain']),
               'occupation_agent': set(['FRAD033_EAC_00001']),
-              'has_citation': set(['29']),
+              'has_citation': set(['32']),
               'equivalent_concept': set(['http://pifgadget.com']),
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1987, 1, 1)]),
+              'end_date': set([datetime.date(2099, 1, 1)])
+              },
+             ),
             ('Citation', _gen_extid(),
              {'note': set([u'la bible']),
               },
@@ -324,7 +330,7 @@
                               u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
                               u'xmlns:xlink="http://www.w3.org/1999/xlink">very famous</p>']),
               'content_format': set([u'text/html']),
-              'has_citation': set(['31']),
+              'has_citation': set(['34']),
               'general_context_of': set(['FRAD033_EAC_00001']),
               }
              ),
@@ -338,16 +344,20 @@
               },
              ),
             ('HierarchicalRelation', _gen_extid(),
-             {'start_date': set([datetime.date(2008, 1, 1)]),
-              'end_date': set([datetime.date(2099, 1, 1)]),
-              'entry': set([u"Gironde. Conseil général. Direction de l'administration et de "
+             {'entry': set([u"Gironde. Conseil général. Direction de l'administration et de "
                             u"la sécurité juridique"]),
+              'date_relation': set(['36']),
               'description': set([u'Coucou']),
               'description_format': set([u'text/plain']),
               'hierarchical_parent': set(['CG33-DIRADSJ']),
               'hierarchical_child': set(['FRAD033_EAC_00001']),
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(2008, 1, 1)]),
+              'end_date': set([datetime.date(2099, 1, 1)])
+              },
+             ),
             ('ExternalUri', 'whatever',
              {'uri': set([u'whatever']),
               'cwuri': set([u'whatever']),
@@ -361,15 +371,19 @@
             ('ChronologicalRelation', _gen_extid(),
              {'chronological_predecessor': set(['whatever']),
               'chronological_successor': set(['FRAD033_EAC_00001']),
-              'start_date': set([datetime.date(1917, 1, 1)]),
-              'end_date': set([datetime.date(2009, 1, 1)]),
+              'date_relation': set(['38']),
               'entry': set([u'CG32']),
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1917, 1, 1)]),
+              'end_date': set([datetime.date(2009, 1, 1)])
+              },
+             ),
             ('ChronologicalRelation', _gen_extid(),
              {'chronological_predecessor': set(['FRAD033_EAC_00001']),
               'chronological_successor': set(['/dev/null']),
-              'start_date': set([datetime.date(2042, 1, 1)]),
+              'date_relation': set(['40']),
               'xml_wrap': set(['<gloups xmlns="urn:isbn:1-931666-33-4"'
                                u' xmlns:xsi="http://www.w3.org/2001/XML'
                                u'Schema-instance" xmlns:xlink="http://'
@@ -377,6 +391,10 @@
               'entry': set([u'Trash']),
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(2042, 1, 1)])
+              },
+             ),
             ('AssociationRelation', _gen_extid(),
              {'association_from': set(['FRAD033_EAC_00001']),
               'association_to': set(['agent-x']),
@@ -384,6 +402,7 @@
              ),
             ('EACResourceRelation', _gen_extid(),
              {'agent_role': set([u'creatorOf']),
+              'date_relation': set(['43']),
               '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"}']),
@@ -393,14 +412,17 @@
               'resource_relation_resource': set([
                   'http://gael.gironde.fr/ead.html?id=FRAD033_IR_N']),
               'resource_relation_agent': set(['FRAD033_EAC_00001']),
-              'start_date': set([datetime.date(1673, 1, 1)]),
-              'end_date': set([datetime.date(1963, 1, 1)]),
               'xml_wrap': set(['<he xmlns="urn:isbn:1-931666-33-4" '
                                u'xmlns:xlink="http://www.w3.org/1999'
                                u'/xlink" xmlns:xsi="http://www.w3.org'
                                u'/2001/XMLSchema-instance">joe</he>'])
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1673, 1, 1)]),
+              'end_date': set([datetime.date(1963, 1, 1)])
+              },
+             ),
             ('EACFunctionRelation', _gen_extid(),
              {'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http:/'
                                   '/www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http:'
@@ -440,14 +462,18 @@
                                   'The second responsibility of the\n\t  '
                                   'Department is to control the establishment\n\t  '
                                   'and abolishment of schools.\n\t  </p>']),
-              'end_date': set([datetime.date(2001, 1, 1)]),
               'r_type': set([u'controls']),
               'description_format': set([u'text/html']),
+              'date_relation': set(['46']),
               'relation_entry': set([u'Establishment and abolishment\n\tof schools\n\t']),
-              'start_date': set([datetime.date(1922, 1, 1)]),
               'xml_attributes': set([u'{}'])
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1922, 1, 1)]),
+              'end_date': set([datetime.date(2001, 1, 1)])
+              },
+             ),
             ('EACFunctionRelation', _gen_extid(),
              {'function_relation_agent': set([u'FRAD033_EAC_00001']),
               'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
@@ -456,11 +482,15 @@
                                   u'w.w3.org/1999/xlink">Some description'
                                   u'\n            </p>']),
               'function_relation_function': set([u'ONLY_XLINK']),
-              'end_date': set([datetime.date(2001, 1, 1)]),
               'description_format': set([u'text/html']),
               'relation_entry': set([u'Some relation entry\n          ']),
-              'start_date': set([datetime.date(1922, 1, 1)]),
-              'xml_attributes': set([u'{}'])
+              'xml_attributes': set([u'{}']),
+              'date_relation': ['48'],
+              },
+             ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1922, 1, 1)]),
+              'end_date': set([datetime.date(2001, 1, 1)])
               },
              ),
             ('EACFunctionRelation', _gen_extid(),
@@ -471,11 +501,15 @@
                                   u'w.w3.org/1999/xlink">Some description'
                                   u'\n            </p>']),
               'r_type': set([u'ONLY_RELATION_TYPE']),
-              'end_date': set([datetime.date(2001, 1, 1)]),
               'description_format': set([u'text/html']),
               'relation_entry': set([u'Some relation entry\n          ']),
-              'start_date': set([datetime.date(1922, 1, 1)]),
-              'xml_attributes': set([u'{}'])
+              'xml_attributes': set([u'{}']),
+              'date_relation': ['50'],
+              },
+             ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1922, 1, 1)]),
+              'end_date': set([datetime.date(2001, 1, 1)])
               },
              ),
             ('ExternalUri', 'ONLY_XLINK',
@@ -681,7 +715,7 @@
                                cwuri=u'http://data.culture.fr/thesaurus/page/ark:/67717/T1-1074')
             cnx.commit()
             created, updated = testutils.eac_import(cnx, fpath)
-            self.assertEqual(len(created), 51)
+            self.assertEqual(len(created), 60)
             self.assertEqual(updated, set())
             rset = cnx.find('AuthorityRecord', isni=u'22330001300016')
             self.assertEqual(len(rset), 1)
@@ -826,10 +860,6 @@
         self.assertEqual(func_relation.function_relation_agent[0], record)
         self.assertEqual(func_relation.function_relation_function[0].uri,
                          u'FRAD033_IR_N')
-        self.assertEqual(func_relation.start_date,
-                         datetime.date(1922, 1, 1))
-        self.assertEqual(func_relation.end_date,
-                         datetime.date(2001, 1, 1))
 
     def _check_equivalent_concept(self, cnx, record):
         functions = dict((f.name, f) for f in record.reverse_function_agent)
diff -r 64b8b0772995 -r 3b9957c5d256 test/test_schema.py
--- a/test/test_schema.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/test/test_schema.py	Fri Jul 26 13:56:10 2019 +0200
@@ -103,6 +103,10 @@
                 'GeneralContext', 'Mandate', 'Occupation', 'AgentFunction',
                 'AgentPlace', 'History', 'LegalStatus', 'Convention',
             ])},
+            'DateEntity': {('date_relation', 'object'): set([
+                'HistoricalEvent', 'AgentFunction', 'EACFunctionRelation',
+                'LegalStatus', 'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation'
+            ])},
             'EACFunctionRelation': {('function_relation_agent', 'subject'):
                                     set(['AuthorityRecord'])},
             'EACOtherRecordId': {('eac_other_record_id_of', 'subject'):


More information about the saem-devel mailing list