You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recursive hierarchies are parent-child hierarchies, where each entity references its parent and through that defines the hierarchical structure. A common example is a company organization structure or HR reporting, where each employee entity references another employee a as direct report or manager.
1144
-
1145
-
##### Domain Model
1146
-
1147
-
The simplest domain model looks as follows:
1148
-
1149
-
```cds
1150
-
entity Employee : Hierarchy {
1151
-
key ID : UUID;
1152
-
parent : Association to Employee;
1153
-
fullName : String;
1154
-
}
1155
-
1156
-
aspect Hierarchy {
1157
-
virtual LimitedDescendantCount : Integer64;
1158
-
virtual DistanceFromRoot : Integer64;
1159
-
virtual DrillState : String;
1160
-
virtual LimitedRank : Integer64;
1161
-
}
1162
-
```
1163
-
1164
-
The entity `Employee` has the element `ID`, which identifies the hierarchy node. The `parent` association references the same entity, which establishes the parent-child relationship.
1165
-
1166
-
##### Virtual Elements of a Hierarchy
1167
-
1168
-
The `Hierarchy` aspect defines a set of virtual elements, automatically calculated by the backend at runtime, to describe the state of the hierarchy. This information is requested by the UI to correctly render the hierarchy in a *TreeTable* during user interaction.
1169
-
1170
-
##### Service Model
1171
-
1172
-
The following service defines the projection on the domain model.
1173
-
1174
-
```cds
1175
-
service HRService {
1176
-
entity HREmployee as projection on Employee;
1177
-
}
1178
-
```
1179
-
1180
-
1181
-
##### OData v4 Annotations for Fiori
1182
-
1183
-
To link the backend and Fiori UI, the projected service entity must be enriched with the following annotations.
1184
-
1185
-
```cds
1186
-
annotate HRService.HREmployee with @Aggregation.RecursiveHierarchy #EmployeeHierarchy: {
1187
-
$Type: 'Aggregation.RecursiveHierarchyType',
1188
-
NodeProperty: ID,
1189
-
ParentNavigationProperty: parent
1190
-
};
1191
-
```
1192
-
1193
-
Here the `EmployeeHierarchy` specifies a hierarchy qualifier, `NodeProperty` (identifying the hierarchy node) is linked to `ID` of the entity `HREmployee`, and the `ParentNavigationProperty` is linked to a corresponding `parent` association.
1194
-
1195
-
```cds
1196
-
annotate HRService.HREmployee with @Hierarchy.RecursiveHierarchy #EmployeeHierarchy: {
1197
-
$Type: 'Hierarchy.RecursiveHierarchyType',
1198
-
LimitedDescendantCount: LimitedDescendantCount,
1199
-
DistanceFromRoot: DistanceFromRoot,
1200
-
DrillState: DrillState,
1201
-
LimitedRank: LimitedRank
1202
-
};
1203
-
```
1204
-
1205
-
Here the same qualifier `EmployeeHierarchy` is referenced to list the names of the [virtual elements of the hierarchy](#virtual-elements-of-a-hierarchy).
0 commit comments