Tuesday, March 1, 2011

RequestFactory and GData glue

Hi,

I am working on a GWT 2.2 application and the server side connects to the GData Contacts Feed.

First implementation  was sending wrapped GData contacts as ValueProxy over to the client.

Coming to the think about it, a GData ContactEntry is actually an entity, but not the typical database entity.
So it would be great to work on a contact list with RequestFactory and eventbus dispatchen updates to the editors and managing a cache.

So I implemented a Locator for a ContactEntry :

public class ContactLocator extends Locator<ContactEntry, String> {
@Override
public ContactEntry create(Class<? extends ContactEntry> clazz) {
ContactEntry contactEntry = null;
try {
contactEntry = new ContactEntry();
Name name = new Name();
contactEntry.setName(name);
// Ask the service to insert the new entry
URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/default/id/" + contactEntry.getId());
contactEntry = ContactsServiceImpl.getContactsService().insert(postUrl, contactEntry);
} catch (Exception e) {
// TODO: deal with this;
}
return new ContactEntry(contactEntry);
}

@Override
public ContactEntry find(Class<? extends ContactEntry> clazz, String id) {
ContactEntry contactEntry = null;
try {
// Build the GData URL for the contact entry and retrieve;
contactEntry = ContactsServiceImpl.getContactsService().getEntry(
new URL(id), ContactEntry.class);
} catch (Exception e) {
// TODO: deal with this;
}
return contactEntry;
}

@Override
public Class<ContactEntry> getDomainType() {
return ContactEntry.class;
}

@Override
public String getId(ContactEntry contactEntry) {
String ret = null;
if (contactEntry != null) {
ret = contactEntry.getEditLink().getHref();
}
return ret;
}

@Override
public Class<String> getIdType() {
return String.class;
}

@Override
public Long getVersion(ContactEntry contactEntry) {
if (contactEntry != null) {
return contactEntry.getUpdated().getValue();
} else {
return null;
}
}
}


I setup ContactProxy as EntityProxy for GDATA ContactEntry

@ProxyForName(value = "com.google.gdata.data.contacts.ContactEntry", locator = "com.example.domain.ContactLocator")
public interface ContactProxy extends EntityProxy {
NameProxy getName();
List<EmailProxy> getEmailAddresses();
}


NameProxy and EmailProxy are ValueProxies mapping the properties from the respective Name and Email extension in GData.

One question, one problem :

PROBLEM :
- I make a service call to query for all contacts. The list with contact proxies is correctly returned to the client. But all value proxies (getName, getEmailAddresses) are NULL, so I can't access the information. 
QUESTION 
- After the query for all contacts, the locator find by Id methods are called for each ContactEntry. This seems like a lot of overkill - why does it do so ?

Maybe my approach is total overkill, don't hesitate to question it;


cheers,

Koen



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment