diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java index 7a023be3281..adf014dc7d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java @@ -48,20 +48,20 @@ public interface FeaturePropertyDAO { /** * 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. * @throws MobileDeviceManagementDAOException */ - boolean deleteFeatureProperty(int propertyId) throws MobileDeviceManagementDAOException; + boolean deleteFeatureProperty(String property) throws MobileDeviceManagementDAOException; /** * 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. * @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 . diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceDAO.java index c1eb2c33390..3ef6eb92f26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceDAO.java @@ -25,14 +25,14 @@ import java.util.List; */ 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 getAllDevices() throws MobileDeviceManagementDAOException; + List getAllMobileDevices() throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java index dc270e5ff6b..ddaf0adf82d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java @@ -53,16 +53,16 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener { return new MobileDeviceDAOImpl(dataSource); } - public static OperationDAO getOperationDAO() { - return new OperationDAOImpl(dataSource); + public static MobileOperationDAO getMobileOperationDAO() { + return new MobileOperationDAOImpl(dataSource); } - public static OperationPropertyDAO geOperationPropertyDAO() { - return new OperationPropertyDAOImpl(dataSource); + public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { + return new MobileOperationPropertyDAOImpl(dataSource); } - public static DeviceOperationDAO getDeviceOperationDAO() { - return new DeviceOperationDAOImpl(dataSource); + public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() { + return new MobileDeviceOperationDAOImpl(dataSource); } public static FeatureDAO getFeatureDAO() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/DeviceOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationDAO.java similarity index 83% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/DeviceOperationDAO.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationDAO.java index b0f24f7240a..ad2710e2f6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/DeviceOperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationDAO.java @@ -16,14 +16,14 @@ 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; /** * This class represents the mapping between device and operations. */ -public interface DeviceOperationDAO { +public interface MobileDeviceOperationDAO { /** * 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. * @throws MobileDeviceManagementDAOException */ - boolean addDeviceOperation(DeviceOperation deviceOperation) + boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation) throws MobileDeviceManagementDAOException; /** @@ -42,7 +42,7 @@ public interface DeviceOperationDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateDeviceOperation(DeviceOperation deviceOperation) + boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation) throws MobileDeviceManagementDAOException; /** @@ -53,7 +53,7 @@ public interface DeviceOperationDAO { * @return The status of the operation. If the deletion was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean deleteDeviceOperation(String deviceId, int operationId) + boolean deleteMobileDeviceOperation(String deviceId, int operationId) throws MobileDeviceManagementDAOException; /** @@ -65,7 +65,7 @@ public interface DeviceOperationDAO { * deviceId and operationId. * @throws MobileDeviceManagementDAOException */ - DeviceOperation getDeviceOperation(String deviceId, int operationId) + MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId) throws MobileDeviceManagementDAOException; /** @@ -74,6 +74,6 @@ public interface DeviceOperationDAO { * @return Device operation mapping object list. * @throws MobileDeviceManagementDAOException */ - List getAllDeviceOperationOfDevice(String deviceId) + List getAllMobileDeviceOperationsOfDevice(String deviceId) throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java similarity index 70% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java index dc00711688f..bdd69c7edfa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java @@ -16,46 +16,44 @@ package org.wso2.carbon.device.mgt.mobile.dao; -import org.wso2.carbon.device.mgt.mobile.dto.Operation; - -import java.util.List; +import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; /** * This class represents the key operations associated with persisting operation related * 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. * @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned. * @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. * @return The status of the operation. If the update was successful or not. * @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. * @return The status of the operation. If the operationId was successful or not. * @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. * @return Operation object that holds data of the feature represented by operationId. * @throws MobileDeviceManagementDAOException */ - Operation getOperation(int operationId) throws MobileDeviceManagementDAOException; + MobileOperation getMobileOperation(int operationId) throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationPropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java similarity index 65% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationPropertyDAO.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java index d4d0c451ddf..4d8ef7eebbd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationPropertyDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java @@ -16,7 +16,7 @@ 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; @@ -24,15 +24,16 @@ import java.util.List; * This class represents the key operations associated with persisting operation property related * information. */ -public interface OperationPropertyDAO { +public interface MobileOperationPropertyDAO { /** * 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. * @throws MobileDeviceManagementDAOException */ - boolean addOperationProperty(OperationProperty operationProperty) + boolean addMobileOperationProperty(MobileOperationProperty operationProperty) throws MobileDeviceManagementDAOException; /** @@ -42,36 +43,38 @@ public interface OperationPropertyDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateOperationProperty(OperationProperty operationProperty) + boolean updateMobileOperationProperty(MobileOperationProperty operationProperty) 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. * @throws MobileDeviceManagementDAOException */ - boolean deleteOperationProperty(int operationPropertyId) + boolean deleteMobileOperationProperties(int operationId) 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. - * @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 */ - OperationProperty getOperationProperty(String deviceId, int operationId) + MobileOperationProperty getMobileOperationProperty(int operationId, String property) 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. * @throws MobileDeviceManagementDAOException */ - List getAllDeviceOperationOfDevice(String deviceId) + List getAllMobileOperationPropertiesOfOperation(int operationId) throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java index bd30662a4d1..429349e1867 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java @@ -32,7 +32,7 @@ import java.util.ArrayList; import java.util.List; /** - * Implementation of FeatureDAO + * Implementation of FeatureDAO. */ public class FeatureDAOImpl implements FeatureDAO { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java index e81b25208db..4c623fad3e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java @@ -32,7 +32,7 @@ import java.util.ArrayList; import java.util.List; /** - * Implementation of FeaturePropertyDAO + * Implementation of FeaturePropertyDAO. */ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { @@ -81,18 +81,17 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { try { conn = this.getConnection(); 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.setString(1, featureProperty.getProperty()); - stmt.setString(2, featureProperty.getFeatureID()); - stmt.setInt(3, featureProperty.getPropertyId()); + stmt.setString(1, featureProperty.getFeatureID()); + stmt.setString(2, featureProperty.getProperty()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; } } catch (SQLException e) { - String msg = "Error occurred while updating the feature property with property id - '" + - featureProperty.getPropertyId() + "'"; + String msg = "Error occurred while updating the feature property with property - '" + + featureProperty.getProperty() + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -102,7 +101,7 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { } @Override - public boolean deleteFeatureProperty(int propertyId) + public boolean deleteFeatureProperty(String property) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -110,16 +109,16 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_FEATURE_PROPERTY WHERE PROPERTY_ID = ?"; + "DELETE FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?"; stmt = conn.prepareStatement(deleteDBQuery); - stmt.setInt(1, propertyId); + stmt.setString(1, property); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; } } catch (SQLException e) { - String msg = "Error occurred while deleting feature property with property Id - " + - propertyId; + String msg = "Error occurred while deleting feature property with property - " + + property; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -129,7 +128,7 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { } @Override - public FeatureProperty getFeatureProperty(int propertyId) + public FeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -137,9 +136,9 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { try { conn = this.getConnection(); 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.setInt(1, propertyId); + stmt.setString(1, property); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { featureProperty = new FeatureProperty(); @@ -148,8 +147,8 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { break; } } catch (SQLException e) { - String msg = "Error occurred while fetching property Id - '" + - propertyId + "'"; + String msg = "Error occurred while fetching property - '" + + property + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -168,15 +167,14 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { try { conn = this.getConnection(); 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.setString(1, featureId); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { featureProperty = new FeatureProperty(); - featureProperty.setPropertyId(resultSet.getInt(1)); - featureProperty.setProperty(resultSet.getString(2)); - featureProperty.setFeatureID(resultSet.getString(3)); + featureProperty.setProperty(resultSet.getString(1)); + featureProperty.setFeatureID(resultSet.getString(2)); FeatureProperties.add(featureProperty); } return FeatureProperties; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java index ee81a893f20..ef75ac0b026 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java @@ -44,7 +44,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { } @Override - public MobileDevice getDevice(String deviceId) throws MobileDeviceManagementDAOException { + public MobileDevice getMobileDevice(String deviceId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; MobileDevice mobileDevice = null; @@ -80,7 +80,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { } @Override - public boolean addDevice(MobileDevice mobileDevice) + public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -106,8 +106,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { status = true; } } catch (SQLException e) { - String msg = "Error occurred while enrolling mobile device '" + - mobileDevice.getMobileDeviceId() + "'"; + String msg = "Error occurred while adding the mobile device '" + + mobileDevice.getMobileDeviceId() + "' to the mobile db."; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -117,7 +117,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { } @Override - public boolean updateDevice(MobileDevice mobileDevice) + public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -153,7 +153,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { } @Override - public boolean deleteDevice(String deviceId) throws MobileDeviceManagementDAOException { + public boolean deleteMobileDevice(String deviceId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; PreparedStatement stmt = null; @@ -178,7 +178,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { } @Override - public List getAllDevices() throws MobileDeviceManagementDAOException { + public List getAllMobileDevices() throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; MobileDevice mobileDevice; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java similarity index 78% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java index 0baf28f2f08..e2d24e5e9bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java @@ -18,10 +18,10 @@ 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.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.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 java.sql.Connection; @@ -32,19 +32,19 @@ import java.util.ArrayList; import java.util.List; /** - * Implementation of DeviceOperationDAO + * Implementation of MobileDeviceOperationDAO. */ -public class DeviceOperationDAOImpl implements DeviceOperationDAO { +public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { 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; } @Override - public boolean addDeviceOperation(DeviceOperation deviceOperation) + public boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -66,7 +66,8 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } catch (SQLException e) { String msg = "Error occurred while adding device 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); throw new MobileDeviceManagementDAOException(msg, e); @@ -77,7 +78,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } @Override - public boolean updateDeviceOperation(DeviceOperation deviceOperation) + public boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -85,7 +86,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { try { conn = this.getConnection(); 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.setLong(1, deviceOperation.getSentDate()); stmt.setLong(2, deviceOperation.getReceivedDate()); @@ -98,7 +99,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } catch (SQLException e) { String msg = "Error occurred while updating device 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); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -108,7 +109,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } @Override - public boolean deleteDeviceOperation(String deviceId, int operationId) + public boolean deleteMobileDeviceOperation(String deviceId, int operationId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -116,7 +117,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { try { conn = this.getConnection(); 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.setString(1, deviceId); stmt.setInt(2, operationId); @@ -126,7 +127,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } } catch (SQLException e) { 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; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -137,21 +138,21 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } @Override - public DeviceOperation getDeviceOperation(String deviceId, int operationId) + public MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - DeviceOperation deviceOperation = null; + MobileDeviceOperation deviceOperation = null; try { conn = this.getConnection(); 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.setString(1, deviceId); stmt.setInt(2, operationId); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - deviceOperation = new DeviceOperation(); + deviceOperation = new MobileDeviceOperation(); deviceOperation.setDeviceId(resultSet.getString(1)); deviceOperation.setOperationId(resultSet.getInt(2)); deviceOperation.setSentDate(resultSet.getInt(3)); @@ -160,7 +161,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } } catch (SQLException e) { 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; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -171,12 +172,12 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } @Override - public List getAllDeviceOperationOfDevice(String deviceId) + public List getAllMobileDeviceOperationsOfDevice(String deviceId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - DeviceOperation deviceOperation = null; - List deviceOperations = new ArrayList(); + MobileDeviceOperation deviceOperation = null; + List deviceOperations = new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = @@ -185,17 +186,16 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { stmt.setString(1, deviceId); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - deviceOperation = new DeviceOperation(); + deviceOperation = new MobileDeviceOperation(); deviceOperation.setDeviceId(resultSet.getString(1)); deviceOperation.setOperationId(resultSet.getInt(2)); deviceOperation.setSentDate(resultSet.getInt(3)); deviceOperation.setReceivedDate(resultSet.getInt(4)); deviceOperations.add(deviceOperation); - break; } } catch (SQLException e) { 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; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java similarity index 81% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java index 913719bcaf7..01612098a1b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java @@ -19,9 +19,9 @@ 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.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.dto.Operation; +import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; import javax.sql.DataSource; import java.sql.Connection; @@ -30,19 +30,19 @@ import java.sql.ResultSet; import java.sql.SQLException; /** - * Implementation of OperationDAO + * Implementation of MobileOperationDAO. */ -public class OperationDAOImpl implements OperationDAO { +public class MobileOperationDAOImpl implements MobileOperationDAO { 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; } @Override - public int addOperation(Operation operation) + public int addMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException { int status = -1; Connection conn = null; @@ -51,7 +51,6 @@ public class OperationDAOImpl implements OperationDAO { conn = this.getConnection(); String createDBQuery = "INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; - stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" }); stmt.setString(1, operation.getFeatureCode()); stmt.setLong(2, operation.getCreatedDate()); @@ -63,8 +62,8 @@ public class OperationDAOImpl implements OperationDAO { } } } catch (SQLException e) { - String msg = "Error occurred while adding feature code - '" + - operation.getFeatureCode() + "' to operations table"; + String msg = "Error occurred while adding the operation - '" + + operation.getFeatureCode() + "' to MBL_OPERATION table"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -74,7 +73,7 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public boolean updateOperation(Operation operation) + public boolean updateMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -92,7 +91,7 @@ public class OperationDAOImpl implements OperationDAO { status = true; } } 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() + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -103,7 +102,7 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public boolean deleteOperation(int operationId) + public boolean deleteMobileOperation(int operationId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -119,7 +118,7 @@ public class OperationDAOImpl implements OperationDAO { status = true; } } 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); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -129,11 +128,11 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public Operation getOperation(int operationId) + public MobileOperation getMobileOperation(int operationId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - Operation operation = null; + MobileOperation operation = null; try { conn = this.getConnection(); String selectDBQuery = @@ -142,13 +141,13 @@ public class OperationDAOImpl implements OperationDAO { stmt.setInt(1, operation.getOperationId()); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - operation = new Operation(); + operation = new MobileOperation(); operation.setOperationId(resultSet.getInt(1)); break; } } catch (SQLException e) { String msg = "Error occurred while fetching operationId - '" + - operationId + "'"; + operationId + "' from MBL_OPERATION"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -167,4 +166,4 @@ public class OperationDAOImpl implements OperationDAO { throw new MobileDeviceManagementDAOException(msg, e); } } -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java new file mode 100644 index 00000000000..334217060df --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java @@ -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 getAllMobileOperationPropertiesOfOperation( + int operationId) throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + MobileOperationProperty mobileOperationProperty = null; + List properties = new ArrayList(); + 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); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationPropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationPropertyDAOImpl.java deleted file mode 100644 index 6f856a41dc3..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationPropertyDAOImpl.java +++ /dev/null @@ -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 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); - } - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java index cdbdad4f43b..a29cebaff69 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.dto; */ public class FeatureProperty { - private int propertyId; private String property; private String featureID; @@ -33,14 +32,6 @@ public class FeatureProperty { this.featureID = featureID; } - public int getPropertyId() { - return propertyId; - } - - public void setPropertyId(int propertyId) { - this.propertyId = propertyId; - } - public String getProperty() { return property; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/DeviceOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperation.java similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/DeviceOperation.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperation.java index a4f85723d57..c565accdb4c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/DeviceOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperation.java @@ -17,9 +17,9 @@ 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 int operationId; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperation.java similarity index 84% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/Operation.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperation.java index ce10e703ade..a1a139f8437 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperation.java @@ -19,14 +19,14 @@ package org.wso2.carbon.device.mgt.mobile.dto; import java.util.List; /** - * DTO of operation. + * DTO of MobileOperation. */ -public class Operation { +public class MobileOperation { private int operationId; private String featureCode; private long createdDate; - private List properties; + private List properties; public int getOperationId() { return operationId; @@ -36,11 +36,11 @@ public class Operation { this.operationId = operationId; } - public List getProperties() { + public List getProperties() { return properties; } - public void setProperties(List properties) { + public void setProperties(List properties) { this.properties = properties; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/OperationProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperationProperty.java similarity index 69% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/OperationProperty.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperationProperty.java index f47a23bd895..5262da6e733 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/OperationProperty.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperationProperty.java @@ -17,13 +17,12 @@ 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 propertyId; + private String property; private String value; public String getValue() { @@ -34,14 +33,6 @@ public class OperationProperty { this.value = value; } - public int getOperationPropertyId() { - return operationPropertyId; - } - - public void setOperationPropertyId(int operationPropertyId) { - this.operationPropertyId = operationPropertyId; - } - public int getOperationId() { return operationId; } @@ -50,12 +41,12 @@ public class OperationProperty { this.operationId = operationId; } - public int getPropertyId() { - return propertyId; + public String getProperty() { + return property; } - public void setPropertyId(int propertyId) { - this.propertyId = propertyId; + public void setProperty(String property) { + this.property = property; } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java index 39499134c03..953f97290ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java @@ -50,7 +50,8 @@ public class AndroidDeviceManagerService implements DeviceManagerService { boolean status; MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addDevice(mobileDevice); + status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier(); @@ -66,7 +67,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateDevice(mobileDevice); + .updateMobileDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while updating the enrollment of the Android device : " + device.getDeviceIdentifier(); @@ -81,7 +82,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { boolean status; try { status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .deleteDevice(deviceId.getId()); + .deleteMobileDevice(deviceId.getId()); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while removing the Android device : " + deviceId.getId(); log.error(msg, e); @@ -95,7 +96,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { boolean isEnrolled = false; try { MobileDevice mobileDevice = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getDevice( + MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( deviceId.getId()); if (mobileDevice != null) { isEnrolled = true; @@ -125,7 +126,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { Device device; try { MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getDevice(deviceId.getId()); + getMobileDevice(deviceId.getId()); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while fetching the Android device : " + deviceId.getId(); @@ -147,7 +148,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateDevice(mobileDevice); + .updateMobileDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); log.error(msg, e); @@ -162,7 +163,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { try { List mobileDevices = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getAllDevices(); + getAllMobileDevices(); if (mobileDevices != null) { devices = new ArrayList(); for (MobileDevice mobileDevice : mobileDevices) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java index 50c359068fe..f04bba9a94b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java @@ -18,15 +18,17 @@ package org.wso2.carbon.device.mgt.mobile.impl.android; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.OperationManagementException; 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.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dto.DeviceOperation; -import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation; +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; public class AndroidMobileOperationManager extends AbstractMobileOperationManager { @@ -36,26 +38,67 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage @Override public boolean addOperation(Operation operation, List devices) throws OperationManagementException { + boolean status = false; try { - MobileDeviceManagementDAOFactory.getOperationDAO().addOperation( - new org.wso2.carbon.device.mgt.mobile.dto.Operation()); - MobileDeviceManagementDAOFactory.geOperationPropertyDAO() - .addOperationProperty(new OperationProperty()); - MobileDeviceManagementDAOFactory.getDeviceOperationDAO() - .addDeviceOperation(new DeviceOperation()); + MobileDeviceOperation mobileDeviceOperation = null; + MobileOperation mobileOperation = + MobileDeviceManagementUtil.convertToMobileOperation(operation); + int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO() + .addMobileOperation(mobileOperation); + 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) { - String msg = "Error while updating the enrollment of the Android device : " + - devices.get(0).getId(); + String msg = + "Error while adding an operation " + operation.getCode() + "to Android devices"; log.error(msg, e); throw new OperationManagementException(msg, e); } - return false; + return status; } @Override public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { - return null; + List operations = new ArrayList(); + List mobileDeviceOperations = null; + MobileOperation mobileOperation = null; + try { + mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() + .getAllMobileDeviceOperationsOfDevice( + deviceIdentifier + .getId()); + if (mobileDeviceOperations.size() > 0) { + List 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; } - } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 6734efcc242..d170379eea5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -21,9 +21,11 @@ import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.wso2.carbon.device.mgt.common.Device; 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.Operation; -import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation; +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.DocumentBuilderFactory; @@ -69,7 +71,7 @@ public class MobileDeviceManagementUtil { private static Device.Property getProperty(String property, String value) { Device.Property prop = null; - if(property != null){ + if (property != null) { prop = new Device.Property(); prop.setName(property); prop.setValue(value); @@ -89,40 +91,66 @@ public class MobileDeviceManagementUtil { mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); - mobileDevice.setLatitude(getPropertyValue(device,MOBILE_DEVICE_LATITUDE)); - mobileDevice.setLongitude(getPropertyValue(device,MOBILE_DEVICE_LONGITUDE)); + mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } public static Device convertToDevice(MobileDevice mobileDevice) { Device device = null; - if(mobileDevice!=null){ + if (mobileDevice != null) { device = new Device(); List propertyList = new ArrayList(); - propertyList.add(getProperty(MOBILE_DEVICE_IMEI,mobileDevice.getImei())); - propertyList.add(getProperty(MOBILE_DEVICE_IMSI,mobileDevice.getImsi())); - propertyList.add(getProperty(MOBILE_DEVICE_REG_ID,mobileDevice.getRegId())); - propertyList.add(getProperty(MOBILE_DEVICE_MODEL,mobileDevice.getModel())); - propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION,mobileDevice.getOsVersion())); - propertyList.add(getProperty(MOBILE_DEVICE_VENDOR,mobileDevice.getVendor())); - propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE,mobileDevice.getLatitude())); - propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE,mobileDevice.getLongitude())); + propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); + propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); + propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId())); + propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); + propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); + propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); + propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); + propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; } - public static Operation convertToOperation(org.wso2.carbon.device.mgt.common.Operation operation){ - Operation mobileOperation = new Operation(); - List properties = new LinkedList(); + public static MobileOperation convertToMobileOperation( + org.wso2.carbon.device.mgt.common.Operation operation) { + MobileOperation mobileOperation = new MobileOperation(); + MobileOperationProperty operationProperty = null; + List properties = new LinkedList(); mobileOperation.setFeatureCode(operation.getCode()); mobileOperation.setCreatedDate(new Date().getTime()); Properties operationProperties = operation.getProperties(); - for(String key : operationProperties.stringPropertyNames()) { - String value = operationProperties.getProperty(key); + for (String key : operationProperties.stringPropertyNames()) { + operationProperty = new MobileOperationProperty(); + operationProperty.setProperty(key); + operationProperty.setValue(operationProperties.getProperty(key)); + properties.add(operationProperty); } + mobileOperation.setProperties(properties); return mobileOperation; } + + public static List getMobileOperationIdsFromMobileDeviceOperations( + List mobileDeviceOperations) { + List mobileOperationIds = new ArrayList(); + 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; + } } diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql index 1a8f0231166..fd239aa58fc 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , - `CODE` VARCHAR(45) NULL , + `CODE` VARCHAR(45) NOT NULL , `NAME` VARCHAR(100) NULL , `DESCRIPTION` VARCHAR(200) NULL , PRIMARY KEY (`FEATURE_ID`) ); @@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , - `FEATURE_CODE` VARCHAR(45) NULL , + `FEATURE_CODE` VARCHAR(45) NOT NULL , `CREATED_DATE` INT NULL , PRIMARY KEY (`OPERATION_ID`) , CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1` @@ -40,9 +40,9 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( 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 , `OPERATION_ID` INT NOT NULL , `SENT_DATE` INT NULL , @@ -63,11 +63,10 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPING` ( -- Table `MBL_OPERATION_PROPERTY` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( - `OPERATION_PROPERTY_ID` INT NOT NULL AUTO_INCREMENT , - `OPERATION_ID` INT NULL , - `PROPERTY_ID` INT NULL , + `OPERATION_ID` INT NOT NULL , + `PROPERTY` VARCHAR(45) NOT NULL , `VALUE` TEXT NULL , - PRIMARY KEY (`OPERATION_PROPERTY_ID`) , + PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` FOREIGN KEY (`OPERATION_ID` ) REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) @@ -78,13 +77,11 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( -- Table `MBL_FEATURE_PROPERTY` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( - `PROPERTY_ID` INT NOT NULL AUTO_INCREMENT , - `PROPERTY` VARCHAR(100) NULL , - `FEATURE_ID` VARCHAR(45) NULL , - PRIMARY KEY (`PROPERTY_ID`) , + `PROPERTY` VARCHAR(45) NOT NULL , + `FEATURE_ID` VARCHAR(45) NOT NULL , + PRIMARY KEY (`PROPERTY`) , CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` FOREIGN KEY (`FEATURE_ID` ) REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION); - diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql index b4943b70508..10adee8d0a6 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql @@ -3,12 +3,14 @@ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, - `REG_ID` VARCHAR(45) NULL, - `IMEI` VARCHAR(45) NULL, - `IMSI` VARCHAR(45) NULL, - `OS_VERSION` VARCHAR(45) NULL, - `DEVICE_MODEL` VARCHAR(45) NULL, - `VENDOR` VARCHAR(45) NULL, + `REG_ID` VARCHAR(45) NULL DEFAULT NULL, + `IMEI` VARCHAR(45) NULL DEFAULT NULL, + `IMSI` VARCHAR(45) NULL DEFAULT NULL, + `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, + `VENDOR` VARCHAR(45) NULL DEFAULT NULL, + `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, + `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, PRIMARY KEY (`MOBILE_DEVICE_ID`)) ENGINE = InnoDB; @@ -16,50 +18,44 @@ ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `MBL_FEATURE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , - `CODE` VARCHAR(45) NULL , - `NAME` VARCHAR(100) NULL , - `DESCRIPTION` VARCHAR(200) NULL , - PRIMARY KEY (`FEATURE_ID`) ) +CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `CODE` VARCHAR(45) NULL, + `NAME` VARCHAR(100) NULL, + `DESCRIPTION` VARCHAR(200) NULL, + PRIMARY KEY (`FEATURE_ID`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `MBL_OPERATION` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( - `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , - `FEATURE_CODE` VARCHAR(45) NULL , - `CREATED_DATE` INT NULL , - 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) +CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( + `OPERATION_ID` INT NOT NULL AUTO_INCREMENT, + `FEATURE_CODE` VARCHAR(45) NULL, + `CREATED_DATE` INT NULL, + PRIMARY KEY (`OPERATION_ID`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `MBL_DEVICE_OPERATION_MAPING` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPING` ( - `DEVICE_ID` VARCHAR(45) NOT NULL , - `OPERATION_ID` INT NOT NULL , - `SENT_DATE` INT NULL , - `RECEIVED_DATE` INT NULL , - PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , - INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC) , +CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( + `DEVICE_ID` VARCHAR(45) NOT NULL, + `OPERATION_ID` INT NOT NULL, + `SENT_DATE` INT NULL, + `RECEIVED_DATE` INT NULL, + PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`), + INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC), CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` - FOREIGN KEY (`DEVICE_ID` ) - REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID` ) + FOREIGN KEY (`DEVICE_ID`) + REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) + FOREIGN KEY (`OPERATION_ID`) + REFERENCES `MBL_OPERATION` (`OPERATION_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; @@ -68,16 +64,16 @@ ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `MBL_OPERATION_PROPERTY` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( - `OPERATION_PROPERTY_ID` INT NOT NULL AUTO_INCREMENT , - `OPERATION_ID` INT NULL , - `PROPERTY_ID` INT NULL , - `VALUE` TEXT NULL , - PRIMARY KEY (`OPERATION_PROPERTY_ID`) , - INDEX `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1_idx` (`OPERATION_ID` ASC) , +CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( + `OPERATION_PROPERTY_ID` INT NOT NULL AUTO_INCREMENT, + `OPERATION_ID` INT NULL, + `PROPERTY_ID` INT NULL, + `VALUE` TEXT NULL, + PRIMARY KEY (`OPERATION_PROPERTY_ID`), + INDEX `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1_idx` (`OPERATION_ID` ASC), CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) + FOREIGN KEY (`OPERATION_ID`) + REFERENCES `MBL_OPERATION` (`OPERATION_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; @@ -86,15 +82,15 @@ ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `MBL_FEATURE_PROPERTY` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( - `PROPERTY_ID` INT NOT NULL AUTO_INCREMENT , - `PROPERTY` VARCHAR(100) NULL , - `FEATURE_ID` VARCHAR(45) NULL , - PRIMARY KEY (`PROPERTY_ID`) , - INDEX `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1_idx` (`FEATURE_ID` ASC) , +CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( + `PROPERTY_ID` INT NOT NULL AUTO_INCREMENT, + `PROPERTY` VARCHAR(100) NULL, + `FEATURE_ID` VARCHAR(45) NULL, + PRIMARY KEY (`PROPERTY_ID`), + INDEX `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1_idx` (`FEATURE_ID` ASC), CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` - FOREIGN KEY (`FEATURE_ID` ) - REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) + FOREIGN KEY (`FEATURE_ID`) + REFERENCES `MBL_FEATURE` (`FEATURE_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java index c4d59291c32..42553649771 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java @@ -35,74 +35,73 @@ import java.util.List; @Consumes({ "application/json", "application/xml" }) public class Operation { - private static Log log = LogFactory.getLog(Operation.class); + private static Log log = LogFactory.getLog(Operation.class); - @GET - @Path("{id}") - public List getAllOperations(@PathParam("id") String id) - throws AndroidAgentException { + @GET + @Path("{id}") + public List getAllOperations( + @PathParam("id") String id) + throws AndroidAgentException { - List operations; - String msg; - DeviceManagementService dmService; + List operations; + String msg; + DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } catch (DeviceManagementServiceException deviceMgtServiceEx) { - msg = "Device management service error"; - log.error(msg, deviceMgtServiceEx); - throw new AndroidAgentException(msg, deviceMgtServiceEx); - } + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + operations = dmService.getOperationManager( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID) + .getOperations(deviceIdentifier); + Response.status(HttpStatus.SC_OK); + return operations; + } catch (DeviceManagementServiceException deviceMgtServiceEx) { + msg = "Device management service error"; + log.error(msg, deviceMgtServiceEx); + throw new AndroidAgentException(msg, deviceMgtServiceEx); + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the operation manager for the device type."; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + throw new AndroidAgentException(msg, e); + } catch (OperationManagementException e) { + msg = "Error occurred while fetching the operation list for the device."; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + throw new AndroidAgentException(msg, e); + } + } - try { - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - operations = dmService.getOperationManager( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID) - .getOperations(deviceIdentifier); - return operations; - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the operation manager for the device type."; - log.error(msg, e); - throw new AndroidAgentException(msg, e); - } catch (OperationManagementException e) { - msg = "Error occurred while fetching the operation list for the device."; - log.error(msg, e); - throw new AndroidAgentException(msg, e); - } - } - - @PUT - public Message updateOperation() throws AndroidAgentException { - - String msg; - DeviceManagementService dmService; - Message responseMsg = new Message(); - - try { - 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); - if (result) { - responseMsg.setResponseMessage("Device has already enrolled"); - } else { - Response.status(Response.Status.NOT_FOUND); - responseMsg.setResponseMessage("Operation not found"); - } - return responseMsg; - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the operation manager for the device type."; - log.error(msg, e); - throw new AndroidAgentException(msg, e); - } catch (OperationManagementException e) { - msg = "Error occurred while updating the operation status for the device."; - log.error(msg, e); - throw new AndroidAgentException(msg, e); - } - } + @PUT + public Message updateOperation() throws AndroidAgentException { + String msg; + DeviceManagementService dmService; + Message responseMsg = new Message(); + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + boolean result = dmService.getOperationManager("").addOperation(null, null); + if (result) { + Response.status(HttpStatus.SC_OK); + responseMsg.setResponseMessage("Device has already enrolled"); + } else { + Response.status(HttpStatus.SC_NOT_FOUND); + responseMsg.setResponseMessage("Operation not found"); + } + return responseMsg; + } catch (DeviceManagementServiceException deviceMgtServiceEx) { + msg = "Device management service error"; + log.error(msg, deviceMgtServiceEx); + throw new AndroidAgentException(msg, deviceMgtServiceEx); + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the operation manager for the device type."; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + throw new AndroidAgentException(msg, e); + } catch (OperationManagementException e) { + msg = "Error occurred while updating the operation status for the device."; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + throw new AndroidAgentException(msg, e); + } + } } \ No newline at end of file diff --git a/product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/Operation.java b/product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/Operation.java index 5237b08c243..09f0c9136a1 100644 --- a/product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/Operation.java +++ b/product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/Operation.java @@ -50,16 +50,13 @@ public class Operation { OperationManager operationManager; try { dmService = CDMAPIUtils.getDeviceManagementService(); + operationManager = dmService.getOperationManager( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + operations = operationManager.getOperations(null); } catch (DeviceManagementServiceException deviceServiceMgtEx) { String errorMsg = "Device management service error"; log.error(errorMsg, deviceServiceMgtEx); throw new CDMAPIException(errorMsg, deviceServiceMgtEx); - } - - try { - operationManager = dmService.getOperationManager( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - operations = operationManager.getOperations(null); } catch (DeviceManagementException deviceMgtEx) { String errorMsg = "Error occurred while fetching the operation manager."; log.error(errorMsg, deviceMgtEx); @@ -79,13 +76,6 @@ public class Operation { Message responseMsg = new Message(); try { 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( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); boolean status = operationManager.addOperation(operationContext.getOperation(), @@ -98,6 +88,10 @@ public class Operation { responseMsg.setResponseMessage("Failure in adding the Operation."); } return responseMsg; + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new CDMAPIException(errorMsg, deviceServiceMgtEx); } catch (DeviceManagementException deviceMgtEx) { String errorMsg = "Error occurred while adding the operation"; log.error(errorMsg, deviceMgtEx);