async def convert_manifest_to_syms(doc: 'CdmManifestDefinition', adapter: 'StorageAdapter', path: str, res_opt: 'ResolveOptions', options: 'CopyOptions')-> 'SymsManifestContent': database_entity = None is_delta_sync = True existing_syms_tables = None existing_syms_relationship_entities = None try: req = await adapter.read_async(path) database_entity = DatabaseEntity().deserialize(json.loads(req)) except Exception as e: if e.code == 404: is_delta_sync = False else: raise if is_delta_sync: json_data = await adapter.read_async("/" + database_entity.name + "/" + database_entity.name + ".manifest.cdm.json/entitydefinition") from cdm.persistence.syms.models.query_artifacts_response import QueryArtifactsResponse entities = QueryArtifactsResponse().deserialize(json.loads(json_data)) existing_syms_tables = entities json_data = await adapter.read_async("/" + database_entity.name + "/" + database_entity.name+ ".manifest.cdm.json/relationships") realtionships = QueryArtifactsResponse().deserialize(json.loads(json_data)) existing_syms_relationship_entities = realtionships return await ManifestPersistence.to_data_async(doc, res_opt, options, is_delta_sync, existing_syms_tables, existing_syms_relationship_entities)
async def to_data_async(instance: CdmManifestDefinition, res_opt: ResolveOptions, options: CopyOptions, is_delta_sync: bool = False, existing_syms_tables: List[TableEntity] = None, existing_syms_relationships: List[RelationshipEntity] = None) -> SymsManifestContent: source = ManifestPersistence.create_data_source(instance) if source == None: return None properties = ManifestPersistence.create_database_propertybags(instance, res_opt, options) existing_table_entities = {} removed_syms_table = [] if existing_syms_tables is not None and len(existing_syms_tables.items) > 0 : # convert to dictionary for better searching ents = [] for ent in instance.entities: ents.append(ent.entity_name) for item in existing_syms_tables.items: entity_obj = TableEntity(None, None).deserialize(item) if entity_obj.type == SASEntityType.table: existing_table_entities[entity_obj.name] = entity_obj if entity_obj.name not in ents: removed_syms_table.append(entity_obj.name) added_or_modified_syms_tables = await ManifestPersistence.create_syms_tables_objects(instance, res_opt, options, source.location, existing_table_entities) # TODO: Submanifest existing_relationship_entities = {} removed_syms_relationships = [] if existing_syms_relationships is not None and len(existing_syms_relationships.items) > 0: rels = [] for rel in instance.relationships: rels.append(rel.name) for item in existing_syms_relationships.items: rel_obj = RelationshipEntity(None, None).deserialize(item) existing_relationship_entities[rel_obj.name] = rel_obj if rel_obj.name not in rels: removed_syms_relationships.append(rel_obj.name) added_or_modified_syms_relationships = ManifestPersistence.create_relationships(instance, existing_relationship_entities, res_opt, options) dbproperties = DatabaseProperties(source=source) if instance.explanation is not None: dbproperties.description = instance.explanation else: dbproperties.description = instance.manifest_name + " syms database" dbproperties.properties = properties database_entity = DatabaseEntity(name = instance.manifest_name, properties = dbproperties, type = SASEntityType.database) syms_content = SymsManifestContent() syms_content.database = database_entity syms_content.entities = added_or_modified_syms_tables syms_content.relationships = added_or_modified_syms_relationships syms_content.intial_sync = not is_delta_sync syms_content.removed_entities = removed_syms_table syms_content.removed_relationships = removed_syms_relationships return syms_content
async def get_syms_model(adapter: 'StorageAdapter', database_response: str, doc_path: str)-> 'SymsManifestContent': from cdm.persistence.syms.models.query_artifacts_response import QueryArtifactsResponse db = DatabaseEntity().deserialize(json.loads(database_response)) entities = await adapter.read_async('/' + db.name + '/' + db.name + '.manifest.cdm.json/entitydefinition') relationships = await adapter.read_async(doc_path + '/relationships') return SymsManifestContent( database = db, entities = QueryArtifactsResponse().deserialize(json.loads(entities)), relationships = QueryArtifactsResponse().deserialize(json.loads(relationships)), intial_sync = False, removed_entities = None, removed_relationships = None)
def from_object( ctx: CdmCorpusContext, name: str, namespace: str, path: str, data_objs: 'SymsDatabasesResponse') -> 'CdmManifestDefinition': manifest = ctx.corpus.make_object(CdmObjectType.MANIFEST_DEF, name) manifest.name = name manifest._folder_path = path manifest._namespace = namespace manifest.explanation = 'This manifest contains list of SyMS databases represented as sub-manifests.' if len(manifest.imports) == 0 or not ( x for x in manifest.imports if x.corpus_path == Constants._FOUNDATIONS_CORPUS_PATH): manifest.imports.append(Constants._FOUNDATIONS_CORPUS_PATH) if data_objs is not None and data_objs.items is not None: for item in data_objs.items: database = DatabaseEntity().deserialize(item) if database.type == SASEntityType.database: manifest.sub_manifests.append( ManifestDeclarationPersistence.from_data( ctx, database)) return manifest