Friday, February 12, 2010

Connect Google Calendar Data to ADF Faces Calendar Front End

Oracle ADF Faces has a calendar component. This blog post discusses how to attach an ADF Faces front end to the google calendar back end. I have written a demo which you can download and run, this demo has been tested in JDev 11.1.1.2.0.


In this blog


Before getting into the details, here's some images to give you an idea of what the demo does. First here's the google calendar:




And here's the running demo, which shows the google data with the adf faces front end:


Running the Demo

The demo was tested using Jdev 11.1.1.2.0

Proxy

If you have a proxy you will need to setup the proxy in jdev:

  • Go to Tools->Preferences
  • Click on "Web Browser and Proxy" on the left pane
  • Check "Use HTTP Proxy Server"
  • Add the host and port number and click ok

JCE

To get google calendar data you will need to upgrade to Java Cryptography Extension (JCE) Unlimited Strength. Without the upgrade I was getting an error like this: java.security.InvalidKeyException: Illegal key size

  • Download JCE Unlimited Strength for jdk 1.6
  • You will find local_policy.jar and US_export_policy.jar in the zip. Copy these two jars to your jdk directory.
    • $JDEV_HOME/jdk160_14_R27.6.5-32/jre/lib/security
    • Note that these jars will already be in the directory, but you should replace them.
    • Also note that when you unzip, the jars are in a directory 'jce', so if you blindly unzip into the jdk directory above, you will add a jce directory rather than replacing the jars, so try unzipping somewhere like the temp directory, and then copy the jars into the jdk directory above, replacing the jars that are already in there.

Getting the Google Jars


You will need some jars from google in order to run the demos. To get these jars go to the google download page and open gdata-src.java-[VERSION].zip. I used version 1.39.0, but the latest version should also work. From the zip get these jars
  • gdata-calendar-2.0.jar
  • gdata-client-1.0.jar
  • gdata-core-1.0.jar
  • google-collect-1.0-rc1.jar
  • jsr305.jar

Opening the Project

  • Download the workspace
  • Open JDeveloper 11.1.1.2.0
  • Go to File -> Open and select "ADFFacesGoogleCalendar.jws"
  • Under "Projects" double click on "Calendar" to open the project properties dialog. Go to "Libraries and Classpath" and click on "Add JAR/Directory", then add the google jars you downloaded in the previous section.
  • go to calendar.view.bean.calendar.Calendar.java and in the _initialize() method change the params "userName" and "userPassword" to the google calendar you want to to see.
  • right click on the "Calendar" project and choose "Rebuild Calendar.jpr"
  • go to calendar.jspx, right click, and choose run

Documentation Links


Here are the docs I used from Google:
.

Oracle ADF Faces Docs


API Overview


Generally speaking here's the mapping of Google api to ADF Faces api:

I'm not going to go into details about the demo, because the blog would be painfully long, but in the code you can look at GoogleCalendarActivity to see how to get and/or set the following information from a Google CalendarEventEntry object (some of these you can only get but not set, ran out of time).

  • time info (and handle timezone issues)
  • id
  • location
  • description
  • all day vs time based
  • readonly
  • recurring
  • reminders

And you can look at GoogleCalendarProvider, which contains a Google CalendarEntry object, for the following

  • getting events - see "Getting Events" section below for more about that
  • get calendar name
  • add and delete an activity
  • toggle showing the calendar on and off
  • change calendar colors

Google Issues


For the most part you can look at the code to see details of how the demo was implemented. However here are the things I wish Google would add or change about their documentation.

Need JCE


As discussed in the JCE section, without upgrading to Java Cryptography Extension (JCE) Unlimited Strength I was getting an error like this:
java.security.InvalidKeyException: Illegal key size

Maybe I missed it, but I didn't see any mention of this in the developer's guide nor on the getting started pages.

See JCE section on what to do if you see this.

Deleting Events


Initially I followed the developer's guide section on deleting events, and ran into this google issue, so just call delete on the CalendarEventEntry itself rather than following the developer guide.

Changing Providers


I couldn't find any doc on how to move an event from one calendar to the other. Maybe this is obvious to everyone else, but this actually took me a minute to figure out, so it would be nice if google could add doc about this. What I did was to take the event and
  • delete it from the current provider (under the covers this is calling delete() on the google CalendarEventEntry)
  • add it to the new provider (under the covers this is calling CalendarService.insert(_eventFeedUrl, calendarEventEntry))

Getting Events


The "Retrieving Events" of the Google Calendar Developer Guide tells you how to create an event feed url. Unfortunately, it only tells you how to do that for the main calendar, it does not tell you how to get the url for secondary calendars.

It doesn't seem possible that getting the event feed url for the calendar entry is this esoteric, but so far the way I've found to get the event feed url is to ask for the link of link relation type"http://schemas.google.com/gCal/2005#eventFeed"


Link eventFeedLink = calendarEntry.getLink("http://schemas.google.com/gCal/2005#eventFeed", null);
_eventFeedUrl = new URL(eventFeedLink.getHref());


The other way I could have created this is to parse the id of the calendar, so the calendar event feed url should be:

http://www.google.com/calendar/feeds/dtonb2emggsuv20o3j95bvup7s%40group.calendar.google.com/private/full


and the calendar id might be:

http://www.google.com/calendar/feeds/user.name%40gmail.com/calendars/dtonb2emggsuv20o3j95bvup7s%40group.calendar.google.com


so to create the event feed url take the id and remove the user name (in this case user.name%40gmail.com) and "/calendars/" from the middle, and then append "/private/full" to the end

If anyone knows an easier way please add a comment to this blog and let me know.