refactor(so-connector): optimize api calls with $select and filtering [31188f42]
This commit is contained in:
@@ -114,11 +114,17 @@ class SuperOfficeClient:
|
|||||||
|
|
||||||
# --- Convenience Wrappers ---
|
# --- Convenience Wrappers ---
|
||||||
|
|
||||||
def get_person(self, person_id):
|
def get_person(self, person_id, select: list = None):
|
||||||
return self._get(f"Person/{person_id}")
|
endpoint = f"Person/{person_id}"
|
||||||
|
if select:
|
||||||
|
endpoint += f"?$select={','.join(select)}"
|
||||||
|
return self._get(endpoint)
|
||||||
|
|
||||||
def get_contact(self, contact_id):
|
def get_contact(self, contact_id, select: list = None):
|
||||||
return self._get(f"Contact/{contact_id}")
|
endpoint = f"Contact/{contact_id}"
|
||||||
|
if select:
|
||||||
|
endpoint += f"?$select={','.join(select)}"
|
||||||
|
return self._get(endpoint)
|
||||||
|
|
||||||
def search(self, query_string: str):
|
def search(self, query_string: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ sys.path.append(connector_dir)
|
|||||||
# Note: backend.app needs to be importable. If backend is a package.
|
# Note: backend.app needs to be importable. If backend is a package.
|
||||||
try:
|
try:
|
||||||
from backend.app import app, get_db
|
from backend.app import app, get_db
|
||||||
from backend.database import Base, Industry, Persona, MarketingMatrix, JobRoleMapping, Company, Contact, init_db
|
from backend.database import Base, Industry, Persona, MarketingMatrix, JobRolePattern, Company, Contact, init_db
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Try alternate import if running from root
|
# Try alternate import if running from root
|
||||||
sys.path.append(os.path.abspath("company-explorer"))
|
sys.path.append(os.path.abspath("company-explorer"))
|
||||||
from backend.app import app, get_db
|
from backend.app import app, get_db
|
||||||
from backend.database import Base, Industry, Persona, MarketingMatrix, JobRoleMapping, Company, Contact, init_db
|
from backend.database import Base, Industry, Persona, MarketingMatrix, JobRolePattern, Company, Contact, init_db
|
||||||
|
|
||||||
# Import Worker Logic
|
# Import Worker Logic
|
||||||
from worker import process_job
|
from worker import process_job
|
||||||
@@ -56,10 +56,10 @@ class MockSuperOfficeClient:
|
|||||||
self.contacts = {} # id -> data
|
self.contacts = {} # id -> data
|
||||||
self.persons = {} # id -> data
|
self.persons = {} # id -> data
|
||||||
|
|
||||||
def get_contact(self, contact_id):
|
def get_contact(self, contact_id, select=None):
|
||||||
return self.contacts.get(int(contact_id))
|
return self.contacts.get(int(contact_id))
|
||||||
|
|
||||||
def get_person(self, person_id):
|
def get_person(self, person_id, select=None):
|
||||||
return self.persons.get(int(person_id))
|
return self.persons.get(int(person_id))
|
||||||
|
|
||||||
def update_entity_udfs(self, entity_id, entity_type, udfs):
|
def update_entity_udfs(self, entity_id, entity_type, udfs):
|
||||||
@@ -152,7 +152,7 @@ class TestE2EFlow(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
db.add(matrix2)
|
db.add(matrix2)
|
||||||
|
|
||||||
mapping = JobRoleMapping(pattern="%Head of Operations%", role="Operativer Entscheider")
|
mapping = JobRolePattern(pattern_value="Head of Operations", role="Operativer Entscheider", pattern_type="exact")
|
||||||
db.add(mapping)
|
db.add(mapping)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ def process_job(job, so_client: SuperOfficeClient):
|
|||||||
# Fallback/Deep Lookup & Fetch JobTitle if missing
|
# Fallback/Deep Lookup & Fetch JobTitle if missing
|
||||||
if person_id:
|
if person_id:
|
||||||
try:
|
try:
|
||||||
person_details = so_client.get_person(person_id)
|
person_details = so_client.get_person(
|
||||||
|
person_id,
|
||||||
|
select=["JobTitle", "Title", "Contact/ContactId", "FirstName", "LastName", "UserDefinedFields", "Position"]
|
||||||
|
)
|
||||||
if person_details:
|
if person_details:
|
||||||
if not job_title:
|
if not job_title:
|
||||||
job_title = person_details.get("JobTitle") or person_details.get("Title")
|
job_title = person_details.get("JobTitle") or person_details.get("Title")
|
||||||
@@ -96,7 +99,7 @@ def process_job(job, so_client: SuperOfficeClient):
|
|||||||
if "contact" in event_low and not person_id:
|
if "contact" in event_low and not person_id:
|
||||||
logger.info(f"Company event detected. Triggering cascade for all persons of Contact {contact_id}.")
|
logger.info(f"Company event detected. Triggering cascade for all persons of Contact {contact_id}.")
|
||||||
try:
|
try:
|
||||||
persons = so_client.search(f"Person?$filter=contact/contactId eq {contact_id}")
|
persons = so_client.search(f"Person?$select=PersonId&$filter=contact/contactId eq {contact_id}")
|
||||||
if persons:
|
if persons:
|
||||||
q = JobQueue()
|
q = JobQueue()
|
||||||
for p in persons:
|
for p in persons:
|
||||||
@@ -114,7 +117,10 @@ def process_job(job, so_client: SuperOfficeClient):
|
|||||||
contact_details = None
|
contact_details = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
contact_details = so_client.get_contact(contact_id)
|
contact_details = so_client.get_contact(
|
||||||
|
contact_id,
|
||||||
|
select=["Name", "UrlAddress", "Urls", "UserDefinedFields", "Address", "OrgNr"]
|
||||||
|
)
|
||||||
if not contact_details:
|
if not contact_details:
|
||||||
raise ValueError(f"Contact {contact_id} not found (API returned None)")
|
raise ValueError(f"Contact {contact_id} not found (API returned None)")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user