Currently the "Developing with SAP Extension Suite" Learning Journey has some limitations, because code snippets required in some of the exercises are yet to be included. This blog post provides the snippets for the individual exercises in unit 4 to unit 6 until they are included in the official Learning Journey.
See also Code snippets for the "Developing with SAP Extension Suite" Learning Journey Unit 1 to Unit 3
URL for API_BUSINESS_PARTNER destination
https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER/
xsappname in generated xs-security.json
risk-management-<YOURDEVSPACE>
Make sure to replace <YOURDEVSPACE> with your dev-space name.
Additional lines for package.json requires section
"xsuaa": {
"kind": "xsuaa"
}
New requires section of package.json file
Note: Lines starting with //### BEGIN OF INSERT and ending with //### END OF INSERT have been added to the previous version of the section. Lines starting with //### BEGIN OF DELETE and ending with //### END OF DELETE need to be removed from the section.
{
...
...
"cds": {
"requires": {
"API_BUSINESS_PARTNER": {
"kind": "odata",
"model": "srv/external/API_BUSINESS_PARTNER",
//### BEGIN OF DELETE
"credentials": {
"url": "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER/"
},
//### END OF DELETE
//### BEGIN OF INSERT
"[development]": {
"credentials": {
"url": "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER/"
}
},
"[production]": {
"credentials": {
"destination": "API_BUSINESS_PARTNER"
}
}
//### END OF INSERT
},
"db": {
"kind": "sql"
},
"xsuaa": {
"kind": "xsuaa"
}
},
"hana": {
"deploy-format": "hdbtable"
}
}
}
New resource in mta.yaml file
# ------------------------------------------------------------
- name: risk-management-destination-service
# ------------------------------------------------------------
type: org.cloudfoundry.managed-service
parameters:
service: destination
service-plan: lite
New content of srv/risk-service.cds file
Note: Lines starting with //### BEGIN OF INSERT and ending with //### END OF INSERT have been added to the previous version of the file. Lines starting with //### BEGIN OF DELETE and ending with //### END OF DELETE need to be removed from the file.
using {riskmanagement as rm} from '../db/schema';
/**
* For serving end users
*/
service RiskService @(path : 'service/risk') {
//### BEGIN OF DELETE
entity Risks as projection on rm.Risks;
//### END OF DELETE
//### BEGIN OF INSERT
entity Risks @(restrict : [
{
grant : [ 'READ' ],
to : [ 'RiskViewer' ]
},
{
grant : [ '*' ],
to : [ 'RiskManager' ]
}
]) as projection on rm.Risks;
//### END OF INSERT
annotate Risks with @odata.draft.enabled;
//### BEGIN OF DELETE
entity Mitigations as projection on rm.Mitigations;
//### END OF DELETE
//### BEGIN OF INSERT
entity Mitigations @(restrict : [
{
grant : [ 'READ' ],
to : [ 'RiskViewer' ]
},
{
grant : [ '*' ],
to : [ 'RiskManager' ]
}
]) as projection on rm.Mitigations;
//### END OF INSERT
annotate Mitigations with @odata.draft.enabled;
entity BusinessPartners as projection on rm.BusinessPartners;
}
Code for .cdsrc file
{
"[development]": {
"auth": {
"passport": {
"strategy": "mock",
"users": {
"risk.viewer@tester.sap.com": {
"password": "initial",
"ID": "riskviewer",
"userAttributes": {
"email": "risk.viewer@tester.sap.com"
},
"roles": ["RiskViewer"]
},
"risk.manager@tester.sap.com": {
"password": "initial",
"ID": "riskmanager",
"userAttributes": {
"email": "risk.manager@tester.sap.com"
},
"roles": ["RiskManager"]
}
}
}
}
}
}
Command to install hdb module and add it as dependency to package.json file
npm i --save @sap/xssec @sap/xsenv
Command to compile project to xs-security.json file
cds compile srv --to xsuaa >xs-security.json
Additional lines for risk-management-xsuaa resource in mta.yaml file
config:
xsappname: 'risk-management-${space}'
role-collections:
- name: 'RiskManager-${space}'
description: Manage Risks
role-template-references:
- $XSAPPNAME.RiskManager
- name: 'RiskViewer-${space}'
description: View Risks
role-template-references:
- $XSAPPNAME.RiskViewer
Command to get the required Node.js version
cat node_modules/@sap/approuter/package.json | grep '"node"'
Lines to be added and removed in approuter/package.json file
Note: Lines starting with //### BEGIN OF INSERT and ending with //### END OF INSERT have been added to the previous version of the file. Lines starting with //### BEGIN OF DELETE and ending with //### END OF DELETE need to be removed from the file.
{
"name": "approuter",
...
"scripts": {
//### BEGIN OF DELETE
"test": "echo \"Error: no test specified\" && exit 1"
//### END OF DELETE
//### BEGIN OF INSERT
"start": "node node_modules/@sap/approuter/approuter.js"
//### END OF INSERT
},
...
"dependencies": {
"@sap/approuter": "^8.5.5"
//### BEGIN OF DELETE
}
//### END OF DELETE
//### BEGIN OF INSERT
},
"engines": {
"node": "^14.0.0"
}
//### END OF INSERT
}
Content for xs-app.json file
{
"welcomeFile": "/app/risks/webapp/index.html",
"authenticationMethod": "route",
"sessionTimeout": 30,
"logout": {
"logoutEndpoint": "/do/logout",
"logoutPage": "/"
},
"routes": [
{
"source": "^/app/(.*)$",
"target": "$1",
"localDir": "resources",
"authenticationType": "xsuaa"
},
{
"source": "^/service/(.*)$",
"destination": "srv-binding",
"authenticationType": "xsuaa"
}
]
}
Additional lines for mta.yaml file
# -------------------- APPROUTER -----------------------------
- name: risk-management-approuter
# ------------------------------------------------------------
type: nodejs
path: approuter
requires:
- name: risk-management-xsuaa
- name: srv-api
group: destinations
properties:
forwardAuthToken: true
strictSSL: true
name: srv-binding
url: "~{srv-url}"
build-parameters:
requires:
- name: risk-management-app
artifacts:
- ./*
target-path: resources
# -------------------- UI -----------------------------------
- name: risk-management-app
# ------------------------------------------------------------
type: html5
path: app
build-parameters:
supported-platforms: []
New content for .pipeline/config.yml file
###
# This file configures the project “Piper” pipeline of your project.
# For a reference of the configuration concept and available options, please have a look into its documentation.
#
# The documentation for the most recent pipeline version can always be found at:
# https://sap.github.io/jenkins-library/
#
# This is a YAML-file. YAML is an indentation-sensitive file format. Please make sure to properly indent changes to it.
###
### General project setup
---
general:
pipeline: "sap-cloud-sdk"
buildTool: "mta"
stages:
Build:
mavenExecuteStaticCodeChecks: false
npmExecuteLint: false
Additional Unit Tests:
npmExecuteScripts: false
karmaExecuteTests: false
Release:
cloudFoundryDeploy: true
tmsUpload: false
steps:
cloudFoundryDeploy:
cloudFoundry:
apiEndpoint: "https://api.cf.eu10.hana.ondemand.com"
org: "myOrg"
space: "mySpace"
credentialsId: "myDeploymentCredentialsId" # set this to 'cfdeploy'
appName: ""
mtaDeployParameters: "-f --version-rule ALL"
artifactPrepareVersion:
versioningType: "cloud_noTag"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 | |
1 |