Skip to content

Commit ac0164c

Browse files
authored
Adding "artifactType" as a filter option when searching. Fixes #5535 (#5536)
1 parent 81b5476 commit ac0164c

File tree

12 files changed

+126
-45
lines changed

12 files changed

+126
-45
lines changed

app/src/main/java/io/apicurio/registry/rest/v3/SearchResourceImpl.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class SearchResourceImpl implements SearchResource {
6262
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
6363
public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, BigInteger limit,
6464
SortOrder order, ArtifactSortBy orderby, List<String> labels, String description, String groupId,
65-
Long globalId, Long contentId, String artifactId) {
65+
Long globalId, Long contentId, String artifactId, String artifactType) {
6666
if (orderby == null) {
6767
orderby = ArtifactSortBy.name;
6868
}
@@ -90,6 +90,9 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
9090
if (!StringUtil.isEmpty(artifactId)) {
9191
filters.add(SearchFilter.ofArtifactId(artifactId));
9292
}
93+
if (!StringUtil.isEmpty(artifactType)) {
94+
filters.add(SearchFilter.ofArtifactType(artifactType));
95+
}
9396

9497
if (labels != null && !labels.isEmpty()) {
9598
labels.stream().map(prop -> {
@@ -234,7 +237,8 @@ public GroupSearchResults searchGroups(BigInteger offset, BigInteger limit, Sort
234237
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
235238
public VersionSearchResults searchVersions(String version, BigInteger offset, BigInteger limit,
236239
SortOrder order, VersionSortBy orderby, List<String> labels, String description, String groupId,
237-
Long globalId, Long contentId, String artifactId, String name, VersionState state) {
240+
Long globalId, Long contentId, String artifactId, String name, VersionState state,
241+
String artifactType) {
238242
if (orderby == null) {
239243
orderby = VersionSortBy.globalId;
240244
}
@@ -265,6 +269,9 @@ public VersionSearchResults searchVersions(String version, BigInteger offset, Bi
265269
if (!StringUtil.isEmpty(description)) {
266270
filters.add(SearchFilter.ofDescription(description));
267271
}
272+
if (!StringUtil.isEmpty(artifactType)) {
273+
filters.add(SearchFilter.ofArtifactType(artifactType));
274+
}
268275
if (labels != null && !labels.isEmpty()) {
269276
labels.stream().map(prop -> {
270277
int delimiterIndex = prop.indexOf(":");

app/src/main/java/io/apicurio/registry/storage/dto/SearchFilter.java

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public static SearchFilter ofVersion(String value) {
6262
return new SearchFilter(SearchFilterType.version, value);
6363
}
6464

65+
public static SearchFilter ofArtifactType(String value) {
66+
return new SearchFilter(SearchFilterType.artifactType, value);
67+
}
68+
6569
public static SearchFilter ofCanonicalHash(String value) {
6670
return new SearchFilter(SearchFilterType.canonicalHash, value);
6771
}

app/src/main/java/io/apicurio/registry/storage/dto/SearchFilterType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public enum SearchFilterType {
44

5-
groupId, artifactId, version, name, description, labels, contentHash, canonicalHash, globalId, contentId, state
5+
groupId, artifactId, version, name, description, labels, contentHash, canonicalHash, globalId, contentId, state, artifactType
66

77
}

app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,13 @@ public ArtifactSearchResultsDto searchArtifacts(Set<SearchFilter> filters, Order
990990
query.bind(idx, filter.getStringValue());
991991
});
992992
break;
993+
case artifactType:
994+
op = filter.isNot() ? "!=" : "=";
995+
where.append("a.type " + op + " ?");
996+
binders.add((query, idx) -> {
997+
query.bind(idx, filter.getStringValue());
998+
});
999+
break;
9931000
case contentHash:
9941001
op = filter.isNot() ? "!=" : "=";
9951002
where.append(
@@ -1601,9 +1608,17 @@ public VersionSearchResultsDto searchVersions(Set<SearchFilter> filters, OrderBy
16011608
query.bind(idx, normalizeGroupId(filter.getStringValue()));
16021609
});
16031610
break;
1611+
case artifactType:
1612+
op = filter.isNot() ? "!=" : "=";
1613+
where.append("a.type " + op + " ?");
1614+
binders.add((query, idx) -> {
1615+
query.bind(idx, filter.getStringValue());
1616+
});
1617+
break;
16041618
case artifactId:
16051619
case contentId:
16061620
case globalId:
1621+
case state:
16071622
case version:
16081623
op = filter.isNot() ? "!=" : "=";
16091624
where.append("v.");
@@ -1664,13 +1679,6 @@ public VersionSearchResultsDto searchVersions(Set<SearchFilter> filters, OrderBy
16641679
});
16651680
where.append(")");
16661681
break;
1667-
case state:
1668-
op = filter.isNot() ? "!=" : "=";
1669-
where.append("v.state " + op + " ?");
1670-
binders.add((query, idx) -> {
1671-
query.bind(idx, normalizeGroupId(filter.getStringValue()));
1672-
});
1673-
break;
16741682
default:
16751683
throw new RegistryStorageException("Filter type not supported: " + filter.getType());
16761684
}

app/src/test/java/io/apicurio/registry/noprofile/ArtifactSearchTest.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.apicurio.registry.rest.client.models.SortOrder;
99
import io.apicurio.registry.types.ArtifactType;
1010
import io.apicurio.registry.types.ContentTypes;
11+
import io.apicurio.registry.utils.tests.TestUtils;
1112
import io.quarkus.test.junit.QuarkusTest;
1213
import org.junit.jupiter.api.Assertions;
1314
import org.junit.jupiter.api.Test;
@@ -195,4 +196,31 @@ void testCaseInsensitiveSearch() throws Exception {
195196
Assertions.assertEquals(1, propertiesSearch.getCount());
196197
}
197198

198-
}
199+
@Test
200+
void testFilterByArtifactType() throws Exception {
201+
String groupId = TestUtils.generateGroupId();
202+
203+
createArtifact(groupId, "avro-artifact", ArtifactType.AVRO, "{}", ContentTypes.APPLICATION_JSON);
204+
createArtifact(groupId, "json-artifact", ArtifactType.JSON, "{}", ContentTypes.APPLICATION_JSON);
205+
206+
ArtifactSearchResults results = clientV3.search().artifacts().get(config -> {
207+
config.queryParameters.groupId = groupId;
208+
});
209+
Assertions.assertNotNull(results);
210+
Assertions.assertEquals(2, results.getCount());
211+
212+
results = clientV3.search().artifacts().get(config -> {
213+
config.queryParameters.groupId = groupId;
214+
config.queryParameters.artifactType = ArtifactType.AVRO;
215+
});
216+
Assertions.assertNotNull(results);
217+
Assertions.assertEquals(1, results.getCount());
218+
219+
results = clientV3.search().artifacts().get(config -> {
220+
config.queryParameters.groupId = groupId;
221+
config.queryParameters.artifactType = ArtifactType.JSON;
222+
});
223+
Assertions.assertNotNull(results);
224+
Assertions.assertEquals(1, results.getCount());
225+
}
226+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.apicurio.registry.noprofile;
2+
3+
import io.apicurio.registry.AbstractResourceTestBase;
4+
import io.apicurio.registry.rest.client.models.VersionSearchResults;
5+
import io.apicurio.registry.types.ArtifactType;
6+
import io.apicurio.registry.types.ContentTypes;
7+
import io.apicurio.registry.utils.tests.TestUtils;
8+
import io.quarkus.test.junit.QuarkusTest;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
12+
@QuarkusTest
13+
public class VersionSearchTest extends AbstractResourceTestBase {
14+
15+
@Test
16+
void testFilterByArtifactType() throws Exception {
17+
String groupId = TestUtils.generateGroupId();
18+
19+
createArtifact(groupId, "avro-artifact", ArtifactType.AVRO, "{}", ContentTypes.APPLICATION_JSON);
20+
createArtifactVersion(groupId, "avro-artifact", "{ }", ContentTypes.APPLICATION_JSON);
21+
createArtifact(groupId, "json-artifact", ArtifactType.JSON, "{}", ContentTypes.APPLICATION_JSON);
22+
23+
VersionSearchResults results = clientV3.search().versions().get(config -> {
24+
config.queryParameters.groupId = groupId;
25+
});
26+
Assertions.assertNotNull(results);
27+
Assertions.assertEquals(3, results.getCount());
28+
29+
results = clientV3.search().versions().get(config -> {
30+
config.queryParameters.groupId = groupId;
31+
config.queryParameters.artifactType = ArtifactType.AVRO;
32+
});
33+
Assertions.assertNotNull(results);
34+
Assertions.assertEquals(2, results.getCount());
35+
36+
results = clientV3.search().versions().get(config -> {
37+
config.queryParameters.groupId = groupId;
38+
config.queryParameters.artifactType = ArtifactType.JSON;
39+
});
40+
Assertions.assertNotNull(results);
41+
Assertions.assertEquals(1, results.getCount());
42+
43+
}
44+
}

common/src/main/resources/META-INF/openapi.json

+16
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@
376376
"type": "string"
377377
},
378378
"in": "query"
379+
},
380+
{
381+
"name": "artifactType",
382+
"description": "Filter by artifact type (`AVRO`, `JSON`, etc).",
383+
"schema": {
384+
"$ref": "#/components/schemas/ArtifactType"
385+
},
386+
"in": "query"
379387
}
380388
],
381389
"responses": {
@@ -2930,6 +2938,14 @@
29302938
"$ref": "#/components/schemas/VersionState"
29312939
},
29322940
"in": "query"
2941+
},
2942+
{
2943+
"name": "artifactType",
2944+
"description": "Filter by artifact type (`AVRO`, `JSON`, etc).",
2945+
"schema": {
2946+
"$ref": "#/components/schemas/ArtifactType"
2947+
},
2948+
"in": "query"
29332949
}
29342950
],
29352951
"responses": {

docs/modules/ROOT/partials/getting-started/ref-registry-all-configs.adoc

-30
Original file line numberDiff line numberDiff line change
@@ -669,36 +669,6 @@ The following {registry} configuration options are available for each component
669669
|`sa`
670670
|`3.0.0`
671671
|Gitops green datasource username
672-
|`apicurio.datasource.jdbc.initial-size`
673-
|`string`
674-
|`20`
675-
|`3.0.0`
676-
|Application datasource pool initial size
677-
|`apicurio.datasource.jdbc.max-size`
678-
|`string`
679-
|`100`
680-
|`3.0.0`
681-
|Application datasource pool maximum size
682-
|`apicurio.datasource.jdbc.min-size`
683-
|`string`
684-
|`20`
685-
|`3.0.0`
686-
|Application datasource pool minimum size
687-
|`apicurio.datasource.password`
688-
|`string`
689-
|`sa`
690-
|`3.0.0`
691-
|Application datasource password
692-
|`apicurio.datasource.url`
693-
|`string`
694-
|`jdbc:h2:mem:registry_db`
695-
|`3.0.0`
696-
|Application datasource jdbc url
697-
|`apicurio.datasource.username`
698-
|`string`
699-
|`sa`
700-
|`3.0.0`
701-
|Application datasource username
702672
|`apicurio.events.kafka.topic`
703673
|`string`
704674
|`registry-events`

0 commit comments

Comments
 (0)