[SEDA 2.1] Make FileCodeListVersion optional
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 03 Mar 2017 11:21:32 +0100
changeset 2410 b2cf743e2787
parent 2402 ad791cf90bc2
child 2411 d8be06a22351
[SEDA 2.1] Make FileCodeListVersion optional
cubicweb_seda/entities/generated.py
cubicweb_seda/hooks.py
cubicweb_seda/i18n/en.po
cubicweb_seda/i18n/fr.po
cubicweb_seda/migration/0.8.0_Any.py
cubicweb_seda/schema/seda2.py
cubicweb_seda/views/uicfg.py
cubicweb_seda/xsd/seda-2.0-technical.xsd
cubicweb_seda/xsd2yams.py
test/test_hooks.py
test/test_profile_generation.py
--- a/cubicweb_seda/entities/generated.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/entities/generated.py	Fri Mar 03 11:21:32 2017 +0100
@@ -73,6 +73,11 @@
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
+class SEDAFileFormatCodeListVersion(SEDAAnyEntity):
+    __regid__ = 'SEDAFileFormatCodeListVersion'
+    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
+    value_attr = None
+
 class SEDACompressionAlgorithmCodeListVersion(SEDAAnyEntity):
     __regid__ = 'SEDACompressionAlgorithmCodeListVersion'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
--- a/cubicweb_seda/hooks.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/hooks.py	Fri Mar 03 11:21:32 2017 +0100
@@ -178,12 +178,10 @@
 
 class SetDefaultCodeListVersionsOp(hook.Operation):
     """Set sensible default values for a transfer's code list versions."""
