cancel
Showing results for 
Search instead for 
Did you mean: 

Model isn't loading when using CAP OData v2 Proxy

mario_brandao2
Employee
Employee
0 Kudos

I have a brand new OData v2 proxy, pointing to a Java based OData v4 CAP service. V4 end point is working as expected, and proxy seems too (it loads metadata and 2 entities with data and no issues).

When launching an app consuming that OData service, it loads metadata but UI5 complains that "M.getMetaModel(...).requestObject is not a function", as you can see in attached image.

As I'm new to OData, I can't tell if that's an issue on my OData or configuration in the UI side, but it works with no issues when consuming OData v4 instead.

I suspect there's something wrong on my manifest.json or how metadata is generated.

Here is the metadata:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">
  <edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1.xml" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:Include Alias="Capabilities" Namespace="Org.OData.Capabilities.V1"/>
  </edmx:Reference>
  <edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/>
  </edmx:Reference>
  <edmx:DataServices m:DataServiceVersion="2.0">
    <Schema Namespace="MasterDataService" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
      <EntityContainer Name="EntityContainer" m:IsDefaultEntityContainer="true">
        <EntitySet Name="BuildingUsageType" EntityType="MasterDataService.BuildingUsageType"/>
        <EntitySet Name="Buildings" EntityType="MasterDataService.Buildings"/>
        <EntitySet Name="Sites" EntityType="MasterDataService.Sites"/>
        <AssociationSet Name="BuildingUsageType_BuildingRef" Association="MasterDataService.BuildingUsageType_BuildingRef">
          <End Role="BuildingUsageType" EntitySet="BuildingUsageType"/>
          <End Role="Buildings" EntitySet="Buildings"/>
        </AssociationSet>
        <AssociationSet Name="Buildings_SiteRef" Association="MasterDataService.Buildings_SiteRef">
          <End Role="Buildings" EntitySet="Buildings"/>
          <End Role="Sites" EntitySet="Sites"/>
        </AssociationSet>
      </EntityContainer>
      <EntityType Name="BuildingUsageType">
        <NavigationProperty Name="BuildingRef" Relationship="MasterDataService.BuildingUsageType_BuildingRef" FromRole="BuildingUsageType" ToRole="Buildings"/>
        <Property Name="UsageType" Type="Edm.String" MaxLength="50"/>
        <Property Name="StartDate" Type="Edm.DateTime" sap:display-format="Date"/>
        <Property Name="EndDate" Type="Edm.DateTime" sap:display-format="Date"/>
        <Property Name="BuildingRef_Irn" Type="Edm.String" MaxLength="50"/>
      </EntityType>
      <EntityType Name="Buildings">
        <Key>
          <PropertyRef Name="Irn"/>
        </Key>
        <Property Name="Irn" Type="Edm.String" MaxLength="50" Nullable="false"/>
        <Property Name="LongName" Type="Edm.String" MaxLength="255"/>
        <Property Name="ShortName" Type="Edm.String" MaxLength="30"/>
        <NavigationProperty Name="SiteRef" Relationship="MasterDataService.Buildings_SiteRef" FromRole="Buildings" ToRole="Sites"/>
        <NavigationProperty Name="UsageTypes" Relationship="MasterDataService.BuildingUsageType_BuildingRef" FromRole="Buildings" ToRole="BuildingUsageType"/>
        <Property Name="SiteRef_Irn" Type="Edm.String" MaxLength="50"/>
      </EntityType>
      <EntityType Name="Sites">
        <Key>
          <PropertyRef Name="Irn"/>
        </Key>
        <Property Name="Irn" Type="Edm.String" MaxLength="50" Nullable="false"/>
        <Property Name="LongName" Type="Edm.String" MaxLength="255"/>
        <Property Name="ShortName" Type="Edm.String" MaxLength="30"/>
        <Property Name="Intreno" Type="Edm.String" MaxLength="40"/>
        <NavigationProperty Name="Buildings" Relationship="MasterDataService.Buildings_SiteRef" FromRole="Sites" ToRole="Buildings"/>
      </EntityType>
      <Association Name="BuildingUsageType_BuildingRef">
        <End Role="BuildingUsageType" Type="MasterDataService.BuildingUsageType" Multiplicity="*"/>
        <End Role="Buildings" Type="MasterDataService.Buildings" Multiplicity="0..1"/>
        <ReferentialConstraint>
          <Principal Role="Buildings">
            <PropertyRef Name="Irn"/>
          </Principal>
          <Dependent Role="BuildingUsageType">
            <PropertyRef Name="BuildingRef_Irn"/>
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Association Name="Buildings_SiteRef">
        <End Role="Buildings" Type="MasterDataService.Buildings" Multiplicity="*"/>
        <End Role="Sites" Type="MasterDataService.Sites" Multiplicity="0..1"/>
        <ReferentialConstraint>
          <Principal Role="Sites">
            <PropertyRef Name="Irn"/>
          </Principal>
          <Dependent Role="Buildings">
            <PropertyRef Name="SiteRef_Irn"/>
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Annotations Target="MasterDataService.EntityContainer/Buildings" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <Annotation Term="Capabilities.DeleteRestrictions">
          <Record Type="Capabilities.DeleteRestrictionsType">
            <PropertyValue Property="Deletable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.InsertRestrictions">
          <Record Type="Capabilities.InsertRestrictionsType">
            <PropertyValue Property="Insertable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.UpdateRestrictions">
          <Record Type="Capabilities.UpdateRestrictionsType">
            <PropertyValue Property="Updatable" Bool="false"/>
          </Record>
        </Annotation>
      </Annotations>
      <Annotations Target="MasterDataService.EntityContainer/Sites" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <Annotation Term="Capabilities.DeleteRestrictions">
          <Record Type="Capabilities.DeleteRestrictionsType">
            <PropertyValue Property="Deletable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.InsertRestrictions">
          <Record Type="Capabilities.InsertRestrictionsType">
            <PropertyValue Property="Insertable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.UpdateRestrictions">
          <Record Type="Capabilities.UpdateRestrictionsType">
            <PropertyValue Property="Updatable" Bool="false"/>
          </Record>
        </Annotation>
      </Annotations>
      <Annotations Target="MasterDataService.Sites/Intreno" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <Annotation Term="Core.Computed" Bool="true"/>
      </Annotations>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

