[PATCH eac] Add prefix for the record id for db problems

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Wed Aug 28 10:30:49 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1561992566 -7200
#      Mon Jul 01 16:49:26 2019 +0200
# Node ID 683a13a4e83ba29a2c5dd6feb8716f7aaa91c24f
# Parent  999d2390ec6fefc19205dae04cfd7d9f2002319b
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 683a13a4e83b
Add prefix for the record id for db problems

Add the prefix so there is no more collision in the database between the eid of AR and the eid of ExternalUri

Fix a problem of extid and eid collision in the database.

diff -r 999d2390ec6f -r 683a13a4e83b cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Tue Jul 23 15:16:16 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Mon Jul 01 16:49:26 2019 +0200
@@ -1018,7 +1018,7 @@
         """Parse the `control` tag."""
         record_id = self._elem_find(control, 'eac:recordId')
         if record_id is not None and record_id.text and record_id.text.strip():
-            self.record.extid = record_id.text.strip()
+            self.record.extid = 'authorityrecord-{}'.format(record_id.text.strip())
             self.record.values['record_id'] = set([to_unicode(record_id.text)])
             self.record_visited(record_id, self.record)
         else:
diff -r 999d2390ec6f -r 683a13a4e83b test/test_dataimport.py
--- a/test/test_dataimport.py	Tue Jul 23 15:16:16 2019 +0200
+++ b/test/test_dataimport.py	Mon Jul 01 16:49:26 2019 +0200
@@ -86,34 +86,26 @@
     def test_parse_FRAD033_EAC_00001(self):
         _gen_extid = map(str, (x for x in count() if x not in (2, 36))).next
         expected = [
-            ('AuthorityRecord', 'FRAD033_EAC_00001',
-             {'isni': set([u'22330001300016']),
-              'start_date': set([datetime.date(1800, 1, 1)]),
-              'end_date': set([datetime.date(2099, 1, 1)]),
-              'agent_kind': set(['agentkind/authority']),
-              'record_id': set(['FRAD033_EAC_00001'])
-              },
-             ),
             ('EACOtherRecordId', _gen_extid(),
-             {'eac_other_record_id_of': set(['FRAD033_EAC_00001']),
+             {'eac_other_record_id_of': set(['authorityrecord-FRAD033_EAC_00001']),
               'value': set([u'1234']),
               },
              ),
             ('EACOtherRecordId', _gen_extid(),
-             {'eac_other_record_id_of': set(['FRAD033_EAC_00001']),
+             {'eac_other_record_id_of': set(['authorityrecord-FRAD033_EAC_00001']),
               'value': set([u'ABCD']),
               'local_type': set([u'letters']),
               },
              ),
             ('EACSource', _gen_extid(),
-             {'source_agent': set(['FRAD033_EAC_00001']),
+             {'source_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'title': set([u'1. Ouvrages imprimés...']),
               'description': set([u'des bouquins']),
               'description_format': set([u'text/plain']),
               },
              ),
             ('EACSource', _gen_extid(),
-             {'source_agent': set(['FRAD033_EAC_00001']),
+             {'source_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'url': set([u'http://archives.gironde.fr']),
               'title': set([u'Site des Archives départementales de la Gironde']),
               },
@@ -121,7 +113,7 @@
             ('Activity', _gen_extid(),
              {'type': set([u'create']),
               'agent_type': [u'human'],
-              'generated': set(['FRAD033_EAC_00001']),
+              'generated': set(['authorityrecord-FRAD033_EAC_00001']),
               'start': set([datetime.datetime(2013, 4, 24, 5, 34, 41)]),
               'end': set([datetime.datetime(2013, 4, 24, 5, 34, 41)]),
               'description': set([u'bla bla']),
@@ -129,7 +121,7 @@
               },
              ),
             ('Activity', _gen_extid(),
-             {'generated': set(['FRAD033_EAC_00001']),
+             {'generated': set(['authorityrecord-FRAD033_EAC_00001']),
               'type': set([u'modify']),
               'agent_type': [u'human'],
               'start': set([datetime.datetime(2015, 1, 15, 7, 16, 33)]),
@@ -138,7 +130,7 @@
               },
              ),
             ('Convention', _gen_extid(),
-             {'convention_of': ['FRAD033_EAC_00001'],
+             {'convention_of': ['authorityrecord-FRAD033_EAC_00001'],
               'abbrev': set([u'ISAAR(CPF)']),
               'has_citation': ['8'],
               'description_format': set([u'text/html']),
@@ -154,7 +146,7 @@
               },
              ),
             ('Convention', _gen_extid(),
-             {'convention_of': ['FRAD033_EAC_00001'],
+             {'convention_of': ['authorityrecord-FRAD033_EAC_00001'],
               'description_format': set([u'text/html']),
               'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
                                   u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -165,7 +157,7 @@
               },
              ),
             ('Convention', _gen_extid(),
-             {'convention_of': ['FRAD033_EAC_00001'],
+             {'convention_of': ['authorityrecord-FRAD033_EAC_00001'],
               'description_format': set([u'text/html']),
               'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
                                   u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -182,17 +174,17 @@
             ('NameEntry', _gen_extid(),
              {'parts': set([u'Gironde, Conseil général']),
               'form_variant': set([u'authorized']),
-              'name_entry_for': set(['FRAD033_EAC_00001']),
+              'name_entry_for': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('NameEntry', _gen_extid(),
              {'parts': set([u'CG33']),
               'form_variant': set([u'alternative']),
-              'name_entry_for': set(['FRAD033_EAC_00001']),
+              'name_entry_for': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('ParallelNames', _gen_extid(),
-             {'parallel_names_of': set(['FRAD033_EAC_00001']),
+             {'parallel_names_of': set(['authorityrecord-FRAD033_EAC_00001']),
               'simple_name_relation': set(['15', '14']),
               'authorized_form': set([u'AFNOR_Z44-060\n\t'])
               },
@@ -211,9 +203,9 @@
               },
              ),
             ('ParallelNames', _gen_extid(),
-             {'parallel_names_of': set(['FRAD033_EAC_00001']),
+             {'parallel_names_of': set(['authorityrecord-FRAD033_EAC_00001']),
               'date_relation': set(['17']),
-              'simple_name_relation': set(['19', '18', '20'])
+              'simple_name_relation': set(['20', '19', '18'])
               },
              ),
             ('DateEntity', _gen_extid(),
@@ -240,7 +232,7 @@
              ),
             ('AgentPlace', _gen_extid(),
              {'role': set([u'siege']),
-              'place_agent': set(['FRAD033_EAC_00001']),
+              'place_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'place_entry_relation': set(['23']),
               'place_address': set(['21']),
               },
@@ -251,7 +243,7 @@
               },
              ),
             ('AgentPlace', _gen_extid(),
-             {'place_agent': set(['FRAD033_EAC_00001']),
+             {'place_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'place_entry_relation': set(['25']),
               'role': set([u'domicile']),
               },
@@ -264,7 +256,7 @@
               },
              ),
             ('AgentPlace', _gen_extid(),
-             {'place_agent': set(['FRAD033_EAC_00001']),
+             {'place_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'role': set([u'dodo']),
               'place_entry_relation': set(['27']),
               },
@@ -278,7 +270,7 @@
               'date_relation': set(['29']),
               'description': set([u'Description du statut']),
               'description_format': set([u'text/plain']),
-              'legal_status_agent': set(['FRAD033_EAC_00001']),
+              'legal_status_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('DateEntity', _gen_extid(),
@@ -290,7 +282,7 @@
              {'term': set([u'1. Constitutions françaises']),
               'description': set([u'Description du mandat']),
               'description_format': set([u'text/plain']),
-              'mandate_agent': set(['FRAD033_EAC_00001']),
+              'mandate_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('History', _gen_extid(),
@@ -316,7 +308,7 @@
                             u'       style:italic">Gems\n\t      </span>\n\t'
                             u'      (1931)\n\t    </li>\n\t  </ul>\n      ']),
               'items_format': set([u'text/html']),
-              'history_agent': set(['FRAD033_EAC_00001']),
+              'history_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('Citation', _gen_extid(),
@@ -343,7 +335,7 @@
                                   u'xmlns:xlink="http://www.w3.org/1999/xlink">Pour accomplir '
                                   u'ses missions ...</p>']),
               'description_format': set([u'text/html']),
-              'structure_agent': set(['FRAD033_EAC_00001']),
+              'structure_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('AgentFunction', _gen_extid(),
@@ -352,12 +344,12 @@
                                   u'xmlns:xlink="http://www.w3.org/1999/xlink">Quatre grands '
                                   u'domaines de compétence...</p>']),
               'description_format': set([u'text/html']),
-              'function_agent': set(['FRAD033_EAC_00001']),
+              'function_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('AgentFunction', _gen_extid(),
              {'name': set([u'action sociale']),
-              'function_agent': set(['FRAD033_EAC_00001']),
+              'function_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'description': set([u'<p 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">1. Solidarité\n'
@@ -370,7 +362,7 @@
              ),
             ('AgentFunction', _gen_extid(),
              {'name': set([u'environnement']),
-              'function_agent': set(['FRAD033_EAC_00001']),
+              'function_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'equivalent_concept': set([
                   u'http://data.culture.fr/thesaurus/page/ark:/67717/T1-1074']),
               },
@@ -380,7 +372,7 @@
               'date_relation': set(['42']),
               'description': set([u'Organisation des réunions ...']),
               'description_format': set([u'text/plain']),
-              'occupation_agent': set(['FRAD033_EAC_00001']),
+              'occupation_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'has_citation': set(['43']),
               'equivalent_concept': set(['http://pifgadget.com']),
               },
@@ -400,7 +392,7 @@
                               u'xmlns:xlink="http://www.w3.org/1999/xlink">very famous</p>']),
               'content_format': set([u'text/html']),
               'has_citation': set(['45']),
-              'general_context_of': set(['FRAD033_EAC_00001']),
+              'general_context_of': set(['authorityrecord-FRAD033_EAC_00001']),
               }
              ),
             ('Citation', _gen_extid(),
@@ -419,7 +411,7 @@
               'description': set([u'Coucou']),
               'description_format': set([u'text/plain']),
               'hierarchical_parent': set(['CG33-DIRADSJ']),
-              'hierarchical_child': set(['FRAD033_EAC_00001']),
+              'hierarchical_child': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
             ('DateEntity', _gen_extid(),
@@ -439,7 +431,7 @@
              ),
             ('ChronologicalRelation', _gen_extid(),
              {'chronological_predecessor': set(['whatever']),
-              'chronological_successor': set(['FRAD033_EAC_00001']),
+              'chronological_successor': set(['authorityrecord-FRAD033_EAC_00001']),
               'date_relation': set(['49']),
               'entry': set([u'CG32']),
               },
@@ -450,7 +442,7 @@
               },
              ),
             ('ChronologicalRelation', _gen_extid(),
-             {'chronological_predecessor': set(['FRAD033_EAC_00001']),
+             {'chronological_predecessor': set(['authorityrecord-FRAD033_EAC_00001']),
               'chronological_successor': set(['/dev/null']),
               'date_relation': set(['51']),
               'xml_wrap': set(['<gloups xmlns="urn:isbn:1-931666-33-4"'
@@ -465,7 +457,7 @@
               },
              ),
             ('AssociationRelation', _gen_extid(),
-             {'association_from': set(['FRAD033_EAC_00001']),
+             {'association_from': set(['authorityrecord-FRAD033_EAC_00001']),
               'association_to': set(['agent-x']),
               },
              ),
@@ -480,7 +472,7 @@
               'resource_role': set([u'Fonds d\'archives']),
               'resource_relation_resource': set([
                   'http://gael.gironde.fr/ead.html?id=FRAD033_IR_N']),
-              'resource_relation_agent': set(['FRAD033_EAC_00001']),
+              'resource_relation_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               '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'
@@ -499,7 +491,7 @@
                                   '\'s\n\t  communication with its alumni.\n\t  </p>']),
               'r_type': set([u'performs']),
               'description_format': set([u'text/html']),
-              'function_relation_agent': set([u'FRAD033_EAC_00001']),
+              'function_relation_agent': set([u'authorityrecord-FRAD033_EAC_00001']),
               'function_relation_function': set([u'http://gael.gironde.fr/ead.html?'
                                                  'id=FRAD033_IR_N']),
               'relation_entry': set([u'Alumni communication\n\tmanagement, '
@@ -524,7 +516,7 @@
              ),
             ('EACFunctionRelation', _gen_extid(),
              {'function_relation_function': set([u'FRAD033_IR_N']),
-              'function_relation_agent': set([u'FRAD033_EAC_00001']),
+              'function_relation_agent': set([u'authorityrecord-FRAD033_EAC_00001']),
               'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
                                   'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
                                   'xmlns:xlink="http://www.w3.org/1999/xlink">'
@@ -544,7 +536,7 @@
               },
              ),
             ('EACFunctionRelation', _gen_extid(),
-             {'function_relation_agent': set([u'FRAD033_EAC_00001']),
+             {'function_relation_agent': set([u'authorityrecord-FRAD033_EAC_00001']),
               'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
                                   u'xmlns:xsi="http://www.w3.org/2001/X'
                                   u'MLSchema-instance" xmlns:xlink="http://ww'
@@ -563,7 +555,7 @@
               },
              ),
             ('EACFunctionRelation', _gen_extid(),
-             {'function_relation_agent': set([u'FRAD033_EAC_00001']),
+             {'function_relation_agent': set([u'authorityrecord-FRAD033_EAC_00001']),
               'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" '
                                   u'xmlns:xsi="http://www.w3.org/2001/X'
                                   u'MLSchema-instance" xmlns:xlink="http://ww'
@@ -612,6 +604,14 @@
              {'uri': set([u'http://pifgadget.com']),
               'cwuri': set([u'http://pifgadget.com'])},
              ),
+            ('AuthorityRecord', 'authorityrecord-FRAD033_EAC_00001',
+             {'isni': set([u'22330001300016']),
+              'start_date': set([datetime.date(1800, 1, 1)]),
+              'end_date': set([datetime.date(2099, 1, 1)]),
+              'agent_kind': set(['agentkind/authority']),
+              'record_id': set(['FRAD033_EAC_00001']),
+              },
+             ),
         ]
         expected = [ExtEntity(*vals) for vals in expected]
         fpath = self.datapath('FRAD033_EAC_00001_simplified.xml')


More information about the saem-devel mailing list