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

[REST API] Created a /search/versions endpoint #4726

Merged
merged 4 commits into from
Jun 3, 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 @@ -31,7 +31,7 @@ public CompatibilityCheckResponse testCompatibilityBySubjectName(String subject,
final List<String> versions = storage.getArtifactVersions(groupId, subject);
for (String version : versions) {
final ArtifactVersionMetaDataDto artifactVersionMetaData = storage.getArtifactVersionMetaData(groupId, subject, version);
rulesService.applyRules(groupId, subject, version, artifactVersionMetaData.getType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
rulesService.applyRules(groupId, subject, version, artifactVersionMetaData.getArtifactType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
}
return CompatibilityCheckResponse.IS_COMPATIBLE;
} catch (RuleViolationException ex) {
Expand All @@ -53,7 +53,7 @@ public CompatibilityCheckResponse testCompatibilityByVersion(String subject, Str
return parseVersionString(subject, versionString, groupId, v -> {
try {
final ArtifactVersionMetaDataDto artifact = storage.getArtifactVersionMetaData(groupId, subject, v);
rulesService.applyRules(groupId, subject, v, artifact.getType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
rulesService.applyRules(groupId, subject, v, artifact.getArtifactType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
return CompatibilityCheckResponse.IS_COMPATIBLE;
} catch (RuleViolationException ex) {
if (fverbose) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected Schema getSchema(String groupId, String subject, String versionString,
ArtifactVersionMetaDataDto amd = storage.getArtifactVersionMetaData(groupId, subject, version);
if (amd.getState() != VersionState.DISABLED || deleted) {
StoredArtifactVersionDto storedArtifact = storage.getArtifactVersionContent(groupId, subject, amd.getVersion());
return converter.convert(subject, storedArtifact, amd.getType());
return converter.convert(subject, storedArtifact, amd.getArtifactType());
} else {
throw new VersionNotFoundException(groupId, subject, version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public class SubjectsResourceImpl extends AbstractResource implements SubjectsRe
public List<String> listSubjects(String subjectPrefix, Boolean deleted, String groupId) {
//Since contexts are not supported, subjectPrefix is not used
final boolean fdeleted = deleted == null ? Boolean.FALSE : deleted;
Set<SearchFilter> filters = new HashSet<>(Set.of(SearchFilter.ofGroup(groupId)));
Set<SearchFilter> filters = new HashSet<>(Set.of(SearchFilter.ofGroupId(groupId)));
if (!fdeleted) {
filters.add(SearchFilter.ofState(VersionState.DISABLED).negated());
}
ArtifactSearchResultsDto searchResults = storage.searchArtifacts(filters,
OrderBy.createdOn, OrderDirection.asc, 0, cconfig.maxSubjects.get());
return searchResults.getArtifacts().stream()
.filter(searchedArtifactDto -> isCcompatManagedType(searchedArtifactDto.getType()) /* && shouldFilterState(fdeleted, searchedArtifactDto.getState())*/)
.filter(searchedArtifactDto -> isCcompatManagedType(searchedArtifactDto.getArtifactType()) /* && shouldFilterState(fdeleted, searchedArtifactDto.getState())*/)
.map(SearchedArtifactDto::getArtifactId)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public class GroupsResourceImpl extends AbstractResourceImpl implements GroupsRe
io.apicurio.registry.rest.v3.GroupsResourceImpl v3;

/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getLatestArtifact(java.lang.String, java.lang.String, boolean)
* @see io.apicurio.registry.rest.v2.GroupsResource#getLatestArtifact(java.lang.String, java.lang.String, Boolean)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
Expand All @@ -173,10 +173,10 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, latestGAV.getRawVersionId());

MediaType contentType = factory.getArtifactMediaType(metaData.getType());
MediaType contentType = factory.getArtifactMediaType(metaData.getArtifactType());

ContentHandle contentToReturn = artifact.getContent();
contentToReturn = handleContentReferences(dereference, metaData.getType(), contentToReturn, artifact.getReferences());
contentToReturn = handleContentReferences(dereference, metaData.getArtifactType(), contentToReturn, artifact.getReferences());

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
checkIfDeprecated(metaData::getState, groupId, artifactId, metaData.getVersion(), builder);
Expand Down Expand Up @@ -272,7 +272,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
GAV latestGAV = storage.getArtifactBranchTip(new GA(groupId, artifactId), BranchId.LATEST, ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST);
ArtifactVersionMetaDataDto vdto = storage.getArtifactVersionMetaData(latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());

ArtifactMetaData amd = V2ApiUtil.dtoToMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getType(), dto);
ArtifactMetaData amd = V2ApiUtil.dtoToMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getArtifactType(), dto);
amd.setContentId(vdto.getContentId());
amd.setGlobalId(vdto.getGlobalId());
amd.setVersion(vdto.getVersion());
Expand Down Expand Up @@ -415,7 +415,7 @@ private VersionMetaData getArtifactVersionMetaDataByContent(String groupId, Stri
final List<ArtifactReferenceDto> artifactReferenceDtos = toReferenceDtos(artifactReferences);

ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaDataByContent(defaultGroupIdToNull(groupId), artifactId, canonical, content, artifactReferenceDtos);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getType(), dto);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getArtifactType(), dto);
}

/**
Expand Down Expand Up @@ -579,10 +579,10 @@ public Response getArtifactVersion(String groupId, String artifactId, String ver
}
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, version);

MediaType contentType = factory.getArtifactMediaType(metaData.getType());
MediaType contentType = factory.getArtifactMediaType(metaData.getArtifactType());

ContentHandle contentToReturn = artifact.getContent();
contentToReturn = handleContentReferences(dereference, metaData.getType(), contentToReturn, artifact.getReferences());
contentToReturn = handleContentReferences(dereference, metaData.getArtifactType(), contentToReturn, artifact.getReferences());

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
checkIfDeprecated(metaData::getState, groupId, artifactId, version, builder);
Expand Down Expand Up @@ -617,7 +617,7 @@ public VersionMetaData getArtifactVersionMetaData(String groupId, String artifac
requireParameter("version", version);

ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaData(defaultGroupIdToNull(groupId), artifactId, version);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getType(), dto);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getArtifactType(), dto);
}

/**
Expand Down Expand Up @@ -754,7 +754,7 @@ public ArtifactSearchResults listArtifactsInGroup(String groupId, BigInteger lim
final OrderDirection oDir = order == null || order == SortOrder.asc ? OrderDirection.asc : OrderDirection.desc;

Set<SearchFilter> filters = new HashSet<>();
filters.add(SearchFilter.ofGroup(defaultGroupIdToNull(groupId)));
filters.add(SearchFilter.ofGroupId(defaultGroupIdToNull(groupId)));

ArtifactSearchResultsDto resultsDto = storage.searchArtifacts(filters, oBy, oDir, offset.intValue(), limit.intValue());
return V2ApiUtil.dtoToSearchResults(resultsDto);
Expand Down Expand Up @@ -1005,15 +1005,21 @@ public VersionSearchResults listArtifactVersions(String groupId, String artifact
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);

// This will check if the artifact exists (throws 404 if not).
storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);

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

VersionSearchResultsDto resultsDto = storage.searchVersions(defaultGroupIdToNull(groupId),
artifactId, OrderBy.createdOn, OrderDirection.asc, offset.intValue(), limit.intValue());
Set<SearchFilter> filters = Set.of(
SearchFilter.ofGroupId(defaultGroupIdToNull(groupId)),
SearchFilter.ofArtifactId(artifactId)
);
VersionSearchResultsDto resultsDto = storage.searchVersions(filters, OrderBy.createdOn, OrderDirection.asc, offset.intValue(), limit.intValue());
return V2ApiUtil.dtoToSearchResults(resultsDto);
}

Expand Down Expand Up @@ -1116,7 +1122,7 @@ private void checkIfDeprecated(Supplier<VersionState> stateSupplier, String grou
* @param artifactId
*/
private String lookupArtifactType(String groupId, String artifactId) {
return storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId).getType();
return storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId).getArtifactType();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package io.apicurio.registry.rest.v2;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import io.apicurio.common.apps.logging.Logged;
import io.apicurio.registry.auth.Authorized;
import io.apicurio.registry.auth.AuthorizedLevel;
Expand All @@ -28,6 +24,10 @@
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

@ApplicationScoped
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
@Logged
Expand All @@ -52,7 +52,7 @@ public Response getContentById(long contentId) {
}

/**
* @see io.apicurio.registry.rest.v2.IdsResource#getContentByGlobalId(long, io.apicurio.registry.rest.v2.beans.HandleReferencesType)
* @see io.apicurio.registry.rest.v2.IdsResource#getContentByGlobalId(long, Boolean)
*/
@Override
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
Expand All @@ -68,10 +68,10 @@ public Response getContentByGlobalId(long globalId, Boolean dereference) {

StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(globalId);

MediaType contentType = factory.getArtifactMediaType(metaData.getType());
MediaType contentType = factory.getArtifactMediaType(metaData.getArtifactType());

ContentHandle contentToReturn = artifact.getContent();
handleContentReferences(dereference, metaData.getType(), contentToReturn, artifact.getReferences());
handleContentReferences(dereference, metaData.getArtifactType(), contentToReturn, artifact.getReferences());

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
checkIfDeprecated(metaData::getState, metaData.getArtifactId(), metaData.getVersion(), builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
package io.apicurio.registry.rest.v2;

import java.io.InputStream;
import java.math.BigInteger;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.core.Context;

import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;

import io.apicurio.common.apps.logging.Logged;
import io.apicurio.registry.auth.Authorized;
import io.apicurio.registry.auth.AuthorizedLevel;
import io.apicurio.registry.auth.AuthorizedStyle;
import io.apicurio.registry.content.ContentHandle;
import io.apicurio.registry.content.canon.ContentCanonicalizer;
import io.apicurio.common.apps.logging.Logged;
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
Expand All @@ -38,6 +21,21 @@
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
import io.apicurio.registry.util.ContentTypeUtil;
import io.apicurio.registry.utils.StringUtil;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.core.Context;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;

import java.io.InputStream;
import java.math.BigInteger;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@ApplicationScoped
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
Expand All @@ -61,7 +59,7 @@ public class SearchResourceImpl implements SearchResource {
HttpServletRequest request;

/**
* @see io.apicurio.registry.rest.v2.SearchResource#searchArtifacts(java.lang.String, java.lang.Integer, java.lang.Integer, io.apicurio.registry.rest.v2.beans.SortOrder, io.apicurio.registry.rest.v2.beans.SortBy, java.util.List, java.util.List, java.lang.String, java.lang.String, java.lang.Long, java.lang.Long)
* @see io.apicurio.registry.rest.v2.SearchResource#searchArtifacts(String, BigInteger, BigInteger, SortOrder, SortBy, List, List, String, String, Long, Long)
*/
@Override
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
Expand Down Expand Up @@ -90,7 +88,7 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
filters.add(SearchFilter.ofDescription(description));
}
if (!StringUtil.isEmpty(group)) {
filters.add(SearchFilter.ofGroup(gidOrNull(group)));
filters.add(SearchFilter.ofGroupId(gidOrNull(group)));
}

if (properties != null && !properties.isEmpty()) {
Expand Down Expand Up @@ -128,7 +126,7 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
}

/**
* @see io.apicurio.registry.rest.v2.SearchResource#searchArtifactsByContent(java.lang.Boolean, io.apicurio.registry.types.ArtifactType, java.lang.Integer, java.lang.Integer, io.apicurio.registry.rest.v2.beans.SortOrder, io.apicurio.registry.rest.v2.beans.SortBy, java.io.InputStream)
* @see io.apicurio.registry.rest.v2.SearchResource#searchArtifactsByContent(Boolean, String, BigInteger, BigInteger, SortOrder, SortBy, InputStream)
*/
@Override
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/io/apicurio/registry/rest/v2/V2ApiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static ArtifactMetaData dtoToMetaData(String groupId, String artifactId,
if (artifactType != null) {
metaData.setType(artifactType);
} else {
metaData.setType(dto.getType());
metaData.setType(dto.getArtifactType());
}
metaData.setState(ArtifactState.ENABLED); // TODO artifact state has gone away from the storage layer
metaData.setLabels(toV2Labels(dto.getLabels()));
Expand Down Expand Up @@ -152,7 +152,7 @@ public static ArtifactMetaData dtoToMetaData(String groupId, String artifactId,
if (artifactType != null) {
metaData.setType(artifactType);
} else {
metaData.setType(dto.getType());
metaData.setType(dto.getArtifactType());
}
metaData.setVersion(dto.getVersion());
metaData.setGlobalId(dto.getGlobalId());
Expand Down Expand Up @@ -265,7 +265,7 @@ public static ArtifactSearchResults dtoToSearchResults(ArtifactSearchResultsDto
sa.setModifiedOn(artifact.getModifiedOn());
sa.setName(artifact.getName());
sa.setState(ArtifactState.ENABLED);
sa.setType(artifact.getType());
sa.setType(artifact.getArtifactType());
results.getArtifacts().add(sa);
});
return results;
Expand Down Expand Up @@ -301,7 +301,7 @@ public static VersionSearchResults dtoToSearchResults(VersionSearchResultsDto dt
sv.setContentId(version.getContentId());
sv.setName(version.getName());
sv.setState(ArtifactState.fromValue(version.getState().name()));
sv.setType(version.getType());
sv.setType(version.getArtifactType());
sv.setVersion(version.getVersion());
results.getVersions().add(sv);
});
Expand Down
Loading
Loading