3737from auth_api .services import SimpleOrg as SimpleOrgService
3838from auth_api .services import User as UserService
3939from auth_api .services .authorization import Authorization as AuthorizationService
40+ from auth_api .services .entity_mapping import EntityMappingService
41+ from auth_api .services .flags import flags
4042from auth_api .utils .auth import jwt as _jwt
4143from auth_api .utils .endpoints_enums import EndpointEnum
4244from auth_api .utils .enums import AccessType , NotificationType , OrgStatus , OrgType , PatchActions , Status
@@ -351,7 +353,7 @@ def delete_organzization_contact(org_id):
351353def get_organization_affiliations_search (org_id ):
352354 """Get all affiliated entities for the given org, this works with pagination."""
353355 try :
354- response , status = new_affiliation_search (org_id )
356+ response , status = affiliation_search (org_id , use_entity_mapping = True )
355357 except BusinessException as exception :
356358 response , status = {"code" : exception .code , "message" : exception .message }, exception .status_code
357359 except ServiceUnavailableException as exception :
@@ -371,7 +373,7 @@ def get_organization_affiliations(org_id):
371373 HTTPStatus .OK ,
372374 )
373375 # Remove below after UI is pointing at new route.
374- response , status = new_affiliation_search (org_id )
376+ response , status = affiliation_search (org_id )
375377 except BusinessException as exception :
376378 response , status = {"code" : exception .code , "message" : exception .message }, exception .status_code
377379 except ServiceUnavailableException as exception :
@@ -380,16 +382,19 @@ def get_organization_affiliations(org_id):
380382 return response , status
381383
382384
383- def new_affiliation_search (org_id ):
385+ def affiliation_search (org_id , use_entity_mapping = False ):
384386 """Get all affiliated entities for the given org by calling into Names and LEAR."""
385- # get affiliation identifiers and the urls for the source data
386387 org = OrgService .find_by_org_id (org_id , allowed_roles = ALL_ALLOWED_ROLES )
387388 if org is None :
388389 raise BusinessException (Error .DATA_NOT_FOUND , None )
389- affiliations = AffiliationModel .find_affiliations_by_org_id (org_id )
390390 search_details = AffiliationSearchDetails .from_request_args (request )
391+ if use_entity_mapping :
392+ affiliation_bases = EntityMappingService .populate_affiliation_base (org_id , search_details )
393+ else :
394+ affiliations = AffiliationModel .find_affiliations_by_org_id (org_id )
395+ affiliation_bases = AffiliationService .affiliation_to_affiliation_base (affiliations )
391396 affiliations_details_list = asyncio .run (
392- AffiliationService .get_affiliation_details (affiliations , search_details , org_id )
397+ AffiliationService .get_affiliation_details (affiliation_bases , search_details , org_id )
393398 )
394399 # Use orjson serializer here, it's quite a bit faster.
395400 response , status = (
@@ -428,7 +433,6 @@ def post_organization_affiliation(org_id):
428433 phone = request_json .get ("phone" ),
429434 certified_by_name = request_json .get ("certifiedByName" ),
430435 )
431-
432436 response , status = (
433437 AffiliationService .create_new_business_affiliation (affiliation_data ).as_dict (),
434438 HTTPStatus .CREATED ,
@@ -444,10 +448,15 @@ def post_organization_affiliation(org_id):
444448 ).as_dict (),
445449 HTTPStatus .CREATED ,
446450 )
447-
448451 entity_details = request_json .get ("entityDetails" , None )
449452 if entity_details :
453+ if flags .is_on ("enable-entity-mapping" , default = False ) is True :
454+ EntityMappingService .from_entity_details (entity_details )
450455 AffiliationService .fix_stale_affiliations (org_id , entity_details )
456+ # Auth-queue handles the row creation for new business (NR only), this handles passcode missing info
457+ elif is_new_business is False :
458+ if flags .is_on ("enable-entity-mapping" , default = False ) is True :
459+ EntityMappingService .populate_entity_mapping_for_identifier (business_identifier )
451460 except BusinessException as exception :
452461 response , status = {"code" : exception .code , "message" : exception .message }, exception .status_code
453462
0 commit comments