Commit 43c549ca authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Implement rule inheritance when exporting to SEDA 0.2 or 1.0

by looking for the closes rule and climbing up to the transfer node.

Closes #15927695
parent a46551645361
......@@ -748,6 +748,18 @@ class SEDA2RelaxNGExport(RNGMixin, SEDA2ExportAdapter):
return parent
def climb_rule_holders(transfer_or_archive_unit):
"""Starting from a transfer or archive unit entity, yield entity that may be linked to management
rule until the root (transfer) is reached.
"""
while transfer_or_archive_unit is not None:
if transfer_or_archive_unit.cw_etype == 'SEDAArchiveTransfer':
yield transfer_or_archive_unit
else:
yield transfer_or_archive_unit.first_level_choice.content_sequence
transfer_or_archive_unit = transfer_or_archive_unit.cw_adapt_to('ITreeBase').parent()
class XAttr(namedtuple('_XAttr', ['name', 'qualified_type', 'cardinality', 'fixed_value'])):
"""Simple representation of an attribute element in a schema (RNG or XSD).
......@@ -910,8 +922,10 @@ class SEDA1XSDExport(SEDA2XSDExport):
return seq.contents[0].title
def archive_unit_appraisal_rule(self, archive_unit):
seq = archive_unit.first_level_choice.content_sequence
return seq.reverse_seda_appraisal_rule[0] if seq.reverse_seda_appraisal_rule else None
for rule_holder in climb_rule_holders(archive_unit):
if rule_holder.reverse_seda_appraisal_rule:
return rule_holder.reverse_seda_appraisal_rule[0]
return None
def xsd_appraisal_rule(self, parent, appraisal_rule):
# XXX cardinality 1 on rule, not multiple + element name : 'Appraisal' ou 'AppraisalRule'
......@@ -934,8 +948,10 @@ class SEDA1XSDExport(SEDA2XSDExport):
self.element_schema(ar_node, 'StartDate', 'udt:DateType')
def archive_unit_access_rule(self, archive_unit):
seq = archive_unit.first_level_choice.content_sequence
return seq.reverse_seda_access_rule[0] if seq.reverse_seda_access_rule else None
for rule_holder in climb_rule_holders(archive_unit):
if rule_holder.reverse_seda_access_rule:
return rule_holder.reverse_seda_access_rule[0]
return None
access_restriction_tag_name = 'AccessRestrictionRule'
......
......@@ -161,6 +161,39 @@
<rng:element name="Name">
<rng:data type="string"/>
</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 type="string">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 type="string">P10Y</rng:value>
</rng:element>
<rng:element name="StartDate">
<rng:data type="string"/>
</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 type="string"/>
</rng:element>
<rng:element name="StartDate">
<rng:data type="string"/>
</rng:element>
</rng:element>
<rng:element name="DescriptionLevel">
<rng:attribute name="listVersionID">
<rng:value type="token">edition 2009</rng:value>
......
......@@ -274,6 +274,48 @@
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element minOccurs="0" name="Appraisal">
<xsd:annotation>
<xsd:documentation>detruire le document</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element fixed="detruire" 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 fixed="P10Y" name="Duration" type="qdt:ArchivesDurationType">
<xsd:annotation>
<xsd:documentation>C'est dans 10ans je m'en irai</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="StartDate" type="udt:DateType"/>
</xsd:sequence>
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="AccessRestriction">
<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="prohibited"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="DescriptionLevel">
<xsd:complexType>
<xsd:simpleContent>
......
......@@ -166,6 +166,39 @@
<rng:element name="Name">
<rng:data type="string"/>
</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 type="string">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 type="string">P10Y</rng:value>
</rng:element>
<rng:element name="StartDate">
<rng:data type="string"/>
</rng:element>
</rng:element>
</rng:optional>
<rng:element name="AccessRestrictionRule">
<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="ContentDescription">
<rng:element name="DescriptionLevel">
<rng:attribute name="listVersionID">
......
......@@ -273,6 +273,48 @@
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element minOccurs="0" name="Appraisal">
<xsd:annotation>
<xsd:documentation>detruire le document</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element fixed="detruire" 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 fixed="P10Y" name="Duration" type="qdt:ArchivesDurationType">
<xsd:annotation>
<xsd:documentation>C'est dans 10ans je m'en irai</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="StartDate" type="udt:DateType"/>
</xsd:sequence>
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
</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="prohibited"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="ContentDescription">
<xsd:complexType>
<xsd:sequence>
......
......@@ -686,13 +686,23 @@ class OldSEDAExportMixin(object):
comment=u'my profile description &&',
seda_comment=transfer)
_, _, unit_alt_seq = create_archive_unit(transfer, id=u'au1',
user_cardinality=u'1..n')
create('SEDAAccessRule', # XXX mandatory for seda 1.0
user_cardinality=u'1',
seda_access_rule=unit_alt_seq,
seda_access_rule=transfer,
seda_seq_access_rule_rule=create(
'SEDASeqAccessRuleRule', reverse_seda_start_date=create('SEDAStartDate')))
appraisal_rule_rule = create('SEDASeqAppraisalRuleRule',
seda_rule=concepts['P10Y'],
user_annotation=u"C'est dans 10ans je m'en irai",
reverse_seda_start_date=create('SEDAStartDate'))
create('SEDAAppraisalRule',
seda_appraisal_rule=transfer,
seda_final_action=concepts['detruire'],
seda_seq_appraisal_rule_rule=appraisal_rule_rule,
user_annotation=u'detruire le document')
_, _, unit_alt_seq = create_archive_unit(transfer, id=u'au1',
user_cardinality=u'1..n')
content = create('SEDAContent',
user_cardinality=u'1',
......@@ -714,16 +724,6 @@ class OldSEDAExportMixin(object):
seda_keyword_reference_to=concepts['file'],
seda_keyword_reference_to_scheme=concepts['file'].scheme)
appraisal_rule_rule = create('SEDASeqAppraisalRuleRule',
seda_rule=concepts['P10Y'],
user_annotation=u"C'est dans 10ans je m'en irai",
reverse_seda_start_date=create('SEDAStartDate'))
create('SEDAAppraisalRule',
seda_appraisal_rule=unit_alt_seq,
seda_final_action=concepts['detruire'],
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'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment