prabathabey 10 years ago
commit 1fb4864307

@ -60,7 +60,7 @@
javax.xml.bind.*, javax.xml.bind.*,
javax.naming, javax.naming,
javax.sql, javax.sql,
javax.xml.bind.annotation, javax.xml.bind.annotation.*,
javax.xml.parsers, javax.xml.parsers,
org.w3c.dom, org.w3c.dom,
org.wso2.carbon.core, org.wso2.carbon.core,

@ -33,8 +33,8 @@ public abstract class AbstractMobileOperationManager implements OperationManager
} }
@Override @Override
public boolean addOperation(Operation operation, public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
List<DeviceIdentifier> devices) throws OperationManagementException { OperationManagementException {
return true; return true;
} }

@ -75,8 +75,5 @@ public class MobileDeviceConfigurationManager {
return currentMobileDeviceConfig; return currentMobileDeviceConfig;
} }
public MobileDataSourceConfig getMobileDataSourceConfig() {
return currentMobileDeviceConfig.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
}
} }

@ -18,10 +18,14 @@
package org.wso2.carbon.device.mgt.mobile.config; 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 org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; 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. * Class for holding management repository data.
@ -29,15 +33,25 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "ManagementRepository") @XmlRootElement(name = "ManagementRepository")
public class MobileDeviceManagementRepository { public class MobileDeviceManagementRepository {
private MobileDataSourceConfig mobileDataSourceConfig; private Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap;
private List<MobileDataSourceConfig> mobileDataSourceConfigs;
@XmlElement(name = "DataSourceConfiguration", nillable = false) public MobileDataSourceConfig getMobileDataSourceConfig(String provider) {
public MobileDataSourceConfig getMobileDataSourceConfig() { return mobileDataSourceConfigMap.get(provider);
return mobileDataSourceConfig; }
}
public void setMobileDataSourceConfig(MobileDataSourceConfig mobileDataSourceConfig) { @XmlElement(name = "DataSourceConfigurations")
this.mobileDataSourceConfig = mobileDataSourceConfig; @XmlJavaTypeAdapter(DataSourceConfigAdapter.class)
} public Map<String, MobileDataSourceConfig> getMobileDataSourceConfigMap() {
return mobileDataSourceConfigMap;
}
public void setMobileDataSourceConfigMap(Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap) {
this.mobileDataSourceConfigMap = mobileDataSourceConfigMap;
}
public List<MobileDataSourceConfig> getMobileDataSourceConfigs() {
return (List<MobileDataSourceConfig>) mobileDataSourceConfigMap.values();
}
} }

@ -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<MobileDataSourceConfigurations, Map<String, MobileDataSourceConfig>> {
@Override
public Map<String, MobileDataSourceConfig> unmarshal(MobileDataSourceConfigurations mobileDataSourceConfigurations)
throws Exception {
Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap = new HashMap<String, MobileDataSourceConfig>();
for (MobileDataSourceConfig mobileDataSourceConfig : mobileDataSourceConfigurations
.getMobileDataSourceConfigs()) {
mobileDataSourceConfigMap.put(mobileDataSourceConfig.getType(), mobileDataSourceConfig);
}
return mobileDataSourceConfigMap;
}
@Override
public MobileDataSourceConfigurations marshal(Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap)
throws Exception {
MobileDataSourceConfigurations mobileDataSourceConfigurations = new MobileDataSourceConfigurations();
mobileDataSourceConfigurations.setMobileDataSourceConfigs(
(List<MobileDataSourceConfig>) mobileDataSourceConfigMap.values());
return mobileDataSourceConfigurations;
}
}

