MDM-312 fix : Refactored code of MDM MobileImpl component

revert-dabc3590
harshanL 10 years ago
parent 7f436f4f75
commit dbf296605f

@ -24,15 +24,17 @@ import java.util.List;
public abstract class AbstractMobileOperationManager implements OperationManager {
@Override
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
return null;
}
@Override
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
return null;
}
@Override
public boolean addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
return true;
}
@Override
public boolean addOperation(Operation operation,
List<DeviceIdentifier> devices)
throws OperationManagementException {
return true;
}
}

@ -34,13 +34,14 @@ import java.io.File;
public class MobileDeviceConfigurationManager {
private static final String MOBILE_DEVICE_CONFIG_XML_NAME = "mobile-config.xml";
private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile";
private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile";
private MobileDeviceManagementConfig currentMobileDeviceConfig;
private static MobileDeviceConfigurationManager mobileDeviceConfigManager;
private final String mobileDeviceMgtConfigXMLPath =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator +
MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME;
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" +
File.separator +
MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME;
public static MobileDeviceConfigurationManager getInstance() {
if (mobileDeviceConfigManager == null) {

@ -29,8 +29,8 @@ public interface MobileDeviceOperationMappingDAO {
/**
* Add a new mobile device operation mapping to the table.
*
* @param deviceOperation MobileDeviceOperation object that holds data related to the MobileDeviceOperation
* to be inserted.
* @param deviceOperation MobileDeviceOperation object that holds data related to the
* MobileDeviceOperation to be inserted.
* @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException
*/
@ -85,8 +85,8 @@ public interface MobileDeviceOperationMappingDAO {
*
* @param deviceId Device id of the mapping to be retrieved.
* @param operationId Operation id of the mapping to be retrieved.
* @return MobileDeviceOperation object that holds data of the device operation mapping represented by
* deviceId and operationId.
* @return MobileDeviceOperation object that holds data of the device operation mapping
* represented by deviceId and operationId.
* @throws MobileDeviceManagementDAOException
*/
MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId, int operationId)

@ -23,14 +23,15 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
import java.util.List;
/**
* This class represents the key operations associated with persisting mobile feature property related
* information.
* This class represents the key operations associated with persisting mobile feature property
* related information.
*/
public interface MobileFeaturePropertyDAO {
/**
* Add a new feature property to feature property table.
*
* @param mobileFeatureProperty Feature property object that holds data related to the feature property to be inserted.
* @param mobileFeatureProperty Feature property object that holds data related to the feature
* property to be inserted.
* @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException
*/

@ -128,7 +128,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
conn = this.getConnection();
String updateDBQuery =
"UPDATE MBL_DEVICE SET REG_ID = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," +
"DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? WHERE MOBILE_DEVICE_ID = ?";
"DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? " +
"WHERE MOBILE_DEVICE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, mobileDevice.getRegId());
stmt.setString(2, mobileDevice.getImei());

@ -20,8 +20,8 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO;
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
@ -73,7 +73,6 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
deviceOperation.getDeviceId() + " and operation id - " +
deviceOperation.getOperationId() +
" to mapping table MBL_DEVICE_OPERATION";
;
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
@ -91,8 +90,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
try {
conn = this.getConnection();
String updateDBQuery =
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, STATUS = ? " +
"WHERE DEVICE_ID = ? AND OPERATION_ID=?";
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " +
"STATUS = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?";
stmt = conn.prepareStatement(updateDBQuery);
stmt.setLong(1, deviceOperation.getSentDate());
stmt.setLong(2, deviceOperation.getReceivedDate());
@ -159,7 +158,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
conn = this.getConnection();
String updateDBQuery =
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " +
"WHERE DEVICE_ID = ? AND OPERATION_ID=?";
"WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
stmt.setLong(1, new Date().getTime());
stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name());
@ -191,7 +190,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
try {
conn = this.getConnection();
String deleteDBQuery =
"DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
"DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " +
"OPERATION_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1, deviceId);
stmt.setInt(2, operationId);
@ -222,19 +222,18 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
conn = this.getConnection();
String selectDBQuery =
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
stmt.setInt(2, operationId);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
if (resultSet.next()) {
mblDeviceOperation = new MobileDeviceOperationMapping();
mblDeviceOperation.setDeviceId(resultSet.getString(1));
mblDeviceOperation.setOperationId(resultSet.getInt(2));
mblDeviceOperation.setSentDate(resultSet.getInt(3));
mblDeviceOperation.setReceivedDate(resultSet.getInt(4));
mblDeviceOperation.setStatus(resultSet.getString(5));
break;
}
} catch (SQLException e) {
String msg =
@ -254,8 +253,9 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileDeviceOperationMapping mblDeviceOperation = null;
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
MobileDeviceOperationMapping mblDeviceOperation;
List<MobileDeviceOperationMapping> mblDeviceOperations =
new ArrayList<MobileDeviceOperationMapping>();
try {
conn = this.getConnection();
String selectDBQuery =
@ -292,15 +292,17 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
Connection conn = null;
PreparedStatement stmt = null;
MobileDeviceOperationMapping mblDeviceOperation = null;
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
List<MobileDeviceOperationMapping> mblDeviceOperations =
new ArrayList<MobileDeviceOperationMapping>();
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" +
" MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = 'NEW'";
" MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
stmt.setString(2, MobileDeviceOperationMapping.Status.NEW.name());
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
mblDeviceOperation = new MobileDeviceOperationMapping();

@ -46,7 +46,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public int addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
public int addMobileFeature(MobileFeature mobileFeature)
throws MobileDeviceManagementDAOException {
int status = 0;
Connection conn = null;
PreparedStatement stmt = null;
@ -87,7 +88,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
try {
conn = this.getConnection();
String updateDBQuery =
"UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ? WHERE FEATURE_ID = ?";
"UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ?" +
" WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, mobileFeature.getCode());
stmt.setString(2, mobileFeature.getName());
@ -170,18 +172,18 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE CODE = ?";
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE " +
"WHERE CODE = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, featureCode);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
if (resultSet.next()) {
mobileFeature = new MobileFeature();
mobileFeature.setId(resultSet.getInt(1));
mobileFeature.setCode(resultSet.getString(2));
mobileFeature.setName(resultSet.getString(3));
mobileFeature.setDescription(resultSet.getString(4));
mobileFeature.setDeviceType(resultSet.getString(5));
break;
}
} catch (SQLException e) {
String msg = "Error occurred while fetching feature code - '" +
@ -203,18 +205,18 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE FEATURE_ID = ?";
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" +
" WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, featureID);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
if (resultSet.next()) {
mobileFeature = new MobileFeature();
mobileFeature.setId(resultSet.getInt(1));
mobileFeature.setCode(resultSet.getString(2));
mobileFeature.setName(resultSet.getString(3));
mobileFeature.setDescription(resultSet.getString(4));
mobileFeature.setDeviceType(resultSet.getString(5));
break;
}
} catch (SQLException e) {
String msg = "Error occurred while fetching feature id - '" +
@ -259,7 +261,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException {
public List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws
MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileFeature mobileFeature;
@ -267,7 +270,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE DEVICE_TYPE = ?";
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" +
" WHERE DEVICE_TYPE = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceType);
ResultSet resultSet = stmt.executeQuery();
@ -285,7 +289,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
String msg = "Error occurred while fetching all features.'";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
}finally {
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
}

@ -169,11 +169,10 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, property);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
if (resultSet.next()) {
mobileFeatureProperty = new MobileFeatureProperty();
mobileFeatureProperty.setProperty(resultSet.getString(1));
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
break;
}
} catch (SQLException e) {
String msg = "Error occurred while fetching property - '" +
@ -191,7 +190,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileFeatureProperty mobileFeatureProperty = null;
MobileFeatureProperty mobileFeatureProperty;
List<MobileFeatureProperty> FeatureProperties = new ArrayList<MobileFeatureProperty>();
try {
conn = this.getConnection();

@ -84,7 +84,8 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
try {
conn = this.getConnection();
String updateDBQuery =
"UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE OPERATION_ID = ?";
"UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " +
"OPERATION_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, operation.getFeatureCode());
stmt.setLong(2, operation.getCreatedDate());
@ -140,16 +141,16 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
try {
conn = this.getConnection();
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.setInt(1, operationId);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
if (resultSet.next()) {
operation = new MobileOperation();
operation.setOperationId(resultSet.getInt(1));
operation.setFeatureCode(resultSet.getString(2));
operation.setCreatedDate(resultSet.getLong(3));
break;
}
} catch (SQLException e) {
String msg = "Error occurred while fetching operationId - '" +

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO;
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
import javax.sql.DataSource;
@ -55,8 +54,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
try {
conn = this.getConnection();
String createDBQuery =
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) VALUES ( ?, ?, ?)";
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " +
"VALUES ( ?, ?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt.setInt(1, operationProperty.getOperationId());
stmt.setString(2, operationProperty.getProperty());
@ -67,7 +66,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
}
} catch (SQLException e) {
String msg =
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY table";
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY " +
"table";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
@ -86,8 +86,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
try {
conn = this.getConnection();
String createDBQuery =
"UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND PROPERTY = ?";
"UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " +
"PROPERTY = ?";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, operationProperty.getValue());
stmt.setInt(2, operationProperty.getOperationId());
@ -98,7 +98,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
}
} catch (SQLException e) {
String msg =
"Error occurred while updating the mobile operation property in MBL_OPERATION_PROPERTY table.";
"Error occurred while updating the mobile operation property in" +
" MBL_OPERATION_PROPERTY table.";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
@ -144,17 +145,17 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ? AND PROPERTY = ?";
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " +
"OPERATION_ID = ? AND PROPERTY = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, operationId);
stmt.setString(2, property);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
if (resultSet.next()) {
mobileOperationProperty = new MobileOperationProperty();
mobileOperationProperty.setOperationId(resultSet.getInt(1));
mobileOperationProperty.setProperty(resultSet.getString(2));
mobileOperationProperty.setValue(resultSet.getString(3));
break;
}
} catch (SQLException e) {
String msg =
@ -173,12 +174,13 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
int operationId) throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileOperationProperty mobileOperationProperty = null;
MobileOperationProperty mobileOperationProperty;
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " +
"OPERATION_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, operationId);
ResultSet resultSet = stmt.executeQuery();

@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.dao.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementSchemaInitializer;
import javax.naming.InitialContext;
@ -32,7 +30,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.List;
/**
* Utility method required by MobileDeviceManagement DAO classes.
@ -94,8 +91,8 @@ public class MobileDeviceManagementDAOUtil {
try {
initializer.createRegistryDatabase();
} catch (Exception e) {
throw new DeviceManagementException("Error occurred while initializing Mobile Device Management " +
"database schema", e);
throw new DeviceManagementException("Error occurred while initializing Mobile Device " +
"Management database schema", e);
}
}

@ -42,7 +42,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
OperationManagementException {
boolean status = false;
try {
MobileDeviceOperationMapping mobileDeviceOperationMapping = null;
MobileDeviceOperationMapping mobileDeviceOperationMapping;
MobileOperation mobileOperation =
MobileDeviceManagementUtil.convertToMobileOperation(operation);
int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
@ -77,14 +77,15 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
List<Operation> operations = new ArrayList<Operation>();
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
List<MobileOperationProperty> operationProperties = null;
MobileOperation mobileOperation = null;
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings;
List<MobileOperationProperty> operationProperties;
MobileOperation mobileOperation;
try {
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllMobileDeviceOperationMappingsOfDevice(
deviceIdentifier
.getId());
mobileDeviceOperationMappings =
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllMobileDeviceOperationMappingsOfDevice(
deviceIdentifier
.getId());
if (mobileDeviceOperationMappings.size() > 0) {
List<Integer> operationIds = MobileDeviceManagementUtil
.getMobileOperationIdsFromMobileDeviceOperations(
@ -116,15 +117,16 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
public List<Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
List<Operation> operations = new ArrayList<Operation>();
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
List<MobileOperationProperty> operationProperties = null;
MobileOperation mobileOperation = null;
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings;
List<MobileOperationProperty> operationProperties ;
MobileOperation mobileOperation;
try {
//Get the list of pending operations for the given device
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllPendingOperationMappingsOfMobileDevice(
deviceIdentifier
.getId());
mobileDeviceOperationMappings =
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllPendingOperationMappingsOfMobileDevice(
deviceIdentifier
.getId());
//Go through each operation mapping for retrieving the data corresponding to each operation
for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) {
//Get the MobileOperation data
@ -158,19 +160,23 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
}
@Override
public List<Feature> getFeaturesForDeviceType(String deviceType) throws FeatureManagementException {
public List<Feature> getFeaturesForDeviceType(String deviceType)
throws FeatureManagementException {
MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO();
MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
MobileFeaturePropertyDAO featurePropertyDAO =
MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
List<Feature> features = new ArrayList<Feature>();
try {
List<MobileFeature> mobileFeatures = featureDAO.getMobileFeatureByDeviceType(deviceType);
List<MobileFeature> mobileFeatures =
featureDAO.getMobileFeatureByDeviceType(deviceType);
for (MobileFeature mobileFeature : mobileFeatures) {
Feature feature = new Feature();
feature.setId(mobileFeature.getId());
feature.setDeviceType(mobileFeature.getDeviceType());
feature.setName(mobileFeature.getName());
feature.setDescription(mobileFeature.getDescription());
List<Feature.MetadataEntry> metadataEntries = new ArrayList<Feature.MetadataEntry>();
List<Feature.MetadataEntry> metadataEntries =
new ArrayList<Feature.MetadataEntry>();
List<MobileFeatureProperty> properties =
featurePropertyDAO.getFeaturePropertiesOfFeature(mobileFeature.getId());
for (MobileFeatureProperty property : properties) {

@ -40,129 +40,136 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerServic
import java.util.ArrayList;
import java.util.List;
/**
* BundleActivator of MobileDeviceManagement component.
*/
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
private ServiceRegistration androidServiceRegRef;
private ServiceRegistration iOSServiceRegRef;
private ServiceRegistration windowsServiceRegRef;
private ServiceRegistration androidServiceRegRef;
private ServiceRegistration iOSServiceRegRef;
private ServiceRegistration windowsServiceRegRef;
private static List<DataSourceListener> dataSourceListeners = new ArrayList<DataSourceListener>();
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);
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);
@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 datasource configuration */
MobileDeviceConfigurationManager.getInstance().initConfig();
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
.getMobileDeviceManagementConfig();
MobileDataSourceConfig dsConfig =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
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);
MobileDeviceConfigurationManager.getInstance().initConfig();
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
.getMobileDeviceManagementConfig();
MobileDataSourceConfig dsConfig =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
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 */
this.initAPIConfigs();
/* Publish all mobile device management related JAX-RS services as APIs */
this.publishAPIs();
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();
iOSServiceRegRef.unregister();
windowsServiceRegRef.unregister();
bundleContext.removeBundleListener(this);
this.initAPIConfigs();
/* Publish all mobile device management related JAX-RS services as APIs */
this.publishAPIs();
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();
iOSServiceRegRef.unregister();
windowsServiceRegRef.unregister();
bundleContext.removeBundleListener(this);
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
services */
this.removeAPIs();
} 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;
}
private void initAPIConfigs() throws DeviceManagementException {
List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) {
try {
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
apiConfig.init(provider);
} 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();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
}
}
private void removeAPIs() throws DeviceManagementException {
List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
}
}
this.removeAPIs();
} 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;
}
private void initAPIConfigs() throws DeviceManagementException {
List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) {
try {
APIProvider provider =
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
apiConfig.init(provider);
} 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();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
}
}
private void removeAPIs() throws DeviceManagementException {
List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
}
}
}

