Source code for module.lesson_9_registries

from dotenv import find_dotenv, load_dotenv
import avesterra as av
import orchestra.env as env
from utils import (
    create_company_entity,
    create_person_entity,
    create_registry,
    how_to_get_entities_from_registries,
    set_company_facts,
    set_person_facts,
)


[docs] def main(): # Initialize connection to AvesTerra server at IP Address load_dotenv(find_dotenv()) host = env.get_or_raise("AVESTERRA_HOST") cert_dir = env.get_or_raise("AVESTERRA_CERTIFICATE_DIR_PATH") auth = env.get_or_raise("AVESTERRA_AUTH", av.AvAuthorization) av.initialize(server=host, directory=cert_dir, socket_count=2) # Create people john_entity = create_person_entity.create_entity(name="John Smith", auth=auth) jane_entity = create_person_entity.create_entity(name="Jane Smith", auth=auth) # Create companies ibm_entity = create_company_entity.create_company(name="IBM", auth=auth) amazon_entity = create_company_entity.create_company(name="AMAZON", auth=auth) # Set some person facts set_person_facts.set_person_facts( person_entity=john_entity, name="John Smith", address="101 South Home", occupation="Software Engineer", company="IBM", auth=auth, ) set_person_facts.set_person_facts( person_entity=jane_entity, name="Jane Smith", address="501 North Home", occupation="Sales", company="AMAZON", auth=auth, ) # Set some company facts set_company_facts.set_company_facts( company_entity=ibm_entity, name="IBM", address="201 IBM Way", employee="John Smith", auth=auth, ) set_company_facts.set_company_facts( company_entity=amazon_entity, name="AMAZON", address="601 AMAZON Way", employee="Jane Smith", auth=auth, ) # Create Person Registry and register people in the registry person_registry = create_registry.create_person_registry(auth=auth) create_registry.add_person_to_registry( person_registry=person_registry, person_entity=john_entity, auth=auth ) create_registry.add_person_to_registry( person_registry=person_registry, person_entity=jane_entity, auth=auth ) # lookup people from person registry how_to_get_entities_from_registries.examples_of_get_from_person_registry( person_registry=person_registry, auth=auth ) # Create Company Registry and register companies in the registry company_registry = create_registry.create_company_registry(auth=auth) create_registry.add_company_to_registry( company_registry=company_registry, company_entity=ibm_entity, auth=auth ) create_registry.add_company_to_registry( company_registry=company_registry, company_entity=amazon_entity, auth=auth ) # lookup company from company registry how_to_get_entities_from_registries.examples_of_get_from_company_registry( company_registry=company_registry, auth=auth ) print("") print("----------------Lookup these Entity IDs in Maestro or avu ----------------") print(f"John_entity: {john_entity}") print(f"Jane_entity: {jane_entity}") print(f"ibm_entity: {ibm_entity}") print(f"amazon_entity: {amazon_entity}") print(f"person_registry: {person_registry}") print(f"company_registry: {company_registry}") print("------------------------------------------------------------------") av.finalize()
if __name__ == "__main__": main()