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 cuid, managed, Country, sap.common.CodeList
} from '@sap/cds/common'; } from '@sap/cds/common';
namespace Z_bookshop.extension; namespace Z_bookshop.extension;
// extend existing entity // extend existing entity
extend orders.Orders with { extend orders.Orders with {
Z_newField : String default 'Default Value'; Z_Customer : Association to one Z_Customers;
Z_NewEntity : Association to one Z_NewEntity; Z_SalesRegion : Association to one Z_SalesRegion;
Z_NewCodeList : Association to one Z_NewCodeList; Z_priority : String @assert.range enum {high; medium; low} default 'medium';
Z_NewCompEntity : Composition of many Z_NewCompEntity on Z_NewCompEntity.parent = $self; Z_Remarks : Composition of many Z_Remarks on Z_Remarks.parent = $self;
} }
// new entity - as association target // new entity - as association target
entity Z_NewEntity : cuid, managed entity Z_Customers : cuid, managed
{ {
description : String; email : String;
dateField : Date; firstName : String;
integerField : Integer; lastName : String;
stringField : String; creditCardNo : String;
enumField : String @assert.range enum {high; medium; low} default 'medium'; dateOfBirth : Date;
rangeField : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0; 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 // new unique constraint (secondary index)
entity Z_NewCodeList : CodeList { annotate Z_Customers with @assert.unique: { email: [ email ] }
key code : String(11); {
email @mandatory; // mandatory check
} }
// new entity - as composition target // new entity - as composition target
entity Z_NewCompEntity : cuid, managed entity Z_CustomerPostalAddresses : cuid, managed
{ {
parent : Association to one orders.Orders; Customer : Association to one Z_Customers;
description : String; description : String;
dateField : Date; street : String;
integerField : Integer; town : String;
stringField : 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'; using { Z_bookshop.extension as ext } from '../db/extension';
extend service OrdersService with { extend service OrdersService with {
entity Z_NewEntity as projection on ext.Z_NewEntity ; entity Z_Customers as projection on ext.Z_Customers;
entity Z_NewCodeList as projection on ext.Z_NewCodeList; entity Z_SalesRegion as projection on ext.Z_SalesRegion;
} }

View File

@@ -3,40 +3,84 @@ using OrdersService from './extension_service';
// new entity -- draft enabled // 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 // new codelist entity -- draft enabled
annotate OrdersService.Z_SalesRegion with @odata.draft.enabled; annotate OrdersService.Z_SalesRegion with @odata.draft.enabled;
// new entity -- titles // new entity -- titles
annotate OrdersService.Z_NewEntity with { annotate OrdersService.Z_Customers with {
description @title : 'Description'; ID @(
integerField @title : 'Integer Field Title'; UI.Hidden,
dateField @title : 'Date Field Title'; Common : {Text : email}
stringField @title : 'String Field Title'; );
enumField @title : 'Enum Field Title'; firstName @title : 'First Name';
rangeField @title : 'Range Field Title'; 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 // new entity -- titles
annotate OrdersService.Z_NewCodeList with { annotate OrdersService.Z_CustomerPostalAddresses with {
code @title: 'Code Title'; ID @(
UI.Hidden,
Common : {Text : description}
);
description @title : 'Description';
street @title : 'Street';
town @title : 'Town';
country @title : 'Country';
} }
// new entity -- titles // new entity -- titles
annotate OrdersService.Z_NewCompEntity with { annotate OrdersService.Z_SalesRegion with {
description @title : 'Description'; regionCode @title: 'Region Code';
integerField @title : 'Integer Field Title'; }
dateField @title : 'Date Field Title';
stringField @title : 'String Field Title'; // new entity -- titles
annotate OrdersService.Z_Remarks with {
number @title: 'Remark Number';
remarksLine @title: 'Remark';
} }
// new entity in service -- UI // new entity in service -- UI
annotate OrdersService.Z_NewEntity with @(UI : { annotate OrdersService.Z_Customers with @(UI : {
HeaderInfo : { HeaderInfo : {
TypeName : 'New Entity', TypeName : 'Customer',
TypeNamePlural : 'New Entities', 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 : { Title : {
$Type : 'UI.DataField', $Type : 'UI.DataField',
Value : description Value : description
@@ -44,46 +88,47 @@ annotate OrdersService.Z_NewEntity with @(UI : {
}, },
LineItem : [ LineItem : [
{Value : description}, {Value : description},
{Value : dateField }, {Value : street},
{Value : integerField }, {Value : town},
{Value : stringField}, {Value : country_code}
{Value : enumField}, ],
{Value : rangeField}
],
Facets : [ Facets : [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target : '@UI.FieldGroup#Main'} {$Type: 'UI.ReferenceFacet', Label: 'Main', Target : '@UI.FieldGroup#Main'}
], ],
FieldGroup #Main : {Data : [ FieldGroup #Main : {Data : [
{Value : description}, {Value : description},
{Value : dateField }, {Value : street},
{Value : integerField }, {Value : town},
{Value : stringField}, {Value : country_code}
{Value : enumField},
{Value : rangeField}
]} ]}
} ) ; }, ) {
};
// new entity -- UI // new entity -- UI
annotate OrdersService.Z_NewCodeList with @( annotate OrdersService.Z_SalesRegion with @(
UI: { UI: {
HeaderInfo: { HeaderInfo: {
TypeName: 'New Code', TypeName: 'Sales Region',
TypeNamePlural: 'New Codes', TypeNamePlural: 'Sales Regions',
Title : { Title : {
$Type : 'UI.DataField', $Type : 'UI.DataField',
Value : code Value : regionCode
} }
}, },
LineItem: [ LineItem: [
{Value: code} {Value: regionCode},
{Value: name},
{Value: descr}
], ],
Facets: [ Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'} {$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'}
], ],
FieldGroup#Main: { FieldGroup#Main: {
Data: [ Data: [
{Value: code} {Value: regionCode},
{Value: name},
{Value: descr}
] ]
} }
}, },
@@ -93,31 +138,27 @@ annotate OrdersService.Z_NewCodeList with @(
// new entity -- UI // new entity -- UI
annotate OrdersService.Z_NewCompEntity with @( annotate OrdersService.Z_Remarks with @(
UI: { UI: {
HeaderInfo: { HeaderInfo: {
TypeName: 'New Composition', TypeName: 'Remark',
TypeNamePlural: 'New Compositions', TypeNamePlural: 'Remarks',
Title : { Title : {
$Type : 'UI.DataField', $Type : 'UI.DataField',
Value : description Value : number
} }
}, },
LineItem: [ LineItem: [
{Value : description}, {Value: number},
{Value : dateField }, {Value: remarksLine}
{Value : integerField },
{Value : stringField}
], ],
Facets: [ Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'} {$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'}
], ],
FieldGroup#Main: { FieldGroup#Main: {
Data: [ Data: [
{Value : description}, {Value: number},
{Value : dateField }, {Value: remarksLine}
{Value : integerField },
{Value : stringField}
] ]
} }
}, },
@@ -125,84 +166,50 @@ annotate OrdersService.Z_NewCompEntity with @(
}; };
// extend existing entity Orders with new extension fields and new composition // extend existing entity Orders with new extension fields and new composition
@odata.draft.enabled
annotate OrdersService.Orders with @( annotate OrdersService.Orders with @(
UI: { UI: {
SelectionFields: [ createdAt, createdBy ], LineItem: [...,
LineItem: [ {Value: Z_Customer_ID, Label:'Customer'}, // extension field
{Value: OrderNo, Label:'OrderNo'}, {Value: Z_SalesRegion_regionCode, Label:'Sales Region'}, // extension field
{Value: Z_newField, Label:'New Field'}, // extension field {Value: Z_priority, Label:'Priority'} // extension field
{Value: Z_NewEntity_ID, Label:'New Entity'}, // extension field
{Value: Z_NewCodeList_code, Label:'New Code'}, // extension field
{Value: createdAt, Label:'Date'}
], ],
HeaderInfo: { Facets: [...,
TypeName: 'Order', TypeNamePlural: 'Orders', {$Type: 'UI.ReferenceFacet', Label: 'Remarks', Target: 'Z_Remarks/@UI.LineItem'} // new composition
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
], ],
FieldGroup#Details: { FieldGroup#Details: {
Data: [ Data: [...,
{Value: currency_code, Label:'Currency'}, {Value: Z_Customer_ID, Label:'Customer'}, // extension field
{Value: Z_newField, Label:'New Field'}, // extension field {Value: Z_SalesRegion_regionCode, Label:'Sales Region'}, // extension field
{Value: Z_NewEntity_ID, Label:'New Entity'}, // extension field {Value: Z_priority, Label:'Priority'} // extension field
{Value: Z_NewCodeList_code, Label:'New Code'}, // 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 // new field in existing service -- exchange ID with text
annotate OrdersService.Orders with { annotate OrdersService.Orders with {
Z_NewEntity @( Z_Customer @(
Common: { Common: {
//show description, not id for New Entity in the context of Orders //show email, not id for Customer in the context of Orders
Text: Z_NewEntity.description , TextArrangement: #TextOnly, Text: Z_Customer.email , TextArrangement: #TextOnly,
ValueList: { ValueList: {
Label: 'New Entity', Label: 'Customers',
CollectionPath: 'Z_NewEntity', CollectionPath: 'Z_Customers',
Parameters: [ Parameters: [
{ $Type: 'Common.ValueListParameterInOut', { $Type: 'Common.ValueListParameterInOut',
LocalDataProperty: Z_NewEntity_ID, LocalDataProperty: Z_Customer_ID,
ValueListProperty: 'ID' ValueListProperty: 'ID'
}, },
{ $Type: 'Common.ValueListParameterDisplayOnly', { $Type: 'Common.ValueListParameterDisplayOnly',
ValueListProperty: 'description' ValueListProperty: 'email'
} }
] ]
} }
} }
); );
} }