This commit is contained in:
Wolfgang Koch
2021-09-22 10:37:13 +02:00
parent 0a8ab2c137
commit 88c05a9c7f
4 changed files with 157 additions and 153 deletions

View File

@@ -6,39 +6,55 @@ using {
cuid, managed, Country, sap.common.CodeList
} from '@sap/cds/common';
namespace Z_bookshop.extension;
// extend existing entity
extend orders.Orders with {
Z_newField : String default 'Default Value';
Z_NewEntity : Association to one Z_NewEntity;
Z_NewCodeList : Association to one Z_NewCodeList;
Z_NewCompEntity : Composition of many Z_NewCompEntity on Z_NewCompEntity.parent = $self;
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_NewEntity : cuid, managed
entity Z_Customers : cuid, managed
{
description : String;
dateField : Date;
integerField : Integer;
stringField : String;
enumField : String @assert.range enum {high; medium; low} default 'medium';
rangeField : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0;
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 entity - as code list
entity Z_NewCodeList : CodeList {
key code : String(11);
// new unique constraint (secondary index)
annotate Z_Customers with @assert.unique: { email: [ email ] }
{
email @mandatory; // mandatory check
}
// new entity - as composition target
entity Z_NewCompEntity : cuid, managed
{
parent : Association to one orders.Orders;
description : String;
dateField : Date;
integerField : Integer;
stringField : String;
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;
}

View File

@@ -1,21 +0,0 @@
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_newDefaultField : String default 'Default Value';
Z_description : String;
Z_dateField : Date;
Z_integerField : Integer;
Z_stringField : String;
Z_enumField : String @assert.range enum {high; medium; low} default 'medium';
Z_rangeField : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0;
}

View File

@@ -4,7 +4,9 @@ using from '_base/srv/orders-service';
using { Z_bookshop.extension as ext } from '../db/extension';
extend service OrdersService with {
entity Z_NewEntity as projection on ext.Z_NewEntity ;
entity Z_NewCodeList as projection on ext.Z_NewCodeList;
}
entity Z_Customers as projection on ext.Z_Customers;
entity Z_SalesRegion as projection on ext.Z_SalesRegion;
}

View File

@@ -3,40 +3,84 @@ using OrdersService from './extension_service';
// new entity -- draft enabled
annotate OrdersService.Z_NewEntity with @odata.draft.enabled;
annotate OrdersService.Z_Customers with @odata.draft.enabled;
// new codelist entity -- draft enabled
annotate OrdersService.Z_SalesRegion with @odata.draft.enabled;
// new entity -- titles
annotate OrdersService.Z_NewEntity with {
description @title : 'Description';
integerField @title : 'Integer Field Title';
dateField @title : 'Date Field Title';
stringField @title : 'String Field Title';
enumField @title : 'Enum Field Title';
rangeField @title : 'Range Field Title';
annotate OrdersService.Z_Customers with {
ID @(
UI.Hidden,
Common : {Text : email}
);
firstName @title : 'First Name';
lastName @title : 'Last Name';
email @title : 'Email';
creditCardNo @title : 'Credit Card No';
dateOfBirth @title : 'Date of Birth';
status @title : 'Status';
creditScore @title : 'Credit Score';
}
// new entity -- titles
annotate OrdersService.Z_NewCodeList with {
code @title: 'Code Title';
annotate OrdersService.Z_CustomerPostalAddresses with {
ID @(
UI.Hidden,
Common : {Text : description}
);
description @title : 'Description';
street @title : 'Street';
town @title : 'Town';
country @title : 'Country';
}
// new entity -- titles
annotate OrdersService.Z_NewCompEntity with {
description @title : 'Description';
integerField @title : 'Integer Field Title';
dateField @title : 'Date Field Title';
stringField @title : 'String Field Title';
annotate OrdersService.Z_SalesRegion with {
regionCode @title: 'Region Code';
}
// new entity -- titles
annotate OrdersService.Z_Remarks with {
number @title: 'Remark Number';
remarksLine @title: 'Remark';
}
// new entity in service -- UI
annotate OrdersService.Z_NewEntity with @(UI : {
annotate OrdersService.Z_Customers with @(UI : {
HeaderInfo : {
TypeName : 'New Entity',
TypeNamePlural : 'New Entities',
TypeName : 'Customer',
TypeNamePlural : 'Customers',
Title : {
$Type : 'UI.DataField',
Value : email
}
},
LineItem : [
{Value : firstName},
{Value : lastName},
{Value : email},
{Value : status},
{Value : creditScore}
],
Facets : [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target : '@UI.FieldGroup#Main'},
{$Type: 'UI.ReferenceFacet', Label: 'Customer Postal Addresses', Target: 'PostalAddresses/@UI.LineItem'}
],
FieldGroup #Main : {Data : [
{Value : firstName},
{Value : lastName},
{Value : email},
{Value : status},
{Value : creditScore}
]}
} ) ;
// new entity -- UI
annotate OrdersService.Z_CustomerPostalAddresses with @(UI : {
HeaderInfo : {
TypeName : 'CustomerPostalAddress',
TypeNamePlural : 'CustomerPostalAddresses',
Title : {
$Type : 'UI.DataField',
Value : description
@@ -44,46 +88,47 @@ annotate OrdersService.Z_NewEntity with @(UI : {
},
LineItem : [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField},
{Value : enumField},
{Value : rangeField}
],
{Value : street},
{Value : town},
{Value : country_code}
],
Facets : [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target : '@UI.FieldGroup#Main'}
],
FieldGroup #Main : {Data : [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField},
{Value : enumField},
{Value : rangeField}
{Value : street},
{Value : town},
{Value : country_code}
]}
} ) ;
}, ) {
};
// new entity -- UI
annotate OrdersService.Z_NewCodeList with @(
annotate OrdersService.Z_SalesRegion with @(
UI: {
HeaderInfo: {
TypeName: 'New Code',
TypeNamePlural: 'New Codes',
TypeName: 'Sales Region',
TypeNamePlural: 'Sales Regions',
Title : {
$Type : 'UI.DataField',
Value : code
Value : regionCode
}
},
LineItem: [
{Value: code}
{Value: regionCode},
{Value: name},
{Value: descr}
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'}
],
FieldGroup#Main: {
Data: [
{Value: code}
{Value: regionCode},
{Value: name},
{Value: descr}
]
}
},
@@ -93,31 +138,27 @@ annotate OrdersService.Z_NewCodeList with @(
// new entity -- UI
annotate OrdersService.Z_NewCompEntity with @(
annotate OrdersService.Z_Remarks with @(
UI: {
HeaderInfo: {
TypeName: 'New Composition',
TypeNamePlural: 'New Compositions',
TypeName: 'Remark',
TypeNamePlural: 'Remarks',
Title : {
$Type : 'UI.DataField',
Value : description
Value : number
}
},
LineItem: [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField}
{Value: number},
{Value: remarksLine}
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'}
],
FieldGroup#Main: {
Data: [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField}
{Value: number},
{Value: remarksLine}
]
}
},
@@ -125,84 +166,50 @@ annotate OrdersService.Z_NewCompEntity with @(
};
// extend existing entity Orders with new extension fields and new composition
@odata.draft.enabled
annotate OrdersService.Orders with @(
UI: {
SelectionFields: [ createdAt, createdBy ],
LineItem: [
{Value: OrderNo, Label:'OrderNo'},
{Value: Z_newField, Label:'New Field'}, // extension field
{Value: Z_NewEntity_ID, Label:'New Entity'}, // extension field
{Value: Z_NewCodeList_code, Label:'New Code'}, // extension field
{Value: createdAt, Label:'Date'}
LineItem: [...,
{Value: Z_Customer_ID, Label:'Customer'}, // extension field
{Value: Z_SalesRegion_regionCode, Label:'Sales Region'}, // extension field
{Value: Z_priority, Label:'Priority'} // extension field
],
HeaderInfo: {
TypeName: 'Order', TypeNamePlural: 'Orders',
Title: {
Label: 'Order number ', //A label is possible but it is not considered on the ObjectPage yet
Value: OrderNo
},
Description: {Value: createdBy}
},
Identification: [ //Is the main field group
{Value: createdBy, Label:'Customer'},
{Value: createdAt, Label:'Date'},
{Value: OrderNo },
],
HeaderFacets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Created}', Target: '@UI.FieldGroup#Created'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Modified}', Target: '@UI.FieldGroup#Modified'},
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: 'Items/@UI.LineItem'},
{$Type: 'UI.ReferenceFacet', Label: 'New Composition', Target: 'Z_NewCompEntity/@UI.LineItem'} // new composition
Facets: [...,
{$Type: 'UI.ReferenceFacet', Label: 'Remarks', Target: 'Z_Remarks/@UI.LineItem'} // new composition
],
FieldGroup#Details: {
Data: [
{Value: currency_code, Label:'Currency'},
{Value: Z_newField, Label:'New Field'}, // extension field
{Value: Z_NewEntity_ID, Label:'New Entity'}, // extension field
{Value: Z_NewCodeList_code, Label:'New Code'}, // extension field
Data: [...,
{Value: Z_Customer_ID, Label:'Customer'}, // extension field
{Value: Z_SalesRegion_regionCode, Label:'Sales Region'}, // extension field
{Value: Z_priority, Label:'Priority'} // extension field
]
},
FieldGroup#Created: {
Data: [
{Value: createdBy},
{Value: createdAt},
]
},
FieldGroup#Modified: {
Data: [
{Value: modifiedBy},
{Value: modifiedAt},
]
},
},
) ;
}
}
);
// new field in existing service -- exchange ID with text
annotate OrdersService.Orders with {
Z_NewEntity @(
Z_Customer @(
Common: {
//show description, not id for New Entity in the context of Orders
Text: Z_NewEntity.description , TextArrangement: #TextOnly,
//show email, not id for Customer in the context of Orders
Text: Z_Customer.email , TextArrangement: #TextOnly,
ValueList: {
Label: 'New Entity',
CollectionPath: 'Z_NewEntity',
Label: 'Customers',
CollectionPath: 'Z_Customers',
Parameters: [
{ $Type: 'Common.ValueListParameterInOut',
LocalDataProperty: Z_NewEntity_ID,
LocalDataProperty: Z_Customer_ID,
ValueListProperty: 'ID'
},
{ $Type: 'Common.ValueListParameterDisplayOnly',
ValueListProperty: 'description'
ValueListProperty: 'email'
}
]
}
}
);
}
}