应用 cds init
初始化一个 CAP 利用,而后 npm install
, cds watch
启动服务器。
创立一个 schema 文件,内容如下:
namespace sap.ui.riskmanagement;using { managed } from '@sap/cds/common'; entity Risks : managed { key ID : UUID @(Core.Computed : true); title : String(100); } entity Mitigations : managed { key ID : UUID @(Core.Computed : true); risks : Association to many Risks on risks.miti = $self; }
留神,schema 文件能够定义 namespace.
这两个模型的 key 由 CAP 服务器主动填充,该服务器应用正文 @(Core.Computed : true) 向服务用户公开。
只有 entity 还无奈被 end user 生产,须要通过 service 裸露给内部。
在 srv
文件夹里新建一个文件 risk-service.cds
,留神这个文件和 entity schema 文件在不同的文件夹(前者在 db
):
using { sap.ui.riskmanagement as my } from '../db/schema';@path: 'service/risk'service RiskService { entity Risks as projection on my.Risks; annotate Risks with @odata.draft.enabled; entity Mitigations as projection on my.Mitigations; annotate Mitigations with @odata.draft.enabled;}
应用 cds watch
看到的主动生成的页面:
这个 index.html 的模板文件地位:
node_modules\@sap\cds-dk\node_modules\@sap\cds\app\index.html
在应用程序平安文件 (xs-security.json) 中,role templates 属性使您可能定义一个数组,其中列出了拜访特定利用程序模块所需的一个或多个 roles
(具备相应的范畴和任何必须的属性)。能够定义多个角色模板,每个模板都有本人的范畴和属性。
一个例子:
"role-templates": [ { "name" : "Editor", "description" : "View, edit, delete books", "scope-references" : [ "$XSAPPNAME.Edit", "$XSAPPNAME.Delete" ], "attribute-references": [ "Country", "CostCenter" ] },]
必须实例化角色模板。 对于角色模板中定义的任何属性和具体的属性值尤其如此,这些属性须要定制,因而无奈主动提供。 只蕴含“本地”范畴的角色模板能够在没有用户交互的状况下被实例化。 对于 foreign scope 也是如此,其中范畴所有者已在某种白名单中申明批准(例如,供“公共”应用或已知“敌人”应用)。