Basic export of simplified profile to SEDA 0.2 RNG
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 11 Oct 2016 17:02:06 +0200
changeset 1634 c2ccf07bb418
parent 1628 9393d8e2702f
child 1685 51669dddb342
Basic export of simplified profile to SEDA 0.2 RNG Related to #15524427
entities/profile_generation.py
test/data/seda_02_export.rng
test/test_profile_generation.py
--- a/entities/profile_generation.py	Fri Oct 07 18:04:30 2016 +0200
+++ b/entities/profile_generation.py	Tue Oct 11 17:02:06 2016 +0200
@@ -1197,20 +1197,7 @@
     kw_content_tag_attributes = [XAttr('languageID', 'xsd:language')]
 
 
-class SEDA1RNGExport(RNGMixin, SEDA1XSDExport):
-    """Adapter to build an RNG representation of a simplified SEDA profile, using SEDA 1.0
-    specification.
-    """
-    __regid__ = 'SEDA-1.0.rng'
-    __select__ = SEDA2XSDExport.__select__ & simplified_profile()
-    extension = 'rng'
-
-    namespaces = SEDA1XSDExport.namespaces.copy()
-    namespaces['rng'] = 'http://relaxng.org/ns/structure/1.0'
-    root_attributes = {
-        'ns': 'fr:gouv:culture:archivesdefrance:seda:v1.0',
-        'datatypeLibrary': 'http://www.w3.org/2001/XMLSchema-datatypes',
-    }
+class OldSEDARNGExportMixin(RNGMixin):
 
     def element_schema(self, parent, name, xsd_type=None, fixed_value=None, cardinality='1',
                        documentation=None, xsd_attributes=()):
@@ -1244,6 +1231,36 @@
         return root
 
 
