[profile gen] Support for digest algorithm in SEDA 1.0 export
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 09 Mar 2017 16:26:34 +0100
changeset 2473 6c5b63064379
parent 2472 5897c8060f8e
child 2474 d331fbee620a
[profile gen] Support for digest algorithm in SEDA 1.0 export Using Integrity element of the document (data object). Related to #16687452
cubicweb_seda/entities/profile_generation.py
test/data/seda_1_export.rng
test/data/seda_1_export.xsd
test/test_profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py	Thu Mar 09 16:24:12 2017 +0100
+++ b/cubicweb_seda/entities/profile_generation.py	Thu Mar 09 16:26:34 2017 +0100
@@ -973,6 +973,7 @@
         self.xsd_system_id(document_node, data_object)
         self.xsd_attachment(document_node, data_object)
         self.xsd_date_created(document_node, data_object)
+        self.xsd_integrity(document_node, data_object)
         self.xsd_document_type(document_node, data_object)
 
     def xsd_children(self, parent, entity):
@@ -1191,6 +1192,15 @@
         if content.originating_agency:
             self.xsd_agency(parent, 'OriginatingAgency', content.originating_agency)
 
+    def xsd_integrity(self, parent, data_object):
+        algorithm = data_object.seda_algorithm[0] if data_object.seda_algorithm else None
+        self.element_schema(parent, 'Integrity', 'qdt:ArchivesHashcodeBinaryObjectType',
+                            cardinality='0..1',
+                            xsd_attributes=[XAttr('algorithme', 'xsd:string',
+                                                  cardinality='1',
+                                                  fixed_value=_concept_value(
+                                                      algorithm, self.concepts_language))])
+
     # extracted from xsd_keyword to allow parametrization for SEDA 1.0 vs 0.2 generation
     kw_tag_name = 'Keyword'
     kw_content_tag_type = 'qdt:KeywordContentType'
--- a/test/data/seda_1_export.rng	Thu Mar 09 16:24:12 2017 +0100
+++ b/test/data/seda_1_export.rng	Thu Mar 09 16:26:34 2017 +0100
@@ -543,6 +543,14 @@
                 </rng:attribute>
                 <rng:data type="string"/>
               </rng:element>
+              <rng:optional>
+                <rng:element name="Integrity">
+                  <rng:attribute name="algorithme">
+                    <rng:value type="string">md5</rng:value>
+                  </rng:attribute>
+                  <rng:data type="string"/>
+                </rng:element>
+              </rng:optional>
               <rng:element name="Type">
                 <rng:attribute name="listVersionID">
                   <rng:value type="token">edition 2009</rng:value>
--- a/test/data/seda_1_export.xsd	Thu Mar 09 16:24:12 2017 +0100
+++ b/test/data/seda_1_export.xsd	Thu Mar 09 16:26:34 2017 +0100
@@ -439,6 +439,15 @@
                         </xsd:simpleContent>
                       </xsd:complexType>
                     </xsd:element>
+                    <xsd:element minOccurs="0" name="Integrity">
+                      <xsd:complexType>
+                        <xsd:simpleContent>
+                          <xsd:extension base="qdt:ArchivesHashcodeBinaryObjectType">
+                            <xsd:attribute fixed="md5" name="algorithme" type="xsd:string" use="required"/>
+                          </xsd:extension>
+                        </xsd:simpleContent>
+                      </xsd:complexType>
+                    </xsd:element>
                     <xsd:element fixed="CDO" name="Type">
                       <xsd:complexType>
                         <xsd:simpleContent>
--- a/test/test_profile_generation.py	Thu Mar 09 16:24:12 2017 +0100
+++ b/test/test_profile_generation.py	Thu Mar 09 16:26:34 2017 +0100
@@ -725,6 +725,7 @@
                     ('seda_encoding_to', None, u'6'),
                     ('seda_type_to', None, u'CDO'),
                     ('seda_description_level', None, u'file'),
+                    ('seda_algorithm', 'SEDABinaryDataObject', u'md5'),
                     ('seda_rule', 'SEDASeqAppraisalRuleRule', u'P10Y'),
                     ('seda_rule', 'SEDASeqAccessRuleRule', u'AR038'),
                     ('seda_final_action', 'SEDAAppraisalRule', u'detruire'),
@@ -808,6 +809,7 @@
             ref = create('SEDADataObjectReference', seda_data_object_reference=unit_alt_seq)
             bdo = testutils.create_data_object(transfer, user_cardinality=u'0..n',
                                                filename=u'this_is_the_filename.pdf',
+                                               seda_algorithm=concepts['md5'],
                                                reverse_seda_data_object_reference_id=ref)
 
             create('SEDAFormatId',