Skip to content

Commit

Permalink
Adding "artifactType" as a filter option when searching. Fixes #5535
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Nov 15, 2024
1 parent 0ce36c2 commit cdd12d2
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class SearchResourceImpl implements SearchResource {
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, BigInteger limit,
SortOrder order, ArtifactSortBy orderby, List<String> labels, String description, String groupId,
Long globalId, Long contentId, String artifactId) {
Long globalId, Long contentId, String artifactId, String artifactType) {
if (orderby == null) {
orderby = ArtifactSortBy.name;
}
Expand Down Expand Up @@ -90,6 +90,9 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
if (!StringUtil.isEmpty(artifactId)) {
filters.add(SearchFilter.ofArtifactId(artifactId));
}
if (!StringUtil.isEmpty(artifactType)) {
filters.add(SearchFilter.ofArtifactType(artifactType));
}

if (labels != null && !labels.isEmpty()) {
labels.stream().map(prop -> {
Expand Down Expand Up @@ -234,7 +237,8 @@ public GroupSearchResults searchGroups(BigInteger offset, BigInteger limit, Sort
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
public VersionSearchResults searchVersions(String version, BigInteger offset, BigInteger limit,
SortOrder order, VersionSortBy orderby, List<String> labels, String description, String groupId,
Long globalId, Long contentId, String artifactId, String name, VersionState state) {
Long globalId, Long contentId, String artifactId, String name, VersionState state,
String artifactType) {
if (orderby == null) {
orderby = VersionSortBy.globalId;
}
Expand Down Expand Up @@ -265,6 +269,9 @@ public VersionSearchResults searchVersions(String version, BigInteger offset, Bi
if (!StringUtil.isEmpty(description)) {
filters.add(SearchFilter.ofDescription(description));
}
if (!StringUtil.isEmpty(artifactType)) {
filters.add(SearchFilter.ofArtifactType(artifactType));
}
if (labels != null && !labels.isEmpty()) {
labels.stream().map(prop -> {
int delimiterIndex = prop.indexOf(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public static SearchFilter ofVersion(String value) {
return new SearchFilter(SearchFilterType.version, value);
}

public static SearchFilter ofArtifactType(String value) {
return new SearchFilter(SearchFilterType.artifactType, value);
}

public static SearchFilter ofCanonicalHash(String value) {
return new SearchFilter(SearchFilterType.canonicalHash, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public enum SearchFilterType {

groupId, artifactId, version, name, description, labels, contentHash, canonicalHash, globalId, contentId, state
groupId, artifactId, version, name, description, labels, contentHash, canonicalHash, globalId, contentId, state, artifactType

}
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,13 @@ public ArtifactSearchResultsDto searchArtifacts(Set<SearchFilter> filters, Order
query.bind(idx, filter.getStringValue());
});
break;
case artifactType:
op = filter.isNot() ? "!=" : "=";
where.append("a.type " + op + " ?");
binders.add((query, idx) -> {
query.bind(idx, filter.getStringValue());
});
break;
case contentHash:
op = filter.isNot() ? "!=" : "=";
where.append(
Expand Down Expand Up @@ -1601,9 +1608,17 @@ public VersionSearchResultsDto searchVersions(Set<SearchFilter> filters, OrderBy
query.bind(idx, normalizeGroupId(filter.getStringValue()));
});
break;
case artifactType:
op = filter.isNot() ? "!=" : "=";
where.append("a.type " + op + " ?");
binders.add((query, idx) -> {
query.bind(idx, filter.getStringValue());
});
break;
case artifactId:
case contentId:
case globalId:
case state:
case version:
op = filter.isNot() ? "!=" : "=";
where.append("v.");
Expand Down Expand Up @@ -1664,13 +1679,6 @@ public VersionSearchResultsDto searchVersions(Set<SearchFilter> filters, OrderBy
});
where.append(")");
break;
case state:
op = filter.isNot() ? "!=" : "=";
where.append("v.state " + op + " ?");
binders.add((query, idx) -> {
query.bind(idx, normalizeGroupId(filter.getStringValue()));
});
break;
default:
throw new RegistryStorageException("Filter type not supported: " + filter.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.apicurio.registry.rest.client.models.SortOrder;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.ContentTypes;
import io.apicurio.registry.utils.tests.TestUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -195,4 +196,31 @@ void testCaseInsensitiveSearch() throws Exception {
Assertions.assertEquals(1, propertiesSearch.getCount());
}

}
@Test
void testFilterByArtifactType() throws Exception {
String groupId = TestUtils.generateGroupId();

createArtifact(groupId, "avro-artifact", ArtifactType.AVRO, "{}", ContentTypes.APPLICATION_JSON);
createArtifact(groupId, "json-artifact", ArtifactType.JSON, "{}", ContentTypes.APPLICATION_JSON);

ArtifactSearchResults results = clientV3.search().artifacts().get(config -> {
config.queryParameters.groupId = groupId;
});
Assertions.assertNotNull(results);
Assertions.assertEquals(2, results.getCount());

results = clientV3.search().artifacts().get(config -> {
config.queryParameters.groupId = groupId;
config.queryParameters.artifactType = ArtifactType.AVRO;
});
Assertions.assertNotNull(results);
Assertions.assertEquals(1, results.getCount());

results = clientV3.search().artifacts().get(config -> {
config.queryParameters.groupId = groupId;
config.queryParameters.artifactType = ArtifactType.JSON;
});
Assertions.assertNotNull(results);
Assertions.assertEquals(1, results.getCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.apicurio.registry.noprofile;

import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.rest.client.models.VersionSearchResults;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.ContentTypes;
import io.apicurio.registry.utils.tests.TestUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class VersionSearchTest extends AbstractResourceTestBase {

@Test
void testFilterByArtifactType() throws Exception {
String groupId = TestUtils.generateGroupId();

createArtifact(groupId, "avro-artifact", ArtifactType.AVRO, "{}", ContentTypes.APPLICATION_JSON);
createArtifactVersion(groupId, "avro-artifact", "{ }", ContentTypes.APPLICATION_JSON);
createArtifact(groupId, "json-artifact", ArtifactType.JSON, "{}", ContentTypes.APPLICATION_JSON);

VersionSearchResults results = clientV3.search().versions().get(config -> {
config.queryParameters.groupId = groupId;
});
Assertions.assertNotNull(results);
Assertions.assertEquals(3, results.getCount());

results = clientV3.search().versions().get(config -> {
config.queryParameters.groupId = groupId;
config.queryParameters.artifactType = ArtifactType.AVRO;
});
Assertions.assertNotNull(results);
Assertions.assertEquals(2, results.getCount());

results = clientV3.search().versions().get(config -> {
config.queryParameters.groupId = groupId;
config.queryParameters.artifactType = ArtifactType.JSON;
});
Assertions.assertNotNull(results);
Assertions.assertEquals(1, results.getCount());

}
}
16 changes: 16 additions & 0 deletions common/src/main/resources/META-INF/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@
"type": "string"
},
"in": "query"
},
{
"name": "artifactType",
"description": "Filter by artifact type (`AVRO`, `JSON`, etc).",
"schema": {
"$ref": "#/components/schemas/ArtifactType"
},
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -2930,6 +2938,14 @@
"$ref": "#/components/schemas/VersionState"
},
"in": "query"
},
{
"name": "artifactType",
"description": "Filter by artifact type (`AVRO`, `JSON`, etc).",
"schema": {
"$ref": "#/components/schemas/ArtifactType"
},
"in": "query"
}
],
"responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,36 +669,6 @@ The following {registry} configuration options are available for each component
|`sa`
|`3.0.0`
|Gitops green datasource username
|`apicurio.datasource.jdbc.initial-size`
|`string`
|`20`
|`3.0.0`
|Application datasource pool initial size
|`apicurio.datasource.jdbc.max-size`
|`string`
|`100`
|`3.0.0`
|Application datasource pool maximum size
|`apicurio.datasource.jdbc.min-size`
|`string`
|`20`
|`3.0.0`
|Application datasource pool minimum size
|`apicurio.datasource.password`
|`string`
|`sa`
|`3.0.0`
|Application datasource password
|`apicurio.datasource.url`
|`string`
|`jdbc:h2:mem:registry_db`
|`3.0.0`
|Application datasource jdbc url
|`apicurio.datasource.username`
|`string`
|`sa`
|`3.0.0`
|Application datasource username
|`apicurio.events.kafka.topic`
|`string`
|`registry-events`
Expand Down
Loading

0 comments on commit cdd12d2

Please sign in to comment.