Export content's type to SEDA 1.0 XSD.
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 Oct 2016 13:21:35 +0200
changeset 1622 eeb9a2a9b20c
parent 1621 b9560f846e58
child 1623 23f825b308db
Export content's type to SEDA 1.0 XSD. Closes #15524427
entities/custom.py
entities/profile_generation.py
test/data/seda_1_export.xsd
test/test_profile_generation.py
--- a/entities/custom.py	Tue Oct 11 16:09:10 2016 +0200
+++ b/entities/custom.py	Fri Oct 07 13:21:35 2016 +0200
@@ -59,6 +59,13 @@
     def encoding(self):
         return self.reverse_seda_encoding_from[0]
 
+    @property
+    def referenced_by(self):
+        """Return an iterator on archive unit's content sequences referencing this data-object."""
+        for ref in self.reverse_seda_data_object_reference_id:
+            for seq in ref.seda_data_object_reference:
+                yield seq
+
 
 class SEDAAltArchiveUnitArchiveUnitRefId(generated.SEDAAltArchiveUnitArchiveUnitRefId):
 
@@ -105,6 +112,10 @@
         return self.reverse_seda_keyword
 
     @property
+    def type(self):
+        return self.reverse_seda_type_from[0] if self.reverse_seda_type_from else None
+
+    @property
     def description_level_concept(self):
         return self.seda_description_level[0] if self.seda_description_level else None
 
@@ -242,3 +253,10 @@
     @property
     def concept(self):
         return self.seda_encoding_to[0] if self.seda_encoding_to else None
+
+
+class SEDAType(generated.SEDAType):
+
+    @property
+    def concept(self):
+        return self.seda_type_to[0] if self.seda_type_to else None
--- a/entities/profile_generation.py	Tue Oct 11 16:09:10 2016 +0200
+++ b/entities/profile_generation.py	Fri Oct 07 13:21:35 2016 +0200
@@ -1026,11 +1026,12 @@
                              XSDAttr('uri', 'xsd:anyURI'),
                              XSDAttr('filename', 'xsd:string'),
                          ])
-        # XXX seda 2 equivalent?
-        # self.xsd_element(document_node, 'Type', 'qdt:CodeDocumentType',
-        #                  fixed_value=_concept_value(document.document_type_code,
-        #                                       'seda_document_type_code_value'),
-        #                  xsd_attributes=[LIST_VERSION_ID_2009])
+        references = list(data_object.referenced_by)
+        assert len(references) == 1
+        seq = references[0]
+        self.xsd_element(document_node, 'Type', 'qdt:CodeDocumentType',
+                         fixed_value=safe_concept_value(seq.contents[0].type),
+                         xsd_attributes=[LIST_VERSION_ID_2009])
         # if document.description:
         #     self.xsd_description(document_node, document.description)
 
--- a/test/data/seda_1_export.xsd	Tue Oct 11 16:09:10 2016 +0200
+++ b/test/data/seda_1_export.xsd	Fri Oct 07 13:21:35 2016 +0200
@@ -270,6 +270,15 @@
                         </xsd:simpleContent>
                       </xsd:complexType>
                     </xsd:element>
+                    <xsd:element fixed="CDO" name="Type">
+                      <xsd:complexType>
+                        <xsd:simpleContent>
+                          <xsd:extension base="qdt:CodeDocumentType">
+                            <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
+                          </xsd:extension>
+                        </xsd:simpleContent>
+                      </xsd:complexType>
+                    </xsd:element>
                   </xsd:sequence>
                   <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
                 </xsd:complexType>
--- a/test/test_profile_generation.py	Tue Oct 11 16:09:10 2016 +0200
+++ b/test/test_profile_generation.py	Fri Oct 07 13:21:35 2016 +0200
@@ -675,11 +675,11 @@
             for rtype, etype, value in [
                     ('seda_format_id_to', None, u'fmt/123'),
                     ('seda_encoding_to', None, u'6'),
+                    ('seda_type_to', None, u'CDO'),
                     ('seda_description_level', None, u'file'),
                     ('seda_rule', 'SEDASeqAppraisalRuleRule', u'P10Y'),
                     ('seda_rule', 'SEDASeqAccessRuleRule', u'AR038'),
                     ('seda_final_action', 'SEDAAppraisalRule', u'detruire'),
-                    # XXX (u'seda_document_type_code', u'CDO', None),
             ]:
                 scheme = scheme_for_type(cnx, rtype, etype, value)
                 concepts[value] = scheme.reverse_in_scheme[0]
@@ -727,6 +727,9 @@
                    seda_seq_appraisal_rule_rule=appraisal_rule_rule,
                    user_annotation=u'detruire le document')
 
+            cnx.create_entity('SEDAType', seda_type_from=content,
+                              seda_type_to=concepts['CDO'])
+
             # Add sub archive unit
             _, _, subunit_alt_seq = create_archive_unit(unit_alt_seq, id=u'au2',
                                                         user_cardinality=u'1..n')
@@ -762,9 +765,6 @@
                    user_cardinality=u'1',
                    seda_encoding_from=bdo,
                    seda_encoding_to=concepts['6'])
-            # document_type_code_value = testutils.concept(cnx, 'CDO')
-            # document_type_code = create(
-            #     'SEDADocumentTypeCode', seda_document_type_code_value=document_type_code_value)
 
             # Add another sub archive unit
             _, _, subunit2_alt_seq = create_archive_unit(unit_alt_seq, id=u'au3',