diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index e337fc88fa5..dc1578fe10a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -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", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 73da2227520..796a618bc15 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -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); @@ -149,8 +147,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { // check whether the user is device-mgt admin if (deviceAccessAuthorizationService.isDeviceAdminUser()) { - if (user != null && !user.isEmpty()) { + 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()) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java index 151e86b6ad6..3799b397ba2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java @@ -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; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 71ba7b24edf..d62f2c1674c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -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()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index b60072be2ac..353eaedb38a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -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()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index a1773f505fd..2f96e94d003 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -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()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 2965f727ed6..8578892885a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -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()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index fe942787f89..c1b4dc0529c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -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()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 0138c578977..755768d5f84 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -302,6 +302,9 @@ deviceModule = function () { publicMethods.getDevices = function (userName) { var url = devicemgtProps["httpsURL"] + 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; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index f8649271860..007cb4e01c6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -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,