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 d6c399d1309..7b3ff89d1f2 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 @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.common; import java.io.Serializable; -public class EnrolmentInfo implements Serializable{ +public class EnrolmentInfo implements Serializable { private static final long serialVersionUID = 1998101712L; @@ -40,7 +40,8 @@ public class EnrolmentInfo implements Serializable{ private Status status; private String owner; - public EnrolmentInfo() {} + public EnrolmentInfo() { + } public EnrolmentInfo(Device device, String owner, OwnerShip ownership, Status status) { this.device = device; @@ -109,19 +110,12 @@ public class EnrolmentInfo implements Serializable{ 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())) { + if (this.owner != null && this.ownership != null) { + if (this.owner.equals(tempInfo.getOwner()) && this.ownership.equals(tempInfo.getOwnership())) { return true; - } else { - return false; } - } 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/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 6ec2eb26d52..75e916589dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -42,9 +42,8 @@ public class DeviceDAOImpl implements DeviceDAO { int deviceId = -1; try { conn = this.getConnection(); - String sql = - "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " + - "VALUES (?, ?, ?, ?, ?)"; + String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " + + "VALUES (?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, device.getDescription()); stmt.setString(2, device.getName()); @@ -74,9 +73,8 @@ public class DeviceDAOImpl implements DeviceDAO { int deviceId = -1; try { conn = this.getConnection(); - String sql = - "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " + - "DEVICE_TYPE_ID = ? AND TENANT_ID = ?"; + String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " + + "DEVICE_TYPE_ID = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, device.getDescription()); stmt.setString(2, device.getName()); @@ -111,13 +109,12 @@ public class DeviceDAOImpl implements DeviceDAO { Device device = null; try { conn = this.getConnection(); - String sql = - "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + - "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + - "FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " + - "t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " + - "t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " + - "AND TENANT_ID = ?"; + String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " + + "t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " + + "t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " + + "AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, deviceId.getType()); stmt.setString(2, deviceId.getId()); @@ -144,12 +141,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = null; try { conn = this.getConnection(); - String sql = - "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + - "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + - "FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," + - "d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; + String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " + + "d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " + + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " + + "WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); stmt.setInt(2, tenantId); @@ -176,12 +173,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = null; try { conn = this.getConnection(); - String sql = - "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + - "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + - "FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME " + - "AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " + - "AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; + String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " + + "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " + + "DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " + + "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, type); stmt.setInt(2, tenantId); @@ -207,13 +204,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = new ArrayList<>(); try { conn = this.getConnection(); - String sql = - "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + - "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + - "e.DATE_OF_ENROLMENT , e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, " + - "d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " + - "WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?"; + String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, " + + "d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " + + "WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " + + "WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); stmt.setInt(2, tenantId); @@ -281,12 +277,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = new ArrayList<>(); try { conn = this.getConnection(); - String sql = - "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + - "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + - "FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DESCRIPTION, t.NAME AS DEVICE_TYPE, " + - "d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + - "AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; + String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " + + "d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " + + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " + + "WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, deviceName + "%"); stmt.setInt(2, tenantId); @@ -314,9 +310,8 @@ public class DeviceDAOImpl implements DeviceDAO { int enrolmentId = -1; try { conn = this.getConnection(); - String sql = - "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " + - "TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)"; + String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " + + "DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setInt(1, device.getId()); stmt.setString(2, device.getEnrolmentInfo().getOwner()); @@ -346,10 +341,9 @@ public class DeviceDAOImpl implements DeviceDAO { PreparedStatement stmt = null; try { conn = this.getConnection(); - String sql = - "UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + - "AND OWNER = ? AND TENANT_ID = ?"; + String sql = "UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " + + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? " + + "AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, status.toString()); stmt.setString(2, deviceId.getId()); @@ -375,10 +369,9 @@ public class DeviceDAOImpl implements DeviceDAO { Status status = null; try { conn = this.getConnection(); - String sql = - "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = " + - "(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND " + - "d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?"; + String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " + + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? " + + "AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, deviceId.getId()); stmt.setString(2, deviceId.getType()); @@ -407,11 +400,11 @@ public class DeviceDAOImpl implements DeviceDAO { EnrolmentInfo enrolmentInfo = null; try { conn = this.getConnection(); - String sql = - "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " + - "TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + - "AND OWNER = ? AND TENANT_ID = ?"; + String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " + + "DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " + + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + + "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + + "AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, deviceId.getId()); stmt.setString(2, deviceId.getType()); @@ -438,10 +431,10 @@ public class DeviceDAOImpl implements DeviceDAO { ResultSet rs = null; try { conn = this.getConnection(); - String sql = - "SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " + - "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? " + - "AND d.TENANT_ID = ?) AND STATUS = ? AND TENANT_ID = ?"; + String sql = "SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " + + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + + "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + + "AND STATUS = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, deviceId.getId()); stmt.setString(2, deviceId.getType()); @@ -491,13 +484,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = new ArrayList<>(); try { conn = this.getConnection(); - String sql = - "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + - "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + - "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + - "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + - "AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " + - "AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; + String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + + "WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " + + "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); stmt.setString(2, status.toString()); 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/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 4aaf8bf06fb..bd0223e962f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -93,7 +93,7 @@ public interface DeviceManagementProviderService extends OperationManager { void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; /** - * This method is used to retrieve list of devices based on the device status + * This method is used to retrieve list of devices based on the device status. * * @param status Device status * @return List of devices 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 f9f382185e2..d5000da8891 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 @@ -414,7 +414,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)); @@ -469,8 +469,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)); @@ -479,7 +479,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)); @@ -748,10 +748,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.closeConnection(); } for (Device device : userDevices) { - Device dmsDevice = - this.getPluginRepository().getDeviceManagementService( - device.getType()).getDeviceManager().getDevice( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + Device dmsDevice = this.getDeviceManager(device.getType()). + getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); if (dmsDevice != null) { device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -792,10 +790,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.closeConnection(); } for (Device device : allDevices) { - Device dmsDevice = - this.getPluginRepository().getDeviceManagementService( - device.getType()).getDeviceManager().getDevice( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + Device dmsDevice = this.getDeviceManager(device.getType()). + getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); if (dmsDevice != null) { device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -865,10 +861,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } for (Device device : allDevices) { - Device dmsDevice = - this.getPluginRepository().getDeviceManagementService( - device.getType()).getDeviceManager().getDevice( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + Device dmsDevice = this.getDeviceManager(device.getType()). + getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); if (dmsDevice != null) { device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java index 0cdb0a097f9..c8233233648 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java @@ -128,6 +128,10 @@ public class DynamicClientRegistrationUtil { serviceProvider.setDescription("Service Provider for application " + applicationName); ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); + if (appMgtService == null) { + throw new IllegalStateException("Error occurred while retrieving Application Management" + + "Service"); + } appMgtService.createApplication(serviceProvider); ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); @@ -228,6 +232,11 @@ public class DynamicClientRegistrationUtil { oAuthAdminService.removeOAuthApplicationData(consumerKey); ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); + + if (appMgtService == null) { + throw new IllegalStateException("Error occurred while retrieving Application Management" + + "Service"); + } ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); if (createdServiceProvider == null) { diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java index a31673a7762..962b7210918 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java @@ -45,9 +45,24 @@ public interface RegistrationService { } } + /** + * This method is used to register an Oauth application. + * + * @param profile contains the necessary attributes that are + * needed in order to register an app. + * @return Status 200 if success including consumerKey and consumerSecret. + */ @POST Response register(RegistrationProfile profile); + /** + * This method is used to remove already registered Oauth application. + * + * @param applicationName name of the application. + * @param userId name of the application owner. + * @param consumerKey provided consumerKey for the registered application. + * @return Status 200 if success. + */ @DELETE public Response unregister(@QueryParam("applicationName") String applicationName, @QueryParam("userId") String userId, diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java index 2c1a42bae3a..25a760ab258 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/RegistrationProfile.java @@ -164,6 +164,4 @@ public class RegistrationProfile { public void setGrantType(String grantType) { this.grantType = grantType; } - - } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java index 19c9c137158..3b8ecec20c0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java @@ -25,34 +25,102 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature; import java.util.List; +/** + * This interface represents the key operations related to profile features of device policies. + */ public interface FeatureDAO { -/* Feature addFeature(Feature feature) throws FeatureManagerDAOException; - - List addFeatures(List feature) throws FeatureManagerDAOException; - - Feature updateFeature(Feature feature) throws FeatureManagerDAOException;*/ - + /** + * This method is used to add a feature related to given profile. + * + * @param feature consists of device specific configurations. + * @param profileId id of the profile. + * @return returns ProfileFeature object. + * @throws FeatureManagerDAOException + */ ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; + /** + * This method is used to update a feature related to given profile. + * @param feature consists of device specific configurations. + * @param profileId id of the profile. + * @return returns updated ProfileFeature object. + * @throws FeatureManagerDAOException + */ ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; + /** + * This method is used to add set of features to a given profile. + * + * @param features consists of device specific configurations. + * @param profileId id of the profile. + * @return returns list of ProfileFeature objects. + * @throws FeatureManagerDAOException + */ List addProfileFeatures(List features, int profileId) throws FeatureManagerDAOException; + /** + * This method is used to update set of features to a given profile. + * + * @param features consists of device specific configurations. + * @param profileId id of the profile. + * @return returns list of ProfileFeature objects. + * @throws FeatureManagerDAOException + */ List updateProfileFeatures(List features, int profileId) throws FeatureManagerDAOException; + /** + * This method is used to retrieve all the profile features. + * + * @return returns list of ProfileFeature objects. + * @throws FeatureManagerDAOException + */ List getAllProfileFeatures() throws FeatureManagerDAOException; + /** + * This method is used to retrieve all the profile features based on device type. + * + * @return returns list of ProfileFeature objects. + * @throws FeatureManagerDAOException + */ List getAllFeatures(String deviceType) throws FeatureManagerDAOException; - List getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException; - + /** + * This method is used to retrieve all the profile features of given profile. + * + * @param profileId id of the profile. + * @return returns list of ProfileFeature objects. + * @throws FeatureManagerDAOException + */ + List getFeaturesForProfile(int profileId) throws FeatureManagerDAOException; + + /** + * This method is used remove a feature. + * + * @param featureId id of the removing feature. + * @return returns true if success. + * @throws FeatureManagerDAOException + */ boolean deleteFeature(int featureId) throws FeatureManagerDAOException; + /** + * This method is used to remove set of features of given profile. + * + * @param profile that contains features to be removed. + * @return returns true if success. + * @throws FeatureManagerDAOException + */ boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; + /** + * This method is used to remove set of features of given profile id. + * + * @param profileId id of the profile. + * @return returns true if success. + * @throws FeatureManagerDAOException + */ boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java index 174ca08c48b..5d91650d7e4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java @@ -24,20 +24,67 @@ import org.wso2.carbon.policy.mgt.common.Profile; import java.util.List; +/** + * This interface represents the key operations related to policy profile. + */ public interface ProfileDAO { + /** + * This method is used to add a profile. + * + * @param profile profile object. + * @return returns added profile object. + * @throws ProfileManagerDAOException + */ Profile addProfile(Profile profile) throws ProfileManagerDAOException; + /** + * This method is used to update a profile + * @param profile profile object. + * @return returns updated profile object. + * @throws ProfileManagerDAOException + */ Profile updateProfile(Profile profile) throws ProfileManagerDAOException; + /** + * This method is used to remove a profile. + * @param profile profile object + * @return returns true if success. + * @throws ProfileManagerDAOException + */ boolean deleteProfile(Profile profile) throws ProfileManagerDAOException; + /** + * This method is used to remove a profile of given policy id. + * @param policyId policy id. + * @return returns true if success. + * @throws ProfileManagerDAOException + */ boolean deleteProfile(int policyId) throws ProfileManagerDAOException; - Profile getProfiles(int profileId) throws ProfileManagerDAOException; + /** + * This method is used to retrieve a profile when id is given. + * @param profileId profile id. + * @return returns profile object. + * @throws ProfileManagerDAOException + */ + Profile getProfile(int profileId) throws ProfileManagerDAOException; + /** + * This method is used to retrieve all the profiles. + * + * @return returns a list of profile objects. + * @throws ProfileManagerDAOException + */ List getAllProfiles() throws ProfileManagerDAOException; + /** + * This method is used to retrieve all the profile of given device type. + * + * @param deviceType device type object. + * @return retruns list of profiles. + * @throws ProfileManagerDAOException + */ List getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java index c1092d0d881..9688d1c53da 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java @@ -43,115 +43,6 @@ public class FeatureDAOImpl implements FeatureDAO { private static final Log log = LogFactory.getLog(FeatureDAOImpl.class); - -/* @Override - public Feature addFeature(Feature feature) throws FeatureManagerDAOException { - - Connection conn; - PreparedStatement stmt = null; - ResultSet generatedKeys = null; - - try { - conn = this.getConnection(); - String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); - stmt.setString(1, feature.getName()); - stmt.setString(2, feature.getCode()); - stmt.setString(3, feature.getDescription()); - int affectedRows = stmt.executeUpdate(); - - if (log.isDebugEnabled()) { - log.debug(affectedRows + " feature is added."); - } - generatedKeys = stmt.getGeneratedKeys(); - - while (generatedKeys.next()) { - feature.setId(generatedKeys.getInt(1)); - } - - } catch (SQLException e) { - String msg = "Error occurred while adding feature to the database."; - log.error(msg, e); - throw new FeatureManagerDAOException(msg, e); - } finally { - PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys); - } - return feature; - }*/ - - /* @Override - public List addFeatures(List features) throws FeatureManagerDAOException { - - Connection conn; - PreparedStatement stmt = null; - ResultSet generatedKeys = null; - List featureList = new ArrayList(); - - try { - conn = this.getConnection(); - String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); - - for (Feature feature : features) { - stmt.setString(1, feature.getName()); - stmt.setString(2, feature.getCode()); - stmt.setString(3, feature.getDescription()); - stmt.addBatch(); - } - - int[] affectedRows = stmt.executeBatch(); - - generatedKeys = stmt.getGeneratedKeys(); - - if (log.isDebugEnabled()) { - log.debug(affectedRows.length + " features are added to the database."); - } - generatedKeys = stmt.getGeneratedKeys(); - int i = 0; - - while (generatedKeys.next()) { - features.get(i).setId(generatedKeys.getInt(1)); - i++; - } - } catch (SQLException e) { - String msg = "Error occurred while adding feature to the database."; - log.error(msg, e); - throw new FeatureManagerDAOException(msg, e); - } finally { - PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys); - } - return featureList; - }*/ - - - /* @Override - public Feature updateFeature(Feature feature) throws FeatureManagerDAOException { - - Connection conn; - PreparedStatement stmt = null; - - try { - conn = this.getConnection(); - String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ? WHERE ID = ?"; - stmt = conn.prepareStatement(query); - stmt.setString(1, feature.getName()); - stmt.setString(2, feature.getCode()); - stmt.setString(3, feature.getDescription()); - stmt.setInt(4, feature.getId()); - stmt.executeUpdate(); - - } catch (SQLException e) { - String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the - database."; - log.error(msg, e); - throw new FeatureManagerDAOException(msg, e); - } finally { - PolicyManagementDAOUtil.cleanupResources(stmt, null); - } - - return feature; - }*/ - @Override public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { return null; @@ -247,7 +138,6 @@ public class FeatureDAOImpl implements FeatureDAO { @Override public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException { - Connection conn; PreparedStatement stmt = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -258,9 +148,10 @@ public class FeatureDAOImpl implements FeatureDAO { stmt = conn.prepareStatement(query); stmt.setInt(1, profile.getProfileId()); stmt.setInt(2, tenantId); - stmt.executeUpdate(); - return true; - + if (stmt.executeUpdate() > 0) { + return true; + } + return false; } catch (SQLException e) { throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); } finally { @@ -270,7 +161,6 @@ public class FeatureDAOImpl implements FeatureDAO { @Override public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException { - Connection conn; PreparedStatement stmt = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -280,9 +170,10 @@ public class FeatureDAOImpl implements FeatureDAO { stmt = conn.prepareStatement(query); stmt.setInt(1, profileId); stmt.setInt(2, tenantId); - stmt.executeUpdate(); - return true; - + if (stmt.executeUpdate() > 0) { + return true; + } + return false; } catch (SQLException e) { throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); } finally { @@ -448,7 +339,6 @@ public class FeatureDAOImpl implements FeatureDAO { @Override public boolean deleteFeature(int featureId) throws FeatureManagerDAOException { - Connection conn; PreparedStatement stmt = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -459,9 +349,10 @@ public class FeatureDAOImpl implements FeatureDAO { stmt = conn.prepareStatement(query); stmt.setInt(1, featureId); stmt.setInt(2, tenantId); - stmt.executeUpdate(); - return true; - + if(stmt.executeUpdate() > 0) { + return true; + } + return false; } catch (SQLException e) { throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " + "from database.", e); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java index 8565d5db0f5..fc10f61ee17 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java @@ -132,7 +132,6 @@ public class ProfileDAOImpl implements ProfileDAO { @Override public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException { - Connection conn; PreparedStatement stmt = null; @@ -141,9 +140,10 @@ public class ProfileDAOImpl implements ProfileDAO { String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, profile.getProfileId()); - stmt.executeUpdate(); - return true; - + if (stmt.executeUpdate() > 0) { + return true; + } + return false; } catch (SQLException e) { String msg = "Error occurred while deleting the profile from the data base."; log.error(msg); @@ -163,9 +163,10 @@ public class ProfileDAOImpl implements ProfileDAO { String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, profileId); - stmt.executeUpdate(); - return true; - + if (stmt.executeUpdate() > 0) { + return true; + } + return false; } catch (SQLException e) { String msg = "Error occurred while deleting the profile from the data base."; log.error(msg); @@ -177,8 +178,7 @@ public class ProfileDAOImpl implements ProfileDAO { @Override - public Profile getProfiles(int profileId) throws ProfileManagerDAOException { - + public Profile getProfile(int profileId) throws ProfileManagerDAOException { Connection conn; PreparedStatement stmt = null; ResultSet resultSet = null; @@ -216,7 +216,6 @@ public class ProfileDAOImpl implements ProfileDAO { @Override public List getAllProfiles() throws ProfileManagerDAOException { - Connection conn; PreparedStatement stmt = null; ResultSet resultSet = null; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 3a0dd3d78d8..e3a4d99efa9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -362,7 +362,6 @@ public class MonitoringManagerImpl implements MonitoringManager { DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); service.addOperation(monitoringOperation, deviceIdentifiers); - } private List getDeviceIdentifiersFromDevices(List devices) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index e36b01f010d..a9f1a10fd86 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -439,7 +439,7 @@ public class PolicyManagerImpl implements PolicyManager { policy = policyDAO.getPolicyByProfileID(profileId); roleNames = policyDAO.getPolicyAppliedRoles(policy.getId()); - profile = profileDAO.getProfiles(profileId); + profile = profileDAO.getProfile(profileId); policy.setProfile(profile); policy.setRoles(roleNames); @@ -474,7 +474,7 @@ public class PolicyManagerImpl implements PolicyManager { policy = policyDAO.getPolicy(policyId); roleNames = policyDAO.getPolicyAppliedRoles(policyId); - Profile profile = profileDAO.getProfiles(policy.getProfileId()); + Profile profile = profileDAO.getProfile(policy.getProfileId()); policy.setProfile(profile); policy.setRoles(roleNames); @@ -871,12 +871,9 @@ public class PolicyManagerImpl implements PolicyManager { @Override public int getPolicyCount() throws PolicyManagementException { - - int policyCount; try { PolicyManagementDAOFactory.openConnection(); - policyCount = policyDAO.getPolicyCount(); - return policyCount; + return policyDAO.getPolicyCount(); } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while getting policy count", e); } catch (SQLException e) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java index 6c7cfcdb693..394124cbeb5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java @@ -147,7 +147,7 @@ public class ProfileManagerImpl implements ProfileManager { try { PolicyManagementDAOFactory.openConnection(); - profile = profileDAO.getProfiles(profileId); + profile = profileDAO.getProfile(profileId); featureList = featureDAO.getFeaturesForProfile(profileId); profile.setProfileFeaturesList(featureList); } catch (ProfileManagerDAOException e) { diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml index a20ebb17c68..eae36b42e94 100644 --- a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml @@ -37,14 +37,6 @@ This feature contains oauth functionality - - - - - - - - @@ -101,8 +93,6 @@ - - org.wso2.maven carbon-p2-plugin @@ -123,20 +113,6 @@ org.eclipse.equinox.p2.type.group:false - - - - - - - - - - - - - - org.wso2.carbon.core.server:${carbon.kernel.version} @@ -145,10 +121,6 @@ - - - -