Merge pull request #786 from harshanL/master

Fixed wso2/product-iots#406
4.x.x
Geeth 8 years ago committed by GitHub
commit 11cd14321f

@ -221,6 +221,12 @@ public interface DeviceManagementService {
required = false) required = false)
@QueryParam("user") @QueryParam("user")
String user, String user,
@ApiParam(
name = "userPattern",
value = "The pattern of username of the owner of the device.",
required = false)
@QueryParam("userPattern")
String userPattern,
@ApiParam( @ApiParam(
name = "role", name = "role",
value = "A role of device owners. Ex : store-admin", value = "A role of device owners. Ex : store-admin",

@ -90,6 +90,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("name") String name, @QueryParam("name") String name,
@QueryParam("type") String type, @QueryParam("type") String type,
@QueryParam("user") String user, @QueryParam("user") String user,
@QueryParam("userPattern") String userPattern,
@QueryParam("role") String role, @QueryParam("role") String role,
@QueryParam("ownership") String ownership, @QueryParam("ownership") String ownership,
@QueryParam("status") String status, @QueryParam("status") String status,
@ -126,9 +127,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
if (type != null && !type.isEmpty()) { if (type != null && !type.isEmpty()) {
request.setDeviceType(type); request.setDeviceType(type);
} }
if (user != null && !user.isEmpty()) {
request.setOwner(user);
}
if (ownership != null && !ownership.isEmpty()) { if (ownership != null && !ownership.isEmpty()) {
RequestValidationUtil.validateOwnershipType(ownership); RequestValidationUtil.validateOwnershipType(ownership);
request.setOwnership(ownership); request.setOwnership(ownership);
@ -151,6 +149,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
if (deviceAccessAuthorizationService.isDeviceAdminUser()) { if (deviceAccessAuthorizationService.isDeviceAdminUser()) {
if (user != null && !user.isEmpty()) { if (user != null && !user.isEmpty()) {
request.setOwner(MultitenantUtils.getTenantAwareUsername(user)); request.setOwner(MultitenantUtils.getTenantAwareUsername(user));
} else if (userPattern != null && !userPattern.isEmpty()) {
request.setOwnerPattern(userPattern);
} }
} else { } else {
if (user != null && !user.isEmpty()) { if (user != null && !user.isEmpty()) {

@ -29,6 +29,7 @@ public class PaginationRequest {
private int rowCount; private int rowCount;
private int groupId; private int groupId;
private String owner; private String owner;
private String ownerPattern;
private String status; private String status;
private String deviceType; private String deviceType;
private String deviceName; private String deviceName;
@ -120,4 +121,12 @@ public class PaginationRequest {
public void setOwnerRole(String ownerRole) { public void setOwnerRole(String ownerRole) {
this.ownerRole = ownerRole; this.ownerRole = ownerRole;
} }
public String getOwnerPattern() {
return ownerPattern;
}
public void setOwnerPattern(String ownerPattern) {
this.ownerPattern = ownerPattern;
}
} }

@ -485,6 +485,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
boolean isDeviceNameProvided = false; boolean isDeviceNameProvided = false;
String owner = request.getOwner(); String owner = request.getOwner();
boolean isOwnerProvided = false; boolean isOwnerProvided = false;
String ownerPattern = request.getOwnerPattern();
boolean isOwnerPatternProvided = false;
String ownership = request.getOwnership(); String ownership = request.getOwnership();
boolean isOwnershipProvided = false; boolean isOwnershipProvided = false;
String status = request.getStatus(); String status = request.getStatus();
@ -523,9 +525,13 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
isOwnershipProvided = true; isOwnershipProvided = true;
} }
//Add the query for owner
if (owner != null && !owner.isEmpty()) { if (owner != null && !owner.isEmpty()) {
sql = sql + " AND LOWER(e.OWNER) LIKE LOWER(?)"; sql = sql + " AND e.OWNER = ?";
isOwnerProvided = true; isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
isOwnerPatternProvided = true;
} }
if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
@ -551,7 +557,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
stmt.setString(paramIdx++, request.getOwnership()); stmt.setString(paramIdx++, request.getOwnership());
} }
if (isOwnerProvided) { if (isOwnerProvided) {
stmt.setString(paramIdx++, request.getOwner() + "%"); stmt.setString(paramIdx++, owner);
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
} }
if (isStatusProvided) { if (isStatusProvided) {
stmt.setString(paramIdx++, request.getStatus()); stmt.setString(paramIdx++, request.getStatus());

@ -48,6 +48,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
boolean isDeviceNameProvided = false; boolean isDeviceNameProvided = false;
String owner = request.getOwner(); String owner = request.getOwner();
boolean isOwnerProvided = false; boolean isOwnerProvided = false;
String ownerPattern = request.getOwnerPattern();
boolean isOwnerPatternProvided = false;
String ownership = request.getOwnership(); String ownership = request.getOwnership();
boolean isOwnershipProvided = false; boolean isOwnershipProvided = false;
String status = request.getStatus(); String status = request.getStatus();
@ -95,8 +97,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
//Add the query for owner //Add the query for owner
if (owner != null && !owner.isEmpty()) { if (owner != null && !owner.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?"; sql = sql + " AND e.OWNER = ?";
isOwnerProvided = true; isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
isOwnerPatternProvided = true;
} }
//Add the query for status //Add the query for status
if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
@ -113,21 +118,23 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
stmt.setLong(paramIdx++, since.getTime()); stmt.setLong(paramIdx++, since.getTime());
} }
if (isDeviceTypeProvided) { if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, request.getDeviceType()); stmt.setString(paramIdx++, deviceType);
} }
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
stmt.setString(paramIdx++, request.getDeviceName() + "%"); stmt.setString(paramIdx++, deviceName + "%");
} }
stmt.setInt(paramIdx++, tenantId); stmt.setInt(paramIdx++, tenantId);
if (isOwnershipProvided) { if (isOwnershipProvided) {
stmt.setString(paramIdx++, request.getOwnership()); stmt.setString(paramIdx++, ownership);
} }
if (isOwnerProvided) { if (isOwnerProvided) {
stmt.setString(paramIdx++, request.getOwner() + "%"); stmt.setString(paramIdx++, owner);
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
} }
if (isStatusProvided) { if (isStatusProvided) {
stmt.setString(paramIdx++, request.getStatus()); stmt.setString(paramIdx++, status);
} }
stmt.setInt(paramIdx++, request.getStartIndex()); stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount()); stmt.setInt(paramIdx, request.getRowCount());