Here is manifest.json:

{
  "_version": "1.8.0",
  "sap.app": {
    "id": "buildings",
    "type": "application",
    "title": "Buildings Details",
    "description": "buildings",
    "dataSources": {
      "MasterDataService": {
        "uri": "/v2/MasterDataService/",
        "type": "OData",
        "settings": {
          "odataVersion": "2.0"
        }
      }
    }
  },
  "sap.ui5": {
    "dependencies": {
      "libs": {
        "sap.fe.templates": {}
      }
    },
    "models": {
      "": {
        "dataSource": "MasterDataService",
        "settings": {
          "synchronizationMode": "None",
          "operationMode": "Server",
          "autoExpandSelect": false,
          "earlyRequests": false,
          "groupProperties": {
            "default": {
              "submit": "Auto"
            }
          }
        }
      }
    },
    "routing": {
      "routes": [
        {
          "pattern": ":?query:",
          "name": "Buildings",
          "target": "Buildings"
        }
      ],
      "config": {
        "routerClass": "sap.m.routing.Router",
        "viewType": "XML",
        "async": true,
        "viewPath": "buildings.view",
        "controlAggregation": "pages",
        "clearControlAggregation": false
      },
      "targets": {
        "Buildings": {
          "type": "Component",
          "id": "Buildings",
          "viewType": "XML",
          "transition": "slide",
          "clearControlAggregation": false,
          "viewId": "MarioId",
          "viewName": "App",
          "options": {
            "settings": {
              "entitySet": "Buildings"
            }
          }
        }
      }
    }
  }
}

and here my view:

<mvc:View
   xmlns="sap.m"
   xmlns:mvc="sap.ui.core.mvc"
   xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
   xmlns:smartTable="sap.ui.comp.smarttable"
   displayBlock="true"
   >
    <App id="app">
        <pages>
            <Page id="page" title="{i18n>title}">
                <content>
                </content>
            </Page>
        </pages>
    </App>
</mvc:View>

If anyone can help, it would be very nice of you.

gregorw
Active Contributor
0 Kudos

Please share the JavaScript that you use to run the standalone proxy.

mario_brandao2
Employee
Employee
0 Kudos

