Set default cardinality of keyword reference to 1
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 20 Jan 2017 14:53:52 +0100
changeset 2316 f54a06d45f49
parent 2315 17b947d38a25
child 2317 e66d8c8b3a4b
Set default cardinality of keyword reference to 1 Now that we have a different ui for simple vs reference keyword, cardinality on keyword reference is no more meaningful and hidden in the UI, since we would like to always have cardinality=1 for reference keyword when generating profiles. The easiest way to do so is to set proper default value, else by removing the attribute we would have to do extra customization to the SEDA 2 profile generator to consider that it shouldn't use the cardinality in the SEDA 2 XSD (0..1). Closes #16070921
schema/seda2.py
test/data/seda_02_export.rng
test/data/seda_02_export.xsd
test/data/seda_1_export.rng
test/data/seda_1_export.xsd
test/test_profile_generation.py
xsd2yams.py
--- a/schema/seda2.py	Fri Jan 20 14:45:50 2017 +0100
+++ b/schema/seda2.py	Fri Jan 20 14:53:52 2017 +0100
@@ -2254,7 +2254,7 @@
     inlined = True
     constraints = []
 
-@seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='0..1',
+@seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='1',
                       annotable=True)
 class SEDAKeywordReference(EntityType):
     u""""""
--- a/test/data/seda_02_export.rng	Fri Jan 20 14:45:50 2017 +0100
+++ b/test/data/seda_02_export.rng	Fri Jan 20 14:53:52 2017 +0100
@@ -263,37 +263,35 @@
                   </rng:optional>
                   <rng:value type="string">file</rng:value>
                 </rng:element>
-                <rng:optional>
-                  <rng:element name="KeywordReference">
-                    <rng:optional>
-                      <rng:attribute name="schemeID">
-                        <rng:data type="token"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:attribute name="schemeName">
-                      <rng:value type="string">seda_description_level/None vocabulary</rng:value>
+                <rng:element name="KeywordReference">
+                  <rng:optional>
+                    <rng:attribute name="schemeID">
+                      <rng:data type="token"/>
+                    </rng:attribute>
+                  </rng:optional>
+                  <rng:attribute name="schemeName">
+                    <rng:value type="string">seda_description_level/None vocabulary</rng:value>
+                  </rng:attribute>
+                  <rng:optional>
+                    <rng:attribute name="schemeAgencyName">
+                      <rng:data type="string"/>
                     </rng:attribute>
-                    <rng:optional>
-                      <rng:attribute name="schemeAgencyName">
-                        <rng:data type="string"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:optional>
-                      <rng:attribute name="schemeVersionID">
-                        <rng:data type="token"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:optional>
-                      <rng:attribute name="schemeDataURI">
-                        <rng:data type="anyURI"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:attribute name="schemeURI">
-                      <rng:value type="anyURI">%(scheme-uri)s</rng:value>
+                  </rng:optional>
+                  <rng:optional>
+                    <rng:attribute name="schemeVersionID">
+                      <rng:data type="token"/>
                     </rng:attribute>
-                    <rng:value type="string">%(concept-uri)s</rng:value>
-                  </rng:element>
-                </rng:optional>
+                  </rng:optional>
+                  <rng:optional>
+                    <rng:attribute name="schemeDataURI">
+                      <rng:data type="anyURI"/>
+                    </rng:attribute>
+                  </rng:optional>
+                  <rng:attribute name="schemeURI">
+                    <rng:value type="anyURI">%(scheme-uri)s</rng:value>
+                  </rng:attribute>
+                  <rng:value type="string">%(concept-uri)s</rng:value>
+                </rng:element>
                 <rng:optional>
                   <rng:element name="KeywordType">
                     <rng:attribute name="listVersionID">
--- a/test/data/seda_02_export.xsd	Fri Jan 20 14:45:50 2017 +0100
+++ b/test/data/seda_02_export.xsd	Fri Jan 20 14:53:52 2017 +0100
@@ -170,7 +170,7 @@
                               </xsd:simpleContent>
                             </xsd:complexType>
                           </xsd:element>
-                          <xsd:element fixed="%(concept-uri)s" minOccurs="0" name="KeywordReference">
+                          <xsd:element fixed="%(concept-uri)s" name="KeywordReference">
                             <xsd:complexType>
                               <xsd:simpleContent>
                                 <xsd:extension base="qdt:ArchivesIDType">
--- a/test/data/seda_1_export.rng	Fri Jan 20 14:45:50 2017 +0100
+++ b/test/data/seda_1_export.rng	Fri Jan 20 14:53:52 2017 +0100
@@ -235,37 +235,35 @@
                   </rng:optional>
                   <rng:value type="string">file</rng:value>
                 </rng:element>
