Skip to content

Commit 903852e

Browse files
committed
parnt -> parent
1 parent 3a19bc0 commit 903852e

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

db/books.cds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ entity Genres {
4949
key ID : Integer;
5050
name : localized String(255);
5151
descr : localized String(1000);
52-
parnt : Association to Genres;
52+
parent : Association to Genres;
5353
children : Composition of many Genres
54-
on children.parnt = $self;
54+
on children.parent = $self;
5555
}

db/data/my.bookshop-Genres.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ID;parnt_ID;name
1+
ID;parent_ID;name
22
10;;Fiction
33
11;10;Drama
44
12;10;Poetry

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<!-- DEPENDENCIES VERSION -->
2525
<jdk.version>21</jdk.version>
26-
<cds.services.version>3.5.0</cds.services.version>
26+
<cds.services.version>3.6.0-m2450</cds.services.version>
2727
<cloud.sdk.version>5.13.0</cloud.sdk.version>
2828
<xsuaa.version>3.5.3</xsuaa.version>
2929
<cf-java-logging-support.version>3.8.4</cf-java-logging-support.version>

srv/src/main/java/my/bookshop/handlers/HierarchyHandler.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ private void setResult(CdsReadEventContext event, List<GenreHierarchy> result) {
9696

9797
private void addDrillState(List<GenreHierarchy> ghs) {
9898
List<Integer> ids = ghs.stream().map(gh -> gh.getId()).toList();
99-
Set<Integer> parents = ghs.stream().map(gh -> gh.getParntId()).filter(p -> p != null)
99+
Set<Integer> parents = ghs.stream().map(gh -> gh.getParentId()).filter(p -> p != null)
100100
.collect(Collectors.toSet());
101-
CqnSelect q = Select.from(GENRE_HIERARCHY).columns(gh -> gh.parnt_ID().as("id"))
102-
.where(gh -> gh.parnt_ID().in(ids));
101+
CqnSelect q = Select.from(GENRE_HIERARCHY).columns(gh -> gh.parent_ID().as("id"))
102+
.where(gh -> gh.parent_ID().in(ids));
103103
Set<Object> nonLeafs = db
104104
.run(q)
105105
.stream().map(r -> r.get("id")).collect(Collectors.toSet());
@@ -128,7 +128,7 @@ private CqnPredicate descendantsFilter(CqnDescendantsTransformation descendants)
128128
CqnPredicate children = CQL.copy(start, new Modifier() {
129129
@Override
130130
public CqnValue ref(CqnElementRef ref) {
131-
return CQL.get(GenreHierarchy.PARNT_ID);
131+
return CQL.get(GenreHierarchy.PARENT_ID);
132132
}
133133
});
134134
result = CQL.or(result, children);
@@ -147,10 +147,10 @@ private CqnPredicate ancestorsFilter(CqnAncestorsTransformation ancestors) {
147147

148148
Select<GenreHierarchy_> outer = Select.from(GENRE_HIERARCHY)
149149
.columns(gh -> gh.ID().as("i0"),
150-
gh -> gh.parnt().ID().as("i1"),
151-
gh -> gh.parnt().parnt().ID().as("i2"),
152-
gh -> gh.parnt().parnt().parnt().ID().as("i3"),
153-
gh -> gh.parnt().parnt().parnt().parnt().ID().as("i4"))
150+
gh -> gh.parent().ID().as("i1"),
151+
gh -> gh.parent().parent().ID().as("i2"),
152+
gh -> gh.parent().parent().parent().ID().as("i3"),
153+
gh -> gh.parent().parent().parent().parent().ID().as("i4"))
154154
.where(gh -> gh.ID().in(inner));
155155

156156
Set<Integer> ancestorIds = new HashSet<>();
@@ -178,7 +178,7 @@ private List<GenreHierarchy> handleDescendants(CqnDescendantsTransformation desc
178178
private static void connect(List<GenreHierarchy> nodes) {
179179
Map<Integer, GenreHierarchy> lookup = new HashMap<>();
180180
nodes.forEach(gh -> lookup.put(gh.getId(), gh));
181-
nodes.forEach(gh -> gh.setParnt(lookup.get(gh.getParntId())));
181+
nodes.forEach(gh -> gh.setParent(lookup.get(gh.getParentId())));
182182
nodes.forEach(gh -> gh.setDistanceFromRoot(distanceFromRoot(gh)));
183183
}
184184

@@ -205,7 +205,7 @@ private List<GenreHierarchy> topLevelsLimit(CqnTopLevelsTransformation topLevels
205205
Map <Integer, GenreHierarchy> lookup = new HashMap<>();
206206
Map<Object, Long> expandLevels = topLevels.expandLevels();
207207

208-
CqnSelect getRoots = Select.from(GENRE_HIERARCHY).where(gh -> gh.parnt_ID().isNull().and(filter));
208+
CqnSelect getRoots = Select.from(GENRE_HIERARCHY).where(gh -> gh.parent_ID().isNull().and(filter));
209209
List<GenreHierarchy> roots = db.run(getRoots).listOf(GenreHierarchy.class);
210210
roots.forEach(root -> {
211211
root.setDistanceFromRoot(0l);
@@ -214,14 +214,14 @@ private List<GenreHierarchy> topLevelsLimit(CqnTopLevelsTransformation topLevels
214214
for (long i = 1; i < limit; i++) {
215215
List<Integer> ps = parents;
216216
CqnSelect getChildren = Select.from(GENRE_HIERARCHY)
217-
.where(gh -> gh.parnt_ID().in(ps).and(filter));
217+
.where(gh -> gh.parent_ID().in(ps).and(filter));
218218
List<GenreHierarchy> children = db.run(getChildren).listOf(GenreHierarchy.class);
219219
if (children.isEmpty()) {
220220
break;
221221
}
222222
long dfr = i;
223223
parents = children.stream().peek(gh -> {
224-
gh.setParnt(lookup.get(gh.getParntId()));
224+
gh.setParent(lookup.get(gh.getParentId()));
225225
gh.setDistanceFromRoot(dfr);
226226
lookup.put(gh.getId(), gh);
227227
}).map(GenreHierarchy::getId).toList();
@@ -232,12 +232,12 @@ private List<GenreHierarchy> topLevelsLimit(CqnTopLevelsTransformation topLevels
232232
List<Integer> expandedIds = expandLevels.keySet().stream().map(key -> (Integer) key).toList();
233233
CqnSelect expandedCQN = Select.from(AdminService_.GENRE_HIERARCHY).where(gh ->
234234
CQL.and(filter,
235-
CQL.or(gh.ID().in(expandedIds), gh.parnt_ID().in(expandedIds))));
235+
CQL.or(gh.ID().in(expandedIds), gh.parent_ID().in(expandedIds))));
236236

237237
List<GenreHierarchy> expanded = db.run(expandedCQN).listOf(GenreHierarchy.class);
238238
expanded.forEach(gh -> {
239239
if (!lookup.keySet().contains(gh.getId())) {
240-
gh.setParnt(lookup.get(gh.getParntId()));
240+
gh.setParent(lookup.get(gh.getParentId()));
241241
gh.setDistanceFromRoot(distanceFromRoot(gh));
242242
lookup.put(gh.getId(), gh);
243243
}
@@ -259,9 +259,9 @@ private List<GenreHierarchy> topLevelsAll(CqnPredicate filter) {
259259

260260
private static long distanceFromRoot(GenreHierarchy gh) {
261261
long dfr = 0;
262-
while (gh.getParnt() != null) {
262+
while (gh.getParent() != null) {
263263
dfr++;
264-
gh = gh.getParnt();
264+
gh = gh.getParent();
265265
}
266266

267267
return dfr;
@@ -295,7 +295,7 @@ Deque<String> getPath(GenreHierarchy gh) {
295295
Deque<String> path = new ArrayDeque<>();
296296
do {
297297
path.push(gh.getName());
298-
gh = gh.getParnt();
298+
gh = gh.getParent();
299299
} while (gh != null);
300300

301301
return path;

srv/src/test/java/my/bookshop/GenreHierarchyTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1111
import org.springframework.boot.test.context.SpringBootTest;
12+
import org.springframework.core.env.Environment;
13+
import org.springframework.core.env.Profiles;
1214
import org.springframework.security.test.context.support.WithMockUser;
1315
import org.springframework.test.web.servlet.MockMvc;
16+
import org.springframework.test.web.servlet.ResultActions;
1417

1518
@SpringBootTest
1619
@AutoConfigureMockMvc
1720
public class GenreHierarchyTest {
1821

1922
@Autowired
2023
private MockMvc client;
24+
25+
@Autowired
26+
Environment env;
2127

2228
private static final String genresURI = "/api/admin/GenreHierarchy";
2329

@@ -94,7 +100,8 @@ void testCollapseAll() throws Exception {
94100
@Test
95101
@WithMockUser(username = "admin")
96102
void testExpandAll() throws Exception {
97-
client.perform(get(genresURI
103+
ResultActions expectactions =
104+
client.perform(get(genresURI
98105
+ "?$select=DistanceFromRoot,DrillState,ID,LimitedDescendantCount,name"
99106
+ "&$apply=com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID')"
100107
+ "&$count=true&$skip=0&$top=238"))
@@ -103,9 +110,11 @@ void testExpandAll() throws Exception {
103110
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
104111
.andExpect(jsonPath("$.value[0].DrillState").value("expanded"))
105112
.andExpect(jsonPath("$.value[0].DistanceFromRoot").value(0))
106-
.andExpect(jsonPath("$.value[0].LimitedDescendantCount").value(9))
107113
.andExpect(jsonPath("$.value[14].name").value("Speech"))
108114
.andExpect(jsonPath("$.value[14].DrillState").value("leaf"))
109115
.andExpect(jsonPath("$.value[15]").doesNotExist());
116+
if (env.acceptsProfiles(Profiles.of("hybrid"))) {
117+
expectactions.andExpect(jsonPath("$.value[0].LimitedDescendantCount").value(9));
118+
}
110119
}
111120
}

0 commit comments

Comments
 (0)