Skip to Content

Navigation is supported in soap data source when a web service has such an operation which takes an input parameter which is the key element of another entity set.

Steps from Design Time tool

  1. Create an OData Service Implementation Project
  2. Create an OData Model for 2 entities salesOrders and Customers. Define a navigation from customers to salesOrders as below. This model fetches all the salesOrders for a specific customer. So the web service must have an operation like getSalesOrders and this operation must take customerId as an input parameter and return the sales order list. Here Navigation Property Name is SalesOrdersSet

/wp-content/uploads/2014/10/1_579253.png

    3. Right click on odatasvc and choose Select data source

    4. Select the SalesOrders entitySet and choose the query CRUD operation. Select the data source SOAP Service.

    Img2.jpg

    5. Specify the wsdl file and choose the getSalesOrders operation from the list of soap operations and click on finish

Img3.jpg

    6. Right click on Query and select Define Custom Code

Img4.jpg

     7. Select the script type as either javascript or groovy script

Img5.jpg

     8. The navigation segment path has to be fetched from the odata request uri and a proper request payload has to be created. If the navigation segment path is like CustomerSet(10)/SalesOrdersSet, then the key predicate customerId = 10 must be fetched from the navigation segment path and this should be an input parameter to the web service operation getSalesOrders.


function processRequestData(message) {
var uriInfo = getUriInfo(message);
importPackage(org.apache.olingo.odata2.api.uri);
importPackage(java.util);
var map = new HashMap();
var navSegments = uriInfo.getNavigationSegments();
var first = true;
if (navSegments.size() > 0) {
  var keyPredicate = "";
  for (var i=0; i<uriInfo.getKeyPredicates().size();i++) {
   importPackage(org.apache.olingo.odata2.api.edm);
   var key=uriInfo.getKeyPredicates().get(i);
   edmSimpleType = key.getProperty().getType();
   if (first) {
    first = false;
   } else {
    first = true;
   }
   keyPredicate = getWhereString(key, edmSimpleType);
  }
  map.put("CustID", keyPredicate);
  message.setBody(map);
}
return message;
}
function getUriInfo(message) {
importPackage(org.apache.olingo.odata2.api.uri);
importPackage(com.sap.gateway.core.ip.component.commons);
var uriInfo = message.getHeaders().get(
   ODataExchangeHeaderProperty.UriInfo.toString());
return uriInfo;
}
function getWhereString(key, edmSimpleType) {
var appendStr = "";
importPackage(org.apache.olingo.odata2.api.edm);
if (!(edmSimpleType == EdmSimpleTypeKind.Int16
   .getEdmSimpleTypeInstance()
   || edmSimpleType == EdmSimpleTypeKind.Int32
     .getEdmSimpleTypeInstance()
   || edmSimpleType == EdmSimpleTypeKind.Int64
     .getEdmSimpleTypeInstance()
   || edmSimpleType == EdmSimpleTypeKind.Decimal
     .getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.Double
    .getEdmSimpleTypeInstance())) {
  appendStr = "\'" + key.getLiteral() + "\'";
} else {
  appendStr = key.getLiteral();
}
return appendStr;
}

If the OData request is https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet(10)/SalesOrdersSet

The request payload looks like

   <soapenv:Body>
      <tes:getSalesOrders>
         <tes:CustID>10</tes:CustID>
      </tes:getSalesOrders>
   </soapenv:Body>

   9. Right click on Query and select Define Response Mapping

Img9.jpg

   10. Do the response mapping.

   11. Select a data source for the other entity set as well.

   12. Right Click on Project and select Generate and Deploy Integration Content. This will deploy the bundle.

Now fire an OData Request https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet(10)/SalesOrdersSet on the browser and response will give the list of sales orders with customerId 10.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Midhun VP

    Hi Ramya,

    Thanks for the blog. Few of the images are not visible, sometimes this issue comes when we drag and drop images. Could you please try with “image insert” icon.

    – Midhun VP

    (0) 

Leave a Reply