[PATCH 4 of 5 seda] [profile gen] Support for digest algorithm in SEDA 1.0 export

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 9 17:13:51 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489073194 -3600
#      Thu Mar 09 16:26:34 2017 +0100
# Node ID 6c5b6306437922460ddc337b805854000941c244
# Parent  5897c8060f8ea299b200d641dbe551c757c34a78
[profile gen] Support for digest algorithm in SEDA 1.0 export

Using Integrity element of the document (data object).

Related to #16687452

diff --git a/cubicweb_seda/entities/profile_generation.py b/cubicweb_seda/entities/profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py
+++ b/cubicweb_seda/entities/profile_generation.py
@@ -971,10 +971,11 @@ class SEDA1XSDExport(SEDA2XSDExport):
                                             xsd_attributes=[XAttr('Id', 'xsd:ID')])
 
         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):
         """Iter on archive/archive object children, which may be either
         archive objects or documents, and append XSD elements for them to the given parent node.
@@ -1189,10 +1190,19 @@ class SEDA1XSDExport(SEDA2XSDExport):
 
     def xsd_originating_agency(self, parent, content):
         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'
     kw_content_tag_attributes = [XAttr('role', 'xsd:token'),
                                  XAttr('languageID', 'xsd:language')]
diff --git a/test/data/seda_1_export.rng b/test/data/seda_1_export.rng
--- a/test/data/seda_1_export.rng
+++ b/test/data/seda_1_export.rng
@@ -541,10 +541,18 @@
                 <rng:attribute name="filename">
                   <rng:value type="string">this_is_the_filename.pdf</rng:value>
                 </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>
                 </rng:attribute>
                 <rng:value type="string">CDO</rng:value>
diff --git a/test/data/seda_1_export.xsd b/test/data/seda_1_export.xsd
--- a/test/data/seda_1_export.xsd
+++ b/test/data/seda_1_export.xsd
@@ -437,10 +437,19 @@
                             <xsd:attribute name="uri" type="xsd:anyURI" use="prohibited"/>
                           </xsd:extension>
                         </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>
                           <xsd:extension base="qdt:CodeDocumentType">
                             <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
diff --git a/test/test_profile_generation.py b/test/test_profile_generation.py
--- a/test/test_profile_generation.py
+++ b/test/test_profile_generation.py
@@ -723,10 +723,11 @@ class OldSEDAExportMixin(object):
             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_algorithm', 'SEDABinaryDataObject', u'md5'),
                     ('seda_rule', 'SEDASeqAppraisalRuleRule', u'P10Y'),
                     ('seda_rule', 'SEDASeqAccessRuleRule', u'AR038'),
                     ('seda_final_action', 'SEDAAppraisalRule', u'detruire'),
             ]:
                 scheme = testutils.scheme_for_type(cnx, rtype, etype, value)
@@ -806,10 +807,11 @@ class OldSEDAExportMixin(object):
 
             # Add minimal document to first level archive
             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',
                    user_cardinality=u'1',
                    seda_format_id_from=bdo,


More information about the saem-devel mailing list