async def from_data(
        ctx: 'CdmCorpusContext', data_obj: 'LocalEntity',
        extension_trait_def_list: List['CdmTraitDefinition'],
        local_extension_trait_def_list: List['CdmTraitDefinition']
    ) -> Optional['CdmDocumentDefinition']:
        doc = ctx.corpus.make_object(CdmObjectType.DOCUMENT_DEF,
                                     '{}.cdm.json'.format(data_obj.name))

        # import at least foundations
        doc.imports.append('cdm:/foundations.cdm.json')

        entity_dec = await EntityPersistence.from_data(
            ctx, data_obj, extension_trait_def_list,
            local_extension_trait_def_list)

        if not entity_dec:
            logger.error(
                DocumentPersistence.__name__, ctx,
                'There was an error while trying to convert a model.json entity to the CDM entity.'
            )
            return None

        if data_obj.get('imports'):
            for element in data_obj.imports:
                if element.corpusPath == 'cdm:/foundations.cdm.json':
                    # don't add foundations twice
                    continue

                doc.imports.append(CdmImportPersistence.from_data(
                    ctx, element))

        doc.definitions.append(entity_dec)

        return doc
Esempio n. 2
0
    async def from_data(
        ctx: 'CdmCorpusContext', data_obj: 'LocalEntity',
        extension_trait_def_list: List['CdmTraitDefinition'],
        local_extension_trait_def_list: List['CdmTraitDefinition']
    ) -> Optional['CdmDocumentDefinition']:
        doc = ctx.corpus.make_object(CdmObjectType.DOCUMENT_DEF,
                                     '{}.cdm.json'.format(data_obj.name))

        # import at least foundations
        doc.imports.append(Constants._FOUNDATIONS_CORPUS_PATH)

        entity_dec = await EntityPersistence.from_data(
            ctx, data_obj, extension_trait_def_list,
            local_extension_trait_def_list)

        if not entity_dec:
            logger.error(
                ctx, DocumentPersistence.__name__,
                DocumentPersistence.from_data.__name__, None,
                CdmLogCode.ERR_PERSIST_MODELJSON_ENTITY_CONVERSION_ERROR,
                data_obj.name)
            return None

        if data_obj.get('imports'):
            for element in data_obj.imports:
                if element.corpusPath == Constants._FOUNDATIONS_CORPUS_PATH:
                    # don't add foundations twice
                    continue

                doc.imports.append(CdmImportPersistence.from_data(
                    ctx, element))

        doc.definitions.append(entity_dec)

        return doc