« Domino views in the BlackBerry browser | Main| »

Shared Contacts - Behind the scenes

Category
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 


Mike has already posted about our new free Shared Contacts BlackBerry application here, and I thought it might be nice to talk about the technical side of the development.

The basis of the solution is a fairly straight-forward 'persistent store & push listener' model. The idea is that the Notes database can push down contacts data, which is then stored locally on the BlackBerry. The BlackBerry app allows the user to search for contacts and to make calls and send emails directly from within the app.

The Notes database has some agents and scripts which handle the pushing of data out to the BlackBerrys. These make use of the Java Push Library that RIM so very kindly provided.

The key thing we wanted was for the app to be as generic as possible, with the idea that you could paste in the few design elements into your own database and with a tiny bit of tweaking make it grab your own contacts data. I felt the simplest way to do this was to get the data from a custom view. That way you can tweak the view to show your documents, and make sure the correct fields show in each column. The agent then works its way through the view, and builds up a string of pseudo-xml that it can push out to the BlackBerrys. This way, the agent needs no changes when integrating the push code into different databases. There are probably better ideas, but this seemed like a good place to start.

On the BlackBerry side, I also wanted to try and make the listener and persistent store as generic as possible. I have written a fair few persistent store apps, and while much of the code is reusable, I always find it irritating to customize it for each app.

What I did was build a generic database class library, and being a LotusScript programmer at heart, I designed it so that it behaved like a NotesDatabase, with 'NotesDocumentCollections' and 'NotesDocuments'. So I have nice familiar methods like db.openByID(), coll = db.getAllDocuments(), doc = coll.getFirstDocument(), doc = coll.getNextDocument(doc), doc.getItemValue("MyField"), etc.

I also built a pushlistener class which can accept the pushed data stream, which is in its own pseudo-xml, and then passes this stream out to any database objects it knows about in the app. The database class has an update() method which the pushlistener can call, passing the received data. The stream's xml contains a name for the destination database, so the database object can decide if the data is for it or not. It is a very simple observer pattern, which allows me to have several databases in one app all being handled by one listener. For example, in this app I have two databases (i.e. persistent stores), one is for configuration data, and the other for the contacts data.

Its all a bit raw and unpolished at the moment, but I am hoping that this will all make my next development much easier, and will form a nice platform for extending the app. (One thing I can think of is handling dates, as currently my field storage can handle only strings and numbers). Part of the point of this whole application is that it is simple, but can be extended to fit particular requirements, such as to mimic a particular CRM, for example.

I am now working on the next version, which will have a pseudo-replication model. I will keep a 'replication history' for each BlackBerry, and can then send out only the changes since the last successful push for each BlackBerry. Part of this will be a basic structure for two-way updates (I hesitate to call it anything as grand as 'replication'), which isn't really appropriate for this app, but will be useful for something else.

Mike has more details in our blog (see above), but if you are interested the links to the app and database are:

BlackBerry download: http://lotusphere.turtleweb.com/contacts.jad
Notes database: http://lotusphere.turtleweb.com/bbcontacts.zip

The install instructions are in the 'Using This Database' of the Notes database.

As always, we'd be very interested in what people think

Comments

Gravatar Image1 - I get a "907 Invalid COD" when attempting to download to my BlackBerry. Any ideas?

Gravatar Image2 - In the past, 907 errors have been fixed by taking the battery out of the blackberry and restarting it. If this doesn't help, can you let me know which model and OS version you are using? Thanks.

Gravatar Image3 - Following up from a comment on our own blog: I forgot to list the Config view as an element needing to be copied into your own db. I have amended the instructions in the 'Using This Database' and put an updated db on our download site. (Thanks for helping us out on this, Cesar).

Gravatar Image4 - A couple of people have pointed out the need to sign the database with the server id to make sure the agents run OK. I'll add that to the instructions, too.