Skip to Content
0

Build UI5 application which agnositic to underline service

Jan 31 at 11:41 AM

158

avatar image
Former Member

HI,

I want to create UI5 application which use services from several providers ,

hence I want to create some abstraction layer which is agnostic to the underline services

for example the UI should provide the exact same values but can use different services.

what is the best practice of UI5 in this case ? how it's suggested to create this abstraction layer ? example or reference will be very helpful since Im fairly new to UI5

Thanks

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

avatar image
Former Member Feb 01 at 08:43 AM
0

Hi All,

Any idea? direction ?

Thanks!

Share
10 |10000 characters needed characters left characters exceeded
Bernard Le Tourneur Feb 23 at 07:00 AM
0

My approach is as follows.

Its common practice to have a models.js file. This, for example, is often used to create the device model.

In this file I create my service model that includes all urls that I will need - you can vary this depending on the environment your are deploying to (will ignore that complexity).

In the models.js file I would, as an example, include these service urls:

 createEnvironmentModel: function(environment, source){

var data = {
 urls: {
 functions: "https://****api************.net/",
 logging: "https://crosscutting.********/",
 identity: "https://identity.********/",
 proto: "http://localhost:57109/"
 }, ...
...
var cModel = new JSONModel(data);

Consequently this model is accessible from the application as a whole (a global model if you like) given that the above is called from within the Component.js (again as is common practice)

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/model/json/JSONModel",
    "blt/ui5/model/models"
], function (UIComponent, JSONModel, models) {
    "use strict";
    return UIComponent.extend("blt.ui5.Component", {
        metadata: {
            manifest: "json"
        },
        init: function () {
            var sEnvironment = "/qac";
            this.setModel(models.createEnvironmentModel(sEnvironment, this), "current");  // <------ named model
            // set the device model
            this.setModel(models.createDeviceModel(), "device");

I then use this in my service calls (split across a query service (for READ activity) and a command service (for CrUD activity (WRITE))

An example below:

    getAssetByVin: function (session, vin) {
        return simpleGet(session.urls.functions + "/v1/asset?primaryIdentifier=" + vin, session);
    },

Where session is effectively the named model (current)

I hope that makes sense - ask further if you need more direction.

Share
10 |10000 characters needed characters left characters exceeded
Sharath M G Feb 22 at 03:48 PM
0

Any service REST complaint can be invoked from the UI5 layer. Bundle service call in a separate JS file, which would act a service layer.

Then, load the results of service in local JSON models.

These JSON models can be used in controller or view.

Regards,

Sharath

Share
10 |10000 characters needed characters left characters exceeded