def get_contacts(self, entity_id=None, contact_type=None, source_system=None, convert=None, verify=None, normalize=None): # Return a list of contact values for the specified parameters, # or if entity_id is None, a dict {entity_id: [contact values]}. entity = Entity.EntityContactInfo(self.db) cont_tab = {} if not convert: convert = str for row in entity.list_contact_info(entity_id=entity_id, source_system=source_system, contact_type=contact_type): c_list = [convert(str(row['contact_value']))] if '$' in c_list[0]: c_list = c_list[0].split('$') elif normalize == normalize_phone and '/' in c_list[0]: c_list = c_list[0].split('/') key = int(row['entity_id']) if cont_tab.has_key(key): cont_tab[key].extend(c_list) else: cont_tab[key] = c_list for key, c_list in cont_tab.iteritems(): cont_tab[key] = self.attr_unique(filter( verify, [c for c in c_list if c not in ('', '0')]), normalize=normalize) if entity_id is None: return cont_tab else: return (cont_tab.values() or ((), ))[0]
def person_authn_methods(self): """ Returns a contact info mapping for update_person_authn. Initializes self.person_authn_methods with a dict that maps person entity_id to a list of dicts with contact info: person_id: [ {'contact_type': <const>, 'source_system': <const>, 'value': <str>, }, ... ], ... """ if not hasattr(self, '_person_authn_methods'): timer = make_timer(self.logger, 'Fetching authentication methods...') entity = Entity.EntityContactInfo(self.db) self._person_authn_methods = dict() # Find the unique systems and contact types for filtering source_systems = set( (v[0] for s in self.person_authn_selection.itervalues() for v in s)) contact_types = set( (v[1] for s in self.person_authn_selection.itervalues() for v in s)) if not source_systems or not contact_types: # No authn methods to cache return self._person_authn_methods # Cache contact info count = 0 for row in entity.list_contact_info( entity_type=self.const.entity_person, source_system=list(source_systems), contact_type=list(contact_types)): c_type = self.const.ContactInfo(row['contact_type']) system = self.const.AuthoritativeSystem(row['source_system']) self._person_authn_methods.setdefault(int( row['entity_id']), list()).append({ 'value': six.text_type(row['contact_value']), 'contact_type': c_type, 'source_system': system, }) count += 1 timer("...authentication methods done.") return self._person_authn_methods
def get_contact_aliases(self, contact_type=None, source_system=None, convert=None, verify=None, normalize=None): """Return a dict {entity_id: [list of contact aliases]}.""" # The code mimics a reduced modules/OrgLDIF.py:get_contacts(). entity = Entity.EntityContactInfo(self.db) cont_tab = defaultdict(list) if not convert: convert = str if not verify: verify = bool for row in entity.list_contact_info(source_system=source_system, contact_type=contact_type): alias = convert(str(row['contact_alias'])) if alias and verify(alias): cont_tab[int(row['entity_id'])].append(alias) return dict((key, self.attr_unique(values, normalize=normalize)) for key, values in cont_tab.iteritems())