async def from_data( ctx: 'CdmCorpusContext', data_obj: 'ReferenceEntity', location: str) -> 'CdmReferencedEntityDeclarationDefinition': referenced_entity = ctx.corpus.make_object( CdmObjectType.REFERENCED_ENTITY_DECLARATION_DEF, data_obj.name) referenced_entity.entity_name = data_obj.name corpus_path = ctx.corpus.storage.adapter_path_to_corpus_path(location) if corpus_path is None: logger.error( ctx, _TAG, "from_data", None, CdmLogCode.ERR_PERSIST_MODEL_JSON_REF_ENTITY_INVALID_LOCATION, location, referenced_entity.entity_name) return None referenced_entity.entity_path = '{}/{}'.format(corpus_path, data_obj.source) referenced_entity.explanation = data_obj.get('description') if data_obj.get('lastFileStatusCheckTime'): referenced_entity.last_file_status_check_time = dateutil.parser.parse( data_obj.get('lastFileStatusCheckTime')) if data_obj.get('lastFileModifiedTime'): referenced_entity.last_file_modified_time = dateutil.parser.parse( data_obj.get('lastFileModifiedTime')) await utils.process_annotations_from_data( ctx, data_obj, referenced_entity.exhibits_traits) if data_obj.get('isHidden'): is_hidden_trait = ctx.corpus.make_ref(CdmObjectType.TRAIT_REF, 'is.hidden', True) is_hidden_trait.is_from_property = True referenced_entity.exhibits_traits.append(is_hidden_trait) properties_trait = ctx.corpus.make_ref( CdmObjectType.TRAIT_REF, 'is.propertyContent.multiTrait', False) properties_trait.is_from_property = True argument = ctx.corpus.make_object(CdmObjectType.ARGUMENT_DEF, 'modelId') argument.value = data_obj.modelId properties_trait.arguments.append(argument) referenced_entity.exhibits_traits.append(properties_trait) extension_trait_def_list = [] # type: List[CdmTraitDefinition] extension_traits = CdmTraitCollection(ctx, referenced_entity) extension_helper.process_extension_from_json(ctx, data_obj, extension_traits, extension_trait_def_list) if extension_trait_def_list: logger.warning( ctx, _TAG, ReferencedEntityDeclarationPersistence.from_data.__name__, None, CdmLogCode.WARN_PERSIST_CUSTOM_EXT_NOT_SUPPORTED) return referenced_entity
async def from_data( ctx: 'CdmCorpusContext', data_obj: 'ReferenceEntity', location: str) -> 'CdmReferencedEntityDeclarationDefinition': referenced_entity = ctx.corpus.make_object( CdmObjectType.REFERENCED_ENTITY_DECLARATION_DEF, data_obj.name) corpus_path = ctx.corpus.storage.adapter_path_to_corpus_path(location) referenced_entity.entity_name = data_obj.name referenced_entity.entity_path = '{}/{}'.format(corpus_path, data_obj.source) referenced_entity.explanation = data_obj.get('description') if data_obj.get('lastFileStatusCheckTime'): referenced_entity.last_file_status_check_time = dateutil.parser.parse( data_obj.get('lastFileStatusCheckTime')) if data_obj.get('lastFileModifiedTime'): referenced_entity.last_file_modified_time = dateutil.parser.parse( data_obj.get('lastFileModifiedTime')) await utils.process_annotations_from_data( ctx, data_obj, referenced_entity.exhibits_traits) if data_obj.get('isHidden'): is_hidden_trait = ctx.corpus.make_ref(CdmObjectType.TRAIT_REF, 'is.hidden', True) is_hidden_trait.is_from_property = True referenced_entity.exhibits_traits.append(is_hidden_trait) properties_trait = ctx.corpus.make_ref( CdmObjectType.TRAIT_REF, 'is.propertyContent.multiTrait', False) properties_trait.is_from_property = True argument = ctx.corpus.make_object(CdmObjectType.ARGUMENT_DEF, 'modelId') argument.value = data_obj.modelId properties_trait.arguments.append(argument) referenced_entity.exhibits_traits.append(properties_trait) extension_trait_def_list = [] # type: List[CdmTraitDefinition] extension_traits = CdmTraitCollection(ctx, referenced_entity) extension_helper.process_extension_from_json(ctx, data_obj, extension_traits, extension_trait_def_list) if extension_trait_def_list: logger.warning( _TAG, ctx, 'Custom extensions are not supported in referenced entity.') return referenced_entity