Skip to content

Commit 216de81

Browse files
authored
[REST API] Created a /search/versions endpoint (#4726)
* Added a new /search/versions endpoint * Remove test generated script.sql file * Fix examples due to mojo property rename from "type" to "artifactType"
1 parent 55505d5 commit 216de81

File tree

79 files changed

+5816
-5312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5816
-5312
lines changed

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/CompatibilityResourceImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public CompatibilityCheckResponse testCompatibilityBySubjectName(String subject,
3131
final List<String> versions = storage.getArtifactVersions(groupId, subject);
3232
for (String version : versions) {
3333
final ArtifactVersionMetaDataDto artifactVersionMetaData = storage.getArtifactVersionMetaData(groupId, subject, version);
34-
rulesService.applyRules(groupId, subject, version, artifactVersionMetaData.getType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
34+
rulesService.applyRules(groupId, subject, version, artifactVersionMetaData.getArtifactType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
3535
}
3636
return CompatibilityCheckResponse.IS_COMPATIBLE;
3737
} catch (RuleViolationException ex) {
@@ -53,7 +53,7 @@ public CompatibilityCheckResponse testCompatibilityByVersion(String subject, Str
5353
return parseVersionString(subject, versionString, groupId, v -> {
5454
try {
5555
final ArtifactVersionMetaDataDto artifact = storage.getArtifactVersionMetaData(groupId, subject, v);
56-
rulesService.applyRules(groupId, subject, v, artifact.getType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
56+
rulesService.applyRules(groupId, subject, v, artifact.getArtifactType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
5757
return CompatibilityCheckResponse.IS_COMPATIBLE;
5858
} catch (RuleViolationException ex) {
5959
if (fverbose) {

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/SubjectVersionsResourceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected Schema getSchema(String groupId, String subject, String versionString,
186186
ArtifactVersionMetaDataDto amd = storage.getArtifactVersionMetaData(groupId, subject, version);
187187
if (amd.getState() != VersionState.DISABLED || deleted) {
188188
StoredArtifactVersionDto storedArtifact = storage.getArtifactVersionContent(groupId, subject, amd.getVersion());
189-
return converter.convert(subject, storedArtifact, amd.getType());
189+
return converter.convert(subject, storedArtifact, amd.getArtifactType());
190190
} else {
191191
throw new VersionNotFoundException(groupId, subject, version);
192192
}

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/SubjectsResourceImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public class SubjectsResourceImpl extends AbstractResource implements SubjectsRe
4444
public List<String> listSubjects(String subjectPrefix, Boolean deleted, String groupId) {
4545
//Since contexts are not supported, subjectPrefix is not used
4646
final boolean fdeleted = deleted == null ? Boolean.FALSE : deleted;
47-
Set<SearchFilter> filters = new HashSet<>(Set.of(SearchFilter.ofGroup(groupId)));
47+
Set<SearchFilter> filters = new HashSet<>(Set.of(SearchFilter.ofGroupId(groupId)));
4848
if (!fdeleted) {
4949
filters.add(SearchFilter.ofState(VersionState.DISABLED).negated());
5050
}
5151
ArtifactSearchResultsDto searchResults = storage.searchArtifacts(filters,
5252
OrderBy.createdOn, OrderDirection.asc, 0, cconfig.maxSubjects.get());
5353
return searchResults.getArtifacts().stream()
54-
.filter(searchedArtifactDto -> isCcompatManagedType(searchedArtifactDto.getType()) /* && shouldFilterState(fdeleted, searchedArtifactDto.getState())*/)
54+
.filter(searchedArtifactDto -> isCcompatManagedType(searchedArtifactDto.getArtifactType()) /* && shouldFilterState(fdeleted, searchedArtifactDto.getState())*/)
5555
.map(SearchedArtifactDto::getArtifactId)
5656
.collect(Collectors.toList());
5757
}

app/src/main/java/io/apicurio/registry/rest/v2/GroupsResourceImpl.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public class GroupsResourceImpl extends AbstractResourceImpl implements GroupsRe
156156
io.apicurio.registry.rest.v3.GroupsResourceImpl v3;
157157

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

176-
MediaType contentType = factory.getArtifactMediaType(metaData.getType());
176+
MediaType contentType = factory.getArtifactMediaType(metaData.getArtifactType());
177177

178178
ContentHandle contentToReturn = artifact.getContent();
179-
contentToReturn = handleContentReferences(dereference, metaData.getType(), contentToReturn, artifact.getReferences());
179+
contentToReturn = handleContentReferences(dereference, metaData.getArtifactType(), contentToReturn, artifact.getReferences());
180180

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

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

417417
ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaDataByContent(defaultGroupIdToNull(groupId), artifactId, canonical, content, artifactReferenceDtos);
418-
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getType(), dto);
418+
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getArtifactType(), dto);
419419
}
420420

421421
/**
@@ -579,10 +579,10 @@ public Response getArtifactVersion(String groupId, String artifactId, String ver
579579
}
580580
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, version);
581581

582-
MediaType contentType = factory.getArtifactMediaType(metaData.getType());
582+
MediaType contentType = factory.getArtifactMediaType(metaData.getArtifactType());
583583

584584
ContentHandle contentToReturn = artifact.getContent();
585-
contentToReturn = handleContentReferences(dereference, metaData.getType(), contentToReturn, artifact.getReferences());
585+
contentToReturn = handleContentReferences(dereference, metaData.getArtifactType(), contentToReturn, artifact.getReferences());
586586

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

619619
ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaData(defaultGroupIdToNull(groupId), artifactId, version);
620-
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getType(), dto);
620+
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getArtifactType(), dto);
621621
}
622622

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

756756
Set<SearchFilter> filters = new HashSet<>();
757-
filters.add(SearchFilter.ofGroup(defaultGroupIdToNull(groupId)));
757+
filters.add(SearchFilter.ofGroupId(defaultGroupIdToNull(groupId)));
758758

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

1008+
// This will check if the artifact exists (throws 404 if not).
1009+
storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);
1010+
10081011
if (offset == null) {
10091012
offset = BigInteger.valueOf(0);
10101013
}
10111014
if (limit == null) {
10121015
limit = BigInteger.valueOf(20);
10131016
}
10141017

1015-
VersionSearchResultsDto resultsDto = storage.searchVersions(defaultGroupIdToNull(groupId),
1016-
artifactId, OrderBy.createdOn, OrderDirection.asc, offset.intValue(), limit.intValue());
1018+
Set<SearchFilter> filters = Set.of(
1019+
SearchFilter.ofGroupId(defaultGroupIdToNull(groupId)),
1020+
SearchFilter.ofArtifactId(artifactId)
1021+
);
1022+
VersionSearchResultsDto resultsDto = storage.searchVersions(filters, OrderBy.createdOn, OrderDirection.asc, offset.intValue(), limit.intValue());
10171023
return V2ApiUtil.dtoToSearchResults(resultsDto);
10181024
}
10191025

@@ -1116,7 +1122,7 @@ private void checkIfDeprecated(Supplier<VersionState> stateSupplier, String grou
11161122
* @param artifactId
11171123
*/
11181124
private String lookupArtifactType(String groupId, String artifactId) {
1119-
return storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId).getType();
1125+
return storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId).getArtifactType();
11201126
}
11211127

11221128
/**

app/src/main/java/io/apicurio/registry/rest/v2/IdsResourceImpl.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package io.apicurio.registry.rest.v2;
22

3-
import java.util.List;
4-
import java.util.function.Supplier;
5-
import java.util.stream.Collectors;
6-
73
import io.apicurio.common.apps.logging.Logged;
84
import io.apicurio.registry.auth.Authorized;
95
import io.apicurio.registry.auth.AuthorizedLevel;
@@ -28,6 +24,10 @@
2824
import jakarta.ws.rs.core.MediaType;
2925
import jakarta.ws.rs.core.Response;
3026

27+
import java.util.List;
28+
import java.util.function.Supplier;
29+
import java.util.stream.Collectors;
30+
3131
@ApplicationScoped
3232
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
3333
@Logged
@@ -52,7 +52,7 @@ public Response getContentById(long contentId) {
5252
}
5353

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

6969
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(globalId);
7070

71-
MediaType contentType = factory.getArtifactMediaType(metaData.getType());
71+
MediaType contentType = factory.getArtifactMediaType(metaData.getArtifactType());
7272

7373
ContentHandle contentToReturn = artifact.getContent();
74-
handleContentReferences(dereference, metaData.getType(), contentToReturn, artifact.getReferences());
74+
handleContentReferences(dereference, metaData.getArtifactType(), contentToReturn, artifact.getReferences());
7575

7676
Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
7777
checkIfDeprecated(metaData::getState, metaData.getArtifactId(), metaData.getVersion(), builder);

app/src/main/java/io/apicurio/registry/rest/v2/SearchResourceImpl.java

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
package io.apicurio.registry.rest.v2;
22

3-
import java.io.InputStream;
4-
import java.math.BigInteger;
5-
import java.util.Collections;
6-
import java.util.HashSet;
7-
import java.util.List;
8-
import java.util.Set;
9-
10-
import jakarta.enterprise.context.ApplicationScoped;
11-
import jakarta.inject.Inject;
12-
import jakarta.interceptor.Interceptors;
13-
import jakarta.servlet.http.HttpServletRequest;
14-
import jakarta.ws.rs.BadRequestException;
15-
import jakarta.ws.rs.core.Context;
16-
17-
import org.apache.commons.codec.digest.DigestUtils;
18-
import org.slf4j.Logger;
19-
3+
import io.apicurio.common.apps.logging.Logged;
204
import io.apicurio.registry.auth.Authorized;
215
import io.apicurio.registry.auth.AuthorizedLevel;
226
import io.apicurio.registry.auth.AuthorizedStyle;
237
import io.apicurio.registry.content.ContentHandle;
248
import io.apicurio.registry.content.canon.ContentCanonicalizer;
25-
import io.apicurio.common.apps.logging.Logged;
269
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2710
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
2811
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
@@ -38,6 +21,21 @@
3821
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
3922
import io.apicurio.registry.util.ContentTypeUtil;
4023
import io.apicurio.registry.utils.StringUtil;
24+
import jakarta.enterprise.context.ApplicationScoped;
25+
import jakarta.inject.Inject;
26+
import jakarta.interceptor.Interceptors;
27+
import jakarta.servlet.http.HttpServletRequest;
28+
import jakarta.ws.rs.BadRequestException;
29+
import jakarta.ws.rs.core.Context;
30+
import org.apache.commons.codec.digest.DigestUtils;
31+
import org.slf4j.Logger;
32+
33+
import java.io.InputStream;
34+
import java.math.BigInteger;
35+
import java.util.Collections;
36+
import java.util.HashSet;
37+
import java.util.List;
38+
import java.util.Set;
4139

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

6361
/**
64-
* @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)
62+
* @see io.apicurio.registry.rest.v2.SearchResource#searchArtifacts(String, BigInteger, BigInteger, SortOrder, SortBy, List, List, String, String, Long, Long)
6563
*/
6664
@Override
6765
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
@@ -90,7 +88,7 @@ public ArtifactSearchResults searchArtifacts(String name, BigInteger offset, Big
9088
filters.add(SearchFilter.ofDescription(description));
9189
}
9290
if (!StringUtil.isEmpty(group)) {
93-
filters.add(SearchFilter.ofGroup(gidOrNull(group)));
91+
filters.add(SearchFilter.ofGroupId(gidOrNull(group)));
9492
}
9593

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

130128
/**
131-
* @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)
129+
* @see io.apicurio.registry.rest.v2.SearchResource#searchArtifactsByContent(Boolean, String, BigInteger, BigInteger, SortOrder, SortBy, InputStream)
132130
*/
133131
@Override
134132
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)

app/src/main/java/io/apicurio/registry/rest/v2/V2ApiUtil.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static ArtifactMetaData dtoToMetaData(String groupId, String artifactId,
6666
if (artifactType != null) {
6767
metaData.setType(artifactType);
6868
} else {
69-
metaData.setType(dto.getType());
69+
metaData.setType(dto.getArtifactType());
7070
}
7171
metaData.setState(ArtifactState.ENABLED); // TODO artifact state has gone away from the storage layer
7272
metaData.setLabels(toV2Labels(dto.getLabels()));
@@ -152,7 +152,7 @@ public static ArtifactMetaData dtoToMetaData(String groupId, String artifactId,
152152
if (artifactType != null) {
153153
metaData.setType(artifactType);
154154
} else {
155-
metaData.setType(dto.getType());
155+
metaData.setType(dto.getArtifactType());
156156
}
157157
metaData.setVersion(dto.getVersion());
158158
metaData.setGlobalId(dto.getGlobalId());
@@ -265,7 +265,7 @@ public static ArtifactSearchResults dtoToSearchResults(ArtifactSearchResultsDto
265265
sa.setModifiedOn(artifact.getModifiedOn());
266266
sa.setName(artifact.getName());
267267
sa.setState(ArtifactState.ENABLED);
268-
sa.setType(artifact.getType());
268+
sa.setType(artifact.getArtifactType());
269269
results.getArtifacts().add(sa);
270270
});
271271
return results;
@@ -301,7 +301,7 @@ public static VersionSearchResults dtoToSearchResults(VersionSearchResultsDto dt
301301
sv.setContentId(version.getContentId());
302302
sv.setName(version.getName());
303303
sv.setState(ArtifactState.fromValue(version.getState().name()));
304-
sv.setType(version.getType());
304+
sv.setType(version.getArtifactType());
305305
sv.setVersion(version.getVersion());
306306
results.getVersions().add(sv);
307307
});

0 commit comments

Comments
 (0)