From df4b16976400ec787c933c9a422c5b577abd57d4 Mon Sep 17 00:00:00 2001 From: Eric Wittmann Date: Tue, 29 Oct 2024 09:33:59 -0400 Subject: [PATCH] Implement the artifactId filter when searching artifacts --- .../registry/rest/v3/SearchResourceImpl.java | 7 +++++-- .../impl/sql/AbstractSqlRegistryStorage.java | 14 +++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/apicurio/registry/rest/v3/SearchResourceImpl.java b/app/src/main/java/io/apicurio/registry/rest/v3/SearchResourceImpl.java index 6e64dbe93c..ff16facbac 100644 --- a/app/src/main/java/io/apicurio/registry/rest/v3/SearchResourceImpl.java +++ b/app/src/main/java/io/apicurio/registry/rest/v3/SearchResourceImpl.java @@ -87,6 +87,9 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big if (!StringUtil.isEmpty(groupId)) { filters.add(SearchFilter.ofGroupId(new GroupId(groupId).getRawGroupIdWithNull())); } + if (!StringUtil.isEmpty(artifactId)) { + filters.add(SearchFilter.ofArtifactId(artifactId)); + } if (labels != null && !labels.isEmpty()) { labels.stream().map(prop -> { @@ -95,11 +98,11 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big String labelValue; if (delimiterIndex == 0) { throw new BadRequestException( - "label search filter wrong formatted, missing left side of ':' delimiter"); + "label search filter wrong format, missing left side of ':' delimiter"); } if (delimiterIndex == (prop.length() - 1)) { throw new BadRequestException( - "label search filter wrong formatted, missing right side of ':' delimiter"); + "label search filter wrong format, missing right side of ':' delimiter"); } if (delimiterIndex < 0) { labelKey = prop; diff --git a/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java b/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java index 6aa0a57f01..120a5e5e52 100644 --- a/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java +++ b/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java @@ -983,6 +983,13 @@ public ArtifactSearchResultsDto searchArtifacts(Set filters, Order query.bind(idx, normalizeGroupId(filter.getStringValue())); }); break; + case artifactId: + op = filter.isNot() ? "!=" : "="; + where.append("a.artifactId " + op + " ?"); + binders.add((query, idx) -> { + query.bind(idx, filter.getStringValue()); + }); + break; case contentHash: op = filter.isNot() ? "!=" : "="; where.append( @@ -1053,6 +1060,8 @@ public ArtifactSearchResultsDto searchArtifacts(Set filters, Order }); where.append(")"); break; + default: + throw new RegistryStorageException("Filter type not supported: " + filter.getType()); } where.append(")"); } @@ -1663,7 +1672,7 @@ public VersionSearchResultsDto searchVersions(Set filters, OrderBy }); break; default: - break; + throw new RegistryStorageException("Filter type not supported: " + filter.getType()); } where.append(")"); } @@ -2838,8 +2847,7 @@ public GroupSearchResultsDto searchGroups(Set filters, OrderBy ord where.append(" AND l.groupId = g.groupId)"); break; default: - - break; + throw new RegistryStorageException("Filter type not supported: " + filter.getType()); } where.append(")"); }