use of com.google.gdata.data.contacts.ContactFeed in project jitsi by jitsi.
the class GoogleContactsServiceImpl method searchContact.
/**
* Perform a search for a contact using regular expression.
*
* @param cnx <tt>GoogleContactsConnection</tt> to perform the query
* @param gQuery Google query
* @param count maximum number of matched contacts
* @param callback object that will be notified for each new
* <tt>GoogleContactsEntry</tt> found
* @return list of <tt>GoogleContactsEntry</tt>
*/
public List<GoogleContactsEntry> searchContact(GoogleContactsConnection cnx, GoogleQuery gQuery, int count, GoogleEntryCallback callback) {
URL url = null;
ContactFeed contactFeed = null;
ContactQuery query = null;
List<GoogleContactsEntry> ret = new ArrayList<GoogleContactsEntry>();
boolean endOfContacts = false;
int matchedContacts = 0;
int index = 1;
GoogleContactsConnectionImpl cnxImpl = (GoogleContactsConnectionImpl) cnx;
if (count <= 0) {
count = MAX_RESULT;
}
try {
url = new URL(feedURL);
} catch (MalformedURLException e) {
logger.info("Malformed URL", e);
return ret;
}
if (gQuery.isCancelled()) {
return ret;
}
while (matchedContacts < count || endOfContacts) {
query = new ContactQuery(url);
query.setStartIndex(index);
query.setMaxResults(MAX_NUMBER);
query.setSortOrder(ContactQuery.SortOrder.DESCENDING);
if (gQuery.isCancelled()) {
return ret;
}
try {
contactFeed = cnxImpl.query(query);
} catch (Exception e) {
logger.warn("Problem occurred during Google Contacts query", e);
return ret;
}
if (contactFeed.getEntries().size() == 0) {
endOfContacts = true;
break;
}
for (int i = 0; i < contactFeed.getEntries().size(); i++) {
if (gQuery.isCancelled()) {
return ret;
}
ContactEntry entry = contactFeed.getEntries().get(i);
if (filter(entry, gQuery.getQueryPattern())) {
GoogleContactsEntry gcEntry = null;
gcEntry = getGoogleContactsEntry(entry);
matchedContacts++;
ret.add(gcEntry);
if (callback != null) {
callback.callback(gcEntry);
}
if (matchedContacts >= count) {
break;
}
}
}
index += contactFeed.getEntries().size();
}
return ret;
}
use of com.google.gdata.data.contacts.ContactFeed 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 com.google.gdata.data.contacts.ContactFeed in project janrufmonitor by tbrandt77.
the class GoogleContactsProxy method preload.
public void preload() throws GoogleContactsException {
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());
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());
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);
}
}
}
} 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 {
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;
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();
this.m_dbh.delete(c.getUUID());
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
}
this.m_dbh.commit();
} catch (SQLException e) {
throw new GoogleContactsException(e.getMessage(), e);
}
} else {
this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
}
}
Aggregations