Added operation persistance logic & refactored the code

revert-dabc3590
harshanL 10 years ago
parent dd9bfdb6a7
commit 193eca9e2d

@ -48,20 +48,20 @@ public interface FeaturePropertyDAO {
/** /**
* Delete a given feature property from feature property table. * Delete a given feature property from feature property table.
* *
* @param propertyId Id of the feature property to be deleted. * @param property Property of the feature property to be deleted.
* @return The status of the operation. If the operationId was successful or not. * @return The status of the operation. If the operationId was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean deleteFeatureProperty(int propertyId) throws MobileDeviceManagementDAOException; boolean deleteFeatureProperty(String property) throws MobileDeviceManagementDAOException;
/** /**
* Retrieve a given feature property from feature property table. * Retrieve a given feature property from feature property table.
* *
* @param propertyId Id of the feature property to be retrieved. * @param property Property of the feature property to be retrieved.
* @return Feature property object that holds data of the feature property represented by propertyId. * @return Feature property object that holds data of the feature property represented by propertyId.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
FeatureProperty getFeatureProperty(int propertyId) throws MobileDeviceManagementDAOException; FeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException;
/** /**
* Retrieve a list of feature property corresponds to a feature id . * Retrieve a list of feature property corresponds to a feature id .

@ -25,14 +25,14 @@ import java.util.List;
*/ */
public interface MobileDeviceDAO { public interface MobileDeviceDAO {
MobileDevice getDevice(String deviceId) throws MobileDeviceManagementDAOException; MobileDevice getMobileDevice(String deviceId) throws MobileDeviceManagementDAOException;
boolean addDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException; boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException;
boolean updateDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException; boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException;
boolean deleteDevice(String deviceId) throws MobileDeviceManagementDAOException; boolean deleteMobileDevice(String deviceId) throws MobileDeviceManagementDAOException;
List<MobileDevice> getAllDevices() throws MobileDeviceManagementDAOException; List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException;
} }

@ -53,16 +53,16 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener {
return new MobileDeviceDAOImpl(dataSource); return new MobileDeviceDAOImpl(dataSource);
} }
public static OperationDAO getOperationDAO() { public static MobileOperationDAO getMobileOperationDAO() {
return new OperationDAOImpl(dataSource); return new MobileOperationDAOImpl(dataSource);
} }
public static OperationPropertyDAO geOperationPropertyDAO() { public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
return new OperationPropertyDAOImpl(dataSource); return new MobileOperationPropertyDAOImpl(dataSource);
} }
public static DeviceOperationDAO getDeviceOperationDAO() { public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() {
return new DeviceOperationDAOImpl(dataSource); return new MobileDeviceOperationDAOImpl(dataSource);
} }
public static FeatureDAO getFeatureDAO() { public static FeatureDAO getFeatureDAO() {

@ -16,14 +16,14 @@
package org.wso2.carbon.device.mgt.mobile.dao; package org.wso2.carbon.device.mgt.mobile.dao;
import org.wso2.carbon.device.mgt.mobile.dto.DeviceOperation; import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation;
import java.util.List; import java.util.List;
/** /**
* This class represents the mapping between device and operations. * This class represents the mapping between device and operations.
*/ */
public interface DeviceOperationDAO { public interface MobileDeviceOperationDAO {
/** /**
* Add a new mapping to plugin device_operation table. * Add a new mapping to plugin device_operation table.
* *
@ -32,7 +32,7 @@ public interface DeviceOperationDAO {
* @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
*/ */
boolean addDeviceOperation(DeviceOperation deviceOperation) boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
@ -42,7 +42,7 @@ public interface DeviceOperationDAO {
* @return The status of the operation. If the update was successful or not. * @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean updateDeviceOperation(DeviceOperation deviceOperation) boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
@ -53,7 +53,7 @@ public interface DeviceOperationDAO {
* @return The status of the operation. If the deletion was successful or not. * @return The status of the operation. If the deletion was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean deleteDeviceOperation(String deviceId, int operationId) boolean deleteMobileDeviceOperation(String deviceId, int operationId)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
@ -65,7 +65,7 @@ public interface DeviceOperationDAO {
* deviceId and operationId. * deviceId and operationId.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
DeviceOperation getDeviceOperation(String deviceId, int operationId) MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
@ -74,6 +74,6 @@ public interface DeviceOperationDAO {
* @return Device operation mapping object list. * @return Device operation mapping object list.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
List<DeviceOperation> getAllDeviceOperationOfDevice(String deviceId) List<MobileDeviceOperation> getAllMobileDeviceOperationsOfDevice(String deviceId)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
} }

@ -16,46 +16,44 @@
package org.wso2.carbon.device.mgt.mobile.dao; package org.wso2.carbon.device.mgt.mobile.dao;
import org.wso2.carbon.device.mgt.mobile.dto.Operation; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
import java.util.List;
/** /**
* This class represents the key operations associated with persisting operation related * This class represents the key operations associated with persisting operation related
* information. * information.
*/ */
public interface OperationDAO { public interface MobileOperationDAO {
/** /**
* Add a new operation to plugin operation table. * Add a new Mobile operation to plugin operation table.
* @param operation Operation object that holds data related to the operation to be inserted. * @param operation Operation object that holds data related to the operation to be inserted.
* @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned. * @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
int addOperation(Operation operation) throws MobileDeviceManagementDAOException; int addMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException;
/** /**
* Update a operation in the operation table. * Update a Mobile operation in the operation table.
* @param operation Operation object that holds data has to be updated. * @param operation Operation object that holds data has to be updated.
* @return The status of the operation. If the update was successful or not. * @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean updateOperation(Operation operation) throws MobileDeviceManagementDAOException; boolean updateMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException;
/** /**
* Delete a given operation from plugin database. * Delete a given Mobile operation from plugin database.
* @param operationId Operation code of the operation to be deleted. * @param operationId Operation code of the operation to be deleted.
* @return The status of the operation. If the operationId was successful or not. * @return The status of the operation. If the operationId was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean deleteOperation(int operationId) throws MobileDeviceManagementDAOException; boolean deleteMobileOperation(int operationId) throws MobileDeviceManagementDAOException;
/** /**
* Retrieve a given operation from plugin database. * Retrieve a given Mobile operation from plugin database.
* @param operationId Operation id of the operation to be retrieved. * @param operationId Operation id of the operation to be retrieved.
* @return Operation object that holds data of the feature represented by operationId. * @return Operation object that holds data of the feature represented by operationId.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
Operation getOperation(int operationId) throws MobileDeviceManagementDAOException; MobileOperation getMobileOperation(int operationId) throws MobileDeviceManagementDAOException;
} }

@ -16,7 +16,7 @@
package org.wso2.carbon.device.mgt.mobile.dao; package org.wso2.carbon.device.mgt.mobile.dao;
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
import java.util.List; import java.util.List;
@ -24,15 +24,16 @@ import java.util.List;
* This class represents the key operations associated with persisting operation property related * This class represents the key operations associated with persisting operation property related
* information. * information.
*/ */
public interface OperationPropertyDAO { public interface MobileOperationPropertyDAO {
/** /**
* Add a new mapping to plugin operation property table. * Add a new mapping to plugin operation property table.
* *
* @param operationProperty OperationProperty object that holds data related to the operation property to be inserted. * @param operationProperty OperationProperty object that holds data related to the operation
* 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
*/ */
boolean addOperationProperty(OperationProperty operationProperty) boolean addMobileOperationProperty(MobileOperationProperty operationProperty)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
@ -42,36 +43,38 @@ public interface OperationPropertyDAO {
* @return The status of the operation. If the update was successful or not. * @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean updateOperationProperty(OperationProperty operationProperty) boolean updateMobileOperationProperty(MobileOperationProperty operationProperty)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
* Delete a given device operation from plugin database. * Deletes mobile operation properties of a given operation id from the plugin database.
* *
* @param operationPropertyId Device id of the mapping to be deleted. * @param operationId Operation id of the mapping to be deleted.
* @return The status of the operation. If the deletion was successful or not. * @return The status of the operation. If the deletion was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean deleteOperationProperty(int operationPropertyId) boolean deleteMobileOperationProperties(int operationId)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
* Retrieve a given device operation from plugin database. * Retrieve a given mobile operation property from plugin database.
* *
* @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 DeviceOperation object that holds data of the device operation mapping represented by deviceId and operationId. * @param property Property of the mapping to be retrieved.
* @return DeviceOperation object that holds data of the device operation mapping represented by
* deviceId and operationId.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
OperationProperty getOperationProperty(String deviceId, int operationId) MobileOperationProperty getMobileOperationProperty(int operationId, String property)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
* Retrieve all the device operation mapping from plugin database. * Retrieve all the mobile operation properties related to the a operation id.
* *
* @param operationId Operation id of the mapping to be retrieved.
* @return Device operation mapping object list. * @return Device operation mapping object list.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
List<OperationProperty> getAllDeviceOperationOfDevice(String deviceId) List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(int operationId)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
} }

@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Implementation of FeatureDAO * Implementation of FeatureDAO.
*/ */
public class FeatureDAOImpl implements FeatureDAO { public class FeatureDAOImpl implements FeatureDAO {

@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Implementation of FeaturePropertyDAO * Implementation of FeaturePropertyDAO.
*/ */
public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
@ -81,18 +81,17 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String updateDBQuery = String updateDBQuery =
"UPDATE MBL_FEATURE_PROPERTY SET PROPERTY = ?, FEATURE_ID = ? WHERE PROPERTY_ID = ?"; "UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?";
stmt = conn.prepareStatement(updateDBQuery); stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, featureProperty.getProperty()); stmt.setString(1, featureProperty.getFeatureID());
stmt.setString(2, featureProperty.getFeatureID()); stmt.setString(2, featureProperty.getProperty());
stmt.setInt(3, featureProperty.getPropertyId());
int rows = stmt.executeUpdate(); int rows = stmt.executeUpdate();
if (rows > 0) { if (rows > 0) {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating the feature property with property id - '" + String msg = "Error occurred while updating the feature property with property - '" +
featureProperty.getPropertyId() + "'"; featureProperty.getProperty() + "'";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -102,7 +101,7 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
} }
@Override @Override
public boolean deleteFeatureProperty(int propertyId) public boolean deleteFeatureProperty(String property)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -110,16 +109,16 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String deleteDBQuery = String deleteDBQuery =
"DELETE FROM MBL_FEATURE_PROPERTY WHERE PROPERTY_ID = ?"; "DELETE FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?";
stmt = conn.prepareStatement(deleteDBQuery); stmt = conn.prepareStatement(deleteDBQuery);
stmt.setInt(1, propertyId); stmt.setString(1, property);
int rows = stmt.executeUpdate(); int rows = stmt.executeUpdate();
if (rows > 0) { if (rows > 0) {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting feature property with property Id - " + String msg = "Error occurred while deleting feature property with property - " +
propertyId; property;
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -129,7 +128,7 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
} }
@Override @Override
public FeatureProperty getFeatureProperty(int propertyId) public FeatureProperty getFeatureProperty(String property)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -137,9 +136,9 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
"SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE PROPERTY_ID = ?"; "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?";
stmt = conn.prepareStatement(selectDBQuery); stmt = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, propertyId); stmt.setString(1, property);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
featureProperty = new FeatureProperty(); featureProperty = new FeatureProperty();
@ -148,8 +147,8 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
break; break;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while fetching property Id - '" + String msg = "Error occurred while fetching property - '" +
propertyId + "'"; property + "'";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -168,15 +167,14 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
"SELECT PROPERTY_ID,PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery); stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, featureId); stmt.setString(1, featureId);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
featureProperty = new FeatureProperty(); featureProperty = new FeatureProperty();
featureProperty.setPropertyId(resultSet.getInt(1)); featureProperty.setProperty(resultSet.getString(1));
featureProperty.setProperty(resultSet.getString(2)); featureProperty.setFeatureID(resultSet.getString(2));
featureProperty.setFeatureID(resultSet.getString(3));
FeatureProperties.add(featureProperty); FeatureProperties.add(featureProperty);
} }
return FeatureProperties; return FeatureProperties;

@ -44,7 +44,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
} }
@Override @Override
public MobileDevice getDevice(String deviceId) throws MobileDeviceManagementDAOException { public MobileDevice getMobileDevice(String deviceId) throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
MobileDevice mobileDevice = null; MobileDevice mobileDevice = null;
@ -80,7 +80,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
} }
@Override @Override
public boolean addDevice(MobileDevice mobileDevice) public boolean addMobileDevice(MobileDevice mobileDevice)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -106,8 +106,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while enrolling mobile device '" + String msg = "Error occurred while adding the mobile device '" +
mobileDevice.getMobileDeviceId() + "'"; mobileDevice.getMobileDeviceId() + "' to the mobile db.";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -117,7 +117,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
} }
@Override @Override
public boolean updateDevice(MobileDevice mobileDevice) public boolean updateMobileDevice(MobileDevice mobileDevice)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -153,7 +153,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
} }
@Override @Override
public boolean deleteDevice(String deviceId) throws MobileDeviceManagementDAOException { public boolean deleteMobileDevice(String deviceId) throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -178,7 +178,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
} }
@Override @Override
public List<MobileDevice> getAllDevices() throws MobileDeviceManagementDAOException { public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
MobileDevice mobileDevice; MobileDevice mobileDevice;

@ -18,10 +18,10 @@ 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.DeviceOperationDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationDAO;
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.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.dto.DeviceOperation; import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
@ -32,19 +32,19 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Implementation of DeviceOperationDAO * Implementation of MobileDeviceOperationDAO.
*/ */
public class DeviceOperationDAOImpl implements DeviceOperationDAO { public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
private DataSource dataSource; private DataSource dataSource;
private static final Log log = LogFactory.getLog(DeviceOperationDAOImpl.class); private static final Log log = LogFactory.getLog(MobileDeviceOperationDAOImpl.class);
public DeviceOperationDAOImpl(DataSource dataSource) { public MobileDeviceOperationDAOImpl(DataSource dataSource) {
this.dataSource = dataSource; this.dataSource = dataSource;
} }
@Override @Override
public boolean addDeviceOperation(DeviceOperation deviceOperation) public boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -66,7 +66,8 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding device id - '" + String msg = "Error occurred while adding device id - '" +
deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getDeviceId() + " and operation id - " +
deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION"; deviceOperation.getOperationId() +
" to mapping table MBL_DEVICE_OPERATION";
; ;
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
@ -77,7 +78,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} }
@Override @Override
public boolean updateDeviceOperation(DeviceOperation deviceOperation) public boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -85,7 +86,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
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 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());
@ -98,7 +99,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating device id - '" + String msg = "Error occurred while updating device id - '" +
deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getDeviceId() + " and operation id - " +
deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION"; deviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -108,7 +109,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} }
@Override @Override
public boolean deleteDeviceOperation(String deviceId, int operationId) public boolean deleteMobileDeviceOperation(String deviceId, int operationId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -116,7 +117,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
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 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);
@ -126,7 +127,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = String msg =
"Error occurred while deleting mapping table MBL_DEVICE_OPERATION with device id - '" + "Error occurred while deleting the table entry MBL_DEVICE_OPERATION with device id - '" +
deviceId + " and operation id - " + operationId; deviceId + " and operation id - " + operationId;
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
@ -137,21 +138,21 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} }
@Override @Override
public DeviceOperation getDeviceOperation(String deviceId, int operationId) public MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
DeviceOperation deviceOperation = null; MobileDeviceOperation deviceOperation = null;
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 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()) { while (resultSet.next()) {
deviceOperation = new DeviceOperation(); deviceOperation = new MobileDeviceOperation();
deviceOperation.setDeviceId(resultSet.getString(1)); deviceOperation.setDeviceId(resultSet.getString(1));
deviceOperation.setOperationId(resultSet.getInt(2)); deviceOperation.setOperationId(resultSet.getInt(2));
deviceOperation.setSentDate(resultSet.getInt(3)); deviceOperation.setSentDate(resultSet.getInt(3));
@ -160,7 +161,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = String msg =
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" + "Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" +
deviceId + " and operation id - " + operationId; deviceId + " and operation id - " + operationId;
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
@ -171,12 +172,12 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
} }
@Override @Override
public List<DeviceOperation> getAllDeviceOperationOfDevice(String deviceId) public List<MobileDeviceOperation> getAllMobileDeviceOperationsOfDevice(String deviceId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
DeviceOperation deviceOperation = null; MobileDeviceOperation deviceOperation = null;
List<DeviceOperation> deviceOperations = new ArrayList<DeviceOperation>(); List<MobileDeviceOperation> deviceOperations = new ArrayList<MobileDeviceOperation>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -185,17 +186,16 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO {
stmt.setString(1, deviceId); stmt.setString(1, deviceId);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
deviceOperation = new DeviceOperation(); deviceOperation = new MobileDeviceOperation();
deviceOperation.setDeviceId(resultSet.getString(1)); deviceOperation.setDeviceId(resultSet.getString(1));
deviceOperation.setOperationId(resultSet.getInt(2)); deviceOperation.setOperationId(resultSet.getInt(2));
deviceOperation.setSentDate(resultSet.getInt(3)); deviceOperation.setSentDate(resultSet.getInt(3));
deviceOperation.setReceivedDate(resultSet.getInt(4)); deviceOperation.setReceivedDate(resultSet.getInt(4));
deviceOperations.add(deviceOperation); deviceOperations.add(deviceOperation);
break;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = String msg =
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" + "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of device id - '" +
deviceId; deviceId;
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);

@ -19,9 +19,9 @@ 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.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.OperationDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationDAO;
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.Operation; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
@ -30,19 +30,19 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* Implementation of OperationDAO * Implementation of MobileOperationDAO.
*/ */
public class OperationDAOImpl implements OperationDAO { public class MobileOperationDAOImpl implements MobileOperationDAO {
private DataSource dataSource; private DataSource dataSource;
private static final Log log = LogFactory.getLog(OperationDAOImpl.class); private static final Log log = LogFactory.getLog(MobileOperationDAOImpl.class);
public OperationDAOImpl(DataSource dataSource) { public MobileOperationDAOImpl(DataSource dataSource) {
this.dataSource = dataSource; this.dataSource = dataSource;
} }
@Override @Override
public int addOperation(Operation operation) public int addMobileOperation(MobileOperation operation)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
int status = -1; int status = -1;
Connection conn = null; Connection conn = null;
@ -51,7 +51,6 @@ public class OperationDAOImpl implements OperationDAO {
conn = this.getConnection(); conn = this.getConnection();
String createDBQuery = String createDBQuery =
"INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; "INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)";
stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" }); stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" });
stmt.setString(1, operation.getFeatureCode()); stmt.setString(1, operation.getFeatureCode());
stmt.setLong(2, operation.getCreatedDate()); stmt.setLong(2, operation.getCreatedDate());
@ -63,8 +62,8 @@ public class OperationDAOImpl implements OperationDAO {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding feature code - '" + String msg = "Error occurred while adding the operation - '" +
operation.getFeatureCode() + "' to operations table"; operation.getFeatureCode() + "' to MBL_OPERATION table";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -74,7 +73,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public boolean updateOperation(Operation operation) public boolean updateMobileOperation(MobileOperation operation)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -92,7 +91,7 @@ public class OperationDAOImpl implements OperationDAO {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating the operation with operation id - '" + String msg = "Error occurred while updating the MBL_OPERATION table entry with operation id - '" +
operation.getOperationId() + "'"; operation.getOperationId() + "'";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
@ -103,7 +102,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public boolean deleteOperation(int operationId) public boolean deleteMobileOperation(int operationId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -119,7 +118,7 @@ public class OperationDAOImpl implements OperationDAO {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting operation with operation Id - "; String msg = "Error occurred while deleting MBL_OPERATION entry with operation Id - ";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -129,11 +128,11 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public Operation getOperation(int operationId) public MobileOperation getMobileOperation(int operationId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
Operation operation = null; MobileOperation operation = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -142,13 +141,13 @@ public class OperationDAOImpl implements OperationDAO {
stmt.setInt(1, operation.getOperationId()); stmt.setInt(1, operation.getOperationId());
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
operation = new Operation(); operation = new MobileOperation();
operation.setOperationId(resultSet.getInt(1)); operation.setOperationId(resultSet.getInt(1));
break; break;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while fetching operationId - '" + String msg = "Error occurred while fetching operationId - '" +
operationId + "'"; operationId + "' from MBL_OPERATION";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {

@ -0,0 +1,212 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.device.mgt.mobile.dao.impl;
import org.apache.commons.logging.Log;
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;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Implementation of MobileOperationPropertyDAO.
*/
public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDAO {
private DataSource dataSource;
private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOImpl.class);
public MobileOperationPropertyDAOImpl(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public boolean addMobileOperationProperty(MobileOperationProperty operationProperty)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String createDBQuery =
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) VALUES ( ?, ?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt.setInt(1, operationProperty.getOperationId());
stmt.setString(2, operationProperty.getProperty());
stmt.setString(3, operationProperty.getValue());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
}
} catch (SQLException e) {
String msg =
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY table";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return status;
}
@Override
public boolean updateMobileOperationProperty(
MobileOperationProperty operationProperty)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String createDBQuery =
"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());
stmt.setString(3, operationProperty.getProperty());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
}
} catch (SQLException e) {
String msg =
"Error occurred while updating the mobile operation property in MBL_OPERATION_PROPERTY table.";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return status;
}
@Override
public boolean deleteMobileOperationProperties(int operationId)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String deleteDBQuery =
"DELETE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setInt(1, operationId);
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
}
} catch (SQLException e) {
String msg =
"Error occurred while deleting MBL_OPERATION_PROPERTY entry with operation Id - ";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return status;
}
@Override
public MobileOperationProperty getMobileOperationProperty(int operationId,
String property)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileOperationProperty mobileOperationProperty = null;
try {
conn = this.getConnection();
String selectDBQuery =
"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()) {
mobileOperationProperty = new MobileOperationProperty();
mobileOperationProperty.setOperationId(resultSet.getInt(1));
mobileOperationProperty.setProperty(resultSet.getString(2));
mobileOperationProperty.setValue(resultSet.getString(3));
break;
}
} catch (SQLException e) {
String msg =
"Error occurred while fetching the mobile operation property of Operation_id : " +
operationId + " and Property : " + property;
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return mobileOperationProperty;
}
@Override
public List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(
int operationId) throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileOperationProperty mobileOperationProperty = null;
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setInt(1, operationId);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
mobileOperationProperty = new MobileOperationProperty();
mobileOperationProperty.setOperationId(resultSet.getInt(1));
mobileOperationProperty.setProperty(resultSet.getString(2));
mobileOperationProperty.setValue(resultSet.getString(3));
properties.add(mobileOperationProperty);
}
} catch (SQLException e) {
String msg =
"Error occurred while fetching the mobile operation properties of Operation_id " +
operationId;
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return properties;
}
private Connection getConnection() throws MobileDeviceManagementDAOException {
try {
return dataSource.getConnection();
} catch (SQLException e) {
String msg = "Error occurred while obtaining a connection from the mobile device " +
"management metadata repository datasource.";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
}
}
}

