in objectModel/Python/cdm/objectmodel/cdm_attribute_resolution_guidance_def.py [0:0]
def _update_attribute_defaults(self, att_name: str, owner: 'CdmObject') -> None:
# handle the cardinality and expansion group.
# default is one, but if there is some hint of an array, make it work
if self.cardinality is None:
if self.expansion is not None:
self.cardinality = 'many'
else:
self.cardinality = 'one'
if self.cardinality == 'many' and self.expansion is None:
self.expansion = CdmAttributeResolutionGuidance_Expansion()
if self.cardinality == 'many' and self.expansion is not None:
if self.expansion.starting_ordinal is None:
self.expansion.starting_ordinal = 0
if self.expansion.maximum_expansion is None:
self.expansion.maximum_expansion = 5
if self.expansion.count_attribute is None:
self.expansion.count_attribute = self.ctx.corpus._fetch_artifact_attribute('count')
self.expansion.count_attribute.owner = owner
self.expansion.count_attribute.in_document = owner.in_document
# entity by ref. anything mentioned?
if self.entity_by_reference:
if self.entity_by_reference.allow_reference is None:
self.entity_by_reference.allow_reference = True
if self.entity_by_reference.allow_reference:
if self.entity_by_reference.always_include_foreign_key is None:
self.entity_by_reference.always_include_foreign_key = False
if self.entity_by_reference.foreign_key_attribute is None:
# make up a fk
self.entity_by_reference.foreign_key_attribute = self.ctx.corpus._fetch_artifact_attribute('id')
self.entity_by_reference.foreign_key_attribute.owner = owner
self.entity_by_reference.foreign_key_attribute.in_document = owner.in_document
# selects one>
if self.selects_sub_attribute:
if self.selects_sub_attribute.selects is None:
self.selects_sub_attribute.selects = 'one'
if self.selects_sub_attribute.selects == 'one':
if self.selects_sub_attribute.selected_type_attribute is None:
# make up a type indicator
self.selects_sub_attribute.selected_type_attribute = self.ctx.corpus._fetch_artifact_attribute('type')
self.selects_sub_attribute.selected_type_attribute.owner = owner
self.selects_sub_attribute.selected_type_attribute.in_document = owner.in_document
# only set a rename format if one is needed for arrays or added atts
if self.rename_format is None:
if att_name is None: # a type attribute, so no nesting
if self.cardinality == 'many':
self.rename_format = '{a}{o}'
else:
if self.cardinality == 'many':
self.rename_format = '{a}{o}{M}'
else:
self.rename_format = '{a}{M}'
if self.rename_format is not None:
# rename format is a lie. actually only supports sub-attribute name and ordinal as 'a' and 'o'
if att_name is not None:
# replace the use of {a or A} with the outer attributeName
upper = False
index_a = self.rename_format.find('{a}')
if index_a < 0:
index_a = self.rename_format.find('{A}')
upper = True
if index_a >= 0:
if upper:
att_name = att_name[0].upper() + att_name[1:]
self.rename_format = self.rename_format[0:index_a] + att_name + self.rename_format[index_a + 3:]
# now, use of {m/M} should be turned to {a/A}
index_m = self.rename_format.find('{m}')
if index_m >= 0:
self.rename_format = self.rename_format[0:index_m] + '{a}' + self.rename_format[index_m + 3:]
else:
index_m = self.rename_format.find('{M}')
if index_m >= 0:
self.rename_format = self.rename_format[0:index_m] + '{A}' + self.rename_format[index_m + 3:]