Device search in store uninstall modal

revert-70ac1926
MalshaPiumini 4 years ago
parent e0669d3898
commit 74c4f1004a

@ -22,6 +22,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDT
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.SubscriptionManagementException;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.util.List;
@ -127,13 +128,12 @@ public interface SubscriptionManager {
* This method used to get the app id ,device ids and pass them to DM service method.
*
* @param appUUID UUID of the application release.
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param request paginated request object.
* @param status status of the devices.
* @return deviceDetails - device details for given application release.
* @throws {@link ApplicationManagementException} Exception of the application management
*/
PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID,
PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID,
List<String> status) throws ApplicationManagementException;
/***

@ -65,10 +65,7 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
import org.wso2.carbon.device.application.mgt.core.util.OAuthUtils;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.MDMAppConstants;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.App;
import org.wso2.carbon.device.mgt.common.app.mgt.MobileAppTypes;
import org.wso2.carbon.device.mgt.common.app.mgt.android.CustomApplication;
@ -88,7 +85,6 @@ import org.wso2.carbon.device.mgt.core.util.MDMIOSOperationUtil;
import org.wso2.carbon.device.mgt.core.util.MDMWindowsOperationUtil;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import javax.ws.rs.core.MediaType;
import java.io.BufferedReader;
@ -1223,7 +1219,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, List<String> status)
public PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, List<String> status)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
@ -1262,8 +1258,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
//pass the device id list to device manager service method
try {
PaginationResult deviceDetails = deviceManagementProviderService
.getAppSubscribedDevices(offsetValue, limitValue, deviceIdList, status);
PaginationResult deviceDetails = deviceManagementProviderService.getAppSubscribedDevices
(request, deviceIdList, status);
if (deviceDetails == null) {
String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList;
@ -1344,6 +1340,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
@Override
public PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID)
throws ApplicationManagementException {
PaginationRequest request = new PaginationRequest(offsetValue, limitValue);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
@ -1378,7 +1375,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try {
//pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService
.getAppSubscribedDevices(offsetValue, limitValue, deviceIdList, null);
.getAppSubscribedDevices(request, deviceIdList, null);
List<DeviceSubscriptionData> deviceSubscriptionDataList = new ArrayList<>();
if (!paginationResult.getData().isEmpty()) {

@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import javax.ws.rs.Path;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
@ -337,6 +338,28 @@ public interface SubscriptionManagementAPI {
response = ErrorResponse.class)
})
Response getAppInstalledDevices(
@ApiParam(
name = "name",
value = "The device name. For example, Nexus devices can have names, suhc as shamu, bullhead or angler.",
required = false)
@Size(max = 45)
String name,
@ApiParam(
name = "user",
value = "The username of the owner of the device.",
required = false)
@QueryParam("user")
String user,
@ApiParam(
name = "ownership",
allowableValues = "BYOD, COPE",
value = "Provide the ownership status of the device. The following values can be assigned:\n" +
"- BYOD: Bring Your Own Device\n" +
"- COPE: Corporate-Owned, Personally-Enabled",
required = false)
@QueryParam("ownership")
@Size(max = 45)
String ownership,
@ApiParam(
name="uuid",
value="uuid of the application release.",

@ -33,6 +33,7 @@ import org.wso2.carbon.device.application.mgt.common.BasicUserInfo;
import org.wso2.carbon.device.application.mgt.common.BasicUserInfoList;
import org.wso2.carbon.device.application.mgt.common.RoleList;
import org.wso2.carbon.device.application.mgt.common.DeviceGroupList;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
@ -273,6 +274,9 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@Produces("application/json")
@Path("/{uuid}/devices")
public Response getAppInstalledDevices(
@QueryParam("name") String name,
@QueryParam("user") String user,
@QueryParam("ownership") String ownership,
@PathParam("uuid") String uuid,
@DefaultValue("0")
@QueryParam("offset") int offset,
@ -281,8 +285,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@QueryParam("status") List<String> status) {
try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscribedDeviceDetails = subscriptionManager
.getAppInstalledDevices(offset, limit, uuid, status);
PaginationRequest request = new PaginationRequest(offset, limit);
if (name != null && !name.isEmpty()) {
request.setDeviceName(name);
}
if (user != null && !user.isEmpty()) {
request.setOwner(user);
}
if (ownership != null && !ownership.isEmpty()) {
request.setOwnership(ownership);
}
PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid, status);
DeviceList devices = new DeviceList();
devices.setList((List<Device>) subscribedDeviceDetails.getData());
devices.setCount(subscribedDeviceDetails.getRecordsTotal());

@ -651,16 +651,15 @@ public interface DeviceDAO {
/**
* This method is used to get the details of subscribed devices.
*
* @param deviceIds device ids of the subscribed devices.
* @param tenantId Id of the current tenant.
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param status status of the devices.
* @param deviceIds device ids of the subscribed devices.
* @param tenantId Id of the current tenant.
* @param request paginated request object.
* @param status status of the devices.
* @return devices - subscribed device details list
* @throws DeviceManagementDAOException if connections establishment fails.
*/
List<Device> getSubscribedDevices(int offsetValue, int limitValue, List<Integer> deviceIds,
int tenantId, List<String> status) throws DeviceManagementDAOException;
List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId,
List<String> status) throws DeviceManagementDAOException;
/**
* @param deviceIds device ids of the subscribed devices.

@ -877,16 +877,24 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
@Override
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, List<String> status)
public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId,
List<String> status)
throws DeviceManagementDAOException {
Connection conn;
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
String name = request.getDeviceName();
String user = request.getOwner();
String ownership = request.getOwnership();
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
boolean isDeviceNameProvided = false;
boolean isOwnerProvided = false;
boolean isOwnershipProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT "
+ "DM_DEVICE.ID AS DEVICE_ID, "
@ -914,6 +922,18 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (name != null && !name.isEmpty()) {
query += " AND DM_DEVICE.NAME LIKE ?";
isDeviceNameProvided = true;
}
if (ownership != null && !ownership.isEmpty()) {
query += " AND e.OWNERSHIP = ?";
isOwnershipProvided = true;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
query += buildStatusQuery(status);
isStatusProvided = true;
@ -926,8 +946,16 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
for (Integer deviceId : deviceIds) {
ps.setObject(index++, deviceId);
}
ps.setInt(index++, tenantId);
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
}
if (isOwnerProvided) {
ps.setString(index++, user);
}
if (isStatusProvided) {
for (String deviceStatus : status) {
ps.setString(index++, deviceStatus);

@ -847,16 +847,23 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
@Override
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, List<String> status)
public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId,
List<String> status)
throws DeviceManagementDAOException {
Connection conn;
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
String name = request.getDeviceName();
String user = request.getOwner();
String ownership = request.getOwnership();
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
boolean isDeviceNameProvided = false;
boolean isOwnerProvided = false;
boolean isOwnershipProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT "
+ "DM_DEVICE.ID AS DEVICE_ID, "
@ -884,6 +891,18 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (name != null && !name.isEmpty()) {
query += " AND DM_DEVICE.NAME LIKE ?";
isDeviceNameProvided = true;
}
if (ownership != null && !ownership.isEmpty()) {
query += " AND e.OWNERSHIP = ?";
isOwnershipProvided = true;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
query += buildStatusQuery(status);
isStatusProvided = true;
@ -898,6 +917,15 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
}
if (isOwnerProvided) {
ps.setString(index++, user);
}
if (isStatusProvided) {
for (String deviceStatus : status) {
ps.setString(index++, deviceStatus);

@ -827,16 +827,23 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
@Override
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, List<String> status)
public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId,
List<String> status)
throws DeviceManagementDAOException {
Connection conn;
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
String name = request.getDeviceName();
String user = request.getOwner();
String ownership = request.getOwnership();
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
boolean isDeviceNameProvided = false;
boolean isOwnerProvided = false;
boolean isOwnershipProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT "
+ "DM_DEVICE.ID AS DEVICE_ID, "
@ -864,6 +871,18 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (name != null && !name.isEmpty()) {
query += " AND DM_DEVICE.NAME LIKE ?";
isDeviceNameProvided = true;
}
if (ownership != null && !ownership.isEmpty()) {
query += " AND e.OWNERSHIP = ?";
isOwnershipProvided = true;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
query += buildStatusQuery(status);
isStatusProvided = true;
@ -878,6 +897,15 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
}
if (isOwnerProvided) {
ps.setString(index++, user);
}
if (isStatusProvided) {
for (String deviceStatus : status) {
ps.setString(index++, deviceStatus);

@ -693,16 +693,23 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
@Override
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
public List<Device> getSubscribedDevices(PaginationRequest request,
List<Integer> deviceIds, int tenantId, List<String> status)
throws DeviceManagementDAOException {
Connection conn;
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
String name = request.getDeviceName();
String user = request.getOwner();
String ownership = request.getOwnership();
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
boolean isDeviceNameProvided = false;
boolean isOwnerProvided = false;
boolean isOwnershipProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT "
+ "DM_DEVICE.ID AS DEVICE_ID, "
@ -730,6 +737,18 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (name != null && !name.isEmpty()) {
query += " AND DM_DEVICE.NAME LIKE ?";
isDeviceNameProvided = true;
}
if (ownership != null && !ownership.isEmpty()) {
query += " AND e.OWNERSHIP = ?";
isOwnershipProvided = true;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
query += buildStatusQuery(status);
isStatusProvided = true;
@ -744,6 +763,15 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
}
if (isOwnerProvided) {
ps.setString(index++, user);
}
if (isStatusProvided) {
for (String deviceStatus : status) {
ps.setString(index++, deviceStatus);

@ -905,14 +905,13 @@ public interface DeviceManagementProviderService {
* This method retrieves a list of subscribed devices.
*
* @param devicesIds devices ids of the subscribed devices.
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param status status of the devices.
* @param request paginated request object.
* @param status status of the devices.
* @return {@link PaginationResult}
* @throws DeviceManagementException if any service level or DAO level error occurs.
*/
PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue,
List<Integer> devicesIds, List<String> status) throws DeviceManagementException;
PaginationResult getAppSubscribedDevices(PaginationRequest request, List<Integer> devicesIds, List<String> status)
throws DeviceManagementException;
/**
* This method is used to get a list of applications installed in all enrolled devices

@ -4156,9 +4156,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue, List<Integer> devicesIds,
public PaginationResult getAppSubscribedDevices(PaginationRequest request, List<Integer> devicesIds,
List<String> status) throws DeviceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (log.isDebugEnabled()) {
log.debug("Getting all devices details for device ids: " + devicesIds);
@ -4167,8 +4166,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
List<Device> subscribedDeviceDetails;
try {
DeviceManagementDAOFactory.openConnection();
subscribedDeviceDetails = deviceDAO
.getSubscribedDevices(offsetValue, limitValue, devicesIds, tenantId, status);
subscribedDeviceDetails = deviceDAO.getSubscribedDevices(request, devicesIds, tenantId, status);
if (subscribedDeviceDetails.isEmpty()) {
paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0);

Loading…
Cancel
Save