diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java index ae813f50a88..9934bcd61c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java @@ -27,10 +27,15 @@ public class PaginationRequest { private int rowCount; private String owner; private String status; - private String type; + private String deviceType; private String deviceName; private String ownership; + public PaginationRequest(int start, int rowCount) { + this.startIndex = start; + this.rowCount = rowCount; + } + public int getStartIndex() { return startIndex; } @@ -63,12 +68,12 @@ public class PaginationRequest { this.status = status; } - public String getType() { - return type; + public String getDeviceType() { + return deviceType; } - public void setType(String type) { - this.type = type; + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; } public String getDeviceName() { 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 6b204b008d7..d154e8ae91d 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 @@ -38,7 +38,7 @@ public interface DeviceDAO { * @return returns the device count of given type. * @throws DeviceManagementDAOException */ - int getDeviceCount(String type, int tenantId) throws DeviceManagementDAOException; + int getDeviceCountByType(String type, int tenantId) throws DeviceManagementDAOException; /** * This method is used to get the device count by user. @@ -68,7 +68,7 @@ public interface DeviceDAO { * @return returns the device count of given status. * @throws DeviceManagementDAOException */ - int getDeviceCount(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; + int getDeviceCountByStatus(String status, int tenantId) throws DeviceManagementDAOException; /** * This method is used to get the device count by ownership. @@ -78,7 +78,7 @@ public interface DeviceDAO { * @return returns the device count of given ownership. * @throws DeviceManagementDAOException */ - int getDeviceCountByOwnership(EnrolmentInfo.OwnerShip ownerShip, int tenantId) throws DeviceManagementDAOException; + int getDeviceCountByOwnership(String ownerShip, int tenantId) throws DeviceManagementDAOException; /** * This method is used to add a device. @@ -174,13 +174,12 @@ public interface DeviceDAO { /** * This method is used to retrieve the devices of a given tenant and type as a paginated result. * - * @param type device type. - * @param request PaginationRequest object holding the data for pagination + * @param request PaginationRequest object holding the data for pagination and search. * @param tenantId tenant id. * @return returns paginated list of devices of provided type. * @throws DeviceManagementDAOException */ - List getDevices(String type, PaginationRequest request, int tenantId) throws DeviceManagementDAOException; + List getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; /** * This method is used to retrieve all the devices of a given tenant and device type. @@ -203,15 +202,14 @@ public interface DeviceDAO { List getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException; /** - * This method is used to retrieve devices of a given user. + * This method is used to retrieve devices of a given user as a paginated result. * - * @param username user name. - * @param request PaginationRequest object holding the data for pagination + * @param request PaginationRequest object holding the data for pagination and search data. * @param tenantId tenant id. * @return returns paginated list of devices in which owner matches (search) with given username. * @throws DeviceManagementDAOException */ - List getDevicesOfUser(String username, PaginationRequest request, int tenantId) throws DeviceManagementDAOException; + List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; /** * This method is used to retrieve the device count of a given tenant. @@ -251,15 +249,14 @@ public interface DeviceDAO { List getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException; /** - * This method is used to retrieve devices of a given device name. + * This method is used to retrieve devices of a given device name as a paginated result. * - * @param deviceName device name. - * @param request PaginationRequest object holding the data for pagination + * @param request PaginationRequest object holding the data for pagination and device search info. * @param tenantId tenant id. * @return returns paginated list of devices which name matches (search) given device-name. * @throws DeviceManagementDAOException */ - List getDevicesByName(String deviceName, PaginationRequest request, int tenantId) + List getDevicesByName(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; /** @@ -320,27 +317,25 @@ public interface DeviceDAO { List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; /** - * This method is used to retrieve devices of a given ownership. + * This method is used to retrieve devices of a given ownership as a paginated result. * - * @param ownerShip Ownership of devices. - * @param request PaginationRequest object holding the data for pagination + * @param request PaginationRequest object holding the data for pagination and device search. * @param tenantId tenant id. * @return returns list of devices of given ownership. * @throws DeviceManagementDAOException */ - List getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request, int tenantId) + List getDevicesByOwnership(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; /** - * This method is used to retrieve devices of a given enrollment status. + * This method is used to retrieve devices of a given enrollment status as a paginated result * - * @param status enrollment status. * @param request PaginationRequest object holding the data for pagination * @param tenantId tenant id. * @return returns paginated list of devices of given status. * @throws DeviceManagementDAOException */ - List getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request, int tenantId) + List getDevicesByStatus(PaginationRequest request, 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/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index c1e4718df1f..a41b2c80540 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -368,7 +368,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - String deviceType = request.getType(); + String deviceType = request.getDeviceType(); boolean isDeviceTypeProvided = false; String deviceName = request.getDeviceName(); boolean isDeviceNameProvided = false; @@ -415,7 +415,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { stmt.setInt(1, tenantId); int paramIdx = 2; if (isDeviceTypeProvided) { - stmt.setString(paramIdx++, request.getType()); + stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); @@ -444,7 +444,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } @Override - public int getDeviceCount(String type, int tenantId) throws DeviceManagementDAOException { + public int getDeviceCountByType(String type, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; @@ -478,11 +478,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { try { conn = this.getConnection(); String sql = "SELECT COUNT(e1.DEVICE_ID) AS DEVICE_COUNT FROM DM_DEVICE d, (SELECT e.DEVICE_ID " + - "FROM DM_ENROLMENT e WHERE e.TENANT_ID = ? AND e.OWNER LIKE ?) " + + "FROM DM_ENROLMENT e WHERE e.TENANT_ID = ? AND e.OWNER = ?) " + "e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID AND t.ID = d.DEVICE_TYPE_ID"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, username + "%"); + stmt.setString(2, username); ResultSet rs = stmt.executeQuery(); if (rs.next()) { @@ -526,7 +526,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } @Override - public int getDeviceCountByOwnership(EnrolmentInfo.OwnerShip ownerShip, int tenantId) throws DeviceManagementDAOException { + public int getDeviceCountByOwnership(String ownerShip, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; int deviceCount = 0; @@ -537,7 +537,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "DM_DEVICE_TYPE t WHERE d.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, ownerShip.toString()); + stmt.setString(2, ownerShip); stmt.setInt(3, tenantId); ResultSet rs = stmt.executeQuery(); @@ -554,7 +554,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } @Override - public int getDeviceCount(Status status, int tenantId) throws DeviceManagementDAOException { + public int getDeviceCountByStatus(String status, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; int deviceCount = 0; @@ -565,7 +565,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "DM_DEVICE_TYPE t WHERE d.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()); + stmt.setString(2, status); stmt.setInt(3, tenantId); ResultSet rs = stmt.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 134ccb8dffa..e009fd63430 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.dao.impl.device; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -45,7 +44,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; List devices = null; - String deviceType = request.getType(); + String deviceType = request.getDeviceType(); boolean isDeviceTypeProvided = false; String deviceName = request.getDeviceName(); boolean isDeviceNameProvided = false; @@ -98,7 +97,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt.setInt(1, tenantId); int paramIdx = 2; if (isDeviceTypeProvided) { - stmt.setString(paramIdx++, request.getType()); + stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); @@ -131,7 +130,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevices(String type, PaginationRequest request, int tenantId) + public List getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -146,7 +145,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "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 = ? LIMIT ?,?"; stmt = conn.prepareStatement(sql); - stmt.setString(1, type); + stmt.setString(1, request.getDeviceType()); stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); @@ -158,7 +157,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e); + throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -166,7 +165,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesOfUser(String username, PaginationRequest request, int tenantId) + public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -177,11 +176,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { " e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " + "AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " + "e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " + - "e.TENANT_ID = ? AND e.OWNER LIKE ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + + "e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + "AND t.ID = d.DEVICE_TYPE_ID LIMIT ?,?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, username + "%"); + stmt.setString(2, request.getOwner()); stmt.setInt(3, request.getStartIndex()); stmt.setInt(4, request.getRowCount()); ResultSet rs = stmt.executeQuery(); @@ -192,7 +191,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" + - username + "'", e); + request.getOwner() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -200,7 +199,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByName(String deviceName, PaginationRequest request, int tenantId) + public List getDevicesByName(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -214,7 +213,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "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 = ? LIMIT ?,?"; stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceName + "%"); + stmt.setString(1, request.getDeviceName() + "%"); stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); @@ -227,7 +226,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + - "'" + deviceName + "'", e); + "'" + request.getDeviceName() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -235,8 +234,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByOwnership(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; List devices = new ArrayList<>(); @@ -250,7 +249,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ?,?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, ownerShip.toString()); + stmt.setString(2, request.getOwnership()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -262,7 +261,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + - "'" + ownerShip + "'", e); + "'" + request.getOwnership() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -270,8 +269,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByStatus(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; List devices = new ArrayList<>(); @@ -285,7 +284,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ?,?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, status.toString()); + stmt.setString(2, request.getStatus()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -297,7 +296,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + - "'" + status + "'", e); + "'" + request.getStatus() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index c75162ae4a3..c5612c22c03 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.dao.impl.device; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -46,7 +45,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; List devices = null; - String deviceType = request.getType(); + String deviceType = request.getDeviceType(); boolean isDeviceTypeProvided = false; String deviceName = request.getDeviceName(); boolean isDeviceNameProvided = false; @@ -99,7 +98,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt.setInt(1, tenantId); int paramIdx = 2; if (isDeviceTypeProvided) { - stmt.setString(paramIdx++, request.getType()); + stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); @@ -132,7 +131,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevices(String type, PaginationRequest request, int tenantId) + public List getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -147,7 +146,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { "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 = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); - stmt.setString(1, type); + stmt.setString(1, request.getDeviceType()); stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); @@ -159,7 +158,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e); + throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -167,7 +166,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesOfUser(String username, PaginationRequest request, int tenantId) + public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -178,11 +177,11 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { " e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " + "AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " + "e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " + - "e.TENANT_ID = ? AND e.OWNER LIKE ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + + "e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + "AND t.ID = d.DEVICE_TYPE_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, username + "%"); + stmt.setString(2, request.getOwner()); stmt.setInt(3, request.getStartIndex()); stmt.setInt(4, request.getRowCount()); ResultSet rs = stmt.executeQuery(); @@ -193,7 +192,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" + - username + "'", e); + request.getOwner() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -201,23 +200,22 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByName(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; 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, 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 = ? OFFSET ? ROWS" + - " FETCH NEXT ? ROWS ONLY"; + 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 = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); - stmt.setString(2, status.toString()); + stmt.setString(1, request.getDeviceName() + "%"); + stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -228,8 +226,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + - "'" + status + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + + "'" + request.getDeviceName() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -237,22 +235,23 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByName(String deviceName, PaginationRequest request, int tenantId) + public List getDevicesByOwnership(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; 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 = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + 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, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + + "WHERE TENANT_ID = ? AND OWNERSHIP = ?) 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 = ? OFFSET ? " + + "ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceName + "%"); - stmt.setInt(2, tenantId); + stmt.setInt(1, tenantId); + stmt.setString(2, request.getOwnership()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -263,8 +262,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + - "'" + deviceName + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + + "'" + request.getOwnership() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -272,8 +271,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByStatus(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; List devices = new ArrayList<>(); @@ -283,12 +282,12 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { "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, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + - "WHERE TENANT_ID = ? AND OWNERSHIP = ?) 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 = ? OFFSET ? " + - "ROWS FETCH NEXT ? ROWS ONLY"; + "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 = ? OFFSET ? ROWS" + + " FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, ownerShip.toString()); + stmt.setString(2, request.getStatus()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -299,8 +298,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + - "'" + ownerShip + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + + "'" + request.getStatus() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index ce22de94f99..00ed10661bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.dao.impl.device; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -45,7 +44,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; List devices = null; - String deviceType = request.getType(); + String deviceType = request.getDeviceType(); boolean isDeviceTypeProvided = false; String deviceName = request.getDeviceName(); boolean isDeviceNameProvided = false; @@ -98,7 +97,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt.setInt(1, tenantId); int paramIdx = 2; if (isDeviceTypeProvided) { - stmt.setString(paramIdx++, request.getType()); + stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); @@ -113,8 +112,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { if (isStatusProvided) { stmt.setString(paramIdx++, request.getStatus()); } - stmt.setInt(paramIdx, request.getRowCount()); - stmt.setInt(paramIdx++, request.getStartIndex()); + stmt.setInt(paramIdx++, request.getRowCount()); + stmt.setInt(paramIdx, request.getStartIndex()); rs = stmt.executeQuery(); devices = new ArrayList<>(); while (rs.next()) { @@ -131,7 +130,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevices(String type, PaginationRequest request, int tenantId) + public List getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -146,7 +145,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { "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 = ? LIMIT ? OFFSET ?"; stmt = conn.prepareStatement(sql); - stmt.setString(1, type); + stmt.setString(1, request.getDeviceType()); stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getRowCount()); @@ -158,7 +157,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e); + throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -166,7 +165,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesOfUser(String username, PaginationRequest request, int tenantId) + public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -177,11 +176,11 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { " e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " + "AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " + "e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " + - "e.TENANT_ID = ? AND e.OWNER LIKE ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + + "e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + "AND t.ID = d.DEVICE_TYPE_ID LIMIT ? OFFSET ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, username + "%"); + stmt.setString(2, request.getOwner()); stmt.setInt(3, request.getRowCount()); stmt.setInt(4, request.getStartIndex()); ResultSet rs = stmt.executeQuery(); @@ -192,7 +191,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" + - username + "'", e); + request.getOwner() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -200,22 +199,22 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByName(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; 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, 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 = ? LIMIT ? OFFSET ?"; + 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 = ? LIMIT ? OFFSET ?"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); - stmt.setString(2, status.toString()); + stmt.setString(1, request.getDeviceName() + "%"); + stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getRowCount()); stmt.setInt(5, request.getStartIndex()); @@ -226,8 +225,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + - "'" + status + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + + "'" + request.getDeviceName() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -235,22 +234,22 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByName(String deviceName, PaginationRequest request, int tenantId) + public List getDevicesByOwnership(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; 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 = ? LIMIT ? OFFSET ?"; + 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, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + + "WHERE TENANT_ID = ? AND OWNERSHIP = ?) 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 = ? LIMIT ? OFFSET ?"; stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceName + "%"); - stmt.setInt(2, tenantId); + stmt.setInt(1, tenantId); + stmt.setString(2, request.getOwnership()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getRowCount()); stmt.setInt(5, request.getStartIndex()); @@ -261,8 +260,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + - "'" + deviceName + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + + "'" + request.getOwnership() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -270,8 +269,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByStatus(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; List devices = new ArrayList<>(); @@ -281,11 +280,11 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { "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, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + - "WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " + + "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 = ? LIMIT ? OFFSET ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, ownerShip.toString()); + stmt.setString(2, request.getStatus()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getRowCount()); stmt.setInt(5, request.getStartIndex()); @@ -296,8 +295,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + - "'" + ownerShip + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + + "'" + request.getStatus() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index 393712fb5ab..e3ecf07f22e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.dao.impl.device; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -45,7 +44,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; List devices = null; - String deviceType = request.getType(); + String deviceType = request.getDeviceType(); boolean isDeviceTypeProvided = false; String deviceName = request.getDeviceName(); boolean isDeviceNameProvided = false; @@ -98,7 +97,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt.setInt(1, tenantId); int paramIdx = 2; if (isDeviceTypeProvided) { - stmt.setString(paramIdx++, request.getType()); + stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); @@ -131,7 +130,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevices(String type, PaginationRequest request, int tenantId) + public List getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -146,7 +145,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { "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 = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); - stmt.setString(1, type); + stmt.setString(1, request.getDeviceType()); stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); @@ -158,7 +157,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e); + throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -166,7 +165,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesOfUser(String username, PaginationRequest request, int tenantId) + public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -177,11 +176,11 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { " e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " + "AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " + "e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " + - "e.TENANT_ID = ? AND e.OWNER LIKE ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + + "e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " + "AND t.ID = d.DEVICE_TYPE_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, username + "%"); + stmt.setString(2, request.getOwner()); stmt.setInt(3, request.getStartIndex()); stmt.setInt(4, request.getRowCount()); ResultSet rs = stmt.executeQuery(); @@ -192,7 +191,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" + - username + "'", e); + request.getOwner() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -200,23 +199,22 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByName(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; 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, 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 = ? OFFSET ? ROWS" + - " FETCH NEXT ? ROWS ONLY"; + 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 = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); - stmt.setString(2, status.toString()); + stmt.setString(1, request.getDeviceName() + "%"); + stmt.setInt(2, tenantId); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -227,8 +225,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + - "'" + status + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + + "'" + request.getDeviceName() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -236,22 +234,23 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByName(String deviceName, PaginationRequest request, int tenantId) + public List getDevicesByOwnership(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; 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 = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + 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, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + + "WHERE TENANT_ID = ? AND OWNERSHIP = ?) 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 = ? OFFSET ? " + + "ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceName + "%"); - stmt.setInt(2, tenantId); + stmt.setInt(1, tenantId); + stmt.setString(2, request.getOwnership()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -262,8 +261,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " + - "'" + deviceName + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + + "'" + request.getOwnership() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -271,8 +270,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request, - int tenantId) throws DeviceManagementDAOException { + public List getDevicesByStatus(PaginationRequest request, int tenantId) + throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; List devices = new ArrayList<>(); @@ -282,12 +281,12 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { "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, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + - "WHERE TENANT_ID = ? AND OWNERSHIP = ?) 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 = ? OFFSET ? " + - "ROWS FETCH NEXT ? ROWS ONLY"; + "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 = ? OFFSET ? ROWS" + + " FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setString(2, ownerShip.toString()); + stmt.setString(2, request.getStatus()); stmt.setInt(3, tenantId); stmt.setInt(4, request.getStartIndex()); stmt.setInt(5, request.getRowCount()); @@ -298,8 +297,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { devices.add(device); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " + - "'" + ownerShip + "'", e); + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + + "'" + request.getStatus() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } 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 8c1a3cb7f3c..75388447555 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 @@ -42,13 +42,12 @@ public interface DeviceManagementProviderService extends OperationManager { /** * Method to retrieve all the devices with pagination support. * - * @param deviceType Device platform * @param request PaginationRequest object holding the data for pagination * @return PaginationResult - Result including the required parameters necessary to do pagination. * @throws DeviceManagementException If some unusual behaviour is observed while fetching the * devices. */ - PaginationResult getAllDevices(String deviceType, PaginationRequest request) throws DeviceManagementException; + PaginationResult getDevicesByType(PaginationRequest request) throws DeviceManagementException; /** * Method to retrieve all the devices with pagination support. @@ -79,25 +78,22 @@ public interface DeviceManagementProviderService extends OperationManager { /** * Method to get the list of devices owned by an user with paging information. * - * @param userName Username of the user - * @param request PaginationRequest object holding the data for pagination + * @param request PaginationRequest object holding the data for pagination * @return List of devices owned by a particular user along with the required parameters necessary to do pagination. * @throws DeviceManagementException If some unusual behaviour is observed while fetching the * device list */ - PaginationResult getDevicesOfUser(String userName, PaginationRequest request) throws DeviceManagementException; + PaginationResult getDevicesOfUser(PaginationRequest request) throws DeviceManagementException; /** * Method to get the list of devices filtered by the ownership with paging information. * - * @param ownerShip Ownership type of devices - * @param request PaginationRequest object holding the data for pagination + * @param request PaginationRequest object holding the data for pagination * @return List of devices owned by a particular user along with the required parameters necessary to do pagination. * @throws DeviceManagementException If some unusual behaviour is observed while fetching the * device list */ - PaginationResult getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request) - throws DeviceManagementException; + PaginationResult getDevicesByOwnership(PaginationRequest request) throws DeviceManagementException; /** * Method to get the list of devices owned by an user. @@ -140,13 +136,12 @@ public interface DeviceManagementProviderService extends OperationManager { /** * This method is used to retrieve list of devices that matches with the given device name with paging information. * - * @param deviceName name of the device * @param request PaginationRequest object holding the data for pagination * @return List of devices in given status along with the required parameters necessary to do pagination. * @throws DeviceManagementException If some unusual behaviour is observed while fetching the * device list */ - PaginationResult getDevicesByName(String deviceName, PaginationRequest request) throws DeviceManagementException; + PaginationResult getDevicesByName(PaginationRequest request) throws DeviceManagementException; void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; @@ -162,13 +157,12 @@ public interface DeviceManagementProviderService extends OperationManager { /** * This method is used to retrieve list of devices based on the device status with paging information. * - * @param status Device status * @param request PaginationRequest object holding the data for pagination * @return List of devices in given status along with the required parameters necessary to do pagination. * @throws DeviceManagementException If some unusual behaviour is observed while fetching the * device list */ - PaginationResult getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request) throws DeviceManagementException; + PaginationResult getDevicesByStatus(PaginationRequest request) throws DeviceManagementException; License getLicense(String deviceType, String languageCode) throws DeviceManagementException; 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 16a1fa105e3..80a1ae57d5f 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 @@ -21,7 +21,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; @@ -394,19 +393,20 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getAllDevices(String deviceType, PaginationRequest request) throws DeviceManagementException { + public PaginationResult getDevicesByType(PaginationRequest request) throws DeviceManagementException { PaginationResult paginationResult = new PaginationResult(); List devices = new ArrayList<>(); List allDevices = new ArrayList<>(); int count = 0; int tenantId = this.getTenantId(); + String deviceType = request.getDeviceType(); try { DeviceManagementDAOFactory.openConnection(); - allDevices = deviceDAO.getDevices(deviceType, request, tenantId); - count = deviceDAO.getDeviceCount(deviceType, tenantId); + allDevices = deviceDAO.getDevices(request, tenantId); + count = deviceDAO.getDeviceCountByType(deviceType, tenantId); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + - "the current tenant", e); + "the current tenant of type " + deviceType, e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } finally { @@ -962,16 +962,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getDevicesOfUser(String username, PaginationRequest request) + public PaginationResult getDevicesOfUser(PaginationRequest request) throws DeviceManagementException { PaginationResult result = new PaginationResult(); int deviceCount = 0; int tenantId = this.getTenantId(); + String username = request.getOwner(); List devices = new ArrayList<>(); List userDevices = new ArrayList<>(); try { DeviceManagementDAOFactory.openConnection(); - userDevices = deviceDAO.getDevicesOfUser(username, request, tenantId); + userDevices = deviceDAO.getDevicesOfUser(request, tenantId); deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the list of devices that " + @@ -1007,17 +1008,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, - PaginationRequest request) + public PaginationResult getDevicesByOwnership(PaginationRequest request) throws DeviceManagementException { PaginationResult result = new PaginationResult(); List devices = new ArrayList<>(); List allDevices; int deviceCount = 0; int tenantId = this.getTenantId(); + String ownerShip = request.getOwnership(); try { DeviceManagementDAOFactory.openConnection(); - allDevices = deviceDAO.getDevicesByOwnership(ownerShip, request, tenantId); + allDevices = deviceDAO.getDevicesByOwnership(request, tenantId); deviceCount = deviceDAO.getDeviceCountByOwnership(ownerShip, tenantId); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException( @@ -1121,15 +1122,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getDevicesByName(String deviceName, PaginationRequest request) + public PaginationResult getDevicesByName(PaginationRequest request) throws DeviceManagementException { PaginationResult result = new PaginationResult(); int tenantId = this.getTenantId(); List devices = new ArrayList<>(); List allDevices = new ArrayList<>(); + String deviceName = request.getDeviceName(); try { DeviceManagementDAOFactory.openConnection(); - allDevices = deviceDAO.getDevicesByName(deviceName, request, tenantId); + allDevices = deviceDAO.getDevicesByName(request, tenantId); int deviceCount = deviceDAO.getDeviceCountByName(deviceName, tenantId); result.setRecordsTotal(deviceCount); result.setRecordsFiltered(deviceCount); @@ -1221,16 +1223,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public PaginationResult getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request) + public PaginationResult getDevicesByStatus(PaginationRequest request) throws DeviceManagementException { PaginationResult result = new PaginationResult(); List devices = new ArrayList<>(); List allDevices = new ArrayList<>(); int tenantId = this.getTenantId(); + String status = request.getStatus(); try { DeviceManagementDAOFactory.openConnection(); - allDevices = deviceDAO.getDevicesByStatus(status, request, tenantId); - int deviceCount = deviceDAO.getDeviceCount(status, tenantId); + allDevices = deviceDAO.getDevicesByStatus(request, tenantId); + int deviceCount = deviceDAO.getDeviceCountByStatus(status, tenantId); result.setRecordsTotal(deviceCount); result.setRecordsFiltered(deviceCount); } catch (DeviceManagementDAOException e) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index f78feca333f..7fd9d04d75b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -1282,11 +1282,6 @@ public class PolicyDAOImpl implements PolicyDAO { stmt.setInt(1, policyId); stmt.executeUpdate(); - String deleteComplianceStatus ="DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE POLICY_ID =?"; - stmt = conn.prepareStatement(deleteComplianceStatus); - stmt.setInt(1, policyId); - stmt.executeUpdate(); - if (log.isDebugEnabled()) { log.debug("Policy (" + policyId + ") related configs deleted from database."); } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 2ef6a292204..87e8b135272 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -308,12 +308,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( LAST_REQUESTED_TIME TIMESTAMP NULL, LAST_FAILED_TIME TIMESTAMP NULL, ATTEMPTS INT NULL, - PRIMARY KEY (ID), - CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION + PRIMARY KEY (ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index fc5639649fe..b2f954f69e9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -311,12 +311,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( LAST_REQUESTED_TIME DATETIME2(0) NULL, LAST_FAILED_TIME DATETIME2(0) NULL, ATTEMPTS INT NULL, - PRIMARY KEY (ID), - CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION + PRIMARY KEY (ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 2132a66d0ed..2c0fa846246 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -302,12 +302,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( LAST_REQUESTED_TIME TIMESTAMP NULL, LAST_FAILED_TIME TIMESTAMP NULL, ATTEMPTS INT NULL, - PRIMARY KEY (ID), - CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION + PRIMARY KEY (ID) )ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 10e92f5047b..728233d24b3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -397,10 +397,7 @@ CREATE TABLE DM_DEVICE_POLICY_APPLIED ( CONSTRAINT PK_DM_POLICY_DEV_APPLIED PRIMARY KEY (ID) , CONSTRAINT FK_DM_POLICY_DEV_APPLIED FOREIGN KEY (DEVICE_ID ) - REFERENCES DM_DEVICE (ID ), - CONSTRAINT FK_DM_POLICY_DEV_APPLY_POLICY - FOREIGN KEY (POLICY_ID ) - REFERENCES DM_POLICY (ID ) + REFERENCES DM_DEVICE (ID ) ) / -- Generate ID using sequence and trigger @@ -503,10 +500,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( LAST_REQUESTED_TIME TIMESTAMP(0) NULL, LAST_FAILED_TIME TIMESTAMP(0) NULL, ATTEMPTS NUMBER(10) NULL, - CONSTRAINT PK_DM_POLICY_COMP_STATUS PRIMARY KEY (ID), - CONSTRAINT FK_POLICY_COMP_STATUS_POLICY - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) + CONSTRAINT PK_DM_POLICY_COMP_STATUS PRIMARY KEY (ID) ) / -- Generate ID using sequence and trigger diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 4299ac52b6c..2e3654d6d08 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -266,12 +266,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( LAST_SUCCESS_TIME TIMESTAMP NULL, LAST_REQUESTED_TIME TIMESTAMP NULL, LAST_FAILED_TIME TIMESTAMP NULL, - ATTEMPTS INTEGER NULL, - CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION + ATTEMPTS INTEGER NULL ); CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml index a9e0c9d8326..0f3c278b34a 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml @@ -4,7 +4,7 @@ OAuth org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthenticator - true + false https://localhost:9443 admin admin diff --git a/pom.xml b/pom.xml index 37865f8aa5e..5c045450078 100644 --- a/pom.xml +++ b/pom.xml @@ -1519,7 +1519,7 @@ 4.6.0 - 5.0.5 + 5.0.7 4.5.0