-    simple_rtypes = [
-        ('seda_file_format_code_list_version', 'seda_format_id_to'),
-        # ('seda_message_digest_algorithm_code_list_version'),
-    ]
     # XXX factorize with data structure in dataimport
     complex_rtypes = [
+        ('seda_file_format_code_list_version', 'seda_format_id_to', None),
+        # ('seda_message_digest_algorithm_code_list_version'),
         ('seda_mime_type_code_list_version', 'seda_mime_type_to', None),
         ('seda_encoding_code_list_version', 'seda_encoding_to', None),
         ('seda_data_object_version_code_list_version', 'seda_data_object_version_to', None),
@@ -200,10 +198,6 @@
     def precommit_event(self):
         transfer = self.transfer_eid
         cnx = self.cnx
-        for rtype, ref_rtype in self.simple_rtypes:
-            cnx.execute('SET T {rtype} CS WHERE NOT T {rtype} CS, T eid %(t)s, '
-                        'CS scheme_relation_type RT, RT name %(rt)s'.format(rtype=rtype),
-                        {'t': transfer, 'rt': ref_rtype})
         for rtype, ref_rtype, ref_etype in self.complex_rtypes:
             etype = 'SEDA' + ''.join(word.capitalize() for word in rtype.split('_')[1:])
             rql = ('INSERT {etype} X: X {rtype}_from T, X {rtype}_to CS '
--- a/cubicweb_seda/i18n/en.po	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/i18n/en.po	Fri Mar 03 11:21:32 2017 +0100
@@ -290,6 +290,9 @@
 msgid "New SEDAEventType"
 msgstr ""
 
+msgid "New SEDAFileFormatCodeListVersion"
+msgstr ""
+
 msgid "New SEDAFilePlanPosition"
 msgstr ""
 
@@ -1136,6 +1139,12 @@
 msgid "SEDAEvent_plural"
 msgstr ""
 
+msgid "SEDAFileFormatCodeListVersion"
+msgstr ""
+
+msgid "SEDAFileFormatCodeListVersion_plural"
+msgstr ""
+
 msgid "SEDAFilePlanPosition"
 msgstr ""
 
@@ -2339,6 +2348,12 @@
 msgid "This SEDAEventType:"
 msgstr ""
 
+msgid "This SEDAFileFormatCodeListVersion"
+msgstr ""
+
+msgid "This SEDAFileFormatCodeListVersion:"
+msgstr ""
+
 msgid "This SEDAFilePlanPosition"
 msgstr ""
 
@@ -3248,6 +3263,9 @@
 msgid "add a SEDAEventType"
 msgstr ""
 
+msgid "add a SEDAFileFormatCodeListVersion"
+msgstr ""
+
 msgid "add a SEDAFilePlanPosition"
 msgstr ""
 
@@ -4120,6 +4138,10 @@
 msgid "container"
 msgstr ""
 
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "container"
+msgstr ""
+
 msgctxt "SEDAFilePlanPosition"
 msgid "container"
 msgstr ""
@@ -6016,18 +6038,32 @@
 msgid "seda_events_tab"
 msgstr ""
 
-msgid "seda_file_format_code_list_version"
+msgid "seda_file_format_code_list_version_from"
+msgstr ""
+
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "seda_file_format_code_list_version_from"
+msgstr ""
+
+msgid "seda_file_format_code_list_version_from_object"
 msgstr ""
 
 msgctxt "SEDAArchiveTransfer"
-msgid "seda_file_format_code_list_version"
-msgstr ""
-
-msgid "seda_file_format_code_list_version_object"
+msgid "seda_file_format_code_list_version_from_object"
+msgstr ""
+
+msgid "seda_file_format_code_list_version_to"
+msgstr ""
+
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "seda_file_format_code_list_version_to"
+msgstr ""
+
+msgid "seda_file_format_code_list_version_to_object"
 msgstr ""
 
 msgctxt "ConceptScheme"
-msgid "seda_file_format_code_list_version_object"
+msgid "seda_file_format_code_list_version_to_object"
 msgstr ""
 
 msgid "seda_file_plan_position"
@@ -8006,6 +8042,10 @@
 msgid "user_annotation"
 msgstr ""
 
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "user_annotation"
+msgstr ""
+
 msgctxt "SEDAFilePlanPosition"
 msgid "user_annotation"
 msgstr ""
@@ -8513,6 +8553,10 @@
 msgid "user_cardinality"
 msgstr ""
 
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "user_cardinality"
+msgstr ""
+
 msgctxt "SEDAFilePlanPosition"
 msgid "user_cardinality"
 msgstr ""
--- a/cubicweb_seda/i18n/fr.po	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/i18n/fr.po	Fri Mar 03 11:21:32 2017 +0100
@@ -297,6 +297,9 @@
 msgid "New SEDAEventType"
 msgstr ""
 
+msgid "New SEDAFileFormatCodeListVersion"
+msgstr ""
+
 msgid "New SEDAFilePlanPosition"
 msgstr ""
 
@@ -1146,6 +1149,12 @@
 msgid "SEDAEvent_plural"
 msgstr ""
 
+msgid "SEDAFileFormatCodeListVersion"
+msgstr ""
+
+msgid "SEDAFileFormatCodeListVersion_plural"
+msgstr ""
+
 msgid "SEDAFilePlanPosition"
 msgstr ""
 
@@ -2351,6 +2360,12 @@
 msgid "This SEDAEventType:"
 msgstr ""
 
+msgid "This SEDAFileFormatCodeListVersion"
+msgstr ""
+
+msgid "This SEDAFileFormatCodeListVersion:"
+msgstr ""
+
 msgid "This SEDAFilePlanPosition"
 msgstr ""
 
@@ -3262,6 +3277,9 @@
 msgid "add a SEDAEventType"
 msgstr ""
 
+msgid "add a SEDAFileFormatCodeListVersion"
+msgstr ""
+
 msgid "add a SEDAFilePlanPosition"
 msgstr ""
 
@@ -4134,6 +4152,10 @@
 msgid "container"
 msgstr ""
 
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "container"
+msgstr ""
+
 msgctxt "SEDAFilePlanPosition"
 msgid "container"
 msgstr ""
@@ -6037,18 +6059,32 @@
 msgid "seda_events_tab"
 msgstr "événements"
 
-msgid "seda_file_format_code_list_version"
+msgid "seda_file_format_code_list_version_from"
+msgstr ""
+
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "seda_file_format_code_list_version_from"
+msgstr ""
+
+msgid "seda_file_format_code_list_version_from_object"
 msgstr "formats de fichier"
 
 msgctxt "SEDAArchiveTransfer"
-msgid "seda_file_format_code_list_version"
-msgstr ""
-
-msgid "seda_file_format_code_list_version_object"
+msgid "seda_file_format_code_list_version_from_object"
+msgstr ""
+
+msgid "seda_file_format_code_list_version_to"
+msgstr ""
+
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "seda_file_format_code_list_version_to"
+msgstr ""
+
+msgid "seda_file_format_code_list_version_to_object"
 msgstr ""
 
 msgctxt "ConceptScheme"
-msgid "seda_file_format_code_list_version_object"
+msgid "seda_file_format_code_list_version_to_object"
 msgstr ""
 
 msgid "seda_file_plan_position"
@@ -8033,6 +8069,10 @@
 msgid "user_annotation"
 msgstr ""
 
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "user_annotation"
+msgstr ""
+
 msgctxt "SEDAFilePlanPosition"
 msgid "user_annotation"
 msgstr ""
@@ -8540,6 +8580,10 @@
 msgid "user_cardinality"
 msgstr ""
 
+msgctxt "SEDAFileFormatCodeListVersion"
+msgid "user_cardinality"
+msgstr ""
+
 msgctxt "SEDAFilePlanPosition"
 msgid "user_cardinality"
 msgstr ""
--- a/cubicweb_seda/migration/0.8.0_Any.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/migration/0.8.0_Any.py	Fri Mar 03 11:21:32 2017 +0100
@@ -2,10 +2,13 @@
 
 add_entity_type('SEDAMessageDigestAlgorithmCodeListVersion')
 drop_relation_type('seda_message_digest_algorithm_code_list_version')
+add_entity_type('SEDAFileFormatCodeListVersion')
+drop_relation_type('seda_file_format_code_list_version')
 
 add_entity_type('SEDALegalStatus')
 
 sync_schema_props_perms('seda_algorithm')
+sync_schema_props_perms('seda_format_id_to')
 
 lcsv_files = [file_def for file_def in LCSV_FILES
               if file_def[-1] == 'legal_status.csv']
--- a/cubicweb_seda/schema/seda2.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/schema/seda2.py	Fri Mar 03 11:21:32 2017 +0100
@@ -199,9 +199,24 @@
     inlined = True
     constraints = []
 
-class archive_transfer_file_format_code_list_version(RelationDefinition):
-    name = 'seda_file_format_code_list_version'
-    subject = 'SEDAArchiveTransfer'
+@seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='0..1',
+                      annotable=True)
+class SEDAFileFormatCodeListVersion(EntityType):
+    u""""""
+
+
+class archive_transfer_file_format_code_list_version_from(RelationDefinition):
+    name = 'seda_file_format_code_list_version_from'
+    subject = 'SEDAFileFormatCodeListVersion'
+    object = 'SEDAArchiveTransfer'
+    cardinality = '1?'
+    composite = fulltext_container = 'object'
+    inlined = True
+    constraints = []
+
+class file_format_code_list_version_file_format_code_list_version_to(RelationDefinition):
+    name = 'seda_file_format_code_list_version_to'
+    subject = 'SEDAFileFormatCodeListVersion'
     object = 'ConceptScheme'
     cardinality = '?*'
     composite = fulltext_container = None
@@ -840,7 +855,7 @@
     cardinality = '?*'
     composite = fulltext_container = None
     inlined = True
-    constraints = [RQLConstraint('O in_scheme CS,  AT seda_file_format_code_list_version CS, S container AT')]
+    constraints = [RQLConstraint('O in_scheme CS, CACL seda_file_format_code_list_version_from AT, CACL seda_file_format_code_list_version_to CS, S container AT')]
 
 @seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='0..1',
                       annotable=True)