+class SEDA1RNGExport(OldSEDARNGExportMixin, SEDA1XSDExport):
+    """Adapter to build an RNG representation of a simplified SEDA profile, using SEDA 1.0
+    specification.
+    """
+    __regid__ = 'SEDA-1.0.rng'
+    extension = 'rng'
+
+    namespaces = SEDA1XSDExport.namespaces.copy()
+    namespaces['rng'] = 'http://relaxng.org/ns/structure/1.0'
+    root_attributes = {
+        'ns': 'fr:gouv:culture:archivesdefrance:seda:v1.0',
+        'datatypeLibrary': 'http://www.w3.org/2001/XMLSchema-datatypes',
+    }
+
+
+class SEDA02RNGExport(OldSEDARNGExportMixin, SEDA02XSDExport):
+    """Adapter to build an RNG representation of a simplified SEDA profile, using SEDA 0.2
+    specification.
+    """
+    __regid__ = 'SEDA-0.2.rng'
+    extension = 'rng'
+
+    namespaces = SEDA1XSDExport.namespaces.copy()
+    namespaces['rng'] = 'http://relaxng.org/ns/structure/1.0'
+    root_attributes = {
+        'ns': 'fr:gouv:ae:archive:draft:standard_echange_v0.2',
+        'datatypeLibrary': 'http://www.w3.org/2001/XMLSchema-datatypes',
+    }
+
+
 def xsd_element_cardinality(occ, card_entity):
     """Return XSD element cardinality for the given pyxst Occurence. Cardinality may be overriden by
     the data model's user_cardinality value.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/data/seda_02_export.rng	Tue Oct 11 17:02:06 2016 +0200
@@ -0,0 +1,185 @@
+<?xml version='1.0' encoding='utf-8' standalone='no'?>
+<rng:grammar xmlns:clmDAFFileTypeCode="urn:un:unece:uncefact:codelist:draft:DAF:fileTypeCode:2009-08-18" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:clm60133="urn:un:unece:uncefact:codelist:standard:6:0133:40106" xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:standard:IANA:MIMEMediaType:2008-11-12" xmlns:qdt="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" xmlns:clmIANACharacterSetCode="urn:un:unece:uncefact:codelist:standard:IANA:CharacterSetCode:2007-05-14" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" xmlns:rng="http://relaxng.org/ns/structure/1.0" xmlns="fr:gouv:culture:archivesdefrance:seda:v1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" ns="fr:gouv:ae:archive:draft:standard_echange_v0.2">
+  <rng:start>
+    <rng:element name="ArchiveTransfer">
+      <xsd:annotation>
+        <xsd:documentation>my profile title &amp;&amp;</xsd:documentation>
+      </xsd:annotation>
+      <rng:element name="Comment">
+        <rng:value datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="TextType">my profile description &amp;&amp;</rng:value>
+      </rng:element>
+      <rng:element name="Date">
+        <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateTimeType"/>
+      </rng:element>
+      <rng:element name="TransferIdentifier">
+        <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="ArchivesIDType"/>
+      </rng:element>
+      <rng:oneOrMore>
+        <rng:element name="Contains">
+          <rng:element name="DescriptionLanguage">
+            <rng:attribute name="listVersionID">
+              <rng:value type="token">edition 2009</rng:value>
+            </rng:attribute>
+            <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeLanguageType">fr</rng:value>
+          </rng:element>
+          <rng:element name="Name">
+            <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="TextType"/>
+          </rng:element>
+          <rng:element name="DescriptionLevel">
+            <rng:attribute name="listVersionID">
+              <rng:value type="token">edition 2009</rng:value>
+            </rng:attribute>
+            <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeDescriptionLevelType">file</rng:value>
+          </rng:element>
+          <rng:optional>
+            <rng:element name="Appraisal">
+              <xsd:annotation>
+                <xsd:documentation>detruire le document</xsd:documentation>
+              </xsd:annotation>
+              <rng:element name="Code">
+                <rng:attribute name="listVersionID">
+                  <rng:value type="token">edition 2009</rng:value>
+                </rng:attribute>
+                <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeAppraisalType">detruire</rng:value>
+              </rng:element>
+              <rng:element name="Duration">
+                <xsd:annotation>
+                  <xsd:documentation>C'est dans 10ans je m'en irai</xsd:documentation>
+                </xsd:annotation>
+                <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="ArchivesDurationType">P10Y</rng:value>
+              </rng:element>
+              <rng:element name="StartDate">
+                <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateType"/>
+              </rng:element>
+            </rng:element>
+          </rng:optional>
+          <rng:element name="AccessRestriction">
+            <rng:element name="Code">
+              <rng:attribute name="listVersionID">
+                <rng:value type="token">edition 2009</rng:value>
+              </rng:attribute>
+              <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeAccessRestrictionType"/>
+            </rng:element>
+            <rng:element name="StartDate">
+              <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateType"/>
+            </rng:element>
+          </rng:element>
+          <rng:element name="ContentDescription">
+            <rng:optional>
+              <rng:element name="OldestDate">
+                <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateType"/>
+              </rng:element>
+            </rng:optional>
+            <rng:optional>
+              <rng:element name="LatestDate">
+                <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateType"/>
+              </rng:element>
+            </rng:optional>
+            <rng:optional>
+              <rng:element name="Description">
+                <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="TextType"/>
+              </rng:element>
+            </rng:optional>
+            <rng:element name="DescriptionLanguage">
+              <rng:attribute name="listVersionID">
+                <rng:value type="token">edition 2009</rng:value>
+              </rng:attribute>
+              <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeLanguageType">fr</rng:value>
+            </rng:element>
+            <rng:zeroOrMore>
+              <rng:element name="ContentDescriptive">
+                <rng:element name="KeywordContent">
+                  <rng:value datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="TextType">file</rng:value>
+                </rng:element>
+                <rng:element name="KeywordReference">
+                  <rng:attribute name="schemeName">
+                    <rng:value type="string">seda_description_level/None vocabulary</rng:value>
+                  </rng:attribute>
+                  <rng:attribute name="schemeURI">
+                    <rng:value type="anyURI">%(scheme-uri)s</rng:value>
+                  </rng:attribute>
+                  <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="ArchivesIDType">%(concept-uri)s</rng:value>
+                </rng:element>
+              </rng:element>
+            </rng:zeroOrMore>
+          </rng:element>
+          <rng:oneOrMore>
+            <rng:element name="Contains">
+              <rng:element name="Name">
+                <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="TextType"/>
+              </rng:element>
+              <rng:optional>
+                <rng:element name="Appraisal">
+                  <rng:element name="Code">
+                    <rng:attribute name="listVersionID">
+                      <rng:value type="token">edition 2009</rng:value>
+                    </rng:attribute>
+                    <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeAppraisalType"/>
+                  </rng:element>
+                  <rng:element name="Duration">
+                    <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="ArchivesDurationType"/>
+                  </rng:element>
+                  <rng:element name="StartDate">
+                    <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateType"/>
+                  </rng:element>
+                </rng:element>
+              </rng:optional>
+              <rng:element name="AccessRestriction">
+                <xsd:annotation>
+                  <xsd:documentation>restrict</xsd:documentation>
+                </xsd:annotation>
+                <rng:element name="Code">
+                  <rng:attribute name="listVersionID">
+                    <rng:value type="token">edition 2009</rng:value>
+                  </rng:attribute>
+                  <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeAccessRestrictionType">AR038</rng:value>
+                </rng:element>
+                <rng:element name="StartDate">
+                  <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="DateType"/>
+                </rng:element>
+              </rng:element>
+              <rng:element name="DescriptionLevel">
+                <rng:attribute name="listVersionID">
+                  <rng:value type="token">edition 2009</rng:value>
+                </rng:attribute>
+                <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeDescriptionLevelType"/>
+              </rng:element>
+            </rng:element>
+          </rng:oneOrMore>
+          <rng:oneOrMore>
+            <rng:element name="Contains">
+              <rng:element name="Name">
+                <rng:data datatypeLibrary="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:10" type="TextType"/>
+              </rng:element>
+              <rng:element name="DescriptionLevel">
+                <rng:attribute name="listVersionID">
+                  <rng:value type="token">edition 2009</rng:value>
+                </rng:attribute>
+                <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeDescriptionLevelType"/>
+              </rng:element>
+            </rng:element>
+          </rng:oneOrMore>
+          <rng:zeroOrMore>
+            <rng:element name="Document">
+              <rng:element name="Attachment">
+                <rng:attribute name="format">
+                  <rng:value datatypeLibrary="urn:un:unece:uncefact:codelist:draft:DAF:fileTypeCode:2009-08-18" type="FileTypeCodeType">fmt/123</rng:value>
+                </rng:attribute>
+                <rng:attribute name="encodingCode">
+                  <rng:value datatypeLibrary="urn:un:unece:uncefact:codelist:standard:6:0133:40106" type="CharacterSetEncodingCodeContentType">6</rng:value>
+                </rng:attribute>
+                <rng:data datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="ArchivesBinaryObjectType"/>
+              </rng:element>
+              <rng:element name="Type">
+                <rng:attribute name="listVersionID">
+                  <rng:value type="token">edition 2009</rng:value>
+                </rng:attribute>
+                <rng:value datatypeLibrary="fr:gouv:culture:archivesdefrance:seda:v1.0:QualifiedDataType:1" type="CodeDocumentType">CDO</rng:value>
+              </rng:element>
+            </rng:element>
+          </rng:zeroOrMore>
+        </rng:element>
+      </rng:oneOrMore>
+    </rng:element>
+  </rng:start>
+</rng:grammar>
--- a/test/test_profile_generation.py	Fri Oct 07 18:04:30 2016 +0200
+++ b/test/test_profile_generation.py	Tue Oct 11 17:02:06 2016 +0200
@@ -817,6 +817,9 @@
     def test_seda_1_0(self):
         self._test_profile('SEDA-1.0.rng', 'seda_1_export.rng')
 
+    def test_seda_0_2_rng(self):
+        self._test_profile('SEDA-0.2.rng', 'seda_02_export.rng')
+
 
 if __name__ == '__main__':
     import unittest