print("Searching through entities") export_records(old_client, folder_path, list_of_types_to_consider) # Discover the Relationship Guids that will be uploaded later print("Discovering guids to remap from disk") relationship_guids = discover_guids(folder_path, ["relationshipGuid"]) with open(relationships_guid_path, 'a+') as fp: for relationship in relationship_guids: fp.write(relationship) fp.write("\n") # Get Guids and replace them print("Remapping guids from disk and into memory") old_entity_guids = discover_guids(folder_path, indicators) orig_guid_to_temp_guid = {g: str(gt.get_guid()) for g in old_entity_guids} remapped_entities = remap_guids(orig_guid_to_temp_guid, folder_path, output_path) print("Processing entities in memory") for entity in remapped_entities: # Strip the relationshipAttributes, they will be added later. entity["relationshipAttributes"] = {} entity.pop("lastModifiedTS") entity.pop("createdBy") entity.pop("updatedBy") entity.pop("createTime") entity.pop("updateTime") input("Ready to upload entities. Continue? Ctrl + C to back out now.") # Upload and get results["guidAssignments"] for new guids results = new_client.upload_entities(batch=remapped_entities)
print("Writing glossary terms in prep to be re-mapped to temporary guids") with open(glossary_prep_path, 'w') as fp: json.dump(glossary_terms_copy, fp) print("Discovering guids and remapping guids") # Remap the guids and write them back out to the output_path old_glossary_guids = discover_guids([glossary_prep_path], ["guid", "termGuid"]) # Provide a new guid (temp guid) for the upload (must be a negative number) orig_guid_to_temp_guid = { g: str(gt.get_guid()) for g in old_glossary_guids } # Execute the find and replace of old guid with temp guid remapped_glossary = remap_guids(orig_guid_to_temp_guid, [glossary_prep_path], output_path) print("Processing the glossary terms in memory") headers = [ "antonyms", "classifies", "isA", "preferredTerms", "preferredToTerms", "replacedBy", "replacementTerms", "seeAlso", "synonyms", "translatedTerms", "translationTerms", "validValues", "validValuesFor" ] for term in remapped_glossary: # Remove everything that will be created automatically try: term["anchor"].pop("relationGuid") term.pop("lastModifiedTS") term.pop("createdBy") term.pop("qualifiedName")
with open( os.path.join(relationships_path, f"batch-{counter}.json"), 'w') as fp: json.dump(buffer, fp) buffer = [] counter = counter + 1 if len(buffer) > 0: with open(os.path.join(relationships_path, f"batch-last.json"), 'w') as fp: json.dump(buffer, fp) # Now we can read load the remapping files and # Load in the remapping files print('Remapping guids') remapped_relationships = remap_guids(old_to_new_guids, relationships_path, output_path) # Clean up the remapped relationship and upload one by one... # This will take a while... gt = GuidTracker() counter = 0 skipped = 0 total_relationships = len(remapped_relationships) for relationship in remapped_relationships: inner_relationship = relationship["relationship"] inner_relationship["guid"] = str(gt.get_guid()) # Pop attributes that break the upload inner_relationship.pop("updateTime") inner_relationship.pop("lastModifiedTS") inner_relationship.pop("updatedBy") inner_relationship.pop("createTime")