--- a/cubicweb_seda/views/uicfg.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/views/uicfg.py	Fri Mar 03 11:21:32 2017 +0100
@@ -60,6 +60,7 @@
 ives['SEDAIsVersionOf'] = 'subobject'
 ives['SEDAArchivalAgreement'] = 'subobject'
 ives['SEDArestrictionEndDate'] = 'subobject'
+ives['SEDAFileFormatCodeListVersion'] = 'subobject'
 ives['SEDASeqAltArchiveUnitArchiveUnitRefIdManagement'] = 'subobject'
 ives['SEDATitle'] = 'subobject'
 ives['SEDAGpsDateStamp'] = 'subobject'
@@ -188,8 +189,10 @@
 abaa.tag_object_of(('*', 'seda_encoding_code_list_version_from', '*'), False)
 abaa.tag_object_of(('*', 'seda_encoding_code_list_version_to', '*'), False)
 abaa.tag_subject_of(('*', 'seda_encoding_code_list_version_to', '*'), False)
-abaa.tag_object_of(('*', 'seda_file_format_code_list_version', '*'), False)
-abaa.tag_subject_of(('*', 'seda_file_format_code_list_version', '*'), False)
+abaa.tag_subject_of(('*', 'seda_file_format_code_list_version_from', '*'), False)
+abaa.tag_object_of(('*', 'seda_file_format_code_list_version_from', '*'), False)
+abaa.tag_object_of(('*', 'seda_file_format_code_list_version_to', '*'), False)
+abaa.tag_subject_of(('*', 'seda_file_format_code_list_version_to', '*'), False)
 abaa.tag_subject_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), False)
 abaa.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), False)
 abaa.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_to', '*'), False)
