From 340cf2a00344bcb56c9d8b337c60ce12336ad75e Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 23 Mar 2015 18:19:11 +0530 Subject: [PATCH] Removing API registration logic from mobile plugin implementation --- .../pom.xml | 9 -- ...MobileDeviceManagementStartupObserver.java | 87 -------------- .../device/mgt/mobile/config/APIConfig.java | 101 ---------------- .../mgt/mobile/config/APIPublisherConfig.java | 41 ------- .../config/MobileDeviceManagementConfig.java | 10 -- ...MobileDeviceManagementBundleActivator.java | 49 -------- ...obileDeviceManagementServiceComponent.java | 34 ------ .../DeviceManagementAPIPublisherUtil.java | 112 ------------------ 8 files changed, 443 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/MobileDeviceManagementStartupObserver.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIConfig.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIPublisherConfig.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementAPIPublisherUtil.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index 1208edd03..d3d4069a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -66,7 +66,6 @@ org.wso2.carbon.core, org.wso2.carbon.utils.*, org.wso2.carbon.device.mgt.common.*, - org.wso2.carbon.apimgt.*; !org.wso2.carbon.device.mgt.mobile.internal, @@ -117,14 +116,6 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.api - - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.impl - org.testng testng diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/MobileDeviceManagementStartupObserver.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/MobileDeviceManagementStartupObserver.java deleted file mode 100644 index 8a306811b..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/MobileDeviceManagementStartupObserver.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.apimgt.api.APIProvider; -import org.wso2.carbon.apimgt.impl.APIManagerFactory; -import org.wso2.carbon.core.ServerStartupObserver; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.mobile.config.APIConfig; -import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; -import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; - -import java.util.List; - -public class MobileDeviceManagementStartupObserver implements ServerStartupObserver { - - private static final Log log = LogFactory.getLog(MobileDeviceManagementStartupObserver.class); - - public void completingServerStartup() { - - } - - public void completedServerStartup() { - try { - this.initAPIConfigs(); - /* Publish all mobile device management related JAX-RS services as APIs */ - this.publishAPIs(); - } catch (DeviceManagementException e) { - log.error("Error occurred while publishing Mobile Device Management related APIs", e); - } - } - - private void initAPIConfigs() throws DeviceManagementException { - if (log.isDebugEnabled()) { - log.debug("Initializing Mobile Device Management related APIs"); - } - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - try { - APIProvider provider = - APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); - apiConfig.init(provider); - } catch (APIManagementException e) { - throw new DeviceManagementException("Error occurred while initializing API Config '" + - apiConfig.getName() + "'", e); - } - } - } - - private void publishAPIs() throws DeviceManagementException { - if (log.isDebugEnabled()) { - log.debug("Publishing Mobile Device Management related APIs"); - } - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - DeviceManagementAPIPublisherUtil.publishAPI(apiConfig); - if (log.isDebugEnabled()) { - log.debug("Successfully published API '" + apiConfig.getName() + "' with the context '" + - apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'"); - } - } - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIConfig.java deleted file mode 100644 index 215a72f1f..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIConfig.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.config; - -import org.wso2.carbon.apimgt.api.APIProvider; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -@XmlRootElement(name = "API") -public class APIConfig { - - private String name; - private String owner; - private String context; - private String endpoint; - private String version; - private String transports; - private APIProvider provider; - - public void init(APIProvider provider) { - this.provider = provider; - } - - @XmlTransient - public APIProvider getProvider() { - return provider; - } - - @XmlElement(name = "Name", nillable = false) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @XmlElement(name = "Owner", nillable = false) - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - @XmlElement(name = "Context", nillable = false) - public String getContext() { - return context; - } - - public void setContext(String context) { - this.context = context; - } - - @XmlElement(name = "Endpoint", nillable = false) - public String getEndpoint() { - return endpoint; - } - - public void setEndpoint(String endpoint) { - this.endpoint = endpoint; - } - - @XmlElement(name = "Version", nillable = false) - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - @XmlElement(name = "Transports", nillable = false) - public String getTransports() { - return transports; - } - - public void setTransports(String transports) { - this.transports = transports; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIPublisherConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIPublisherConfig.java deleted file mode 100644 index 285730048..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/APIPublisherConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.config; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.List; - -@XmlRootElement(name = "APIPublisher") -public class APIPublisherConfig { - - private List apis; - - @XmlElementWrapper(name = "APIs", nillable = false, required = true) - @XmlElement(name = "API", nillable = false) - public List getAPIs() { - return apis; - } - - public void setAPIs(List apis) { - this.apis = apis; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementConfig.java index 9827532de..ced99f955 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementConfig.java @@ -28,7 +28,6 @@ import javax.xml.bind.annotation.XmlRootElement; public final class MobileDeviceManagementConfig { private MobileDeviceManagementRepository mobileDeviceMgtRepository; - private APIPublisherConfig apiPublisherConfig; @XmlElement(name = "ManagementRepository", nillable = false) public MobileDeviceManagementRepository getMobileDeviceMgtRepository() { @@ -40,13 +39,4 @@ public final class MobileDeviceManagementConfig { this.mobileDeviceMgtRepository = mobileDeviceMgtRepository; } - @XmlElement(name = "APIPublisher") - public APIPublisherConfig getApiPublisherConfig() { - return apiPublisherConfig; - } - - public void setApiPublisherConfig(APIPublisherConfig apiPublisherConfig) { - this.apiPublisherConfig = apiPublisherConfig; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java index 826ff2ccf..3fb0b8554 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java @@ -21,13 +21,8 @@ package org.wso2.carbon.device.mgt.mobile.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.*; -import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.apimgt.api.APIProvider; -import org.wso2.carbon.apimgt.impl.APIManagerFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.mobile.DataSourceListener; -import org.wso2.carbon.device.mgt.mobile.config.APIConfig; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; @@ -35,7 +30,6 @@ import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager; import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager; import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager; -import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; import java.util.ArrayList; import java.util.List; @@ -83,11 +77,6 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B bundleContext.registerService(DeviceManager.class.getName(), new WindowsDeviceManager(), null); - /* Initialize all API configurations with corresponding API Providers */ - this.initAPIConfigs(); - /* Publish all mobile device management related JAX-RS services as APIs */ - this.publishAPIs(); - if (log.isDebugEnabled()) { log.debug("Mobile Device Management Service bundle is activated"); } @@ -107,10 +96,6 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B windowsServiceRegRef.unregister(); bundleContext.removeBundleListener(this); - - /* Removing all APIs published upon start-up for mobile device management related JAX-RS - services */ - this.removeAPIs(); } catch (Throwable e) { log.error("Error occurred while de-activating Mobile Device Management bundle", e); } @@ -137,39 +122,5 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B return dataSourceListeners; } - private void initAPIConfigs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - try { - APIProvider provider = - APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); - apiConfig.init(provider); - } catch (APIManagementException e) { - throw new DeviceManagementException( - "Error occurred while initializing API Config '" + - apiConfig.getName() + "'", e); - } - } - } - - private void publishAPIs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - DeviceManagementAPIPublisherUtil.publishAPI(apiConfig); - } - } - - private void removeAPIs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - DeviceManagementAPIPublisherUtil.removeAPI(apiConfig); - } - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 6a3dd19fc..1dc22c977 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -23,12 +23,8 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; -import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; -import org.wso2.carbon.device.mgt.mobile.MobileDeviceManagementStartupObserver; -import org.wso2.carbon.device.mgt.mobile.config.APIConfig; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; @@ -37,19 +33,10 @@ import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager; import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager; import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager; -import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; - -import java.util.List; /** * @scr.component name="org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementServiceComponent" * immediate="true" - * @scr.reference name="api.manager.config.service" - * interface="org.wso2.carbon.apimgt.impl.APIManagerConfigurationService" - * cardinality="1..1" - * policy="dynamic" - * bind="setAPIManagerConfigurationService" - * unbind="unsetAPIManagerConfigurationService" *

* Adding reference to API Manager Configuration service is an unavoidable hack to get rid of NPEs thrown while * initializing APIMgtDAOs attempting to register APIs programmatically. APIMgtDAO needs to be proper cleaned up @@ -102,8 +89,6 @@ public class MobileDeviceManagementServiceComponent { windowsServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), new WindowsDeviceManager(), null); - serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class, - new MobileDeviceManagementStartupObserver(), null); if (log.isDebugEnabled()) { log.debug("Mobile Device Management Service Component has been successfully activated"); } @@ -122,9 +107,6 @@ public class MobileDeviceManagementServiceComponent { windowsServiceRegRef.unregister(); serverStartupObserverRef.unregister(); - /* Removing all APIs published upon start-up for mobile device management related JAX-RS - services */ - this.removeAPIs(); if (log.isDebugEnabled()) { log.debug( "Mobile Device Management Service Component has been successfully de-activated"); @@ -134,21 +116,5 @@ public class MobileDeviceManagementServiceComponent { } } - private void removeAPIs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - DeviceManagementAPIPublisherUtil.removeAPI(apiConfig); - } - } - - protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { - //do nothing - } - - protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) { - //do nothing - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementAPIPublisherUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementAPIPublisherUtil.java deleted file mode 100644 index eea7fa7fb..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementAPIPublisherUtil.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.util; - -import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.apimgt.api.APIProvider; -import org.wso2.carbon.apimgt.api.model.API; -import org.wso2.carbon.apimgt.api.model.APIIdentifier; -import org.wso2.carbon.apimgt.api.model.APIStatus; -import org.wso2.carbon.apimgt.api.model.URITemplate; -import org.wso2.carbon.apimgt.impl.APIConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.mobile.config.APIConfig; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -public class DeviceManagementAPIPublisherUtil { - - enum HTTPMethod { - GET, POST, DELETE, PUT, OPTIONS - } - - private static List httpMethods; - - static { - httpMethods = new ArrayList(); - httpMethods.add(HTTPMethod.GET); - httpMethods.add(HTTPMethod.POST); - httpMethods.add(HTTPMethod.DELETE); - httpMethods.add(HTTPMethod.PUT); - httpMethods.add(HTTPMethod.OPTIONS); - } - - public static void publishAPI(APIConfig config) throws DeviceManagementException { - APIProvider provider = config.getProvider(); - APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion()); - API api = new API(id); - try { - api.setContext(config.getContext()); - api.setUrl(config.getVersion()); - 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); - } - } - - public static void removeAPI(APIConfig config) throws DeviceManagementException { - try { - APIProvider provider = config.getProvider(); - APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion()); - provider.deleteAPI(id); - } catch (APIManagementException e) { - throw new DeviceManagementException("Error occurred while removing API", e); - } - } - - private static Set getURITemplates(String endpoint, String authType) { - Set uriTemplates = new LinkedHashSet(); - if (APIConstants.AUTH_NO_AUTHENTICATION.equals(authType)) { - for (HTTPMethod method : httpMethods) { - URITemplate template = new URITemplate(); - template.setAuthType(APIConstants.AUTH_NO_AUTHENTICATION); - template.setHTTPVerb(method.toString()); - template.setResourceURI(endpoint); - template.setUriTemplate("/*"); - uriTemplates.add(template); - } - } else { - for (HTTPMethod method : httpMethods) { - URITemplate template = new URITemplate(); - if (HTTPMethod.OPTIONS.equals(method)) { - template.setAuthType(APIConstants.AUTH_NO_AUTHENTICATION); - } else { - template.setAuthType(APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN); - } - template.setHTTPVerb(method.toString()); - template.setResourceURI(endpoint); - template.setUriTemplate("/*"); - uriTemplates.add(template); - } - } - return uriTemplates; - } - -}