From 1370b8761813c00f39e4ddffeda04ccfda83d1e2 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 25 Jan 2017 09:24:23 +0530 Subject: [PATCH] fixed apim application issue --- ...ApiApplicationRegistrationServiceImpl.java | 1 - .../APIManagementProviderServiceImpl.java | 19 ++++++++++++--- .../publisher/APIPublisherServiceImpl.java | 24 ++++++++++++------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java index 268ec154ec..425c9a1141 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java @@ -60,7 +60,6 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi } String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() .getRealmConfiguration().getAdminUserName(); - username = username + "@" + APIUtil.getTenantDomainOftheUser(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index f319c29632..fdeccb2aca 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -99,14 +99,27 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe } if (apiList.getList() != null && apiList.getList().size() > 0) { - for (APIInfo apiInfo :apiList.getList()) { + for (APIInfo apiInfo : apiList.getList()) { Subscription subscription = new Subscription(); subscription.setApiIdentifier(apiInfo.getId()); subscription.setApplicationId(application.getApplicationId()); subscription.tier(ApiApplicationConstants.DEFAULT_TIER); - storeClient.getIndividualSubscription().subscriptionsPost(subscription, CONTENT_TYPE); + SubscriptionList subscriptionList = storeClient.getSubscriptions().subscriptionsGet + (apiInfo.getId(), application.getApplicationId(), "", 0, 100, CONTENT_TYPE, null); + boolean subscriptionExist = false; + if (subscriptionList.getList() != null && subscriptionList.getList().size() > 0) { + for (Subscription subs : subscriptionList.getList()) { + if (subs.getApiIdentifier().equals(apiInfo.getId()) && subs.getApplicationId().equals( + application.getApplicationId())) { + subscriptionExist = true; + break; + } + } + } + if (!subscriptionExist) { + storeClient.getIndividualSubscription().subscriptionsPost(subscription, CONTENT_TYPE); + } } - } } } 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 ee4801f545..9e21d731f0 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 @@ -53,7 +53,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { API api = getAPI(apiConfig); APIList apiList = publisherClient.getApi().apisGet(100, 0, "name:" + api.getName(), CONTENT_TYPE, null); - if (apiList == null || apiList.getList() == null || apiList.getList().size() == 0) { + if (!isExist(api, apiList)) { api = publisherClient.getApi().apisPost(api, CONTENT_TYPE); if (CREATED_STATUS.equals(api.getStatus())) { publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, null); @@ -61,9 +61,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { } else { if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) { for (APIInfo apiInfo : apiList.getList()) { - if (api.getVersion().equals(apiInfo.getVersion())) { - api = publisherClient.getApi().apisApiIdPut(apiInfo.getId(), api, CONTENT_TYPE, null, - null); + if (api.getName().equals(apiInfo.getName()) && api.getVersion().equals(apiInfo.getVersion())) { + api = publisherClient.getApi().apisApiIdPut(apiInfo.getId(), api, CONTENT_TYPE, null, null); if (CREATED_STATUS.equals(api.getStatus())) { publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, null); @@ -80,6 +79,18 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } + private boolean isExist(API api, APIList apiList) { + if (apiList == null || apiList.getList() == null || apiList.getList().size() == 0) { + return false; + } + for (APIInfo existingApi : apiList.getList()) { + if (existingApi.getName().equals(api.getName()) && existingApi.getVersion().equals(api.getVersion())) { + return true; + } + } + return false; + } + private API getAPI(APIConfig config) { API api = new API(); @@ -88,11 +99,6 @@ public class APIPublisherServiceImpl implements APIPublisherService { String context = config.getContext(); context = context.startsWith("/") ? context : ("/" + context); - String providerDomain = config.getTenantDomain(); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(providerDomain)) { - //Create tenant aware context for API - context = "/t/" + providerDomain + context; - } api.setContext(context); api.setVersion(config.getVersion()); api.setProvider(config.getOwner());