@ -1,103 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.device.mgt.mobile.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.OperationPropertyDAO;
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
/**
* Implementation of OperationPropertyDAO
*/
public class OperationPropertyDAOImpl implements OperationPropertyDAO {
private DataSource dataSource;
private static final Log log = LogFactory.getLog(OperationPropertyDAOImpl.class);
public OperationPropertyDAOImpl(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public boolean addOperationProperty(OperationProperty operationProperty)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String createDBQuery =
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY_ID, VALUE) VALUES ( ?, ?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt.setInt(1, operationProperty.getOperationId());
stmt.setInt(2, operationProperty.getPropertyId());
stmt.setString(3, operationProperty.getValue());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
}
} catch (SQLException e) {
String msg = "Error occurred while adding feature property to operation property table";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return status;
}
@Override public boolean updateOperationProperty(OperationProperty operationProperty)
throws MobileDeviceManagementDAOException {
return false;
}
@Override public boolean deleteOperationProperty(int operationPropertyId)
throws MobileDeviceManagementDAOException {
return false;
}
@Override public OperationProperty getOperationProperty(String deviceId, int operationId)
throws MobileDeviceManagementDAOException {
return null;
}
@Override public List<OperationProperty> getAllDeviceOperationOfDevice(String deviceId)
throws MobileDeviceManagementDAOException {
return null;
}
private Connection getConnection() throws MobileDeviceManagementDAOException {
try {
return dataSource.getConnection();
} catch (SQLException e) {
String msg = "Error occurred while obtaining a connection from the mobile device " +
"management metadata repository datasource.";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
}
}
}

