Simplified Extension Example

This commit is contained in:
nkaputnik
2021-05-26 11:55:16 +02:00
parent 1e034e964e
commit bbd09b1697
13 changed files with 535 additions and 345 deletions

View File

@@ -1,65 +1,44 @@
using {sap.capire.bookshop} from '_base/db/schema';
using {sap.capire.orders} from '_base/db/schema';
using from '_base/db/capire_common';
using {
cuid, managed, Country, sap.common.CodeList
} from '@sap/cds/common';
namespace Z_bookshop.extension;
// extend existing entity
extend orders.Orders with {
Z_Customer : Association to one Z_Customers;
Z_SalesRegion : Association to one Z_SalesRegion;
Z_priority : String @assert.range enum {high; medium; low} default 'medium';
Z_Remarks : Composition of many Z_Remarks on Z_Remarks.parent = $self;
}
// new entity - as association target
entity Z_Customers : cuid, managed
{
email : String;
firstName : String;
lastName : String;
creditCardNo : String;
dateOfBirth : Date;
status : String @assert.range enum {platinum; gold; silver; bronze} default 'bronze';
creditScore : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0;
PostalAddresses : Composition of many Z_CustomerPostalAddresses on PostalAddresses.Customer = $self;
}
// new unique constraint (secondary index)
annotate Z_Customers with @assert.unique: { email: [ email ] }
{
email @mandatory; // mandatory check
}
// new entity - as composition target
entity Z_CustomerPostalAddresses : cuid, managed
{
Customer : Association to one Z_Customers;
description : String;
street : String;
town : String;
country : Country;
}
// new entity - as code list
entity Z_SalesRegion: CodeList {
key regionCode : String(11);
}
// new entity - as composition target
entity Z_Remarks : cuid, managed
{
parent : Association to one orders.Orders;
number : Integer;
remarksLine : String;
}
using {sap.capire.bookshop} from '_base/db/schema';
using {sap.capire.orders} from '_base/db/schema';
using from '_base/db/capire_common';
//using {Z_bookshop.fieldExtension as field} from './field_extension';
using {
cuid, managed, Country, sap.common.CodeList
} from '@sap/cds/common';
namespace Z_bookshop.assocExtension;
// extend existing entity
extend orders.Orders with {
Z_Customer : Association to one Z_Customers;
Z_SalesRegion : Association to one Z_SalesRegion;
}
// new entity - as association target
entity Z_Customers : cuid, managed
{
email : String;
firstName : String;
lastName : String;
creditCardNo : String;
dateOfBirth : Date;
status : String @assert.range enum {platinum; gold; silver; bronze} default 'bronze';
creditScore : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0;
}
// new unique constraint (secondary index)
annotate Z_Customers with @assert.unique: { email: [ email ] }
{
email @mandatory; // mandatory check
}
// new entity - as code list
entity Z_SalesRegion: CodeList {
key regionCode : String(11);
}

41
db/comp_extension.cds_ Normal file
View File

@@ -0,0 +1,41 @@
using {sap.capire.bookshop} from '_base/db/schema';
using {sap.capire.orders} from '_base/db/schema';
using from '_base/db/capire_common';
using {Z_bookshop.assocExtension as assoc} from './assoc_extension';
using {
cuid, managed, Country, sap.common.CodeList
} from '@sap/cds/common';
namespace Z_bookshop.compExtension;
// extend existing entity
extend orders.Orders with {
Z_Remarks : Composition of many Z_Remarks on Z_Remarks.parent = $self;
}
// new entity - as composition target
entity Z_CustomerPostalAddresses : cuid, managed
{
Customer : Association to one assoc.Z_Customers;
description : String;
street : String;
town : String;
country : Country;
}
// new entity - as composition target
entity Z_Remarks : cuid, managed
{
parent : Association to one orders.Orders;
number : Integer;
remarksLine : String;
}
extend assoc.Z_Customers with {
PostalAddresses : Composition of many Z_CustomerPostalAddresses on PostalAddresses.Customer = $self;
}

View File

@@ -1,5 +1,5 @@
ID;modifiedAt;createdAt;createdBy;modifiedBy;Customer_ID;description;street;town;country_code
1e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-04-04;2019-01-31;admin@business.com;admin@business.com;8e2f2640-6866-4dcf-8f4d-3027aa831cad;Home;Hauptstrasse 11;Berlin;DE
24e718c9-ff99-47f1-8ca3-950c850777d4;2019-04-04;2019-01-30;admin@business.com;admin@business.com;74e718c9-ff99-47f1-8ca3-950c850777d4;Home;Main Street 22;London;GB
3e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-04-04;2019-01-31;admin@business.com;admin@business.com;8e2f2640-6866-4dcf-8f4d-3027aa831cad;Work;Siemensstrasse 21;Berlin;DE
44e718c9-ff99-47f1-8ca3-950c850777d4;2019-04-04;2019-01-30;admin@business.com;admin@business.com;74e718c9-ff99-47f1-8ca3-950c850777d4;Work;Work Street 34;London;GB
ID;modifiedAt;createdAt;createdBy;modifiedBy;Customer_ID;description;street;town;country_code
1e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-04-04;2019-01-31;admin@business.com;admin@business.com;8e2f2640-6866-4dcf-8f4d-3027aa831cad;Home;Hauptstrasse 11;Berlin;DE
24e718c9-ff99-47f1-8ca3-950c850777d4;2019-04-04;2019-01-30;admin@business.com;admin@business.com;74e718c9-ff99-47f1-8ca3-950c850777d4;Home;Main Street 22;London;GB
3e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-04-04;2019-01-31;admin@business.com;admin@business.com;8e2f2640-6866-4dcf-8f4d-3027aa831cad;Work;Siemensstrasse 21;Berlin;DE
44e718c9-ff99-47f1-8ca3-950c850777d4;2019-04-04;2019-01-30;admin@business.com;admin@business.com;74e718c9-ff99-47f1-8ca3-950c850777d4;Work;Work Street 34;London;GB

