From 2002c920320d883ab9c499d0ccd049e2b154fac6 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Thu, 26 Mar 2015 19:40:00 +0530 Subject: [PATCH] adding existing API check before publishing --- .../mgt/core/util/DeviceManagerUtil.java | 24 ++++++++++--------- .../conf/user-api-publisher-config.xml | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 74c7d5d140..de1460075f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -172,17 +172,19 @@ public final class DeviceManagerUtil { APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion()); API api = new API(id); try { - api.setContext(config.getContext()); - api.setUrl(config.getEndpoint()); - api.setUriTemplates(getURITemplates(config.getEndpoint(), - APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN)); - api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY); - api.addAvailableTiers(provider.getTiers()); - api.setEndpointSecured(false); - api.setStatus(APIStatus.PUBLISHED); - api.setTransports(config.getTransports()); - - provider.addAPI(api); + if(!provider.isAPIAvailable(id)) { + api.setContext(config.getContext()); + api.setUrl(config.getEndpoint()); + api.setUriTemplates(getURITemplates(config.getEndpoint(), + APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN)); + api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY); + api.addAvailableTiers(provider.getTiers()); + api.setEndpointSecured(false); + api.setStatus(APIStatus.PUBLISHED); + api.setTransports(config.getTransports()); + + provider.addAPI(api); + } } catch (APIManagementException e) { throw new DeviceManagementException("Error occurred while registering the API", e); } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml index fc89db770c..8cc9771877 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml @@ -21,7 +21,7 @@ appmanager admin - devices + /devices 1.0.0 http://localhost:9763/ http,https