def _get_contact_info(self, value): """Return a sequence of dicts containing entity_contact_info entries for the specified contact value. We scan system_voip ONLY. value is matched both against contact_value and contact_alias. """ result = list() eci = EntityContactInfo(self.db) for row in eci.list_contact_info(source_system=self.const.system_voip, contact_value=value): result.append(row.dict()) for row in eci.list_contact_info(source_system=self.const.system_voip, contact_alias=value): result.append(row.dict()) return result
def _get_contact_info(self, value): """Return a sequence of dicts containing entity_contact_info entries for the specified contact value. We scan system_voip ONLY. value is matched both against contact_value and contact_alias. """ result = list() eci = EntityContactInfo(self.db) for row in eci.list_contact_info(source_system=self.const.system_voip, contact_value=str(value)): result.append(row.dict()) for row in eci.list_contact_info(source_system=self.const.system_voip, contact_alias=str(value)): result.append(row.dict()) return result
def list_voip_attributes(self, *args): """Return a generator over what looks like get_voip_attributes() return value. *args passes cached look ups from generate_voip_ldif.py to _cache_owner_person_attrs. This is a speed up function for LDAP export. The idea is to cache all the attributes up front, so we don't have to pay a penalty associated with multiple database lookups per voipAddress. """ # ou_id -> stedkode # Will pass it to the cache functions so we can get stedkode and not OUs back ou = Factory.get("OU")(self._db) ou2sko = dict( (x["ou_id"], "%02d%02d%02d" % (x["fakultet"], x["institutt"], x["avdeling"])) for x in ou.get_stedkoder()) owner_data = self._cache_owner_voip_service_attrs(ou2sko) owner_data.update(self._cache_owner_person_attrs(ou2sko, *args)) voipify = self._voipify voipify_short = self._voipify_short # owner_id -> sequence of contact info (value, alias)-pairs owner2contact_info = dict() eci = EntityContactInfo(self._db) for row in eci.list_contact_info(source_system=self.const.system_voip): owner_id = row["entity_id"] tpl = (row["contact_value"], row["contact_alias"]) owner2contact_info.setdefault(owner_id, list()).append(tpl) # owner_id -> mobile owner2mobiles = dict() for row in eci.list_contact_info( source_system=self.const.system_sap, contact_type=self.const.contact_mobile_phone, entity_type=self.const.entity_person): owner2mobiles.setdefault(row["entity_id"], list()).append(row["contact_value"]) for row in self.search(): entry = dict((key, None) for key in self._required_voip_attributes) entry["voipOwnerId"] = str(row["owner_entity_id"]) entry["voipSipUri"] = list() entry["entity_id"] = row["entity_id"] owner_id = row["owner_entity_id"] address_id = row["entity_id"] # Why this way? Well, if owner_data has required attributes and they # are missing, the LDAP import will fail (by design). We cannot # allow that, if the sole reason for missing entry is the fact that # owner_data cache dict is out of sync at this point (it takes a # while to construct that dict) if owner_id not in owner_data: continue entry.update(owner_data[owner_id]) # voipSipUri for item in owner2contact_info.get(owner_id, list()): full, alias = item entry["voipSipUri"].append(voipify(full)) if alias: entry["voipSipUri"].append(voipify_short(alias)) if entry["mail"]: value = self._voipify(entry["mail"], None) entry["voipSipPrimaryUri"] = value if entry["voipOwnerType"] != "person": entry["voipSipUri"].append(value) entry["mobile"] = owner2mobiles.get(owner_id, list()) # voipE164Uri + voipExtensionUri if owner2contact_info.get(owner_id): full, alias = owner2contact_info[owner_id][0] entry["voipE164Uri"] = voipify(full) if alias: entry["voipExtensionUri"] = voipify_short(alias) yield entry
def list_voip_attributes(self, *args): """Return a generator over what looks like get_voip_attributes() return value. *args passes cached look ups from generate_voip_ldif.py to _cache_owner_person_attrs. This is a speed up function for LDAP export. The idea is to cache all the attributes up front, so we don't have to pay a penalty associated with multiple database lookups per voipAddress. """ # ou_id -> stedkode # Will pass it to the cache functions so we can get stedkode and not OUs back ou = Factory.get("OU")(self._db) ou2sko = dict((x["ou_id"], "%02d%02d%02d" % (x["fakultet"], x["institutt"], x["avdeling"])) for x in ou.get_stedkoder()) owner_data = self._cache_owner_voip_service_attrs(ou2sko) owner_data.update(self._cache_owner_person_attrs(ou2sko, *args)) voipify = self._voipify voipify_short = self._voipify_short # owner_id -> sequence of contact info (value, alias)-pairs owner2contact_info = dict() eci = EntityContactInfo(self._db) for row in eci.list_contact_info(source_system=self.const.system_voip): owner_id = row["entity_id"] tpl = (row["contact_value"], row["contact_alias"]) owner2contact_info.setdefault(owner_id, list()).append(tpl) # owner_id -> mobile owner2mobiles = dict() for row in eci.list_contact_info( source_system=self.const.system_sap, contact_type=self.const.contact_mobile_phone, entity_type=self.const.entity_person): owner2mobiles.setdefault(row["entity_id"], list()).append( row["contact_value"]) for row in self.search(): entry = dict((key, None) for key in self._required_voip_attributes) entry["voipOwnerId"] = str(row["owner_entity_id"]) entry["voipSipUri"] = list() entry["entity_id"] = row["entity_id"] owner_id = row["owner_entity_id"] address_id = row["entity_id"] # Why this way? Well, if owner_data has required attributes and they # are missing, the LDAP import will fail (by design). We cannot # allow that, if the sole reason for missing entry is the fact that # owner_data cache dict is out of sync at this point (it takes a # while to construct that dict) if owner_id not in owner_data: continue entry.update(owner_data[owner_id]) # voipSipUri for item in owner2contact_info.get(owner_id, list()): full, alias = item entry["voipSipUri"].append(voipify(full)) if alias: entry["voipSipUri"].append(voipify_short(alias)) if entry["mail"]: value = self._voipify(entry["mail"], None) entry["voipSipPrimaryUri"] = value if entry["voipOwnerType"] != "person": entry["voipSipUri"].append(value) entry["mobile"] = owner2mobiles.get(owner_id, list()) # voipE164Uri + voipExtensionUri if owner2contact_info.get(owner_id): full, alias = owner2contact_info[owner_id][0] entry["voipE164Uri"] = voipify(full) if alias: entry["voipExtensionUri"] = voipify_short(alias) yield entry