MDM-312 fix : Refactored code of MDM MobileImpl component

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

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

@ -39,7 +39,8 @@ public class MobileDeviceConfigurationManager {
private static MobileDeviceConfigurationManager mobileDeviceConfigManager; private static MobileDeviceConfigurationManager mobileDeviceConfigManager;
private final String mobileDeviceMgtConfigXMLPath = private final String mobileDeviceMgtConfigXMLPath =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" +
File.separator +
MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME; MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME;
public static MobileDeviceConfigurationManager getInstance() { public static MobileDeviceConfigurationManager getInstance() {

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

@ -23,14 +23,15 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
import java.util.List; import java.util.List;
/** /**
* This class represents the key operations associated with persisting mobile feature property related * This class represents the key operations associated with persisting mobile feature property
* information. * related information.
*/ */
public interface MobileFeaturePropertyDAO { public interface MobileFeaturePropertyDAO {
/** /**
* Add a new feature property to feature property table. * 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. * @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */

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

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

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

@ -84,7 +84,8 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String updateDBQuery = 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 = conn.prepareStatement(updateDBQuery);
stmt.setString(1, operation.getFeatureCode()); stmt.setString(1, operation.getFeatureCode());
stmt.setLong(2, operation.getCreatedDate()); stmt.setLong(2, operation.getCreatedDate());
@ -140,16 +141,16 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
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, operationId); stmt.setInt(1, operationId);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { if (resultSet.next()) {
operation = new MobileOperation(); operation = new MobileOperation();
operation.setOperationId(resultSet.getInt(1)); operation.setOperationId(resultSet.getInt(1));
operation.setFeatureCode(resultSet.getString(2)); operation.setFeatureCode(resultSet.getString(2));
operation.setCreatedDate(resultSet.getLong(3)); operation.setCreatedDate(resultSet.getLong(3));
break;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while fetching operationId - '" + 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.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO; 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.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -55,8 +54,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
try { try {
conn = this.getConnection(); conn = this.getConnection();
String createDBQuery = 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 = conn.prepareStatement(createDBQuery);
stmt.setInt(1, operationProperty.getOperationId()); stmt.setInt(1, operationProperty.getOperationId());
stmt.setString(2, operationProperty.getProperty()); stmt.setString(2, operationProperty.getProperty());
@ -67,7 +66,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = 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); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -86,8 +86,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
try { try {
conn = this.getConnection(); conn = this.getConnection();
String createDBQuery = 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 = conn.prepareStatement(createDBQuery);
stmt.setString(1, operationProperty.getValue()); stmt.setString(1, operationProperty.getValue());
stmt.setInt(2, operationProperty.getOperationId()); stmt.setInt(2, operationProperty.getOperationId());
@ -98,7 +98,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = 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); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -144,17 +145,17 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = 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 = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setString(2, property); stmt.setString(2, property);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { if (resultSet.next()) {
mobileOperationProperty = new MobileOperationProperty(); mobileOperationProperty = new MobileOperationProperty();
mobileOperationProperty.setOperationId(resultSet.getInt(1)); mobileOperationProperty.setOperationId(resultSet.getInt(1));
mobileOperationProperty.setProperty(resultSet.getString(2)); mobileOperationProperty.setProperty(resultSet.getString(2));
mobileOperationProperty.setValue(resultSet.getString(3)); mobileOperationProperty.setValue(resultSet.getString(3));
break;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = String msg =
@ -173,12 +174,13 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
int operationId) throws MobileDeviceManagementDAOException { int operationId) throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
MobileOperationProperty mobileOperationProperty = null; MobileOperationProperty mobileOperationProperty;
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>(); List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = 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 = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
ResultSet resultSet = stmt.executeQuery(); 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.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.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementSchemaInitializer; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementSchemaInitializer;
import javax.naming.InitialContext; import javax.naming.InitialContext;
@ -32,7 +30,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
/** /**
* Utility method required by MobileDeviceManagement DAO classes. * Utility method required by MobileDeviceManagement DAO classes.
@ -94,8 +91,8 @@ public class MobileDeviceManagementDAOUtil {
try { try {
initializer.createRegistryDatabase(); initializer.createRegistryDatabase();
} catch (Exception e) { } catch (Exception e) {
throw new DeviceManagementException("Error occurred while initializing Mobile Device Management " + throw new DeviceManagementException("Error occurred while initializing Mobile Device " +
"database schema", e); "Management database schema", e);
} }
} }

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

@ -40,15 +40,20 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerServic
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* BundleActivator of MobileDeviceManagement component.
*/
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener { public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
private ServiceRegistration androidServiceRegRef; private ServiceRegistration androidServiceRegRef;
private ServiceRegistration iOSServiceRegRef; private ServiceRegistration iOSServiceRegRef;
private ServiceRegistration windowsServiceRegRef; 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 String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT =
"org.wso2.carbon.ndatasource.core";
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class); private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
@Override @Override
@ -138,10 +143,12 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B
getApiPublisherConfig().getAPIs(); getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) { for (APIConfig apiConfig : apiConfigs) {
try { try {
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); APIProvider provider =
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
apiConfig.init(provider); apiConfig.init(provider);
} catch (APIManagementException e) { } catch (APIManagementException e) {
throw new DeviceManagementException("Error occurred while initializing API Config '" + throw new DeviceManagementException(
"Error occurred while initializing API Config '" +
apiConfig.getName() + "'", e); apiConfig.getName() + "'", e);
} }
} }

@ -23,11 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext; 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.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.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; 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 javax.sql.DataSource;
import java.io.File; import java.io.File;
/**
*
* Provides methods for initializing the database script.
*
*/
public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator { public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator {
private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class); 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) { private static Device.Property getProperty(String property, String value) {
Device.Property prop = null;
if (property != null) { if (property != null) {
prop = new Device.Property(); Device.Property prop = new Device.Property();
prop.setName(property); prop.setName(property);
prop.setValue(value); prop.setValue(value);
return prop; return prop;
} }
return prop; return null;
} }
public static MobileDevice convertToMobileDevice(Device device) { 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) { public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) {
MobileOperation mobileOperation = new MobileOperation(); MobileOperation mobileOperation = new MobileOperation();
MobileOperationProperty operationProperty = null; MobileOperationProperty operationProperty;
List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>(); List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
mobileOperation.setFeatureCode(operation.getCode()); mobileOperation.setFeatureCode(operation.getCode());
mobileOperation.setCreatedDate(new Date().getTime()); mobileOperation.setCreatedDate(new Date().getTime());

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

Loading…
Cancel
Save