mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merging left over changes from MDM. Most of the changes are from @harshahL.
This commit is contained in:
parent
bc93ff08a4
commit
99f7cd25e8
@ -19,81 +19,108 @@ 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.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.MobileDeviceManagementBundleActivator;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class used to create MobileDeviceManagement related DAO objects.
|
* Factory class used to create MobileDeviceManagement related DAO objects.
|
||||||
*/
|
*/
|
||||||
public class MobileDeviceManagementDAOFactory implements DataSourceListener {
|
public class MobileDeviceManagementDAOFactory {
|
||||||
|
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static MobileDataSourceConfig mobileDataSourceConfig;
|
private static MobileDataSourceConfig mobileDataSourceConfig;
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
|
||||||
|
|
||||||
public MobileDeviceManagementDAOFactory() {
|
public MobileDeviceManagementDAOFactory() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() throws DeviceManagementException {
|
public static void init() {
|
||||||
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
try {
|
||||||
if (dataSource != null) {
|
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig);
|
||||||
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
} catch (DeviceManagementException e) {
|
||||||
} else {
|
log.error("Exception occurred while initializing the mobile datasource.",e);
|
||||||
MobileDeviceManagementBundleActivator.registerDataSourceListener(this);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static MobileDeviceDAO getMobileDeviceDAO() {
|
/**
|
||||||
return new MobileDeviceDAOImpl(dataSource);
|
* Resolve data source from the data source definition.
|
||||||
}
|
*
|
||||||
|
* @param config Mobile data source configuration
|
||||||
|
* @return data source resolved from the data source definition
|
||||||
|
*/
|
||||||
|
private static DataSource resolveDataSource(MobileDataSourceConfig config)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
DataSource dataSource = null;
|
||||||
|
if (config == null) {
|
||||||
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
||||||
|
"is null and thus, is not initialized");
|
||||||
|
}
|
||||||
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
|
||||||
|
if (jndiConfig != null) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
||||||
|
"Lookup Definition");
|
||||||
|
}
|
||||||
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
||||||
|
jndiConfig.getJndiProperties();
|
||||||
|
if (jndiPropertyList != null) {
|
||||||
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
||||||
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
|
}
|
||||||
|
dataSource =
|
||||||
|
MobileDeviceManagementDAOUtil
|
||||||
|
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||||
|
} else {
|
||||||
|
dataSource = MobileDeviceManagementDAOUtil
|
||||||
|
.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
public static MobileOperationDAO getMobileOperationDAO() {
|
public static MobileDeviceDAO getMobileDeviceDAO() {
|
||||||
return new MobileOperationDAOImpl(dataSource);
|
return new MobileDeviceDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
public static MobileOperationDAO getMobileOperationDAO() {
|
||||||
return new MobileOperationPropertyDAOImpl(dataSource);
|
return new MobileOperationDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() {
|
public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
||||||
return new MobileDeviceOperationDAOImpl(dataSource);
|
return new MobileOperationPropertyDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FeatureDAO getFeatureDAO() {
|
public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() {
|
||||||
return new FeatureDAOImpl(dataSource);
|
return new MobileDeviceOperationDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FeaturePropertyDAO getFeaturePropertyDAO() {
|
public static FeatureDAO getFeatureDAO() {
|
||||||
return new FeaturePropertyDAOImpl(dataSource);
|
return new FeatureDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MobileDataSourceConfig getMobileDeviceManagementConfig() {
|
public static FeaturePropertyDAO getFeaturePropertyDAO() {
|
||||||
return mobileDataSourceConfig;
|
return new FeaturePropertyDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMobileDataSourceConfig(
|
public static MobileDataSourceConfig getMobileDeviceManagementConfig() {
|
||||||
MobileDataSourceConfig mobileDataSourceConfig) {
|
return mobileDataSourceConfig;
|
||||||
MobileDeviceManagementDAOFactory.mobileDataSourceConfig =
|
}
|
||||||
mobileDataSourceConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DataSource getDataSource() {
|
public static void setMobileDataSourceConfig(
|
||||||
return dataSource;
|
MobileDataSourceConfig mobileDataSourceConfig) {
|
||||||
}
|
MobileDeviceManagementDAOFactory.mobileDataSourceConfig =
|
||||||
|
mobileDataSourceConfig;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public static DataSource getDataSource() {
|
||||||
public void notifyObserver() {
|
return dataSource;
|
||||||
try {
|
}
|
||||||
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
}
|
||||||
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
log.error("Error occurred while resolving mobile device management metadata repository data source", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -52,7 +52,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"INSERT INTO MBL_DEVICE_OPERATION(DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)";
|
"INSERT INTO MBL_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
stmt.setString(1, deviceOperation.getDeviceId());
|
stmt.setString(1, deviceOperation.getDeviceId());
|
||||||
@ -86,7 +86,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE MBL_DEVICE_OPERATION SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setLong(1, deviceOperation.getSentDate());
|
stmt.setLong(1, deviceOperation.getSentDate());
|
||||||
stmt.setLong(2, deviceOperation.getReceivedDate());
|
stmt.setLong(2, deviceOperation.getReceivedDate());
|
||||||
@ -117,7 +117,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
"DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, deviceId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
@ -146,7 +146,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, deviceId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
@ -181,7 +181,7 @@ public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ?";
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, deviceId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
|
|||||||
@ -138,11 +138,13 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setInt(1, operation.getOperationId());
|
stmt.setInt(1, operationId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
operation = new MobileOperation();
|
operation = new MobileOperation();
|
||||||
operation.setOperationId(resultSet.getInt(1));
|
operation.setOperationId(resultSet.getInt(1));
|
||||||
|
operation.setFeatureCode(resultSet.getString(2));
|
||||||
|
operation.setCreatedDate(resultSet.getLong(3));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
mobileDeviceOperation.setDeviceId(deviceIdentifier.getId());
|
mobileDeviceOperation.setDeviceId(deviceIdentifier.getId());
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
||||||
.addMobileDeviceOperation(
|
.addMobileDeviceOperation(
|
||||||
new MobileDeviceOperation());
|
mobileDeviceOperation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
@ -75,6 +75,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
List<MobileDeviceOperation> mobileDeviceOperations = null;
|
List<MobileDeviceOperation> mobileDeviceOperations = null;
|
||||||
|
List<MobileOperationProperty> operationProperties = null;
|
||||||
MobileOperation mobileOperation = null;
|
MobileOperation mobileOperation = null;
|
||||||
try {
|
try {
|
||||||
mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
||||||
@ -88,6 +89,11 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
||||||
.getMobileOperation(
|
.getMobileOperation(
|
||||||
operationId);
|
operationId);
|
||||||
|
operationProperties =
|
||||||
|
MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
||||||
|
.getAllMobileOperationPropertiesOfOperation(
|
||||||
|
operationId);
|
||||||
|
mobileOperation.setProperties(operationProperties);
|
||||||
operations.add(MobileDeviceManagementUtil
|
operations.add(MobileDeviceManagementUtil
|
||||||
.convertMobileOperationToOperation(mobileOperation));
|
.convertMobileOperationToOperation(mobileOperation));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager
|
|||||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
||||||
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.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService;
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService;
|
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService;
|
||||||
@ -54,112 +55,134 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MobileDeviceManagementServiceComponent {
|
public class MobileDeviceManagementServiceComponent {
|
||||||
|
|
||||||
private ServiceRegistration androidServiceRegRef;
|
private ServiceRegistration androidServiceRegRef;
|
||||||
private ServiceRegistration iOSServiceRegRef;
|
private ServiceRegistration iOSServiceRegRef;
|
||||||
private ServiceRegistration windowsServiceRegRef;
|
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) {
|
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");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
BundleContext bundleContext = ctx.getBundleContext();
|
BundleContext bundleContext = ctx.getBundleContext();
|
||||||
|
|
||||||
/* Initialize the datasource configuration */
|
/* Initialize the datasource configuration */
|
||||||
MobileDeviceConfigurationManager.getInstance().initConfig();
|
MobileDeviceConfigurationManager.getInstance().initConfig();
|
||||||
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
||||||
.getMobileDeviceManagementConfig();
|
.getMobileDeviceManagementConfig();
|
||||||
MobileDataSourceConfig dsConfig =
|
MobileDataSourceConfig dsConfig =
|
||||||
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
||||||
|
|
||||||
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
||||||
|
MobileDeviceManagementDAOFactory.init();
|
||||||
|
String setupOption = System.getProperty("setup");
|
||||||
|
if (setupOption != null) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(
|
||||||
|
"-Dsetup is enabled. Mobile Device management repository schema initialization is about " +
|
||||||
|
"to begin");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
|
||||||
|
MobileDeviceManagementDAOFactory.getDataSource());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(
|
||||||
|
"Exception occurred while initializing mobile device management database schema",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
androidServiceRegRef =
|
androidServiceRegRef =
|
||||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||||
new AndroidDeviceManagerService(), null);
|
new AndroidDeviceManagerService(), null);
|
||||||
iOSServiceRegRef =
|
iOSServiceRegRef =
|
||||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||||
new IOSDeviceManagerService(), null);
|
new IOSDeviceManagerService(), null);
|
||||||
windowsServiceRegRef =
|
windowsServiceRegRef =
|
||||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||||
new WindowsDeviceManagerService(), null);
|
new WindowsDeviceManagerService(), null);
|
||||||
|
|
||||||
/* Initialize all API configurations with corresponding API Providers */
|
/* Initialize all API configurations with corresponding API Providers */
|
||||||
this.initAPIConfigs();
|
this.initAPIConfigs();
|
||||||
/* Publish all mobile device management related JAX-RS services as APIs */
|
/* Publish all mobile device management related JAX-RS services as APIs */
|
||||||
this.publishAPIs();
|
this.publishAPIs();
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Mobile Device Management Service Component has been successfully activated");
|
log.debug(
|
||||||
}
|
"Mobile Device Management Service Component has been successfully activated");
|
||||||
} catch (Throwable e) {
|
}
|
||||||
log.error("Error occurred while activating Mobile Device Management Service Component", e);
|
} catch (Throwable e) {
|
||||||
}
|
log.error("Error occurred while activating Mobile Device Management Service Component",
|
||||||
}
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void deactivate(ComponentContext ctx) {
|
protected void deactivate(ComponentContext ctx) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("De-activating Mobile Device Management Service Component");
|
log.debug("De-activating Mobile Device Management Service Component");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
BundleContext bundleContext = ctx.getBundleContext();
|
BundleContext bundleContext = ctx.getBundleContext();
|
||||||
|
|
||||||
androidServiceRegRef.unregister();
|
androidServiceRegRef.unregister();
|
||||||
iOSServiceRegRef.unregister();
|
iOSServiceRegRef.unregister();
|
||||||
windowsServiceRegRef.unregister();
|
windowsServiceRegRef.unregister();
|
||||||
|
|
||||||
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
||||||
services */
|
services */
|
||||||
this.removeAPIs();
|
this.removeAPIs();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Mobile Device Management Service Component has been successfully de-activated");
|
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);
|
} catch (Throwable e) {
|
||||||
}
|
log.error("Error occurred while de-activating Mobile Device Management bundle", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initAPIConfigs() throws DeviceManagementException {
|
private void initAPIConfigs() throws DeviceManagementException {
|
||||||
List<APIConfig> apiConfigs =
|
List<APIConfig> apiConfigs =
|
||||||
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||||
getApiPublisherConfig().getAPIs();
|
getApiPublisherConfig().getAPIs();
|
||||||
for (APIConfig apiConfig : apiConfigs) {
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
try {
|
try {
|
||||||
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
APIProvider provider =
|
||||||
apiConfig.init(provider);
|
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
||||||
} catch (APIManagementException e) {
|
apiConfig.init(provider);
|
||||||
throw new DeviceManagementException("Error occurred while initializing API Config '" +
|
} catch (APIManagementException e) {
|
||||||
apiConfig.getName() + "'", e);
|
throw new DeviceManagementException(
|
||||||
}
|
"Error occurred while initializing API Config '" +
|
||||||
}
|
apiConfig.getName() + "'", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void publishAPIs() throws DeviceManagementException {
|
private void publishAPIs() throws DeviceManagementException {
|
||||||
List<APIConfig> apiConfigs =
|
List<APIConfig> apiConfigs =
|
||||||
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||||
getApiPublisherConfig().getAPIs();
|
getApiPublisherConfig().getAPIs();
|
||||||
for (APIConfig apiConfig : apiConfigs) {
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeAPIs() throws DeviceManagementException {
|
private void removeAPIs() throws DeviceManagementException {
|
||||||
List<APIConfig> apiConfigs =
|
List<APIConfig> apiConfigs =
|
||||||
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||||
getApiPublisherConfig().getAPIs();
|
getApiPublisherConfig().getAPIs();
|
||||||
for (APIConfig apiConfig : apiConfigs) {
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
|
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,39 +60,19 @@ public class MobileDeviceManagementUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPropertyValue(Device device, String property) {
|
|
||||||
for (Device.Property prop : device.getProperties()) {
|
|
||||||
if (property.equals(prop.getName())) {
|
|
||||||
return prop.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Device.Property getProperty(String property, String value) {
|
|
||||||
Device.Property prop = null;
|
|
||||||
if (property != null) {
|
|
||||||
prop = new Device.Property();
|
|
||||||
prop.setName(property);
|
|
||||||
prop.setValue(value);
|
|
||||||
return prop;
|
|
||||||
}
|
|
||||||
return prop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MobileDevice convertToMobileDevice(Device device) {
|
public static MobileDevice convertToMobileDevice(Device device) {
|
||||||
MobileDevice mobileDevice = null;
|
MobileDevice mobileDevice = null;
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
mobileDevice = new MobileDevice();
|
mobileDevice = new MobileDevice();
|
||||||
mobileDevice.setMobileDeviceId(device.getDeviceIdentifier());
|
mobileDevice.setMobileDeviceId(device.getDeviceIdentifier());
|
||||||
mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI));
|
mobileDevice.setImei(device.getProperties().get(MOBILE_DEVICE_IMEI));
|
||||||
mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI));
|
mobileDevice.setImsi(device.getProperties().get(MOBILE_DEVICE_IMSI));
|
||||||
mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID));
|
mobileDevice.setRegId(device.getProperties().get(MOBILE_DEVICE_REG_ID));
|
||||||
mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL));
|
mobileDevice.setModel(device.getProperties().get(MOBILE_DEVICE_MODEL));
|
||||||
mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION));
|
mobileDevice.setOsVersion(device.getProperties().get(MOBILE_DEVICE_OS_VERSION));
|
||||||
mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR));
|
mobileDevice.setVendor(device.getProperties().get(MOBILE_DEVICE_VENDOR));
|
||||||
mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE));
|
mobileDevice.setLatitude(device.getProperties().get(MOBILE_DEVICE_LATITUDE));
|
||||||
mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE));
|
mobileDevice.setLongitude(device.getProperties().get(MOBILE_DEVICE_LONGITUDE));
|
||||||
}
|
}
|
||||||
return mobileDevice;
|
return mobileDevice;
|
||||||
}
|
}
|
||||||
@ -101,16 +81,16 @@ public class MobileDeviceManagementUtil {
|
|||||||
Device device = null;
|
Device device = null;
|
||||||
if (mobileDevice != null) {
|
if (mobileDevice != null) {
|
||||||
device = new Device();
|
device = new Device();
|
||||||
List<Device.Property> propertyList = new ArrayList<Device.Property>();
|
Map<String, String> propertyMap = new HashMap<String, String>();
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei()));
|
propertyMap.put(MOBILE_DEVICE_IMEI, mobileDevice.getImei());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()));
|
propertyMap.put(MOBILE_DEVICE_IMSI, mobileDevice.getImsi());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId()));
|
propertyMap.put(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel()));
|
propertyMap.put(MOBILE_DEVICE_MODEL, mobileDevice.getModel());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()));
|
propertyMap.put(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()));
|
propertyMap.put(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()));
|
propertyMap.put(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude());
|
||||||
propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()));
|
propertyMap.put(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude());
|
||||||
device.setProperties(propertyList);
|
device.setProperties(propertyMap);
|
||||||
device.setDeviceIdentifier(mobileDevice.getMobileDeviceId());
|
device.setDeviceIdentifier(mobileDevice.getMobileDeviceId());
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
|
|||||||
@ -23,9 +23,9 @@
|
|||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
|
|
||||||
<jaxrs:server id="customerService" address="/register">
|
<jaxrs:server id="operationService" address="/operations">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<ref bean="deviceMgtServiceBean"/>
|
<ref bean="operationServiceBean"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
<jaxrs:providers>
|
<jaxrs:providers>
|
||||||
<ref bean="jsonProvider"/>
|
<ref bean="jsonProvider"/>
|
||||||
@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
<bean id="deviceMgtServiceBean" class="org.wso2.cdmserver.mobileservices.android.Device"/>
|
<bean id="deviceMgtServiceBean" class="org.wso2.cdmserver.mobileservices.android.Device"/>
|
||||||
<bean id="enrollmentServiceBean" class="org.wso2.cdmserver.mobileservices.android.Enrollment"/>
|
<bean id="enrollmentServiceBean" class="org.wso2.cdmserver.mobileservices.android.Enrollment"/>
|
||||||
|
<bean id="operationServiceBean" class="org.wso2.cdmserver.mobileservices.android.Operation"/>
|
||||||
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||||
<bean id="errorHandler" class="org.wso2.cdmserver.mobileservices.android.common.ErrorHandler"/>
|
<bean id="errorHandler" class="org.wso2.cdmserver.mobileservices.android.common.ErrorHandler"/>
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user