Monday, September 27, 2010

Playing around with Funambol web demo app

I was involved working with asset management database for the first 2 weeks and it was very educational. I was given a lookup feature to be included in the database front end which I completed in 1 week. I also tested the same by adding up more than 40 devices into the database through the lookup feature. I hope my lead was impressed by this feat. He seemed satisfied. When delivering him the final package I asked if he wants me to look into something else. There was not much to do in the database part so he included me into the blackberry apps group which is also handled by him.
It was then that I came to know about Funambol, my first assignment.
Funambol is an open source mobile sync feature for various mobile devices. The concept is simple. Users can download and install it in their mobile. Then specify the email address from which you want to sync your device with. If I give my yahoo mail address, it copies the contacts, calender etc from that account and the Funambol-Email will also display(sync) the inbox into your device. This helps people access their account on the go. Just open the application, choose the server sync option, when its done, you can see the new changes (if any) like new mails, new tasks etc that has been added into your email account. Through Funambol you can also set new task, contact, send email to others, upload pictures into facebook on the go etc.
How does it work? I haven't researched it well but I believe the funambol data server communicates with regularly with your yahoo account and stores the email, contacts etc from their and when u select the device sync option, it actually loads data from the funambol server. The same happens when you want something to go out from your device, like uploading a picture.
More detail information can be found at Funambol site, http://www.funambol.com/
I installed the funambol data server application (free!). Through this you can make your own PC act as the Funambol data server, and the device will contact your PC for updates. Once it is installed, start the funambol data server (start->all programs->funambol->funambol data server->start server). It will take some time to be up. The open the browser and type http://localhost:8080/funambol/ds and you can see the web demo client. By default the admin username is included (username: admin password: sa). You can also open the funambol administration tool. Play around with funambol for a while. Get yourself comfortable about its working. The settings for web demo is in the C:\Program Files\Funambol\tools\tomcat\conf\server.xml file. You can change the default port 8080 to something else like 8181, which I did. The documentatio for funambol can be downloaded from this site, https://www.forge.funambol.org/download/documentation.html#runserver

My Task: When we login into the web demo client (say using admin account), and create a new account, the common fields are First Name, Last Name etc. What if I want to add more fields like (Nickname) on top of the exisiting ones. This is necessary because in a blackberry when we create a new account, we have all sorts of extra fields and we need to map Funambol's server contact fields with BlackBerry's so that when sync-ing, all fields in BB gets populated. Investigate.


Initial Approach: I could see that the web demo client front end is bunch of jsp pages. When I populate the contact fields and click Add, some jsp page is called passing the values. The jsp pages are in C:\Program Files\Funambol\tools\tomcat\webapps\webdemo and main.jsp, add.jsp, view.jsp and list.jsp handles the contact part. Looking into the source code isn't much of a help. But I know that parameters are being sent/received from somewhere, parameters like operation=ADD, type=contact etc.
Next approach is to find the source code. Browsing in the Funambol folder, there is no .java files, only .class files (in C:\Program Files\Funambol\tools\tomcat\webapps\webdemo\WEB-INF\classes). If its open source application, where is it?
As it turns out, the source code doesn't come with the installation package. One can download the source code separately, modify, rebuild the package the replace the .class files with the one thats in the installation package and you get your new modified funambol.
Okay. Next thing to do is download the source code, from https://core.forge.funambol.org/source/browse/core/ using the command "svn checkout https://core.forge.funambol.org/svn/core/trunk encore --username kundan " in the command prompt(win)/terminal(linux). I recommend one should register at the funambol site. One can also use the anonymous username (no password) to download the source. This will copy the source code into the encore folder. Next step, how to build it?
I followed the instruction mentioned in https://core.forge.funambol.org/wiki/BuildingFunambolV8?highlight=%28CategoryDeveloper%29 to build the whole funambol bundle. I did all the package settings as it asked me to. Building the whole package is a feat in itself. When I tried "ant forge-bundle-win", I faced lots of errors. These may arise because of fault in settings etc. Bottom line is, debugging the build error is out of my reach.

On further reading the how to build wiki page(above), I could see that we can build individual sections separately. I am concerned with webdemo part only, why not build webdemo only? So, I went into "encore\funambol\modules\webdemo-module\webdemo-webapp" and ran "mvn package". result: BUILD SUCCESSFUL. A target folder is created containing the new class files. Now its time to edit the souce code.
Open the encore\funambol\modules\webdemo-module\webdemo-webapp\src\main\java location and edit the PDIServlet.java file. Study the source code. You have to add parameters for nickname going by the same format as name, surname etc in the java file. The main contact class is in https://core.forge.f​unambol.org/source/b​rowse/core/trunk/fun​ambol/common/pim-fra​mework/src/main/java​/com/funambol/common​/pim/contact/ and the servlet file calls functions of this file to read/write contact properties. One can see that Name.Java file indeed has fields for nickname, suffix, initials etc. These are the fields that are already supported by Funambol but for some reason they do not show up in the web demo. We are closer on our way to displaying them. Build the package again after modifying. target folder is created. Copy the .class files into the funambol install dir i.e at C:\Program Files\Funambol\tools\tomcat\webapps\webdemo\WEB-INF\classes.
Finally we need to modify the corresponding jsp files to display text boxes for those fields. Modify the view.jsp and add.jsp to display field for Nickname in the same manner as Name and Surname etc are being displayed there.
We are done!

Open the web demo portal(you might need to restart server for changes to take effect), login using any (admin/guest/user) account. Click on new contact and see the Nickname field. Test the modification by adding a new contact and then displaying the same. The nickname field is saved.
Through this we are now able to write nickname field into database whose value previously being written was null.
Another interesting thing to check. One can confirm that the nickname field is being written into the database by looking into the funambol.log file.Since I have used the default db i.e hypersonic, so if I open \hyper​sonic\data\funambo​l.log file, at the bottom I can see the sql script being invoked to insert data into db and there is one less NULL data being written because we have now enabled the nickname field. :)

That summarizes my first funambol experience. A further look into Name.java, Address.java etc will tell us what are the funambol supported contact fields.
Next task I think is to know how to add a new field, the one that is not even supported by funambol. May be next time I'll reflect on this.

Useful reads:
https://core.forge.funambol.org/ds/viewMessage.do?dsForumId=405&dsMessageId=125526
https://core.forge.funambol.org/ds/viewMessage.do?dsForumId=405&dsMessageId=125104

--

Stumble Upon Toolbar

No comments:

Post a Comment