@ -18,15 +18,18 @@
package org.wso2.carbon.device.mgt.mobile.config.datasource; 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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
/** /**
* Class for holding data source configuration in mobile-config.xml at parsing with JAXB. * 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 JNDILookupDefinition jndiLookupDefinition;
private String type;
@XmlElement(name = "JndiLookupDefinition", nillable = true) @XmlElement(name = "JndiLookupDefinition", nillable = true)
public JNDILookupDefinition getJndiLookupDefinition() { public JNDILookupDefinition getJndiLookupDefinition() {
@ -37,4 +40,12 @@ import javax.xml.bind.annotation.XmlRootElement;
this.jndiLookupDefinition = jndiLookupDefinition; this.jndiLookupDefinition = jndiLookupDefinition;
} }
@XmlAttribute(name = "type")
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
} }

@ -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<MobileDataSourceConfig> mobileDataSourceConfigs;
public List<MobileDataSourceConfig> getMobileDataSourceConfigs() {
return mobileDataSourceConfigs;
}
public void setMobileDataSourceConfigs(List<MobileDataSourceConfig> mobileDataSourceConfigs) {
this.mobileDataSourceConfigs = mobileDataSourceConfigs;
}
}

@ -21,41 +21,45 @@ package org.wso2.carbon.device.mgt.mobile.dao;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.DataSourceNotAvailableException;
import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; 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.config.datasource.MobileDataSourceConfig;
import org.wso2.carbon.device.mgt.mobile.dao.impl.*; 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.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementServiceComponent;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Factory class used to create MobileDeviceManagement related DAO objects. * Factory class used to create MobileDeviceManagement related DAO objects.
*/ */
public class MobileDeviceManagementDAOFactory { public class MobileDeviceManagementDAOFactory {
private static DataSource dataSource;
private static MobileDataSourceConfig dsConfig;
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class); private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
private static Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap;
private static Map<String, DataSource> dataSourceMap;
private String pluginProvider;
private DataSource dataSource;
private static boolean isInitialized; private static boolean isInitialized;
public MobileDeviceManagementDAOFactory(String pluginProvider) {
this.pluginProvider = pluginProvider;
this.dataSource = dataSourceMap.get(pluginProvider);
}
public static void init() throws DeviceManagementException { public static void init() throws DeviceManagementException {
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(dsConfig);
dataSourceMap = new HashMap<String, DataSource>();
DataSource dataSource;
for (String pluginType : mobileDataSourceConfigMap.keySet()) {
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get
(pluginType));
dataSourceMap.put(pluginType, dataSource);
}
isInitialized = true; 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()); jndiProperties.put(prop.getName(), prop.getValue());
} }
dataSource = dataSource =
MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); MobileDeviceManagementDAOUtil
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
} else { } else {
dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); dataSource = MobileDeviceManagementDAOUtil
.lookupDataSource(jndiConfig.getJndiName(), null);
} }
} }
return dataSource; return dataSource;
} }
public static MobileDeviceDAO getMobileDeviceDAO() { public MobileDeviceDAO getMobileDeviceDAO() {
assertDataSourceInitialization();
return new MobileDeviceDAOImpl(dataSource); return new MobileDeviceDAOImpl(dataSource);
} }
public static MobileOperationDAO getMobileOperationDAO() { public MobileOperationDAO getMobileOperationDAO() {
assertDataSourceInitialization();
return new MobileOperationDAOImpl(dataSource); return new MobileOperationDAOImpl(dataSource);
} }
public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { public MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
assertDataSourceInitialization();
return new MobileOperationPropertyDAOImpl(dataSource); return new MobileOperationPropertyDAOImpl(dataSource);
} }
public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
assertDataSourceInitialization();
return new MobileDeviceOperationMappingDAOImpl(dataSource); return new MobileDeviceOperationMappingDAOImpl(dataSource);
} }
public static MobileFeatureDAO getFeatureDAO() { public MobileFeatureDAO getFeatureDAO() {
assertDataSourceInitialization();
return new MobileFeatureDAOImpl(dataSource); return new MobileFeatureDAOImpl(dataSource);
} }
public static MobileFeaturePropertyDAO getFeaturePropertyDAO() { public MobileFeaturePropertyDAO getFeaturePropertyDAO() {
assertDataSourceInitialization();
return new MobileFeaturePropertyDAOImpl(dataSource); return new MobileFeaturePropertyDAOImpl(dataSource);
} }
public static void setDatSourceConfig(MobileDataSourceConfig dsConfig) { public MobileDataSourceConfig getMobileDeviceManagementConfig(String pluginType) {
MobileDeviceManagementDAOFactory.dsConfig = dsConfig; return mobileDataSourceConfigMap.get(pluginType);
} }
public static DataSource getDataSource() { public static Map<String, MobileDataSourceConfig> getMobileDataSourceConfigMap() {
return dataSource; return mobileDataSourceConfigMap;
}
public static void setMobileDataSourceConfigMap(Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap) {
MobileDeviceManagementDAOFactory.mobileDataSourceConfigMap = mobileDataSourceConfigMap;
}
public DataSource getDataSource(String type) {
return dataSourceMap.get(type);
}
public static Map<String, DataSource> getDataSourceMap() {
return dataSourceMap;
} }
private static void assertDataSourceInitialization() { private static void assertDataSourceInitialization() {
@ -137,5 +149,4 @@ public class MobileDeviceManagementDAOFactory {
"is not initialized"); "is not initialized");
} }
} }
} }

