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] Updated the branch API to be a bit more REST compatible #4763

Merged
merged 11 commits into from
Jun 14, 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 @@ -14,7 +14,7 @@
import io.apicurio.registry.rules.RuleViolationException;
import io.apicurio.registry.rules.RulesService;
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior;
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.ContentWrapperDto;
Expand Down Expand Up @@ -191,7 +191,7 @@ protected boolean isArtifactActive(String subject, String groupId) {

protected String getLatestArtifactVersionForSubject(String subject, String groupId) {
try {
GAV latestGAV = storage.getArtifactBranchTip(new GA(groupId, subject), BranchId.LATEST, ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST);
GAV latestGAV = storage.getBranchTip(new GA(groupId, subject), BranchId.LATEST, RetrievalBehavior.SKIP_DISABLED_LATEST);
return latestGAV.getRawVersionId();
} catch (ArtifactNotFoundException ex) {
throw new VersionNotFoundException(groupId, subject, "latest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ARTIFACT_ID;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_VERSION;
import static io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior.DEFAULT;
import static io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior.SKIP_DISABLED_LATEST;
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.DEFAULT;
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.SKIP_DISABLED_LATEST;

@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
@Logged
Expand All @@ -51,11 +51,16 @@ public class SubjectVersionsResourceImpl extends AbstractResource implements Sub
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public List<Integer> listVersions(String subject, String groupId, Boolean deleted) throws Exception {
final boolean fdeleted = deleted == null ? Boolean.FALSE : deleted;
List<Integer> rval;
if (fdeleted) {
return storage.getArtifactVersions(groupId, subject, DEFAULT).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
rval = storage.getArtifactVersions(groupId, subject, DEFAULT).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
} else {
return storage.getArtifactVersions(groupId, subject, SKIP_DISABLED_LATEST).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
rval = storage.getArtifactVersions(groupId, subject, SKIP_DISABLED_LATEST).stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted().collect(Collectors.toList());
}
if (rval.isEmpty()) {
throw new ArtifactNotFoundException(groupId, subject);
}
return rval;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import io.apicurio.registry.rest.v2.shared.CommonResourceOperations;
import io.apicurio.registry.rules.RuleApplicationType;
import io.apicurio.registry.rules.RulesService;
import io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior;
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactSearchResultsDto;
Expand Down Expand Up @@ -169,7 +169,7 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der
}

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

Expand Down Expand Up @@ -267,7 +267,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
requireParameter("artifactId", artifactId);

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

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

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

Expand Down
Loading
Loading