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 b8ac184fb..9724e4eaf 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 @@ -60,7 +60,7 @@ javax.xml.bind.*, javax.naming, javax.sql, - javax.xml.bind.annotation, + javax.xml.bind.annotation.*, javax.xml.parsers, org.w3c.dom, org.wso2.carbon.core, 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 5a63eef8b..1b369bb16 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 @@ -33,8 +33,8 @@ public abstract class AbstractMobileOperationManager implements OperationManager } @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { + public boolean addOperation(Operation operation, 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/config/MobileDeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java index 755e71f90..07123434d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java @@ -75,8 +75,5 @@ public class MobileDeviceConfigurationManager { return currentMobileDeviceConfig; } - public MobileDataSourceConfig getMobileDataSourceConfig() { - return currentMobileDeviceConfig.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java index 96b6644b2..88369dd84 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java @@ -18,10 +18,14 @@ package org.wso2.carbon.device.mgt.mobile.config; +import org.wso2.carbon.device.mgt.mobile.config.datasource.DataSourceConfigAdapter; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.List; +import java.util.Map; /** * Class for holding management repository data. @@ -29,15 +33,25 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "ManagementRepository") public class MobileDeviceManagementRepository { - private MobileDataSourceConfig mobileDataSourceConfig; + private Map mobileDataSourceConfigMap; + private List mobileDataSourceConfigs; - @XmlElement(name = "DataSourceConfiguration", nillable = false) - public MobileDataSourceConfig getMobileDataSourceConfig() { - return mobileDataSourceConfig; - } + public MobileDataSourceConfig getMobileDataSourceConfig(String provider) { + return mobileDataSourceConfigMap.get(provider); + } - public void setMobileDataSourceConfig(MobileDataSourceConfig mobileDataSourceConfig) { - this.mobileDataSourceConfig = mobileDataSourceConfig; - } + @XmlElement(name = "DataSourceConfigurations") + @XmlJavaTypeAdapter(DataSourceConfigAdapter.class) + public Map getMobileDataSourceConfigMap() { + return mobileDataSourceConfigMap; + } + + public void setMobileDataSourceConfigMap(Map mobileDataSourceConfigMap) { + this.mobileDataSourceConfigMap = mobileDataSourceConfigMap; + } + + public List getMobileDataSourceConfigs() { + return (List) mobileDataSourceConfigMap.values(); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java new file mode 100644 index 000000000..71675785c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java @@ -0,0 +1,51 @@ +/* + * 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.config.datasource; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DataSourceConfigAdapter + extends XmlAdapter> { + + @Override + public Map unmarshal(MobileDataSourceConfigurations mobileDataSourceConfigurations) + throws Exception { + + Map mobileDataSourceConfigMap = new HashMap(); + for (MobileDataSourceConfig mobileDataSourceConfig : mobileDataSourceConfigurations + .getMobileDataSourceConfigs()) { + mobileDataSourceConfigMap.put(mobileDataSourceConfig.getType(), mobileDataSourceConfig); + } + return mobileDataSourceConfigMap; + } + + @Override + public MobileDataSourceConfigurations marshal(Map mobileDataSourceConfigMap) + throws Exception { + + MobileDataSourceConfigurations mobileDataSourceConfigurations = new MobileDataSourceConfigurations(); + mobileDataSourceConfigurations.setMobileDataSourceConfigs( + (List) mobileDataSourceConfigMap.values()); + + return mobileDataSourceConfigurations; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java index 53eced08e..869aaf12e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java @@ -18,15 +18,18 @@ package org.wso2.carbon.device.mgt.mobile.config.datasource; +import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** * Class for holding data source configuration in mobile-config.xml at parsing with JAXB. */ -@XmlRootElement(name = "DataSourceConfiguration") public class MobileDataSourceConfig { +@XmlRootElement(name = "DataSourceConfiguration") +public class MobileDataSourceConfig { private JNDILookupDefinition jndiLookupDefinition; + private String type; @XmlElement(name = "JndiLookupDefinition", nillable = true) public JNDILookupDefinition getJndiLookupDefinition() { @@ -37,4 +40,12 @@ import javax.xml.bind.annotation.XmlRootElement; this.jndiLookupDefinition = jndiLookupDefinition; } + @XmlAttribute(name = "type") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java new file mode 100644 index 000000000..17e80f5bf --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java @@ -0,0 +1,41 @@ +/* + * 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.config.datasource; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement(name = "DataSourceConfigurations") +@XmlAccessorType(XmlAccessType.FIELD) +public class MobileDataSourceConfigurations { + + @XmlElement(name = "DataSourceConfiguration", nillable = true) + private List mobileDataSourceConfigs; + + public List getMobileDataSourceConfigs() { + return mobileDataSourceConfigs; + } + + public void setMobileDataSourceConfigs(List mobileDataSourceConfigs) { + this.mobileDataSourceConfigs = mobileDataSourceConfigs; + } + +} 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 0f10a4a04..c1eebf913 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 @@ -21,41 +21,45 @@ 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.DataSourceNotAvailableException; 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.MobileDeviceManagementServiceComponent; import javax.sql.DataSource; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; +import java.util.Map; /** * Factory class used to create MobileDeviceManagement related DAO objects. */ public class MobileDeviceManagementDAOFactory { - private static DataSource dataSource; - private static MobileDataSourceConfig dsConfig; private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class); + private static Map mobileDataSourceConfigMap; + private static Map dataSourceMap; + private String pluginProvider; + private DataSource dataSource; private static boolean isInitialized; + public MobileDeviceManagementDAOFactory(String pluginProvider) { + this.pluginProvider = pluginProvider; + this.dataSource = dataSourceMap.get(pluginProvider); + } + public static void init() throws DeviceManagementException { - dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(dsConfig); + + dataSourceMap = new HashMap(); + DataSource dataSource; + for (String pluginType : mobileDataSourceConfigMap.keySet()) { + dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get + (pluginType)); + dataSourceMap.put(pluginType, dataSource); + } isInitialized = true; -// MobileDeviceManagementServiceComponent.registerDataSourceListener(new DataSourceListener() { -// @Override -// public void notifyObserver() { -// try { -// initDataSource(); -// } catch (DeviceManagementException e) { -// log.error("Error occurred while registering data source"); -// } -// } -// }); } /** @@ -85,50 +89,58 @@ public class MobileDeviceManagementDAOFactory { jndiProperties.put(prop.getName(), prop.getValue()); } dataSource = - MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + MobileDeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); } else { - dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + dataSource = MobileDeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), null); } } return dataSource; } - public static MobileDeviceDAO getMobileDeviceDAO() { - assertDataSourceInitialization(); + public MobileDeviceDAO getMobileDeviceDAO() { return new MobileDeviceDAOImpl(dataSource); } - public static MobileOperationDAO getMobileOperationDAO() { - assertDataSourceInitialization(); + public MobileOperationDAO getMobileOperationDAO() { return new MobileOperationDAOImpl(dataSource); } - public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { - assertDataSourceInitialization(); + public MobileOperationPropertyDAO getMobileOperationPropertyDAO() { return new MobileOperationPropertyDAOImpl(dataSource); } - public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { - assertDataSourceInitialization(); + public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { return new MobileDeviceOperationMappingDAOImpl(dataSource); } - public static MobileFeatureDAO getFeatureDAO() { - assertDataSourceInitialization(); + public MobileFeatureDAO getFeatureDAO() { return new MobileFeatureDAOImpl(dataSource); } - public static MobileFeaturePropertyDAO getFeaturePropertyDAO() { - assertDataSourceInitialization(); + public MobileFeaturePropertyDAO getFeaturePropertyDAO() { return new MobileFeaturePropertyDAOImpl(dataSource); } - public static void setDatSourceConfig(MobileDataSourceConfig dsConfig) { - MobileDeviceManagementDAOFactory.dsConfig = dsConfig; + public MobileDataSourceConfig getMobileDeviceManagementConfig(String pluginType) { + return mobileDataSourceConfigMap.get(pluginType); } - public static DataSource getDataSource() { - return dataSource; + public static Map getMobileDataSourceConfigMap() { + return mobileDataSourceConfigMap; + } + + public static void setMobileDataSourceConfigMap(Map mobileDataSourceConfigMap) { + MobileDeviceManagementDAOFactory.mobileDataSourceConfigMap = mobileDataSourceConfigMap; + } + + public DataSource getDataSource(String type) { + return dataSourceMap.get(type); + } + + public static Map getDataSourceMap() { + return dataSourceMap; } private static void assertDataSourceInitialization() { @@ -137,5 +149,4 @@ public class MobileDeviceManagementDAOFactory { "is not initialized"); } } - } \ 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/impl/android/AndroidDeviceManager.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 index 77b652e10..70256e52b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.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 @@ -20,12 +20,12 @@ 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.*; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import org.wso2.carbon.device.mgt.common.*; import java.util.ArrayList; import java.util.List; @@ -35,12 +35,18 @@ import java.util.List; */ public class AndroidDeviceManager implements DeviceManager { + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; private static final Log log = LogFactory.getLog(AndroidDeviceManager.class); - @Override - public String getProviderType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; - } + public AndroidDeviceManager() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + } + + @Override + public String getProviderType() { + return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; + } @Override public FeatureManager getFeatureManager() { @@ -48,157 +54,157 @@ public class AndroidDeviceManager implements DeviceManager { } @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( - mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while enrolling the Android device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Modifying the Android device enrollment data"); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while updating the enrollment of the Android device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean status; - try { - if (log.isDebugEnabled()) { - log.debug("Dis-enrolling Android device : " + deviceId); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .deleteMobileDevice(deviceId.getId()); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while removing the Android device : " + deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean isEnrolled = false; - try { - if (log.isDebugEnabled()) { - log.debug("Checking the enrollment of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( - deviceId.getId()); - if (mobileDevice != null) { - isEnrolled = true; - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while checking the enrollment status of Android device : " + - deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return isEnrolled; - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return true; - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - return true; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - Device device; - try { - if (log.isDebugEnabled()) { - log.debug("Getting the details of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getMobileDevice(deviceId.getId()); - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while fetching the Android device : " + deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return device; - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return true; - } - - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("updating the details of Android device : " + device.getDeviceIdentifier()); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public List getAllDevices() throws DeviceManagementException { - List devices = null; - try { - if (log.isDebugEnabled()) { - log.debug("Fetching the details of all Android devices"); - } - List mobileDevices = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getAllMobileDevices(); - if (mobileDevices != null) { - devices = new ArrayList(); + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while enrolling the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the Android device enrollment data"); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while updating the enrollment of the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling Android device : " + deviceId); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .deleteMobileDevice(deviceId.getId()); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while removing the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean isEnrolled = false; + try { + if (log.isDebugEnabled()) { + log.debug("Checking the enrollment of Android device : " + deviceId.getId()); + } + MobileDevice mobileDevice = + mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( + deviceId.getId()); + if (mobileDevice != null) { + isEnrolled = true; + } + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while checking the enrollment status of Android device : " + + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return isEnrolled; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + Device device; + try { + if (log.isDebugEnabled()) { + log.debug("Getting the details of Android device : " + deviceId.getId()); + } + MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + getMobileDevice(deviceId.getId()); + device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while fetching the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return device; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("updating the details of Android device : " + device.getDeviceIdentifier()); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + List devices = null; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all Android devices"); + } + List mobileDevices = + mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + getAllMobileDevices(); + if (mobileDevices != null) { + devices = new ArrayList(); for (MobileDevice mobileDevice : mobileDevices) { devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); } - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while fetching all Android devices."; - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return devices; - } + } + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while fetching all Android devices."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return devices; + } } \ 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/impl/ios/IOSDeviceManager.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 index 7f0b761f7..c96ede764 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.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 @@ -34,13 +34,19 @@ import java.util.List; */ public class IOSDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(IOSDeviceManager.class); + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + private static final Log log = LogFactory.getLog(IOSDeviceManager.class); @Override public String getProviderType() { return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS; } + public IOSDeviceManager() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants + .MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS); + } + @Override public FeatureManager getFeatureManager() { return null; @@ -51,7 +57,7 @@ public class IOSDeviceManager implements DeviceManager { boolean status; MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while enrolling the iOS device : " + @@ -70,7 +76,7 @@ public class IOSDeviceManager implements DeviceManager { if (log.isDebugEnabled()) { log.debug("Modifying the iOS device enrollment data"); } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() .updateMobileDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while updating the enrollment of the iOS device : " + @@ -94,7 +100,7 @@ public class IOSDeviceManager implements DeviceManager { log.debug("Checking the enrollment of iOS device : " + deviceId.getId()); } MobileDevice mobileDevice = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( + mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( deviceId.getId()); if (mobileDevice != null) { isEnrolled = true; @@ -131,7 +137,7 @@ public class IOSDeviceManager implements DeviceManager { if (log.isDebugEnabled()) { log.debug("Getting the details of iOS device : " + deviceId.getId()); } - MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). getMobileDevice(deviceId.getId()); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.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 index 377695472..054e1eab8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.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 @@ -34,6 +34,12 @@ import java.util.List; */ public class WindowsDeviceManager implements DeviceManager { + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + + public WindowsDeviceManager() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants + .MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + } private static final Log log = LogFactory.getLog(WindowsDeviceManager.class); @Override @@ -97,7 +103,7 @@ public class WindowsDeviceManager implements DeviceManager { boolean status; MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while enrolling the Windows device : " + 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 2eed5266c..e2482e692 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 @@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * BundleActivator of MobileDeviceManagement component. @@ -58,14 +59,13 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B } bundleContext.addBundleListener(this); - /* Initialize the datasource configuration */ + /* Initialize the data source configuration */ MobileDeviceConfigurationManager.getInstance().initConfig(); MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - - MobileDeviceManagementDAOFactory.setDatSourceConfig(dsConfig); + Map mobileDataSourceConfigMap = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap(); + MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(mobileDataSourceConfigMap); androidServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), 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 a00dd92c2..5e5d87c34 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 @@ -35,6 +35,9 @@ import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager; import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager; import org.wso2.carbon.ndatasource.core.DataSourceService; +import javax.sql.DataSource; +import java.util.Map; + /** * @scr.component name="org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementServiceComponent" * immediate="true" @@ -51,18 +54,28 @@ import org.wso2.carbon.ndatasource.core.DataSourceService; */ public class MobileDeviceManagementServiceComponent { - private ServiceRegistration androidServiceRegRef; - private ServiceRegistration iOSServiceRegRef; - private ServiceRegistration windowsServiceRegRef; + private ServiceRegistration serverStartupObserverRef; + 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 data source configuration */ + MobileDeviceConfigurationManager.getInstance().initConfig(); + MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() + .getMobileDeviceManagementConfig(); + Map dsConfigMap = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap(); + MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap); + MobileDeviceManagementDAOFactory.init(); String setupOption = System.getProperty("setup"); if (setupOption != null) { @@ -72,8 +85,11 @@ public class MobileDeviceManagementServiceComponent { "to begin"); } try { - MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema( - MobileDeviceManagementDAOFactory.getDataSource()); + Map dataSourceMap = MobileDeviceManagementDAOFactory.getDataSourceMap(); + for (DataSource dataSource : dataSourceMap.values()) { + MobileDeviceManagementDAOUtil + .setupMobileDeviceManagementSchema(dataSource); + } } catch (DeviceManagementException e) { log.error("Exception occurred while initializing mobile device management database schema", e); } @@ -108,41 +124,24 @@ public class MobileDeviceManagementServiceComponent { if (windowsServiceRegRef != null) { windowsServiceRegRef.unregister(); } - - 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); - } - } + 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); + } + } protected void setDataSourceService(DataSourceService dataSourceService) { /* This is to avoid mobile device management component getting initialized before the underlying datasources are registered */ - try { - initConfigs(); - } catch (DeviceManagementException e) { - log.error("Error occurred while initializing mobile device management repository datasource", e); + if (log.isDebugEnabled()) { + log.debug("Data source service set to mobile service component"); } } - private void initConfigs() throws DeviceManagementException { - /* Initialize the datasource configuration */ - MobileDeviceConfigurationManager.getInstance().initConfig(); - - MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() - .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - - MobileDeviceManagementDAOFactory.setDatSourceConfig(dsConfig); - MobileDeviceManagementDAOFactory.init(); - } - protected void unsetDataSourceService(DataSourceService dataSourceService) { //do nothing } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml index 69f2044ec..3fad2eceb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml @@ -19,24 +19,23 @@ - - - jdbc/MobileDM_DS - - + + + + jdbc/MobileIOSDM_DS + + + + + jdbc/MobileAndroidDM_DS + + + + + jdbc/MobileWindowsDM_DS + + + - - - - - enrollment - admin - enrollment - 1.0.0 - http://localhost:9763/ - http,https - - - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml index 9ed6b8af0..9daf68724 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml @@ -19,13 +19,24 @@ - + + - jdbc/MobileDM_DS + jdbc/MobileIOSDM_DS + + + jdbc/MobileAndroidDM_DS + + + + + jdbc/MobileWindowsDM_DS + + + -