|
|
|
@ -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<Device> 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<Device> getDevices(String type, PaginationRequest request, int tenantId)
|
|
|
|
|
public List<Device> 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<Device> getDevicesOfUser(String username, PaginationRequest request, int tenantId)
|
|
|
|
|
public List<Device> 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<Device> getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request,
|
|
|
|
|
int tenantId) throws DeviceManagementDAOException {
|
|
|
|
|
public List<Device> getDevicesByName(PaginationRequest request, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
Connection conn;
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
List<Device> 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<Device> getDevicesByName(String deviceName, PaginationRequest request, int tenantId)
|
|
|
|
|
public List<Device> getDevicesByOwnership(PaginationRequest request, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
Connection conn;
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
List<Device> 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<Device> getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request,
|
|
|
|
|
int tenantId) throws DeviceManagementDAOException {
|
|
|
|
|
public List<Device> getDevicesByStatus(PaginationRequest request, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
Connection conn;
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
List<Device> 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);
|
|
|
|
|
}
|
|
|
|
|