use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class GenericWebAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof ICall || o instanceof ICaller) {
Properties configuration = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(this.getNamespace());
if (configuration != null) {
String url = configuration.getProperty("url");
if (url != null && url.trim().length() > 0) {
this.m_logger.info("Found valid web url to execute: " + url);
Formatter f = Formatter.getInstance(this.getRuntime());
url = f.parse(url, o);
this.m_logger.info("Parsed web url to execute: " + url);
Program.launch(url);
}
} else {
this.m_logger.warning("Found invalid configuration for namespace: " + this.getNamespace());
}
}
}
}
}
use of de.janrufmonitor.framework.ICaller 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.ICaller in project janrufmonitor by tbrandt77.
the class GoogleContactsProxy method deleteContacts.
public synchronized void deleteContacts(ICallerList cl) throws GoogleContactsException {
this.m_current = 0;
this.m_total = 0;
this.m_total = cl.size();
try {
fetchCategories();
} catch (IOException e) {
throw new GoogleContactsException(e.getMessage(), e);
} catch (ServiceException e) {
throw new GoogleContactsException(e.getMessage(), e);
}
ContactsService cs = login();
ICaller c = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
try {
if (c.getAttributes().contains("entryUrl")) {
String entryUrl = c.getAttribute("entryUrl").getValue();
if (entryUrl.length() > 0) {
ContactEntry entry = (ContactEntry) cs.getEntry(new URL(entryUrl), ContactEntry.class);
if (entry != null) {
this.m_logger.info("Deleting google contact: " + entry.getEtag());
entry.delete();
this.m_current++;
}
}
}
if (this.m_dbh != null) {
try {
this.m_dbh.delete(c.getUUID());
} catch (SQLException e) {
throw new GoogleContactsException(e.getMessage(), e);
}
} else {
this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
}
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
} catch (ServiceException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
}
}
use of de.janrufmonitor.framework.ICaller 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.ICaller in project janrufmonitor by tbrandt77.
the class HttpCallerManager method getCaller.
public ICaller getCaller(IPhonenumber number) throws CallerNotFoundException {
if (!this.isConnected()) {
this.m_logger.warning("Client is not yet connected with the server.");
throw new CallerNotFoundException("No caller found. Client is not yet connected with the server.");
}
IRequester r = this.getRequester(new CallerGetHandler(number, this.getCallerManager()));
IHttpResponse resp = r.request();
String xml = this.getXmlContent(resp);
this.handleRequester(resp, r);
ICaller c = XMLSerializer.toCaller(xml);
if (c != null) {
return c;
}
throw new CallerNotFoundException("no caller found.");
}
Aggregations