Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(search): Adding "artifactType" as a filter option when searching #5536

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,4 +1,4 @@
{

Check warning on line 1 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-api-servers

Check warning on line 1 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

rhoas-servers-config
"openapi": "3.0.3",
"info": {
"title": "Apicurio Registry API [v3]",
Expand All @@ -14,7 +14,7 @@
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"paths": {

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-media-example "value" property type must be string

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-media-example "value" property must have required property "title"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "version" property type must be string

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must match pattern "^[a-zA-Z0-9._\-+]{1,256}$"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must be equal to one of the allowed values: "OUTBOUND", "INBOUND". Did you mean "INBOUND"?

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "content" property must have required property "contentType"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must have required property "title"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "createdOn" property must match format "date-time"
"/ids/globalIds/{globalId}": {
"summary": "Access artifact content utilizing an artifact version's globally unique identifier.",
"get": {
Expand Down 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
Loading