@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.dto;
*/ */
public class FeatureProperty { public class FeatureProperty {
private int propertyId;
private String property; private String property;
private String featureID; private String featureID;
@ -33,14 +32,6 @@ public class FeatureProperty {
this.featureID = featureID; this.featureID = featureID;
} }
public int getPropertyId() {
return propertyId;
}
public void setPropertyId(int propertyId) {
this.propertyId = propertyId;
}
public String getProperty() { public String getProperty() {
return property; return property;
} }

@ -17,9 +17,9 @@
package org.wso2.carbon.device.mgt.mobile.dto; package org.wso2.carbon.device.mgt.mobile.dto;
/** /**
* DTO of Operations. * DTO of Mobile Device Operations.
*/ */
public class DeviceOperation { public class MobileDeviceOperation {
private String deviceId; private String deviceId;
private int operationId; private int operationId;

@ -19,14 +19,14 @@ package org.wso2.carbon.device.mgt.mobile.dto;
import java.util.List; import java.util.List;
/** /**
* DTO of operation. * DTO of MobileOperation.
*/ */
public class Operation { public class MobileOperation {
private int operationId; private int operationId;
private String featureCode; private String featureCode;
private long createdDate; private long createdDate;
private List<OperationProperty> properties; private List<MobileOperationProperty> properties;
public int getOperationId() { public int getOperationId() {
return operationId; return operationId;
@ -36,11 +36,11 @@ public class Operation {
this.operationId = operationId; this.operationId = operationId;
} }
public List<OperationProperty> getProperties() { public List<MobileOperationProperty> getProperties() {
return properties; return properties;
} }
public void setProperties(List<OperationProperty> properties) { public void setProperties(List<MobileOperationProperty> properties) {
this.properties = properties; this.properties = properties;
} }

@ -17,13 +17,12 @@
package org.wso2.carbon.device.mgt.mobile.dto; package org.wso2.carbon.device.mgt.mobile.dto;
/** /**
* DTO of operation property. * DTO of Mobile Operation property.
*/ */
public class OperationProperty { public class MobileOperationProperty {
private int operationPropertyId;
private int operationId; private int operationId;
private int propertyId; private String property;
private String value; private String value;
public String getValue() { public String getValue() {
@ -34,14 +33,6 @@ public class OperationProperty {
this.value = value; this.value = value;
} }
public int getOperationPropertyId() {
return operationPropertyId;
}
public void setOperationPropertyId(int operationPropertyId) {
this.operationPropertyId = operationPropertyId;
}
public int getOperationId() { public int getOperationId() {
return operationId; return operationId;
} }
@ -50,12 +41,12 @@ public class OperationProperty {
this.operationId = operationId; this.operationId = operationId;
} }
public int getPropertyId() { public String getProperty() {
return propertyId; return property;
} }
public void setPropertyId(int propertyId) { public void setProperty(String property) {
this.propertyId = propertyId; this.property = property;
} }
} }

@ -50,7 +50,8 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addDevice(mobileDevice); status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while enrolling the Android device : " + String msg = "Error while enrolling the Android device : " +
device.getDeviceIdentifier(); device.getDeviceIdentifier();
@ -66,7 +67,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateDevice(mobileDevice); .updateMobileDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while updating the enrollment of the Android device : " + String msg = "Error while updating the enrollment of the Android device : " +
device.getDeviceIdentifier(); device.getDeviceIdentifier();
@ -81,7 +82,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
boolean status; boolean status;
try { try {
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.deleteDevice(deviceId.getId()); .deleteMobileDevice(deviceId.getId());
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while removing the Android device : " + deviceId.getId(); String msg = "Error while removing the Android device : " + deviceId.getId();
log.error(msg, e); log.error(msg, e);
@ -95,7 +96,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
boolean isEnrolled = false; boolean isEnrolled = false;
try { try {
MobileDevice mobileDevice = MobileDevice mobileDevice =
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getDevice( MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId()); deviceId.getId());
if (mobileDevice != null) { if (mobileDevice != null) {
isEnrolled = true; isEnrolled = true;
@ -125,7 +126,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
Device device; Device device;
try { try {
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getDevice(deviceId.getId()); getMobileDevice(deviceId.getId());
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching the Android device : " + deviceId.getId(); String msg = "Error while fetching the Android device : " + deviceId.getId();
@ -147,7 +148,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateDevice(mobileDevice); .updateMobileDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); String msg = "Error while updating the Android device : " + device.getDeviceIdentifier();
log.error(msg, e); log.error(msg, e);
@ -162,7 +163,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
try { try {
List<MobileDevice> mobileDevices = List<MobileDevice> mobileDevices =
MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getAllDevices(); getAllMobileDevices();
if (mobileDevices != null) { if (mobileDevices != null) {
devices = new ArrayList<Device>(); devices = new ArrayList<Device>();
for (MobileDevice mobileDevice : mobileDevices) { for (MobileDevice mobileDevice : mobileDevices) {

@ -18,15 +18,17 @@ package org.wso2.carbon.device.mgt.mobile.impl.android;
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.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Operation; import org.wso2.carbon.device.mgt.common.Operation;
import org.wso2.carbon.device.mgt.common.OperationManagementException; import org.wso2.carbon.device.mgt.common.OperationManagementException;
import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager; import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dto.DeviceOperation; import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation;
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty; 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.util.MobileDeviceManagementUtil;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class AndroidMobileOperationManager extends AbstractMobileOperationManager { public class AndroidMobileOperationManager extends AbstractMobileOperationManager {
@ -36,26 +38,67 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
@Override @Override
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
OperationManagementException { OperationManagementException {
boolean status = false;
try { try {
MobileDeviceManagementDAOFactory.getOperationDAO().addOperation( MobileDeviceOperation mobileDeviceOperation = null;
new org.wso2.carbon.device.mgt.mobile.dto.Operation()); MobileOperation mobileOperation =
MobileDeviceManagementDAOFactory.geOperationPropertyDAO() MobileDeviceManagementUtil.convertToMobileOperation(operation);
.addOperationProperty(new OperationProperty()); int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
MobileDeviceManagementDAOFactory.getDeviceOperationDAO() .addMobileOperation(mobileOperation);
.addDeviceOperation(new DeviceOperation()); if (operationId > 0) {
for (MobileOperationProperty operationProperty : mobileOperation.getProperties()) {
operationProperty.setOperationId(operationId);
status = MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
.addMobileOperationProperty(
operationProperty);
}
for (DeviceIdentifier deviceIdentifier : devices) {
mobileDeviceOperation = new MobileDeviceOperation();
mobileDeviceOperation.setOperationId(operationId);
mobileDeviceOperation.setDeviceId(deviceIdentifier.getId());
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.addMobileDeviceOperation(
new MobileDeviceOperation());
}
}
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while updating the enrollment of the Android device : " + String msg =
devices.get(0).getId(); "Error while adding an operation " + operation.getCode() + "to Android devices";
log.error(msg, e); log.error(msg, e);
throw new OperationManagementException(msg, e); throw new OperationManagementException(msg, e);
} }
return false; return status;
} }
@Override @Override
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier) public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException { throws OperationManagementException {
return null; List<Operation> operations = new ArrayList<Operation>();
List<MobileDeviceOperation> mobileDeviceOperations = null;
MobileOperation mobileOperation = null;
try {
mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllMobileDeviceOperationsOfDevice(
deviceIdentifier
.getId());
if (mobileDeviceOperations.size() > 0) {
List<Integer> operationIds = MobileDeviceManagementUtil
.getMobileOperationIdsFromMobileDeviceOperations(mobileDeviceOperations);
for (Integer operationId : operationIds) {
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
.getMobileOperation(
operationId);
operations.add(MobileDeviceManagementUtil
.convertMobileOperationToOperation(mobileOperation));
}
}
} catch (MobileDeviceManagementDAOException e) {
String msg =
"Error while fetching the operations for the android device " +
deviceIdentifier.getId();
log.error(msg, e);
throw new OperationManagementException(msg, e);
}
return operations;
} }
} }

@ -21,9 +21,11 @@ import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Operation;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
import org.wso2.carbon.device.mgt.mobile.dto.Operation; import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation;
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -114,15 +116,41 @@ public class MobileDeviceManagementUtil {
return device; return device;
} }
public static Operation convertToOperation(org.wso2.carbon.device.mgt.common.Operation operation){ public static MobileOperation convertToMobileOperation(
Operation mobileOperation = new Operation(); org.wso2.carbon.device.mgt.common.Operation operation) {
List<OperationProperty> properties = new LinkedList<OperationProperty>(); MobileOperation mobileOperation = new MobileOperation();
MobileOperationProperty operationProperty = null;
List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
mobileOperation.setFeatureCode(operation.getCode()); mobileOperation.setFeatureCode(operation.getCode());
mobileOperation.setCreatedDate(new Date().getTime()); mobileOperation.setCreatedDate(new Date().getTime());
Properties operationProperties = operation.getProperties(); Properties operationProperties = operation.getProperties();
for (String key : operationProperties.stringPropertyNames()) { for (String key : operationProperties.stringPropertyNames()) {
String value = operationProperties.getProperty(key); operationProperty = new MobileOperationProperty();
operationProperty.setProperty(key);
operationProperty.setValue(operationProperties.getProperty(key));
properties.add(operationProperty);
} }
mobileOperation.setProperties(properties);
return mobileOperation; return mobileOperation;
} }
public static List<Integer> getMobileOperationIdsFromMobileDeviceOperations(
List<MobileDeviceOperation> mobileDeviceOperations) {
List<Integer> mobileOperationIds = new ArrayList<Integer>();
for(MobileDeviceOperation mobileDeviceOperation:mobileDeviceOperations){
mobileOperationIds.add(mobileDeviceOperation.getOperationId());
}
return mobileOperationIds;
}
public static Operation convertMobileOperationToOperation(MobileOperation mobileOperation){
Operation operation = new Operation();
Properties properties = new Properties();
operation.setCode(mobileOperation.getFeatureCode());
for(MobileOperationProperty mobileOperationProperty:mobileOperation.getProperties()){
properties.put(mobileOperationProperty.getProperty(),mobileOperationProperty.getValue());
}
operation.setProperties(properties);
return operation;
}
} }

@ -20,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`) );
@ -30,7 +30,7 @@ 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` INT NULL ,
PRIMARY KEY (`OPERATION_ID`) , PRIMARY KEY (`OPERATION_ID`) ,
CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1` CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1`
@ -40,9 +40,9 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION` (
ON UPDATE 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` INT NULL ,
@ -63,11 +63,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` )
@ -78,13 +77,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);

@ -3,12 +3,14 @@
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
`MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL,
`REG_ID` VARCHAR(45) NULL, `REG_ID` VARCHAR(45) NULL DEFAULT NULL,
`IMEI` VARCHAR(45) NULL, `IMEI` VARCHAR(45) NULL DEFAULT NULL,
`IMSI` VARCHAR(45) NULL, `IMSI` VARCHAR(45) NULL DEFAULT NULL,
`OS_VERSION` VARCHAR(45) NULL, `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
`DEVICE_MODEL` VARCHAR(45) NULL, `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
`VENDOR` VARCHAR(45) 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`))
ENGINE = InnoDB; ENGINE = InnoDB;
@ -32,20 +34,14 @@ 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) NULL,
`CREATED_DATE` INT NULL, `CREATED_DATE` INT NULL,
PRIMARY KEY (`OPERATION_ID`) , PRIMARY KEY (`OPERATION_ID`))
INDEX `fk_MBL_OPERATION_MBL_FEATURES1_idx` (`FEATURE_CODE` ASC) ,
CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1`
FOREIGN KEY (`FEATURE_CODE` )
REFERENCES `MBL_FEATURE` (`CODE` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `MBL_DEVICE_OPERATION_MAPING` -- Table `MBL_DEVICE_OPERATION_MAPING`
-- ----------------------------------------------------- -- -----------------------------------------------------
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` INT NULL,

@ -40,7 +40,8 @@ public class Operation {
@GET @GET
@Path("{id}") @Path("{id}")
public List<org.wso2.carbon.device.mgt.common.Operation> getAllOperations(@PathParam("id") String id) public List<org.wso2.carbon.device.mgt.common.Operation> getAllOperations(
@PathParam("id") String id)
throws AndroidAgentException { throws AndroidAgentException {
List<org.wso2.carbon.device.mgt.common.Operation> operations; List<org.wso2.carbon.device.mgt.common.Operation> operations;
@ -49,19 +50,16 @@ public class Operation {
try { try {
dmService = AndroidAPIUtils.getDeviceManagementService(); dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
msg = "Device management service error";
log.error(msg, deviceMgtServiceEx);
throw new AndroidAgentException(msg, deviceMgtServiceEx);
}
try {
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
operations = dmService.getOperationManager( operations = dmService.getOperationManager(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID) DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID)
.getOperations(deviceIdentifier); .getOperations(deviceIdentifier);
Response.status(HttpStatus.SC_OK); Response.status(HttpStatus.SC_OK);
return operations; return operations;
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
msg = "Device management service error";
log.error(msg, deviceMgtServiceEx);
throw new AndroidAgentException(msg, deviceMgtServiceEx);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
msg = "Error occurred while fetching the operation manager for the device type."; msg = "Error occurred while fetching the operation manager for the device type.";
log.error(msg, e); log.error(msg, e);
@ -77,21 +75,11 @@ public class Operation {
@PUT @PUT
public Message updateOperation() throws AndroidAgentException { public Message updateOperation() throws AndroidAgentException {
String msg; String msg;
DeviceManagementService dmService; DeviceManagementService dmService;
Message responseMsg = new Message(); Message responseMsg = new Message();
try { try {
dmService = AndroidAPIUtils.getDeviceManagementService(); dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
msg = "Device management service error";
log.error(msg, deviceMgtServiceEx);
throw new AndroidAgentException(msg, deviceMgtServiceEx);
}
try {
boolean result = dmService.getOperationManager("").addOperation(null, null); boolean result = dmService.getOperationManager("").addOperation(null, null);
if (result) { if (result) {
Response.status(HttpStatus.SC_OK); Response.status(HttpStatus.SC_OK);
@ -101,6 +89,10 @@ public class Operation {
responseMsg.setResponseMessage("Operation not found"); responseMsg.setResponseMessage("Operation not found");
} }
return responseMsg; return responseMsg;
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
msg = "Device management service error";
log.error(msg, deviceMgtServiceEx);
throw new AndroidAgentException(msg, deviceMgtServiceEx);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
msg = "Error occurred while fetching the operation manager for the device type."; msg = "Error occurred while fetching the operation manager for the device type.";
log.error(msg, e); log.error(msg, e);

@ -50,16 +50,13 @@ public class Operation {
OperationManager operationManager; OperationManager operationManager;
try { try {
dmService = CDMAPIUtils.getDeviceManagementService(); dmService = CDMAPIUtils.getDeviceManagementService();
operationManager = dmService.getOperationManager(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
operations = operationManager.getOperations(null);
} catch (DeviceManagementServiceException deviceServiceMgtEx) { } catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error"; String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx); log.error(errorMsg, deviceServiceMgtEx);
throw new CDMAPIException(errorMsg, deviceServiceMgtEx); throw new CDMAPIException(errorMsg, deviceServiceMgtEx);
}
try {
operationManager = dmService.getOperationManager(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
operations = operationManager.getOperations(null);
} catch (DeviceManagementException deviceMgtEx) { } catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while fetching the operation manager."; String errorMsg = "Error occurred while fetching the operation manager.";
log.error(errorMsg, deviceMgtEx); log.error(errorMsg, deviceMgtEx);
@ -79,13 +76,6 @@ public class Operation {
Message responseMsg = new Message(); Message responseMsg = new Message();
try { try {
dmService = CDMAPIUtils.getDeviceManagementService(); dmService = CDMAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx);
throw new CDMAPIException(errorMsg, deviceServiceMgtEx);
}
try {
operationManager = dmService.getOperationManager( operationManager = dmService.getOperationManager(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
boolean status = operationManager.addOperation(operationContext.getOperation(), boolean status = operationManager.addOperation(operationContext.getOperation(),
@ -98,6 +88,10 @@ public class Operation {
responseMsg.setResponseMessage("Failure in adding the Operation."); responseMsg.setResponseMessage("Failure in adding the Operation.");
} }
return responseMsg; return responseMsg;
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx);
throw new CDMAPIException(errorMsg, deviceServiceMgtEx);
} catch (DeviceManagementException deviceMgtEx) { } catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while adding the operation"; String errorMsg = "Error occurred while adding the operation";
log.error(errorMsg, deviceMgtEx); log.error(errorMsg, deviceMgtEx);

Loading…
Cancel
Save