mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
8628e5e523
@ -27,10 +27,15 @@ public class PaginationRequest {
|
|||||||
private int rowCount;
|
private int rowCount;
|
||||||
private String owner;
|
private String owner;
|
||||||
private String status;
|
private String status;
|
||||||
private String type;
|
private String deviceType;
|
||||||
private String deviceName;
|
private String deviceName;
|
||||||
private String ownership;
|
private String ownership;
|
||||||
|
|
||||||
|
public PaginationRequest(int start, int rowCount) {
|
||||||
|
this.startIndex = start;
|
||||||
|
this.rowCount = rowCount;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStartIndex() {
|
public int getStartIndex() {
|
||||||
return startIndex;
|
return startIndex;
|
||||||
}
|
}
|
||||||
@ -63,12 +68,12 @@ public class PaginationRequest {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getDeviceType() {
|
||||||
return type;
|
return deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setDeviceType(String deviceType) {
|
||||||
this.type = type;
|
this.deviceType = deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeviceName() {
|
public String getDeviceName() {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public interface DeviceDAO {
|
|||||||
* @return returns the device count of given type.
|
* @return returns the device count of given type.
|
||||||
* @throws DeviceManagementDAOException
|
* @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.
|
* 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.
|
* @return returns the device count of given status.
|
||||||
* @throws DeviceManagementDAOException
|
* @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.
|
* 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.
|
* @return returns the device count of given ownership.
|
||||||
* @throws DeviceManagementDAOException
|
* @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.
|
* 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.
|
* 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 and search.
|
||||||
* @param request PaginationRequest object holding the data for pagination
|
|
||||||
* @param tenantId tenant id.
|
* @param tenantId tenant id.
|
||||||
* @return returns paginated list of devices of provided type.
|
* @return returns paginated list of devices of provided type.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<Device> getDevices(String type, PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
List<Device> getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to retrieve all the devices of a given tenant and device type.
|
* This method is used to retrieve all the devices of a given tenant and device type.
|
||||||
@ -203,15 +202,14 @@ public interface DeviceDAO {
|
|||||||
List<Device> getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException;
|
List<Device> 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 and search data.
|
||||||
* @param request PaginationRequest object holding the data for pagination
|
|
||||||
* @param tenantId tenant id.
|
* @param tenantId tenant id.
|
||||||
* @return returns paginated list of devices in which owner matches (search) with given username.
|
* @return returns paginated list of devices in which owner matches (search) with given username.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<Device> getDevicesOfUser(String username, PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
List<Device> getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to retrieve the device count of a given tenant.
|
* This method is used to retrieve the device count of a given tenant.
|
||||||
@ -251,15 +249,14 @@ public interface DeviceDAO {
|
|||||||
List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException;
|
List<Device> 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 and device search info.
|
||||||
* @param request PaginationRequest object holding the data for pagination
|
|
||||||
* @param tenantId tenant id.
|
* @param tenantId tenant id.
|
||||||
* @return returns paginated list of devices which name matches (search) given device-name.
|
* @return returns paginated list of devices which name matches (search) given device-name.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<Device> getDevicesByName(String deviceName, PaginationRequest request, int tenantId)
|
List<Device> getDevicesByName(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException;
|
throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,27 +317,25 @@ public interface DeviceDAO {
|
|||||||
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException;
|
List<Device> 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 and device search.
|
||||||
* @param request PaginationRequest object holding the data for pagination
|
|
||||||
* @param tenantId tenant id.
|
* @param tenantId tenant id.
|
||||||
* @return returns list of devices of given ownership.
|
* @return returns list of devices of given ownership.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<Device> getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request, int tenantId)
|
List<Device> getDevicesByOwnership(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException;
|
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 request PaginationRequest object holding the data for pagination
|
||||||
* @param tenantId tenant id.
|
* @param tenantId tenant id.
|
||||||
* @return returns paginated list of devices of given status.
|
* @return returns paginated list of devices of given status.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request, int tenantId)
|
List<Device> getDevicesByStatus(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException;
|
throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -368,7 +368,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
String deviceType = request.getType();
|
String deviceType = request.getDeviceType();
|
||||||
boolean isDeviceTypeProvided = false;
|
boolean isDeviceTypeProvided = false;
|
||||||
String deviceName = request.getDeviceName();
|
String deviceName = request.getDeviceName();
|
||||||
boolean isDeviceNameProvided = false;
|
boolean isDeviceNameProvided = false;
|
||||||
@ -415,7 +415,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
int paramIdx = 2;
|
int paramIdx = 2;
|
||||||
if (isDeviceTypeProvided) {
|
if (isDeviceTypeProvided) {
|
||||||
stmt.setString(paramIdx++, request.getType());
|
stmt.setString(paramIdx++, request.getDeviceType());
|
||||||
}
|
}
|
||||||
if (isDeviceNameProvided) {
|
if (isDeviceNameProvided) {
|
||||||
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
||||||
@ -444,7 +444,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDeviceCount(String type, int tenantId) throws DeviceManagementDAOException {
|
public int getDeviceCountByType(String type, int tenantId) throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -478,11 +478,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT COUNT(e1.DEVICE_ID) AS DEVICE_COUNT FROM DM_DEVICE d, (SELECT e.DEVICE_ID " +
|
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";
|
"e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID AND t.ID = d.DEVICE_TYPE_ID";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, username + "%");
|
stmt.setString(2, username);
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
@ -526,7 +526,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDeviceCountByOwnership(EnrolmentInfo.OwnerShip ownerShip, int tenantId) throws DeviceManagementDAOException {
|
public int getDeviceCountByOwnership(String ownerShip, int tenantId) throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
int deviceCount = 0;
|
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 = ?";
|
"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 = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, ownerShip.toString());
|
stmt.setString(2, ownerShip);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
@ -554,7 +554,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDeviceCount(Status status, int tenantId) throws DeviceManagementDAOException {
|
public int getDeviceCountByStatus(String status, int tenantId) throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
int deviceCount = 0;
|
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 = ?";
|
"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 = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, status.toString());
|
stmt.setString(2, status);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao.impl.device;
|
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.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
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.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
@ -45,7 +44,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Device> devices = null;
|
List<Device> devices = null;
|
||||||
String deviceType = request.getType();
|
String deviceType = request.getDeviceType();
|
||||||
boolean isDeviceTypeProvided = false;
|
boolean isDeviceTypeProvided = false;
|
||||||
String deviceName = request.getDeviceName();
|
String deviceName = request.getDeviceName();
|
||||||
boolean isDeviceNameProvided = false;
|
boolean isDeviceNameProvided = false;
|
||||||
@ -98,7 +97,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
int paramIdx = 2;
|
int paramIdx = 2;
|
||||||
if (isDeviceTypeProvided) {
|
if (isDeviceTypeProvided) {
|
||||||
stmt.setString(paramIdx++, request.getType());
|
stmt.setString(paramIdx++, request.getDeviceType());
|
||||||
}
|
}
|
||||||
if (isDeviceNameProvided) {
|
if (isDeviceNameProvided) {
|
||||||
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
||||||
@ -131,7 +130,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevices(String type, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 = ? " +
|
"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 ?,?";
|
"AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ?,?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, type);
|
stmt.setString(1, request.getDeviceType());
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
@ -158,7 +157,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
devices.add(device);
|
devices.add(device);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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 {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -166,7 +165,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesOfUser(String username, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 " +
|
" 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, " +
|
"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.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 ?,?";
|
"AND t.ID = d.DEVICE_TYPE_ID LIMIT ?,?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, username + "%");
|
stmt.setString(2, request.getOwner());
|
||||||
stmt.setInt(3, request.getStartIndex());
|
stmt.setInt(3, request.getStartIndex());
|
||||||
stmt.setInt(4, request.getRowCount());
|
stmt.setInt(4, request.getRowCount());
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
@ -192,7 +191,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
||||||
username + "'", e);
|
request.getOwner() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -200,7 +199,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByName(String deviceName, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesByName(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 " +
|
"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 ?,?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ?,?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceName + "%");
|
stmt.setString(1, request.getDeviceName() + "%");
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
@ -227,7 +226,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
||||||
"'" + deviceName + "'", e);
|
"'" + request.getDeviceName() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -235,8 +234,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request,
|
public List<Device> getDevicesByOwnership(PaginationRequest request, int tenantId)
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> 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 ?,?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ?,?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, ownerShip.toString());
|
stmt.setString(2, request.getOwnership());
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
stmt.setInt(5, request.getRowCount());
|
stmt.setInt(5, request.getRowCount());
|
||||||
@ -262,7 +261,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
||||||
"'" + ownerShip + "'", e);
|
"'" + request.getOwnership() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -270,8 +269,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request,
|
public List<Device> getDevicesByStatus(PaginationRequest request, int tenantId)
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> 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 ?,?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ?,?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, status.toString());
|
stmt.setString(2, request.getStatus());
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
stmt.setInt(5, request.getRowCount());
|
stmt.setInt(5, request.getRowCount());
|
||||||
@ -297,7 +296,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
||||||
"'" + status + "'", e);
|
"'" + request.getStatus() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao.impl.device;
|
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.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
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.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
@ -46,7 +45,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Device> devices = null;
|
List<Device> devices = null;
|
||||||
String deviceType = request.getType();
|
String deviceType = request.getDeviceType();
|
||||||
boolean isDeviceTypeProvided = false;
|
boolean isDeviceTypeProvided = false;
|
||||||
String deviceName = request.getDeviceName();
|
String deviceName = request.getDeviceName();
|
||||||
boolean isDeviceNameProvided = false;
|
boolean isDeviceNameProvided = false;
|
||||||
@ -99,7 +98,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
int paramIdx = 2;
|
int paramIdx = 2;
|
||||||
if (isDeviceTypeProvided) {
|
if (isDeviceTypeProvided) {
|
||||||
stmt.setString(paramIdx++, request.getType());
|
stmt.setString(paramIdx++, request.getDeviceType());
|
||||||
}
|
}
|
||||||
if (isDeviceNameProvided) {
|
if (isDeviceNameProvided) {
|
||||||
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
||||||
@ -132,7 +131,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevices(String type, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 = ? " +
|
"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";
|
"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 = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, type);
|
stmt.setString(1, request.getDeviceType());
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
@ -159,7 +158,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
devices.add(device);
|
devices.add(device);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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 {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -167,7 +166,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesOfUser(String username, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 " +
|
" 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, " +
|
"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.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";
|
"AND t.ID = d.DEVICE_TYPE_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, username + "%");
|
stmt.setString(2, request.getOwner());
|
||||||
stmt.setInt(3, request.getStartIndex());
|
stmt.setInt(3, request.getStartIndex());
|
||||||
stmt.setInt(4, request.getRowCount());
|
stmt.setInt(4, request.getRowCount());
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
@ -193,7 +192,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
||||||
username + "'", e);
|
request.getOwner() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -201,43 +200,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request,
|
public List<Device> getDevicesByName(PaginationRequest request, int tenantId)
|
||||||
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 = ? OFFSET ? ROWS" +
|
|
||||||
" FETCH NEXT ? ROWS ONLY";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt.setString(2, status.toString());
|
|
||||||
stmt.setInt(3, tenantId);
|
|
||||||
stmt.setInt(4, request.getStartIndex());
|
|
||||||
stmt.setInt(5, request.getRowCount());
|
|
||||||
ResultSet rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
||||||
devices.add(device);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
|
||||||
"'" + status + "'", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Device> getDevicesByName(String deviceName, PaginationRequest request, int tenantId)
|
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -251,7 +214,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
"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";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceName + "%");
|
stmt.setString(1, request.getDeviceName() + "%");
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
@ -264,7 +227,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
||||||
"'" + deviceName + "'", e);
|
"'" + request.getDeviceName() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -272,8 +235,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request,
|
public List<Device> getDevicesByOwnership(PaginationRequest request, int tenantId)
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
@ -288,7 +251,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"ROWS FETCH NEXT ? ROWS ONLY";
|
"ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, ownerShip.toString());
|
stmt.setString(2, request.getOwnership());
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
stmt.setInt(5, request.getRowCount());
|
stmt.setInt(5, request.getRowCount());
|
||||||
@ -300,7 +263,43 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
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);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesByStatus(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 = ? OFFSET ? ROWS" +
|
||||||
|
" FETCH NEXT ? ROWS ONLY";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, request.getStatus());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setInt(4, request.getStartIndex());
|
||||||
|
stmt.setInt(5, request.getRowCount());
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||||
|
devices.add(device);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
||||||
|
"'" + request.getStatus() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao.impl.device;
|
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.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
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.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
@ -45,7 +44,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Device> devices = null;
|
List<Device> devices = null;
|
||||||
String deviceType = request.getType();
|
String deviceType = request.getDeviceType();
|
||||||
boolean isDeviceTypeProvided = false;
|
boolean isDeviceTypeProvided = false;
|
||||||
String deviceName = request.getDeviceName();
|
String deviceName = request.getDeviceName();
|
||||||
boolean isDeviceNameProvided = false;
|
boolean isDeviceNameProvided = false;
|
||||||
@ -98,7 +97,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
int paramIdx = 2;
|
int paramIdx = 2;
|
||||||
if (isDeviceTypeProvided) {
|
if (isDeviceTypeProvided) {
|
||||||
stmt.setString(paramIdx++, request.getType());
|
stmt.setString(paramIdx++, request.getDeviceType());
|
||||||
}
|
}
|
||||||
if (isDeviceNameProvided) {
|
if (isDeviceNameProvided) {
|
||||||
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
||||||
@ -113,8 +112,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
if (isStatusProvided) {
|
if (isStatusProvided) {
|
||||||
stmt.setString(paramIdx++, request.getStatus());
|
stmt.setString(paramIdx++, request.getStatus());
|
||||||
}
|
}
|
||||||
stmt.setInt(paramIdx, request.getRowCount());
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
stmt.setInt(paramIdx, request.getStartIndex());
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
devices = new ArrayList<>();
|
devices = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -131,7 +130,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevices(String type, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 = ? " +
|
"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 ?";
|
"AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? OFFSET ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, type);
|
stmt.setString(1, request.getDeviceType());
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getRowCount());
|
stmt.setInt(4, request.getRowCount());
|
||||||
@ -158,7 +157,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
devices.add(device);
|
devices.add(device);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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 {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -166,7 +165,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesOfUser(String username, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 " +
|
" 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, " +
|
"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.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 ?";
|
"AND t.ID = d.DEVICE_TYPE_ID LIMIT ? OFFSET ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, username + "%");
|
stmt.setString(2, request.getOwner());
|
||||||
stmt.setInt(3, request.getRowCount());
|
stmt.setInt(3, request.getRowCount());
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
@ -192,7 +191,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
||||||
username + "'", e);
|
request.getOwner() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -200,42 +199,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request,
|
public List<Device> getDevicesByName(PaginationRequest request, int tenantId)
|
||||||
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 ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt.setString(2, status.toString());
|
|
||||||
stmt.setInt(3, tenantId);
|
|
||||||
stmt.setInt(4, request.getRowCount());
|
|
||||||
stmt.setInt(5, request.getStartIndex());
|
|
||||||
ResultSet rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
||||||
devices.add(device);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
|
||||||
"'" + status + "'", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Device> getDevicesByName(String deviceName, PaginationRequest request, int tenantId)
|
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -249,7 +213,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
"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 ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? OFFSET ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceName + "%");
|
stmt.setString(1, request.getDeviceName() + "%");
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getRowCount());
|
stmt.setInt(4, request.getRowCount());
|
||||||
@ -262,7 +226,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
||||||
"'" + deviceName + "'", e);
|
"'" + request.getDeviceName() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -270,8 +234,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request,
|
public List<Device> getDevicesByOwnership(PaginationRequest request, int tenantId)
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
@ -285,7 +249,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ? OFFSET ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ? OFFSET ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, ownerShip.toString());
|
stmt.setString(2, request.getOwnership());
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getRowCount());
|
stmt.setInt(4, request.getRowCount());
|
||||||
stmt.setInt(5, request.getStartIndex());
|
stmt.setInt(5, request.getStartIndex());
|
||||||
@ -297,7 +261,42 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
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);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesByStatus(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 ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, request.getStatus());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setInt(4, request.getRowCount());
|
||||||
|
stmt.setInt(5, request.getStartIndex());
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||||
|
devices.add(device);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
||||||
|
"'" + request.getStatus() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao.impl.device;
|
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.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
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.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
@ -45,7 +44,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Device> devices = null;
|
List<Device> devices = null;
|
||||||
String deviceType = request.getType();
|
String deviceType = request.getDeviceType();
|
||||||
boolean isDeviceTypeProvided = false;
|
boolean isDeviceTypeProvided = false;
|
||||||
String deviceName = request.getDeviceName();
|
String deviceName = request.getDeviceName();
|
||||||
boolean isDeviceNameProvided = false;
|
boolean isDeviceNameProvided = false;
|
||||||
@ -98,7 +97,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
int paramIdx = 2;
|
int paramIdx = 2;
|
||||||
if (isDeviceTypeProvided) {
|
if (isDeviceTypeProvided) {
|
||||||
stmt.setString(paramIdx++, request.getType());
|
stmt.setString(paramIdx++, request.getDeviceType());
|
||||||
}
|
}
|
||||||
if (isDeviceNameProvided) {
|
if (isDeviceNameProvided) {
|
||||||
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
stmt.setString(paramIdx++, request.getDeviceName() + "%");
|
||||||
@ -131,7 +130,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevices(String type, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 = ? " +
|
"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";
|
"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 = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, type);
|
stmt.setString(1, request.getDeviceType());
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
@ -158,7 +157,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
devices.add(device);
|
devices.add(device);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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 {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -166,7 +165,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesOfUser(String username, PaginationRequest request, int tenantId)
|
public List<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
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 " +
|
" 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, " +
|
"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.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";
|
"AND t.ID = d.DEVICE_TYPE_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, username + "%");
|
stmt.setString(2, request.getOwner());
|
||||||
stmt.setInt(3, request.getStartIndex());
|
stmt.setInt(3, request.getStartIndex());
|
||||||
stmt.setInt(4, request.getRowCount());
|
stmt.setInt(4, request.getRowCount());
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
@ -192,7 +191,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
||||||
username + "'", e);
|
request.getOwner() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -200,43 +199,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request,
|
public List<Device> getDevicesByName(PaginationRequest request, int tenantId)
|
||||||
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 = ? OFFSET ? ROWS" +
|
|
||||||
" FETCH NEXT ? ROWS ONLY";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt.setString(2, status.toString());
|
|
||||||
stmt.setInt(3, tenantId);
|
|
||||||
stmt.setInt(4, request.getStartIndex());
|
|
||||||
stmt.setInt(5, request.getRowCount());
|
|
||||||
ResultSet rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
||||||
devices.add(device);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
|
||||||
"'" + status + "'", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Device> getDevicesByName(String deviceName, PaginationRequest request, int tenantId)
|
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -250,7 +213,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
"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";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceName + "%");
|
stmt.setString(1, request.getDeviceName() + "%");
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
@ -263,7 +226,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
||||||
"'" + deviceName + "'", e);
|
"'" + request.getDeviceName() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -271,8 +234,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request,
|
public List<Device> getDevicesByOwnership(PaginationRequest request, int tenantId)
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
@ -287,7 +250,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"ROWS FETCH NEXT ? ROWS ONLY";
|
"ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, ownerShip.toString());
|
stmt.setString(2, request.getOwnership());
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, tenantId);
|
||||||
stmt.setInt(4, request.getStartIndex());
|
stmt.setInt(4, request.getStartIndex());
|
||||||
stmt.setInt(5, request.getRowCount());
|
stmt.setInt(5, request.getRowCount());
|
||||||
@ -299,7 +262,43 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
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);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesByStatus(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 = ? OFFSET ? ROWS" +
|
||||||
|
" FETCH NEXT ? ROWS ONLY";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, request.getStatus());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setInt(4, request.getStartIndex());
|
||||||
|
stmt.setInt(5, request.getRowCount());
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||||
|
devices.add(device);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
||||||
|
"'" + request.getStatus() + "'", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,13 +42,12 @@ public interface DeviceManagementProviderService extends OperationManager {
|
|||||||
/**
|
/**
|
||||||
* Method to retrieve all the devices with pagination support.
|
* Method to retrieve all the devices with pagination support.
|
||||||
*
|
*
|
||||||
* @param deviceType Device platform
|
|
||||||
* @param request PaginationRequest object holding the data for pagination
|
* @param request PaginationRequest object holding the data for pagination
|
||||||
* @return PaginationResult - Result including the required parameters necessary to do pagination.
|
* @return PaginationResult - Result including the required parameters necessary to do pagination.
|
||||||
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
||||||
* devices.
|
* devices.
|
||||||
*/
|
*/
|
||||||
PaginationResult getAllDevices(String deviceType, PaginationRequest request) throws DeviceManagementException;
|
PaginationResult getDevicesByType(PaginationRequest request) throws DeviceManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to retrieve all the devices with pagination support.
|
* 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.
|
* 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.
|
* @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
|
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
||||||
* device list
|
* 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.
|
* 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.
|
* @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
|
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
||||||
* device list
|
* device list
|
||||||
*/
|
*/
|
||||||
PaginationResult getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip, PaginationRequest request)
|
PaginationResult getDevicesByOwnership(PaginationRequest request) throws DeviceManagementException;
|
||||||
throws DeviceManagementException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the list of devices owned by an user.
|
* 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.
|
* 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
|
* @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.
|
* @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
|
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
||||||
* device list
|
* 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;
|
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.
|
* 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
|
* @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.
|
* @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
|
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
||||||
* device list
|
* 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;
|
License getLicense(String deviceType, String languageCode) throws DeviceManagementException;
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.*;
|
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.configuration.mgt.TenantConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
@ -394,19 +393,20 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getAllDevices(String deviceType, PaginationRequest request) throws DeviceManagementException {
|
public PaginationResult getDevicesByType(PaginationRequest request) throws DeviceManagementException {
|
||||||
PaginationResult paginationResult = new PaginationResult();
|
PaginationResult paginationResult = new PaginationResult();
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
List<Device> allDevices = new ArrayList<>();
|
List<Device> allDevices = new ArrayList<>();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
|
String deviceType = request.getDeviceType();
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevices(deviceType, request, tenantId);
|
allDevices = deviceDAO.getDevices(request, tenantId);
|
||||||
count = deviceDAO.getDeviceCount(deviceType, tenantId);
|
count = deviceDAO.getDeviceCountByType(deviceType, tenantId);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
|
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) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -962,16 +962,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getDevicesOfUser(String username, PaginationRequest request)
|
public PaginationResult getDevicesOfUser(PaginationRequest request)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
PaginationResult result = new PaginationResult();
|
PaginationResult result = new PaginationResult();
|
||||||
int deviceCount = 0;
|
int deviceCount = 0;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
|
String username = request.getOwner();
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
List<Device> userDevices = new ArrayList<>();
|
List<Device> userDevices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
userDevices = deviceDAO.getDevicesOfUser(username, request, tenantId);
|
userDevices = deviceDAO.getDevicesOfUser(request, tenantId);
|
||||||
deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId);
|
deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the list of devices that " +
|
throw new DeviceManagementException("Error occurred while retrieving the list of devices that " +
|
||||||
@ -1007,17 +1008,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getDevicesByOwnership(EnrolmentInfo.OwnerShip ownerShip,
|
public PaginationResult getDevicesByOwnership(PaginationRequest request)
|
||||||
PaginationRequest request)
|
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
PaginationResult result = new PaginationResult();
|
PaginationResult result = new PaginationResult();
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
List<Device> allDevices;
|
List<Device> allDevices;
|
||||||
int deviceCount = 0;
|
int deviceCount = 0;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
|
String ownerShip = request.getOwnership();
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevicesByOwnership(ownerShip, request, tenantId);
|
allDevices = deviceDAO.getDevicesByOwnership(request, tenantId);
|
||||||
deviceCount = deviceDAO.getDeviceCountByOwnership(ownerShip, tenantId);
|
deviceCount = deviceDAO.getDeviceCountByOwnership(ownerShip, tenantId);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException(
|
throw new DeviceManagementException(
|
||||||
@ -1121,15 +1122,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getDevicesByName(String deviceName, PaginationRequest request)
|
public PaginationResult getDevicesByName(PaginationRequest request)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
PaginationResult result = new PaginationResult();
|
PaginationResult result = new PaginationResult();
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
List<Device> allDevices = new ArrayList<>();
|
List<Device> allDevices = new ArrayList<>();
|
||||||
|
String deviceName = request.getDeviceName();
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevicesByName(deviceName, request, tenantId);
|
allDevices = deviceDAO.getDevicesByName(request, tenantId);
|
||||||
int deviceCount = deviceDAO.getDeviceCountByName(deviceName, tenantId);
|
int deviceCount = deviceDAO.getDeviceCountByName(deviceName, tenantId);
|
||||||
result.setRecordsTotal(deviceCount);
|
result.setRecordsTotal(deviceCount);
|
||||||
result.setRecordsFiltered(deviceCount);
|
result.setRecordsFiltered(deviceCount);
|
||||||
@ -1221,16 +1223,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getDevicesByStatus(EnrolmentInfo.Status status, PaginationRequest request)
|
public PaginationResult getDevicesByStatus(PaginationRequest request)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
PaginationResult result = new PaginationResult();
|
PaginationResult result = new PaginationResult();
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
List<Device> allDevices = new ArrayList<>();
|
List<Device> allDevices = new ArrayList<>();
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
|
String status = request.getStatus();
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevicesByStatus(status, request, tenantId);
|
allDevices = deviceDAO.getDevicesByStatus(request, tenantId);
|
||||||
int deviceCount = deviceDAO.getDeviceCount(status, tenantId);
|
int deviceCount = deviceDAO.getDeviceCountByStatus(status, tenantId);
|
||||||
result.setRecordsTotal(deviceCount);
|
result.setRecordsTotal(deviceCount);
|
||||||
result.setRecordsFiltered(deviceCount);
|
result.setRecordsFiltered(deviceCount);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
<Name>OAuth</Name>
|
<Name>OAuth</Name>
|
||||||
<ClassName>org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthenticator</ClassName>
|
<ClassName>org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthenticator</ClassName>
|
||||||
<Parameters>
|
<Parameters>
|
||||||
<Parameter Name="IsRemote">true</Parameter>
|
<Parameter Name="IsRemote">false</Parameter>
|
||||||
<Parameter Name="TokenValidationEndpointUrl">https://localhost:9443</Parameter>
|
<Parameter Name="TokenValidationEndpointUrl">https://localhost:9443</Parameter>
|
||||||
<Parameter Name="Username">admin</Parameter>
|
<Parameter Name="Username">admin</Parameter>
|
||||||
<Parameter Name="Password">admin</Parameter>
|
<Parameter Name="Password">admin</Parameter>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user