use of de.janrufmonitor.framework.ICallerList 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;
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class MacAddressBookManager method getCallers.
public ICallerList getCallers(IFilter[] filters, ISearchTerm[] searchTerms) {
try {
String searchTerm = "";
if (searchTerms != null) {
for (int i = 0; i < searchTerms.length; i++) {
searchTerm += " " + searchTerms[i].getSearchTerm();
}
}
if (filters != null && filters[0] != null && searchTerm.trim().length() > 0) {
ICallerList cl = getRuntime().getCallerFactory().createCallerList();
cl.add(getProxy().findContacts(searchTerm.trim()));
this.applyFilters(cl, filters);
return cl;
}
if (searchTerm.trim().length() == 0)
return this.getCallers(filters);
return getProxy().findContacts(searchTerm.trim());
} catch (MacAddressBookProxyException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return getRuntime().getCallerFactory().createCallerList();
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class ThunderbirdTransformer method parseContacts.
private void parseContacts(ICallerList cl, List rawData) {
Map m = null;
ICallerList c = null;
for (int i = 0, j = rawData.size(); i < j; i++) {
m = (Map) rawData.get(i);
if (this.checkPhone(m)) {
c = parseMap(m);
if (c != null && c.size() > 0)
cl.add(c);
}
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class ThunderbirdTransformer method getCallers.
public ICallerList getCallers() {
ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
if (this.m_filename == null)
return cl;
File f = new File(this.m_filename);
if (!f.exists() || !f.isFile()) {
this.m_logger.warning("Mozilla Thunderbird file " + this.m_filename + " does not exists.");
PropagationFactory.getInstance().fire(new Message(Message.INFO, ThunderbirdCallerManager.NAMESPACE, "nofile", new Exception("Sync Mozilla Thunderbird Adressbook...")));
return cl;
}
if (this.m_sync)
PropagationFactory.getInstance().fire(new Message(Message.INFO, ThunderbirdCallerManager.NAMESPACE, "sync", new Exception("Sync Mozilla Thunderbird Adressbook...")));
try {
List rawData = new ArrayList();
FileInputStream fis = new FileInputStream(f);
MorkDocument md = new MorkDocument(new InputStreamReader(fis));
List l = md.getRows();
Row r = null;
for (int i = 0, j = l.size(); i < j; i++) {
r = (Row) l.get(i);
rawData.add(r.getAliases());
}
l = md.getTables();
Table t = null;
for (int i = 0, j = l.size(); i < j; i++) {
t = (Table) l.get(i);
for (int k = 0; k < t.getRows().size(); k++) {
r = (Row) t.getRows().get(k);
rawData.add(r.getAliases());
}
}
fis.close();
this.m_total = rawData.size();
if (rawData.size() > 0) {
this.m_logger.info("Found " + rawData.size() + " Mozilla Thunderbird contacts.");
this.parseContacts(cl, rawData);
}
} catch (FileNotFoundException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
this.m_logger.info(cl.size() + " contacts from Mozilla Thunderbird available.");
return cl;
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class ThunderbirdTransformer method parseMap.
private ICallerList parseMap(Map mx) {
this.m_current++;
Map m = new HashMap();
m.putAll(mx);
ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList(2);
ICaller c = null;
if (this.checkWork(m)) {
c = buildWorkContact(m);
if (c != null)
cl.add(c);
}
if (this.checkHome(m)) {
c = buildHomeContact(m);
if (c != null)
cl.add(c);
}
return cl;
}
Aggregations