[profile gen] In SEDA 1.0, Appraisal rule should appear after access rule
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Nov 2017 14:38:33 +0100
changeset 2871 20d1509fb15a
parent 2870 c463fd270e81
child 2872 1e715baea780
[profile gen] In SEDA 1.0, Appraisal rule should appear after access rule Related to #17113836
cubicweb_seda/entities/profile_generation.py
test/data/seda_1_export.rng
test/data/seda_1_export.xsd
--- a/cubicweb_seda/entities/profile_generation.py	Tue Nov 07 12:13:32 2017 +0100
+++ b/cubicweb_seda/entities/profile_generation.py	Tue Nov 07 14:38:33 2017 +0100
@@ -806,12 +806,7 @@
         self.xsd_transferring_agency_archive_identifier(archive_node, content_entity,
                                                         'TransferringAgencyArchiveIdentifier')
         self.xsd_content_description(archive_node, content_entity)
-        appraisal_rule_entity = archive_unit.inherited_rule('appraisal')
-        if appraisal_rule_entity:
-            self.xsd_appraisal_rule(archive_node, appraisal_rule_entity)
-        # not optional in seda 1
-        access_rule_entity = archive_unit.inherited_rule('access')
-        self.xsd_access_rule(archive_node, access_rule_entity)
+        self.xsd_rules(archive_node, archive_unit)
         self.xsd_children(archive_node, archive_unit)
 
     archive_object_tag_name = 'ArchiveObject'
@@ -838,12 +833,7 @@
                 or content_entity.description
                 or content_entity.keywords):
             self.xsd_content_description(ao_node, content_entity)
-        appraisal_rule_entity = archive_unit.inherited_rule('appraisal')
-        if appraisal_rule_entity:
-            self.xsd_appraisal_rule(ao_node, appraisal_rule_entity)
-        access_rule_entity = archive_unit.inherited_rule('access')
-        if access_rule_entity:
-            self.xsd_access_rule(ao_node, access_rule_entity)
+        self.xsd_rules(ao_node, archive_unit)
         self.xsd_children(ao_node, archive_unit)
 
         return ao_node
@@ -995,6 +985,14 @@
                 documentation=agency_entity.user_annotation,
                 xsd_attributes=self.xsd_attributes_scheme())
 
+    def xsd_rules(self, parent, archive_unit):
+        access_rule_entity = archive_unit.inherited_rule('access')
+        if access_rule_entity:
+            self.xsd_access_rule(parent, access_rule_entity)
+        appraisal_rule_entity = archive_unit.inherited_rule('appraisal')
+        if appraisal_rule_entity:
+            self.xsd_appraisal_rule(parent, appraisal_rule_entity)
+
     def xsd_appraisal_rule(self, parent, appraisal_rule):
         # XXX cardinality 1 on rule, not multiple + element name : 'Appraisal' ou 'AppraisalRule'
         # (cf http://www.archivesdefrance.culture.gouv.fr/seda/api/index.html)
@@ -1240,13 +1238,7 @@
                                                         'TransferringAgencyArchiveIdentifier')
         self.xsd_content_description(archive_node, content_entity)
 
-        appraisal_rule_entity = archive_unit.inherited_rule('appraisal')
-        if appraisal_rule_entity:
-            self.xsd_appraisal_rule(archive_node, appraisal_rule_entity)
-        # in SEDA 0.2, access restriction is not mandatory
-        access_rule_entity = archive_unit.inherited_rule('access')
-        if access_rule_entity:
-            self.xsd_access_rule(archive_node, access_rule_entity)
+        self.xsd_rules(archive_node, archive_unit)
         self.xsd_children(archive_node, archive_unit)
         return archive_node
 
@@ -1286,6 +1278,14 @@
         self.xsd_originating_agency(cd_node, content)
         self.xsd_keywords(cd_node, content)
 
+    def xsd_rules(self, parent, archive_unit):
+        appraisal_rule_entity = archive_unit.inherited_rule('appraisal')
+        if appraisal_rule_entity:
+            self.xsd_appraisal_rule(parent, appraisal_rule_entity)
+        access_rule_entity = archive_unit.inherited_rule('access')
+        if access_rule_entity:
+            self.xsd_access_rule(parent, access_rule_entity)
+
     def xsd_custodial_history(self, parent, content):
         if content.custodial_history_items:
             item = content.custodial_history_items[0]
--- a/test/data/seda_1_export.rng	Tue Nov 07 12:13:32 2017 +0100
+++ b/test/data/seda_1_export.rng	Tue Nov 07 14:38:33 2017 +0100
@@ -331,6 +331,22 @@
               </rng:element>
             </rng:optional>
           </rng:element>
+          <rng:element name="AccessRestrictionRule">
+            <rng:optional>
+              <rng:attribute name="Id">
+                <rng:data type="ID"/>
+              </rng:attribute>
+            </rng:optional>
+            <rng:element name="Code">
+              <rng:attribute name="listVersionID">
+                <rng:value type="token">edition 2009</rng:value>
+              </rng:attribute>
+              <rng:data type="string"/>
+            </rng:element>
+            <rng:element name="StartDate">
+              <rng:data type="string"/>
+            </rng:element>
+          </rng:element>
           <rng:optional>
             <rng:element name="Appraisal">
               <xsd:annotation>
