use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class GoogleContactsCallerManager method setCaller.
public void setCaller(ICaller caller) {
ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
this.addCreationAttributes(caller);
this.addSystemAttributes(caller);
cl.add(caller);
this.setCaller(cl);
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class GoogleContactsCallerManager method getCallers.
public ICallerList getCallers(IFilter filter) {
try {
if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
return getProxy().getContacts(a.getValue());
}
}
if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
ICallerList cl = getProxy().getContacts(null);
this.applyFilters(cl, new IFilter[] { filter });
return cl;
}
return getProxy().getContacts(null);
} catch (GoogleContactsException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "loginerror", e));
}
return getRuntime().getCallerFactory().createCallerList();
}
use of de.janrufmonitor.framework.ICallerList 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.ICallerList in project janrufmonitor by tbrandt77.
the class HttpCallerManager method removeCaller.
public void removeCaller(ICaller caller) {
ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
cl.add(caller);
this.removeCaller(cl);
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class HttpCallerManager method getCallers.
public ICallerList getCallers(IFilter filter) {
if (!this.isConnected()) {
this.m_logger.warning("Client is not yet connected with the server.");
return this.getRuntime().getCallerFactory().createCallerList();
}
if (filter != null) {
return this.getCallers(new IFilter[] { filter });
}
this.m_logger.info("No filter is applied.");
IRequester r = this.getRequester(new CallerListGetHandler(this.getCallerManager()));
IHttpResponse resp = r.request();
String xml = this.getXmlContent(resp);
this.handleRequester(resp, r);
ICallerList l = XMLSerializer.toCallerList(xml);
if (l != null) {
this.addCallerManagerAttribute(l);
return l;
}
this.m_logger.warning("Callerlist from remote host was empty.");
return this.getRuntime().getCallerFactory().createCallerList();
}
Aggregations