All MobileFabric Posts

Kony Storage Service

Ajay Bhat - Jan 02, 2017 - Integration

The Kony MobileFabric team wishes you a Happy New Year! To give your mobile development effort a flying start in the new year, Aravind Kashyap walks you through using the Kony Storage Service to store data that you'll use in your app.

In this agile world, a readily available space allocation to manage data becomes very essential to develop an application for a quick demo/service. If that space is available in a secured cloud, it makes the app developer's job much simpler, minimizing development efforts, cost and other maintenance hassles.

Kony offers storage as a service as part of MobileFabric and has developed this storage service supporting both cloud and On-Premise. Kony manages the cloud part and while On-Premise, one can connect to the database space that can be configured while installing MobileFabric.

How about having such a space for your app needs? Want to do a test drive? Here you go.

  1. What you need to do to get this space for you?
    • Cloud: Approach kony.com
    • On-premise: Install MobileFabric.
  2. How can you create your own schema for your application and make it available to use?
    • Login to Mobile Fabric Console and click on Apps on the left pane to create an App.
    • Create an identity to protect your storage service (This is optional)

  • Click on Objects tab -> Configure New -> Select Endpoint Type as Storage -> Select Security Level – Authentication

  • Configure your data model


 

  • Configure Mapping

  1. How to apply various OData filters?

 

  1. How to configure security filters and use it to control data access?
  • You can control the data access by configuring security filters as shown below

            e.g. Use Identity to set security filter for CreatedBy column. With this, data can only have accessed by the user who has created it.

  1. How can you quickly test the storage service by performing standard CRUD on the schema from Mobile Fabric Console?

  1. What is Clone App Data Model and how it can be used?
  1. This helps in reducing the efforts to create App Data Model again.
  2. You just need to use the tool “Clone App Data Model” to clone
  3. In general, storage first can be used as a proof of concept (POC) and then mapped to the actual backend post POC.

  1. How can you use the Mobile Fabric SDK to access storage service from the device?

We will now access our storage service from the MobileFabric SDK APIs.

Description: Get metadata of an Object from storage "storageDemoOrders", Data Object "orders"

function getObjectMetadata()
{
    var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});

    kony.application.showLoadingScreen
    (   								 
        null, "Fetching metadata ...", 
        constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
        true, 
        true, 
        null
     );
    objSvc.getMetadataOfObject
    (
        "orders", {},
        function(res) 
        {
            kony.application.dismissLoadingScreen();  		  
            getStorageRecords (); 
        },
        function(err) 
       {
           kony.application.dismissLoadingScreen(); 
           alert ("Error in record deletion:: " + JSON.stringify(err));
       }
   );
}

Description: Get full metadata of the storage service.

function getFullMetadata()
{
     var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});

    kony.application.showLoadingScreen
    (   								 
        null, "Fetching full storage service metadata ...", 
        constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
        true, 
        true, 
        null
    );

    objSvc.getMetadataOfAllObjects
    (
        {},
        function(res)
        {
            kony.application.dismissLoadingScreen(); 
            getStorageRecords ();
        },
            function(err)
            {
                kony.application.dismissLoadingScreen(); 
                alert("Error in record deletion :: " + JSON.stringify(err));
             }
  	);
}

Description: Get ObjectData from the Storage Service

function getOrderRecords ()
{
     var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});
     var dataObject = new kony.sdk.dto.DataObject("orders");
     var options = {"dataObject":dataObject};
     kony.application.showLoadingScreen
     (   								 
         null, "Fetching data for the object...", 
         constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
         true, 
         true, 
         null
      );
  objSvc.fetch
  (
      options,
      function(res)
      {
           kony.application.dismissLoadingScreen(); 
    	   alert ("Records :: " + JSON.stringify(res.records));
      },
      function(err)
      {
          kony.application.dismissLoadingScreen(); 
          alert ("Failed to fetch data :: " + JSON.stringify(err));
      }
  );
}

Description: Get ObjectData from a Storage Service with OData Filter applied