@ -20,12 +20,12 @@ package org.wso2.carbon.device.mgt.mobile.impl.android;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; 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.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import org.wso2.carbon.device.mgt.common.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -35,12 +35,18 @@ import java.util.List;
*/ */
public class AndroidDeviceManager implements DeviceManager { public class AndroidDeviceManager implements DeviceManager {
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
private static final Log log = LogFactory.getLog(AndroidDeviceManager.class); private static final Log log = LogFactory.getLog(AndroidDeviceManager.class);
@Override public AndroidDeviceManager() {
public String getProviderType() { mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
} }
@Override
public String getProviderType() {
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
}
@Override @Override
public FeatureManager getFeatureManager() { public FeatureManager getFeatureManager() {
@ -48,157 +54,157 @@ public class AndroidDeviceManager implements DeviceManager {
} }
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
} }
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
mobileDevice); mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while enrolling the Android device : " + String msg = "Error while enrolling the Android device : " +
device.getDeviceIdentifier(); device.getDeviceIdentifier();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Modifying the Android device enrollment data"); log.debug("Modifying the Android device enrollment data");
} }
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice); .updateMobileDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while updating the enrollment of the Android device : " + String msg = "Error while updating the enrollment of the Android device : " +
device.getDeviceIdentifier(); device.getDeviceIdentifier();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@Override @Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean status; boolean status;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Android device : " + deviceId); log.debug("Dis-enrolling Android device : " + deviceId);
} }
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.deleteMobileDevice(deviceId.getId()); .deleteMobileDevice(deviceId.getId());
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while removing the Android device : " + deviceId.getId(); String msg = "Error while removing the Android device : " + deviceId.getId();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean isEnrolled = false; boolean isEnrolled = false;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Checking the enrollment of Android device : " + deviceId.getId()); log.debug("Checking the enrollment of Android device : " + deviceId.getId());
} }
MobileDevice mobileDevice = MobileDevice mobileDevice =
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId()); deviceId.getId());
if (mobileDevice != null) { if (mobileDevice != null) {
isEnrolled = true; isEnrolled = true;
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while checking the enrollment status of Android device : " + String msg = "Error while checking the enrollment status of Android device : " +
deviceId.getId(); deviceId.getId();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return isEnrolled; return isEnrolled;
} }
@Override @Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return true; return true;
} }
@Override @Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException { throws DeviceManagementException {
return true; return true;
} }
@Override @Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device; Device device;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the details of Android device : " + deviceId.getId()); log.debug("Getting the details of Android device : " + deviceId.getId());
} }
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getMobileDevice(deviceId.getId()); getMobileDevice(deviceId.getId());
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching the Android device : " + deviceId.getId(); String msg = "Error while fetching the Android device : " + deviceId.getId();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return device; return device;
} }
@Override @Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException { throws DeviceManagementException {
return true; return true;
} }
@Override @Override
public boolean updateDeviceInfo(Device device) throws DeviceManagementException { public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("updating the details of Android device : " + device.getDeviceIdentifier()); log.debug("updating the details of Android device : " + device.getDeviceIdentifier());
} }
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice); .updateMobileDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); String msg = "Error while updating the Android device : " + device.getDeviceIdentifier();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@Override @Override
public List<Device> getAllDevices() throws DeviceManagementException { public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null; List<Device> devices = null;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Android devices"); log.debug("Fetching the details of all Android devices");
} }
List<MobileDevice> mobileDevices = List<MobileDevice> mobileDevices =
MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getAllMobileDevices(); getAllMobileDevices();
if (mobileDevices != null) { if (mobileDevices != null) {
devices = new ArrayList<Device>(); devices = new ArrayList<Device>();
for (MobileDevice mobileDevice : mobileDevices) { for (MobileDevice mobileDevice : mobileDevices) {
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
} }
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching all Android devices."; String msg = "Error while fetching all Android devices.";
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return devices; return devices;
} }
} }

