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

[profile gen] Reorganize SEDA 1.0 / 0.2 export code

Move xsd_* methods all together, with the first one being the structural ones (i.e archive, archive unit, data object).
parent 8e3b7419f789
......@@ -890,22 +890,6 @@ class SEDA1XSDExport(SEDA2XSDExport):
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',
......@@ -935,15 +919,106 @@ class SEDA1XSDExport(SEDA2XSDExport):
self.xsd_access_rule(archive_node, access_rule_entity)
self.xsd_children(archive_node, archive_unit)
def archive_unit_name(self, archive_unit):
seq = archive_unit.first_level_choice.content_sequence
return seq.contents[0].title
archive_object_tag_name = 'ArchiveObject'
def archive_unit_appraisal_rule(self, archive_unit):
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_archive_object(self, parent, archive_unit):
"""Append XSD elements for the archive object to the given parent node."""
ao_node = self.element_schema(parent, self.archive_object_tag_name,
cardinality=archive_unit.user_cardinality,
documentation=archive_unit.user_annotation,
xsd_attributes=[XAttr('Id', 'xsd:ID')])
content_entity = self.archive_unit_content(archive_unit)
self.element_schema(ao_node, 'Name', 'udt:TextType',
fixed_value=content_entity.title.title,
documentation=content_entity.title.user_annotation,
xsd_attributes=[XAttr('languageID', 'xsd:language')])
self.xsd_transferring_agency_archive_identifier(ao_node, content_entity,
'TransferringAgencyObjectIdentifier')
if (self.__regid__.startswith('SEDA-1.0')
or content_entity.start_date
or content_entity.end_date
or content_entity.description
or content_entity.keywords):
self.xsd_content_description(ao_node, content_entity)
appraisal_rule_entity = self.archive_unit_appraisal_rule(archive_unit)
if appraisal_rule_entity:
self.xsd_appraisal_rule(ao_node, appraisal_rule_entity)
access_rule_entity = self.archive_unit_access_rule(archive_unit)
if access_rule_entity:
self.xsd_access_rule(ao_node, access_rule_entity)
self.xsd_children(ao_node, archive_unit)
return ao_node
def xsd_document(self, parent, data_object):
"""Append XSD elements for the document to the given parent node."""
document_node = self.element_schema(parent, 'Document',
cardinality=data_object.user_cardinality,
documentation=data_object.user_annotation,
xsd_attributes=[XAttr('Id', 'xsd:ID')])
def safe_cardinality(entity):
if entity is None:
return None
return entity.user_cardinality
def safe_concept_value(entity):
if entity is None:
return None
return _concept_value(entity.concept, self.concepts_language)
format_id = data_object.format_id
encoding = data_object.encoding
mime_type = data_object.mime_type
self.element_schema(document_node, 'Attachment', 'qdt:ArchivesBinaryObjectType',
xsd_attributes=[
XAttr('format', 'clmDAFFileTypeCode:FileTypeCodeType',
cardinality=safe_cardinality(format_id),
fixed_value=safe_concept_value(format_id)),
XAttr('encodingCode',
'clm60133:CharacterSetEncodingCodeContentType',
cardinality=safe_cardinality(encoding),
fixed_value=safe_concept_value(encoding)),
XAttr('mimeCode', 'clmIANAMIMEMediaType:MIMEMediaTypeContentType',
cardinality=safe_cardinality(mime_type),
fixed_value=safe_concept_value(mime_type)),
XAttr('filename', 'xsd:string',
cardinality='0..1',
fixed_value=data_object.filename),
# hard-coded attributes
XAttr('characterSetCode',
'clmIANACharacterSetCode:CharacterSetCodeContentType'),
XAttr('uri', 'xsd:anyURI'),
])
references = list(data_object.referenced_by)
assert len(references) == 1, (
'Unexpected number of references in document {} of {}: {}'.format(
data_object.eid, data_object.container[0].eid, references))
seq = references[0]
self.element_schema(document_node, 'Type', 'qdt:CodeDocumentType',
fixed_value=safe_concept_value(seq.contents[0].type),
xsd_attributes=[LIST_VERSION_ID_2009])
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.
"""
for au_or_bdo in entity.cw_adapt_to('ITreeBase').iterchildren():
if au_or_bdo.cw_etype == 'SEDABinaryDataObject':
self.xsd_document(parent, au_or_bdo)
else:
assert au_or_bdo.cw_etype == 'SEDAArchiveUnit'
self.xsd_archive_object(parent, au_or_bdo)
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 xsd_archival_agreement(self, parent, transfer):
agreement = transfer.archival_agreement
......@@ -984,12 +1059,6 @@ class SEDA1XSDExport(SEDA2XSDExport):
documentation=rule.user_annotation if rule else None)
self.element_schema(ar_node, 'StartDate', 'udt:DateType')
def archive_unit_access_rule(self, archive_unit):
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'
def xsd_access_rule(self, parent, access_rule):
......@@ -1007,10 +1076,6 @@ class SEDA1XSDExport(SEDA2XSDExport):
xsd_attributes=[LIST_VERSION_ID_2009])
self.element_schema(ar_node, 'StartDate', 'udt:DateType')
def archive_unit_content(self, archive_unit):
seq = archive_unit.first_level_choice.content_sequence
return seq.contents[0]
def xsd_content_description(self, parent, content):
"""Append XSD elements for a description content to the given parent node"""
cd_node = self.element_schema(parent, 'ContentDescription',
......@@ -1102,99 +1167,6 @@ class SEDA1XSDExport(SEDA2XSDExport):
self.concepts_language),
xsd_attributes=[LIST_VERSION_ID_2009])
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.
"""
for au_or_bdo in entity.cw_adapt_to('ITreeBase').iterchildren():
if au_or_bdo.cw_etype == 'SEDABinaryDataObject':
self.xsd_document(parent, au_or_bdo)
else:
assert au_or_bdo.cw_etype == 'SEDAArchiveUnit'
self.xsd_archive_object(parent, au_or_bdo)
archive_object_tag_name = 'ArchiveObject'
def xsd_archive_object(self, parent, archive_unit):
"""Append XSD elements for the archive object to the given parent node."""
ao_node = self.element_schema(parent, self.archive_object_tag_name,
cardinality=archive_unit.user_cardinality,
documentation=archive_unit.user_annotation,
xsd_attributes=[XAttr('Id', 'xsd:ID')])
content_entity = self.archive_unit_content(archive_unit)
self.element_schema(ao_node, 'Name', 'udt:TextType',
fixed_value=content_entity.title.title,
documentation=content_entity.title.user_annotation,
xsd_attributes=[XAttr('languageID', 'xsd:language')])
self.xsd_transferring_agency_archive_identifier(ao_node, content_entity,
'TransferringAgencyObjectIdentifier')
if (self.__regid__.startswith('SEDA-1.0')
or content_entity.start_date
or content_entity.end_date
or content_entity.description
or content_entity.keywords):
self.xsd_content_description(ao_node, content_entity)
appraisal_rule_entity = self.archive_unit_appraisal_rule(archive_unit)
if appraisal_rule_entity:
self.xsd_appraisal_rule(ao_node, appraisal_rule_entity)
access_rule_entity = self.archive_unit_access_rule(archive_unit)
if access_rule_entity:
self.xsd_access_rule(ao_node, access_rule_entity)
self.xsd_children(ao_node, archive_unit)
return ao_node
def xsd_document(self, parent, data_object):
"""Append XSD elements for the document to the given parent node."""
document_node = self.element_schema(parent, 'Document',
cardinality=data_object.user_cardinality,
documentation=data_object.user_annotation,
xsd_attributes=[XAttr('Id', 'xsd:ID')])
def safe_cardinality(entity):
if entity is None:
return None
return entity.user_cardinality
def safe_concept_value(entity):
if entity is None:
return None
return _concept_value(entity.concept, self.concepts_language)
format_id = data_object.format_id
encoding = data_object.encoding
mime_type = data_object.mime_type
self.element_schema(document_node, 'Attachment', 'qdt:ArchivesBinaryObjectType',
xsd_attributes=[
XAttr('format', 'clmDAFFileTypeCode:FileTypeCodeType',
cardinality=safe_cardinality(format_id),
fixed_value=safe_concept_value(format_id)),
XAttr('encodingCode',
'clm60133:CharacterSetEncodingCodeContentType',
cardinality=safe_cardinality(encoding),
fixed_value=safe_concept_value(encoding)),
XAttr('mimeCode', 'clmIANAMIMEMediaType:MIMEMediaTypeContentType',
cardinality=safe_cardinality(mime_type),
fixed_value=safe_concept_value(mime_type)),
XAttr('filename', 'xsd:string',
cardinality='0..1',
fixed_value=data_object.filename),
# hard-coded attributes
XAttr('characterSetCode',
'clmIANACharacterSetCode:CharacterSetCodeContentType'),
XAttr('uri', 'xsd:anyURI'),
])
references = list(data_object.referenced_by)
assert len(references) == 1, (
'Unexpected number of references in document {} of {}: {}'.format(
data_object.eid, data_object.container[0].eid, references))
seq = references[0]
self.element_schema(document_node, 'Type', 'qdt:CodeDocumentType',
fixed_value=safe_concept_value(seq.contents[0].type),
xsd_attributes=[LIST_VERSION_ID_2009])
# if document.description:
# self.xsd_description(document_node, document.description)
@classmethod
def xsd_attributes_scheme(cls, scheme=None):
"""Return a list of :class:`XAttr` for a scheme definition, with some proper values
......@@ -1216,6 +1188,32 @@ class SEDA1XSDExport(SEDA2XSDExport):
# attributes[0]['use'] = 'required'
return attributes
def archive_unit_access_rule(self, archive_unit):
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
def archive_unit_name(self, archive_unit):
seq = archive_unit.first_level_choice.content_sequence
return seq.contents[0].title
def archive_unit_appraisal_rule(self, archive_unit):
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 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 archive_unit_content(self, archive_unit):
seq = archive_unit.first_level_choice.content_sequence
return seq.contents[0]
@staticmethod
def cwuri_url(entity):
"""Return "public" URI for the given entity.
......
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