Thanks gregorw here it goes:

const express = require("express");
const proxy = require("@sap/cds-odata-v2-adapter-proxy");

const host = "0.0.0.0";
const port = process.env.PORT || 4004;

(async () => {
  const app = express();

  app.use(proxy({
    target: "http://localhost:8080/odata/v4",
    model: "./csnv2.json",
    services: {
      "/MasterDataService/": "MasterDataService"
    }
  }));

  const server = app.listen(port, host, () => console.info(`app is listing at ${host}:${port}`));
  server.on("error", error => console.error(error.stack));
})();
mario_brandao2
Employee
Employee
0 Kudos

And csn file too, if that helps.

csnv2json.txt

T1mey
Participant
0 Kudos

Hello gregorw

I have a very similar issue. Using a generated fiori elements app and CAP.

I do not need the draft function (and "normal" edit seems not to be implemented with v4) and so I decided to move to ODATA v2. I added

and my ODATA service is available with .../v2 in URL. Services are coming out of the db/schema entities.

As well changes my manifest.json of the UI app to:

Ending upin the same problem as described above.

Tried the approach described here

But it does not work. I was not sure what model to take. So I generated it with cds complie ../srv/Applications.cds --to csn.

Any idea ?

Accepted Solutions (0)

Answers (1)

Answers (1)

gregorw
Active Contributor
0 Kudos

Hi Mario,

please try:

    services:{"/MasterData": "MasterDataService"}

like in my example: index.js#L19

CU
Gregor

mario_brandao2
Employee
Employee
0 Kudos

I see, but how is it related to the issue I'm facing?

My v4 end point uses MasterDataService as much as v2, so, I tried removing the trailing slash to be services:{"/MasterDataService": "MasterDataService"} instead, but it made no difference on UI5's error.

Thanks

gregorw
Active Contributor
0 Kudos

Hi mario.brandao2

but isn't the V4 endpoint reachable at /master-data ? So you have to use the service-path as described in: https://www.npmjs.com/package/@sap/cds-odata-v2-adapter-proxy#cds-standalone-backend-cap-java-or-cap...

"<odata-v4-service-path>": "<qualified.ServiceName>"
mario_brandao2
Employee
Employee
0 Kudos