@ -54,6 +54,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
boolean isDeviceNameProvided = false; boolean isDeviceNameProvided = false;
String owner = request.getOwner(); String owner = request.getOwner();
boolean isOwnerProvided = false; boolean isOwnerProvided = false;
String ownerPattern = request.getOwnerPattern();
boolean isOwnerPatternProvided = false;
String ownership = request.getOwnership(); String ownership = request.getOwnership();
boolean isOwnershipProvided = false; boolean isOwnershipProvided = false;
String status = request.getStatus(); String status = request.getStatus();
@ -101,8 +103,11 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
//Add the query for owner //Add the query for owner
if (owner != null && !owner.isEmpty()) { if (owner != null && !owner.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?"; sql = sql + " AND e.OWNER = ?";
isOwnerProvided = true; isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
isOwnerPatternProvided = true;
} }
//Add the query for status //Add the query for status
if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
@ -119,20 +124,23 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
stmt.setLong(paramIdx++, since.getTime()); stmt.setLong(paramIdx++, since.getTime());
} }
if (isDeviceTypeProvided) { if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, request.getDeviceType()); stmt.setString(paramIdx++, deviceType);
} }
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
stmt.setString(paramIdx++, request.getDeviceName() + "%"); stmt.setString(paramIdx++, deviceName + "%");
} }
stmt.setInt(paramIdx++, tenantId); stmt.setInt(paramIdx++, tenantId);
if (isOwnershipProvided) { if (isOwnershipProvided) {
stmt.setString(paramIdx++, request.getOwnership()); stmt.setString(paramIdx++, ownership);
} }
if (isOwnerProvided) { if (isOwnerProvided) {
stmt.setString(paramIdx++, request.getOwner() + "%"); stmt.setString(paramIdx++, owner);
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
} }
if (isStatusProvided) { if (isStatusProvided) {
stmt.setString(paramIdx++, request.getStatus()); stmt.setString(paramIdx++, status);
} }
stmt.setInt(paramIdx++, request.getStartIndex()); stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount()); stmt.setInt(paramIdx, request.getRowCount());

