Skip to content

Commit

Permalink
Merge pull request #12192 from shnrndk/restorerevisionbug
Browse files Browse the repository at this point in the history
Api restore lifeCycleState state inconsistency fixed
  • Loading branch information
Arshardh authored Dec 4, 2023
2 parents 3c21850 + 055fe6f commit 9064f3d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ public void restoreAPIRevision(Organization org, String apiUUID, String revision
GenericArtifactManager artifactManager = RegistryPersistenceUtil.getArtifactManager(registry,
APIConstants.API_KEY);
GenericArtifact apiArtifact = artifactManager.getGenericArtifact(apiUUID);
String lcState = ((GenericArtifactImpl) apiArtifact).getLcState();
if (apiArtifact != null) {
String existingVersionComparable = apiArtifact.getAttribute(APIConstants
.API_OVERVIEW_VERSION_COMPARABLE);
Expand All @@ -359,15 +358,19 @@ public void restoreAPIRevision(Organization org, String apiUUID, String revision
visibleRoles = visibleRolesList.split(",");
}
String apiPath = GovernanceUtils.getArtifactPath(registry, apiUUID);
String lifecycleStatus = artifactManager.getGenericArtifact(apiUUID)
.getAttribute(APIConstants.API_OVERVIEW_STATUS);
int prependIndex = apiPath.lastIndexOf("/api");
String apiSourcePath = apiPath.substring(0, prependIndex);
String revisionTargetPath = RegistryPersistenceUtil.getRevisionPath(apiUUID, revisionId);
registry.delete(apiSourcePath);
registry.copy(revisionTargetPath, apiSourcePath);
Resource newAPIArtifact = registry.get(apiPath);
newAPIArtifact.setUUID(apiUUID);
newAPIArtifact.setProperty("registry.lifecycle.APILifeCycle.state", java.util.Arrays.asList((lcState)));
registry.put(apiPath, newAPIArtifact);
GenericArtifact artifact = getAPIArtifact(apiUUID, registry);
artifact.setAttribute(APIConstants.API_OVERVIEW_STATUS, lifecycleStatus);
artifactManager.updateGenericArtifact(apiArtifact);
RegistryPersistenceUtil.clearResourcePermissions(apiPath, api.getId(),
((UserRegistry) registry).getTenantId());
RegistryPersistenceUtil.setResourcePermissions(api.getId().getProviderName(), api.getVisibility(),
Expand Down

0 comments on commit 9064f3d

Please sign in to comment.