Skip to content

Commit

Permalink
Update the PR based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipto-at-sap committed Dec 2, 2024
1 parent 2b2e379 commit 6d0f266
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 28 deletions.
14 changes: 11 additions & 3 deletions __tests__/__snapshots__/ordCdsrc.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
],
},
],
"mandatory": true,
"title": "Integration Aspect sample title",
},
],
"description": "Integration Dependency sample description",
"lastUpdate": "2024-11-04T14:33:25+01:00",
"mandatory": true,
"ordId": "sap.test.cdsrc.sample:integrationDependency:sap.s4.beh.businesspartner.v1.BusinessPartner:v1",
Expand Down Expand Up @@ -198,6 +195,17 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
"vendor": "customer:vendor:Customer:",
"version": "1.0.1",
},
{
"description": "Description for capire bookshop ord sample",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-integration-dependency:v1",
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description for capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for capire bookshop ord sample version 2",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-api:v2",
Expand Down
3 changes: 0 additions & 3 deletions __tests__/__snapshots__/ordPackageJson.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,8 @@ exports[`Tests for default ORD document when .cdsrc.json is not present Successf
],
},
],
"mandatory": true,
"title": "Integration Aspect sample title",
},
],
"description": "Integration Dependency sample description",
"lastUpdate": "2024-11-04T14:33:25+01:00",
"mandatory": true,
"ordId": "customer.capirebookshopordsample:integrationDependency:sap.s4.beh.businesspartner.v1.BusinessPartner:v1",
Expand Down
26 changes: 26 additions & 0 deletions __tests__/bookshop/ord/custom.ord.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,31 @@
"sap.sm:entityType:BusinessPartner:v1"
]
}
],
"integrationDependencies": [
{
"ordId": "sap.test.cdsrc.sample:integrationDependency:sap.s4.beh.businesspartner.v1.BusinessPartner:v1",
"title": "Integration Dependency sample title",
"mandatory": true,
"partOfPackage": "sap.test.cdsrc.sample:package:capirebookshopordsample-api:v1",
"lastUpdate": "2024-11-04T14:33:25+01:00",
"releaseStatus": "active",
"version": "1.0.0",
"visibility": "public",
"aspects": [
{
"eventResources": [
{
"ordId": "sap.test.cdsrc.sample:eventResource:sap.s4.beh.businesspartner.v1.BusinessPartner:v1",
"subset": [
{
"eventType": "sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1"
}
]
}
]
}
]
}
]
}
11 changes: 11 additions & 0 deletions __tests__/unittest/__snapshots__/defaults.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ exports[`defaults packages should return default value if policyLevel contains s
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for My Package",
"ordId": "customer.sample:package:MyPackage-integration-dependency:v1",
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
]
`;

Expand Down
12 changes: 6 additions & 6 deletions __tests__/unittest/__snapshots__/templates.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ exports[`templates createIntegrationDependencyTemplate should create integration
"subset": [],
},
],
"mandatory": true,
"title": "Integration Aspect sample title",
},
],
"description": "Integration Dependency sample description",
"extensible": {
"supported": "yes",
},
"lastUpdate": "2022-12-19T15:47:04+00:00",
"mandatory": true,
"ordId": "customer.testNamespace:integrationDependency:MyService:v1",
"partOfPackage": "customer.testNamespace:package:test:v1",
"partOfPackage": "sap.test.cdsrc.sample:package:test-other:v1",
"releaseStatus": "active",
"title": "Integration Dependency sample title",
"version": "1.0.0",
"title": "This is test MyService integrationDependency title",
"version": "2.0.0",
"visibility": "public",
}
`;
Expand Down
9 changes: 9 additions & 0 deletions __tests__/unittest/templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ describe('templates', () => {
title: String;
}
}
annotate MyService with @ORD.Extensions : {
title : 'This is test MyService integrationDependency title',
visibility : 'public',
version : '2.0.0',
partOfPackage : 'sap.test.cdsrc.sample:package:test-other:v1',
extensible : {
supported : 'yes'
}
};
`);
const srvDefinition = linkedModel.definitions[serviceName];
const packageIds = ['customer.testNamespace:package:test:v1'];
Expand Down
3 changes: 2 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const ORD_ODM_ENTITY_NAME_ANNOTATION = "@ODM.entityName";

const ORD_RESOURCE_TYPE = Object.freeze({
api: "api",
event: "event"
event: "event",
integrationDependency: "integration-dependency"
});

const RESOURCE_VISIBILITY = Object.freeze({
Expand Down
1 change: 1 addition & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = {
return [
createPackage(name, "-api:v1"),
createPackage(name, "-event:v1"),
createPackage(name,"-integration-dependency:v1")
];
} else {
return [createPackage(name, ":v1")];
Expand Down
11 changes: 3 additions & 8 deletions lib/ord.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const _ = require("lodash");
const cds = require("@sap/cds");
const defaults = require("./defaults");
const path = require("path");
const { exists } = require('@sap/cds/lib/utils/cds-utils');

const initializeAppConfig = (csn) => {
let packageJsonPath = path.join(cds.root, 'package.json')
Expand All @@ -32,10 +31,6 @@ const initializeAppConfig = (csn) => {
const modelKeys = Object.keys(csn.definitions);
const apiEndpoints = new Set();
const events = [];
let externalServiceKeys = [];
if (packageJson.cds && packageJson.cds.requires) {
externalServiceKeys = Object.keys(packageJson.cds.requires);
}
const serviceNames = [];
const lastUpdate = getRFC3339Date();
const externalServices = [];
Expand Down Expand Up @@ -76,12 +71,12 @@ const initializeAppConfig = (csn) => {
}
}

if (packageJson.cds && packageJson.cds.requires) {
for (const key of externalServiceKeys) {
if (packageJson.cds?.requires) {
for (const key of Object.keys(packageJson.cds.requires)) {
const service = packageJson.cds.requires[key];
if (
service?.kind?.startsWith("odata") &&
[".cds", ".csn"].some((ext) => exists(path.join(cds.root, `${service.model}${ext}`)))
[".cds", ".csn"].some((ext) => cds.utils.exists(path.join(cds.root, `${service.model}${ext}`)))
) {
externalServices.push(key);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,14 @@ const createIntegrationDependencyTemplate = (serviceName, serviceDefinition, app
return {
ordId: `${appConfig.ordNamespace}:integrationDependency:${serviceName}:v1`,
title: ordExtensions.title ?? serviceDefinition['@title'] ?? "Integration Dependency sample title",
partOfPackage: _getPackageID(appConfig.ordNamespace, packageIds, "integration"),
partOfPackage: _getPackageID(appConfig.ordNamespace, packageIds, ORD_RESOURCE_TYPE.integrationDependency),
version: ordExtensions.version ?? "1.0.0",
visibility: ordExtensions.visibility ?? "public",
visibility: ordExtensions.visibility ?? RESOURCE_VISIBILITY.public,
lastUpdate: appConfig.lastUpdate,
description: ordExtensions.description ?? serviceDefinition['@description'] ?? "Integration Dependency sample description",
mandatory: ordExtensions.mandatory ?? true,
releaseStatus: ordExtensions.releaseStatus ?? "active",
aspects: [
{
title: ordExtensions.aspectTitle ?? "Integration Aspect sample title",
mandatory: ordExtensions.aspectMandatory ?? true,
eventResources: [
{
ordId: `${appConfig.ordNamespace}:eventResource:${serviceDefinition.name}:v1`,
Expand Down
26 changes: 26 additions & 0 deletions xmpl/ord/custom.ord.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,31 @@
"supported": "yes"
}
}
],
"integrationDependencies": [
{
"ordId": "sap.test.cdsrc.sample:integrationDependency:sap.s4.beh.businesspartner.v1.BusinessPartner:v1",
"title": "Integration Dependency sample title",
"mandatory": true,
"partOfPackage": "sap.test.cdsrc.sample:package:capirebookshopordsample-integration-dependency:v1",
"lastUpdate": "2024-11-04T14:33:25+01:00",
"releaseStatus": "active",
"version": "1.0.0",
"visibility": "public",
"aspects": [
{
"eventResources": [
{
"ordId": "sap.test.cdsrc.sample:eventResource:sap.s4.beh.businesspartner.v1.BusinessPartner:v1",
"subset": [
{
"eventType": "sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1"
}
]
}
]
}
]
}
]
}
12 changes: 10 additions & 2 deletions xmpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
"devDependencies": {
"@cap-js/sqlite": "*"
},
"private": true
}
"private": true,
"cds": {
"requires": {
"sap.s4.beh.businesspartner.v1.BusinessPartner": {
"kind": "odata",
"model": "srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi"
}
}
}
}
36 changes: 36 additions & 0 deletions xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* checksum : 7c2129da2e89fec3fefa1cfb12090b2c */
@cds.external : 'true'
@AsyncAPI.Extensions : {
![sap-catalog-spec-version]: '1.0',
![sap-api-type] : 'EVENT'
}
@AsyncAPI.ShortText : 'Informs a remote system about created and changed business partners in an SAP S/4HANA Cloud tenant.'
@AsyncAPI.StateInfo : {state: 'ACTIVE'}
@AsyncAPI.Title : 'Business Partner Events'
@AsyncAPI.SchemaVersion: '1.0.0'
@AsyncAPI.Description : ```
A business partner is an organization (company, subsidiary), person or group of people or organizations in which your company has a business interest. The following events are available for business partner:\r
\r
* Business partner changed\r
* Business partner created
```
service sap.s4.beh.businesspartner.v1.BusinessPartner {};

@cds.external: 'true'
@topic : 'sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1'
event sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1 {
BusinessPartner : LargeString;
};

@cds.external: 'true'
@topic : 'sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1'
event sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1 {
BusinessPartner : LargeString;
};

annotate sap.s4.beh.businesspartner.v1.BusinessPartner with @ORD.Extensions: {
title : 'This is Own Service title',
shortDescription: 'short description for OwnService',
visibility : 'public',
extensible : {supported: 'no'}
};
Loading

0 comments on commit 6d0f266

Please sign in to comment.