Skip to content

Commit

Permalink
Implement the artifactId filter when searching artifacts (#5429)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann authored Oct 29, 2024
1 parent 4728176 commit 2986294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,13 @@ public ArtifactSearchResultsDto searchArtifacts(Set<SearchFilter> 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(
Expand Down Expand Up @@ -1053,6 +1060,8 @@ public ArtifactSearchResultsDto searchArtifacts(Set<SearchFilter> filters, Order
});
where.append(")");
break;
default:
throw new RegistryStorageException("Filter type not supported: " + filter.getType());
}
where.append(")");
}
Expand Down Expand Up @@ -1663,7 +1672,7 @@ public VersionSearchResultsDto searchVersions(Set<SearchFilter> filters, OrderBy
});
break;
default:
break;
throw new RegistryStorageException("Filter type not supported: " + filter.getType());
}
where.append(")");
}
Expand Down Expand Up @@ -2838,8 +2847,7 @@ public GroupSearchResultsDto searchGroups(Set<SearchFilter> filters, OrderBy ord
where.append(" AND l.groupId = g.groupId)");
break;
default:

break;
throw new RegistryStorageException("Filter type not supported: " + filter.getType());
}
where.append(")");
}
Expand Down

0 comments on commit 2986294

Please sign in to comment.