Skip to content

Commit 82f59a5

Browse files
authored
[REST API] Updated the branch API to be a bit more REST compatible (#4763)
* Updated the branch API to be a bit more REST compatible * Fix issues with import/export for branches * Additional fix for branch import/export * Slight change to the replace-branch-versions operation to work with the go sdk * Change the return value of replace-branch-versions to be more consistent * Added a full export/import test. Made sure it works! * Fix broken integration tests. * Rename userDefined to systemDefined for branches * Tweak the canonical hash import test * Fix missing classes in the kafkasql message index * Improved error reporting in kafkasql value deserializer
1 parent e0dd2c8 commit 82f59a5

File tree

87 files changed

+4525
-6307
lines changed

Some content is hidden

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

87 files changed

+4525
-6307
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import io.apicurio.registry.rules.RuleViolationException;
1515
import io.apicurio.registry.rules.RulesService;
1616
import io.apicurio.registry.storage.RegistryStorage;
17-
import io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior;
17+
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
1818
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
1919
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
2020
import io.apicurio.registry.storage.dto.ContentWrapperDto;
@@ -191,7 +191,7 @@ protected boolean isArtifactActive(String subject, String groupId) {
191191

192192
protected String getLatestArtifactVersionForSubject(String subject, String groupId) {
193193
try {
194-
GAV latestGAV = storage.getArtifactBranchTip(new GA(groupId, subject), BranchId.LATEST, ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST);
194+
GAV latestGAV = storage.getBranchTip(new GA(groupId, subject), BranchId.LATEST, RetrievalBehavior.SKIP_DISABLED_LATEST);
195195
return latestGAV.getRawVersionId();
196196
} catch (ArtifactNotFoundException ex) {
197197
throw new VersionNotFoundException(groupId, subject, "latest");

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ARTIFACT_ID;
3939
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_VERSION;
40-
import static io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior.DEFAULT;
41-
import static io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST;
40+
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.DEFAULT;
41+
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.SKIP_DISABLED_LATEST;
4242

4343
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
4444
@Logged
@@ -51,11 +51,16 @@ public class SubjectVersionsResourceImpl extends AbstractResource implements Sub
5151
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
5252
public List<Integer> listVersions(String subject, String groupId, Boolean deleted) throws Exception {
5353
final boolean fdeleted = deleted == null ? Boolean.FALSE : deleted;
54+
List<Integer> rval;
5455
if (fdeleted) {
55-
return storage.getArtifactVersions(groupId, subject, DEFAULT).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
56+
rval = storage.getArtifactVersions(groupId, subject, DEFAULT).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
5657
} else {
57-
return storage.getArtifactVersions(groupId, subject, SKIP_DISABLED_LATEST).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
58+
rval = storage.getArtifactVersions(groupId, subject, SKIP_DISABLED_LATEST).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
5859
}
60+
if (rval.isEmpty()) {
61+
throw new ArtifactNotFoundException(groupId, subject);
62+
}
63+
return rval;
5964
}
6065

6166
@Override

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import io.apicurio.registry.rest.v2.shared.CommonResourceOperations;
4242
import io.apicurio.registry.rules.RuleApplicationType;
4343
import io.apicurio.registry.rules.RulesService;
44-
import io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior;
44+
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
4545
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
4646
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
4747
import io.apicurio.registry.storage.dto.ArtifactSearchResultsDto;
@@ -169,7 +169,7 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der
169169
}
170170

171171
try {
172-
GAV latestGAV = storage.getArtifactBranchTip(new GA(groupId, artifactId), BranchId.LATEST, ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST);
172+
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST, RetrievalBehavior.SKIP_DISABLED_LATEST);
173173
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
174174
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, latestGAV.getRawVersionId());
175175

@@ -267,7 +267,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
267267
requireParameter("artifactId", artifactId);
268268

269269
ArtifactMetaDataDto dto = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);
270-
GAV latestGAV = storage.getArtifactBranchTip(new GA(groupId, artifactId), BranchId.LATEST, ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST);
270+
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST, RetrievalBehavior.SKIP_DISABLED_LATEST);
271271
ArtifactVersionMetaDataDto vdto = storage.getArtifactVersionMetaData(latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
272272

273273
ArtifactMetaData amd = V2ApiUtil.dtoToMetaData(defaultGroupIdToNull(groupId), artifactId, dto.getArtifactType(), dto);
@@ -291,7 +291,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
291291
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_EDITABLE_METADATA})
292292
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
293293
public void updateArtifactMetaData(String groupId, String artifactId, EditableMetaData data) {
294-
GAV latestGAV = storage.getArtifactBranchTip(new GA(groupId, artifactId), BranchId.LATEST, ArtifactRetrievalBehavior.DEFAULT);
294+
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST, RetrievalBehavior.DEFAULT);
295295
storage.updateArtifactVersionMetaData(groupId, artifactId, latestGAV.getRawVersionId(), EditableVersionMetaDataDto.builder()
296296
.name(data.getName())
297297
.description(data.getDescription())
@@ -535,8 +535,8 @@ public void updateArtifactState(String groupId, String artifactId, UpdateState d
535535
requireParameter("body.state", data.getState());
536536

537537
// Possible race condition here. Worst case should be that the update fails with a reasonable message.
538-
GAV latestGAV = storage.getArtifactBranchTip(new GA(defaultGroupIdToNull(groupId), artifactId),
539-
BranchId.LATEST, ArtifactRetrievalBehavior.DEFAULT);
538+
GAV latestGAV = storage.getBranchTip(new GA(defaultGroupIdToNull(groupId), artifactId),
539+
BranchId.LATEST, RetrievalBehavior.DEFAULT);
540540
updateArtifactVersionState(groupId, artifactId, latestGAV.getRawVersionId(), data);
541541
}
542542

0 commit comments

Comments
 (0)