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

Updated user interface to support 3.x REST API changes #4709

Merged
merged 6 commits into from
May 29, 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 @@ -1012,7 +1012,8 @@ public VersionSearchResults listArtifactVersions(String groupId, String artifact
limit = BigInteger.valueOf(20);
}

VersionSearchResultsDto resultsDto = storage.searchVersions(defaultGroupIdToNull(groupId), artifactId, offset.intValue(), limit.intValue());
VersionSearchResultsDto resultsDto = storage.searchVersions(defaultGroupIdToNull(groupId),
artifactId, OrderBy.createdOn, OrderDirection.asc, offset.intValue(), limit.intValue());
return V2ApiUtil.dtoToSearchResults(resultsDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.apicurio.registry.rest.v3.beans.ArtifactMetaData;
import io.apicurio.registry.rest.v3.beans.ArtifactReference;
import io.apicurio.registry.rest.v3.beans.ArtifactSearchResults;
import io.apicurio.registry.rest.v3.beans.ArtifactSortBy;
import io.apicurio.registry.rest.v3.beans.Comment;
import io.apicurio.registry.rest.v3.beans.CreateArtifact;
import io.apicurio.registry.rest.v3.beans.CreateArtifactResponse;
Expand All @@ -32,16 +33,16 @@
import io.apicurio.registry.rest.v3.beans.EditableVersionMetaData;
import io.apicurio.registry.rest.v3.beans.GroupMetaData;
import io.apicurio.registry.rest.v3.beans.GroupSearchResults;
import io.apicurio.registry.rest.v3.beans.GroupSortBy;
import io.apicurio.registry.rest.v3.beans.HandleReferencesType;
import io.apicurio.registry.rest.v3.beans.IfArtifactExists;
import io.apicurio.registry.rest.v3.beans.IfVersionExists;
import io.apicurio.registry.rest.v3.beans.NewComment;
import io.apicurio.registry.rest.v3.beans.Rule;
import io.apicurio.registry.rest.v3.beans.SortBy;
import io.apicurio.registry.rest.v3.beans.SortOrder;
import io.apicurio.registry.rest.v3.beans.VersionContent;
import io.apicurio.registry.rest.v3.beans.VersionMetaData;
import io.apicurio.registry.rest.v3.beans.VersionSearchResults;
import io.apicurio.registry.rest.v3.beans.VersionSortBy;
import io.apicurio.registry.rest.v3.shared.CommonResourceOperations;
import io.apicurio.registry.rules.RuleApplicationType;
import io.apicurio.registry.rules.RulesService;
Expand Down Expand Up @@ -248,9 +249,9 @@ public void updateGroupById(String groupId, EditableGroupMetaData data) {

@Override
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
public GroupSearchResults listGroups(BigInteger limit, BigInteger offset, SortOrder order, SortBy orderby) {
public GroupSearchResults listGroups(BigInteger limit, BigInteger offset, SortOrder order, GroupSortBy orderby) {
if (orderby == null) {
orderby = SortBy.name;
orderby = GroupSortBy.groupId;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
Expand All @@ -272,7 +273,7 @@ public GroupSearchResults listGroups(BigInteger limit, BigInteger offset, SortOr
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Write)
public GroupMetaData createGroup(CreateGroup data) {
GroupMetaDataDto.GroupMetaDataDtoBuilder group = GroupMetaDataDto.builder()
.groupId(data.getId())
.groupId(data.getGroupId())
.description(data.getDescription())
.labels(data.getLabels());

Expand All @@ -281,7 +282,7 @@ public GroupMetaData createGroup(CreateGroup data) {

storage.createGroup(group.build());

return V3ApiUtil.groupDtoToGroup(storage.getGroupMetaData(data.getId()));
return V3ApiUtil.groupDtoToGroup(storage.getGroupMetaData(data.getGroupId()));
}

@Override
Expand Down Expand Up @@ -614,11 +615,11 @@ public void updateArtifactVersionComment(String groupId, String artifactId, Stri
@Override
@Authorized(style = AuthorizedStyle.GroupOnly, level = AuthorizedLevel.Read)
public ArtifactSearchResults listArtifactsInGroup(String groupId, BigInteger limit, BigInteger offset,
SortOrder order, SortBy orderby) {
SortOrder order, ArtifactSortBy orderby) {
requireParameter("groupId", groupId);

if (orderby == null) {
orderby = SortBy.name;
orderby = ArtifactSortBy.name;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
Expand Down Expand Up @@ -770,28 +771,34 @@ public CreateArtifactResponse createArtifact(String groupId, IfArtifactExists if
}
}


@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public VersionSearchResults listArtifactVersions(String groupId, String artifactId, BigInteger offset, BigInteger limit) {
public VersionSearchResults listArtifactVersions(String groupId, String artifactId, BigInteger offset,
BigInteger limit, SortOrder order, VersionSortBy orderby) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);

if (orderby == null) {
orderby = VersionSortBy.createdOn;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
}
if (limit == null) {
limit = BigInteger.valueOf(20);
}

VersionSearchResultsDto resultsDto = storage.searchVersions(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, offset.intValue(), limit.intValue());
final OrderBy oBy = OrderBy.valueOf(orderby.name());
final OrderDirection oDir = order == null || order == SortOrder.desc ? OrderDirection.asc : OrderDirection.desc;

VersionSearchResultsDto resultsDto = storage.searchVersions(new GroupId(groupId).getRawGroupIdWithNull(),
artifactId, oBy, oDir, offset.intValue(), limit.intValue());
return V3ApiUtil.dtoToSearchResults(resultsDto);
}

@Override
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_IF_EXISTS})
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID})
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public VersionMetaData createArtifactVersion(String groupId, String artifactId, IfVersionExists ifExists, CreateVersion data) {
public VersionMetaData createArtifactVersion(String groupId, String artifactId, CreateVersion data) {
requireParameter("content", data.getContent());
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
import io.apicurio.registry.model.GroupId;
import io.apicurio.registry.rest.v3.beans.ArtifactSearchResults;
import io.apicurio.registry.rest.v3.beans.SortBy;
import io.apicurio.registry.rest.v3.beans.ArtifactSortBy;
import io.apicurio.registry.rest.v3.beans.GroupSearchResults;
import io.apicurio.registry.rest.v3.beans.GroupSortBy;
import io.apicurio.registry.rest.v3.beans.SortOrder;
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.dto.ArtifactSearchResultsDto;
import io.apicurio.registry.storage.dto.GroupSearchResultsDto;
import io.apicurio.registry.storage.dto.OrderBy;
import io.apicurio.registry.storage.dto.OrderDirection;
import io.apicurio.registry.storage.dto.SearchFilter;
Expand Down Expand Up @@ -51,15 +54,14 @@ public class SearchResourceImpl implements SearchResource {
@Inject
RegistryStorageContentUtils contentUtils;


@Override
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, BigInteger limit, SortOrder order,
SortBy orderby, List<String> labels, String description, String group,
Long globalId, Long contentId)
ArtifactSortBy orderby, List<String> labels, String description, String groupId, Long globalId, Long contentId,
String artifactId)
{
if (orderby == null) {
orderby = SortBy.name;
orderby = ArtifactSortBy.name;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
Expand All @@ -69,7 +71,7 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
}

final OrderBy oBy = OrderBy.valueOf(orderby.name());
final OrderDirection oDir = order == null || order == SortOrder.asc ? OrderDirection.asc : OrderDirection.desc;
final OrderDirection oDir = (order == null || order == SortOrder.asc) ? OrderDirection.asc : OrderDirection.desc;

Set<SearchFilter> filters = new HashSet<SearchFilter>();
if (!StringUtil.isEmpty(name)) {
Expand All @@ -78,8 +80,8 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
if (!StringUtil.isEmpty(description)) {
filters.add(SearchFilter.ofDescription(description));
}
if (!StringUtil.isEmpty(group)) {
filters.add(SearchFilter.ofGroup(new GroupId(group).getRawGroupIdWithNull()));
if (!StringUtil.isEmpty(groupId)) {
filters.add(SearchFilter.ofGroup(new GroupId(groupId).getRawGroupIdWithNull()));
}

if (labels != null && !labels.isEmpty()) {
Expand Down Expand Up @@ -116,13 +118,13 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
return V3ApiUtil.dtoToSearchResults(results);
}


@Override
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
public ArtifactSearchResults searchArtifactsByContent(Boolean canonical, String artifactType, BigInteger offset, BigInteger limit, SortOrder order, SortBy orderby, InputStream data) {
public ArtifactSearchResults searchArtifactsByContent(Boolean canonical, String artifactType, BigInteger offset,
BigInteger limit, SortOrder order, ArtifactSortBy orderby, InputStream data) {

if (orderby == null) {
orderby = SortBy.name;
orderby = ArtifactSortBy.name;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
Expand Down Expand Up @@ -158,6 +160,58 @@ public ArtifactSearchResults searchArtifactsByContent(Boolean canonical, String
return V3ApiUtil.dtoToSearchResults(results);
}

@Override
public GroupSearchResults searchGroups(BigInteger offset, BigInteger limit, SortOrder order, GroupSortBy orderby,
List<String> labels, String description, String groupId) {
if (orderby == null) {
orderby = GroupSortBy.groupId;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
}
if (limit == null) {
limit = BigInteger.valueOf(20);
}

final OrderBy oBy = OrderBy.valueOf(orderby.name());
final OrderDirection oDir = order == null || order == SortOrder.asc ? OrderDirection.asc : OrderDirection.desc;

Set<SearchFilter> filters = new HashSet<SearchFilter>();
if (!StringUtil.isEmpty(groupId)) {
filters.add(SearchFilter.ofGroup(groupId));
}
if (!StringUtil.isEmpty(description)) {
filters.add(SearchFilter.ofDescription(description));
}

if (labels != null && !labels.isEmpty()) {
labels.stream()
.map(prop -> {
int delimiterIndex = prop.indexOf(":");
String labelKey;
String labelValue;
if (delimiterIndex == 0) {
throw new BadRequestException("label search filter wrong formatted, missing left side of ':' delimiter");
}
if (delimiterIndex == (prop.length() - 1)) {
throw new BadRequestException("label search filter wrong formatted, missing right side of ':' delimiter");
}
if (delimiterIndex < 0) {
labelKey = prop;
labelValue = null;
} else{
labelKey = prop.substring(0, delimiterIndex);
labelValue = prop.substring(delimiterIndex + 1);
}
return SearchFilter.ofLabel(labelKey, labelValue);
})
.forEach(filters::add);
}

GroupSearchResultsDto results = storage.searchGroups(filters, oBy, oDir, offset.intValue(), limit.intValue());
return V3ApiUtil.dtoToSearchResults(results);
}

/**
* Make sure this is ONLY used when request instance is active.
* e.g. in actual http request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ void updateArtifactRule(String groupId, String artifactId, RuleType rule, RuleCo
* @throws ArtifactNotFoundException
* @throws RegistryStorageException
*/
VersionSearchResultsDto searchVersions(String groupId, String artifactId, int offset, int limit) throws ArtifactNotFoundException, RegistryStorageException;
VersionSearchResultsDto searchVersions(String groupId, String artifactId, OrderBy orderBy,
OrderDirection orderDirection, int offset, int limit) throws ArtifactNotFoundException, RegistryStorageException;

/**
* Gets the stored artifact content for the artifact version with the given unique global ID.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package io.apicurio.registry.storage.decorator;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

import io.apicurio.common.apps.config.DynamicConfigPropertyDto;
import io.apicurio.registry.content.ContentHandle;
import io.apicurio.registry.model.BranchId;
Expand Down Expand Up @@ -39,6 +32,13 @@
import io.apicurio.registry.types.RuleType;
import io.apicurio.registry.utils.impexp.Entity;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

/**
* Forwards all read-only method calls to the delegate.
*
Expand Down Expand Up @@ -160,11 +160,9 @@ public List<String> getArtifactVersions(String groupId, String artifactId)
return delegate.getArtifactVersions(groupId, artifactId);
}


@Override
public VersionSearchResultsDto searchVersions(String groupId, String artifactId, int offset, int limit)
throws ArtifactNotFoundException, RegistryStorageException {
return delegate.searchVersions(groupId, artifactId, offset, limit);
public VersionSearchResultsDto searchVersions(String groupId, String artifactId, OrderBy orderBy, OrderDirection orderDirection, int offset, int limit) throws RegistryStorageException {
return delegate.searchVersions(groupId, artifactId, orderBy, orderDirection, offset, limit);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.apicurio.registry.storage.dto;

public enum OrderBy {
name, createdOn, globalId
name, createdOn, modifiedOn, // Shared
groupId, // Group specific
artifactId, artifactType, // Artifact specific
globalId, version // Version specific
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public static SearchFilter ofState(VersionState state) {
return new SearchFilter(SearchFilterType.state, state.name());
}

public static SearchFilter ofEverything(String value) {
return new SearchFilter(SearchFilterType.everything, value);
}

@SuppressWarnings("unchecked")
public Pair<String, String> getLabelFilterValue() {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public enum SearchFilterType {

group, name, description, labels, contentHash, canonicalHash,
everything, globalId, contentId, state
group, name, description, labels, contentHash, canonicalHash, globalId, contentId, state

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@
import io.apicurio.common.apps.logging.Logged;
import io.apicurio.registry.content.ContentHandle;
import io.apicurio.registry.metrics.StorageMetricsApply;
import io.apicurio.registry.model.BranchId;
import io.apicurio.registry.model.GA;
import io.apicurio.registry.model.GAV;
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.dto.*;
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactSearchResultsDto;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.CommentDto;
import io.apicurio.registry.storage.dto.ContentWrapperDto;
import io.apicurio.registry.storage.dto.GroupMetaDataDto;
import io.apicurio.registry.storage.dto.GroupSearchResultsDto;
import io.apicurio.registry.storage.dto.OrderBy;
import io.apicurio.registry.storage.dto.OrderDirection;
import io.apicurio.registry.storage.dto.RoleMappingDto;
import io.apicurio.registry.storage.dto.RoleMappingSearchResultsDto;
import io.apicurio.registry.storage.dto.RuleConfigurationDto;
import io.apicurio.registry.storage.dto.SearchFilter;
import io.apicurio.registry.storage.dto.StoredArtifactVersionDto;
import io.apicurio.registry.storage.dto.VersionSearchResultsDto;
import io.apicurio.registry.storage.error.RegistryStorageException;
import io.apicurio.registry.storage.error.VersionNotFoundException;
import io.apicurio.registry.storage.impl.gitops.sql.BlueSqlStorage;
import io.apicurio.registry.storage.impl.gitops.sql.GreenSqlStorage;
import io.apicurio.registry.model.BranchId;
import io.apicurio.registry.model.GA;
import io.apicurio.registry.model.GAV;
import io.apicurio.registry.types.RuleType;
import io.apicurio.registry.utils.impexp.Entity;
import io.quarkus.scheduler.Scheduled;
Expand Down Expand Up @@ -267,10 +282,9 @@ public List<String> getArtifactVersions(String groupId, String artifactId, Artif
return proxy(storage -> storage.getArtifactVersions(groupId, artifactId, behavior));
}


@Override
public VersionSearchResultsDto searchVersions(String groupId, String artifactId, int offset, int limit) {
return proxy(storage -> storage.searchVersions(groupId, artifactId, offset, limit));
public VersionSearchResultsDto searchVersions(String groupId, String artifactId, OrderBy orderBy, OrderDirection orderDirection, int offset, int limit) throws RegistryStorageException {
return proxy(storage -> storage.searchVersions(groupId, artifactId, orderBy, orderDirection, offset, limit));
}


Expand Down
Loading
Loading