use of de.janrufmonitor.framework.IPhonenumber 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.IPhonenumber in project janrufmonitor by tbrandt77.
the class GoogleContactsProxy method parse.
private synchronized ICaller parse(ContactsService cs, ContactEntry e) {
if (e == null)
return null;
if (e.getPhoneNumbers().size() == 0)
return null;
String uuid = parseUUID(e);
IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
m.addAll(parseName(e));
if (e.hasStructuredPostalAddresses()) {
StructuredPostalAddress pa = (StructuredPostalAddress) e.getStructuredPostalAddresses().get(0);
m.addAll(parseAddress(pa));
}
// 2012/10/20: added email support
if (e.hasEmailAddresses()) {
List emaillist = e.getEmailAddresses();
if (emaillist.size() > 0) {
Email email = (Email) emaillist.get(0);
m.add(parseEmail(email));
}
}
List gphones = e.getPhoneNumbers();
List pl = new ArrayList(gphones.size());
PhoneNumber p = null;
IPhonenumber pn = null;
for (int i = 0, j = gphones.size(); i < j; i++) {
p = (PhoneNumber) gphones.get(i);
pn = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(p.getPhoneNumber());
if (pn != null) {
pl.add(pn);
m.add(parseNumberType(pn, p));
}
}
if (pl.size() == 0)
return null;
if (e.getExtendedProperties() != null) {
ExtendedProperty exp = null;
for (int i = 0, j = e.getExtendedProperties().size(); i < j; i++) {
exp = (ExtendedProperty) e.getExtendedProperties().get(i);
if (exp.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) && exp.getValue().length() > 0) {
m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, exp.getValue()));
}
if (exp.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) && exp.getValue().length() > 0) {
m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, exp.getValue()));
}
if (exp.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) && exp.getValue().length() > 0) {
m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, exp.getValue()));
}
}
}
m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, GoogleContactsCallerManager.ID));
m.add(getRuntime().getCallerFactory().createAttribute("entryUrl", e.getSelfLink().getHref()));
IAttribute a = parseCategory(e);
if (a != null)
m.add(a);
try {
a = parseImage(cs, e);
if (a != null) {
m.add(a);
}
} catch (GoogleContactsException ex) {
this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
}
return getRuntime().getCallerFactory().createCaller(uuid, null, pl, m);
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class ClientClickDialAction 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 = ((ICall) o).getCaller();
}
if (o instanceof ICaller) {
o = ((ICaller) o).getPhoneNumber();
}
if (o instanceof ITreeItemCallerData) {
o = ((ITreeItemCallerData) o).getPhone();
}
if (o instanceof IPhonenumber) {
if (((IPhonenumber) o).isClired())
return;
String dial = ((IPhonenumber) o).getTelephoneNumber();
if (PhonenumberAnalyzer.getInstance(getRuntime()).isInternal((IPhonenumber) o)) {
dial = ((IPhonenumber) o).getCallNumber();
} else {
if (!((IPhonenumber) o).getIntAreaCode().equalsIgnoreCase(this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA))) {
dial = "00" + ((IPhonenumber) o).getIntAreaCode() + dial;
}
if (!dial.startsWith("0"))
dial = "0" + dial;
}
ClientDialerDialog id = new ClientDialerDialog(new Shell(DisplayManager.getDefaultDisplay()), dial);
id.open();
this.m_app.updateViews(false);
}
}
}
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class IncomingCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
IPhonenumber pn = null;
try {
String phone = req.getParameter(IncomingCall.PARAMETER_NUMBER);
if (phone == null || phone.length() == 0)
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
else
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(IncomingCall.PARAMETER_CIP), "");
IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(IncomingCall.PARAMETER_MSN), "");
Date date = new Date(Long.parseLong(req.getParameter(IncomingCall.PARAMETER_DATE)));
ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class LastCalled method renderAsText.
public String renderAsText() {
if (this.m_o != null) {
if (this.m_o instanceof ICaller) {
this.m_o = new TreeItemCallerData(((ICaller) this.m_o).getAttributes(), ((ICaller) this.m_o).getPhoneNumber());
}
if (this.m_o instanceof ITreeItemCallerData) {
IPhonenumber pn = ((ITreeItemCallerData) m_o).getPhone();
List cms = PIMRuntime.getInstance().getCallManagerFactory().getTypedCallManagers(IReadCallRepository.class);
if (cms.size() > 0) {
ICallManager cm = null;
for (int i = 0, j = cms.size(); i < j; i++) {
cm = (ICallManager) cms.get(i);
if (cm.isActive() && cm.isSupported(IReadCallRepository.class)) {
IFilter[] filters = new IFilter[] { new PhonenumberFilter(pn), new ItemCountFilter(1) };
ICallList cl = ((IReadCallRepository) cm).getCalls(filters, 1, 0);
cl.sort(0, false);
if (cl.size() > 0) {
ICall c = cl.get(0);
return getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate());
}
}
}
}
}
}
return "";
}
Aggregations