Tuesday, October 11, 2011

Google Apps Integration and App Engine's namespaces

I have integrated our GAE app with Google Apps Marketplace. I set the namespace strategy to GOOGLE_APPS_DOMAIN so that each Google Apps domain will have it's own isolated dataset.

When I enter the app from the app's login page by entering Google App's email id and password, everything works fine. Namespace is being set to the domain name. However, when I enter the app from Google Apps universal navigation link, Namespace is being set to blank instead of the domain name. After a quick troubleshooting session, I found that NamespaceManager.getGoogleAppsNamespace(). method is not returning the domain name when the app is accessed from the universal navigation bar.

After some delving into App Engine's API source code, I came up with a workaround that I can use until I find the root cause of why the original approach didn't work.


case GOOGLE_APPS_DOMAIN: {

/*
* Original code. Commented out because getGoogleAppsNamespace
* not returning the apps domain name. Unable to find out the
* reason
*/

// NamespaceManager.set(NamespaceManager.getGoogleAppsNamespace());



if (NamespaceManager.getGoogleAppsNamespace().equals("")) {

Object userOrganizationObject;
String userOrganization;

userOrganizationObject = com.google.apphosting.api.ApiProxy
.getCurrentEnvironment()
.getAttributes()
.get("com.google.appengine.api.users.UserService.user_organization");

if (userOrganizationObject == null) {
userOrganization = "";
} else {
userOrganization = userOrganizationObject.toString();
}

NamespaceManager.set(userOrganization);

} else {

NamespaceManager.set(NamespaceManager
.getGoogleAppsNamespace());
}

break;
}


Thursday, April 28, 2011

Using Google Refine and Google Maps API to calculate distance between two addresses


Distance Calculation Using Refine and Google Maps API:

·         Create two columns
o   Origin – origin address (address can be anything – complete address, just city, start, zip, country or any combination of tose]
o   Destination – destination address
·         Create a new column “distance api response” based on Origin column using the url option

Copy this in expression field show below [if you use the column names Origin and Destination, you don’t have to change anything in this formula]
"http://maps.googleapis.com/maps/api/directions/json?origin="+escape(value, "url")+"&destination="+escape(cells["Destination"].value, "url")+"&sensor=false"



        
               
·         Create a new column called “distance” – create it based on “distance api response” column and use the following formula in the expression
with(value.parseJson().routes[0].legs[0].distance,pair,pair.text)

Monday, April 18, 2011

How to get GWT DateBox to show only the date part

While searching for tips on this, I found this useful blog post.
The only change i made is I replaced the deprecated function
getShortDateFormat with getFormat method from DateTimeFormat class.

With deprecated method:
So to format a DateBox to display a date like 06/26/2009
dateBox = new DateBox();
dateBox.setFormat(
new DateBox.DefaultFormat(
DateTimeFormat.getShortDateFormat()));

With new method:
fromDate = new DateBox()
fromDate.setFormat(
new DateBox.DefaultFormat(
DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));

Saturday, April 16, 2011

Date Operations in GWT

Standard java class java.util.Calendar does not work in GWT. Instead, use GWT class com.google.gwt.user.datepicker.client.CalendarUtil.



Similarly, for formatting and parsing date/time, use com.google.gwt.i18n.client.DateTimeFormat


Convert Date to String - Format

DateTimeFormat.PredefinedFormat.DATE_SHORT).format(newDate())



Convert String to Date - Parse

DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT).parse(dateString)










Saturday, March 26, 2011

Data Nucleus Enhancer Errors

It appears like there is a limit on how many classes can be enhanced in google app engine projects on eclipse. If there are too many classes, you get the following error ("CreateProcess error=87, The parameter is incorrect") at the build time and some classes do not get enhanced. 




If you try to use the application, you get errors that look like the following:



[ERROR] Excepton in class: javax.jdo.JDOUserException
[ERROR] Persistent class "Class so&so does not seem to have been enhanced.  You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.

How to fix?
In reality, all classes do not need to be enhanced. You can restrict it to a limited set of classes by changing ORM settings under App Engine settings in Eclipse




Friday, March 11, 2011

SuggestBox with UIBinder

Using SuggestBox with in UIBinder is not straighforward. This article explains how to do it.

Monday, February 14, 2011

Download and Upload bulk data to Google App Engine

The bulk loader tool can upload and download data to and from Google App Engine's datastore. This pdf document has step by step instructions.