From 6d0f266772db33a916712e5fb2c16412ed93915c Mon Sep 17 00:00:00 2001 From: Dipto-at-sap Date: Mon, 2 Dec 2024 18:17:10 +0530 Subject: [PATCH] Update the PR based on review comments --- __tests__/__snapshots__/ordCdsrc.test.js.snap | 14 +- .../__snapshots__/ordPackageJson.test.js.snap | 3 - __tests__/bookshop/ord/custom.ord.json | 26 +++ .../__snapshots__/defaults.test.js.snap | 11 ++ .../__snapshots__/templates.test.js.snap | 12 +- __tests__/unittest/templates.test.js | 9 + lib/constants.js | 3 +- lib/defaults.js | 1 + lib/ord.js | 11 +- lib/templates.js | 7 +- xmpl/ord/custom.ord.json | 26 +++ xmpl/package.json | 12 +- .../CE_BUSINESSPARTNEREVENTS.asyncapi.cds | 36 ++++ .../CE_BUSINESSPARTNEREVENTS.asyncapi.json | 162 ++++++++++++++++++ xmpl/srv/services.cds | 12 ++ 15 files changed, 317 insertions(+), 28 deletions(-) create mode 100644 xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.cds create mode 100644 xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.json diff --git a/__tests__/__snapshots__/ordCdsrc.test.js.snap b/__tests__/__snapshots__/ordCdsrc.test.js.snap index d02b4de..48b920d 100644 --- a/__tests__/__snapshots__/ordCdsrc.test.js.snap +++ b/__tests__/__snapshots__/ordCdsrc.test.js.snap @@ -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", @@ -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", diff --git a/__tests__/__snapshots__/ordPackageJson.test.js.snap b/__tests__/__snapshots__/ordPackageJson.test.js.snap index b896c84..201b484 100644 --- a/__tests__/__snapshots__/ordPackageJson.test.js.snap +++ b/__tests__/__snapshots__/ordPackageJson.test.js.snap @@ -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", diff --git a/__tests__/bookshop/ord/custom.ord.json b/__tests__/bookshop/ord/custom.ord.json index a15f260..e92639f 100644 --- a/__tests__/bookshop/ord/custom.ord.json +++ b/__tests__/bookshop/ord/custom.ord.json @@ -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" + } + ] + } + ] + } + ] + } ] } \ No newline at end of file diff --git a/__tests__/unittest/__snapshots__/defaults.test.js.snap b/__tests__/unittest/__snapshots__/defaults.test.js.snap index f80260c..6717e7b 100644 --- a/__tests__/unittest/__snapshots__/defaults.test.js.snap +++ b/__tests__/unittest/__snapshots__/defaults.test.js.snap @@ -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", + }, ] `; diff --git a/__tests__/unittest/__snapshots__/templates.test.js.snap b/__tests__/unittest/__snapshots__/templates.test.js.snap index 3bb4e0b..149095c 100644 --- a/__tests__/unittest/__snapshots__/templates.test.js.snap +++ b/__tests__/unittest/__snapshots__/templates.test.js.snap @@ -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", } `; diff --git a/__tests__/unittest/templates.test.js b/__tests__/unittest/templates.test.js index 8d2c927..c380821 100644 --- a/__tests__/unittest/templates.test.js +++ b/__tests__/unittest/templates.test.js @@ -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']; diff --git a/lib/constants.js b/lib/constants.js index 7b2761c..8db7f3e 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -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({ diff --git a/lib/defaults.js b/lib/defaults.js index 25cd939..9873d31 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -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")]; diff --git a/lib/ord.js b/lib/ord.js index c896e8d..74c966e 100644 --- a/lib/ord.js +++ b/lib/ord.js @@ -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') @@ -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 = []; @@ -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); } diff --git a/lib/templates.js b/lib/templates.js index eb44e0d..179aa61 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -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`, diff --git a/xmpl/ord/custom.ord.json b/xmpl/ord/custom.ord.json index 7ec683f..cad43ed 100644 --- a/xmpl/ord/custom.ord.json +++ b/xmpl/ord/custom.ord.json @@ -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" + } + ] + } + ] + } + ] + } ] } \ No newline at end of file diff --git a/xmpl/package.json b/xmpl/package.json index b79f885..c802f2a 100644 --- a/xmpl/package.json +++ b/xmpl/package.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.cds b/xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.cds new file mode 100644 index 0000000..0b838fa --- /dev/null +++ b/xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.cds @@ -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'} +}; diff --git a/xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.json b/xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.json new file mode 100644 index 0000000..7a18602 --- /dev/null +++ b/xmpl/srv/external/CE_BUSINESSPARTNEREVENTS.asyncapi.json @@ -0,0 +1,162 @@ +{ + "asyncapi": "2.0.0", + "x-sap-catalog-spec-version": "1.0", + "info": { + "title": "Business Partner Events", + "version": "1.0.0", + "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\n\r\n* Business partner changed\r\n* Business partner created" + }, + "x-sap-api-type": "EVENT", + "x-sap-shortText": "Informs a remote system about created and changed business partners in an SAP S/4HANA Cloud tenant.", + "x-sap-stateInfo": { + "state": "ACTIVE" + }, + "channels": { + "ce/sap/s4/beh/businesspartner/v1/BusinessPartner/Changed/v1": { + "subscribe": { + "message": { + "$ref": "#/components/messages/sap_s4_beh_businesspartner_v1_BusinessPartner_Changed_v1" + } + } + }, + "ce/sap/s4/beh/businesspartner/v1/BusinessPartner/Created/v1": { + "subscribe": { + "message": { + "$ref": "#/components/messages/sap_s4_beh_businesspartner_v1_BusinessPartner_Created_v1" + } + } + } + }, + "components": { + "messages": { + "sap_s4_beh_businesspartner_v1_BusinessPartner_Changed_v1": { + "name": "sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1", + "summary": "BusinessPartner Changed", + "description": "This event is raised when Business Partner is changed.", + "headers": { + "properties": { + "type": { + "const": "sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1" + }, + "datacontenttype": { + "const": "application/json" + } + } + }, + "payload": { + "$ref": "#/components/schemas/sap_s4_beh_businesspartner_v1_BusinessPartner_Changed_v1" + }, + "traits": [ + { + "$ref": "#/components/messageTraits/CloudEventContext" + } + ] + }, + "sap_s4_beh_businesspartner_v1_BusinessPartner_Created_v1": { + "name": "sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1", + "summary": "BusinessPartner Created", + "description": "This event is raised when Business Partner is created.", + "headers": { + "properties": { + "type": { + "const": "sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1" + }, + "datacontenttype": { + "const": "application/json" + } + } + }, + "payload": { + "$ref": "#/components/schemas/sap_s4_beh_businesspartner_v1_BusinessPartner_Created_v1" + }, + "traits": [ + { + "$ref": "#/components/messageTraits/CloudEventContext" + } + ] + } + }, + "schemas": { + "sap_s4_beh_businesspartner_v1_BusinessPartner_Changed_v1": { + "type": "object", + "properties": { + "BusinessPartner": { + "description": "# Definition\r\n\r\nKey identifying a **business partner** in the SAP system. The key is unique within a client.", + "type": "string", + "maxLength": 10 + } + } + }, + "sap_s4_beh_businesspartner_v1_BusinessPartner_Created_v1": { + "type": "object", + "properties": { + "BusinessPartner": { + "description": "# Definition\r\n\r\nKey identifying a **business partner** in the SAP system. The key is unique within a client.", + "type": "string", + "maxLength": 10 + } + } + } + }, + "messageTraits": { + "CloudEventContext": { + "headers": { + "type": "object", + "properties": { + "specversion": { + "description": "The version of the CloudEvents specification which the event uses. This enables the interpretation of the context.", + "type": "string", + "const": "1.0" + }, + "type": { + "description": "Type of occurrence which has happened. Often this property is used for routing, observability, policy enforcement, etc.", + "type": "string", + "minLength": 1 + }, + "source": { + "description": "This describes the event producer.", + "type": "string", + "format": "uri-reference" + }, + "subject": { + "description": "The subject of the event in the context of the event producer (identified by source).", + "type": "string", + "minLength": 1 + }, + "id": { + "description": "ID of the event.", + "type": "string", + "minLength": 1, + "examples": [ + "6925d08e-bc19-4ad7-902e-bd29721cc69b" + ] + }, + "time": { + "description": "Timestamp of when the occurrence happened. Must adhere to RFC 3339.", + "type": "string", + "format": "date-time", + "examples": [ + "2018-04-05T17:31:00Z" + ] + }, + "datacontenttype": { + "description": "Describe the data encoding format", + "type": "string", + "const": "application/json" + } + }, + "required": [ + "id", + "specversion", + "source", + "type" + ] + } + } + } + }, + "externalDocs": { + "description": "Business Documentation", + "url": "https://help.sap.com/http.svc/ahp2/SAP_S4HANA_CLOUD/2408.latest/EN/a7/5345282ddd4054a1e5ce7687e4b088/frameset.htm" + } +} \ No newline at end of file diff --git a/xmpl/srv/services.cds b/xmpl/srv/services.cds index 4e134c3..4bb348a 100644 --- a/xmpl/srv/services.cds +++ b/xmpl/srv/services.cds @@ -3,6 +3,7 @@ using { AdminService } from '@capire/incidents/srv/services'; using from '@capire/incidents/db/schema'; +using {sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1 as Created} from './external/CE_BUSINESSPARTNEREVENTS.asyncapi'; namespace sap.capire.incidents; @@ -40,6 +41,17 @@ annotate AdminService with @ORD.Extensions: { lineOfBusiness: ['Sales'] }; +service OwnService { + event BPCreated : projection on Created; +} + +annotate OwnService with @ORD.Extensions: { + title : 'This is Own Service title', + shortDescription: 'short description for OwnService', + visibility : 'public', + extensible : {supported: 'no'} +}; + annotate sap.capire.incidents.Customers with @ODM.entityName: 'Customers'; annotate sap.capire.incidents.Addresses with @ODM.entityName: 'Addresses'; annotate sap.capire.incidents.Incidents with @ODM.entityName: 'Incidents';