From 7e253156f6d25e9efe3694da1dca2d5f6d5829ae Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 18 Mar 2015 20:23:34 +0530 Subject: [PATCH 1/6] Code cleanup --- ...Service.java => AndroidDeviceManager.java} | 6 +- .../impl/android/AndroidFeatureManager.java | 78 +++++++++++++++++++ .../mobile/impl/android/dao/FeatureDAO.java | 36 +++++++++ .../dao/FeatureManagementDAOException.java | 22 ++++++ .../dao/FeatureManagementDAOFactory.java | 29 +++++++ .../impl/android/dao/impl/FeatureDAOImpl.java | 49 ++++++++++++ ...agerService.java => IOSDeviceManager.java} | 4 +- ...Service.java => WindowsDeviceManager.java} | 4 +- ...MobileDeviceManagementBundleActivator.java | 12 +-- ...obileDeviceManagementServiceComponent.java | 15 ++-- 10 files changed, 233 insertions(+), 22 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/{AndroidDeviceManagerService.java => AndroidDeviceManager.java} (98%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/{IOSDeviceManagerService.java => IOSDeviceManager.java} (98%) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/{WindowsDeviceManagerService.java => WindowsDeviceManager.java} (97%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index cffd4d882..77b652e10 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java @@ -33,9 +33,9 @@ import java.util.List; /** * This represents the Android implementation of DeviceManagerService. */ -public class AndroidDeviceManagerService implements DeviceManager { +public class AndroidDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(AndroidDeviceManagerService.class); + private static final Log log = LogFactory.getLog(AndroidDeviceManager.class); @Override public String getProviderType() { @@ -44,7 +44,7 @@ public class AndroidDeviceManagerService implements DeviceManager { @Override public FeatureManager getFeatureManager() { - return null; + return new AndroidFeatureManager(); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java new file mode 100644 index 000000000..be371bf34 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java @@ -0,0 +1,78 @@ +/* + * 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.impl.android; + +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.FeatureManagementException; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory; + +import java.util.List; + +public class AndroidFeatureManager implements FeatureManager { + + private FeatureDAO featureDAO; + + public AndroidFeatureManager() { + this.featureDAO = FeatureManagementDAOFactory.getFeatureDAO(); + } + + @Override + public boolean addFeature(Feature feature) throws DeviceManagementException { + try { + featureDAO.addFeature(feature); + return true; + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while adding the feature", e); + } + } + + @Override + public Feature getFeature(String name) throws DeviceManagementException { + try { + return featureDAO.getFeature(name); + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the feature", e); + } + } + + @Override + public List getFeatures() throws DeviceManagementException { + try { + return featureDAO.getFeatures(); + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the list of features registered " + + "for Android platform", e); + } + } + + @Override + public boolean removeFeature(String name) throws DeviceManagementException { + try { + featureDAO.removeFeature(name); + return true; + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while removing the feature", e); + } + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java new file mode 100644 index 000000000..17b347b1f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java @@ -0,0 +1,36 @@ +/* + * 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.impl.android.dao; + +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.FeatureManagementException; + +import java.util.List; + +public interface FeatureDAO { + + void addFeature(Feature feature) throws FeatureManagementDAOException; + + void removeFeature(String name) throws FeatureManagementDAOException; + + Feature getFeature(String name) throws FeatureManagementDAOException; + + List getFeatures() throws FeatureManagementDAOException; + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java new file mode 100644 index 000000000..24d02f939 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java @@ -0,0 +1,22 @@ +/* + * 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.impl.android.dao; + +public class FeatureManagementDAOException extends Exception { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java new file mode 100644 index 000000000..08c207d94 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java @@ -0,0 +1,29 @@ +/* + * 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.impl.android.dao; + +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.FeatureDAOImpl; + +public class FeatureManagementDAOFactory { + + public static FeatureDAO getFeatureDAO() { + return new FeatureDAOImpl(); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java new file mode 100644 index 000000000..d966b0304 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java @@ -0,0 +1,49 @@ +/* + * 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.impl.android.dao.impl; + +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; + +import java.util.List; + +public class FeatureDAOImpl implements FeatureDAO { + + @Override + public void addFeature(Feature feature) throws FeatureManagementDAOException { + + } + + @Override + public void removeFeature(String name) throws FeatureManagementDAOException { + + } + + @Override + public Feature getFeature(String name) throws FeatureManagementDAOException { + return null; + } + + @Override + public List getFeatures() throws FeatureManagementDAOException { + return null; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java index 29168335b..7f0b761f7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java @@ -32,9 +32,9 @@ import java.util.List; /** * This represents the iOS implementation of DeviceManagerService. */ -public class IOSDeviceManagerService implements DeviceManager { +public class IOSDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(IOSDeviceManagerService.class); + private static final Log log = LogFactory.getLog(IOSDeviceManager.class); @Override public String getProviderType() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 6fca61716..377695472 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -32,9 +32,9 @@ import java.util.List; /** * This represents the Windows implementation of DeviceManagerService. */ -public class WindowsDeviceManagerService implements DeviceManager { +public class WindowsDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(WindowsDeviceManagerService.class); + private static final Log log = LogFactory.getLog(WindowsDeviceManager.class); @Override public String getProviderType() { 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 8b851a83d..826ff2ccf 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 @@ -32,9 +32,9 @@ 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; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; +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; @@ -75,13 +75,13 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B androidServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), - new AndroidDeviceManagerService(), null); + new AndroidDeviceManager(), null); iOSServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), - new IOSDeviceManagerService(), null); + new IOSDeviceManager(), null); windowsServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), - new WindowsDeviceManagerService(), null); + new WindowsDeviceManager(), null); /* Initialize all API configurations with corresponding API Providers */ this.initAPIConfigs(); 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 f68765bfa..6a3dd19fc 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 @@ -34,9 +34,9 @@ import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; +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; @@ -96,14 +96,11 @@ public class MobileDeviceManagementServiceComponent { } androidServiceRegRef = - bundleContext.registerService(DeviceManager.class.getName(), - new AndroidDeviceManagerService(), null); + bundleContext.registerService(DeviceManager.class.getName(), new AndroidDeviceManager(), null); iOSServiceRegRef = - bundleContext.registerService(DeviceManager.class.getName(), - new IOSDeviceManagerService(), null); + bundleContext.registerService(DeviceManager.class.getName(), new IOSDeviceManager(), null); windowsServiceRegRef = - bundleContext.registerService(DeviceManager.class.getName(), - new WindowsDeviceManagerService(), null); + bundleContext.registerService(DeviceManager.class.getName(), new WindowsDeviceManager(), null); serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class, new MobileDeviceManagementStartupObserver(), null); From 3e6ddbfb04095a072f8639b67028a1e27ebbfdd2 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 18 Mar 2015 21:40:44 +0530 Subject: [PATCH 2/6] Fixing build failures --- .../mobile/impl/android/AndroidMobileOperationManager.java | 1 - .../mgt/mobile/impl/ios/IOSMobileOperationManager.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java index 683bf7868..4981295ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java @@ -144,7 +144,6 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage return operations; } - @Override public List getFeatures(String deviceType) throws FeatureManagementException { MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO(); MobileFeaturePropertyDAO featurePropertyDAO = diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java index cbc7411be..38280e2a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java @@ -118,9 +118,4 @@ public class IOSMobileOperationManager extends AbstractMobileOperationManager { return operations; } - @Override - public List getFeatures(String type) throws FeatureManagementException { - return null; - } - } From c09e16021ea2bdba051c9cbdc4c5af8082136515 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 20 Mar 2015 18:06:37 +0530 Subject: [PATCH 3/6] Adding feature management features --- .../src/main/resources/sql/h2.sql | 0 .../src/test/resources/sql/CreateH2TestDB.sql | 88 ------------------- .../src/test/resources/sql/h2.sql | 0 3 files changed, 88 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql new file mode 100644 index 000000000..e69de29bb diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql deleted file mode 100644 index a33e6d477..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql +++ /dev/null @@ -1,88 +0,0 @@ - --- ----------------------------------------------------- --- Table `MBL_DEVICE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , - `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL , - `IMEI` VARCHAR(45) NULL DEFAULT NULL , - `IMSI` VARCHAR(45) NULL DEFAULT NULL , - `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , - `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , - `VENDOR` VARCHAR(45) NULL DEFAULT NULL , - `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, - `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, - `CHALLENGE` VARCHAR(45) NULL DEFAULT NULL, - `TOKEN` VARCHAR(500) NULL DEFAULT NULL, - `UNLOCK_TOKEN` VARCHAR(500) NULL DEFAULT NULL, - `SERIAL` VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`) ); - - --- ----------------------------------------------------- --- Table `MBL_FEATURE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , - `CODE` VARCHAR(45) NOT NULL, - `NAME` VARCHAR(100) NULL , - `DESCRIPTION` VARCHAR(200) NULL , - `DEVICE_TYPE` VARCHAR(50) NULL , - PRIMARY KEY (`FEATURE_ID`) ); - --- ----------------------------------------------------- --- Table `MBL_OPERATION` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( - `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , - `FEATURE_CODE` VARCHAR(45) NOT NULL , - `CREATED_DATE` BIGINT NULL , - PRIMARY KEY (`OPERATION_ID`)); - --- ----------------------------------------------------- --- Table `MBL_DEVICE_OPERATION_MAPPING` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( - `DEVICE_ID` VARCHAR(45) NOT NULL , - `OPERATION_ID` INT NOT NULL , - `SENT_DATE` BIGINT NULL , - `RECEIVED_DATE` BIGINT NULL , - `STATUS` VARCHAR(10) NOT NULL , - PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , - CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` - FOREIGN KEY (`DEVICE_ID` ) - REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); - --- ----------------------------------------------------- --- Table `MBL_OPERATION_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( - `OPERATION_ID` INT NOT NULL , - `PROPERTY` VARCHAR(45) NOT NULL , - `VALUE` TEXT NULL , - PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , - CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); - --- ----------------------------------------------------- --- Table `MBL_FEATURE_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( - `PROPERTY` VARCHAR(45) NOT NULL , - `FEATURE_ID` INT NOT NULL , - PRIMARY KEY (`PROPERTY`) , - CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` - FOREIGN KEY (`FEATURE_ID` ) - REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql new file mode 100644 index 000000000..e69de29bb From 83fbfc98be512ff07ad6735e7b890c0f0c518c86 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 20 Mar 2015 18:16:21 +0530 Subject: [PATCH 4/6] Introducing API changes to Android, iOS and Windows plugin implementations --- .../AbstractMobileOperationManager.java | 6 +- .../mobile/dao/impl/MobileDeviceDAOImpl.java | 10 +- .../MobileDeviceOperationMappingDAOImpl.java | 20 ++-- .../mobile/dao/impl/MobileFeatureDAOImpl.java | 18 ++-- .../impl/MobileFeaturePropertyDAOImpl.java | 12 +-- .../dao/impl/MobileOperationDAOImpl.java | 8 +- .../impl/MobileOperationPropertyDAOImpl.java | 10 +- .../util/MobileDeviceManagementDAOUtil.java | 4 + .../impl/android/AndroidFeatureManager.java | 20 +++- .../AndroidMobileOperationManager.java | 5 + .../mobile/impl/android/dao/FeatureDAO.java | 1 - .../dao/FeatureManagementDAOException.java | 55 +++++++++++ .../dao/FeatureManagementDAOFactory.java | 64 ++++++++++++ .../impl/android/dao/impl/FeatureDAOImpl.java | 91 +++++++++++++++-- .../impl/ios/IOSMobileOperationManager.java | 7 +- .../src/main/resources/sql/h2.sql | 98 +++++++++++++++++++ .../impl/dao/MobileDeviceDAOTestSuite.java | 13 ++- ...ileDeviceOperationMappingDAOTestSuite.java | 10 +- .../impl/dao/MobileFeatureDAOTestSuite.java | 8 +- .../MobileFeaturePropertyDAOTestSuite.java | 6 +- .../impl/dao/MobileOperationDAOTestSuite.java | 6 +- .../MobileOperationPropertyDAOTestSuite.java | 6 +- .../impl/dao/util/MobileDatabaseUtils.java | 2 +- .../src/test/resources/sql/h2.sql | 88 +++++++++++++++++ test.out | 47 +++++++++ 25 files changed, 536 insertions(+), 79 deletions(-) create mode 100644 test.out diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java index 719a38b1a..5a63eef8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java @@ -28,15 +28,13 @@ import java.util.List; public abstract class AbstractMobileOperationManager implements OperationManager { @Override - public List getOperations(DeviceIdentifier deviceIdentifier) - throws OperationManagementException { + public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { return null; } @Override public boolean addOperation(Operation operation, - List devices) - throws OperationManagementException { + List devices) throws OperationManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java index a74e4b383..b06ec3265 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java @@ -54,7 +54,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { conn = this.getConnection(); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " + - "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM MBL_DEVICE" + + "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE" + " WHERE MOBILE_DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); @@ -98,7 +98,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_DEVICE(MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION," + + "INSERT INTO AD_DEVICE(MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION," + "DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, " + "UNLOCK_TOKEN) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -144,7 +144,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_DEVICE SET PUSH_TOKEN = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," + + "UPDATE AD_DEVICE SET PUSH_TOKEN = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," + "DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ?, CHALLENGE = ?," + "SERIAL = ?, TOKEN = ?, UNLOCK_TOKEN = ? WHERE MOBILE_DEVICE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); @@ -188,7 +188,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?"; + "DELETE FROM AD_DEVICE WHERE MOBILE_DEVICE_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, mblDeviceId); int rows = stmt.executeUpdate(); @@ -219,7 +219,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { conn = this.getConnection(); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR," + - "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM MBL_DEVICE"; + "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE"; stmt = conn.prepareStatement(selectDBQuery); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java index 9738f1f60..9058df9ae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java @@ -55,7 +55,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, " + + "INSERT INTO AD_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, " + "RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); @@ -77,7 +77,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio String msg = "Error occurred while adding device id - '" + mblDeviceOperationMapping.getDeviceId() + " and operation id - " + mblDeviceOperationMapping.getOperationId() + - " to mapping table MBL_DEVICE_OPERATION"; + " to mapping table AD_DEVICE_OPERATION"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -95,7 +95,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " + + "UPDATE AD_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " + "STATUS = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setLong(1, mblDeviceOperation.getSentDate()); @@ -132,7 +132,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, STATUS = ? " + + "UPDATE AD_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, STATUS = ? " + "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setLong(1, new Date().getTime()); @@ -170,7 +170,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " + + "UPDATE AD_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " + "WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setLong(1, new Date().getTime()); @@ -207,7 +207,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " + + "DELETE FROM AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " + "OPERATION_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, mblDeviceId); @@ -222,7 +222,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } } catch (SQLException e) { String msg = - "Error occurred while deleting the table entry MBL_DEVICE_OPERATION with " + + "Error occurred while deleting the table entry AD_DEVICE_OPERATION with " + " device id - '" + mblDeviceId + " and operation id - " + operationId; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -243,7 +243,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio conn = this.getConnection(); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); stmt.setInt(2, operationId); @@ -285,7 +285,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio conn = this.getConnection(); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); ResultSet resultSet = stmt.executeQuery(); @@ -327,7 +327,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio conn = this.getConnection(); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" + - " MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?"; + " AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); stmt.setString(2, MobileDeviceOperationMapping.Status.NEW.name()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 66081becd..a19c61e5f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -54,7 +54,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION, DEVICE_TYPE) VALUES (?, ?, ?, ?)"; + "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION, DEVICE_TYPE) VALUES (?, ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, mobileFeature.getCode()); @@ -67,7 +67,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { if (rs != null && rs.next()) { status = rs.getInt(1); } - if (log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Added a new MobileFeature " + mobileFeature.getCode() + " to the" + " MDM database."); } @@ -92,7 +92,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ?" + + "UPDATE AD_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ?" + " WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mobileFeature.getCode()); @@ -127,7 +127,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_FEATURE WHERE CODE = ?"; + "DELETE FROM AD_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, mblFeatureCode); int rows = stmt.executeUpdate(); @@ -157,7 +157,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_FEATURE WHERE FEATURE_ID = ?"; + "DELETE FROM AD_FEATURE WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setInt(1, mblFeatureId); int rows = stmt.executeUpdate(); @@ -187,7 +187,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE " + + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE " + "WHERE CODE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblFeatureCode); @@ -224,7 +224,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" + + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE" + " WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, mblFeatureId); @@ -261,7 +261,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE"; + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE"; stmt = conn.prepareStatement(selectDBQuery); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { @@ -296,7 +296,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" + + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE" + " WHERE DEVICE_TYPE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceType); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java index d768dbd44..e3edfc324 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java @@ -54,7 +54,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; + "INSERT INTO AD_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, mblFeatureProperty.getProperty()); @@ -87,7 +87,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; + "UPDATE AD_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setInt(1, mblFeatureProperty.getFeatureID()); stmt.setString(2, mblFeatureProperty.getProperty()); @@ -118,7 +118,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?"; + "DELETE FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, property); int rows = stmt.executeUpdate(); @@ -148,7 +148,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; + "DELETE FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setInt(1, mblFeatureId); int rows = stmt.executeUpdate(); @@ -179,7 +179,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?"; + "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, property); ResultSet resultSet = stmt.executeQuery(); @@ -213,7 +213,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; + "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, mblFeatureId); ResultSet resultSet = stmt.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java index bd7e8b3c3..9d5694a3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java @@ -53,7 +53,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; + "INSERT INTO AD_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; stmt = conn.prepareStatement(createDBQuery, new String[] { COLUMN_OPERATION_ID }); stmt.setString(1, mblOperation.getFeatureCode()); stmt.setLong(2, mblOperation.getCreatedDate()); @@ -88,7 +88,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " + + "UPDATE AD_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " + "OPERATION_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mblOperation.getFeatureCode()); @@ -123,7 +123,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_OPERATION WHERE OPERATION_ID = ?"; + "DELETE FROM AD_OPERATION WHERE OPERATION_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setInt(1, mblOperationId); int rows = stmt.executeUpdate(); @@ -153,7 +153,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE " + + "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE " + "OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, mblOperationId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java index c4553862f..0542e6347 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java @@ -54,7 +54,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " + + "INSERT INTO AD_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " + "VALUES ( ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setInt(1, mblOperationProperty.getOperationId()); @@ -90,7 +90,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String createDBQuery = - "UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " + + "UPDATE AD_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " + "PROPERTY = ?"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, mblOperationProperty.getValue()); @@ -125,7 +125,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; + "DELETE FROM AD_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setInt(1, mblOperationId); int rows = stmt.executeUpdate(); @@ -158,7 +158,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " + + "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE " + "OPERATION_ID = ? AND PROPERTY = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, mblOperationId); @@ -197,7 +197,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " + + "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE " + "OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, mblOperationId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java index 8091ae186..6209ab6d2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java @@ -78,6 +78,10 @@ public class MobileDeviceManagementDAOUtil { } } + public static void cleanupResources(PreparedStatement stmt, ResultSet rs) { + cleanupResources(null, stmt, rs); + } + /** * Creates the mobile device management schema. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java index be371bf34..3a1d22550 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java @@ -18,6 +18,8 @@ */ package org.wso2.carbon.device.mgt.mobile.impl.android; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManagementException; @@ -31,6 +33,7 @@ import java.util.List; public class AndroidFeatureManager implements FeatureManager { private FeatureDAO featureDAO; + private static final Log log = LogFactory.getLog(AndroidFeatureManager.class); public AndroidFeatureManager() { this.featureDAO = FeatureManagementDAOFactory.getFeatureDAO(); @@ -39,9 +42,16 @@ public class AndroidFeatureManager implements FeatureManager { @Override public boolean addFeature(Feature feature) throws DeviceManagementException { try { + FeatureManagementDAOFactory.beginTransaction(); featureDAO.addFeature(feature); + FeatureManagementDAOFactory.commitTransaction(); return true; } catch (FeatureManagementDAOException e) { + try { + FeatureManagementDAOFactory.rollbackTransaction(); + } catch (FeatureManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } throw new DeviceManagementException("Error occurred while adding the feature", e); } } @@ -49,8 +59,16 @@ public class AndroidFeatureManager implements FeatureManager { @Override public Feature getFeature(String name) throws DeviceManagementException { try { - return featureDAO.getFeature(name); + FeatureManagementDAOFactory.beginTransaction(); + Feature feature = featureDAO.getFeature(name); + FeatureManagementDAOFactory.commitTransaction(); + return feature; } catch (FeatureManagementDAOException e) { + try { + FeatureManagementDAOFactory.rollbackTransaction(); + } catch (FeatureManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } throw new DeviceManagementException("Error occurred while retrieving the feature", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java index 4981295ad..6dc07b6ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java @@ -144,6 +144,11 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage return operations; } + @Override + public Operation getPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { + return null; + } + public List getFeatures(String deviceType) throws FeatureManagementException { MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO(); MobileFeaturePropertyDAO featurePropertyDAO = diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java index 17b347b1f..1aa3289c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao; import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManagementException; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java index 24d02f939..607240350 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java @@ -19,4 +19,59 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao; public class FeatureManagementDAOException extends Exception { + + private String message; + private static final long serialVersionUID = 2021891706072918865L; + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified detail message and + * nested exception. + * + * @param message error message + * @param nestedException exception + */ + public FeatureManagementDAOException(String message, Exception nestedException) { + super(message, nestedException); + setErrorMessage(message); + } + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified detail message + * and cause. + * + * @param message the detail message. + * @param cause the cause of this exception. + */ + public FeatureManagementDAOException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified detail message. + * + * @param message the detail message. + */ + public FeatureManagementDAOException(String message) { + super(message); + setErrorMessage(message); + } + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified and cause. + * + * @param cause the cause of this exception. + */ + public FeatureManagementDAOException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + + public void setErrorMessage(String errorMessage) { + this.message = errorMessage; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java index 08c207d94..a4f4db082 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java @@ -18,12 +18,76 @@ */ package org.wso2.carbon.device.mgt.mobile.impl.android.dao; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.FeatureDAOImpl; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + public class FeatureManagementDAOFactory { + private static DataSource dataSource; + private static ThreadLocal currentConnection = new ThreadLocal(); + private static final Log log = LogFactory.getLog(FeatureManagementDAOFactory.class); + public static FeatureDAO getFeatureDAO() { return new FeatureDAOImpl(); } + public static void init(DataSource dtSource) { + dataSource = dtSource; + } + + public static void beginTransaction() throws FeatureManagementDAOException { + try { + Connection conn = dataSource.getConnection(); + conn.setAutoCommit(false); + currentConnection.set(conn); + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while retrieving datasource connection", e); + } + } + + public static Connection getConnection() { + return currentConnection.get(); + } + + public static void commitTransaction() throws FeatureManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.commit(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence commit " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while committing the transaction", e); + } + } + + public static void rollbackTransaction() throws FeatureManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.rollback(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence rollback " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while rollbacking the transaction", e); + } + } + + public static DataSource getDataSource() { + return dataSource; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java index d966b0304..0641350cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java @@ -19,31 +19,110 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl; import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class FeatureDAOImpl implements FeatureDAO { @Override public void addFeature(Feature feature) throws FeatureManagementDAOException { - + PreparedStatement stmt = null; + try { + Connection conn = FeatureManagementDAOFactory.getConnection(); + String sql = "INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, feature.getCode()); + stmt.setString(2, feature.getName()); + stmt.setString(3, feature.getDescription()); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while adding feature '" + + feature.getName() + "' into the metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } } @Override - public void removeFeature(String name) throws FeatureManagementDAOException { - + public void removeFeature(String code) throws FeatureManagementDAOException { + PreparedStatement stmt = null; + try { + Connection conn = FeatureManagementDAOFactory.getConnection(); + String sql = "DELETE FROM MBL_FEATURE WHERE CODE = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, code); + stmt.execute(); + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while adding feature '" + + code + "' into the metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } } @Override - public Feature getFeature(String name) throws FeatureManagementDAOException { - return null; + public Feature getFeature(String code) throws FeatureManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = FeatureManagementDAOFactory.getConnection(); + String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, code); + rs = stmt.executeQuery(); + + Feature feature = null; + if (rs.next()) { + feature = new Feature(); + feature.setId(rs.getInt("ID")); + feature.setCode(rs.getString("CODE")); + feature.setName(rs.getString("NAME")); + feature.setDescription(rs.getString("DESCRIPTION")); + } + return feature; + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while retrieving feature metadata '" + + code + "' from the feature metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + } } @Override public List getFeatures() throws FeatureManagementDAOException { - return null; + PreparedStatement stmt = null; + ResultSet rs = null; + List features = new ArrayList(); + try { + Connection conn = FeatureManagementDAOFactory.getConnection(); + String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE"; + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + + while (rs.next()) { + Feature feature = new Feature(); + feature.setId(rs.getInt("ID")); + feature.setCode(rs.getString("CODE")); + feature.setName(rs.getString("NAME")); + feature.setDescription(rs.getString("DESCRIPTION")); + } + return features; + } catch (SQLException e) { + throw new FeatureManagementDAOException("Error occurred while retrieving all feature metadata from the " + + "feature metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java index 38280e2a7..08f42568f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java @@ -20,8 +20,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.ios; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager; @@ -118,4 +116,9 @@ public class IOSMobileOperationManager extends AbstractMobileOperationManager { return operations; } + @Override + public Operation getPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { + return null; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql index e69de29bb..dbcc64dac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/resources/sql/h2.sql @@ -0,0 +1,98 @@ +-- ----------------------------------------------------- +-- Table AD_DEVICE +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS AD_FEATURE( + ID INTEGER NOT NULL, + CODE VARCHAR(50) NOT NULL, + NAME VARCHAR(100) NOT NULL, + DESCRIPTION VARCHAR(200) NOT NULL, +) + +-- ----------------------------------------------------- +-- Table AD_DEVICE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_DEVICE ( + MOBILE_DEVICE_ID VARCHAR(45) NOT NULL , + PUSH_TOKEN VARCHAR(45) NULL DEFAULT NULL , + IMEI VARCHAR(45) NULL DEFAULT NULL , + IMSI VARCHAR(45) NULL DEFAULT NULL , + OS_VERSION VARCHAR(45) NULL DEFAULT NULL , + DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL , + VENDOR VARCHAR(45) NULL DEFAULT NULL , + LATITUDE VARCHAR(45) NULL DEFAULT NULL, + LONGITUDE VARCHAR(45) NULL DEFAULT NULL, + CHALLENGE VARCHAR(45) NULL DEFAULT NULL, + TOKEN VARCHAR(500) NULL DEFAULT NULL, + UNLOCK_TOKEN VARCHAR(500) NULL DEFAULT NULL, + SERIAL VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (MOBILE_DEVICE_ID) ); + + +-- ----------------------------------------------------- +-- Table AD_FEATURE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_FEATURE ( + FEATURE_ID INT NOT NULL AUTO_INCREMENT , + CODE VARCHAR(45) NOT NULL, + NAME VARCHAR(100) NULL , + DESCRIPTION VARCHAR(200) NULL , + DEVICE_TYPE VARCHAR(50) NULL , + PRIMARY KEY (FEATURE_ID) ); + +-- ----------------------------------------------------- +-- Table AD_OPERATION +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_OPERATION ( + OPERATION_ID INT NOT NULL AUTO_INCREMENT , + FEATURE_CODE VARCHAR(45) NOT NULL , + CREATED_DATE BIGINT NULL , + PRIMARY KEY (OPERATION_ID)); + +-- ----------------------------------------------------- +-- Table AD_DEVICE_OPERATION_MAPPING +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_DEVICE_OPERATION_MAPPING ( + DEVICE_ID VARCHAR(45) NOT NULL , + OPERATION_ID INT NOT NULL , + SENT_DATE BIGINT NULL , + RECEIVED_DATE BIGINT NULL , + STATUS VARCHAR(10) NOT NULL , + PRIMARY KEY (DEVICE_ID, OPERATION_ID) , + CONSTRAINT fk_AD_DEVICE_OPERATION_AD_DEVICE + FOREIGN KEY (DEVICE_ID ) + REFERENCES AD_DEVICE (MOBILE_DEVICE_ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT fk_AD_DEVICE_OPERATION_AD_OPERATION1 + FOREIGN KEY (OPERATION_ID ) + REFERENCES AD_OPERATION (OPERATION_ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table AD_OPERATION_PROPERTY +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_OPERATION_PROPERTY ( + OPERATION_ID INT NOT NULL , + PROPERTY VARCHAR(45) NOT NULL , + VALUE TEXT NULL , + PRIMARY KEY (OPERATION_ID, PROPERTY) , + CONSTRAINT fk_AD_OPERATION_PROPERTY_AD_OPERATION1 + FOREIGN KEY (OPERATION_ID ) + REFERENCES AD_OPERATION (OPERATION_ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table AD_FEATURE_PROPERTY +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_FEATURE_PROPERTY ( + PROPERTY VARCHAR(45) NOT NULL , + FEATURE_ID INT NOT NULL , + PRIMARY KEY (PROPERTY) , + CONSTRAINT fk_AD_FEATURE_PROPERTY_AD_FEATURE1 + FOREIGN KEY (FEATURE_ID ) + REFERENCES AD_FEATURE (FEATURE_ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java index f148d4794..ccafbc769 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java @@ -85,8 +85,7 @@ public class MobileDeviceDAOTestSuite { } @Test - public void addMobileDeviceTest() - throws MobileDeviceManagementDAOException { + public void addMobileDeviceTest() throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement preparedStatement = null; @@ -111,7 +110,7 @@ public class MobileDeviceDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " + - "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM MBL_DEVICE " + + "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE " + "WHERE MOBILE_DEVICE_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); @@ -209,8 +208,7 @@ public class MobileDeviceDAOTestSuite { @Test(dependsOnMethods = { "addMobileDeviceTest", "getMobileDeviceTest", "getAllMobileDevicesTest" }) - public void updateMobileDeviceTest() - throws MobileDeviceManagementDAOException { + public void updateMobileDeviceTest() throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement preparedStatement = null; @@ -235,7 +233,7 @@ public class MobileDeviceDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " + - "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM MBL_DEVICE " + + "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE " + "WHERE MOBILE_DEVICE_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); @@ -279,7 +277,7 @@ public class MobileDeviceDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " + - "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM MBL_DEVICE " + + "LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE " + "WHERE MOBILE_DEVICE_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); @@ -296,4 +294,5 @@ public class MobileDeviceDAOTestSuite { } Assert.assertTrue(deleted, "MobileDevice has deleted "); } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java index 6c39be232..ea679f060 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java @@ -155,7 +155,7 @@ public class MobileDeviceOperationMappingDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); ResultSet resultSet = preparedStatement.executeQuery(); @@ -252,7 +252,7 @@ public class MobileDeviceOperationMappingDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); preparedStatement.setInt(2, mblOperationId1); @@ -296,7 +296,7 @@ public class MobileDeviceOperationMappingDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); preparedStatement.setInt(2, mblOperationId1); @@ -348,7 +348,7 @@ public class MobileDeviceOperationMappingDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); preparedStatement.setInt(2, mblOperationId1); @@ -422,7 +422,7 @@ public class MobileDeviceOperationMappingDAOTestSuite { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; + "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); preparedStatement.setInt(2, mblOperationId1); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java index 5d1d57672..ef0b40efd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java @@ -91,7 +91,7 @@ public class MobileFeatureDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE CODE = ?"; + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE WHERE CODE = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, MBL_FEATURE_CODE); ResultSet resultSet = preparedStatement.executeQuery(); @@ -174,7 +174,7 @@ public class MobileFeatureDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = ?"; + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(query); stmt.setString(1, MBL_FEATURE_UPDATED_CODE); ResultSet resultSet = stmt.executeQuery(); @@ -207,7 +207,7 @@ public class MobileFeatureDAOTestSuite { boolean status = mblFeatureDAO.deleteMobileFeatureById(mblFeatureId); try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = "SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE FEATURE_ID = ?"; + String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, mblFeatureId); ResultSet resultSet = stmt.executeQuery(); @@ -240,7 +240,7 @@ public class MobileFeatureDAOTestSuite { boolean status = mblFeatureDAO.deleteMobileFeatureByCode(MBL_FEATURE_CODE); try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = "SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE CODE = ?"; + String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE CODE = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, MBL_FEATURE_CODE); ResultSet resultSet = preparedStatement.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java index 95af28f41..bf5d44ed4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java @@ -107,7 +107,7 @@ public class MobileFeaturePropertyDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT FEATURE_ID, PROPERTY FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; + "SELECT FEATURE_ID, PROPERTY FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, mblFeatureId); ResultSet resultSet = preparedStatement.executeQuery(); @@ -187,7 +187,7 @@ public class MobileFeaturePropertyDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?"; + "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, MBL_FEATURE_PROP_2); ResultSet resultSet = preparedStatement.executeQuery(); @@ -217,7 +217,7 @@ public class MobileFeaturePropertyDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; + "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, mblFeatureId); ResultSet resultSet = preparedStatement.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java index d6b03e07e..3b05d09b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java @@ -83,7 +83,7 @@ public class MobileOperationDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?"; + "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setInt(1, mblOperationId); ResultSet resultSet = preparedStatement.executeQuery(); @@ -133,7 +133,7 @@ public class MobileOperationDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?"; + "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setInt(1, mblOperationId); ResultSet resultSet = preparedStatement.executeQuery(); @@ -167,7 +167,7 @@ public class MobileOperationDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?"; + "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setInt(1, mblOperationId); ResultSet resultSet = preparedStatement.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java index 161a6e4e6..1342d6104 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java @@ -111,7 +111,7 @@ public class MobileOperationPropertyDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; + "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setInt(1, mblOperationId); ResultSet resultSet = preparedStatement.executeQuery(); @@ -181,7 +181,7 @@ public class MobileOperationPropertyDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE" + + "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE" + " OPERATION_ID = ? AND PROPERTY = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setInt(1, mblOperationId); @@ -217,7 +217,7 @@ public class MobileOperationPropertyDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE" + + "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE" + " OPERATION_ID = ?"; preparedStatement = conn.prepareStatement(selectDBQuery); preparedStatement.setInt(1, mblOperationId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/util/MobileDatabaseUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/util/MobileDatabaseUtils.java index cd4f45a24..f454f6f06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/util/MobileDatabaseUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/util/MobileDatabaseUtils.java @@ -103,7 +103,7 @@ public class MobileDatabaseUtils { Class.forName(testDBConf.getDriverClassName()); conn = DriverManager.getConnection(testDBConf.getConnectionURL()); stmt = conn.createStatement(); - stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'"); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'"); } finally { cleanupResources(conn, stmt, null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql index e69de29bb..c0c2cebba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql @@ -0,0 +1,88 @@ + +-- ----------------------------------------------------- +-- Table `MBL_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( + `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , + `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL , + `IMEI` VARCHAR(45) NULL DEFAULT NULL , + `IMSI` VARCHAR(45) NULL DEFAULT NULL , + `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , + `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , + `VENDOR` VARCHAR(45) NULL DEFAULT NULL , + `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, + `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, + `CHALLENGE` VARCHAR(45) NULL DEFAULT NULL, + `TOKEN` VARCHAR(500) NULL DEFAULT NULL, + `UNLOCK_TOKEN` VARCHAR(500) NULL DEFAULT NULL, + `SERIAL` VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (`MOBILE_DEVICE_ID`) ); + + +-- ----------------------------------------------------- +-- Table `AD_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , + `CODE` VARCHAR(45) NOT NULL, + `NAME` VARCHAR(100) NULL , + `DESCRIPTION` VARCHAR(200) NULL , + `DEVICE_TYPE` VARCHAR(50) NULL , + PRIMARY KEY (`FEATURE_ID`) ); + +-- ----------------------------------------------------- +-- Table `AD_OPERATION` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_OPERATION` ( + `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , + `FEATURE_CODE` VARCHAR(45) NOT NULL , + `CREATED_DATE` BIGINT NULL , + PRIMARY KEY (`OPERATION_ID`)); + +-- ----------------------------------------------------- +-- Table `AD_DEVICE_OPERATION_MAPPING` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_DEVICE_OPERATION_MAPPING` ( + `DEVICE_ID` VARCHAR(45) NOT NULL , + `OPERATION_ID` INT NOT NULL , + `SENT_DATE` BIGINT NULL , + `RECEIVED_DATE` BIGINT NULL , + `STATUS` VARCHAR(10) NOT NULL , + PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , + CONSTRAINT `fk_AD_DEVICE_OPERATION_AD_DEVICE` + FOREIGN KEY (`DEVICE_ID` ) + REFERENCES `AD_DEVICE` (`MOBILE_DEVICE_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_AD_DEVICE_OPERATION_AD_OPERATION1` + FOREIGN KEY (`OPERATION_ID` ) + REFERENCES `AD_OPERATION` (`OPERATION_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table `AD_OPERATION_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_OPERATION_PROPERTY` ( + `OPERATION_ID` INT NOT NULL , + `PROPERTY` VARCHAR(45) NOT NULL , + `VALUE` TEXT NULL , + PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , + CONSTRAINT `fk_AD_OPERATION_PROPERTY_AD_OPERATION1` + FOREIGN KEY (`OPERATION_ID` ) + REFERENCES `AD_OPERATION` (`OPERATION_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table `AD_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_FEATURE_PROPERTY` ( + `PROPERTY` VARCHAR(45) NOT NULL , + `FEATURE_ID` INT NOT NULL , + PRIMARY KEY (`PROPERTY`) , + CONSTRAINT `fk_AD_FEATURE_PROPERTY_AD_FEATURE1` + FOREIGN KEY (`FEATURE_ID` ) + REFERENCES `AD_FEATURE` (`FEATURE_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); diff --git a/test.out b/test.out new file mode 100644 index 000000000..3a045791a --- /dev/null +++ b/test.out @@ -0,0 +1,47 @@ +diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +index 719a38b..5a63eef 100644 +--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java ++++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +@@ -28,15 +28,13 @@ import java.util.List; + public abstract class AbstractMobileOperationManager implements OperationManager { + + @Override +- public List getOperations(DeviceIdentifier deviceIdentifier) +- throws OperationManagementException { ++ public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { + return null; + } + + @Override + public boolean addOperation(Operation operation, +- List devices) +- throws OperationManagementException { ++ List devices) throws OperationManagementException { + return true; + } + +diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java +index 17b347b..1aa3289 100644 +--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java ++++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java +@@ -19,7 +19,6 @@ + package org.wso2.carbon.device.mgt.mobile.impl.android.dao; + + import org.wso2.carbon.device.mgt.common.Feature; +-import org.wso2.carbon.device.mgt.common.FeatureManagementException; + + import java.util.List; + +diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java +index 38280e2..6607600 100644 +--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java ++++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java +@@ -20,8 +20,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.ios; + import org.apache.commons.logging.Log; + import org.apache.commons.logging.LogFactory; + import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +-import org.wso2.carbon.device.mgt.common.Feature; +-import org.wso2.carbon.device.mgt.common.FeatureManagementException; + import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; + import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; + import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager; From 340cf2a00344bcb56c9d8b337c60ce12336ad75e Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 23 Mar 2015 18:19:11 +0530 Subject: [PATCH 5/6] 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; - } - -} From 2c5cc4c28de5586b7450887d02c49a4c9973b40a Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Tue, 24 Mar 2015 09:31:17 +0530 Subject: [PATCH 6/6] * Added the dbscripts to the feature * Added copying support of dbscripts --- .../main/resources/dbscripts/plugins/h2.sql | 93 ++++++++++++++++ .../resources/dbscripts/plugins/mysql.sql | 103 ++++++++++++++++++ .../src/main/resources/p2.inf | 3 +- 3 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql new file mode 100644 index 000000000..2df2ee2f3 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2.sql @@ -0,0 +1,93 @@ + +-- ----------------------------------------------------- +-- Table `MBL_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( + `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , + `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL , + `IMEI` VARCHAR(45) NULL DEFAULT NULL , + `IMSI` VARCHAR(45) NULL DEFAULT NULL , + `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , + `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , + `VENDOR` VARCHAR(45) NULL DEFAULT NULL , + `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, + `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, + `CHALLENGE` VARCHAR(45) NULL DEFAULT NULL, + `TOKEN` VARCHAR(50) NULL DEFAULT NULL, + `UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL, + `SERIAL` VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (`MOBILE_DEVICE_ID`) ); + + +-- ----------------------------------------------------- +-- Table `MBL_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , + `DEVICE_TYPE` VARCHAR(45) NOT NULL , + `CODE` VARCHAR(45) NOT NULL , + `NAME` VARCHAR(100) NULL , + `DESCRIPTION` VARCHAR(200) NULL , + PRIMARY KEY (`FEATURE_ID`) ); + +-- ----------------------------------------------------- +-- Table `MBL_OPERATION` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( + `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , + `FEATURE_CODE` VARCHAR(45) NOT NULL , + `CREATED_DATE` BIGINT NULL , + PRIMARY KEY (`OPERATION_ID`)); + +-- ----------------------------------------------------- +-- Table `MBL_DEVICE_OPERATION_MAPPING` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( + `DEVICE_ID` VARCHAR(45) NOT NULL , + `OPERATION_ID` INT NOT NULL , + `SENT_DATE` BIGINT NULL , + `RECEIVED_DATE` BIGINT NULL , + `STATUS` VARCHAR(10) NOT NULL , + PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , + CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` + FOREIGN KEY (`DEVICE_ID` ) + REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` + FOREIGN KEY (`OPERATION_ID` ) + REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table `MBL_OPERATION_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( + `OPERATION_ID` INT NOT NULL , + `PROPERTY` VARCHAR(45) NOT NULL , + `VALUE` TEXT NULL , + PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , + CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` + FOREIGN KEY (`OPERATION_ID` ) + REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table `MBL_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( + `PROPERTY` VARCHAR(45) NOT NULL , + `FEATURE_ID` INT NOT NULL , + PRIMARY KEY (`PROPERTY`) , + CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` + FOREIGN KEY (`FEATURE_ID` ) + REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Inserts +-- ----------------------------------------------------- +INSERT INTO MBL_FEATURE (DEVICE_TYPE,NAME,CODE, DESCRIPTION) VALUES ('android','DEVICE_LOCK','503A','Device Lock'),('android','WIPE','504A','Device Wipe'),('android','CLEARPASSCODE','505A','Clear Passcode'),('android','APPLIST','502A','Get All Applications'),('android','LOCATION','501A','Location'),('android','INFO','500A','Device Information'),('android','NOTIFICATION','506A','Message'),('android','WIFI','507A','Setup Wifi'),('android','CAMERA','508A','Camera Control'),('android','MUTE','513A','Mute Device'),('android','INSTALLAPP','509A','Install Application'),('android','UNINSTALLAPP','510A','Uninstall Application'),('android','ENCRYPT','511A','Encrypt Storage'),('android','APN','512A','APN'),('android','WEBCLIP','518A','Create Webclips'),('android','PASSWORDPOLICY','519A','Passcode Policy'),('android','EMAIL','520A','Email Configuration'),('android','GOOGLECALENDAR','521A','Calender Subscription'),('android','VPN','523A','VPN'),('android','LDAP','524A','LDAP'),('android','CHANGEPASSWORD','526A','Set Passcode'),('android','ENTERPRISEWIPE','527A','Enterprise Wipe'),('android','POLICY','500P','Policy Enforcement'),('android','MONITORING','501P','Policy Monitoring '),('android','BLACKLISTAPPS','528B','Blacklist Apps'),('android','REVOKEPOLICY','502P','Revoke Policy'); \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql new file mode 100644 index 000000000..641f7f4dc --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql.sql @@ -0,0 +1,103 @@ +-- ----------------------------------------------------- +-- Table `MBL_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( + `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, + `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL, + `IMEI` VARCHAR(45) NULL DEFAULT NULL, + `IMSI` VARCHAR(45) NULL DEFAULT NULL, + `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, + `VENDOR` VARCHAR(45) NULL DEFAULT NULL, + `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, + `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, + `CHALLENGE` VARCHAR(45) NULL DEFAULT NULL, + `TOKEN` VARCHAR(50) NULL DEFAULT NULL, + `UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL, + `SERIAL` VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (`MOBILE_DEVICE_ID`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `MBL_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `DEVICE_TYPE` VARCHAR(45) NOT NULL , + `CODE` VARCHAR(45) NULL, + `NAME` VARCHAR(100) NULL, + `DESCRIPTION` VARCHAR(200) NULL, + PRIMARY KEY (`FEATURE_ID`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `MBL_OPERATION` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( + `OPERATION_ID` INT NOT NULL AUTO_INCREMENT, + `FEATURE_CODE` VARCHAR(45) NULL, + `CREATED_DATE` INT NULL, + PRIMARY KEY (`OPERATION_ID`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `MBL_DEVICE_OPERATION_MAPING` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( + `DEVICE_ID` VARCHAR(45) NOT NULL, + `OPERATION_ID` INT NOT NULL, + `SENT_DATE` INT NULL, + `RECEIVED_DATE` INT NULL, + `STATUS` VARCHAR(10) NOT NULL, + PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`), + INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC), + CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` + FOREIGN KEY (`DEVICE_ID`) + REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` + FOREIGN KEY (`OPERATION_ID`) + REFERENCES `MBL_OPERATION` (`OPERATION_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `MBL_OPERATION_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( + `OPERATION_ID` INT NULL, + `PROPERTY` VARCHAR(45) NOT NULL ,, + `VALUE` TEXT NULL, + PRIMARY KEY (`OPERATION_ID`, `PROPERTY`), + CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` + FOREIGN KEY (`OPERATION_ID`) + REFERENCES `MBL_OPERATION` (`OPERATION_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + +-- ----------------------------------------------------- +-- Table `MBL_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( + `PROPERTY` VARCHAR(45) NOT NULL , + `FEATURE_ID` INT NOT NULL , + PRIMARY KEY (`PROPERTY`), + CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` + FOREIGN KEY (`FEATURE_ID`) + REFERENCES `MBL_FEATURE` (`FEATURE_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + +-- ----------------------------------------------------- +-- Inserts +-- ----------------------------------------------------- +INSERT INTO MBL_FEATURE (DEVICE_TYPE,NAME,CODE, DESCRIPTION) VALUES ('android','DEVICE_LOCK','503A','Device Lock'),('android','WIPE','504A','Device Wipe'),('android','CLEARPASSCODE','505A','Clear Passcode'),('android','APPLIST','502A','Get All Applications'),('android','LOCATION','501A','Location'),('android','INFO','500A','Device Information'),('android','NOTIFICATION','506A','Message'),('android','WIFI','507A','Setup Wifi'),('android','CAMERA','508A','Camera Control'),('android','MUTE','513A','Mute Device'),('android','INSTALLAPP','509A','Install Application'),('android','UNINSTALLAPP','510A','Uninstall Application'),('android','ENCRYPT','511A','Encrypt Storage'),('android','APN','512A','APN'),('android','WEBCLIP','518A','Create Webclips'),('android','PASSWORDPOLICY','519A','Passcode Policy'),('android','EMAIL','520A','Email Configuration'),('android','GOOGLECALENDAR','521A','Calender Subscription'),('android','VPN','523A','VPN'),('android','LDAP','524A','LDAP'),('android','CHANGEPASSWORD','526A','Set Passcode'),('android','ENTERPRISEWIPE','527A','Enterprise Wipe'),('android','POLICY','500P','Policy Enforcement'),('android','MONITORING','501P','Policy Monitoring '),('android','BLACKLISTAPPS','528B','Blacklist Apps'),('android','REVOKEPOLICY','502P','Revoke Policy'); + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf index f410404d2..3e76789f8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf @@ -1,2 +1,3 @@ instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins,overwrite:true);\ \ No newline at end of file