Added operation support for Android

revert-70aa11f8
harshanL 10 years ago
parent 877ef213e1
commit eb0fd6dc31

@ -28,12 +28,11 @@ public class MobileDataSourceConfig {
private JNDILookupDefinition jndiLookupDefinition; private JNDILookupDefinition jndiLookupDefinition;
@XmlElement(name = "JndiLookupDefinition", nillable = true) @XmlElement(name = "JndiLookupDefinition", nillable = true)
public JNDILookupDefinition getJndiLookupDefintion() { public JNDILookupDefinition getJndiLookupDefinition() {
return jndiLookupDefinition; return jndiLookupDefinition;
} }
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) { public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
this.jndiLookupDefinition = jndiLookupDefinition; this.jndiLookupDefinition = jndiLookupDefinition;
} }
} }

@ -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() { * Resolve data source from the data source definition.
return new MobileDeviceDAOImpl(dataSource); *
} * @param config Mobile data source configuration
* @return data source resolved from the data source definition
public static MobileOperationDAO getMobileOperationDAO() { */
return new MobileOperationDAOImpl(dataSource); private static DataSource resolveDataSource(MobileDataSourceConfig config)
} throws DeviceManagementException {
DataSource dataSource = null;
public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { if (config == null) {
return new MobileOperationPropertyDAOImpl(dataSource); throw new RuntimeException("Device Management Repository data source configuration " +
} "is null and thus, is not initialized");
}
public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() { JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
return new MobileDeviceOperationDAOImpl(dataSource); if (jndiConfig != null) {
} if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI " +
public static FeatureDAO getFeatureDAO() { "Lookup Definition");
return new FeatureDAOImpl(dataSource); }
} List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties();
public static FeaturePropertyDAO getFeaturePropertyDAO() { if (jndiPropertyList != null) {
return new FeaturePropertyDAOImpl(dataSource); Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
} for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
jndiProperties.put(prop.getName(), prop.getValue());
public static MobileDataSourceConfig getMobileDeviceManagementConfig() { }
return mobileDataSourceConfig; dataSource =
} MobileDeviceManagementDAOUtil
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
public static void setMobileDataSourceConfig( } else {
MobileDataSourceConfig mobileDataSourceConfig) { dataSource = MobileDeviceManagementDAOUtil
MobileDeviceManagementDAOFactory.mobileDataSourceConfig = .lookupDataSource(jndiConfig.getJndiName(), null);
mobileDataSourceConfig; }
} }
return dataSource;
public static DataSource getDataSource() { }
return dataSource;
} public static MobileDeviceDAO getMobileDeviceDAO() {
return new MobileDeviceDAOImpl(dataSource);
@Override }
public void notifyObserver() {
try { public static MobileOperationDAO getMobileOperationDAO() {
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig); return new MobileOperationDAOImpl(dataSource);
MobileDeviceManagementDAOUtil.createDataSource(dataSource); }
} catch (DeviceManagementException e) {
log.error("Error occurred while resolving mobile device management metadata repository data source", e); public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
} return new MobileOperationPropertyDAOImpl(dataSource);
} }
public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() {
return new MobileDeviceOperationDAOImpl(dataSource);
}
public static FeatureDAO getFeatureDAO() {
return new FeatureDAOImpl(dataSource);
}
public static FeaturePropertyDAO getFeaturePropertyDAO() {
return new FeaturePropertyDAOImpl(dataSource);
}
public static MobileDataSourceConfig getMobileDeviceManagementConfig() {
return mobileDataSourceConfig;
}
public static void setMobileDataSourceConfig(
MobileDataSourceConfig mobileDataSourceConfig) {
MobileDeviceManagementDAOFactory.mobileDataSourceConfig =
mobileDataSourceConfig;
}
public static DataSource getDataSource() {
return dataSource;
}
} }

