mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge branch 'master' of github.com:wso2/carbon-device-mgt-plugins
This commit is contained in:
commit
36aad88ce0
@ -20,18 +20,16 @@ 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.mobile.DataSourceNotAvailableException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||||
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.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
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.
|
||||||
@ -39,22 +37,11 @@ import java.util.Map;
|
|||||||
public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactoryInterface {
|
public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactoryInterface {
|
||||||
|
|
||||||
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 static boolean isInitialized;
|
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
protected static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
|
|
||||||
public static void init() throws MobileDeviceMgtPluginException {
|
public static void init(MobileDataSourceConfig mobileDataSourceConfig) throws MobileDeviceMgtPluginException {
|
||||||
|
dataSource = resolveDataSource(mobileDataSourceConfig);
|
||||||
dataSourceMap = new HashMap<String, DataSource>();
|
|
||||||
DataSource dataSource;
|
|
||||||
for (String pluginType : mobileDataSourceConfigMap.keySet()) {
|
|
||||||
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get
|
|
||||||
(pluginType));
|
|
||||||
dataSourceMap.put(pluginType, dataSource);
|
|
||||||
}
|
|
||||||
isInitialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,29 +80,6 @@ public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceMa
|
|||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, MobileDataSourceConfig> getMobileDataSourceConfigMap() {
|
|
||||||
return mobileDataSourceConfigMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setMobileDataSourceConfigMap(Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap) {
|
|
||||||
MobileDeviceManagementDAOFactory.mobileDataSourceConfigMap = mobileDataSourceConfigMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DataSource getDataSource(String type) {
|
|
||||||
return dataSourceMap.get(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, DataSource> getDataSourceMap() {
|
|
||||||
return dataSourceMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void assertDataSourceInitialization() {
|
|
||||||
if (!isInitialized) {
|
|
||||||
throw new DataSourceNotAvailableException("Mobile device management metadata repository data source " +
|
|
||||||
"is not initialized");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void beginTransaction() throws MobileDeviceManagementDAOException {
|
public static void beginTransaction() throws MobileDeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
Connection conn = dataSource.getConnection();
|
Connection conn = dataSource.getConnection();
|
||||||
@ -137,6 +101,7 @@ public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceMa
|
|||||||
}
|
}
|
||||||
return currentConnection.get();
|
return currentConnection.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void commitTransaction() throws MobileDeviceManagementDAOException {
|
public static void commitTransaction() throws MobileDeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
@ -151,7 +116,7 @@ public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceMa
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,11 +64,18 @@ public class AndroidDeviceManager implements DeviceMgtService {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
|
MobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
||||||
mobileDevice);
|
mobileDevice);
|
||||||
|
MobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
String msg = "Error while enrolling the Android device : " +
|
try {
|
||||||
device.getDeviceIdentifier();
|
MobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
||||||
|
log.warn(msg, mobileDAOEx);
|
||||||
|
}
|
||||||
|
String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
@ -83,9 +90,17 @@ public class AndroidDeviceManager implements DeviceMgtService {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Modifying the Android device enrollment data");
|
log.debug("Modifying the Android device enrollment data");
|
||||||
}
|
}
|
||||||
|
MobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.updateMobileDevice(mobileDevice);
|
.updateMobileDevice(mobileDevice);
|
||||||
|
MobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
MobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
||||||
|
log.warn(msg, mobileDAOEx);
|
||||||
|
}
|
||||||
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);
|
||||||
@ -101,9 +116,17 @@ public class AndroidDeviceManager implements DeviceMgtService {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Dis-enrolling Android device : " + deviceId);
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
||||||
}
|
}
|
||||||
|
MobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.deleteMobileDevice(deviceId.getId());
|
.deleteMobileDevice(deviceId.getId());
|
||||||
|
MobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
MobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
||||||
|
log.warn(msg, mobileDAOEx);
|
||||||
|
}
|
||||||
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);
|
||||||
@ -177,9 +200,17 @@ public class AndroidDeviceManager implements DeviceMgtService {
|
|||||||
log.debug(
|
log.debug(
|
||||||
"updating the details of Android device : " + device.getDeviceIdentifier());
|
"updating the details of Android device : " + device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
|
MobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.updateMobileDevice(mobileDevice);
|
.updateMobileDevice(mobileDevice);
|
||||||
|
MobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
MobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
||||||
|
log.warn(msg, mobileDAOEx);
|
||||||
|
}
|
||||||
String msg =
|
String msg =
|
||||||
"Error while updating the Android device : " + device.getDeviceIdentifier();
|
"Error while updating the Android device : " + device.getDeviceIdentifier();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
|
|||||||
@ -70,11 +70,6 @@ public class AndroidFeatureManager implements FeatureManager {
|
|||||||
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
|
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
|
||||||
return feature;
|
return feature;
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
|
||||||
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
|
||||||
} catch (MobileDeviceManagementDAOException e1) {
|
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
|
||||||
}
|
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,13 +85,8 @@ public class AndroidFeatureManager implements FeatureManager {
|
|||||||
}
|
}
|
||||||
return featureList;
|
return featureList;
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " +
|
||||||
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
"Android platform", e);
|
||||||
} catch (MobileDeviceManagementDAOException e1) {
|
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
|
||||||
}
|
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"features registered for Android platform", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,16 +32,10 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory
|
|||||||
implements MobileDeviceManagementDAOFactoryInterface {
|
implements MobileDeviceManagementDAOFactoryInterface {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(AndroidDAOFactory.class);
|
private static final Log log = LogFactory.getLog(AndroidDAOFactory.class);
|
||||||
private static DataSource dataSource;
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
dataSource = MobileDeviceManagementDAOFactory.getDataSource(DeviceManagementConstants.MobileDeviceTypes.
|
|
||||||
MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileDeviceDAO getMobileDeviceDAO() {
|
public MobileDeviceDAO getMobileDeviceDAO() {
|
||||||
return new AndroidDeviceDAOImpl(dataSource);
|
return new AndroidDeviceDAOImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,7 +54,7 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public MobileFeatureDAO getMobileFeatureDao() {
|
@Override public MobileFeatureDAO getMobileFeatureDao() {
|
||||||
return new AndroidFeatureDAOImpl(dataSource);
|
return new AndroidFeatureDAOImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
public MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
|
||||||
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.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
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.impl.android.util.AndroidPluginConstants;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants;
|
||||||
@ -42,28 +43,24 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class);
|
private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class);
|
||||||
|
|
||||||
public AndroidDeviceDAOImpl(DataSource dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileDevice getMobileDevice(String mblDeviceId)
|
public MobileDevice getMobileDevice(String mblDeviceId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileDevice mobileDevice = null;
|
MobileDevice mobileDevice = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
|
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
|
||||||
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" +
|
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" +
|
||||||
" FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
" FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, mblDeviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mobileDevice = new MobileDevice();
|
mobileDevice = new MobileDevice();
|
||||||
@ -98,7 +95,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
MobileDeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
return mobileDevice;
|
return mobileDevice;
|
||||||
@ -111,7 +109,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"INSERT INTO AD_DEVICE(ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " +
|
"INSERT INTO AD_DEVICE(ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " +
|
||||||
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " +
|
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " +
|
||||||
@ -154,7 +152,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -166,7 +164,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " +
|
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " +
|
||||||
"MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " +
|
"MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " +
|
||||||
@ -209,7 +207,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -221,7 +219,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
"DELETE FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
@ -239,7 +237,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -247,18 +245,21 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
@Override
|
@Override
|
||||||
public List<MobileDevice> getAllMobileDevices()
|
public List<MobileDevice> getAllMobileDevices()
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
MobileDevice mobileDevice;
|
MobileDevice mobileDevice;
|
||||||
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
|
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
|
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
|
||||||
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " +
|
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " +
|
||||||
"FROM AD_DEVICE";
|
"FROM AD_DEVICE";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mobileDevice = new MobileDevice();
|
mobileDevice = new MobileDevice();
|
||||||
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants.
|
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants.
|
||||||
@ -292,18 +293,9 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
MobileDeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
|
||||||
try {
|
|
||||||
return dataSource.getConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
|
||||||
"management metadata repository datasource";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ 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.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
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.MobileFeatureDAO;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||||
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.dto.MobileFeature;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
@ -38,21 +39,19 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
private static final Log log = LogFactory.getLog(AndroidFeatureDAOImpl.class);
|
private static final Log log = LogFactory.getLog(AndroidFeatureDAOImpl.class);
|
||||||
|
|
||||||
public AndroidFeatureDAOImpl(DataSource dataSource) {
|
public AndroidFeatureDAOImpl() {
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, mobileFeature.getCode());
|
stmt.setString(1, mobileFeature.getCode());
|
||||||
@ -66,7 +65,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
"Error occurred while adding android feature '" +
|
"Error occurred while adding android feature '" +
|
||||||
mobileFeature.getName() + "' into the metadata repository", e);
|
mobileFeature.getName() + "' into the metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -77,7 +76,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE AD_FEATURE SET NAME = ?, DESCRIPTION = ?" +
|
"UPDATE AD_FEATURE SET NAME = ?, DESCRIPTION = ?" +
|
||||||
"WHERE CODE = ?";
|
"WHERE CODE = ?";
|
||||||
@ -101,18 +100,19 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new AndroidFeatureManagementDAOException(msg, e);
|
throw new AndroidFeatureManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "DELETE FROM AD_FEATURE WHERE ID = ?";
|
String sql = "DELETE FROM AD_FEATURE WHERE ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, mblFeatureId);
|
stmt.setInt(1, mblFeatureId);
|
||||||
@ -123,7 +123,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
"Error occurred while deleting android feature '" +
|
"Error occurred while deleting android feature '" +
|
||||||
mblFeatureId + "' from Android database.", e);
|
mblFeatureId + "' from Android database.", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
|
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, mblFeatureCode);
|
stmt.setString(1, mblFeatureCode);
|
||||||
@ -146,7 +146,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
"Error occurred while deleting android feature '" +
|
"Error occurred while deleting android feature '" +
|
||||||
mblFeatureCode + "' from Android database.", e);
|
mblFeatureCode + "' from Android database.", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, mblFeatureId);
|
stmt.setInt(1, mblFeatureId);
|
||||||
@ -181,7 +181,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
"Error occurred while retrieving android feature '" +
|
"Error occurred while retrieving android feature '" +
|
||||||
mblFeatureId + "' from the Android database.", e);
|
mblFeatureId + "' from the Android database.", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
MobileDeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +194,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, mblFeatureCode);
|
stmt.setString(1, mblFeatureCode);
|
||||||
@ -216,7 +217,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
"Error occurred while retrieving android feature '" +
|
"Error occurred while retrieving android feature '" +
|
||||||
mblFeatureCode + "' from the Android database.", e);
|
mblFeatureCode + "' from the Android database.", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
MobileDeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,13 +230,14 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
List<MobileFeature> features = new ArrayList<MobileFeature>();
|
List<MobileFeature> features = new ArrayList<MobileFeature>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
@ -256,18 +259,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " +
|
throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " +
|
||||||
"android features from the android database.", e);
|
"android features from the android database.", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
MobileDeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
|
||||||
|
|
||||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
|
||||||
try {
|
|
||||||
return dataSource.getConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while obtaining a connection from the Android mobile device " +
|
|
||||||
"management metadata repository datasource";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,9 +24,6 @@ import org.wso2.carbon.device.mgt.mobile.dao.*;
|
|||||||
public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
|
public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
|
||||||
implements MobileDeviceManagementDAOFactoryInterface {
|
implements MobileDeviceManagementDAOFactoryInterface {
|
||||||
|
|
||||||
public static void init(MobileDataSourceConfig config) {
|
|
||||||
dataSource = resolveDataSource(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileDeviceDAO getMobileDeviceDAO() {
|
public MobileDeviceDAO getMobileDeviceDAO() {
|
||||||
|
|||||||
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.internal;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.osgi.framework.*;
|
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.DataSourceListener;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager;
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
|
||||||
|
|
||||||
private ServiceRegistration androidServiceRegRef;
|
|
||||||
private ServiceRegistration windowsServiceRegRef;
|
|
||||||
|
|
||||||
private static List<DataSourceListener> dataSourceListeners =
|
|
||||||
new ArrayList<DataSourceListener>();
|
|
||||||
|
|
||||||
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT =
|
|
||||||
"org.wso2.carbon.ndatasource.core";
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(BundleContext bundleContext) throws Exception {
|
|
||||||
try {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Activating Mobile Device Management Service bundle");
|
|
||||||
}
|
|
||||||
bundleContext.addBundleListener(this);
|
|
||||||
|
|
||||||
/* Initialize the data source configuration */
|
|
||||||
MobileDeviceConfigurationManager.getInstance().initConfig();
|
|
||||||
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
|
||||||
.getMobileDeviceManagementConfig();
|
|
||||||
Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap =
|
|
||||||
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
|
|
||||||
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(mobileDataSourceConfigMap);
|
|
||||||
|
|
||||||
androidServiceRegRef =
|
|
||||||
bundleContext.registerService(DeviceManager.class.getName(),
|
|
||||||
new AndroidDeviceManager(), null);
|
|
||||||
windowsServiceRegRef =
|
|
||||||
bundleContext.registerService(DeviceManager.class.getName(),
|
|
||||||
new WindowsDeviceManager(), null);
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Mobile Device Management Service bundle is activated");
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
log.error("Error occurred while activating Mobile Device Management bundle", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop(BundleContext bundleContext) throws Exception {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Deactivating Mobile Device Management Service");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
androidServiceRegRef.unregister();
|
|
||||||
windowsServiceRegRef.unregister();
|
|
||||||
|
|
||||||
bundleContext.removeBundleListener(this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
log.error("Error occurred while de-activating Mobile Device Management bundle", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bundleChanged(BundleEvent bundleEvent) {
|
|
||||||
int eventType = bundleEvent.getType();
|
|
||||||
String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName();
|
|
||||||
|
|
||||||
if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) &&
|
|
||||||
eventType == BundleEvent.STARTED) {
|
|
||||||
for (DataSourceListener listener : this.getDataSourceListeners()) {
|
|
||||||
listener.notifyObserver();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerDataSourceListener(DataSourceListener listener) {
|
|
||||||
dataSourceListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<DataSourceListener> getDataSourceListeners() {
|
|
||||||
return dataSourceListeners;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -26,6 +26,7 @@ import org.osgi.service.component.ComponentContext;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants;
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
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.MobileDeviceManagementConfig;
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||||
@ -34,6 +35,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
|||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager;
|
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
|
||||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -62,6 +64,7 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
|
||||||
|
|
||||||
protected void activate(ComponentContext ctx) {
|
protected void activate(ComponentContext ctx) {
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Activating Mobile Device Management Service Component");
|
log.debug("Activating Mobile Device Management Service Component");
|
||||||
}
|
}
|
||||||
@ -74,10 +77,10 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
.getMobileDeviceManagementConfig();
|
.getMobileDeviceManagementConfig();
|
||||||
Map<String, MobileDataSourceConfig> dsConfigMap =
|
Map<String, MobileDataSourceConfig> dsConfigMap =
|
||||||
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
|
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
|
||||||
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap);
|
|
||||||
MobileDeviceManagementDAOFactory.init();
|
|
||||||
|
|
||||||
AndroidDAOFactory.init();
|
AndroidDAOFactory.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes
|
||||||
|
.MOBILE_DEVICE_TYPE_ANDROID));
|
||||||
|
WindowsDAOFactory.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS));
|
||||||
|
|
||||||
String setupOption = System.getProperty("setup");
|
String setupOption = System.getProperty("setup");
|
||||||
if (setupOption != null) {
|
if (setupOption != null) {
|
||||||
@ -87,8 +90,9 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
"to begin");
|
"to begin");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Map<String, DataSource> dataSourceMap = MobileDeviceManagementDAOFactory.getDataSourceMap();
|
DataSource dataSource;
|
||||||
for (DataSource dataSource : dataSourceMap.values()) {
|
for (MobileDataSourceConfig dataSourceConfig : dsConfigMap.values()) {
|
||||||
|
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(dataSourceConfig);
|
||||||
MobileDeviceManagementDAOUtil
|
MobileDeviceManagementDAOUtil
|
||||||
.setupMobileDeviceManagementSchema(dataSource);
|
.setupMobileDeviceManagementSchema(dataSource);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user