@@ -536,6 +539,7 @@
 affk.tag_subject_of(('*', 'seda_message_digest_algorithm_code_list_version_to', '*'), {'label': 'value'})
 affk.tag_subject_of(('*', 'seda_mime_type_code_list_version_to', '*'), {'label': 'value'})
 affk.tag_subject_of(('*', 'seda_encoding_code_list_version_to', '*'), {'label': 'value'})
+affk.tag_subject_of(('*', 'seda_file_format_code_list_version_to', '*'), {'label': 'value'})
 affk.tag_subject_of(('*', 'seda_compression_algorithm_code_list_version_to', '*'), {'label': 'value'})
 affk.tag_subject_of(('*', 'seda_data_object_version_code_list_version_to', '*'), {'label': 'value'})
 affk.tag_subject_of(('*', 'seda_storage_rule_code_list_version_to', '*'), {'label': 'value'})
@@ -604,8 +608,10 @@
 afs.tag_object_of(('*', 'seda_encoding_code_list_version_from', '*'), 'main', 'hidden')
 afs.tag_object_of(('*', 'seda_encoding_code_list_version_to', '*'), 'main', 'hidden')
 afs.tag_subject_of(('*', 'seda_encoding_code_list_version_to', '*'), 'main', 'attributes')
-afs.tag_object_of(('*', 'seda_file_format_code_list_version', '*'), 'main', 'hidden')
-afs.tag_subject_of(('*', 'seda_file_format_code_list_version', '*'), 'main', 'hidden')
+afs.tag_subject_of(('*', 'seda_file_format_code_list_version_from', '*'), 'main', 'hidden')
+afs.tag_object_of(('*', 'seda_file_format_code_list_version_from', '*'), 'main', 'hidden')
+afs.tag_object_of(('*', 'seda_file_format_code_list_version_to', '*'), 'main', 'hidden')
+afs.tag_subject_of(('*', 'seda_file_format_code_list_version_to', '*'), 'main', 'attributes')
 afs.tag_subject_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), 'main', 'hidden')
 afs.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), 'main', 'hidden')
 afs.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_to', '*'), 'main', 'hidden')
@@ -960,8 +966,9 @@
 pvs.tag_subject_of(('*', 'seda_encoding_code_list_version_from', '*'), 'hidden')
 pvs.tag_object_of(('*', 'seda_encoding_code_list_version_from', '*'), 'hidden')
 pvs.tag_object_of(('*', 'seda_encoding_code_list_version_to', '*'), 'hidden')
-pvs.tag_object_of(('*', 'seda_file_format_code_list_version', '*'), 'hidden')
-pvs.tag_subject_of(('*', 'seda_file_format_code_list_version', '*'), 'hidden')
+pvs.tag_subject_of(('*', 'seda_file_format_code_list_version_from', '*'), 'hidden')
+pvs.tag_object_of(('*', 'seda_file_format_code_list_version_from', '*'), 'hidden')
+pvs.tag_object_of(('*', 'seda_file_format_code_list_version_to', '*'), 'hidden')
 pvs.tag_subject_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), 'hidden')
 pvs.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), 'hidden')
 pvs.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_to', '*'), 'hidden')
@@ -1133,7 +1140,8 @@
 rec.tag_subject_of(('*', 'seda_mime_type_code_list_version_to', '*'), {'novalue_label': '<no value specified>'})
 rec.tag_object_of(('*', 'seda_encoding_code_list_version_from', '*'), {'novalue_label': ' '})
 rec.tag_subject_of(('*', 'seda_encoding_code_list_version_to', '*'), {'novalue_label': '<no value specified>'})