but v2 is working too, for instance, http://0.0.0.0:4004/v2/MasterDataService/$metadata returns the following:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">
  <edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1.xml" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:Include Alias="Capabilities" Namespace="Org.OData.Capabilities.V1"/>
  </edmx:Reference>
  <edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/>
  </edmx:Reference>
  <edmx:DataServices m:DataServiceVersion="2.0">
    <Schema Namespace="MasterDataService" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
      <EntityContainer Name="EntityContainer" m:IsDefaultEntityContainer="true">
        <EntitySet Name="BuildingUsageType" EntityType="MasterDataService.BuildingUsageType"/>
        <EntitySet Name="Buildings" EntityType="MasterDataService.Buildings"/>
        <EntitySet Name="Sites" EntityType="MasterDataService.Sites"/>
        <AssociationSet Name="BuildingUsageType_BuildingRef" Association="MasterDataService.BuildingUsageType_BuildingRef">
          <End Role="BuildingUsageType" EntitySet="BuildingUsageType"/>
          <End Role="Buildings" EntitySet="Buildings"/>
        </AssociationSet>
        <AssociationSet Name="Buildings_SiteRef" Association="MasterDataService.Buildings_SiteRef">
          <End Role="Buildings" EntitySet="Buildings"/>
          <End Role="Sites" EntitySet="Sites"/>
        </AssociationSet>
      </EntityContainer>
      <EntityType Name="BuildingUsageType">
        <NavigationProperty Name="BuildingRef" Relationship="MasterDataService.BuildingUsageType_BuildingRef" FromRole="BuildingUsageType" ToRole="Buildings"/>
        <Property Name="UsageType" Type="Edm.String" MaxLength="50"/>
        <Property Name="StartDate" Type="Edm.DateTime" sap:display-format="Date"/>
        <Property Name="EndDate" Type="Edm.DateTime" sap:display-format="Date"/>
        <Property Name="BuildingRef_Irn" Type="Edm.String" MaxLength="50"/>
      </EntityType>
      <EntityType Name="Buildings">
        <Key>
          <PropertyRef Name="Irn"/>
        </Key>
        <Property Name="Irn" Type="Edm.String" MaxLength="50" Nullable="false"/>
        <Property Name="LongName" Type="Edm.String" MaxLength="255"/>
        <Property Name="ShortName" Type="Edm.String" MaxLength="30"/>
        <NavigationProperty Name="SiteRef" Relationship="MasterDataService.Buildings_SiteRef" FromRole="Buildings" ToRole="Sites"/>
        <NavigationProperty Name="UsageTypes" Relationship="MasterDataService.BuildingUsageType_BuildingRef" FromRole="Buildings" ToRole="BuildingUsageType"/>
        <Property Name="SiteRef_Irn" Type="Edm.String" MaxLength="50"/>
      </EntityType>
      <EntityType Name="Sites">
        <Key>
          <PropertyRef Name="Irn"/>
        </Key>
        <Property Name="Irn" Type="Edm.String" MaxLength="50" Nullable="false"/>
        <Property Name="LongName" Type="Edm.String" MaxLength="255"/>
        <Property Name="ShortName" Type="Edm.String" MaxLength="30"/>
        <Property Name="Intreno" Type="Edm.String" MaxLength="40"/>
        <NavigationProperty Name="Buildings" Relationship="MasterDataService.Buildings_SiteRef" FromRole="Sites" ToRole="Buildings"/>
      </EntityType>
      <Association Name="BuildingUsageType_BuildingRef">
        <End Role="BuildingUsageType" Type="MasterDataService.BuildingUsageType" Multiplicity="*"/>
        <End Role="Buildings" Type="MasterDataService.Buildings" Multiplicity="0..1"/>
        <ReferentialConstraint>
          <Principal Role="Buildings">
            <PropertyRef Name="Irn"/>
          </Principal>
          <Dependent Role="BuildingUsageType">
            <PropertyRef Name="BuildingRef_Irn"/>
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Association Name="Buildings_SiteRef">
        <End Role="Buildings" Type="MasterDataService.Buildings" Multiplicity="*"/>
        <End Role="Sites" Type="MasterDataService.Sites" Multiplicity="0..1"/>
        <ReferentialConstraint>
          <Principal Role="Sites">
            <PropertyRef Name="Irn"/>
          </Principal>
          <Dependent Role="Buildings">
            <PropertyRef Name="SiteRef_Irn"/>
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Annotations Target="MasterDataService.EntityContainer/Buildings" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <Annotation Term="Capabilities.DeleteRestrictions">
          <Record Type="Capabilities.DeleteRestrictionsType">
            <PropertyValue Property="Deletable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.InsertRestrictions">
          <Record Type="Capabilities.InsertRestrictionsType">
            <PropertyValue Property="Insertable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.UpdateRestrictions">
          <Record Type="Capabilities.UpdateRestrictionsType">
            <PropertyValue Property="Updatable" Bool="false"/>
          </Record>
        </Annotation>
      </Annotations>
      <Annotations Target="MasterDataService.EntityContainer/Sites" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <Annotation Term="Capabilities.DeleteRestrictions">
          <Record Type="Capabilities.DeleteRestrictionsType">
            <PropertyValue Property="Deletable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.InsertRestrictions">
          <Record Type="Capabilities.InsertRestrictionsType">
            <PropertyValue Property="Insertable" Bool="false"/>
          </Record>
        </Annotation>
        <Annotation Term="Capabilities.UpdateRestrictions">
          <Record Type="Capabilities.UpdateRestrictionsType">
            <PropertyValue Property="Updatable" Bool="false"/>
          </Record>
        </Annotation>
      </Annotations>
      <Annotations Target="MasterDataService.Sites/Intreno" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <Annotation Term="Core.Computed" Bool="true"/>
      </Annotations>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

The issue happens when the UI5 app is launched pointing to that metadata. The metadata is loaded but then it shows the error I have attached as image above.

On the other side, the very same app worked fine when using OData v4

mario_brandao2
Employee
Employee
0 Kudos

I have solved it. It was just some misconfiguration. Thank you anyway!

0 Kudos

Hi Mario,

I'm facing the same issue, could you explain how did you solve it please?

Thanks.

bdeboer
Explorer
0 Kudos

Hi mario.brandao2 . What was the misconfiguration?