From 99f7cd25e88e57292f25e3240b41051b48099aa9 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Thu, 22 Jan 2015 10:43:36 +0530 Subject: [PATCH] Merging left over changes from MDM. Most of the changes are from @harshahL. --- .../pom1.xml~ | 0 .../dao/MobileDeviceManagementDAOFactory.java | 165 +++++++------ .../impl/MobileDeviceOperationDAOImpl.java | 10 +- .../dao/impl/MobileOperationDAOImpl.java | 4 +- .../AndroidMobileOperationManager.java | 8 +- ...obileDeviceManagementServiceComponent.java | 219 ++++++++++-------- .../util/MobileDeviceManagementUtil.java | 56 ++--- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 5 +- 8 files changed, 253 insertions(+), 214 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom1.xml~ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom1.xml~ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom1.xml~ deleted file mode 100644 index e69de29bb..000000000 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java index ddaf0adf8..8415271d2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java @@ -19,81 +19,108 @@ package org.wso2.carbon.device.mgt.mobile.dao; 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.mobile.DataSourceListener; +import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.dao.impl.*; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementBundleActivator; import javax.sql.DataSource; +import java.util.Hashtable; +import java.util.List; /** * Factory class used to create MobileDeviceManagement related DAO objects. */ -public class MobileDeviceManagementDAOFactory implements DataSourceListener { - - private static DataSource dataSource; - private static MobileDataSourceConfig mobileDataSourceConfig; - private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class); - - public MobileDeviceManagementDAOFactory() { - - } - - public void init() throws DeviceManagementException { - dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig); - if (dataSource != null) { - MobileDeviceManagementDAOUtil.createDataSource(dataSource); - } else { - MobileDeviceManagementBundleActivator.registerDataSourceListener(this); - } - } - - public static MobileDeviceDAO getMobileDeviceDAO() { - return new MobileDeviceDAOImpl(dataSource); - } - - public static MobileOperationDAO getMobileOperationDAO() { - return new MobileOperationDAOImpl(dataSource); - } - - public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { - return new MobileOperationPropertyDAOImpl(dataSource); - } - - public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() { - return new MobileDeviceOperationDAOImpl(dataSource); - } - - public static FeatureDAO getFeatureDAO() { - return new FeatureDAOImpl(dataSource); - } - - public static FeaturePropertyDAO getFeaturePropertyDAO() { - return new FeaturePropertyDAOImpl(dataSource); - } - - public static MobileDataSourceConfig getMobileDeviceManagementConfig() { - return mobileDataSourceConfig; - } - - public static void setMobileDataSourceConfig( - MobileDataSourceConfig mobileDataSourceConfig) { - MobileDeviceManagementDAOFactory.mobileDataSourceConfig = - mobileDataSourceConfig; - } - - public static DataSource getDataSource() { - return dataSource; - } - - @Override - public void notifyObserver() { - try { - dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig); - MobileDeviceManagementDAOUtil.createDataSource(dataSource); - } catch (DeviceManagementException e) { - log.error("Error occurred while resolving mobile device management metadata repository data source", e); - } - } -} +public class MobileDeviceManagementDAOFactory { + + private static DataSource dataSource; + private static MobileDataSourceConfig mobileDataSourceConfig; + private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class); + + public MobileDeviceManagementDAOFactory() { + + } + + public static void init() { + try { + dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig); + } catch (DeviceManagementException e) { + log.error("Exception occurred while initializing the mobile datasource.",e); + } + } + + /** + * Resolve data source from the data source definition. + * + * @param config Mobile data source configuration + * @return data source resolved from the data source definition + */ + private static DataSource resolveDataSource(MobileDataSourceConfig config) + throws DeviceManagementException { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException("Device Management Repository data source configuration " + + "is null and thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = + MobileDeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = MobileDeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } + + public static MobileDeviceDAO getMobileDeviceDAO() { + return new MobileDeviceDAOImpl(dataSource); + } + + public static MobileOperationDAO getMobileOperationDAO() { + return new MobileOperationDAOImpl(dataSource); + } + + public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { + return new MobileOperationPropertyDAOImpl(dataSource); + } + + public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() { + return new MobileDeviceOperationDAOImpl(dataSource); + } + + public static FeatureDAO getFeatureDAO() { + return new FeatureDAOImpl(dataSource); + } + + public static FeaturePropertyDAO getFeaturePropertyDAO() { + return new FeaturePropertyDAOImpl(dataSource); + } + + public static MobileDataSourceConfig getMobileDeviceManagementConfig() { + return mobileDataSourceConfig; + } + + public static void setMobileDataSourceConfig( + MobileDataSourceConfig mobileDataSourceConfig) { + MobileDeviceManagementDAOFactory.mobileDataSourceConfig = + mobileDataSourceConfig; + } + + public static DataSource getDataSource() { + return dataSource; + } +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java index e2d24e5e9..f15af1ac5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java @@ -52,7 +52,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_DEVICE_OPERATION(DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)"; + "INSERT INTO MBL_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, deviceOperation.getDeviceId()); @@ -86,7 +86,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_DEVICE_OPERATION SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setLong(1, deviceOperation.getSentDate()); stmt.setLong(2, deviceOperation.getReceivedDate()); @@ -117,7 +117,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, deviceId); stmt.setInt(2, operationId); @@ -146,7 +146,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceId); stmt.setInt(2, operationId); @@ -181,7 +181,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ?"; + "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceId); 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 01612098a..e2fb47b73 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 @@ -138,11 +138,13 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { String selectDBQuery = "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); - stmt.setInt(1, operation.getOperationId()); + stmt.setInt(1, operationId); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { operation = new MobileOperation(); operation.setOperationId(resultSet.getInt(1)); + operation.setFeatureCode(resultSet.getString(2)); + operation.setCreatedDate(resultSet.getLong(3)); break; } } catch (SQLException 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 f04bba9a9..76c633243 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 @@ -58,7 +58,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage mobileDeviceOperation.setDeviceId(deviceIdentifier.getId()); status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() .addMobileDeviceOperation( - new MobileDeviceOperation()); + mobileDeviceOperation); } } } catch (MobileDeviceManagementDAOException e) { @@ -75,6 +75,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage throws OperationManagementException { List operations = new ArrayList(); List mobileDeviceOperations = null; + List operationProperties = null; MobileOperation mobileOperation = null; try { mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() @@ -88,6 +89,11 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO() .getMobileOperation( operationId); + operationProperties = + MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO() + .getAllMobileOperationPropertiesOfOperation( + operationId); + mobileOperation.setProperties(operationProperties); operations.add(MobileDeviceManagementUtil .convertMobileOperationToOperation(mobileOperation)); } 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 195929bb2..28606783d 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 @@ -31,6 +31,7 @@ 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.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; @@ -54,112 +55,134 @@ 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 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); - - 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); + 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(); + 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(); /* 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 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 + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index d170379ee..d771cb485 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -60,39 +60,19 @@ public class MobileDeviceManagementUtil { } } - private static String getPropertyValue(Device device, String property) { - for (Device.Property prop : device.getProperties()) { - if (property.equals(prop.getName())) { - return prop.getValue(); - } - } - return null; - } - - private static Device.Property getProperty(String property, String value) { - Device.Property prop = null; - if (property != null) { - prop = new Device.Property(); - prop.setName(property); - prop.setValue(value); - return prop; - } - return prop; - } - public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); - mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); - mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); - mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID)); - mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); - mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); - mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); - mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); - mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); + mobileDevice.setImei(device.getProperties().get(MOBILE_DEVICE_IMEI)); + mobileDevice.setImsi(device.getProperties().get(MOBILE_DEVICE_IMSI)); + mobileDevice.setRegId(device.getProperties().get(MOBILE_DEVICE_REG_ID)); + mobileDevice.setModel(device.getProperties().get(MOBILE_DEVICE_MODEL)); + mobileDevice.setOsVersion(device.getProperties().get(MOBILE_DEVICE_OS_VERSION)); + mobileDevice.setVendor(device.getProperties().get(MOBILE_DEVICE_VENDOR)); + mobileDevice.setLatitude(device.getProperties().get(MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(device.getProperties().get(MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } @@ -101,16 +81,16 @@ public class MobileDeviceManagementUtil { Device device = null; if (mobileDevice != null) { device = new Device(); - List propertyList = new ArrayList(); - propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); - propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); - propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId())); - propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); - propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); - propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); - propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); - propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); - device.setProperties(propertyList); + Map propertyMap = new HashMap(); + propertyMap.put(MOBILE_DEVICE_IMEI, mobileDevice.getImei()); + propertyMap.put(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()); + propertyMap.put(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId()); + propertyMap.put(MOBILE_DEVICE_MODEL, mobileDevice.getModel()); + propertyMap.put(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()); + propertyMap.put(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()); + propertyMap.put(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()); + propertyMap.put(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()); + device.setProperties(propertyMap); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml b/product/modules/mobileservices/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml index a58b5fc25..5b0c46836 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -23,9 +23,9 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + - + @@ -53,6 +53,7 @@ +