MartinStenzig / teched-2021

SAP TechEd 2021 - Network Spatial CAP Service Example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SAP TechEd 2021 - Network Spatial CAP Service Example

The intent of this example is to show the use of a custom, CAP based, spatial data provider in the SAP Network Spatial Service (NSS) component.

AIN NSS Screenshot

You will use the NSS configuration app to configure the additional service.

Prerequisites

  1. Business Network - Specifically Asset Intelligence Network (AIN) (or Test and Demo license thereof)
  2. BTP Licenses (or Trial to start with)
    • Application Runtime
    • HANA Cloud
  3. Mapbox API Key

Configuration

In order to build a scenario that does not conflict with anything else we will create a complete new renderer and additional layer.

  1. Either follow the instructions in the section "Step by Step instructions to develop a CAP based source service" to create and deploy the service (mbt build and cf deploy).

  2. Configure a custom Mapbox style. You will need to do this if you want to implement this scenario as described in here and/or you want to use colorful symbols. You can skip this step if you simply want to chose circles (in which case you have to adjust the layer definition outlined below

    1. Open up Mapbox Studio https://studio.mapbox.com/
    2. Select 'New Style'
    3. Choose a template - I used 'Basic' with 'Galaxy' variation
    4. Hit the 'Customize Basic' button at the bottom
    5. Find the Images button at the top and drag and drop the three images located in the ./doc/mapbox-config folder into the 'Images' section
      AIN NSS Screenshot
    6. Hit the publish button to save and publish your changes
    7. Back in the styles menu, click on the three vertical dots and copy the "Style URL" for use below
  3. Configure the new Scenario

    1. Open up the NSS configuration app (Configure Network Maps - Last App in the list below)

      AIN NSS Screenshot
    2. Start by Creating a new Renderer

    3. Create a new Layer

      • Type: Symbol
      • Source Type: GeoJSON
      • Service URL: [route to app router module]/geojson/RealtimeLocations
      • Layout JSON:
      {
        "icon-image": ["match",
                      ["get", "Status"],
                      1,"truck-green-50",
                      2,"truck-orange-50",
                      "truck-red-50"], 
        "icon-size": 0.5
      }
    4. Create a new Scenario

      • Enable Draw Toolbar: 'No' - as this is a read only scenario
      • Enable Bounding Box: 'Yes' - you want to zoom automatically to your selected feature
      • Bounding Box Padding: 200
      • Add the three layers (Current Objects Polygons, Point and Lines to the Layers list, assign a common Group Name (i.e. 'Current') to all three layers.
      • Now add our new Layer to the layers list and set Locked = 'Yes'
    5. Select the Work Order App application, click edit and add the new scenario to the Scenarios list.

  4. Once you have performed these steps you should be good to go. Open the 'Work Orders' App, navigate to the 'GEOMETRY' Tab and switch the scenario to yours. It should looks like this:

    AIN NSS Screenshot



Step by Step instructions to develop a CAP based source service

  1. Create CAP project using cds init command
  2. Add HANA and mta.yaml using cds add hana command
  3. Adjusted the 'mta.yaml' file to make some changes I like
    • Adjusted the mta id
    • Changed the mta description
    • Added 2 parameters to the service
      - memory: 200M
      - disk-quota: 250M
    • Added a explict schema name to the database service
        config:
          schema: teched_2021
  4. Add the data model
  5. Add the service
  6. Add the Rest Test Script
    • At this point you developed the basic service that works locally and can be deployed, but is not functioning in the cloud yet.
  7. Added some custom handlers and some supporting functions to allow for the storage and read of spatial data in a HANA environment.
  8. To expose the service as REST GeoJSON service we create a second service called GeoJSON with the following service defintion and implementation
    • The implementation does some conversion specific to HANA databases as well as to GeoJSON.
    • You can now access the service via the following URL: [host]/geojson/RealtimeLocations
    • Find more details on the approach in this SAP Community blog post
  9. To remove CORS restriction you can add an app router
  • see files in directory /approuter
  • make the following changes in the mta.yaml file
 # ------------------- APP ROUTER MODULE -----------------------
- name: teched-2021-router # Approuter Module channeling the traffic to the correct destination
# ------------------------------------------------------------
 type: nodejs
 path: approuter
 parameters:
    memory: 100M
    buildpack: nodejs_buildpack
 requires:
    - name: teched-2021-srv_api
      group: destinations
      properties:
        name: teched-2021-srv_api
        url: ~{srv-url}
        forwardAuthToken: true
        timeout: 600000
 properties:
    COOKIES: >
        { "SameSite": "None" }
    CORS: >
        [
          {
            "uriPattern": "^(.*)$",
            "allowedOrigin": [ 
                              { "host": "*.hana.ondemand.com", "protocol": "https" },
                              { "host": "*.hana.ondemand.com", "protocol": "http" }
            ],
            "allowedMethods": ["GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE"],
            "allowedHeaders": ["Origin", "Accept", "X-Requested-With", "Content-Type", 
                                                  "Access-Control-Request-Method", 
                                                  "Access-Control-Request-Headers", "Authorization", "X-Sap-Cid", 
                                                  "X-Csrf-Token", "Accept-Language"],
            "exposeHeaders": ["Accept", "Authorization", "X-Requested-With", "X-Sap-Cid", 
                                                "Access-Control-Allow-Origin", "Access-Control-Allow-Credentials", 
                                                "X-Csrf-Token", "Content-Type"]
          }
        ]
  1. You can test the service by using the VS Rest Client Extension with the test script.

About

SAP TechEd 2021 - Network Spatial CAP Service Example


Languages

Language:JavaScript 96.6%Language:HTML 3.4%