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

[code gen] Generate new structures that will ease check for unhandled cardinalities

Those structures will be used as bases for hooks necessary to check for
unhandled cardinalities, that will be introduced by the following change set.

We have to watch composite relation that may lead to several children, and for
the entity types that are possible as children.

Related to #17098404
parent a671735e9217
......@@ -915,3 +915,51 @@ CHOICE_RTYPE = {
]
]
}
CHECK_CARD_ETYPES = [
'SEDAAddressee',
'SEDAArchiveUnit',
'SEDABinaryDataObject',
'SEDACustodialHistoryItem',
'SEDADataObjectReference',
'SEDAEvent',
'SEDAIsPartOf',
'SEDAIsVersionOf',
'SEDAJuridictional',
'SEDAKeyword',
'SEDAPhysicalDataObject',
'SEDARecipient',
'SEDARefNonRuleId',
'SEDAReferences',
'SEDARelatedTransferReference',
'SEDARelationship',
'SEDAReplaces',
'SEDARequires',
'SEDASpatial',
'SEDATag',
'SEDATemporal',
'SEDAWriter'
]
CHECK_CHILDREN_CARD_RTYPES = [
'seda_addressee_from',
'seda_archive_unit',
'seda_binary_data_object',
'seda_custodial_history_item',
'seda_data_object_reference',
'seda_event',
'seda_is_part_of',
'seda_is_version_of',
'seda_juridictional',
'seda_keyword',
'seda_physical_data_object',
'seda_recipient_from',
'seda_ref_non_rule_id_from',
'seda_references',
'seda_related_transfer_reference',
'seda_relationship',
'seda_replaces',
'seda_requires',
'seda_spatial',
'seda_tag',
'seda_temporal',
'seda_writer_from'
]
......@@ -44,15 +44,21 @@ class SEDAAnyEntity(AnyEntity):
''')
self.altetype2rtype = {} # registry of rtype to children elements for all choices
self.altetype2rtype = {} # rtype to children elements for all choices
self.check_card_etypes = set() # entity types whose cardinality must be checked
self.check_card_rtypes = set() # relation types whose children cardinality must be checked
for mapping_element in mapping.ordered:
self._callback('register_alt_rtype_for', mapping_element)
eclass_code = self._callback('entity_class_for', mapping_element)
if eclass_code:
stream.write(eclass_code + '\n')
stream.write(u'CHOICE_RTYPE = ') # Write the registry as a constant
stream.write(json.dumps(self.altetype2rtype, sort_keys=True, indent=2,
separators=(',', ': ')).replace('"', "'") + '\n')
# Write pre-computed data structures as constants
for name, data in [('CHOICE_RTYPE', self.altetype2rtype),
('CHECK_CARD_ETYPES', sorted(self.check_card_etypes)),
('CHECK_CHILDREN_CARD_RTYPES', sorted(self.check_card_rtypes))]:
stream.write(u'{} = '.format(name))
stream.write(json.dumps(data, sort_keys=True, indent=2,
separators=(',', ': ')).replace('"', "'") + '\n')
def entity_class_for_e_type_mapping(self, mapping):
attributes = ordered_attributes(mapping)
......@@ -76,6 +82,10 @@ class SEDAAnyEntity(AnyEntity):
if altetype.startswith('SEDAAlt'):
self.altetype2rtype.setdefault(altetype, []).append((mapping.rtype, composite))
if mapping.card[1] in '*+':
self.check_card_etypes.add(mapping.subjtype)
self.check_card_rtypes.add(mapping.rtype)
if __name__ == '__main__':
EntitiesGenerator.main()
Supports Markdown
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