fixed apim application issue

revert-70aa11f8
ayyoob 8 years ago
parent 7348ae2f2a
commit 1370b87618

@ -60,7 +60,6 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
} }
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
.getRealmConfiguration().getAdminUserName(); .getRealmConfiguration().getAdminUserName();
username = username + "@" + APIUtil.getTenantDomainOftheUser();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(

@ -99,14 +99,27 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
} }
if (apiList.getList() != null && apiList.getList().size() > 0) { if (apiList.getList() != null && apiList.getList().size() > 0) {
for (APIInfo apiInfo :apiList.getList()) { for (APIInfo apiInfo : apiList.getList()) {
Subscription subscription = new Subscription(); Subscription subscription = new Subscription();
subscription.setApiIdentifier(apiInfo.getId()); subscription.setApiIdentifier(apiInfo.getId());
subscription.setApplicationId(application.getApplicationId()); subscription.setApplicationId(application.getApplicationId());
subscription.tier(ApiApplicationConstants.DEFAULT_TIER); 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);
}
} }
} }
} }
} }

@ -53,7 +53,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
API api = getAPI(apiConfig); API api = getAPI(apiConfig);
APIList apiList = publisherClient.getApi().apisGet(100, 0, "name:" + api.getName(), CONTENT_TYPE, null); 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); api = publisherClient.getApi().apisPost(api, CONTENT_TYPE);
if (CREATED_STATUS.equals(api.getStatus())) { if (CREATED_STATUS.equals(api.getStatus())) {
publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, null); publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, null);
@ -61,9 +61,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} else { } else {
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) { if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
for (APIInfo apiInfo : apiList.getList()) { for (APIInfo apiInfo : apiList.getList()) {
if (api.getVersion().equals(apiInfo.getVersion())) { if (api.getName().equals(apiInfo.getName()) && api.getVersion().equals(apiInfo.getVersion())) {
api = publisherClient.getApi().apisApiIdPut(apiInfo.getId(), api, CONTENT_TYPE, null, api = publisherClient.getApi().apisApiIdPut(apiInfo.getId(), api, CONTENT_TYPE, null, null);
null);
if (CREATED_STATUS.equals(api.getStatus())) { if (CREATED_STATUS.equals(api.getStatus())) {
publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, 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) { private API getAPI(APIConfig config) {
API api = new API(); API api = new API();
@ -88,11 +99,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
String context = config.getContext(); String context = config.getContext();
context = context.startsWith("/") ? context : ("/" + context); 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.setContext(context);
api.setVersion(config.getVersion()); api.setVersion(config.getVersion());
api.setProvider(config.getOwner()); api.setProvider(config.getOwner());

Loading…
Cancel
Save