From 6c96d228ae381ee71695d57703acc50bec8e2a3d Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 9 Feb 2017 03:02:56 +0530 Subject: [PATCH] added subscription fix --- .../APIManagementProviderServiceImpl.java | 28 +++++++++++-------- .../store/api/SubscriptionindividualApi.java | 17 +++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) 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 af471ebd6e..50bcc5ad0f 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 @@ -87,6 +87,10 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe throw new APIManagerException ( "Api application creation failed for " + applicationName + " to the user " + username); } + + SubscriptionList subscriptionList = storeClient.getSubscriptions().subscriptionsGet + (null, application.getApplicationId(), "", 0, 100, CONTENT_TYPE, null); + List needToSubscribe = new ArrayList<>(); // subscribe to apis. if (tags != null && tags.length > 0) { for (String tag: tags) { @@ -100,32 +104,32 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe if (apiList.getList() != null && apiList.getList().size() > 0) { for (APIInfo apiInfo : apiList.getList()) { - Subscription subscription = new Subscription(); - //fix for APIMANAGER-5566 admin-AT-tenant1.com-Tenant1API1-1.0.0 - String id = apiInfo.getProvider().replace("@", "-AT-") - + "-" + apiInfo.getName()+ "-" + apiInfo.getVersion(); - subscription.setApiIdentifier(id); - subscription.setApplicationId(application.getApplicationId()); - subscription.tier(ApiApplicationConstants.DEFAULT_TIER); - SubscriptionList subscriptionList = storeClient.getSubscriptions().subscriptionsGet - (id, 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(id) && subs.getApplicationId().equals( - application.getApplicationId())) { + if (subs.getApiIdentifier().equals(apiInfo.getId())) { subscriptionExist = true; break; } } } if (!subscriptionExist) { - storeClient.getIndividualSubscription().subscriptionsPost(subscription, CONTENT_TYPE); + Subscription subscription = new Subscription(); + //fix for APIMANAGER-5566 admin-AT-tenant1.com-Tenant1API1-1.0.0 + String id = apiInfo.getProvider().replace("@", "-AT-") + + "-" + apiInfo.getName()+ "-" + apiInfo.getVersion(); + subscription.setApiIdentifier(id); + subscription.setApplicationId(application.getApplicationId()); + subscription.tier(ApiApplicationConstants.DEFAULT_TIER); + needToSubscribe.add(subscription); } } } } } + if (!needToSubscribe.isEmpty()) { + storeClient.getIndividualSubscription().subscriptionsPost(needToSubscribe, CONTENT_TYPE); + } //end of subscription List applicationKeys = application.getKeys(); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/store/api/SubscriptionindividualApi.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/store/api/SubscriptionindividualApi.java index adf57708a4..02e24ebe62 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/store/api/SubscriptionindividualApi.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/store/api/SubscriptionindividualApi.java @@ -22,6 +22,8 @@ import feign.Param; import feign.RequestLine; import org.wso2.carbon.apimgt.integration.client.store.model.Subscription; +import java.util.List; + @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2017-01-24T00:03:54.991+05:30") public interface SubscriptionindividualApi { @@ -42,6 +44,21 @@ public interface SubscriptionindividualApi { }) Subscription subscriptionsPost(Subscription body, @Param("contentType") String contentType); + /** + * Add new subscriptions + * Add new subscriptions + * @param body Subscription objects that should to be added (required) + * @param contentType Media type of the entity in the body. Default is JSON. (required) + * @return Subscription + */ + @RequestLine("POST /subscriptions/multiple") + @Headers({ + "Content-type: application/json", + "Accept: application/json", + "Content-Type: {contentType}" + }) + List subscriptionsPost(List body, @Param("contentType") String contentType); + /** * Remove subscription * Remove subscription