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

[xsd gen] Generate proper XSD for transfer's signature

It should allow any content. Copy OpenType from original SEDA XSD and reference
it.

Related to #12663412
parent 058e78a48d36
......@@ -125,6 +125,12 @@ class SEDA2XSDExport(EntityAdapter):
self._process(entity, profile_element, child_defs, to_process)
assert not to_process, to_process
open_type = self.element('xsd:complexType', root, {'name': 'OpenType', 'abstract': 'true'})
open_type_seq = self.element('xsd:sequence', open_type)
self.element('xsd:attribute', open_type, {'ref': 'xml:id', 'use': 'optional'})
self.element('xsd:attribute', open_type, {'ref': 'xlink:href', 'use': 'optional'})
self.element('xsd:any', open_type_seq, {'namespace': '##other', 'processContents': 'lax',
'minOccurs': '0'})
def _process(self, entity, profile_element, child_defs, to_process):
for occ, path in child_defs:
......@@ -159,13 +165,13 @@ class SEDA2XSDExport(EntityAdapter):
def element_occ(self, profile_element, occ, target_value, to_process,
cardinality=None, documentation=None):
callback = getattr(self, 'element_' + occ.target.__class__.__name__.lower())
if isinstance(occ.target, graph_nodes.XMLAttribute):
attrs = xsd_attribute_cardinality(occ, cardinality)
else:
attrs = xsd_element_cardinality(occ, cardinality)
attrs['documentation'] = documentation
occ.target.duplicated = isinstance(occ, dict) # XXX iirk
callback = getattr(self, 'element_' + occ.target.__class__.__name__.lower())
callback(occ.target, profile_element, target_value, attrs, to_process)
def element_alternative(self, xselement, profile_element, target_value, attrs, to_process):
......@@ -178,7 +184,11 @@ class SEDA2XSDExport(EntityAdapter):
target_element = self.element('xsd:sequence', parent_element, attrs)
to_process[xselement].append((target_value, target_element))
def element_xmlelement(self, xselement, profile_element, target_value, attrs, to_process):
def element_xmlelement(self, xselement, profile_element, target_value, attrs, to_process): # noqa
if xselement.local_name == 'Signature':
attrs['type'] = 'OpenType'
self._target_element(xselement, profile_element, attrs)
return
target_element = self._target_element(xselement, profile_element, attrs)
content_type = self.xsd_content_type(xselement.textual_content_type)
if content_type:
......
......@@ -200,6 +200,19 @@ class SEDAXSDExportTC(XmlTestMixin, CubicWebTC):
self.assertEqual(len(enum_elts), 1)
self.assertEqual(enum_elts[0].attrib['value'], archival_org.absolute_url())
def test_transfer_signature(self):
with self.admin_access.client_cnx() as cnx:
transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
cnx.create_entity('SEDASignature', seda_signature=transfer)
profile = self.profile_etree(transfer)
xpath = lambda x: profile.xpath(x, namespaces=NAMESPACES)
signatures = xpath('//xs:element[@name="Signature"]')
self.assertEqual(len(signatures), 1)
self.assertEqual(signatures[0].attrib, {'name': 'Signature', 'type': 'OpenType',
'minOccurs': '0'})
open_types = xpath('//xs:complexType[@name="OpenType"]')
self.assertEqual(len(open_types), 1)
def profile_etree(self, transfer_entity):
"""Return etree representation of profile's XSD for the given transfer entity"""
xsd = transfer_entity.cw_adapt_to('SEDA-2.0.xsd').dump()
......
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