From dbf296605f9db59720df09c749fedebee418598f Mon Sep 17 00:00:00 2001 From: harshanL Date: Thu, 12 Feb 2015 19:37:07 +0530 Subject: [PATCH] MDM-312 fix : Refactored code of MDM MobileImpl component --- .../AbstractMobileOperationManager.java | 20 +- .../MobileDeviceConfigurationManager.java | 7 +- .../dao/MobileDeviceOperationMappingDAO.java | 8 +- .../mobile/dao/MobileFeaturePropertyDAO.java | 7 +- .../mobile/dao/impl/MobileDeviceDAOImpl.java | 3 +- .../MobileDeviceOperationMappingDAOImpl.java | 28 ++- .../mobile/dao/impl/MobileFeatureDAOImpl.java | 26 +- .../impl/MobileFeaturePropertyDAOImpl.java | 5 +- .../dao/impl/MobileOperationDAOImpl.java | 9 +- .../impl/MobileOperationPropertyDAOImpl.java | 26 +- .../util/MobileDeviceManagementDAOUtil.java | 7 +- .../AndroidMobileOperationManager.java | 44 ++-- ...MobileDeviceManagementBundleActivator.java | 231 +++++++++--------- ...obileDeviceManagementServiceComponent.java | 4 - ...bileDeviceManagementSchemaInitializer.java | 5 + .../util/MobileDeviceManagementUtil.java | 7 +- .../impl/dao/MobileOperationDAOTestSuite.java | 10 +- 17 files changed, 234 insertions(+), 213 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java index 0bf268ef94..73fe6b9889 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java @@ -24,15 +24,17 @@ import java.util.List; public abstract class AbstractMobileOperationManager implements OperationManager { - @Override - public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { - return null; - } + @Override + public List getOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + return null; + } - @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { - return true; - } + @Override + public boolean addOperation(Operation operation, + List devices) + throws OperationManagementException { + return true; + } } \ 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/config/MobileDeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java index cd42592f02..7143d74df3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java @@ -34,13 +34,14 @@ import java.io.File; public class MobileDeviceConfigurationManager { private static final String MOBILE_DEVICE_CONFIG_XML_NAME = "mobile-config.xml"; - private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile"; + private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile"; private MobileDeviceManagementConfig currentMobileDeviceConfig; private static MobileDeviceConfigurationManager mobileDeviceConfigManager; private final String mobileDeviceMgtConfigXMLPath = - CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator + - MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME; + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + + File.separator + + MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME; public static MobileDeviceConfigurationManager getInstance() { if (mobileDeviceConfigManager == null) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java index f55660e7b1..e9fdb69af2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java @@ -29,8 +29,8 @@ public interface MobileDeviceOperationMappingDAO { /** * Add a new mobile device operation mapping to the table. * - * @param deviceOperation MobileDeviceOperation object that holds data related to the MobileDeviceOperation - * to be inserted. + * @param deviceOperation MobileDeviceOperation object that holds data related to the + * MobileDeviceOperation to be inserted. * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ @@ -85,8 +85,8 @@ public interface MobileDeviceOperationMappingDAO { * * @param deviceId Device id of the mapping to be retrieved. * @param operationId Operation id of the mapping to be retrieved. - * @return MobileDeviceOperation object that holds data of the device operation mapping represented by - * deviceId and operationId. + * @return MobileDeviceOperation object that holds data of the device operation mapping + * represented by deviceId and operationId. * @throws MobileDeviceManagementDAOException */ MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId, int operationId) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java index e4414c6e6c..59828124cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java @@ -23,14 +23,15 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty; import java.util.List; /** - * This class represents the key operations associated with persisting mobile feature property related - * information. + * This class represents the key operations associated with persisting mobile feature property + * related information. */ public interface MobileFeaturePropertyDAO { /** * Add a new feature property to feature property table. * - * @param mobileFeatureProperty Feature property object that holds data related to the feature property to be inserted. + * @param mobileFeatureProperty Feature property object that holds data related to the feature + * property to be inserted. * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ 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 55ec01944a..b5ee24b45c 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 @@ -128,7 +128,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { conn = this.getConnection(); String updateDBQuery = "UPDATE MBL_DEVICE SET REG_ID = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," + - "DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? WHERE MOBILE_DEVICE_ID = ?"; + "DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? " + + "WHERE MOBILE_DEVICE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mobileDevice.getRegId()); stmt.setString(2, mobileDevice.getImei()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java index e1038fc361..211ffe253e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java @@ -20,8 +20,8 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; @@ -73,7 +73,6 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getOperationId() + " to mapping table MBL_DEVICE_OPERATION"; - ; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -91,8 +90,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, STATUS = ? " + - "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " + + "STATUS = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setLong(1, deviceOperation.getSentDate()); stmt.setLong(2, deviceOperation.getReceivedDate()); @@ -159,7 +158,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio conn = this.getConnection(); String updateDBQuery = "UPDATE MBL_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " + - "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setLong(1, new Date().getTime()); stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name()); @@ -191,7 +190,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " + + "OPERATION_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, deviceId); stmt.setInt(2, operationId); @@ -222,19 +222,18 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio conn = this.getConnection(); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceId); stmt.setInt(2, operationId); ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { mblDeviceOperation = new MobileDeviceOperationMapping(); mblDeviceOperation.setDeviceId(resultSet.getString(1)); mblDeviceOperation.setOperationId(resultSet.getInt(2)); mblDeviceOperation.setSentDate(resultSet.getInt(3)); mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); mblDeviceOperation.setStatus(resultSet.getString(5)); - break; } } catch (SQLException e) { String msg = @@ -254,8 +253,9 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - MobileDeviceOperationMapping mblDeviceOperation = null; - List mblDeviceOperations = new ArrayList(); + MobileDeviceOperationMapping mblDeviceOperation; + List mblDeviceOperations = + new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = @@ -292,15 +292,17 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio Connection conn = null; PreparedStatement stmt = null; MobileDeviceOperationMapping mblDeviceOperation = null; - List mblDeviceOperations = new ArrayList(); + List mblDeviceOperations = + new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" + - " MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = 'NEW'"; + " MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceId); + stmt.setString(2, MobileDeviceOperationMapping.Status.NEW.name()); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { mblDeviceOperation = new MobileDeviceOperationMapping(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 78d43352fa..2f5251686e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -46,7 +46,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public int addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { + public int addMobileFeature(MobileFeature mobileFeature) + throws MobileDeviceManagementDAOException { int status = 0; Connection conn = null; PreparedStatement stmt = null; @@ -87,7 +88,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ? WHERE FEATURE_ID = ?"; + "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ?" + + " WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mobileFeature.getCode()); stmt.setString(2, mobileFeature.getName()); @@ -170,18 +172,18 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE CODE = ?"; + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE " + + "WHERE CODE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, featureCode); ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { mobileFeature = new MobileFeature(); mobileFeature.setId(resultSet.getInt(1)); mobileFeature.setCode(resultSet.getString(2)); mobileFeature.setName(resultSet.getString(3)); mobileFeature.setDescription(resultSet.getString(4)); mobileFeature.setDeviceType(resultSet.getString(5)); - break; } } catch (SQLException e) { String msg = "Error occurred while fetching feature code - '" + @@ -203,18 +205,18 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE FEATURE_ID = ?"; + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" + + " WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, featureID); ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { mobileFeature = new MobileFeature(); mobileFeature.setId(resultSet.getInt(1)); mobileFeature.setCode(resultSet.getString(2)); mobileFeature.setName(resultSet.getString(3)); mobileFeature.setDescription(resultSet.getString(4)); mobileFeature.setDeviceType(resultSet.getString(5)); - break; } } catch (SQLException e) { String msg = "Error occurred while fetching feature id - '" + @@ -259,7 +261,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public List getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException { + public List getMobileFeatureByDeviceType(String deviceType) throws + MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; MobileFeature mobileFeature; @@ -267,7 +270,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE DEVICE_TYPE = ?"; + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" + + " WHERE DEVICE_TYPE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceType); ResultSet resultSet = stmt.executeQuery(); @@ -285,7 +289,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { String msg = "Error occurred while fetching all features.'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); - }finally { + } finally { MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java index 95f2e3c107..34523675a6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java @@ -169,11 +169,10 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, property); ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { mobileFeatureProperty = new MobileFeatureProperty(); mobileFeatureProperty.setProperty(resultSet.getString(1)); mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); - break; } } catch (SQLException e) { String msg = "Error occurred while fetching property - '" + @@ -191,7 +190,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - MobileFeatureProperty mobileFeatureProperty = null; + MobileFeatureProperty mobileFeatureProperty; List FeatureProperties = new ArrayList(); try { conn = this.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.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 index f52290a438..21f7d7044d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.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 @@ -84,7 +84,8 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE OPERATION_ID = ?"; + "UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " + + "OPERATION_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, operation.getFeatureCode()); stmt.setLong(2, operation.getCreatedDate()); @@ -140,16 +141,16 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?"; + "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE " + + "OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, operationId); ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { operation = new MobileOperation(); operation.setOperationId(resultSet.getInt(1)); operation.setFeatureCode(resultSet.getString(2)); operation.setCreatedDate(resultSet.getLong(3)); - break; } } catch (SQLException e) { String msg = "Error occurred while fetching operationId - '" + 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 index d5fb2519fd..352d2b6e25 100644 --- 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 @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; import javax.sql.DataSource; @@ -55,8 +54,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) VALUES ( ?, ?, ?)"; - + "INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " + + "VALUES ( ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setInt(1, operationProperty.getOperationId()); stmt.setString(2, operationProperty.getProperty()); @@ -67,7 +66,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA } } catch (SQLException e) { String msg = - "Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY table"; + "Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY " + + "table"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -86,8 +86,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String createDBQuery = - "UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND PROPERTY = ?"; - + "UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " + + "PROPERTY = ?"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, operationProperty.getValue()); stmt.setInt(2, operationProperty.getOperationId()); @@ -98,7 +98,8 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA } } catch (SQLException e) { String msg = - "Error occurred while updating the mobile operation property in MBL_OPERATION_PROPERTY table."; + "Error occurred while updating the mobile operation property in" + + " MBL_OPERATION_PROPERTY table."; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -144,17 +145,17 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA try { conn = this.getConnection(); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ? AND PROPERTY = ?"; + "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " + + "OPERATION_ID = ? AND PROPERTY = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, operationId); stmt.setString(2, property); ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { mobileOperationProperty = new MobileOperationProperty(); mobileOperationProperty.setOperationId(resultSet.getInt(1)); mobileOperationProperty.setProperty(resultSet.getString(2)); mobileOperationProperty.setValue(resultSet.getString(3)); - break; } } catch (SQLException e) { String msg = @@ -173,12 +174,13 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA int operationId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - MobileOperationProperty mobileOperationProperty = null; + MobileOperationProperty mobileOperationProperty; List properties = new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; + "SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " + + "OPERATION_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, operationId); ResultSet resultSet = stmt.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java index 15bb6f4858..8091ae186b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java @@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.dao.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; -import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementSchemaInitializer; import javax.naming.InitialContext; @@ -32,7 +30,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Hashtable; -import java.util.List; /** * Utility method required by MobileDeviceManagement DAO classes. @@ -94,8 +91,8 @@ public class MobileDeviceManagementDAOUtil { try { initializer.createRegistryDatabase(); } catch (Exception e) { - throw new DeviceManagementException("Error occurred while initializing Mobile Device Management " + - "database schema", e); + throw new DeviceManagementException("Error occurred while initializing Mobile Device " + + "Management database schema", e); } } 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 82cfec148e..0fffc3f8ef 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 @@ -42,7 +42,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage OperationManagementException { boolean status = false; try { - MobileDeviceOperationMapping mobileDeviceOperationMapping = null; + MobileDeviceOperationMapping mobileDeviceOperationMapping; MobileOperation mobileOperation = MobileDeviceManagementUtil.convertToMobileOperation(operation); int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO() @@ -77,14 +77,15 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { List operations = new ArrayList(); - List mobileDeviceOperationMappings = null; - List operationProperties = null; - MobileOperation mobileOperation = null; + List mobileDeviceOperationMappings; + List operationProperties; + MobileOperation mobileOperation; try { - mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .getAllMobileDeviceOperationMappingsOfDevice( - deviceIdentifier - .getId()); + mobileDeviceOperationMappings = + MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() + .getAllMobileDeviceOperationMappingsOfDevice( + deviceIdentifier + .getId()); if (mobileDeviceOperationMappings.size() > 0) { List operationIds = MobileDeviceManagementUtil .getMobileOperationIdsFromMobileDeviceOperations( @@ -116,15 +117,16 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage public List getPendingOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { List operations = new ArrayList(); - List mobileDeviceOperationMappings = null; - List operationProperties = null; - MobileOperation mobileOperation = null; + List mobileDeviceOperationMappings; + List operationProperties ; + MobileOperation mobileOperation; try { //Get the list of pending operations for the given device - mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .getAllPendingOperationMappingsOfMobileDevice( - deviceIdentifier - .getId()); + mobileDeviceOperationMappings = + MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() + .getAllPendingOperationMappingsOfMobileDevice( + deviceIdentifier + .getId()); //Go through each operation mapping for retrieving the data corresponding to each operation for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) { //Get the MobileOperation data @@ -158,19 +160,23 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage } @Override - public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException { + public List getFeaturesForDeviceType(String deviceType) + throws FeatureManagementException { MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO(); - MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO(); + MobileFeaturePropertyDAO featurePropertyDAO = + MobileDeviceManagementDAOFactory.getFeaturePropertyDAO(); List features = new ArrayList(); try { - List mobileFeatures = featureDAO.getMobileFeatureByDeviceType(deviceType); + List mobileFeatures = + featureDAO.getMobileFeatureByDeviceType(deviceType); for (MobileFeature mobileFeature : mobileFeatures) { Feature feature = new Feature(); feature.setId(mobileFeature.getId()); feature.setDeviceType(mobileFeature.getDeviceType()); feature.setName(mobileFeature.getName()); feature.setDescription(mobileFeature.getDescription()); - List metadataEntries = new ArrayList(); + List metadataEntries = + new ArrayList(); List properties = featurePropertyDAO.getFeaturePropertiesOfFeature(mobileFeature.getId()); for (MobileFeatureProperty property : properties) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java index 3c0142f026..fb32d4fecc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java @@ -40,129 +40,136 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerServic import java.util.ArrayList; import java.util.List; +/** + * BundleActivator of MobileDeviceManagement component. + */ public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener { - private ServiceRegistration androidServiceRegRef; - private ServiceRegistration iOSServiceRegRef; - private ServiceRegistration windowsServiceRegRef; + private ServiceRegistration androidServiceRegRef; + private ServiceRegistration iOSServiceRegRef; + private ServiceRegistration windowsServiceRegRef; - private static List dataSourceListeners = new ArrayList(); + private static List dataSourceListeners = + new ArrayList(); - private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT = "org.wso2.carbon.ndatasource.core"; - private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class); + private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT = + "org.wso2.carbon.ndatasource.core"; + private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class); - @Override - public void start(BundleContext bundleContext) throws Exception { - try { - if (log.isDebugEnabled()) { - log.debug("Activating Mobile Device Management Service bundle"); - } - bundleContext.addBundleListener(this); + @Override + public void start(BundleContext bundleContext) throws Exception { + try { + if (log.isDebugEnabled()) { + log.debug("Activating Mobile Device Management Service bundle"); + } + bundleContext.addBundleListener(this); /* Initialize the datasource configuration */ - MobileDeviceConfigurationManager.getInstance().initConfig(); - MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() - .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - - MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); - - androidServiceRegRef = - bundleContext.registerService(DeviceManagerService.class.getName(), - new AndroidDeviceManagerService(), null); - iOSServiceRegRef = - bundleContext.registerService(DeviceManagerService.class.getName(), - new IOSDeviceManagerService(), null); - windowsServiceRegRef = - bundleContext.registerService(DeviceManagerService.class.getName(), - new WindowsDeviceManagerService(), null); + MobileDeviceConfigurationManager.getInstance().initConfig(); + MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() + .getMobileDeviceManagementConfig(); + MobileDataSourceConfig dsConfig = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); + + MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); + + androidServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new AndroidDeviceManagerService(), null); + iOSServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new IOSDeviceManagerService(), null); + windowsServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new WindowsDeviceManagerService(), null); /* Initialize all API configurations with corresponding API Providers */ - this.initAPIConfigs(); - /* Publish all mobile device management related JAX-RS services as APIs */ - this.publishAPIs(); - - if (log.isDebugEnabled()) { - log.debug("Mobile Device Management Service bundle is activated"); - } - } catch (Throwable e) { - log.error("Error occurred while activating Mobile Device Management bundle", e); - } - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - if (log.isDebugEnabled()) { - log.debug("Deactivating Mobile Device Management Service"); - } - try { - androidServiceRegRef.unregister(); - iOSServiceRegRef.unregister(); - windowsServiceRegRef.unregister(); - - bundleContext.removeBundleListener(this); + this.initAPIConfigs(); + /* Publish all mobile device management related JAX-RS services as APIs */ + this.publishAPIs(); + + if (log.isDebugEnabled()) { + log.debug("Mobile Device Management Service bundle is activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Mobile Device Management bundle", e); + } + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + if (log.isDebugEnabled()) { + log.debug("Deactivating Mobile Device Management Service"); + } + try { + androidServiceRegRef.unregister(); + iOSServiceRegRef.unregister(); + windowsServiceRegRef.unregister(); + + bundleContext.removeBundleListener(this); /* Removing all APIs published upon start-up for mobile device management related JAX-RS services */ - this.removeAPIs(); - } catch (Throwable e) { - log.error("Error occurred while de-activating Mobile Device Management bundle", e); - } - } - - @Override - public void bundleChanged(BundleEvent bundleEvent) { - int eventType = bundleEvent.getType(); - String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName(); - - if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) && - eventType == BundleEvent.STARTED) { - for (DataSourceListener listener : this.getDataSourceListeners()) { - listener.notifyObserver(); - } - } - } - - public static void registerDataSourceListener(DataSourceListener listener) { - dataSourceListeners.add(listener); - } - - private List getDataSourceListeners() { - return dataSourceListeners; - } - - private void initAPIConfigs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - try { - APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); - apiConfig.init(provider); - } catch (APIManagementException e) { - throw new DeviceManagementException("Error occurred while initializing API Config '" + - apiConfig.getName() + "'", e); - } - } - } - - private void publishAPIs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - DeviceManagementAPIPublisherUtil.publishAPI(apiConfig); - } - } - - private void removeAPIs() throws DeviceManagementException { - List apiConfigs = - MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). - getApiPublisherConfig().getAPIs(); - for (APIConfig apiConfig : apiConfigs) { - DeviceManagementAPIPublisherUtil.removeAPI(apiConfig); - } - } + this.removeAPIs(); + } catch (Throwable e) { + log.error("Error occurred while de-activating Mobile Device Management bundle", e); + } + } + + @Override + public void bundleChanged(BundleEvent bundleEvent) { + int eventType = bundleEvent.getType(); + String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName(); + + if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) && + eventType == BundleEvent.STARTED) { + for (DataSourceListener listener : this.getDataSourceListeners()) { + listener.notifyObserver(); + } + } + } + + public static void registerDataSourceListener(DataSourceListener listener) { + dataSourceListeners.add(listener); + } + + private List getDataSourceListeners() { + return dataSourceListeners; + } + + private void initAPIConfigs() throws DeviceManagementException { + List apiConfigs = + MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). + getApiPublisherConfig().getAPIs(); + for (APIConfig apiConfig : apiConfigs) { + try { + APIProvider provider = + APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); + apiConfig.init(provider); + } catch (APIManagementException e) { + throw new DeviceManagementException( + "Error occurred while initializing API Config '" + + apiConfig.getName() + "'", e); + } + } + } + + private void publishAPIs() throws DeviceManagementException { + List apiConfigs = + MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). + getApiPublisherConfig().getAPIs(); + for (APIConfig apiConfig : apiConfigs) { + DeviceManagementAPIPublisherUtil.publishAPI(apiConfig); + } + } + + private void removeAPIs() throws DeviceManagementException { + List apiConfigs = + MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). + getApiPublisherConfig().getAPIs(); + for (APIConfig apiConfig : apiConfigs) { + DeviceManagementAPIPublisherUtil.removeAPI(apiConfig); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 8d54387308..c048dc105d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -23,11 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.apimgt.api.APIProvider; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; -import org.wso2.carbon.apimgt.impl.APIManagerFactory; -import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil; import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java index bda4a641e3..1d04f60598 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java @@ -26,6 +26,11 @@ import org.wso2.carbon.utils.dbcreator.DatabaseCreator; import javax.sql.DataSource; import java.io.File; +/** + * + * Provides methods for initializing the database script. + * + */ public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator { private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class); 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 0996edfa31..66fa5900df 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 @@ -71,14 +71,13 @@ public class MobileDeviceManagementUtil { } private static Device.Property getProperty(String property, String value) { - Device.Property prop = null; if (property != null) { - prop = new Device.Property(); + Device.Property prop = new Device.Property(); prop.setName(property); prop.setValue(value); return prop; } - return prop; + return null; } public static MobileDevice convertToMobileDevice(Device device) { @@ -119,7 +118,7 @@ public class MobileDeviceManagementUtil { public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) { MobileOperation mobileOperation = new MobileOperation(); - MobileOperationProperty operationProperty = null; + MobileOperationProperty operationProperty; List properties = new LinkedList(); mobileOperation.setFeatureCode(operation.getCode()); mobileOperation.setCreatedDate(new Date().getTime()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java index a6386550e2..d6b03e07ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java @@ -36,9 +36,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils; import java.sql.*; /** - * * Class for holding unit-tests related to MobileOperationDAO class. - * */ public class MobileOperationDAOTestSuite { @@ -101,7 +99,7 @@ public class MobileOperationDAOTestSuite { } finally { MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); } - Assert.assertTrue(mblOperationId > 0 , "MobileOperation has added "); + Assert.assertTrue(mblOperationId > 0, "MobileOperation has added "); Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, testMblOperation.getFeatureCode(), "MobileOperation feature code has persisted "); Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, testMblOperation.getCreatedDate(), @@ -119,7 +117,7 @@ public class MobileOperationDAOTestSuite { "MobileOperation feature-code has retrieved "); } - @Test(dependsOnMethods = { "addMobileOperationTest" , "getMobileOperationTest"}) + @Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest" }) public void updateMobileOperationTest() throws MobileDeviceManagementDAOException { @@ -151,14 +149,14 @@ public class MobileOperationDAOTestSuite { } finally { MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); } - Assert.assertTrue(status , "MobileOperation has updated "); + Assert.assertTrue(status, "MobileOperation has updated "); Assert.assertEquals(TEST_MBL_OPR_UPDATED_FEATURE_CODE, testMblOperation.getFeatureCode(), "MobileOperation feature code has updated "); Assert.assertEquals(updatedDate, testMblOperation.getCreatedDate(), "MobileOperation created-date has updated "); } - @Test(dependsOnMethods = { "addMobileOperationTest" , "getMobileOperationTest", + @Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest", "updateMobileOperationTest" }) public void deleteMobileDeviceTest() throws MobileDeviceManagementDAOException {