Source code for module.utils.create_registry

import avesterra as av


[docs] def create_person_registry(auth: av.AvAuthorization) -> av.AvRegistry: """ This function shows how to check for an existing person registry, create a new person registry, and register a person with the person registry. :param auth: The Orchestra server authorization that allows entity operations. """ try: # First see if the registry already exists. # All registries exit in(0,0,1). person_registry = av.lookup_registry( registry=av.AvEntity(0, 0, 1), key="person_registry", authorization=auth ) except Exception as e: # Create the registry if it doesn't exist person_registry = av.create_registry( name="Person Registry", key="person_registry", authorization=auth ) # All registries get created and exist in the (0,0,1). # Register the newly created person registry entity in (0,0,1). av.register_entity( registry=av.AvEntity(0, 0, 1), name="Person Registry", key="person_registry", entity=person_registry, authorization=auth ) return person_registry
[docs] def add_person_to_registry(person_registry: av.AvEntity, person_entity: av.AvEntity, auth: av.AvAuthorization): person_name = av.AvValue.decode_string(av.get_fact(person_entity, av.AvAttribute.NAME, auth)) person_address = av.AvValue.decode_string(av.get_fact(person_entity, av.AvAttribute.ADDRESS, auth)) # Use the name and address as the unique key. - Note you need to ensure # the key is unique so you don't overwrite an existing person. # Name & address were used since they were available. key = person_name + person_address # Register the person av.register_entity( registry=person_registry, name=person_name, key=key, entity=person_entity, authorization=auth )
[docs] def create_company_registry(auth: av.AvAuthorization) -> av.AvRegistry: """ This function shows how to check for an existing company registry, create a new company registry, and register a company with the company registry. :param auth: The Orchestra server authorization that allows entity operations. """ try: # first see if the registry already exists company_registry = av.lookup_registry( registry=av.AvEntity(0, 0, 1), key="company_registry", authorization=auth ) except Exception as e: # Create the registry if it doesn't exist company_registry = av.create_registry( name="Company Registry", key="company_registry", authorization=auth ) # All registries get created and exist in the (0,0,1). # Register the newly created company registry entity in (0,0,1). av.register_entity( registry=av.AvEntity(0, 0, 1), name="Company Registry", key="company_registry", entity=company_registry, authorization=auth ) return company_registry
[docs] def add_company_to_registry(company_registry: av.AvEntity, company_entity: av.AvEntity, auth: av.AvAuthorization): company_name = av.AvValue.decode_string(av.get_fact(company_entity, av.AvAttribute.NAME, auth)) company_address = av.AvValue.decode_string(av.get_fact(company_entity, av.AvAttribute.ADDRESS, auth)) # Use the name and address as the unique key. - Note you need to ensure # the key is unique so you don't overwrite an existing company. # Name & address were used since they were available. key = company_name + company_address # Register the person av.register_entity( registry=company_registry, name=company_name, key=key, entity=company_entity, authorization=auth )