Skip to content

Commit b4b78a6

Browse files
committed
feat: support multi-value expand parameters on all search/get endpoints
Update documentation to use `array<string>` collection format. Update all uses of expand parameter by extracting it into a ResourceSelectors class. Fixes #659.
1 parent bf10094 commit b4b78a6

File tree

12 files changed

+227
-179
lines changed

12 files changed

+227
-179
lines changed

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/bundle/BundleRestService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.b2international.snowowl.core.internal.ResourceDocument;
2929
import com.b2international.snowowl.core.request.ResourceRequests;
3030
import com.b2international.snowowl.core.rest.AbstractRestService;
31+
import com.b2international.snowowl.core.rest.domain.ResourceSelectors;
3132

3233
import io.swagger.v3.oas.annotations.Operation;
3334
import io.swagger.v3.oas.annotations.Parameter;
@@ -103,11 +104,10 @@ public Promise<Bundle> get(
103104
@PathVariable(value="bundleId", required = true)
104105
final String bundleId,
105106

106-
@Parameter(description="expand")
107-
@RequestParam(value = "expand", required = false)
108-
String expand) {
107+
@ParameterObject
108+
final ResourceSelectors params) {
109109
return ResourceRequests.bundles().prepareGet(bundleId)
110-
.setExpand(expand)
110+
.setExpand(params.getExpand())
111111
.buildAsync()
112112
.execute(getBus());
113113
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.b2international.snowowl.core.rest.commit;
17+
18+
import java.util.List;
19+
20+
import com.b2international.snowowl.core.rest.domain.ObjectRestSearch;
21+
22+
import io.swagger.v3.oas.annotations.Parameter;
23+
24+
/**
25+
* @since 8.0
26+
*/
27+
public class CommitInfoRestSearch extends ObjectRestSearch {
28+
29+
@Parameter(description = "The author of the commit to match")
30+
private String author;
31+
32+
@Parameter(description = "Affected component identifier to match")
33+
private String affectedComponentId;
34+
35+
@Parameter(description = "Commit comment term to match")
36+
private String comment;
37+
38+
@Parameter(description = "One or more branch paths to match")
39+
private List<String> branch;
40+
41+
@Parameter(description = "Commit timestamp to match")
42+
private Long timestamp;
43+
44+
@Parameter(description = "Minimum commit timestamp to search matches from")
45+
private Long timestampFrom;
46+
47+
@Parameter(description = "Maximum commit timestamp to search matches to")
48+
private Long timestampTo;
49+
50+
public String getAuthor() {
51+
return author;
52+
}
53+
54+
public void setAuthor(String author) {
55+
this.author = author;
56+
}
57+
58+
public String getAffectedComponentId() {
59+
return affectedComponentId;
60+
}
61+
62+
public void setAffectedComponentId(String affectedComponentId) {
63+
this.affectedComponentId = affectedComponentId;
64+
}
65+
66+
public String getComment() {
67+
return comment;
68+
}
69+
70+
public void setComment(String comment) {
71+
this.comment = comment;
72+
}
73+
74+
public List<String> getBranch() {
75+
return branch;
76+
}
77+
78+
public void setBranch(List<String> branch) {
79+
this.branch = branch;
80+
}
81+
82+
public Long getTimestamp() {
83+
return timestamp;
84+
}
85+
86+
public void setTimestamp(Long timestamp) {
87+
this.timestamp = timestamp;
88+
}
89+
90+
public Long getTimestampFrom() {
91+
return timestampFrom;
92+
}
93+
94+
public void setTimestampFrom(Long timestampFrom) {
95+
this.timestampFrom = timestampFrom;
96+
}
97+
98+
public Long getTimestampTo() {
99+
return timestampTo;
100+
}
101+
102+
public void setTimestampTo(Long timestampTo) {
103+
this.timestampTo = timestampTo;
104+
}
105+
106+
107+
108+
}

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/commit/RepositoryCommitRestService.java

+19-67
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
package com.b2international.snowowl.core.rest.commit;
1717

1818
import java.util.List;
19-
import java.util.Set;
2019

20+
import org.springdoc.api.annotations.ParameterObject;
2121
import org.springframework.web.bind.annotation.GetMapping;
2222
import org.springframework.web.bind.annotation.PathVariable;
2323
import org.springframework.web.bind.annotation.RequestMapping;
24-
import org.springframework.web.bind.annotation.RequestParam;
2524

25+
import com.b2international.commons.CompareUtils;
2626
import com.b2international.index.revision.Commit;
2727
import com.b2international.snowowl.core.commit.CommitInfo;
2828
import com.b2international.snowowl.core.commit.CommitInfos;
2929
import com.b2international.snowowl.core.events.util.Promise;
3030
import com.b2international.snowowl.core.repository.RepositoryRequests;
3131
import com.b2international.snowowl.core.rest.AbstractRestService;
32-
import com.google.common.base.Strings;
32+
import com.b2international.snowowl.core.rest.domain.ResourceSelectors;
3333

3434
import io.swagger.v3.oas.annotations.Operation;
3535
import io.swagger.v3.oas.annotations.Parameter;
@@ -59,69 +59,22 @@ public RepositoryCommitRestService(String repositoryId) {
5959
@ApiResponse(responseCode = "200", description = "OK")
6060
})
6161
@GetMapping(produces = { AbstractRestService.JSON_MEDIA_TYPE })
62-
public Promise<CommitInfos> search(
63-
@Parameter(description = "The author of the commit to match")
64-
@RequestParam(value="author", required=false)
65-
final String author,
66-
67-
@Parameter(description = "The identifier(s) to match")
68-
@RequestParam(value="id", required=false)
69-
final Set<String> id,
70-
71-
@Parameter(description = "Affected component identifier to match")
72-
@RequestParam(value="affectedComponentId", required=false)
73-
final String affectedComponentId,
74-
75-
@Parameter(description = "Commit comment term to match")
76-
@RequestParam(value="comment", required=false)
77-
final String comment,
78-
79-
@Parameter(description = "One or more branch paths to match")
80-
@RequestParam(value="branch", required=false)
81-
final List<String> branch,
82-
83-
@Parameter(description = "Commit timestamp to match")
84-
@RequestParam(value="timestamp", required=false)
85-
final Long timestamp,
86-
87-
@Parameter(description = "Minimum commit timestamp to search matches from")
88-
@RequestParam(value="timestampFrom", required=false)
89-
final Long timestampFrom,
90-
91-
@Parameter(description = "Maximum commit timestamp to search matches to")
92-
@RequestParam(value="timestampTo", required=false)
93-
final Long timestampTo,
94-
95-
@Parameter(description = "Expansion parameters")
96-
@RequestParam(value="expand", required=false)
97-
final String expand,
98-
99-
@Parameter(description = "The search key to use for retrieving the next page of results")
100-
@RequestParam(value="searchAfter", required=false)
101-
final String searchAfter,
102-
103-
@Parameter(description = "Sort keys")
104-
@RequestParam(value="sort", required=false)
105-
final List<String> sort,
106-
107-
@Parameter(description = "The maximum number of items to return")
108-
@RequestParam(value="limit", defaultValue="50", required=false)
109-
final int limit) {
62+
public Promise<CommitInfos> search(CommitInfoRestSearch params) {
11063
return RepositoryRequests
11164
.commitInfos()
11265
.prepareSearchCommitInfo()
113-
.filterByIds(id)
114-
.filterByAuthor(author)
115-
.filterByAffectedComponent(affectedComponentId)
116-
.filterByComment(comment)
117-
.filterByBranches(branch)
118-
.filterByTimestamp(timestamp)
119-
.filterByTimestamp(timestampFrom, timestampTo)
120-
.setFields(Strings.isNullOrEmpty(expand) ? List.of(Commit.Fields.ID, Commit.Fields.AUTHOR, Commit.Fields.BRANCH, Commit.Fields.COMMENT, Commit.Fields.TIMESTAMP, Commit.Fields.GROUP_ID) : null)
121-
.setExpand(expand)
122-
.setSearchAfter(searchAfter)
123-
.setLimit(limit)
124-
.sortBy(extractSortFields(sort))
66+
.filterByIds(params.getId())
67+
.filterByAuthor(params.getAuthor())
68+
.filterByAffectedComponent(params.getAffectedComponentId())
69+
.filterByComment(params.getComment())
70+
.filterByBranches(params.getBranch())
71+
.filterByTimestamp(params.getTimestamp())
72+
.filterByTimestamp(params.getTimestampFrom(), params.getTimestampTo())
73+
.setFields(CompareUtils.isEmpty(params.getExpand()) ? List.of(Commit.Fields.ID, Commit.Fields.AUTHOR, Commit.Fields.BRANCH, Commit.Fields.COMMENT, Commit.Fields.TIMESTAMP, Commit.Fields.GROUP_ID) : null)
74+
.setExpand(params.getExpand())
75+
.setSearchAfter(params.getSearchAfter())
76+
.setLimit(params.getLimit())
77+
.sortBy(extractSortFields(params.getSort()))
12578
.build(repositoryId)
12679
.execute(getBus());
12780
}
@@ -139,13 +92,12 @@ public Promise<CommitInfo> get(
13992
@PathVariable(value="commitId")
14093
final String commitId,
14194

142-
@Parameter(description = "Expansion parameters")
143-
@RequestParam(value="expand", required=false)
144-
final String expand) {
95+
@ParameterObject
96+
final ResourceSelectors selectors) {
14597
return RepositoryRequests
14698
.commitInfos()
14799
.prepareGetCommitInfo(commitId)
148-
.setExpand(expand)
100+
.setExpand(selectors.getExpand())
149101
.build(repositoryId)
150102
.execute(getBus());
151103
}

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/domain/ObjectRestSearch.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
/**
2424
* @since 7.3
2525
*/
26-
public abstract class ObjectRestSearch {
26+
public class ObjectRestSearch extends ResourceSelectors {
2727

2828
@Parameter(description = "The identifier(s) to match")
2929
private Set<String> id;
3030

3131
// scrolling/paging/expansion/sorting
32-
@Parameter(description = "Expansion parameters")
33-
private String expand;
3432
@Parameter(description = "The search key to use for retrieving the next page of results")
3533
private String searchAfter;
34+
3635
@Parameter(description = "Sort keys")
3736
private List<String> sort;
37+
3838
@Parameter(description = "The maximum number of items to return")
3939
private int limit = 50;
4040

@@ -45,14 +45,6 @@ public final Set<String> getId() {
4545
public final void setId(Set<String> id) {
4646
this.id = id;
4747
}
48-
49-
public final String getExpand() {
50-
return expand;
51-
}
52-
53-
public final void setExpand(String expand) {
54-
this.expand = expand;
55-
}
5648

5749
public final String getSearchAfter() {
5850
return searchAfter;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.b2international.snowowl.core.rest.domain;
17+
18+
import java.util.List;
19+
20+
import io.swagger.v3.oas.annotations.Parameter;
21+
22+
/**
23+
* @since 8.0
24+
*/
25+
public class ResourceSelectors {
26+
27+
@Parameter(description = "Expansion parameters")
28+
private List<String> expand;
29+
30+
public final List<String> getExpand() {
31+
return expand;
32+
}
33+
34+
public final void setExpand(List<String> expand) {
35+
this.expand = expand;
36+
}
37+
38+
}

0 commit comments

Comments
 (0)