@ -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) {

@ -39,40 +39,6 @@ public class MobileDeviceManagementDAOUtil {
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class); private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
/**
* Resolve data source from the data source definition.
*
* @param config Mobile data source configuration
* @return data source resolved from the data source definition
*/
public 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 DataSource lookupDataSource(String dataSourceName, public static DataSource lookupDataSource(String dataSourceName,
final Hashtable<Object, Object> jndiProperties) final Hashtable<Object, Object> jndiProperties)
throws DeviceManagementException { throws DeviceManagementException {
@ -113,27 +79,6 @@ public class MobileDeviceManagementDAOUtil {
} }
} }
/**
* Initializes the creation of mobile device management schema if -Dsetup has provided.
*
* @param dataSource Mobile data source
*/
public static void createDataSource(DataSource dataSource) {
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(dataSource);
} catch (DeviceManagementException e) {
log.error("Exception occurred while initializing mobile device management database schema", e);
}
}
}
/** /**
* Creates the mobile device management schema. * Creates the mobile device management schema.
* *

@ -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();
androidServiceRegRef = String setupOption = System.getProperty("setup");
bundleContext.registerService(DeviceManagerService.class.getName(), if (setupOption != null) {
new AndroidDeviceManagerService(), null); if (log.isDebugEnabled()) {
iOSServiceRegRef = log.debug(
bundleContext.registerService(DeviceManagerService.class.getName(), "-Dsetup is enabled. Mobile Device management repository schema initialization is about " +
new IOSDeviceManagerService(), null); "to begin");
windowsServiceRegRef = }
bundleContext.registerService(DeviceManagerService.class.getName(), try {
new WindowsDeviceManagerService(), null); MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
MobileDeviceManagementDAOFactory.getDataSource());
} catch (DeviceManagementException e) {
log.error(
"Exception occurred while initializing mobile device management database schema",
e);
}
}
androidServiceRegRef =
bundleContext.registerService(DeviceManagerService.class.getName(),
new AndroidDeviceManagerService(), null);
iOSServiceRegRef =
bundleContext.registerService(DeviceManagerService.class.getName(),
new IOSDeviceManagerService(), null);
windowsServiceRegRef =
bundleContext.registerService(DeviceManagerService.class.getName(),
new WindowsDeviceManagerService(), null);
/* Initialize all API configurations with corresponding API Providers */ /* 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) { }
if (log.isDebugEnabled()) {
log.debug("De-activating Mobile Device Management Service Component"); protected void deactivate(ComponentContext ctx) {
} if (log.isDebugEnabled()) {
try { log.debug("De-activating Mobile Device Management Service Component");
BundleContext bundleContext = ctx.getBundleContext(); }
try {
androidServiceRegRef.unregister(); BundleContext bundleContext = ctx.getBundleContext();
iOSServiceRegRef.unregister();
windowsServiceRegRef.unregister(); androidServiceRegRef.unregister();
iOSServiceRegRef.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 {
List<APIConfig> apiConfigs = private void initAPIConfigs() throws DeviceManagementException {
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). List<APIConfig> apiConfigs =
getApiPublisherConfig().getAPIs(); MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
for (APIConfig apiConfig : apiConfigs) { getApiPublisherConfig().getAPIs();
try { for (APIConfig apiConfig : apiConfigs) {
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); try {
apiConfig.init(provider); APIProvider provider =
} catch (APIManagementException e) { APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
throw new DeviceManagementException("Error occurred while initializing API Config '" + apiConfig.init(provider);
apiConfig.getName() + "'", e); } catch (APIManagementException e) {
} throw new DeviceManagementException(
} "Error occurred while initializing API Config '" +
} apiConfig.getName() + "'", e);
}
private void publishAPIs() throws DeviceManagementException { }
List<APIConfig> apiConfigs = }
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs(); private void publishAPIs() throws DeviceManagementException {
for (APIConfig apiConfig : apiConfigs) { List<APIConfig> apiConfigs =
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig); MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
} getApiPublisherConfig().getAPIs();
} for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
private void removeAPIs() throws DeviceManagementException { }
List<APIConfig> apiConfigs = }
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs(); private void removeAPIs() throws DeviceManagementException {
for (APIConfig apiConfig : apiConfigs) { List<APIConfig> apiConfigs =
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig); MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
} getApiPublisherConfig().getAPIs();
} for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { }
//do nothing }
}
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) { //do nothing
//do nothing }
}
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
//do nothing
}
} }

@ -210,7 +210,7 @@
<!-- Copying Device Management related dbscripts --> <!-- Copying Device Management related dbscripts -->
<fileSet> <fileSet>
<directory>../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/cdm</directory> <directory>../distribution/src/repository/dbscripts/cdm</directory>
<outputDirectory>wso2cdm-${project.version}/dbscripts/cdm</outputDirectory> <outputDirectory>wso2cdm-${project.version}/dbscripts/cdm</outputDirectory>
<includes> <includes>
<include>*/**</include> <include>*/**</include>
@ -460,5 +460,15 @@
<fileMode>644</fileMode> <fileMode>644</fileMode>
</file> </file>
<!-- Copying H2 database related files corresponding to default Mobile Device management repository schema -->
<file>
<source>
../distribution/src/repository/database/WSO2MobileDM_DB.h2.db
</source>
<outputDirectory>${pom.artifactId}-${pom.version}/repository/database</outputDirectory>
<destName>WSO2MobileDM_DB.h2.db</destName>
<fileMode>644</fileMode>
</file>
</files> </files>
</assembly> </assembly>

@ -23,4 +23,4 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
-- TO:DO - Remove this INSERT sql statement. -- TO:DO - Remove this INSERT sql statement.
Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android'); Insert into DM_DEVICE_TYPE (NAME) VALUES ('android');

@ -31,13 +31,8 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( CREATE TABLE IF NOT EXISTS `MBL_OPERATION` (
`OPERATION_ID` INT NOT NULL AUTO_INCREMENT , `OPERATION_ID` INT NOT NULL AUTO_INCREMENT ,
`FEATURE_CODE` VARCHAR(45) NOT NULL , `FEATURE_CODE` VARCHAR(45) NOT NULL ,
`CREATED_DATE` INT NULL , `CREATED_DATE` BIGINT NULL ,
PRIMARY KEY (`OPERATION_ID`) , PRIMARY KEY (`OPERATION_ID`));
CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1`
FOREIGN KEY (`FEATURE_CODE` )
REFERENCES `MBL_FEATURE` (`CODE` )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `MBL_DEVICE_OPERATION_MAPPING` -- Table `MBL_DEVICE_OPERATION_MAPPING`
@ -45,8 +40,8 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION` (
CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` (
`DEVICE_ID` VARCHAR(45) NOT NULL , `DEVICE_ID` VARCHAR(45) NOT NULL ,
`OPERATION_ID` INT NOT NULL , `OPERATION_ID` INT NOT NULL ,
`SENT_DATE` INT NULL , `SENT_DATE` BIGINT NULL ,
`RECEIVED_DATE` INT NULL , `RECEIVED_DATE` BIGINT NULL ,
PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) ,
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE`
FOREIGN KEY (`DEVICE_ID` ) FOREIGN KEY (`DEVICE_ID` )

@ -10,6 +10,8 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL ,
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL ,
`VENDOR` VARCHAR(45) NULL DEFAULT NULL , `VENDOR` VARCHAR(45) NULL DEFAULT NULL ,
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`MOBILE_DEVICE_ID`) ); PRIMARY KEY (`MOBILE_DEVICE_ID`) );
@ -18,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
`FEATURE_ID` INT NOT NULL AUTO_INCREMENT , `FEATURE_ID` INT NOT NULL AUTO_INCREMENT ,
`CODE` VARCHAR(45) NULL , `CODE` VARCHAR(45) NOT NULL ,
`NAME` VARCHAR(100) NULL , `NAME` VARCHAR(100) NULL ,
`DESCRIPTION` VARCHAR(200) NULL , `DESCRIPTION` VARCHAR(200) NULL ,
PRIMARY KEY (`FEATURE_ID`) ); PRIMARY KEY (`FEATURE_ID`) );
@ -28,23 +30,18 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( CREATE TABLE IF NOT EXISTS `MBL_OPERATION` (
`OPERATION_ID` INT NOT NULL AUTO_INCREMENT , `OPERATION_ID` INT NOT NULL AUTO_INCREMENT ,
`FEATURE_CODE` VARCHAR(45) NULL , `FEATURE_CODE` VARCHAR(45) NOT NULL ,
`CREATED_DATE` INT NULL , `CREATED_DATE` LONG NULL ,
PRIMARY KEY (`OPERATION_ID`) , PRIMARY KEY (`OPERATION_ID`));
CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1`
FOREIGN KEY (`FEATURE_CODE` )
REFERENCES `MBL_FEATURE` (`CODE` )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `MBL_DEVICE_OPERATION_MAPING` -- Table `MBL_DEVICE_OPERATION_MAPPING`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPING` ( CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` (
`DEVICE_ID` VARCHAR(45) NOT NULL , `DEVICE_ID` VARCHAR(45) NOT NULL ,
`OPERATION_ID` INT NOT NULL , `OPERATION_ID` INT NOT NULL ,
`SENT_DATE` INT NULL , `SENT_DATE` LONG NULL ,
`RECEIVED_DATE` INT NULL , `RECEIVED_DATE` LONG NULL ,
PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) ,
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE`
FOREIGN KEY (`DEVICE_ID` ) FOREIGN KEY (`DEVICE_ID` )
@ -61,11 +58,10 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPING` (
-- Table `MBL_OPERATION_PROPERTY` -- Table `MBL_OPERATION_PROPERTY`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` (
`OPERATION_PROPERTY_ID` INT NOT NULL AUTO_INCREMENT , `OPERATION_ID` INT NOT NULL ,
`OPERATION_ID` INT NULL , `PROPERTY` VARCHAR(45) NOT NULL ,
`PROPERTY_ID` INT NULL ,
`VALUE` TEXT NULL , `VALUE` TEXT NULL ,
PRIMARY KEY (`OPERATION_PROPERTY_ID`) , PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) ,
CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1`
FOREIGN KEY (`OPERATION_ID` ) FOREIGN KEY (`OPERATION_ID` )
REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) REFERENCES `MBL_OPERATION` (`OPERATION_ID` )
@ -76,13 +72,11 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` (
-- Table `MBL_FEATURE_PROPERTY` -- Table `MBL_FEATURE_PROPERTY`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` (
`PROPERTY_ID` INT NOT NULL AUTO_INCREMENT , `PROPERTY` VARCHAR(45) NOT NULL ,
`PROPERTY` VARCHAR(100) NULL , `FEATURE_ID` VARCHAR(45) NOT NULL ,
`FEATURE_ID` VARCHAR(45) NULL , PRIMARY KEY (`PROPERTY`) ,
PRIMARY KEY (`PROPERTY_ID`) ,
CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1`
FOREIGN KEY (`FEATURE_ID` ) FOREIGN KEY (`FEATURE_ID` )
REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) REFERENCES `MBL_FEATURE` (`FEATURE_ID` )
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION); ON UPDATE NO ACTION);

@ -39,112 +39,113 @@ import javax.ws.rs.core.Response;
@Consumes({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" })
public class Enrollment { public class Enrollment {
private static Log log = LogFactory.getLog(Enrollment.class); private static Log log = LogFactory.getLog(Enrollment.class);
@POST @POST
public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device)
throws AndroidAgentException {
Message responseMsg = new Message();
Message responseMsg = new Message();
try {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); try {
AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
Response.status(Response.Status.CREATED); AndroidAPIUtils.getDeviceManagementService().enrollDevice(device);
responseMsg.setResponseMessage("Device enrollment succeeded"); Response.status(Response.Status.CREATED);
return responseMsg; responseMsg.setResponseMessage("Device enrollment succeeded");
} catch (DeviceManagementServiceException deviceServiceMgtEx) { return responseMsg;
String errorMsg = "Device management service error"; } catch (DeviceManagementServiceException deviceServiceMgtEx) {
log.error(errorMsg, deviceServiceMgtEx); String errorMsg = "Device management service error";
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); log.error(errorMsg, deviceServiceMgtEx);
} catch (DeviceManagementException deviceMgtEx) { throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
String errorMsg = "Error occurred while enrolling the device"; } catch (DeviceManagementException deviceMgtEx) {
log.error(errorMsg, deviceMgtEx); String errorMsg = "Error occurred while enrolling the device";
throw new AndroidAgentException(errorMsg, deviceMgtEx); log.error(errorMsg, deviceMgtEx);
} throw new AndroidAgentException(errorMsg, deviceMgtEx);
} }
}
@GET
@Path("{id}") @GET
public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException { @Path("{id}")
public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException {
boolean result;
Message responseMsg = new Message(); boolean result;
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); Message responseMsg = new Message();
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier); try {
if (result) { result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
responseMsg.setResponseMessage("Device has already enrolled"); if (result) {
} else { responseMsg.setResponseMessage("Device has already enrolled");
Response.status(Response.Status.NOT_FOUND); } else {
responseMsg.setResponseMessage("Device not found"); Response.status(Response.Status.NOT_FOUND);
} responseMsg.setResponseMessage("Device not found");
return responseMsg; }
} catch (DeviceManagementServiceException deviceServiceMgtEx) { return responseMsg;
String errorMsg = "Device management service error"; } catch (DeviceManagementServiceException deviceServiceMgtEx) {
log.error(errorMsg, deviceServiceMgtEx); String errorMsg = "Device management service error";
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); log.error(errorMsg, deviceServiceMgtEx);
} catch (DeviceManagementException deviceMgtEx) { throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
String errorMsg = "Error occurred while enrollment of the device."; } catch (DeviceManagementException deviceMgtEx) {
log.error(errorMsg, deviceMgtEx); String errorMsg = "Error occurred while enrollment of the device.";
throw new AndroidAgentException(errorMsg, deviceMgtEx); log.error(errorMsg, deviceMgtEx);
} throw new AndroidAgentException(errorMsg, deviceMgtEx);
} }
}
@PUT
@Path("{id}") @PUT
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) @Path("{id}")
throws AndroidAgentException { public Message modifyEnrollment(@PathParam("id") String id,
org.wso2.carbon.device.mgt.common.Device device)
boolean result; throws AndroidAgentException {
Message responseMsg = new Message();
try { boolean result;
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); Message responseMsg = new Message();
result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device); try {
if (result) { device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
responseMsg.setResponseMessage("Device enrollment has updated successfully"); result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device);
Response.status(Response.Status.ACCEPTED); if (result) {
} else { responseMsg.setResponseMessage("Device enrollment has updated successfully");
responseMsg.setResponseMessage("Device not found for enrollment"); Response.status(Response.Status.ACCEPTED);
Response.status(Response.Status.NOT_MODIFIED); } else {
} responseMsg.setResponseMessage("Device not found for enrollment");
return responseMsg; Response.status(Response.Status.NOT_MODIFIED);
} catch (DeviceManagementServiceException deviceServiceMgtEx) { }
String errorMsg = "Device management service error"; return responseMsg;
log.error(errorMsg, deviceServiceMgtEx); } catch (DeviceManagementServiceException deviceServiceMgtEx) {
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); String errorMsg = "Device management service error";
} catch (DeviceManagementException deviceMgtEx) { log.error(errorMsg, deviceServiceMgtEx);
String errorMsg = "Error occurred while modifying enrollment of the device"; throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
log.error(errorMsg, deviceMgtEx); } catch (DeviceManagementException deviceMgtEx) {
throw new AndroidAgentException(errorMsg, deviceMgtEx); String errorMsg = "Error occurred while modifying enrollment of the device";
} log.error(errorMsg, deviceMgtEx);
} throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
@DELETE }
@Path("{id}")
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException { @DELETE
@Path("{id}")
Message responseMsg = new Message(); public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
boolean result; Message responseMsg = new Message();
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); boolean result;
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); try {
if (result) { result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
responseMsg.setResponseMessage("Device has removed successfully"); if (result) {
} else { responseMsg.setResponseMessage("Device has removed successfully");
responseMsg.setResponseMessage("Device not found"); } else {
Response.status(Response.Status.NOT_FOUND); responseMsg.setResponseMessage("Device not found");
} Response.status(Response.Status.NOT_FOUND);
return responseMsg; }
} catch (DeviceManagementServiceException deviceServiceMgtEx) { return responseMsg;
String errorMsg = "Device management service error"; } catch (DeviceManagementServiceException deviceServiceMgtEx) {
log.error(errorMsg, deviceServiceMgtEx); String errorMsg = "Device management service error";
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); log.error(errorMsg, deviceServiceMgtEx);
} catch (DeviceManagementException deviceMgtEx) { throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
String errorMsg = "Error occurred while dis enrolling the device"; } catch (DeviceManagementException deviceMgtEx) {
log.error(errorMsg, deviceMgtEx); String errorMsg = "Error occurred while dis enrolling the device";
throw new AndroidAgentException(errorMsg, deviceMgtEx); log.error(errorMsg, deviceMgtEx);
} throw new AndroidAgentException(errorMsg, deviceMgtEx);
} }
}
} }

@ -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…
Cancel
Save