@ -23,11 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;

@ -26,6 +26,11 @@ import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
import javax.sql.DataSource;
import java.io.File;
/**
*
* Provides methods for initializing the database script.
*
*/
public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator {
private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class);

@ -71,14 +71,13 @@ public class MobileDeviceManagementUtil {
}
private static Device.Property getProperty(String property, String value) {
Device.Property prop = null;
if (property != null) {
prop = new Device.Property();
Device.Property prop = new Device.Property();
prop.setName(property);
prop.setValue(value);
return prop;
}
return prop;
return null;
}
public static MobileDevice convertToMobileDevice(Device device) {
@ -119,7 +118,7 @@ public class MobileDeviceManagementUtil {
public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) {
MobileOperation mobileOperation = new MobileOperation();
MobileOperationProperty operationProperty = null;
MobileOperationProperty operationProperty;
List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
mobileOperation.setFeatureCode(operation.getCode());
mobileOperation.setCreatedDate(new Date().getTime());

@ -36,9 +36,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
import java.sql.*;
/**
*
* Class for holding unit-tests related to MobileOperationDAO class.
*
*/
public class MobileOperationDAOTestSuite {
@ -101,7 +99,7 @@ public class MobileOperationDAOTestSuite {
} finally {
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
}
Assert.assertTrue(mblOperationId > 0 , "MobileOperation has added ");
Assert.assertTrue(mblOperationId > 0, "MobileOperation has added ");
Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, testMblOperation.getFeatureCode(),
"MobileOperation feature code has persisted ");
Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, testMblOperation.getCreatedDate(),
@ -119,7 +117,7 @@ public class MobileOperationDAOTestSuite {
"MobileOperation feature-code has retrieved ");
}
@Test(dependsOnMethods = { "addMobileOperationTest" , "getMobileOperationTest"})
@Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest" })
public void updateMobileOperationTest()
throws MobileDeviceManagementDAOException {
@ -151,14 +149,14 @@ public class MobileOperationDAOTestSuite {
} finally {
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
}
Assert.assertTrue(status , "MobileOperation has updated ");
Assert.assertTrue(status, "MobileOperation has updated ");
Assert.assertEquals(TEST_MBL_OPR_UPDATED_FEATURE_CODE, testMblOperation.getFeatureCode(),
"MobileOperation feature code has updated ");
Assert.assertEquals(updatedDate, testMblOperation.getCreatedDate(),
"MobileOperation created-date has updated ");
}
@Test(dependsOnMethods = { "addMobileOperationTest" , "getMobileOperationTest",
@Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest",
"updateMobileOperationTest" })
public void deleteMobileDeviceTest()
throws MobileDeviceManagementDAOException {

Loading…
Cancel
Save