Merge pull request #786 from harshanL/master

Fixed wso2/product-iots#406
revert-70aa11f8
Geeth 8 years ago committed by GitHub
commit 11cd14321f

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

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

@ -29,6 +29,7 @@ public class PaginationRequest {
private int rowCount;
private int groupId;
private String owner;
private String ownerPattern;
private String status;
private String deviceType;
private String deviceName;
@ -120,4 +121,12 @@ public class PaginationRequest {
public void setOwnerRole(String 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;
String owner = request.getOwner();
boolean isOwnerProvided = false;
String ownerPattern = request.getOwnerPattern();
boolean isOwnerPatternProvided = false;
String ownership = request.getOwnership();
boolean isOwnershipProvided = false;
String status = request.getStatus();
@ -523,9 +525,13 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
isOwnershipProvided = true;
}
//Add the query for owner
if (owner != null && !owner.isEmpty()) {
sql = sql + " AND LOWER(e.OWNER) LIKE LOWER(?)";
sql = sql + " AND e.OWNER = ?";
isOwnerProvided = true;
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
sql = sql + " AND e.OWNER LIKE ?";
isOwnerPatternProvided = true;
}
if (status != null && !status.isEmpty()) {
@ -551,7 +557,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
stmt.setString(paramIdx++, request.getOwnership());
}
if (isOwnerProvided) {
stmt.setString(paramIdx++, request.getOwner() + "%");
stmt.setString(paramIdx++, owner);
} else if (isOwnerPatternProvided) {
stmt.setString(paramIdx++, ownerPattern + "%");
}
if (isStatusProvided) {
stmt.setString(paramIdx++, request.getStatus());

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

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

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

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

@ -38,17 +38,17 @@ deviceModule = function () {
privateMethods.callBackend = function (url, method) {
if (constants["HTTP_GET"] == method) {
return serviceInvokers.XMLHttp.get(url,
function (backendResponse) {
var response = {};
response.content = backendResponse.responseText;
if (backendResponse.status == 200) {
response.status = "success";
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
backendResponse.status == 404 || backendResponse.status == 500) {
response.status = "error";
}
return response;
}
function (backendResponse) {
var response = {};
response.content = backendResponse.responseText;
if (backendResponse.status == 200) {
response.status = "success";
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
backendResponse.status == 404 || backendResponse.status == 500) {
response.status = "error";
}
return response;
}
);
} else {
log.error("Runtime error : This method only support HTTP GET requests.");
@ -282,7 +282,10 @@ deviceModule = function () {
publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
if (userName && userName !== "") {
url = url + "?user=" + userName;
}
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
var devices = JSON.parse(responsePayload.responseText).devices;

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

Loading…
Cancel
Save