From 69cf3f8939d45cd3101527298de57d691cb2ae28 Mon Sep 17 00:00:00 2001 From: mharindu Date: Thu, 27 Aug 2015 17:15:37 +0530 Subject: [PATCH] Cleaned code and added comments --- .../device/mgt/common/EnrolmentInfo.java | 17 +-- .../carbon/device/mgt/core/dao/DeviceDAO.java | 124 +++++++++++++++++- .../operation/mgt/OperationManagerImpl.java | 4 +- .../mgt/dao/impl/CommandOperationDAOImpl.java | 8 +- .../DeviceManagementProviderServiceImpl.java | 8 +- 5 files changed, 140 insertions(+), 21 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index 2c599474fc9..1054075c34e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -96,19 +96,14 @@ public class EnrolmentInfo { public boolean equals(Object obj) { if (obj instanceof EnrolmentInfo) { EnrolmentInfo tempInfo = (EnrolmentInfo) obj; - if (owner != null && ownership != null - && tempInfo.getOwner() != null && tempInfo.getOwnership() != null) { - - if (owner.equals(tempInfo.getOwner()) && ownership.equals(tempInfo.getOwnership())) { - return true; - } else { - return false; + if (owner != null && ownership != null) { + if (tempInfo.getOwner() != null && tempInfo.getOwnership() != null) { + if (owner.equals(tempInfo.getOwner()) && ownership.equals(tempInfo.getOwnership())) { + return true; + } } - } else { - return false; } - } else { - return false; } + return false; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 5b5d0c66aa6..3eb1f48ac40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -31,38 +31,160 @@ import java.util.List; */ public interface DeviceDAO { + /** + * This method is used to add a device. + * + * @param typeId device type id. + * @param device device object. + * @param tenantId tenant id. + * @return returns the id of the persisted device record. + * @throws DeviceManagementDAOException + */ int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to update a given device. + * + * @param typeId device type id. + * @param device device object. + * @param tenantId tenant id. + * @return returns the id of updated device. + * @throws DeviceManagementDAOException + */ int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to remove a device. + * + * @param deviceId id of the device that should be removed. + * @param tenantId tenant id. + * @return returns the id of removed device. + * @throws DeviceManagementDAOException + */ int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve a device of a given id. + * + * @param deviceId device id. + * @param tenantId tenant id. + * @return returns the device object. + * @throws DeviceManagementDAOException + */ Device getDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve all the devices of a given tenant. + * + * @param tenantId tenant id. + * @return returns a list of devices. + * @throws DeviceManagementDAOException + */ List getDevices(int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve all the devices of a given tenant and device type. + * + * @param type device type. + * @param tenantId tenant id. + * @return returns list of devices. + * @throws DeviceManagementDAOException + */ List getDevices(String type, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve devices of a given user. + * @param username user name. + * @param tenantId tenant id. + * @return returns list of devices. + * @throws DeviceManagementDAOException + */ List getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve the device count of a given tenant. + * + * @param tenantId tenant id. + * @return returns the device count. + * @throws DeviceManagementDAOException + */ int getDeviceCount(int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve devices of a given device name. + * @param deviceName device name. + * @param tenantId tenant id. + * @return returns list of devices. + * @throws DeviceManagementDAOException + */ List getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to add an enrollment information of a given device. + * + * @param device device object. + * @param tenantId tenant id. + * @return returns the id of the enrollment. + * @throws DeviceManagementDAOException + */ int addEnrollment(Device device, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to set the current enrollment status of given device and user. + * + * @param deviceId device id. + * @param currentOwner current user name. + * @param status device status. + * @param tenantId tenant id. + * @return returns true if success. + * @throws DeviceManagementDAOException + */ boolean setEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, Status status, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to get the status of current enrollment of a given user and device. + * + * @param deviceId device id. + * @param currentOwner device owner. + * @param tenantId tenant id. + * @return returns current enrollment status. + * @throws DeviceManagementDAOException + */ Status getEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve current enrollment of a given device and user. + * + * @param deviceId device id. + * @param currentUser user name. + * @param tenantId tenant id. + * @return returns EnrolmentInfo object. + * @throws DeviceManagementDAOException + */ EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException; - + /** + * This method is used to retrieve devices of a given enrollment status. + * + * @param status enrollment status. + * @param tenantId tenant id. + * @return returns list of devices. + * @throws DeviceManagementDAOException + */ List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve the enrollment id of a given device and status. + * + * @param deviceId device id. + * @param status enrollment status. + * @param tenantId tenant id. + * @return returns the id of current enrollment. + * @throws DeviceManagementDAOException + */ int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status, int tenantId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index b2e593291d6..9bdcf595fa3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -76,7 +76,7 @@ public class OperationManagerImpl implements OperationManager { log.debug("operation:[" + operation.toString() + "]"); for (DeviceIdentifier deviceIdentifier : deviceIds) { log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + - deviceIdentifier.getType() + "]"); + deviceIdentifier.getType() + "]"); } } try { @@ -167,7 +167,7 @@ public class OperationManagerImpl implements OperationManager { if (enrolmentId < 0) { throw new OperationManagementException("Device not found for the given device Identifier:" + - deviceId.getId() + " and given type:" + deviceId.getType()); + deviceId.getId() + " and given type:" + deviceId.getType()); } dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index fa3348789f8..f485408d67d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -120,9 +120,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl { List commandOperations = new ArrayList<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS FROM DM_COMMAND_OPERATION co " + - "INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " + - "AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID"; + String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + + "o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS " + + "FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS " + + "FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? AND STATUS = ?) dm " + + "ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 3e05baf788b..c44bf6bd27d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -402,7 +402,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); messageBody = messageBody.trim() + System.getProperty("line.separator") + System.getProperty("line.separator") + url.replaceAll("\\{" - + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", + + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); @@ -458,8 +458,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); messageBody = messageBody.trim().replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants - .USERNAME - + "\\}", + .USERNAME + + "\\}", URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants .ENCODED_SCHEME)); @@ -468,7 +468,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv .ENCODED_SCHEME)); messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{" - + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", + + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));