function getOrderRecordsWithODataFilter()
{
   var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});
    var dataObject = new kony.sdk.dto.DataObject("orders");
    var selQuery = new kony.sdk.dto.SelectQuery("storageDemoOrders", dataObject);
    var odataUrl = "$filter=TableId eq 2";
    dataObject.setSelectQueryObject(selQuery);
    var options = {"dataObject":dataObject};
    kony.application.showLoadingScreen
    (   								 
        null, "Fetching data for the object with OData filters applied...", 
        constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
        true, 
        true, 
        null
    );
    objSvc.fetch
    (
        options,
        function(res)
        {
    	    kony.application.dismissLoadingScreen(); 
    	    alert ("Records:: " + JSON.stringify(res.records));
  	},
        function(err)
        {
    	     kony.application.dismissLoadingScreen(); 
    	     alert ("Failed to fetch data:: " + JSON.stringify(err));
  	}
    );
}

Description: Insert Data into an Object and fetch the data to show in the App

function createOrdersRecord ()
{
    var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});
    var dataObject = new kony.sdk.dto.DataObject("orders");
    dataObject.addField("OrderedBy","myName");
    var options = {"dataObject":dataObject};
    kony.application.showLoadingScreen
    (
      null, 
      "Record creation is in progress...", 
      constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
      true, 
      true, 
      null
    );
    objSvc.create
    (
        options,
        function(response)
        {
    	    kony.application.dismissLoadingScreen(); 
    	    getStorageRecords ();
        },
        function(error)
        {
    	    kony.application.dismissLoadingScreen(); 
    	    alert("Error in record creation :: " + JSON.stringify(error));
        }
    );
}

Description: Update a record in an Object and fetch the data to show in the App.

function updateStorageRecord ()
{
    var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});
    var dataObject = new kony.sdk.dto.DataObject("orders");
    dataObject.addField("OrderAddress","myAddress");
    dataObject.addField("OrderId",1);
     var options = {"dataObject":dataObject};
     kony.application.showLoadingScreen
     (
         null, "Update the record...", 
         constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
         true, 
         true, 
         null
     );
    objSvc.update
    (
        options,
        function(res)
        {
            kony.application.dismissLoadingScreen(); 
    	    getStorageRecords ();
        },
        function(err)
        {
            kony.application.dismissLoadingScreen(); 
            alert("Error in record update :: " + JSON.stringify(err));
        }
    );
}

Description: Delete Data from an Object and fetch the data to show in the App.

function deleteStorageRecord ()
{
    var objSvc = kony.sdk.mvvm.KonyApplicationContext.getAppInstance().getModel("storageDemoOrders ","Orders",{"access":"online"});
    var dataObject = new kony.sdk.dto.DataObject("orders");
    dataObject.addField("orderId",1);
    var options = {"dataObject":dataObject};
    kony.application.showLoadingScreen
    (
        null, 
        "Delete record ...", 
        constants.LOADING_SCREEN_POSITION_ONLY_CENTER, 
        true, 
        true, 
        null
    );
    objSvc.deleteRecord
    (
        options,
        function(res)
        {
            kony.application.dismissLoadingScreen(); 
    	    getStorageRecords ();
        },
        function(err)
        {
            kony.application.dismissLoadingScreen(); 
            alert("Error in record deletion :: " + JSON.stringify(err));
        }
    );
}
  1. How can you export the data and import to another database of the same database type?
    1. A zip file will be downloaded on clicking the export icon.
    2. On zip file extract, you can find Microsoft Excel files.
    3. Each object’s data will get exported to a separate Excel file.
    4. Similarly, you can import the exported .zip file to a MobileFabric storage App.

  1. Databases supported
    • : MySQL
    • : Oracle, MySQL, MSSQL
  2. Current Limitations
    • Supports only number, string, date and boolean datatypes.
    • Supports only One to Many relationships between the entities.
    • Export/Import of the data is only supported for MySQL database.
    • Export/Import of the data can only be done between the same database types (Example: MySQL to MySQL, not MySQL to any other database).
  3. Questions?

Please post your questions to Kony Community Forums