@ -34,13 +34,19 @@ import java.util.List;
*/ */
public class IOSDeviceManager implements DeviceManager { 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 @Override
public String getProviderType() { public String getProviderType() {
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS; return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS;
} }
public IOSDeviceManager() {
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants
.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS);
}
@Override @Override
public FeatureManager getFeatureManager() { public FeatureManager getFeatureManager() {
return null; return null;
@ -51,7 +57,7 @@ public class IOSDeviceManager implements DeviceManager {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
mobileDevice); mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while enrolling the iOS device : " + String msg = "Error while enrolling the iOS device : " +
@ -70,7 +76,7 @@ public class IOSDeviceManager implements DeviceManager {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Modifying the iOS device enrollment data"); log.debug("Modifying the iOS device enrollment data");
} }
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice); .updateMobileDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while updating the enrollment of the iOS device : " + 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()); log.debug("Checking the enrollment of iOS device : " + deviceId.getId());
} }
MobileDevice mobileDevice = MobileDevice mobileDevice =
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId()); deviceId.getId());
if (mobileDevice != null) { if (mobileDevice != null) {
isEnrolled = true; isEnrolled = true;
@ -131,7 +137,7 @@ public class IOSDeviceManager implements DeviceManager {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the details of iOS device : " + deviceId.getId()); log.debug("Getting the details of iOS device : " + deviceId.getId());
} }
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getMobileDevice(deviceId.getId()); getMobileDevice(deviceId.getId());
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {

@ -34,6 +34,12 @@ import java.util.List;
*/ */
public class WindowsDeviceManager implements DeviceManager { 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); private static final Log log = LogFactory.getLog(WindowsDeviceManager.class);
@Override @Override
@ -97,7 +103,7 @@ public class WindowsDeviceManager implements DeviceManager {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
mobileDevice); mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while enrolling the Windows device : " + String msg = "Error while enrolling the Windows device : " +

@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* BundleActivator of MobileDeviceManagement component. * BundleActivator of MobileDeviceManagement component.
@ -58,14 +59,13 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B
} }
bundleContext.addBundleListener(this); bundleContext.addBundleListener(this);
/* Initialize the datasource configuration */ /* Initialize the data source configuration */
MobileDeviceConfigurationManager.getInstance().initConfig(); MobileDeviceConfigurationManager.getInstance().initConfig();
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
.getMobileDeviceManagementConfig(); .getMobileDeviceManagementConfig();
MobileDataSourceConfig dsConfig = Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(mobileDataSourceConfigMap);
MobileDeviceManagementDAOFactory.setDatSourceConfig(dsConfig);
androidServiceRegRef = androidServiceRegRef =
bundleContext.registerService(DeviceManager.class.getName(), bundleContext.registerService(DeviceManager.class.getName(),

@ -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.device.mgt.mobile.impl.windows.WindowsDeviceManager;
import org.wso2.carbon.ndatasource.core.DataSourceService; 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" * @scr.component name="org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementServiceComponent"
* immediate="true" * immediate="true"
@ -51,18 +54,28 @@ import org.wso2.carbon.ndatasource.core.DataSourceService;
*/ */
public class MobileDeviceManagementServiceComponent { public class MobileDeviceManagementServiceComponent {
private ServiceRegistration androidServiceRegRef; private ServiceRegistration serverStartupObserverRef;
private ServiceRegistration iOSServiceRegRef; private ServiceRegistration androidServiceRegRef;
private ServiceRegistration windowsServiceRegRef; 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) { /* Initialize the data source configuration */
if (log.isDebugEnabled()) { MobileDeviceConfigurationManager.getInstance().initConfig();
log.debug("Activating Mobile Device Management Service Component"); MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
} .getMobileDeviceManagementConfig();
try { Map<String, MobileDataSourceConfig> dsConfigMap =
BundleContext bundleContext = ctx.getBundleContext(); config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap);
MobileDeviceManagementDAOFactory.init();
String setupOption = System.getProperty("setup"); String setupOption = System.getProperty("setup");
if (setupOption != null) { if (setupOption != null) {
@ -72,8 +85,11 @@ public class MobileDeviceManagementServiceComponent {
"to begin"); "to begin");
} }
try { try {
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema( Map<String, DataSource> dataSourceMap = MobileDeviceManagementDAOFactory.getDataSourceMap();
MobileDeviceManagementDAOFactory.getDataSource()); for (DataSource dataSource : dataSourceMap.values()) {
MobileDeviceManagementDAOUtil
.setupMobileDeviceManagementSchema(dataSource);
}
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Exception occurred while initializing mobile device management database schema", e); log.error("Exception occurred while initializing mobile device management database schema", e);
} }
@ -108,41 +124,24 @@ public class MobileDeviceManagementServiceComponent {
if (windowsServiceRegRef != null) { if (windowsServiceRegRef != null) {
windowsServiceRegRef.unregister(); windowsServiceRegRef.unregister();
} }
if (log.isDebugEnabled()) {
if (log.isDebugEnabled()) { log.debug(
log.debug( "Mobile Device Management Service Component has been successfully de-activated");
"Mobile Device Management Service Component has been successfully de-activated"); }
} } catch (Throwable e) {
} catch (Throwable e) { log.error("Error occurred while de-activating Mobile Device Management bundle", e);
log.error("Error occurred while de-activating Mobile Device Management bundle", e); }
} }
}
protected void setDataSourceService(DataSourceService dataSourceService) { protected void setDataSourceService(DataSourceService dataSourceService) {
/* This is to avoid mobile device management component getting initialized before the underlying datasources /* This is to avoid mobile device management component getting initialized before the underlying datasources
are registered */ are registered */
try { if (log.isDebugEnabled()) {
initConfigs(); log.debug("Data source service set to mobile service component");
} catch (DeviceManagementException e) {
log.error("Error occurred while initializing mobile device management repository datasource", e);
} }
} }
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) { protected void unsetDataSourceService(DataSourceService dataSourceService) {
//do nothing //do nothing
} }
} }

