def process_traits_and_annotations_to_data(ctx: 'CdmCorpusContext', entity_object: 'MetadataObject', traits: 'CdmTraitCollection'): if traits is None: return annotations = [] extensions = [] for trait in traits: if trait.named_reference.startswith('is.extension.'): extension_helper.process_extension_trait_to_object( trait, entity_object) continue if trait.named_reference == 'is.modelConversion.otherAnnotations': for annotation in trait.arguments[0].value: if isinstance(annotation, dict) and annotation.get('name'): annotations.append(annotation) else: logger.warning(_TAG, ctx, 'Unsupported annotation type.') elif trait.named_reference not in ignored_traits and not trait.named_reference.startswith( 'is.dataFormat') and not (trait.named_reference in model_json_property_traits and trait.is_from_property): extension = TraitReferencePersistence.to_data(trait, None, None) extensions.append(extension) if annotations: entity_object.annotations = annotations if extensions: entity_object.traits = extensions
async def process_traits_and_annotations_to_data( ctx: 'CdmCorpusContext', entity_object: 'MetadataObject', traits: 'CdmTraitCollection'): if traits is None: return annotations = [] extensions = [] for trait in traits: if trait.named_reference.startswith('is.extension.'): extension_helper.process_extension_trait_to_object( trait, entity_object) elif trait.named_reference == 'is.modelConversion.otherAnnotations': for annotation in trait.arguments[0].value: if isinstance(annotation, NameValuePair): element = Annotation() element.name = annotation.name element.value = annotation.value annotations.append(element) elif isinstance(annotation, dict) and annotation.get('name'): annotations.append(annotation) else: logger.warning( ctx, _TAG, process_traits_and_annotations_to_data.__name__, None, CdmLogCode.WARN_ANNOTATION_TYPE_NOT_SUPPORTED) elif isinstance(trait, CdmTraitReference ) and trait.named_reference in trait_to_annotation_map: element = await ArgumentPersistence.to_data( trait.arguments[0], None, None) element.name = convert_trait_to_annotation(trait.named_reference) annotations.append(element) elif trait.named_reference not in ignored_traits and not trait.named_reference.startswith('is.dataFormat') \ and not (trait.named_reference in model_json_property_traits and trait.object_type == CdmObjectType.TRAIT_REF and trait.is_from_property): if trait.object_type == CdmObjectType.TRAIT_GROUP_REF: extension = TraitGroupReferencePersistence.to_data( trait, None, None) else: extension = TraitReferencePersistence.to_data( trait, None, None) extensions.append(extension) if annotations: entity_object.annotations = annotations if extensions: entity_object.traits = extensions
async def process_annotations_to_data(ctx: 'CdmCorpusContext', entity_object: 'MetadataObject', traits: 'CdmTraitCollection'): if traits is None: return annotations = [] extensions = [] for trait in traits: if trait.named_reference.startswith('is.extension.'): extension_helper.process_extension_trait_to_object( trait, entity_object) continue if trait.named_reference == 'is.modelConversion.otherAnnotations': for annotation in trait.arguments[0].value: if isinstance(annotation, dict) and annotation.get('name'): annotations.append(annotation) else: ctx.logger.warning('Unsupported annotation type.') elif not trait.is_from_property: annotation_name = trait_to_annotation_name(trait.named_reference) if annotation_name is not None and trait.arguments is not None \ and isinstance(trait.arguments, list) and len(trait.arguments) == 1: argument = await ArgumentPersistence.to_data( trait.arguments[0], None, None) if argument is not None: argument.name = annotation_name annotations.append(argument) elif trait.named_reference not in ignored_traits: extension = TraitReferencePersistence.to_data( trait, None, None) extensions.append(extension) if annotations: entity_object.annotations = annotations if extensions: entity_object.traits = extensions