From e40424c7583f3f4e3ebc3b60ecfda3bf7b97a1e2 Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 23 Jan 2015 19:44:16 +0530 Subject: [PATCH 1/4] Added copying mobile db scripts to bin.xml & refactored code --- .../impl/dao/MobileFeatureDAOTestSuite.java | 11 ++++- .../modules/distribution/src/assembly/bin.xml | 2 +- .../jax-rs/src/main/java/Licenses.java | 45 ------------------- .../mobileservices/android/Test.java | 35 --------------- 4 files changed, 10 insertions(+), 83 deletions(-) delete mode 100644 product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java delete mode 100644 product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java 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 de81ff5a6..0f94b06a7 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 @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.mobile.impl.dao; import org.apache.commons.dbcp.BasicDataSource; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; @@ -44,6 +46,7 @@ import java.util.List; public class MobileFeatureDAOTestSuite { + private static final Log log = LogFactory.getLog(MobileFeatureDAOTestSuite.class); public static final String MBL_FEATURE_NAME = "Camera"; private static final String MBL_FEATURE_CODE = "500A"; public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable"; @@ -139,6 +142,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in retrieving Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in retrieving Mobile Feature data ", e); } finally { @@ -182,6 +186,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in deleting Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ", e); } finally { @@ -228,6 +233,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in deleting Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ", e); } finally { @@ -252,8 +258,8 @@ public class MobileFeatureDAOTestSuite { stmt = conn.createStatement(); ResultSet resultSet = stmt .executeQuery( - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = " + - MBL_FEATURE_UPDATED_CODE); + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = '" + + MBL_FEATURE_UPDATED_CODE + "'"); while (resultSet.next()) { testMblFeature.setId(resultSet.getInt(1)); testMblFeature.setCode(resultSet.getString(2)); @@ -262,6 +268,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in updating Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in updating Mobile Feature data ", e); } finally { diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 7420ae1f6..0a4cbc57a 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -210,7 +210,7 @@ - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/cdm + ../distribution/src/repository/dbscripts/cdm wso2mdm-${project.version}/dbscripts/cdm */** diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java deleted file mode 100644 index aa49c5939..000000000 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java +++ /dev/null @@ -1,45 +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. - * / - */ - -import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.License; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Produces; - -/** - * License Management related JAX RS APIs - */ - -@Produces({ "application/json", "application/xml" }) -@Consumes({ "application/json", "application/xml" }) -public class Licenses { - - private static Log log = LogFactory.getLog(Licenses.class); - - @GET - public License getLicense(String deviceType) throws AndroidAgentException { - return null; - } - -} diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java deleted file mode 100644 index ee9e56212..000000000 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.wso2.cdmserver.mobileservices.android; - -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.Device; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; - -/** - * This is a Test class - */ -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public class Test { - - @GET - public List getAllDevices() throws DeviceManagementException{ - - Device dev = new Device(); - dev.setName("test1"); - dev.setDateOfEnrolment(11111111L); - dev.setDateOfLastUpdate(992093209L); - dev.setDescription("sassasaas"); - - ArrayList listdevices = new ArrayList(); - listdevices.add(dev); - throw new DeviceManagementException("test ex"); - - } -} From da34270a61548df08a45ed17182a7a9393572bac Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 23 Jan 2015 20:53:50 +0530 Subject: [PATCH 2/4] Fixing API Manager related issues --- ...obileDeviceManagementServiceComponent.java | 214 ++++++++---------- .../src/assembly/filter.properties | 2 +- 2 files changed, 93 insertions(+), 123 deletions(-) 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 28606783d..2d0dc8c91 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 @@ -24,8 +24,11 @@ import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.APIProvider; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.apimgt.impl.APIManagerFactory; +import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil; +import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +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; @@ -55,134 +58,101 @@ import java.util.List; */ public class MobileDeviceManagementServiceComponent { - private ServiceRegistration androidServiceRegRef; - private ServiceRegistration iOSServiceRegRef; - private ServiceRegistration windowsServiceRegRef; + private ServiceRegistration androidServiceRegRef; + private ServiceRegistration iOSServiceRegRef; + private ServiceRegistration windowsServiceRegRef; + private ServiceRegistration serverStartupObserverRef; - private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); + private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); - protected void activate(ComponentContext ctx) { - if (log.isDebugEnabled()) { - log.debug("Activating Mobile Device Management Service Component"); - } - try { - BundleContext bundleContext = ctx.getBundleContext(); + protected void activate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Activating Mobile Device Management Service Component"); + } + try { + BundleContext bundleContext = ctx.getBundleContext(); /* Initialize the datasource configuration */ - MobileDeviceConfigurationManager.getInstance().initConfig(); - MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() - .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - - MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); - MobileDeviceManagementDAOFactory.init(); - String setupOption = System.getProperty("setup"); - if (setupOption != null) { - if (log.isDebugEnabled()) { - log.debug( - "-Dsetup is enabled. Mobile Device management repository schema initialization is about " + - "to begin"); - } - try { - MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema( - MobileDeviceManagementDAOFactory.getDataSource()); - } catch (DeviceManagementException e) { - log.error( - "Exception occurred while initializing mobile device management database schema", - e); - } - } - - androidServiceRegRef = - bundleContext.registerService(DeviceManagerService.class.getName(), - new AndroidDeviceManagerService(), null); - iOSServiceRegRef = - bundleContext.registerService(DeviceManagerService.class.getName(), - new IOSDeviceManagerService(), null); - windowsServiceRegRef = - bundleContext.registerService(DeviceManagerService.class.getName(), - new WindowsDeviceManagerService(), 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 Component has been successfully activated"); - } - } catch (Throwable e) { - log.error("Error occurred while activating Mobile Device Management Service Component", - e); - } - } - - protected void deactivate(ComponentContext ctx) { - if (log.isDebugEnabled()) { - log.debug("De-activating Mobile Device Management Service Component"); - } - try { - BundleContext bundleContext = ctx.getBundleContext(); - - androidServiceRegRef.unregister(); - iOSServiceRegRef.unregister(); - windowsServiceRegRef.unregister(); + MobileDeviceConfigurationManager.getInstance().initConfig(); + MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() + .getMobileDeviceManagementConfig(); + MobileDataSourceConfig dsConfig = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); + + MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); + MobileDeviceManagementDAOFactory.init(); + String setupOption = System.getProperty("setup"); + if (setupOption != null) { + if (log.isDebugEnabled()) { + log.debug( + "-Dsetup is enabled. Mobile Device management repository schema initialization is about " + + "to begin"); + } + try { + MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema( + MobileDeviceManagementDAOFactory.getDataSource()); + } catch (DeviceManagementException e) { + log.error("Exception occurred while initializing mobile device management database schema", e); + } + } + + androidServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new AndroidDeviceManagerService(), null); + iOSServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new IOSDeviceManagerService(), null); + windowsServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new WindowsDeviceManagerService(), null); + + serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class, + new MobileDeviceManagementStartupObserver(), null); + if (log.isDebugEnabled()) { + log.debug("Mobile Device Management Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Mobile Device Management Service Component", e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating Mobile Device Management Service Component"); + } + try { + androidServiceRegRef.unregister(); + iOSServiceRegRef.unregister(); + 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"); - } - } catch (Throwable e) { - log.error("Error occurred while de-activating Mobile Device Management bundle", e); - } - } - - 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); - } - } - - protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { - //do nothing - } - - protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) { - //do nothing - } + this.removeAPIs(); + if (log.isDebugEnabled()) { + log.debug( + "Mobile Device Management Service Component has been successfully de-activated"); + } + } catch (Throwable e) { + log.error("Error occurred while de-activating Mobile Device Management bundle", e); + } + } + + 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/product/modules/distribution/src/assembly/filter.properties b/product/modules/distribution/src/assembly/filter.properties index 19404cf6e..6910642d5 100644 --- a/product/modules/distribution/src/assembly/filter.properties +++ b/product/modules/distribution/src/assembly/filter.properties @@ -1,5 +1,5 @@ product.name=WSO2 Mobile Device Manager -product.version=1.0.0-SNAPSHOT +product.version=2.0.0-SNAPSHOT product.key=MDM hotdeployment=true hotupdate=true From e9ebd884459fe142ce7277449f493f3d508302a3 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 23 Jan 2015 21:29:32 +0530 Subject: [PATCH 3/4] Configuring logging for test cases --- .../pom.xml | 3 ++ .../src/test/resources/log4j.properties | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/log4j.properties 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 cdad607b6..5180e45ed 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 @@ -73,6 +73,9 @@ maven-surefire-plugin 2.18 + + file:src/test/resources/log4j.properties + src/test/resources/testng.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/log4j.properties b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/log4j.properties new file mode 100644 index 000000000..7da6d6c9e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n From f296fb763e07a9cd4ef653d6bbe9447fd29c0371 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 23 Jan 2015 21:36:02 +0530 Subject: [PATCH 4/4] Configuring product.name and product.version variables to be replaced with appropriate filter properties --- product/modules/distribution/src/assembly/bin.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 0a4cbc57a..5cdad53d4 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -470,5 +470,11 @@ 644 + + target/wso2carbon-core-${carbon.kernel.version}/repository/conf/carbon.xml + ${pom.artifactId}-${pom.version}/repository/conf/ + true + +