SAP CAP篇一:快速创建一个Service,基于Java的实现
SAP CAP篇二:为Service加上数据库支持
SAP CAP篇三:定义Model
添加Fiori Elements程序之前,首先先定义业务场景。SAP CAP 采用Book Shop作为业务场景,我们不妨也使用类似的业务背景。
使用如下的简易Model:
其中,Book Category
以及Book
只能被Admin维护。普通用户可以查看Book
并将其添加到Wish List
。
至于是Wish List
还是Shopping List
,对本篇主要是阐述“添加Fiori Elements程序”而言,没有本质区别。
首先,看看DB Schema的定义:
entity Books : cuid, managed {
title : localized String(111);
descr : localized String(1111);
stock : Integer;
price : Decimal(9,2);
currency : Currency;
category : Association to Categories;
}
entity Categories : CodeList {
key ID : Integer;
parent : Association to Categories;
children : Composition of many Categories on children.parent = $self;
}
entity WishLists: managed {
key userID : User;
key book : Association to Books;
}
这里,定义两个Service。
这个Service是给后台Admin使用的。
using { alvachien.learncap.db as db } from '../db/schema';
service AdminService {
entity Books as projection on db.Books;
entity Categories as projection on db.Categories;
}
这个Service是给前台用户使用的。
service AdminService {
@readonly
entity Products as projection on db.Books;
@readonly
entity Categories as projection on db.Categories;
entity WishLists as projection on db.WishLists;
}
app
文件夹在项目文件夹中,创建app
文件夹。这里的app
文件夹实际上为approuter
准备的,但是这个文件夹在本地开发测试的时候也非常有用。
并在文件夹中添加如下文件:
appconfig
folderpackage.json
正如之前提到的那样,这里的这个nodejs
程序,是用于approuter
,所以,package.json
的定义如下:
{
"name": "approuter",
"dependencies": {
"@sap/approuter": "^13"
},
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js"
}
}
fiori.html
文件fiori.html
是用作Fiori Launchpad
的入口程序——类似于绝大多数的HTML程序的index.html
一样。所以,这个fiori.html
是标准的Fiori Launchpad
的定义文件。
DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fiorititle>
<script>
window["sap-ushell-config"] = {
defaultRenderer: "fiori2",
applications: {}
};
script>
<script id="sap-ushell-bootstrap" src="https://sapui5.hana.ondemand.com/1.115.0/test-resources/sap/ushell/bootstrap/sandbox.js">script>
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/1.115.0/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
data-sap-ui-compatVersion="edge"
data-sap-ui-theme="sap_horizon"
data-sap-ui-frameOptions="allow">
script>
<script>
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))
script>
head>
<body class="sapUiBody" id="content">body>
html>
appconfig
文件夹appconfig
用来提供Fiori Launchpad
的Sandbox系统。真正Deploy到SAP BTP上时,需要遵循Launchpad 定义的标准。
{
"services": {
"LaunchPage": {
"adapter": {
"config": {
"catalogs": [],
"groups": [
{
"id": "Admin",
"title": "Admin",
"isPreset": true,
"isVisible": true,
"isGroupLocked": false,
"tiles": [
{
"id": "manage-books",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"targetURL": "#Books-manage",
"title": "Manage Books",
"description": "Find your favorite book"
}
}
]
}, {
"id": "Book",
"title": "Book",
"isPreset": true,
"isVisible": true,
"isGroupLocked": false,
"tiles": [
{
"id": "browse-books",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"targetURL": "#Books-display",
"title": "Display Books",
"description": "Find your favorite book"
}
}
]
}
]
}
}
},
"NavTargetResolution": {
"config": {
"enableClientSideTargetResolution": true
}
},
"ClientSideTargetResolution": {
"adapter": {
"config": {
"inbounds": {
"manage-books": {
"semanticObject": "Books",
"action": "manage",
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=manage-books",
"url": "/manage-books/webapp"
}
},
"browse-books": {
"semanticObject": "Books",
"action": "display",
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=browse-books",
"url": "/browse-books/webapp"
}
}
}
}
}
}
}
}
这里暂时对该文件的内容,暂时不具体介绍。
未完待续。