use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class GoogleContactsProxy method getContacts.
public synchronized ICallerList getContacts(String category) throws GoogleContactsException {
this.m_current = 0;
this.m_total = 0;
try {
fetchCategories();
} catch (IOException e) {
throw new GoogleContactsException(e.getMessage(), e);
} catch (ServiceException e) {
throw new GoogleContactsException(e.getMessage(), e);
}
ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
if (category != null && !this.m_reverseCategories.containsKey(category))
return cl;
ContactsService cs = login();
try {
URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/" + getLoginUser() + "/full");
Query q = new Query(feedUrl);
q.setMaxResults(getMaxResults());
if (category != null)
q.setStringCustomParameter("group", (String) this.m_reverseCategories.get(category));
ContactFeed resultFeed = (ContactFeed) cs.getFeed(q, ContactFeed.class);
List entries = resultFeed.getEntries();
this.m_total = entries.size();
this.m_logger.info("Fetched " + entries.size() + " entries from google account " + getLoginUser());
Object o = null;
for (int i = 0, j = entries.size(); i < j; i++) {
o = entries.get(i);
if (o instanceof ContactEntry) {
// && (category==null || matchCategory(category, (ContactEntry) o))) {
ICaller c = this.parse(cs, (ContactEntry) o);
if (c != null) {
cl.add(c);
this.m_current++;
}
}
}
} catch (MalformedURLException e) {
throw new GoogleContactsException(e.getMessage(), e);
} catch (IOException e) {
throw new GoogleContactsException(e.getMessage(), e);
} catch (ServiceException e) {
throw new GoogleContactsException(e.getMessage(), e);
}
//
if (this.m_dbh != null) {
try {
if (category == null)
this.m_dbh.deleteAll();
ICaller c = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
if (c instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
IPhonenumber pn = null;
if (category != null)
this.m_dbh.delete(c.getUUID());
for (int k = 0; k < phones.size(); k++) {
pn = (IPhonenumber) phones.get(k);
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
} else {
IPhonenumber pn = c.getPhoneNumber();
if (category != null)
this.m_dbh.delete(c.getUUID());
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
}
} catch (SQLException e) {
throw new GoogleContactsException(e.getMessage(), e);
}
} else {
this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
}
return cl;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class GoogleContactsProxy method identify.
public synchronized ICaller identify(IPhonenumber pn) throws GoogleContactsException {
ICaller c = Identifier.identifyDefault(getRuntime(), pn);
if (c != null) {
pn = c.getPhoneNumber();
try {
List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("List of found UUIDs: " + uuids);
}
if (uuids.size() > 0) {
String uuid = null;
ICaller contact = null;
for (int k = 0; k < uuids.size(); k++) {
uuid = (String) uuids.get(k);
try {
contact = this.identifyByUUID(uuid);
if (contact != null) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Google contact found for UUID: " + uuid);
}
contact.setUUID(new UUID().toString());
if (contact instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) contact).getPhonenumbers().clear();
}
contact.setPhoneNumber(pn);
contact.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber()));
return contact;
}
} catch (GoogleContactsException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
} else {
Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(GoogleContactsCallerManager.NAMESPACE);
if (config.getProperty(CFG_GOOGLE_KEEPEXT, "false").equalsIgnoreCase("true")) {
// iterate down
String callnumber = pn.getCallNumber();
if (callnumber.length() > 1) {
pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
ICaller ca = this.identify(pn);
if (ca != null) {
pn.setCallNumber(callnumber);
if (ca instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) ca).getPhonenumbers().clear();
}
ca.setPhoneNumber(pn);
// set extension
if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
if (pn.getTelephoneNumber().length() > centralnumber.length()) {
IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
ca.setAttribute(att);
}
}
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Caller match by central number: " + ca.toString());
}
return ca;
}
}
}
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
}
this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
return null;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class MacAddressBookProxy method getContactsByAreaCode.
@SuppressWarnings("unchecked")
public synchronized ICallerList getContactsByAreaCode(String countrycode, String areacode) throws MacAddressBookProxyException {
this.m_total = 0;
this.m_current = 0;
final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
if (this.m_dbh != null) {
try {
List uuids = this.m_dbh.select(countrycode, areacode);
if (uuids.size() > 0) {
List contacts = getRecordsByUIDs(uuids);
if (contacts.size() > 0) {
this.m_total = contacts.size();
ICaller businessCaller, privateCaller = null;
for (Object contact : contacts) {
if (contact instanceof Map<?, ?>) {
this.m_current++;
privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
if (privateCaller == null && businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
callers.add(businessCaller);
}
if (privateCaller != null && businessCaller == null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
callers.add(privateCaller);
}
if (privateCaller != null && businessCaller != null) {
if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
// only one entry available
IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
businessCaller = null;
}
}
if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
// only one entry available
IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
privateCaller = null;
}
}
if (privateCaller != null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
callers.add(privateCaller);
}
if (businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
callers.add(businessCaller);
}
}
}
}
}
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
if (callers.size() > 0) {
Thread updateDbhThread = new Thread() {
public void run() {
updateProxyDatabase(callers);
}
};
updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
updateDbhThread.start();
}
return callers;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class LdapContactsProxy method identify.
public synchronized ICaller identify(IPhonenumber pn) throws LdapContactsException {
ICaller c = Identifier.identifyDefault(getRuntime(), pn);
if (c == null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
c = getRuntime().getCallerFactory().createCaller(p);
}
if (c != null) {
pn = c.getPhoneNumber();
try {
List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("List of found UUIDs: " + uuids);
}
if (uuids.size() > 0) {
String uuid = null;
ICaller contact = null;
for (int k = 0; k < uuids.size(); k++) {
uuid = (String) uuids.get(k);
try {
contact = this.identifyByUUID(uuid);
if (contact != null) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("LDAP contact found for UUID: " + uuid);
}
contact.setUUID(new UUID().toString());
if (contact instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) contact).getPhonenumbers().clear();
}
contact.setPhoneNumber(pn);
contact.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber()));
return contact;
}
} catch (LdapContactsException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
} else {
Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(LdapRepository.NAMESPACE);
if (config.getProperty(CFG_LDAP_KEEPEXT, "false").equalsIgnoreCase("true")) {
// iterate down
String callnumber = pn.getCallNumber();
if (callnumber.length() > 1) {
pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
ICaller ca = this.identify(pn);
if (ca != null) {
pn.setCallNumber(callnumber);
if (ca instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) ca).getPhonenumbers().clear();
}
ca.setPhoneNumber(pn);
// set extension
if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
if (pn.getTelephoneNumber().length() > centralnumber.length()) {
IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
ca.setAttribute(att);
}
}
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Caller match by central number: " + ca.toString());
}
return ca;
}
}
}
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
}
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
return null;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class LdapContactsProxy method getContacts.
public synchronized ICallerList getContacts(String category) throws LdapContactsException {
ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
String query = "(objectclass=*)";
if (category != null) {
String ldapAttrib = LdapMappingManager.getInstance().getLdapAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
if (ldapAttrib != null && ldapAttrib.trim().length() > 0) {
query = "(" + ldapAttrib + "=" + category + ")";
}
}
LDAPConnection lc = new LDAPConnection();
try {
lc.connect(getServer(), getPort());
lc.bind(LDAPConnection.LDAP_V3, getLoginUser(), getLoginPassword().getBytes("UTF-8"));
LDAPSearchConstraints cons = lc.getSearchConstraints();
cons.setMaxResults(getMaxResults());
String baseDN = this.getBaseDN();
String[] bases = null;
if (baseDN.indexOf("|") > 0) {
bases = baseDN.split("\\|");
} else {
bases = new String[] { baseDN };
}
for (int i = 0; i < bases.length; i++) {
LDAPSearchResults searchResults = lc.search(bases[i], getScope(), query, // return all attributes
null, // return attrs and values
false, cons);
ICaller c = null;
while (searchResults.hasMore()) {
LDAPEntry nextEntry = null;
try {
nextEntry = searchResults.next();
} catch (LDAPException e) {
if (e.getResultCode() == LDAPException.LDAP_TIMEOUT || e.getResultCode() == LDAPException.CONNECT_ERROR)
break;
else
continue;
}
c = LdapMappingManager.getInstance().mapToJamCaller(nextEntry);
if (c != null) {
cl.add(c);
}
}
}
// disconnect from the server
lc.disconnect();
LdapMappingManager.invalidate();
} catch (LDAPException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
throw new LdapContactsException(e.toString(), e);
} catch (UnsupportedEncodingException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
if (this.m_dbh != null) {
try {
this.m_dbh.deleteAll();
ICaller c = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
if (c instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
IPhonenumber pn = null;
for (int k = 0; k < phones.size(); k++) {
pn = (IPhonenumber) phones.get(k);
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
} else {
IPhonenumber pn = c.getPhoneNumber();
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
}
} catch (SQLException e) {
throw new LdapContactsException(e.getMessage(), e);
}
} else {
this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
}
return cl;
}
Aggregations