@ -51,6 +51,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
boolean isDeviceNameProvided = false; boolean isDeviceNameProvided = false;
String owner = request.getOwner(); String owner = request.getOwner();
boolean isOwnerProvided = false; boolean isOwnerProvided = false;
String ownerPattern = request.getOwnerPattern();
boolean isOwnerPatternProvided = false;
String ownership = request.getOwnership(); String ownership = request.getOwnership();
boolean isOwnershipProvided = false; boolean isOwnershipProvided = false;
String status = request.getStatus(); String status = request.getStatus();
@ -85,8 +87,11 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
//Add the query for owner //Add the query for owner
if (owner != null && !owner.isEmpty()) { if (owner != null && !owner.isEmpty()) {
sql = sql + " AND LOWER(e.OWNER) LIKE LOWER(?)"; sql = sql + " AND e.OWNER = ?";
isOwnerProvided = true; isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
isOwnerPatternProvided = true;
} }
//Add the query for status //Add the query for status
if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
@ -100,20 +105,23 @@ 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.getDeviceType()); stmt.setString(paramIdx++, deviceType);
} }
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
stmt.setString(paramIdx++, request.getDeviceName() + "%"); stmt.setString(paramIdx++, deviceName + "%");
} }
stmt.setInt(paramIdx++, tenantId); stmt.setInt(paramIdx++, tenantId);
if (isOwnershipProvided) { if (isOwnershipProvided) {
stmt.setString(paramIdx++, request.getOwnership()); stmt.setString(paramIdx++, ownership);
} }
if (isOwnerProvided) { if (isOwnerProvided) {
stmt.setString(paramIdx++, request.getOwner() + "%"); stmt.setString(paramIdx++, owner);
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
} }
if (isStatusProvided) { if (isStatusProvided) {
stmt.setString(paramIdx++, request.getStatus()); stmt.setString(paramIdx++, status);
} }
stmt.setInt(paramIdx++, request.getRowCount()); stmt.setInt(paramIdx++, request.getRowCount());
stmt.setInt(paramIdx, request.getStartIndex()); stmt.setInt(paramIdx, request.getStartIndex());

@ -51,6 +51,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
boolean isDeviceNameProvided = false; boolean isDeviceNameProvided = false;
String owner = request.getOwner(); String owner = request.getOwner();
boolean isOwnerProvided = false; boolean isOwnerProvided = false;
String ownerPattern = request.getOwnerPattern();
boolean isOwnerPatternProvided = false;
String ownership = request.getOwnership(); String ownership = request.getOwnership();
boolean isOwnershipProvided = false; boolean isOwnershipProvided = false;
String status = request.getStatus(); String status = request.getStatus();
@ -98,8 +100,11 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
//Add the query for owner //Add the query for owner
if (owner != null && !owner.isEmpty()) { if (owner != null && !owner.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?"; sql = sql + " AND e.OWNER = ?";
isOwnerProvided = true; isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
isOwnerPatternProvided = true;
} }
//Add the query for status //Add the query for status
if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
@ -116,20 +121,23 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
stmt.setLong(paramIdx++, since.getTime()); stmt.setLong(paramIdx++, since.getTime());
} }
if (isDeviceTypeProvided) { if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, request.getDeviceType()); stmt.setString(paramIdx++, deviceType);
} }
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
stmt.setString(paramIdx++, request.getDeviceName() + "%"); stmt.setString(paramIdx++, deviceName + "%");
} }
stmt.setInt(paramIdx++, tenantId); stmt.setInt(paramIdx++, tenantId);
if (isOwnershipProvided) { if (isOwnershipProvided) {
stmt.setString(paramIdx++, request.getOwnership()); stmt.setString(paramIdx++, ownership);
} }
if (isOwnerProvided) { if (isOwnerProvided) {
stmt.setString(paramIdx++, request.getOwner() + "%"); stmt.setString(paramIdx++, owner);
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
} }
if (isStatusProvided) { if (isStatusProvided) {
stmt.setString(paramIdx++, request.getStatus()); stmt.setString(paramIdx++, status);
} }
stmt.setInt(paramIdx++, request.getStartIndex()); stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount()); stmt.setInt(paramIdx, request.getRowCount());

