Commit 36e2facb authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[profile gen] Consider originating agency in SEDA 1.0 / 0.2 export

Related to #16269136
parent 88cde09d7d14
......@@ -157,6 +157,12 @@ class SEDAContent(generated.SEDAContent):
return self.reverse_seda_transferring_agency_archive_unit_identifier[0]
return None
@property
def originating_agency(self):
if self.reverse_seda_originating_agency_from:
return self.reverse_seda_originating_agency_from[0]
return None
class SEDAKeyword(generated.SEDAKeyword):
......@@ -312,3 +318,10 @@ class SEDALanguage(generated.SEDALanguage):
@property
def concept(self):
return self.seda_language_to[0] if self.seda_language_to else None
class SEDAOriginatingAgency(generated.SEDAOriginatingAgency):
@property
def agency(self):
return self.seda_originating_agency_to[0] if self.seda_originating_agency_to else None
......@@ -885,14 +885,27 @@ class SEDA1XSDExport(SEDA2XSDExport):
self.element_schema(transfer_node, 'TransferIdentifier', 'qdt:ArchivesIDType',
xsd_attributes=self.xsd_attributes_scheme())
for agency_type in ('TransferringAgency', 'ArchivalAgency'):
agency_node = self.element_schema(transfer_node, agency_type)
self.element_schema(agency_node, 'Identification', 'qdt:ArchivesIDType',
xsd_attributes=self.xsd_attributes_scheme())
self.element_schema(agency_node, 'Name', 'udt:TextType', cardinality='0..1')
self.xsd_agency(transfer_node, agency_type)
for archive_unit in archive_transfer.archive_units:
self.xsd_archive(transfer_node, archive_unit)
def xsd_agency(self, parent, agency_type, agency=None):
agency_node = self.element_schema(parent, agency_type,
cardinality=agency.user_cardinality if agency else '1')
self.element_schema(agency_node, 'Identification', 'qdt:ArchivesIDType',
fixed_value=self.agency_id(agency) if agency else None,
xsd_attributes=self.xsd_attributes_scheme())
self.element_schema(agency_node, 'Name', 'udt:TextType',
fixed_value=self.agency_name(agency) if agency else None,
cardinality='0..1')
def agency_name(self, agency):
return agency.agency.name if agency and agency.agency else None
def agency_id(self, agency):
return text_type(agency.agency.eid) if agency and agency.agency else None
def xsd_archive(self, parent, archive_unit):
"""Append XSD elements for an archive to the given parent node."""
archive_node = self.element_schema(parent, 'Archive',
......@@ -1020,9 +1033,16 @@ class SEDA1XSDExport(SEDA2XSDExport):
documentation=date_entity.user_annotation)
if content.description:
self.xsd_description(cd_node, content.description)
if self.__regid__.startswith('SEDA-0.2') and content.originating_agency:
self.xsd_agency(cd_node, 'OriginatingAgency', content.originating_agency)
for keyword in content.keywords:
self.xsd_keyword(cd_node, keyword)
if self.__regid__.startswith('SEDA-1.0') and content.originating_agency:
self.xsd_agency(cd_node, 'OriginatingAgency', content.originating_agency)
def xsd_description_level(self, parent, concept):
"""Append XSD elements for a description level to the given parent node"""
value = _concept_value(concept, self.concepts_language)
......
......@@ -48,7 +48,7 @@
</rng:attribute>
<rng:value type="string">file</rng:value>
</rng:element>
<rng:element name="Name">
<rng:element name="Name">
<rng:data type="string"/>
</rng:element>
<rng:element name="ContentDescription">
......@@ -73,6 +73,18 @@
<rng:data type="string"/>
</rng:element>
</rng:optional>
<rng:optional>
<rng:element name="OriginatingAgency">
<rng:element name="Identification">
<rng:value type="string">%(agent-id)s</rng:value>
</rng:element>
<rng:optional>
<rng:element name="Name">
<rng:value type="string">%(agent-name)s</rng:value>
</rng:element>
</rng:optional>
</rng:element>
</rng:optional>
<rng:zeroOrMore>
<rng:element name="ContentDescriptive">
<rng:element name="KeywordContent">
......@@ -100,7 +112,7 @@
</rng:element>
</rng:zeroOrMore>
</rng:element>
<rng:optional>
<rng:optional>
<rng:element name="Appraisal">
<xsd:annotation>
<xsd:documentation>detruire le document</xsd:documentation>
......
......@@ -125,6 +125,27 @@
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element minOccurs="0" name="OriginatingAgency">
<xsd:complexType>
<xsd:sequence>
<xsd:element fixed="%(agent-id)s" name="Identification">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element fixed="%(agent-name)s" minOccurs="0" name="Name" type="udt:TextType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="ContentDescriptive">
<xsd:complexType>
<xsd:sequence>
......
......@@ -108,6 +108,18 @@
</rng:optional>
</rng:element>
</rng:zeroOrMore>
<rng:optional>
<rng:element name="OriginatingAgency">
<rng:element name="Identification">
<rng:value type="string">%(agent-id)s</rng:value>
</rng:element>
<rng:optional>
<rng:element name="Name">
<rng:value type="string">%(agent-name)s</rng:value>
</rng:element>
</rng:optional>
</rng:element>
</rng:optional>
</rng:element>
<rng:optional>
<rng:element name="Appraisal">
......
......@@ -165,6 +165,27 @@
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
</xsd:complexType>
</xsd:element>
<xsd:element minOccurs="0" name="OriginatingAgency">
<xsd:complexType>
<xsd:sequence>
<xsd:element fixed="%(agent-id)s" name="Identification">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element fixed="%(agent-name)s" minOccurs="0" name="Name" type="udt:TextType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
</xsd:complexType>
......
......@@ -678,6 +678,8 @@ class OldSEDAExportMixin(object):
scheme = scheme_for_type(cnx, rtype, etype, value)
concepts[value] = scheme.reverse_in_scheme[0]
agent = create('Agent', name=u'bob')
transfer = create('SEDAArchiveTransfer', title=u'my profile title &&',
simplified_profile=True)
......@@ -727,6 +729,9 @@ class OldSEDAExportMixin(object):
seda_keyword_type_from=kw,
user_cardinality=u'0..1')
create('SEDAOriginatingAgency', seda_originating_agency_from=content,
seda_originating_agency_to=agent)
cnx.create_entity('SEDAType', seda_type_from=content,
seda_type_to=concepts['CDO'])
......@@ -774,6 +779,7 @@ class OldSEDAExportMixin(object):
self.transfer_eid = transfer.eid
self.file_concept_eid = concepts['file'].eid
self.agent_eid = agent.eid
def _test_profile(self, adapter_id, expected_file):
with self.admin_access.client_cnx() as cnx:
......@@ -784,10 +790,13 @@ class OldSEDAExportMixin(object):
root = etree.fromstring(generated_xsd)
self.assertXmlValid(root)
file_concept = cnx.entity_from_eid(self.file_concept_eid)
agent = cnx.entity_from_eid(self.agent_eid)
with open(self.datapath(expected_file)) as expected:
self.assertXmlEqual(expected.read()
% {'concept-uri': binary_type(file_concept.cwuri),
'scheme-uri': binary_type(file_concept.scheme.cwuri)},
'scheme-uri': binary_type(file_concept.scheme.cwuri),
'agent-id': binary_type(agent.eid),
'agent-name': binary_type(agent.name)},
generated_xsd)
return adapter, root
......
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