@@ -358,22 +374,6 @@
               </rng:element>
             </rng:element>
           </rng:optional>
-          <rng:element name="AccessRestrictionRule">
-            <rng:optional>
-              <rng:attribute name="Id">
-                <rng:data type="ID"/>
-              </rng:attribute>
-            </rng:optional>
-            <rng:element name="Code">
-              <rng:attribute name="listVersionID">
-                <rng:value type="token">edition 2009</rng:value>
-              </rng:attribute>
-              <rng:data type="string"/>
-            </rng:element>
-            <rng:element name="StartDate">
-              <rng:data type="string"/>
-            </rng:element>
-          </rng:element>
           <rng:element name="ArchiveObject" xml:id="id%(subunit2-eid)s">
             <xsd:annotation>
               <xsd:documentation>archive unit title</xsd:documentation>
@@ -410,6 +410,22 @@
                 <rng:data type="string"/>
               </rng:element>
             </rng:element>
+            <rng:element name="AccessRestrictionRule">
+              <rng:optional>
+                <rng:attribute name="Id">
+                  <rng:data type="ID"/>
+                </rng:attribute>
+              </rng:optional>
+              <rng:element name="Code">
+                <rng:attribute name="listVersionID">
+                  <rng:value type="token">edition 2009</rng:value>
+                </rng:attribute>
+                <rng:data type="string"/>
+              </rng:element>
+              <rng:element name="StartDate">
+                <rng:data type="string"/>
+              </rng:element>
+            </rng:element>
             <rng:optional>
               <rng:element name="Appraisal">
                 <xsd:annotation>
@@ -437,22 +453,6 @@
                 </rng:element>
               </rng:element>
             </rng:optional>
-            <rng:element name="AccessRestrictionRule">
-              <rng:optional>
-                <rng:attribute name="Id">
-                  <rng:data type="ID"/>
-                </rng:attribute>
-              </rng:optional>
-              <rng:element name="Code">
-                <rng:attribute name="listVersionID">
-                  <rng:value type="token">edition 2009</rng:value>
-                </rng:attribute>
-                <rng:data type="string"/>
-              </rng:element>
-              <rng:element name="StartDate">
-                <rng:data type="string"/>
-              </rng:element>
-            </rng:element>
           </rng:element>
           <rng:oneOrMore>
             <rng:element name="ArchiveObject" xml:id="id%(subunit1-eid)s">
@@ -491,6 +491,25 @@
                   <rng:data type="string"/>
                 </rng:element>
               </rng:element>
+              <rng:element name="AccessRestrictionRule">
+                <xsd:annotation>
+                  <xsd:documentation>restrict</xsd:documentation>
+                </xsd:annotation>
+                <rng:optional>
+                  <rng:attribute name="Id">
+                    <rng:data type="ID"/>
+                  </rng:attribute>
+                </rng:optional>
+                <rng:element name="Code">
+                  <rng:attribute name="listVersionID">
+                    <rng:value type="token">edition 2009</rng:value>
+                  </rng:attribute>
+                  <rng:value type="string">AR038</rng:value>
+                </rng:element>
+                <rng:element name="StartDate">
+                  <rng:data type="string"/>
+                </rng:element>
+              </rng:element>
               <rng:optional>
                 <rng:element name="Appraisal">
                   <rng:optional>
@@ -512,25 +531,6 @@
                   </rng:element>
                 </rng:element>
               </rng:optional>
-              <rng:element name="AccessRestrictionRule">
-                <xsd:annotation>
-                  <xsd:documentation>restrict</xsd:documentation>
-                </xsd:annotation>
-                <rng:optional>
-                  <rng:attribute name="Id">
-                    <rng:data type="ID"/>
-                  </rng:attribute>
-                </rng:optional>
-                <rng:element name="Code">
-                  <rng:attribute name="listVersionID">
-                    <rng:value type="token">edition 2009</rng:value>
-                  </rng:attribute>
-                  <rng:value type="string">AR038</rng:value>
-                </rng:element>
-                <rng:element name="StartDate">
-                  <rng:data type="string"/>
-                </rng:element>
-              </rng:element>
             </rng:element>
           </rng:oneOrMore>
           <rng:zeroOrMore>
--- a/test/data/seda_1_export.xsd	Tue Nov 07 12:13:32 2017 +0100
+++ b/test/data/seda_1_export.xsd	Tue Nov 07 14:38:33 2017 +0100
@@ -223,7 +223,24 @@
                   <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                 </xsd:complexType>
               </xsd:element>
-              <xsd:element minOccurs="0" name="Appraisal">
+              <xsd:element name="AccessRestrictionRule">
+                <xsd:complexType>
+                  <xsd:sequence>
+                    <xsd:element name="Code">
+                      <xsd:complexType>
+                        <xsd:simpleContent>
+                          <xsd:extension base="qdt:CodeAccessRestrictionType">
+                            <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
+                          </xsd:extension>
+                        </xsd:simpleContent>
+                      </xsd:complexType>
+                    </xsd:element>
+                    <xsd:element name="StartDate" type="udt:DateType"/>
+                  </xsd:sequence>
+                  <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
+                </xsd:complexType>
+              </xsd:element>
+              <xsd:element minOccurs="0" name="AppraisalRule">
                 <xsd:annotation>
                   <xsd:documentation>detruire le document</xsd:documentation>
                 </xsd:annotation>
@@ -248,23 +265,6 @@
                   <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                 </xsd:complexType>
               </xsd:element>
-              <xsd:element name="AccessRestrictionRule">
-                <xsd:complexType>
-                  <xsd:sequence>
-                    <xsd:element name="Code">
-                      <xsd:complexType>
-                        <xsd:simpleContent>
-                          <xsd:extension base="qdt:CodeAccessRestrictionType">
-                            <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
-                          </xsd:extension>
-                        </xsd:simpleContent>
-                      </xsd:complexType>
-                    </xsd:element>
-                    <xsd:element name="StartDate" type="udt:DateType"/>
-                  </xsd:sequence>
-                  <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
-                </xsd:complexType>
-              </xsd:element>
               <xsd:element name="ArchiveObject" xml:id="id%(subunit2-eid)s">
                 <xsd:annotation>
                   <xsd:documentation>archive unit title</xsd:documentation>
@@ -305,7 +305,24 @@
                         <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                       </xsd:complexType>
                     </xsd:element>
-                    <xsd:element minOccurs="0" name="Appraisal">
+                    <xsd:element name="AccessRestrictionRule">
+                      <xsd:complexType>
+                        <xsd:sequence>
+                          <xsd:element name="Code">
+                            <xsd:complexType>
+                              <xsd:simpleContent>
+                                <xsd:extension base="qdt:CodeAccessRestrictionType">
+                                  <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
+                                </xsd:extension>
+                              </xsd:simpleContent>
+                            </xsd:complexType>
+                          </xsd:element>
+                          <xsd:element name="StartDate" type="udt:DateType"/>
+                        </xsd:sequence>
+                        <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
+                      </xsd:complexType>
+                    </xsd:element>
+                    <xsd:element minOccurs="0" name="AppraisalRule">
                       <xsd:annotation>
                         <xsd:documentation>detruire le document</xsd:documentation>
                       </xsd:annotation>
@@ -330,23 +347,6 @@
                         <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                       </xsd:complexType>
                     </xsd:element>
-                    <xsd:element name="AccessRestrictionRule">
-                      <xsd:complexType>
-                        <xsd:sequence>
-                          <xsd:element name="Code">
-                            <xsd:complexType>
-                              <xsd:simpleContent>
-                                <xsd:extension base="qdt:CodeAccessRestrictionType">
-                                  <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
-                                </xsd:extension>
-                              </xsd:simpleContent>
-                            </xsd:complexType>
-                          </xsd:element>
-                          <xsd:element name="StartDate" type="udt:DateType"/>
-                        </xsd:sequence>
-                        <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
-                      </xsd:complexType>
-                    </xsd:element>
                   </xsd:sequence>
                   <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                 </xsd:complexType>
@@ -391,24 +391,6 @@
                         <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                       </xsd:complexType>
                     </xsd:element>
-                    <xsd:element minOccurs="0" name="Appraisal">
-                      <xsd:complexType>
-                        <xsd:sequence>
-                          <xsd:element name="Code">
-                            <xsd:complexType>
-                              <xsd:simpleContent>
-                                <xsd:extension base="qdt:CodeAppraisalType">
-                                  <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
-                                </xsd:extension>
-                              </xsd:simpleContent>
-                            </xsd:complexType>
-                          </xsd:element>
-                          <xsd:element name="Duration" type="qdt:ArchivesDurationType"/>
-                          <xsd:element name="StartDate" type="udt:DateType"/>
-                        </xsd:sequence>
-                        <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
-                      </xsd:complexType>
-                    </xsd:element>
                     <xsd:element name="AccessRestrictionRule">
                       <xsd:annotation>
                         <xsd:documentation>restrict</xsd:documentation>
@@ -429,6 +411,24 @@
                         <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                       </xsd:complexType>
                     </xsd:element>
+                    <xsd:element minOccurs="0" name="AppraisalRule">
+                      <xsd:complexType>
+                        <xsd:sequence>
+                          <xsd:element name="Code">
+                            <xsd:complexType>
+                              <xsd:simpleContent>
+                                <xsd:extension base="qdt:CodeAppraisalType">
+                                  <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
+                                </xsd:extension>
+                              </xsd:simpleContent>
+                            </xsd:complexType>
+                          </xsd:element>
+                          <xsd:element name="Duration" type="qdt:ArchivesDurationType"/>
+                          <xsd:element name="StartDate" type="udt:DateType"/>
+                        </xsd:sequence>
+                        <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
+                      </xsd:complexType>
+                    </xsd:element>
                   </xsd:sequence>
                   <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
                 </xsd:complexType>