@ -283,6 +283,9 @@ deviceModule = function () {
publicMethods.getDevices = function (userName) { publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] + var url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices"; devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
if (userName && userName !== "") {
url = url + "?user=" + userName;
}
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
var devices = JSON.parse(responsePayload.responseText).devices; var devices = JSON.parse(responsePayload.responseText).devices;

@ -155,7 +155,7 @@ function loadDevices(searchType, searchParam) {
serviceURL = "/api/device-mgt/v1.0/devices"; serviceURL = "/api/device-mgt/v1.0/devices";
} else if (permissionsUtil.hasPermission("LIST_OWN_DEVICES")) { } else if (permissionsUtil.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices //Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/devices?username=" + currentUser; serviceURL = "/api/device-mgt/v1.0/devices?user=" + currentUser;
} else { } else {
$("#loading-content").remove(); $("#loading-content").remove();
$('#device-table').addClass('hidden'); $('#device-table').addClass('hidden');
@ -282,7 +282,7 @@ function loadDevices(searchType, searchParam) {
}, },
{ {
targets: 2, targets: 2,
data: 'user', data: 'userPattern',
class: 'remove-padding-top viewEnabledIcon' class: 'remove-padding-top viewEnabledIcon'
}, },
{ {
@ -410,7 +410,7 @@ function loadDevices(searchType, searchParam) {
$(row).attr('data-url', context + '/device/' + htmlspecialchars(data.deviceType) + '?id=' + htmlspecialchars(data.deviceIdentifier)); $(row).attr('data-url', context + '/device/' + htmlspecialchars(data.deviceType) + '?id=' + htmlspecialchars(data.deviceIdentifier));
var model = htmlspecialchars(getPropertyValue(data.properties, 'DEVICE_MODEL')); var model = htmlspecialchars(getPropertyValue(data.properties, 'DEVICE_MODEL'));
var vendor = htmlspecialchars(getPropertyValue(data.properties, 'VENDOR')); var vendor = htmlspecialchars(getPropertyValue(data.properties, 'VENDOR'));
var owner = htmlspecialchars(data.user); var owner = htmlspecialchars(data.userPattern);
var status = htmlspecialchars(data.status); var status = htmlspecialchars(data.status);
var ownership = htmlspecialchars(data.ownership); var ownership = htmlspecialchars(data.ownership);
var deviceType = htmlspecialchars(data.deviceType); var deviceType = htmlspecialchars(data.deviceType);
@ -460,7 +460,7 @@ function loadDevices(searchType, searchParam) {
{ {
model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"), model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"),
vendor: getPropertyValue(data.devices[index].properties, "VENDOR"), vendor: getPropertyValue(data.devices[index].properties, "VENDOR"),
user: data.devices[index].enrolmentInfo.owner, userPattern: data.devices[index].enrolmentInfo.owner,
status: data.devices[index].enrolmentInfo.status, status: data.devices[index].enrolmentInfo.status,
ownership: data.devices[index].enrolmentInfo.ownership, ownership: data.devices[index].enrolmentInfo.ownership,
deviceType: data.devices[index].type, deviceType: data.devices[index].type,

Loading…
Cancel
Save