diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 99d187b2f48..34c9348e240 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -162,15 +162,30 @@ public class APIPublisherServiceImpl implements APIPublisherService { api.setStatus(existingAPI.getStatus()); apiProvider.updateAPI(api); + // Assumption: Assume the latest revision is the published one + String latestRevisionUUID = apiProvider.getLatestRevisionUUID(existingAPI.getUuid()); + List latestRevisionDeploymentList = + apiProvider.getAPIRevisionDeploymentList(latestRevisionUUID); + + List apiRevisionList = apiProvider.getAPIRevisions(existingAPI.getUuid()); + if (apiRevisionList.size() >= 5) { + String earliestRevisionUUID = apiProvider.getEarliestRevisionUUID(existingAPI.getUuid()); + List earliestRevisionDeploymentList = + apiProvider.getAPIRevisionDeploymentList(earliestRevisionUUID); + apiProvider.undeployAPIRevisionDeployment(existingAPI.getUuid(), earliestRevisionUUID, earliestRevisionDeploymentList); + apiProvider.deleteAPIRevision(existingAPI.getUuid(), earliestRevisionUUID, tenantDomain); + } + + // create new revision + APIRevision apiRevision = new APIRevision(); + apiRevision.setApiUUID(existingAPI.getUuid()); + apiRevision.setDescription("Updated Revision"); + String apiRevisionId = apiProvider.addAPIRevision(apiRevision, tenantDomain); + + apiProvider.deployAPIRevision(existingAPI.getUuid(), apiRevisionId, latestRevisionDeploymentList); + if (CREATED_STATUS.equals(existingAPI.getStatus())) { apiProvider.changeLifeCycleStatus(tenantDomain, existingAPI.getUuid(), PUBLISH_ACTION, null); - APIRevision apiRevision = new APIRevision(); - apiRevision.setApiUUID(existingAPI.getUuid()); - apiRevision.setDescription("Updated Revision"); - String apiRevisionId = apiProvider.addAPIRevision(apiRevision, tenantDomain); - - List apiRevisionDeploymentList = apiProvider.getAPIRevisionDeploymentList(apiRevisionId); - apiProvider.deployAPIRevision(existingAPI.getUuid(), apiRevisionId, apiRevisionDeploymentList); } } }