diff --git a/connector-superoffice/superoffice_client.py b/connector-superoffice/superoffice_client.py index b4c537b0..3844491e 100644 --- a/connector-superoffice/superoffice_client.py +++ b/connector-superoffice/superoffice_client.py @@ -114,11 +114,17 @@ class SuperOfficeClient: # --- Convenience Wrappers --- - def get_person(self, person_id): - return self._get(f"Person/{person_id}") + def get_person(self, person_id, select: list = None): + endpoint = f"Person/{person_id}" + if select: + endpoint += f"?$select={','.join(select)}" + return self._get(endpoint) - def get_contact(self, contact_id): - return self._get(f"Contact/{contact_id}") + def get_contact(self, contact_id, select: list = None): + endpoint = f"Contact/{contact_id}" + if select: + endpoint += f"?$select={','.join(select)}" + return self._get(endpoint) def search(self, query_string: str): """ diff --git a/connector-superoffice/tests/test_e2e_flow.py b/connector-superoffice/tests/test_e2e_flow.py index a2c00f19..b856f729 100644 --- a/connector-superoffice/tests/test_e2e_flow.py +++ b/connector-superoffice/tests/test_e2e_flow.py @@ -20,12 +20,12 @@ sys.path.append(connector_dir) # Note: backend.app needs to be importable. If backend is a package. try: 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: # Try alternate import if running from root sys.path.append(os.path.abspath("company-explorer")) 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 from worker import process_job @@ -56,10 +56,10 @@ class MockSuperOfficeClient: self.contacts = {} # 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)) - def get_person(self, person_id): + def get_person(self, person_id, select=None): return self.persons.get(int(person_id)) def update_entity_udfs(self, entity_id, entity_type, udfs): @@ -152,7 +152,7 @@ class TestE2EFlow(unittest.TestCase): ) 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.commit() diff --git a/connector-superoffice/worker.py b/connector-superoffice/worker.py index a8614f54..bd1b21c1 100644 --- a/connector-superoffice/worker.py +++ b/connector-superoffice/worker.py @@ -43,7 +43,10 @@ def process_job(job, so_client: SuperOfficeClient): # Fallback/Deep Lookup & Fetch JobTitle if missing if person_id: 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 not job_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: logger.info(f"Company event detected. Triggering cascade for all persons of Contact {contact_id}.") 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: q = JobQueue() for p in persons: @@ -114,7 +117,10 @@ def process_job(job, so_client: SuperOfficeClient): contact_details = None 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: raise ValueError(f"Contact {contact_id} not found (API returned None)")