Worklight (JSONStore, HTTP Adapters), NodeJS (ExpressJS REST Api), MongoDB and AngularJS mobile app Part I

I was thinking to myself, "How do I touch pretty much all parts of the technologies that I want to know more about?".  I know, I'll make a mobile application in my spare time as a learning exercise.

I want to utilise "offline" capabilities, I want to use AngularJS to output the UI and handle all the complex stuff inside the controllers and I want a REST Api at the backend to fetch/store data into a NonSQL database.
As I already have most of that setup already running on a Raspberry Pi, it should be pretty quick to get up and running.
I made the decision to use the IBM Worklight mobile application product instead of raw cordova etc... mainly due to my usage of the JSONStore and the HTTP Adapters.  Both of these can be made secure and encrypted.

Whilst figuring out how to work with the JSONStore I discovered that I could not find a proper noobies 'How to build a simple JSONStore mobile app'.  Well, if there was I didn't find it.  What I did find was the InfoCenter that had some code snippets and reference Api info.  I started there and experimented until I got the hang of what was going on.

I then made the decision to make a 'Mobile Inspection' application (well, sometimes the old ones are the best ones) and I would focus it on Restaurant Health&Safety and Customer Service Inspections.

I did have grand plans to (re)make a generic Inspection generator that would allow you to design and build the Inspection Form, allowing for related questions, dependencies, dynamic hide/shows and navigation flow etc... but then I thought, "Best crawl and walk first before attempting the olympics".

I decided to make the Inspections hard-coded for this version (maybe for a later date, I'll make the all-singing version).  What I would do is put the data into a backend database and that will drive what is shown on the mobile device.
For this example, I'll be showing what I did to get this all up and running on a single laptop, split between the laptop and an internet exposed Raspberry Pi.  I did see areas where I could extract out the backend parts to run on Bluemix, which would also allow me to utilise the Bluemix MQA (Mobile Quality Assurance) application.

The walkthrough scenario of usage will something along these lines:
1) User performs a 'Start of Day' sync.  This will call the Worklight Server HTTP Adapter that will call the ExpressJS REST Api that will in turn connect to the MongoDB, extract the list of Inspections for this user and pass the JSON data back.  This data will then be passed back to the device and stored locally within the JSONStore on the device.
By storing the data offline, it allows the Inspector to conduct the inspection even if there is no internet access.

2) User selects to view the Inspections for the Day, clicking on the inspection to start that inspection.
The data captured by the Inspector will be stored locally to the JSONStore.
The Inspector has the ability to 'Save for Later' during an Inspection, but once it has been submitted the data is no longer editable.

3) The Inspector will continue with their job an inspect as many Restaurants as allocated to today.

4) At the End Of Day, the user will perform an 'End of Day' sync.  This will call the Worklight Server HTTP Adapter that will call the ExpressJS REST Api passing the data that was stored within the JSONStore.  This data will now be stored within the MongoDB database.

5) As this data is now in the MongoDB database, dashboards and reports can be used to view the data.
There is also the option that within the Worklight Adapter, if a specific threshhold is breached a BPM Process can be initiated via a REST Api call.


In the diagram above, I've highlighted where the extra security aspects can be added (including encryption of the JSONStore too).  I've also indicated potentially where Bluemix could be used in the future version.


Next I'll start walking through the separated work areas.

1) Building the Mobile App using AngularJS in Worklight using JSONStore to interact with "offline" data
2) Building the MongoDB and populating with initial data
3) Building the ExpressJS REST Api (and testing against the MongoDB)
4) Building the Worklight Server HTTP Adapters (and testing against the REST Api)
5) Connecting it all together.


(Work In Progress...will update soon!)

No comments:

Post a Comment