Fix device type filtering issue

pull/466/head
Rajitha Kumara 4 months ago
parent 4fae9cf2e3
commit 57199a5d89

@ -40,25 +40,27 @@ import java.util.stream.Collectors;
public class SubscriptionManagementHelperUtil {
public static List<DeviceSubscription> getDeviceSubscriptionData(List<DeviceSubscriptionDTO> deviceSubscriptionDTOS,
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria,
boolean isUnsubscribed, int limit, int offset)
boolean isUnsubscribed, int deviceTypeId, int limit, int offset)
throws DeviceManagementException {
List<Integer> deviceIds = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
PaginationRequest paginationRequest = new PaginationRequest(offset, limit);
paginationRequest.setDeviceName(deviceSubscriptionFilterCriteria.getName());
paginationRequest.setDeviceStatus(deviceSubscriptionFilterCriteria.getDeviceStatus());
paginationRequest.setOwner(deviceSubscriptionFilterCriteria.getOwner());
paginationRequest.setDeviceTypeId(deviceTypeId);
List<Device> devices = HelperUtil.getDeviceManagementProviderService().getDevicesByDeviceIds(paginationRequest, deviceIds);
return populateDeviceData(deviceSubscriptionDTOS, devices, isUnsubscribed);
}
public static int getTotalDeviceSubscriptionCount(List<DeviceSubscriptionDTO> deviceSubscriptionDTOS,
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria)
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria, int deviceTypeId)
throws DeviceManagementException {
List<Integer> deviceIds = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
paginationRequest.setDeviceName(deviceSubscriptionFilterCriteria.getName());
paginationRequest.setDeviceStatus(deviceSubscriptionFilterCriteria.getDeviceStatus());
paginationRequest.setOwner(deviceSubscriptionFilterCriteria.getOwner());
paginationRequest.setDeviceTypeId(deviceTypeId);
return HelperUtil.getDeviceManagementProviderService().getDeviceCountByDeviceIds(paginationRequest, deviceIds);
}

@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
@ -76,6 +77,13 @@ public class DeviceBasedSubscriptionManagementHelperServiceImpl implements Subsc
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
if (applicationDTO == null) {
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
log.error(msg);
throw new NotFoundException(msg);
}
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
@ -101,10 +109,10 @@ public class DeviceBasedSubscriptionManagementHelperServiceImpl implements Subsc
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria());
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
}
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, limit, offset);
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
} catch (DeviceManagementException e) {
String msg = "Error encountered while getting device details";

@ -131,10 +131,10 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria());
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
}
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, limit, offset);
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
} catch (GroupManagementException e) {
String msg = "Error encountered while retrieving group details for group: " + subscriptionInfo.getIdentifier();

@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
@ -86,6 +87,13 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
if (applicationDTO == null) {
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
log.error(msg);
throw new NotFoundException(msg);
}
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
@ -113,11 +121,11 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), limit, offset);
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria());
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
}
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.
getDeviceSubscriptionData(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, limit, offset);
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
} catch (UserStoreException e) {

@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
@ -83,6 +84,13 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
if (applicationDTO == null) {
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
log.error(msg);
throw new NotFoundException(msg);
}
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
@ -110,11 +118,10 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria());
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
}
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, limit, offset);
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
} catch (DeviceManagementException e) {
String msg = "Error encountered while getting device details";

@ -54,6 +54,7 @@ public class PaginationRequest {
private List<String> statusList = new ArrayList<>();
private OperationLogFilters operationLogFilters = new OperationLogFilters();
private List<SortColumn> sortColumn = new ArrayList<>();
private int deviceTypeId;
public OperationLogFilters getOperationLogFilters() {
return operationLogFilters;
}
@ -292,4 +293,12 @@ public class PaginationRequest {
public void setTabActionStatus(String tabActionStatus) {
this.tabActionStatus = tabActionStatus;
}
public int getDeviceTypeId() {
return deviceTypeId;
}
public void setDeviceTypeId(int deviceTypeId) {
this.deviceTypeId = deviceTypeId;
}
}

@ -3424,7 +3424,10 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
Connection connection = getConnection();
String sql = "SELECT e.DEVICE_ID, d.DEVICE_IDENTIFICATION, e.STATUS, e.OWNER, d.NAME AS DEVICE_NAME, " +
"e.DEVICE_TYPE, e.OWNERSHIP, e.DATE_OF_LAST_UPDATE FROM DM_DEVICE d INNER JOIN DM_ENROLMENT e " +
"WHERE d.ID = e.DEVICE_ID AND d.TENANT_ID = ? AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " +
"ON d.ID = e.DEVICE_ID " +
"WHERE d.DEVICE_TYPE_ID = ? " +
"AND d.TENANT_ID = ? " +
"AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " +
"AND e.STATUS NOT IN ('DELETED', 'REMOVED')";
if (paginationRequest.getOwner() != null) {
@ -3446,6 +3449,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
int parameterIdx = 1;
preparedStatement.setInt(parameterIdx++, paginationRequest.getDeviceTypeId());
preparedStatement.setInt(parameterIdx++, tenantId);
for (Integer deviceId : deviceIds) {
@ -3501,8 +3505,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
boolean isDeviceNameProvided = false;
try {
Connection connection = getConnection();
String sql = "SELECT COUNT(DISTINCT e.DEVICE_ID) FROM DM_ENROLMENT e " +
"WHERE e.TENANT_ID = ? AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " +
String sql = "SELECT COUNT(DISTINCT e.DEVICE_ID) FROM DM_DEVICE d INNER JOIN DM_ENROLMENT e " +
"ON d.ID = e.DEVICE_ID " +
"WHERE e.TENANT_ID = ? " +
"AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " +
"AND d.DEVICE_TYPE_ID = ? " +
"AND e.STATUS NOT IN ('DELETED', 'REMOVED')";
if (paginationRequest.getOwner() != null) {
@ -3528,6 +3535,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
preparedStatement.setInt(parameterIdx++, deviceId);
}
preparedStatement.setInt(parameterIdx++, paginationRequest.getDeviceTypeId());
if (isOwnerProvided)
preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getOwner() + "%");
if (isDeviceStatusProvided)

Loading…
Cancel
Save