@ -19,24 +19,23 @@
<MobileDeviceMgtConfiguration> <MobileDeviceMgtConfiguration>
<ManagementRepository> <ManagementRepository>
<DataSourceConfiguration> <DataSourceConfigurations>
<JndiLookupDefinition> <DataSourceConfiguration type="ios">
<Name>jdbc/MobileDM_DS</Name> <JndiLookupDefinition>
</JndiLookupDefinition> <Name>jdbc/MobileIOSDM_DS</Name>
</DataSourceConfiguration> </JndiLookupDefinition>
</DataSourceConfiguration>
<DataSourceConfiguration type="android">
<JndiLookupDefinition>
<Name>jdbc/MobileAndroidDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
<DataSourceConfiguration type="windows">
<JndiLookupDefinition>
<Name>jdbc/MobileWindowsDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</DataSourceConfigurations>
</ManagementRepository> </ManagementRepository>
<APIPublisher>
<APIs>
<MalformedAPI>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</MalformedAPI>
</APIs>
</APIPublisher>
</MobileDeviceMgtConfiguration> </MobileDeviceMgtConfiguration>

@ -19,13 +19,24 @@
<MobileDeviceMgtConfiguration> <MobileDeviceMgtConfiguration>
<ManagementRepository> <ManagementRepository>
<DataSourceConfiguration> <DataSourceConfigurations>
<DataSourceConfiguration type="ios">
<JndiLookupDefinition> <JndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name> <Name>jdbc/MobileIOSDM_DS</Name>
</JndiLookupDefinition> </JndiLookupDefinition>
</DataSourceConfiguration> </DataSourceConfiguration>
<DataSourceConfiguration type="android">
<JndiLookupDefinition>
<Name>jdbc/MobileAndroidDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
<DataSourceConfiguration type="windows">
<JndiLookupDefinition>
<Name>jdbc/MobileWindowsDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</DataSourceConfigurations>
</ManagementRepository> </ManagementRepository>
<APIPublisher> <APIPublisher>
<APIs> <APIs>
<API> <API>

Loading…
Cancel
Save