-rec.tag_subject_of(('*', 'seda_file_format_code_list_version', '*'), {'novalue_label': '<no value specified>'})
+rec.tag_object_of(('*', 'seda_file_format_code_list_version_from', '*'), {'novalue_label': ' '})
+rec.tag_subject_of(('*', 'seda_file_format_code_list_version_to', '*'), {'novalue_label': '<no value specified>'})
 rec.tag_object_of(('*', 'seda_compression_algorithm_code_list_version_from', '*'), {'novalue_label': ' '})
 rec.tag_subject_of(('*', 'seda_compression_algorithm_code_list_version_to', '*'), {'novalue_label': '<no value specified>'})
 rec.tag_object_of(('*', 'seda_data_object_version_code_list_version_from', '*'), {'novalue_label': ' '})
--- a/cubicweb_seda/xsd/seda-2.0-technical.xsd	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/xsd/seda-2.0-technical.xsd	Fri Mar 03 11:21:32 2017 +0100
@@ -63,7 +63,7 @@
     </xsd:simpleType>
     <xsd:group name="FileFormatCodeListGroup">
         <xsd:sequence>
-            <xsd:element name="FileFormatCodeListVersion" type="CodeType">
+            <xsd:element name="FileFormatCodeListVersion" type="CodeType" minOccurs="0">
                 <xsd:annotation>
                     <xsd:documentation>Version de la liste de code d'identification du format.</xsd:documentation>
                 </xsd:annotation>
--- a/cubicweb_seda/xsd2yams.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/cubicweb_seda/xsd2yams.py	Fri Mar 03 11:21:32 2017 +0100
@@ -133,7 +133,8 @@
         ' OR EXISTS(S container AU, AU is SEDAArchiveUnit, CS scheme_relation_type RT, '
         '           RT name "seda_encoding_to")'),
     'seda_format_id_to': (
-        'O in_scheme CS,  AT seda_file_format_code_list_version CS, '
+        'O in_scheme CS, CACL seda_file_format_code_list_version_from AT, '
+        'CACL seda_file_format_code_list_version_to CS, '
         'S container AT'),
     'seda_data_object_version_to': (
         'O in_scheme CS, CACLV seda_data_object_version_code_list_version_from AT, '
@@ -230,7 +231,8 @@
         'SEDAArchiveUnit': 'CS scheme_relation_type RT, RT name "seda_encoding_to"',
     },
     'seda_format_id_to': {
-        'SEDAArchiveTransfer': ('AT seda_file_format_code_list_version CS, '
+        'SEDAArchiveTransfer': ('CACLV seda_file_format_code_list_version_from AT, '
+                                'CACLV seda_file_format_code_list_version_to CS, '
                                 'AT eid %(container)s'),
     },
     'seda_data_object_version_to': {
--- a/test/test_hooks.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/test/test_hooks.py	Fri Mar 03 11:21:32 2017 +0100
@@ -143,7 +143,7 @@
             transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
             cnx.commit()
 
-            self.assertTrue(transfer.seda_file_format_code_list_version)
+            self.assertTrue(transfer.reverse_seda_file_format_code_list_version_from)
             self.assertTrue(transfer.reverse_seda_mime_type_code_list_version_from)
             self.assertTrue(transfer.reverse_seda_encoding_code_list_version_from)
             self.assertTrue(transfer.reverse_seda_access_rule_code_list_version_from)
--- a/test/test_profile_generation.py	Fri Mar 03 10:37:07 2017 +0100
+++ b/test/test_profile_generation.py	Fri Mar 03 11:21:32 2017 +0100
@@ -630,6 +630,8 @@
             cnx.create_entity('SEDAMessageDigestAlgorithmCodeListVersion',
                               seda_message_digest_algorithm_code_list_version_from=transfer,
                               seda_message_digest_algorithm_code_list_version_to=scheme)
+            cnx.create_entity('SEDAFileFormatCodeListVersion',
+                              seda_file_format_code_list_version_from=transfer)
             create('SEDAMimeTypeCodeListVersion', seda_mime_type_code_list_version_from=transfer,
                    seda_mime_type_code_list_version_to=scheme)
             access_rule = create('SEDAAccessRule', seda_access_rule=transfer)