Skip to content

Commit

Permalink
Cleanup destinations, read API key from env
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Nov 30, 2020
1 parent df965aa commit 1f2718f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 86 deletions.
66 changes: 2 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ To run against the local mock service [epmbp-mock-service](https://github.com/gr
{
"name": "ES5",
"url": "http://localhost:3000/sap/opu/odata/sap/EPM_REF_APPS_PROD_MAN_SRV"
},
{
"name": "ES5_SDK",
"url": "http://localhost:3000/"
}
]
}
Expand All @@ -43,12 +39,6 @@ If you want to da a local test against the ES5 system then use this content for
"url": "https://sapes5.sapdevcenter.com/sap/opu/odata/sap/EPM_REF_APPS_PROD_MAN_SRV",
"username": "<Your ES5 Username>",
"password": "<Your ES5 Password>"
},
{
"name": "ES5_SDK",
"url": "https://sapes5.sapdevcenter.com",
"username": "<Your ES5 Username>",
"password": "<Your ES5 Password>"
}
]
}
Expand Down Expand Up @@ -80,7 +70,7 @@ Optional

### Preperation for a Connection to ES5

Destination ES5 used by the approuter:
Destination ES5 used by the approuter, CAP and SAP Cloud SDK:

```properties
Description=SAP Gateway Demo System
Expand All @@ -95,39 +85,9 @@ User=<Your ES5 Username>
WebIDESystem=ES5
```

Destination ES5 used by the CAP:

```properties
Description=SAP Gateway Demo System
Type=HTTP
Authentication=BasicAuthentication
WebIDEUsage=odata_abap,ui5_execute_abap,dev_abap,bsp_execute_abap
Name=ES5
WebIDEEnabled=true
URL=https\://sapes5.sapdevcenter.com/sap/opu/odata/sap/EPM_REF_APPS_PROD_MAN_SRV
ProxyType=Internet
User=<Your ES5 Username>
WebIDESystem=ES5
```

Destination ES5_SDK used by the SAP Cloud SDK:

```properties
Description=SAP Gateway Demo System
Type=HTTP
Authentication=BasicAuthentication
WebIDEUsage=odata_abap,ui5_execute_abap,dev_abap,bsp_execute_abap
Name=ES5_SDK
WebIDEEnabled=true
URL=https\://sapes5.sapdevcenter.com
ProxyType=Internet
User=<Your ES5 Username>
WebIDESystem=ES5_SDK
```

### Preperation for on premise connection with principal propagation

Destination ES5 used by the approuter:
Destination ES5 used by the approuter, CAP and SAP Cloud SDK:

```properties
URL=http\://<Virtual Hostname of your ABAP Backend>\:<Virtual Port of your ABAP Backend>
Expand All @@ -138,28 +98,6 @@ sap-client=001
Authentication=PrincipalPropagation
```

Destination ES5 used by the CAP:

```properties
URL=http\://<Virtual Hostname of your ABAP Backend>\:<Virtual Port of your ABAP Backend>/sap/opu/odata/sap/EPM_REF_APPS_PROD_MAN_SRV
Name=ES5
ProxyType=OnPremise
Type=HTTP
sap-client=001
Authentication=PrincipalPropagation
```

Destination ES5_SDK used by the SAP Cloud SDK:

```properties
URL=http\://<Virtual Hostname of your ABAP Backend>\:<Virtual Port of your ABAP Backend>
Name=ES5_SDK
ProxyType=OnPremise
Type=HTTP
sap-client=001
Authentication=NoAuthentication
```

### Build

`npm run build:cf`
Expand Down
1 change: 1 addition & 0 deletions app/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ <h2>CAP only API</h2>
<h2>Reading from Backend via CAP Middleware using Cloud SDK</h2>
<ul>
<li><a href="/catalog/sdkSuppliers">/catalog/sdkSuppliers</a></li>
<li><a href="/catalog/sdkBusinessPartner">/catalog/sdkBusinessPartner</a></li>
<!--
<li><a href="/catalog/Orders?$expand=EPMBusinessPartner">/catalog/Orders?$expand=EPMBusinessPartner</a></li>
-->
Expand Down
29 changes: 7 additions & 22 deletions srv/service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const cds = require('@sap/cds')
const { retrieveJwt } = require('@sap/cloud-sdk-core')

/*
const createFilter = xs => {
const andFilters = xs.map(x => new FilterList([
Expand Down Expand Up @@ -33,7 +35,7 @@ module.exports = async function (){
const externalService = await cds.connect.to('EPM_REF_APPS_PROD_MAN_SRV')
const { Products: externalProducts, Suppliers: externalSuppliers } = externalService.entities

const destinationName = 'ES5_SDK'
const destinationName = 'ES5'
const destinationS4Name = 'APIBusinessHub'


Expand Down Expand Up @@ -79,16 +81,17 @@ module.exports = async function (){
}
})
*/
this.on('READ', 'sdkBusinessPartner', async (results, req) => {
this.on('READ', 'sdkBusinessPartner', async (req, next) => {
var jwt = getJWT(req)
try{
// Read API Key from Envoronment
const apikey = JSON.parse(process.env.destinations).filter(destination => destination.name === "APIBusinessHub")[0].apikey;
const businessPartners = await sdkBusinessPartner
.requestBuilder()
.getAll()
.top(2)
.withCustomHeaders({
apikey: 'myApiKey'
apikey: apikey
})
.execute({ destinationName: destinationS4Name, jwt: jwt})
// console.log("epmSuppliers: " + JSON.stringify(epmSuppliers))
Expand All @@ -103,7 +106,7 @@ module.exports = async function (){
message: e.message,
numericSeverity: 4
}
results.error(msgError)
req.error(msgError)
return {}
}
})
Expand Down Expand Up @@ -140,7 +143,6 @@ module.exports = async function (){

this.on('READ', 'Products', async (req) => {
const tx = externalService.transaction(req)
// var cqn = getCQNforREAD(externalProducts, req)
try {
// let result = await tx.run(cqn)
console.info(req.query)
Expand All @@ -153,20 +155,3 @@ module.exports = async function (){
}
})
}

function getCQNforREAD(entity, req) {
var cqn = SELECT.from(entity)
if(req.query.SELECT.limit) {
cqn.SELECT.limit = req.query.SELECT.limit
}
if(req.query && req.query.SELECT.columns) {
cqn.SELECT.columns = req.query.SELECT.columns
}
if(req.query && req.query.SELECT.where) {
cqn.SELECT.where = req.query.SELECT.where
}
if(req.query.SELECT.orderBy) {
cqn.SELECT.orderBy = req.query.SELECT.orderBy
}
return cqn
}

0 comments on commit 1f2718f

Please sign in to comment.