From c480512f10c88a9b9b35b4fbd909773a2a26e605 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Tue, 23 Jul 2024 17:48:25 +0530 Subject: [PATCH] Fix issues related to new devices and stats --- .../mgt/core/dao/SubscriptionDAO.java | 4 +- .../GenericSubscriptionDAOImpl.java | 24 ++--- .../core/util/SubscriptionManagementUtil.java | 29 ------ ...bscriptionManagementHelperServiceImpl.java | 12 +-- ...bscriptionManagementHelperServiceImpl.java | 23 +++-- ...bscriptionManagementHelperServiceImpl.java | 22 +++-- ...bscriptionManagementHelperServiceImpl.java | 22 +++-- .../core/device/mgt/core/dao/DeviceDAO.java | 4 +- .../core/dao/impl/AbstractDeviceDAOImpl.java | 63 +++++++----- .../dao/impl/device/GenericDeviceDAOImpl.java | 95 ++++--------------- .../dao/impl/device/OracleDeviceDAOImpl.java | 88 ++--------------- .../DeviceManagementProviderService.java | 7 +- .../DeviceManagementProviderServiceImpl.java | 20 +--- 13 files changed, 127 insertions(+), 286 deletions(-) delete mode 100644 components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/SubscriptionManagementUtil.java diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java index cadab204ca..c35c4a5251 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java @@ -527,8 +527,8 @@ public interface SubscriptionDAO { */ int getUserUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException; - SubscriptionStatisticDTO getSubscriptionStatistic(List deviceIds, String subscriptionType, boolean isUnsubscribed, - int tenantId) throws ApplicationManagementDAOException; + SubscriptionStatisticDTO getSubscriptionStatistic(List deviceIds, boolean isUnsubscribed, + int tenantId, int appReleaseId) throws ApplicationManagementDAOException; /** * This method is used to get the counts of devices related to a UUID. * diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index a793638d2d..c459acd7ad 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -18,11 +18,9 @@ package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription; import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata; -import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO; import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity; import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO; -import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO; import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO; import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; @@ -2792,43 +2790,33 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } - // todo: fixed the status @Override - public SubscriptionStatisticDTO getSubscriptionStatistic(List deviceIds, String subscriptionType, - boolean isUnsubscribed, int tenantId) + public SubscriptionStatisticDTO getSubscriptionStatistic(List deviceIds, boolean isUnsubscribed, int tenantId, int appReleaseId) throws ApplicationManagementDAOException { SubscriptionStatisticDTO subscriptionStatisticDTO = new SubscriptionStatisticDTO(); if (deviceIds == null || deviceIds.isEmpty()) return subscriptionStatisticDTO; - boolean doesAllEntriesRequired = true; try { Connection connection = getDBConnection(); String sql = "SELECT COUNT(DISTINCT ID) AS COUNT, " + "STATUS FROM AP_DEVICE_SUBSCRIPTION " + "WHERE TENANT_ID = ? " + - "AND UNSUBSCRIBED = ?" + + "AND AP_APP_RELEASE_ID = ? " + + "AND UNSUBSCRIBED = ? " + "AND DM_DEVICE_ID IN (" + - deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")"; - - if (!Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.DEVICE)) { - sql += " AND ACTION_TRIGGERED_FROM = ?"; - doesAllEntriesRequired = false; - } - - sql += " GROUP BY (STATUS)"; + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") " + + "GROUP BY (STATUS)"; try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { int idx = 1; preparedStatement.setInt(idx++, tenantId); + preparedStatement.setInt(idx++, appReleaseId); preparedStatement.setBoolean(idx++, isUnsubscribed); for (Integer deviceId : deviceIds) { preparedStatement.setInt(idx++, deviceId); } - if (!doesAllEntriesRequired) { - preparedStatement.setString(idx, subscriptionType); - } try (ResultSet resultSet = preparedStatement.executeQuery()) { while (resultSet.next()) { // add the error and in progress diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/SubscriptionManagementUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/SubscriptionManagementUtil.java deleted file mode 100644 index 9c45f57be4..0000000000 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/SubscriptionManagementUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package io.entgra.device.mgt.core.application.mgt.core.util; - -public class SubscriptionManagementUtil { - public static final class DeviceSubscriptionStatus { - public static final String COMPLETED = "COMPLETED"; - public static final String ERROR ="ERROR"; - public static final String NEW = "NEW"; - public static final String SUBSCRIBED = "SUBSCRIBED"; - } -} diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java index b0fc7c97bd..e3c7396bb5 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java @@ -36,7 +36,6 @@ import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil; import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil; import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService; -import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService; import org.apache.commons.logging.Log; @@ -97,20 +96,17 @@ public class DeviceBasedSubscriptionManagementHelperServiceImpl implements Subsc List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream(). map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList()); - List newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription, - new PaginationRequest(offset, limit)); + List newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription); deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); - - deviceCount = deviceManagementProviderService.getDeviceCountNotInGivenIdList(deviceIdsOfSubscription); } else { deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO. getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); - - deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, - subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); } + deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, + subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); + List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS, subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset); return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions); diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java index 1a78df119c..9f7f9db78f 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java @@ -39,7 +39,6 @@ import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil; import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil; import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService; import io.entgra.device.mgt.core.device.mgt.common.Device; -import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO; @@ -115,11 +114,8 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr allDeviceIdsOwnByGroup.remove(deviceId); } - List paginatedNewDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(allDeviceIdsOwnByGroup, - new PaginationRequest(offset, limit)); - deviceSubscriptionDTOS = paginatedNewDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); - - deviceCount = allDeviceIdsOwnByGroup.size(); + List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(allDeviceIdsOwnByGroup); + deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); } else { groupDetailsDTO = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(), applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(), @@ -130,9 +126,10 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr isUnsubscribe, tenantId, paginatedDeviceIdsOwnByGroup, dbSubscriptionStatus, null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); - deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, - subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); } + deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, + subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); + List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS, subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset); return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions); @@ -188,11 +185,19 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { ConnectionManagerUtil.openDBConnection(); + ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. + getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't find an application release for application release UUID: " + + subscriptionInfo.getApplicationUUID(); + log.error(msg); + throw new NotFoundException(msg); + } List devices = HelperUtil.getGroupManagementProviderService(). getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false); List deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList()); SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. - getSubscriptionStatistic(deviceIdsOwnByGroup, null, isUnsubscribe, tenantId); + getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier()); return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); } catch (ApplicationManagementDAOException e) { diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java index b3498db662..93e6ebc46a 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java @@ -111,18 +111,16 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri deviceIdsOwnByRole.remove(deviceId); } - List paginatedNewDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRole, - new PaginationRequest(offset, limit)); - deviceSubscriptionDTOS = paginatedNewDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); - deviceCount = deviceIdsOwnByRole.size(); + List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRole); + deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); } else { deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, deviceIdsOwnByRole, dbSubscriptionStatus, subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); - - deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, - subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); } + deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, + subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); + List deviceSubscriptions = SubscriptionManagementHelperUtil. getDeviceSubscriptionData(deviceSubscriptionDTOS, subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset); @@ -180,9 +178,17 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { ConnectionManagerUtil.openDBConnection(); + ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. + getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't find an application release for application release UUID: " + + subscriptionInfo.getApplicationUUID(); + log.error(msg); + throw new NotFoundException(msg); + } List deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId); SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. - getSubscriptionStatistic(deviceIdsOwnByRole, null, isUnsubscribe, tenantId); + getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); int allDeviceCount = deviceIdsOwnByRole.size(); return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); } catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) { diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java index 83bc8c08e2..a12560146d 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java @@ -107,19 +107,17 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri for (Integer deviceId : deviceIdsOfSubscription) { deviceIdsOwnByUser.remove(deviceId); } - List paginatedNewDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByUser, - new PaginationRequest(offset, limit)); - deviceSubscriptionDTOS = paginatedNewDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); + List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByUser); + deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList()); - deviceCount = deviceIdsOwnByUser.size(); } else { deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, deviceIdsOwnByUser, dbSubscriptionStatus, null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1); - - deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, - subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); } + deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS, + subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId()); + List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS, subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset); return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions); @@ -171,9 +169,17 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { ConnectionManagerUtil.openDBConnection(); + ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. + getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't find an application release for application release UUID: " + + subscriptionInfo.getApplicationUUID(); + log.error(msg); + throw new NotFoundException(msg); + } List deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. - getSubscriptionStatistic(deviceIdsOwnByUser, null, isUnsubscribe, tenantId); + getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); int allDeviceCount = deviceIdsOwnByUser.size(); return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); } catch (DeviceManagementException | ApplicationManagementDAOException e) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java index 3d646768fb..606a1eab5c 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java @@ -865,10 +865,10 @@ public interface DeviceDAO { */ int getCountOfDevicesNotInGroup(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; - List getDevicesNotInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) + List getDevicesNotInGivenIdList(List deviceIds, int tenantId) throws DeviceManagementDAOException; - List getDevicesInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) + List getDevicesInGivenIdList(List deviceIds, int tenantId) throws DeviceManagementDAOException; int getDeviceCountNotInGivenIdList(List deviceIds, int tenantId) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index b195acfc1f..eafa2e0d02 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -3301,7 +3301,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } @Override - public List getDevicesNotInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) + public List getDevicesNotInGivenIdList(List deviceIds, int tenantId) throws DeviceManagementDAOException { List filteredDeviceIds = new ArrayList<>(); try { @@ -3312,8 +3312,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { sql += " AND ID NOT IN ( " + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")"; } - sql += " LIMIT ? OFFSET ?"; - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { int paraIdx = 1; preparedStatement.setInt(paraIdx++, tenantId); @@ -3324,8 +3322,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - preparedStatement.setInt(paraIdx++, request.getRowCount()); - preparedStatement.setInt(paraIdx, request.getStartIndex()); try (ResultSet resultSet = preparedStatement.executeQuery()) { while (resultSet.next()) { filteredDeviceIds.add(resultSet.getInt("DEVICE_ID")); @@ -3341,7 +3337,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } @Override - public List getDevicesInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) + public List getDevicesInGivenIdList(List deviceIds, int tenantId) throws DeviceManagementDAOException { List filteredDeviceIds = new ArrayList<>(); if (deviceIds == null || deviceIds.isEmpty()) return filteredDeviceIds; @@ -3351,19 +3347,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { Connection connection = getConnection(); String sql = "SELECT ID AS DEVICE_ID " + "FROM DM_DEVICE " + - "WHERE ID IN (" + deviceIdStringList + ")" + - " AND TENANT_ID = ? " + - "LIMIT ? " + - "OFFSET ?"; + "WHERE ID IN (" + deviceIdStringList + ") " + + "AND TENANT_ID = ? "; try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { int paraIdx = 1; for (Integer deviceId : deviceIds) { preparedStatement.setInt(paraIdx++, deviceId); } - preparedStatement.setInt(paraIdx++, tenantId); - preparedStatement.setInt(paraIdx++, request.getRowCount()); - preparedStatement.setInt(paraIdx, request.getStartIndex()); + preparedStatement.setInt(paraIdx, tenantId); try (ResultSet resultSet = preparedStatement.executeQuery()) { while (resultSet.next()) { filteredDeviceIds.add(resultSet.getInt("DEVICE_ID")); @@ -3426,6 +3418,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { boolean isOwnerProvided = false; boolean isDeviceStatusProvided = false; boolean isDeviceNameProvided = false; + boolean isDeviceTypeIdProvided = false; + try { Connection connection = getConnection(); String sql = "SELECT e.DEVICE_ID, " + @@ -3439,8 +3433,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "FROM DM_DEVICE d " + "INNER JOIN DM_ENROLMENT e " + "ON d.ID = e.DEVICE_ID " + - "WHERE d.DEVICE_TYPE_ID = ? " + - "AND d.TENANT_ID = ? " + + "WHERE d.TENANT_ID = ? " + "AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " + "AND e.STATUS NOT IN ('DELETED', 'REMOVED')"; @@ -3459,6 +3452,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { isDeviceNameProvided = true; } + if (paginationRequest.getDeviceTypeId() > 0) { + sql = sql + " AND d.DEVICE_TYPE_ID = ?"; + isDeviceTypeIdProvided = true; + } + sql = sql + " LIMIT ? OFFSET ?"; try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { @@ -3470,12 +3468,18 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { preparedStatement.setInt(parameterIdx++, deviceId); } - if (isOwnerProvided) + if (isOwnerProvided) { preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getOwner() + "%"); - if (isDeviceStatusProvided) + } + if (isDeviceStatusProvided) { preparedStatement.setString(parameterIdx++, paginationRequest.getDeviceStatus()); - if (isDeviceNameProvided) + } + if (isDeviceNameProvided) { preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getDeviceName() + "%"); + } + if (isDeviceTypeIdProvided) { + preparedStatement.setInt(parameterIdx++, paginationRequest.getDeviceTypeId()); + } preparedStatement.setInt(parameterIdx++, paginationRequest.getRowCount()); preparedStatement.setInt(parameterIdx, paginationRequest.getStartIndex()); @@ -3506,7 +3510,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - // todo: fix the join query @Override public int getDeviceCountByDeviceIds(PaginationRequest paginationRequest, List deviceIds, int tenantId) throws DeviceManagementDAOException { @@ -3517,6 +3520,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { boolean isOwnerProvided = false; boolean isDeviceStatusProvided = false; boolean isDeviceNameProvided = false; + boolean isDeviceTypeIdProvided = false; try { Connection connection = getConnection(); String sql = "SELECT COUNT(DISTINCT e.DEVICE_ID) AS COUNT " + @@ -3525,7 +3529,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "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) { @@ -3543,6 +3546,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { isDeviceNameProvided = true; } + if (paginationRequest.getDeviceTypeId() > 0) { + sql = sql + " AND d.DEVICE_TYPE_ID = ?"; + isDeviceTypeIdProvided = true; + } + try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { int parameterIdx = 1; preparedStatement.setInt(parameterIdx++, tenantId); @@ -3551,13 +3559,18 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { preparedStatement.setInt(parameterIdx++, deviceId); } - preparedStatement.setInt(parameterIdx++, paginationRequest.getDeviceTypeId()); - if (isOwnerProvided) + if (isOwnerProvided) { preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getOwner() + "%"); - if (isDeviceStatusProvided) + } + if (isDeviceStatusProvided) { preparedStatement.setString(parameterIdx++, paginationRequest.getDeviceStatus()); - if (isDeviceNameProvided) - preparedStatement.setString(parameterIdx, "%" + paginationRequest.getDeviceName() + "%"); + } + if (isDeviceNameProvided) { + preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getDeviceName() + "%"); + } + if (isDeviceTypeIdProvided) { + preparedStatement.setInt(parameterIdx, paginationRequest.getDeviceTypeId()); + } try(ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index e116df7490..6467f912ff 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -1869,6 +1869,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isOwnerProvided = false; boolean isDeviceStatusProvided = false; boolean isDeviceNameProvided = false; + boolean isDeviceTypeIdProvided = false; try { Connection connection = getConnection(); String sql = "SELECT e.DEVICE_ID, " + @@ -1881,8 +1882,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "e.DATE_OF_LAST_UPDATE " + "FROM DM_DEVICE d " + "INNER JOIN DM_ENROLMENT e " + - "WHERE d.ID = e.DEVICE_ID " + - "AND d.TENANT_ID = ? " + + "WHERE d.TENANT_ID = ? " + "AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " + "AND e.STATUS NOT IN ('DELETED', 'REMOVED')"; if (paginationRequest.getOwner() != null) { @@ -1897,6 +1897,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { sql = sql + " AND d.NAME LIKE ?"; isDeviceNameProvided = true; } + if (paginationRequest.getDeviceTypeId() > 0) { + sql = sql + " AND d.DEVICE_TYPE_ID = ?"; + isDeviceTypeIdProvided = true; + } sql = sql + " LIMIT ? OFFSET ?"; try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { int parameterIdx = 1; @@ -1904,12 +1908,19 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { for (Integer deviceId : deviceIds) { preparedStatement.setInt(parameterIdx++, deviceId); } - if (isOwnerProvided) + if (isOwnerProvided) { preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getOwner() + "%"); - if (isDeviceStatusProvided) + } + if (isDeviceStatusProvided) { preparedStatement.setString(parameterIdx++, paginationRequest.getDeviceStatus()); - if (isDeviceNameProvided) + } + if (isDeviceNameProvided) { preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getDeviceName() + "%"); + } + if (isDeviceTypeIdProvided) { + preparedStatement.setInt(parameterIdx++, paginationRequest.getDeviceTypeId()); + } + preparedStatement.setInt(parameterIdx++, paginationRequest.getRowCount()); preparedStatement.setInt(parameterIdx, paginationRequest.getStartIndex()); try(ResultSet resultSet = preparedStatement.executeQuery()) { @@ -1937,78 +1948,4 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { throw new DeviceManagementDAOException(msg, e); } } - - @Override - public List getDevicesInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) - throws DeviceManagementDAOException { - List filteredDeviceIds = new ArrayList<>(); - if (deviceIds == null || deviceIds.isEmpty()) return filteredDeviceIds; - String deviceIdStringList = deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")); - try { - Connection connection = getConnection(); - String sql = "SELECT ID AS DEVICE_ID " + - "FROM DM_DEVICE WHERE ID IN " + - "(" + deviceIdStringList + ") " + - "AND TENANT_ID = ? " + - "LIMIT ? " + - "OFFSET ?"; - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { - int paraIdx = 1; - for (Integer deviceId : deviceIds) { - preparedStatement.setInt(paraIdx++, deviceId); - } - preparedStatement.setInt(paraIdx++, tenantId); - preparedStatement.setInt(paraIdx++, request.getRowCount()); - preparedStatement.setInt(paraIdx, request.getStartIndex()); - try (ResultSet resultSet = preparedStatement.executeQuery()) { - while (resultSet.next()) { - filteredDeviceIds.add(resultSet.getInt("DEVICE_ID")); - } - } - return filteredDeviceIds; - } - } catch (SQLException e) { - String msg = "Error occurred while retrieving device ids in: " + filteredDeviceIds; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } - } - - @Override - public List getDevicesNotInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) - throws DeviceManagementDAOException { - List filteredDeviceIds = new ArrayList<>(); - try { - Connection connection = getConnection(); - String sql = "SELECT ID AS DEVICE_ID " + - "FROM DM_DEVICE" + - " WHERE TENANT_ID = ?"; - - if (deviceIds != null && !deviceIds.isEmpty()) { - sql += " AND ID NOT IN ( " + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")"; - } - sql += " LIMIT ? OFFSET ?"; - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { - int paraIdx = 1; - preparedStatement.setInt(paraIdx++, tenantId); - if (deviceIds != null && !deviceIds.isEmpty()) { - for (Integer deviceId : deviceIds) { - preparedStatement.setInt(paraIdx++, deviceId); - } - } - preparedStatement.setInt(paraIdx++, request.getRowCount()); - preparedStatement.setInt(paraIdx, request.getStartIndex()); - try (ResultSet resultSet = preparedStatement.executeQuery()) { - while (resultSet.next()) { - filteredDeviceIds.add(resultSet.getInt("DEVICE_ID")); - } - } - return filteredDeviceIds; - } - } catch (SQLException e) { - String msg = "Error occurred while retrieving device ids not in: " + filteredDeviceIds; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } - } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index d1649f8528..e9143faae3 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -82,6 +82,7 @@ public class OracleDeviceDAOImpl extends SQLServerDeviceDAOImpl { boolean isOwnerProvided = false; boolean isDeviceStatusProvided = false; boolean isDeviceNameProvided = false; + boolean isDeviceTypeIdProvided = false; try { Connection connection = getConnection(); String sql = "SELECT e.DEVICE_ID, " + @@ -110,6 +111,11 @@ public class OracleDeviceDAOImpl extends SQLServerDeviceDAOImpl { sql += " AND d.NAME LIKE ?"; isDeviceNameProvided = true; } + if (paginationRequest.getDeviceTypeId() > 0) { + sql += " AND d.DEVICE_TYPE_ID = ?"; + isDeviceTypeIdProvided = true; + } + sql += " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { int parameterIdx = 1; @@ -126,6 +132,10 @@ public class OracleDeviceDAOImpl extends SQLServerDeviceDAOImpl { if (isDeviceNameProvided) { preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getDeviceName() + "%"); } + if (isDeviceTypeIdProvided) { + preparedStatement.setInt(parameterIdx++, paginationRequest.getDeviceTypeId()); + } + preparedStatement.setInt(parameterIdx++, paginationRequest.getStartIndex()); preparedStatement.setInt(parameterIdx, paginationRequest.getRowCount()); try (ResultSet resultSet = preparedStatement.executeQuery()) { @@ -152,82 +162,4 @@ public class OracleDeviceDAOImpl extends SQLServerDeviceDAOImpl { throw new DeviceManagementDAOException(msg, e); } } - - @Override - public List getDevicesInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) - throws DeviceManagementDAOException { - List filteredDeviceIds = new ArrayList<>(); - if (deviceIds == null || deviceIds.isEmpty()) return filteredDeviceIds; - - String deviceIdStringList = deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")); - try { - Connection connection = getConnection(); - String sql = "SELECT ID AS DEVICE_ID " + - "FROM DM_DEVICE WHERE ID IN " + - "(" + deviceIdStringList + ") " + - "AND TENANT_ID = ? " + - "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { - int paraIdx = 1; - for (Integer deviceId : deviceIds) { - preparedStatement.setInt(paraIdx++, deviceId); - } - preparedStatement.setInt(paraIdx++, tenantId); - preparedStatement.setInt(paraIdx++, request.getStartIndex()); - preparedStatement.setInt(paraIdx, request.getRowCount()); - - try (ResultSet resultSet = preparedStatement.executeQuery()) { - while (resultSet.next()) { - filteredDeviceIds.add(resultSet.getInt("DEVICE_ID")); - } - } - return filteredDeviceIds; - } - } catch (SQLException e) { - String msg = "Error occurred while retrieving device ids in: " + deviceIds; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } - } - - @Override - public List getDevicesNotInGivenIdList(PaginationRequest request, List deviceIds, int tenantId) - throws DeviceManagementDAOException { - List filteredDeviceIds = new ArrayList<>(); - try { - Connection connection = getConnection(); - String sql = "SELECT ID AS DEVICE_ID " + - "FROM DM_DEVICE " + - "WHERE TENANT_ID = ?"; - - if (deviceIds != null && !deviceIds.isEmpty()) { - sql += " AND ID NOT IN (" + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")"; - } - - sql += "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; - - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { - int paraIdx = 1; - preparedStatement.setInt(paraIdx++, tenantId); - if (deviceIds != null && !deviceIds.isEmpty()) { - for (Integer deviceId : deviceIds) { - preparedStatement.setInt(paraIdx++, deviceId); - } - } - preparedStatement.setInt(paraIdx++, request.getStartIndex()); - preparedStatement.setInt(paraIdx, request.getRowCount()); - - try (ResultSet resultSet = preparedStatement.executeQuery()) { - while (resultSet.next()) { - filteredDeviceIds.add(resultSet.getInt("DEVICE_ID")); - } - } - return filteredDeviceIds; - } - } catch (SQLException e) { - String msg = "Error occurred while retrieving device ids not in: " + deviceIds; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } - } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java index f95bbd3294..56f95d3f44 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java @@ -58,7 +58,6 @@ import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoCluster; import java.sql.SQLException; import java.sql.Timestamp; -import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; @@ -1153,15 +1152,15 @@ public interface DeviceManagementProviderService { Device updateDeviceName(Device device, String deviceType, String deviceId) throws DeviceManagementException, DeviceNotFoundException, ConflictException; - List getDevicesNotInGivenIdList(List deviceIds, PaginationRequest paginationRequest) + List getDevicesNotInGivenIdList(List deviceIds) throws DeviceManagementException; - List getDevicesInGivenIdList(List deviceIds, PaginationRequest paginationRequest) + List getDevicesInGivenIdList(List deviceIds) throws DeviceManagementException; int getDeviceCountNotInGivenIdList(List deviceIds) throws DeviceManagementException; List getDevicesByDeviceIds(PaginationRequest paginationRequest, List deviceIds) throws DeviceManagementException; - public int getDeviceCountByDeviceIds(PaginationRequest paginationRequest, List deviceIds) + int getDeviceCountByDeviceIds(PaginationRequest paginationRequest, List deviceIds) throws DeviceManagementException; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 3fdeb263ea..341714dd10 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -161,7 +161,6 @@ import javax.xml.bind.Marshaller; import java.io.IOException; import java.io.StringWriter; import java.lang.reflect.Type; -import java.sql.Array; import java.sql.SQLException; import java.sql.Timestamp; import java.time.LocalDateTime; @@ -5594,18 +5593,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public List getDevicesNotInGivenIdList(List deviceIds, PaginationRequest paginationRequest) + public List getDevicesNotInGivenIdList(List deviceIds) throws DeviceManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - if (paginationRequest == null) { - String msg = "Received null for pagination request"; - log.error(msg); - throw new DeviceManagementException(msg); - } try { DeviceManagementDAOFactory.openConnection(); - return deviceDAO.getDevicesNotInGivenIdList(paginationRequest, deviceIds, tenantId); + return deviceDAO.getDevicesNotInGivenIdList(deviceIds, tenantId); } catch (DeviceManagementDAOException e) { String msg = "Error encountered while getting device ids"; log.error(msg, e); @@ -5620,19 +5614,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public List getDevicesInGivenIdList(List deviceIds, PaginationRequest paginationRequest) + public List getDevicesInGivenIdList(List deviceIds) throws DeviceManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - if (paginationRequest == null) { - String msg = "Received null for pagination request"; - log.error(msg); - throw new DeviceManagementException(msg); - } - try { DeviceManagementDAOFactory.openConnection(); - return deviceDAO.getDevicesInGivenIdList(paginationRequest, deviceIds, tenantId); + return deviceDAO.getDevicesInGivenIdList(deviceIds, tenantId); } catch (DeviceManagementDAOException e) { String msg = "Error encountered while getting device ids"; log.error(msg, e);