Oracle ADF with Google Firebase

Source: GitHub

This article talks about an interesting integration of Oracle ADF with Google's Firebase database. For those of you who are not aware of this, Firebase is a NoSQL cloud database service, provided free of cost (well, it's free for most of the way) by Google.

Reference: Google Firebase

We also had our eye on MongoDB cloud , but Firebase won the race for one simple reason - it provides out-of-the-box REST API connectors for it's entire data structure, and wrappers for query purposes. You do not need to write or manage a single line of code. Additionally, it provided access for firestore - an online storage space to upload documents.

The data-structure of firebase is quite unique - it stores data as a JSON tree. Every node of that tree is exposed as a REST URL, and all you need is to use the URL in your application.

To show an example, here's what Department and Employee structures look like in Firebase:

To access the desired node, appropriate URL is required to be parsed:

To set up a Firebase database, all you need is a Google account.The remaining steps to create a project and get its web-key is quite simple and are readily available online. I will just run through the key elements of this process.

Step 1: Create a new firebase project (Choose Real-time Database). Create it in test mode. This will ensure that no user authentication will be required to access the database - ideal for POC and development mode!

Step 2: To use a firebase database service account, you need to download a private key (a JSON file), from Service Account tab of the project. This key will be used to initialize our database from our ADF application.

Step 3: Download google firebase jars from Maven Central. These jars will provide us with the APIs to connect and query a Firebase database instance. To get a list of all the jars, you may refer to the GoogleLib library in the ViewController project. I have deployed all the jars as a shared library on my stand-alone WebLogic server (shared-google-lib) and have referenced the same from weblogic-application.xml.

The application structure consists of a task-flow, whose default activity is a method call which initializes the Firebase database instance, with a name of my choice - hrstore. I will be using this name throughout the application, whenever I need to reference the FirebaseApp Singleton.

The JSON file loaded is the web-key generated from Step 2.

The Model layer consists of references to this FirebaseApp instance, which is then used to fetch data and populate programmatic view objects.

Once a department is selected, the current row's department-id is used to create a firebase query, which filters against the Employees collection's department-id value.

An example of such a query would be:\"DepartmentId\"&equalTo=10

In order to allow a REST API to query a particular node of a json object, that node must be indexed. You can use to Rules section of the database to add such an index, as shown below:

If you notice the rules shown above, it says that all nodes can be currently read and written to by an un-authenticated user. This is something which will be covered in a future blog.

The JSON output from the rest call is converted into a HashMap, and is used to populate the ADF view object's rows.

Please note that this application does not use any database connection. For passivation, it uses file system. This is required, since we are using transient view objects.

You can create your own firebase project and then download the source code to play around. All you need is to download the web-key json file for your project and refer the same from class. Also, do not forget to change the name of the firebase URL (same class, same method).

Important note: You will receive a "weblogic hostname verification failed" error while accessing the REST APIs. To get rid of this, go to admin console > servers > server name > Configuration SSL tab > Advanced > Change Hostname Verification drop-down to None.

Some useful links:
3) Common Firebase Queries

Refer to sample-data.json inside repository.
Refer to lib/GoogleLib.library for a list of all required jars.

Update: For a complete list of SDK jars, refer to GoogleLib. This project can be built into a war file and can be deployed to WebLogic as a shared library. This library can be referenced from your application via weblogic.xml as "google-shared-lib".

This article is extended further with secure CRUD operations in my next blog.



Post a Comment