-                <rng:optional>
-                  <rng:element name="KeywordReference">
-                    <rng:optional>
-                      <rng:attribute name="schemeID">
-                        <rng:data type="token"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:attribute name="schemeName">
-                      <rng:value type="string">seda_description_level/None vocabulary</rng:value>
+                <rng:element name="KeywordReference">
+                  <rng:optional>
+                    <rng:attribute name="schemeID">
+                      <rng:data type="token"/>
+                    </rng:attribute>
+                  </rng:optional>
+                  <rng:attribute name="schemeName">
+                    <rng:value type="string">seda_description_level/None vocabulary</rng:value>
+                  </rng:attribute>
+                  <rng:optional>
+                    <rng:attribute name="schemeAgencyName">
+                      <rng:data type="string"/>
                     </rng:attribute>
-                    <rng:optional>
-                      <rng:attribute name="schemeAgencyName">
-                        <rng:data type="string"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:optional>
-                      <rng:attribute name="schemeVersionID">
-                        <rng:data type="token"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:optional>
-                      <rng:attribute name="schemeDataURI">
-                        <rng:data type="anyURI"/>
-                      </rng:attribute>
-                    </rng:optional>
-                    <rng:attribute name="schemeURI">
-                      <rng:value type="anyURI">%(scheme-uri)s</rng:value>
+                  </rng:optional>
+                  <rng:optional>
+                    <rng:attribute name="schemeVersionID">
+                      <rng:data type="token"/>
                     </rng:attribute>
-                    <rng:value type="string">%(concept-uri)s</rng:value>
-                  </rng:element>
-                </rng:optional>
+                  </rng:optional>
+                  <rng:optional>
+                    <rng:attribute name="schemeDataURI">
+                      <rng:data type="anyURI"/>
+                    </rng:attribute>
+                  </rng:optional>
+                  <rng:attribute name="schemeURI">
+                    <rng:value type="anyURI">%(scheme-uri)s</rng:value>
+                  </rng:attribute>
+                  <rng:value type="string">%(concept-uri)s</rng:value>
+                </rng:element>
                 <rng:optional>
                   <rng:element name="KeywordType">
                     <rng:attribute name="listVersionID">
--- a/test/data/seda_1_export.xsd	Fri Jan 20 14:45:50 2017 +0100
+++ b/test/data/seda_1_export.xsd	Fri Jan 20 14:53:52 2017 +0100
@@ -157,7 +157,7 @@
                               </xsd:simpleContent>
                             </xsd:complexType>
                           </xsd:element>
-                          <xsd:element fixed="%(concept-uri)s" minOccurs="0" name="KeywordReference">
+                          <xsd:element fixed="%(concept-uri)s" name="KeywordReference">
                             <xsd:complexType>
                               <xsd:simpleContent>
                                 <xsd:extension base="qdt:ArchivesIDType">
--- a/test/test_profile_generation.py	Fri Jan 20 14:45:50 2017 +0100
+++ b/test/test_profile_generation.py	Fri Jan 20 14:53:52 2017 +0100
@@ -492,8 +492,7 @@
                 [{'name': 'listVersionID', 'fixed': 'seda_keyword_type_to/None vocabulary'}])
             kwr = self.get_element(profile, 'KeywordReference')
             self.assertElementDefinition(kwr, {'name': 'KeywordReference',
-                                               'type': 'xsd:token',
-                                               'minOccurs': '0'})
+                                               'type': 'xsd:token'})
             self.assertXSDAttributes(
                 kwr,
                 [{'name': 'schemeAgencyID', 'type': 'xsd:token', 'use': 'optional'},
@@ -508,8 +507,7 @@
             profile = self.profile_etree(transfer)
             kwr = self.get_element(profile, 'KeywordReference')
             self.assertElementDefinition(kwr, {'name': 'KeywordReference',
-                                               'type': 'xsd:token',
-                                               'minOccurs': '0'})
+                                               'type': 'xsd:token'})
             self.assertXSDAttributes(
                 kwr,
                 [{'name': 'schemeURI', 'fixed': scheme.absolute_url()}])
@@ -519,8 +517,7 @@
             kwr = self.get_element(profile, 'KeywordReference')
             self.assertElementDefinition(kwr, {'name': 'KeywordReference',
                                                'type': 'xsd:token',
-                                               'fixed': 'theme',
-                                               'minOccurs': '0'})
+                                               'fixed': 'theme'})
             self.assertXSDAttributes(
                 kwr,
                 [{'name': 'schemeURI', 'fixed': scheme.absolute_url()}])
--- a/xsd2yams.py	Fri Jan 20 14:45:50 2017 +0100
+++ b/xsd2yams.py	Fri Jan 20 14:53:52 2017 +0100
@@ -197,6 +197,7 @@
 }
 DEFAULT_USER_CARDINALITY = {
     'SEDAStartDate': '1',
+    'SEDAKeywordReference': '1',
 }
 for rule_type in RULE_TYPES:
     etype = 'SEDASeq{0}RuleRule'.format(rule_type.capitalize())