View File

@@ -1,3 +1,3 @@
ID;modifiedAt;createdAt;createdBy;modifiedBy;email;firstName;lastName;creditCardNo;dateOfBirth;status;creditScore
8e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-04-04;2019-01-31;admin@business.com;admin@business.com;john.doe@test.com;John;Doe;9977-6655-4433-2211;1970-01-01;gold;80.0
ID;modifiedAt;createdAt;createdBy;modifiedBy;email;firstName;lastName;creditCardNo;dateOfBirth;status;creditScore
8e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-04-04;2019-01-31;admin@business.com;admin@business.com;john.doe@test.com;John;Doe;9977-6655-4433-2211;1970-01-01;gold;80.0
74e718c9-ff99-47f1-8ca3-950c850777d4;2019-04-04;2019-01-30;admin@business.com;admin@business.com;jane.doe@sap.com;Jane;Doe;2211-3344-5566-7788;1980-11-11;platinum;100.0

View File

@@ -1,4 +1,4 @@
regionCode;name;descr
AMER;Americas;North, Central and South America
EMEA;Europe, the Middle East and Africa;Europe, the Middle East and Africa
regionCode;name;descr
AMER;Americas;North, Central and South America
EMEA;Europe, the Middle East and Africa;Europe, the Middle East and Africa
APJ;Asia Pacific and Japan;Asia Pacific and Japan

View File

@@ -1,3 +1,3 @@
ID;createdAt;createdBy;buyer;OrderNo;currency_code;Z_Customer_ID;Z_priority;Z_SalesRegion_regionCode
7e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-01-31;john.doe@test.com;john.doe@test.com;1;EUR;8e2f2640-6866-4dcf-8f4d-3027aa831cad;high;EMEA
64e718c9-ff99-47f1-8ca3-950c850777d4;2019-01-30;jane.doe@test.com;jane.doe@test.com;2;EUR;74e718c9-ff99-47f1-8ca3-950c850777d4;low;APJ
ID;createdAt;createdBy;buyer;OrderNo;currency_code;Z_orderInfo;Z_internalNo;Z_expectedDelivery;Z_priority;Z_discount;
7e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-01-31;john.doe@test.com;john.doe@test.com;1;EUR;Webshop order;202001;2019-03-31;high;5.0
64e718c9-ff99-47f1-8ca3-950c850777d4;2019-01-30;jane.doe@test.com;jane.doe@test.com;2;EUR;Walk in order;202002;2019-04-15;low;10.0
1 ID ID;createdAt;createdBy;buyer;OrderNo;currency_code;Z_orderInfo;Z_internalNo;Z_expectedDelivery;Z_priority;Z_discount; createdAt createdBy buyer OrderNo currency_code Z_Customer_ID Z_priority Z_SalesRegion_regionCode
2 7e2f2640-6866-4dcf-8f4d-3027aa831cad 7e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-01-31;john.doe@test.com;john.doe@test.com;1;EUR;Webshop order;202001;2019-03-31;high;5.0 2019-01-31 john.doe@test.com john.doe@test.com 1 EUR 8e2f2640-6866-4dcf-8f4d-3027aa831cad high EMEA
3 64e718c9-ff99-47f1-8ca3-950c850777d4 64e718c9-ff99-47f1-8ca3-950c850777d4;2019-01-30;jane.doe@test.com;jane.doe@test.com;2;EUR;Walk in order;202002;2019-04-15;low;10.0 2019-01-30 jane.doe@test.com jane.doe@test.com 2 EUR 74e718c9-ff99-47f1-8ca3-950c850777d4 low APJ

View File

@@ -0,0 +1,3 @@
ID;createdAt;createdBy;buyer;OrderNo;currency_code;Z_Customer_ID;Z_priority;Z_SalesRegion_regionCode
7e2f2640-6866-4dcf-8f4d-3027aa831cad;2019-01-31;john.doe@test.com;john.doe@test.com;1;EUR;8e2f2640-6866-4dcf-8f4d-3027aa831cad;high;EMEA
64e718c9-ff99-47f1-8ca3-950c850777d4;2019-01-30;jane.doe@test.com;jane.doe@test.com;2;EUR;74e718c9-ff99-47f1-8ca3-950c850777d4;low;APJ

38
db/field_extension.cds Normal file
View File

@@ -0,0 +1,38 @@
using {sap.capire.bookshop} from '_base/db/schema';
using {sap.capire.orders} from '_base/db/schema';
using from '_base/db/capire_common';
using {
cuid,
managed,
Country,
sap.common.CodeList
} from '@sap/cds/common';
namespace Z_bookshop.fieldExtension;
// extend existing entity
extend orders.Orders with {
Z_orderInfo : String default 'Webshop order';
Z_internalNo : Integer; // uniqiue constraint
Z_expectedDelivery : Date; //mandatory
Z_priority : String
@assert.range enum {
high;
medium;
low
} default 'medium';
Z_discount : Decimal
@assert.range : [
0.0,
99.9
] default 0.0;
}
// new unique constraint (secondary index)
annotate orders.Orders with @assert.unique : {Z_internalNo : [Z_internalNo]} {
Z_expectedDelivery @mandatory; // mandatory check
}