Refactored the code in subscription management.

-This commit addresses an improvement to code redundancy and repetition.

Testing:
- Verified successful installation on multiple environments.
subscription
Ruwin Dissanayake 3 months ago
parent 0ee4412770
commit 32ff2cfe93

@ -252,7 +252,6 @@ public interface SubscriptionManager {
SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
throws ApplicationManagementException;
/**
* Get subscription statistics related data describes by the {@link SubscriptionInfo}
* @param subscriptionInfo {@link SubscriptionInfo}

@ -19,13 +19,42 @@
package io.entgra.device.mgt.core.application.mgt.core.impl;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.*;
import io.entgra.device.mgt.core.application.mgt.common.dto.*;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.SubAction;
import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
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.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.util.SubscriptionManagementHelperUtil;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
@ -70,7 +99,6 @@ import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.OAuthUtils;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.MobileAppTypes;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.android.CustomApplication;
@ -103,7 +131,16 @@ import java.net.URL;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@ -165,7 +202,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
// Only for iOS devices
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// Ignore checking device type if app is a web clip
if(!applicationDTO.getType().equals("WEB_CLIP")){
if (!applicationDTO.getType().equals("WEB_CLIP")) {
if (DeviceTypes.IOS.toString().equalsIgnoreCase(APIUtil.getDeviceTypeData(applicationDTO
.getDeviceTypeId()).getName())) {
// TODO: replace getAssetByAppId with the correct one in DAO
@ -542,7 +579,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username,
allowingDeviceStatuses, false ));
allowingDeviceStatuses, false));
}
} else {
if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
@ -1217,6 +1254,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/**
* Get the bundle id of the iOS public application.
*
* @param appId Application Id
* @return {@link String} bundle Id
* @throws ApplicationManagementException if error occurred while getting the bundle if of the requesting public
@ -1309,7 +1347,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
public int installEnrollmentApplications(ApplicationPolicyDTO applicationPolicyDTO)
throws ApplicationManagementException {
String requestUrl =null;
String requestUrl = null;
try {
requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + System
.getProperty(Constants.ApplicationInstall.IOT_GATEWAY_HOST) + Constants.ApplicationInstall.COLON
@ -1320,7 +1358,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
HttpPost httpPost = new HttpPost(requestUrl);
StringEntity stringEntity = new StringEntity(payload, Constants.ApplicationInstall.ENCODING);
httpPost.addHeader("Content-Type",MediaType.APPLICATION_JSON);
httpPost.addHeader("Content-Type", MediaType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
return invokeIOTCoreAPI(httpPost);
} catch (UserStoreException e) {
@ -1674,17 +1712,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/**
* Get subscription data describes by {@link SubscriptionInfo} entity
*
* @param subscriptionInfo {@link SubscriptionInfo}
* @param limit Limit value
* @param offset Offset value
* @return {@link SubscriptionResponse}
* @throws ApplicationManagementException Throws when error encountered while getting subscription data
*/
@Override
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
throws ApplicationManagementException {
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED,
subscriptionInfo.getSubscriptionStatus());
final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
ConnectionManagerUtil.openDBConnection();
@ -1702,13 +1741,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
} if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.ROLE)){
}
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.ROLE)) {
List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
getRoleSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getRoleUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
subscriptionDAO.getRoleSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
} if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.USER)){
}
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.USER)) {
List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
getUserSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getUserUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
@ -1728,17 +1769,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/**
* Retrieves subscription statistics described by the {@link SubscriptionInfo} entity.
*
* @param subscriptionInfo The {@link SubscriptionInfo} containing details about the subscription type and identifier.
* @return {@link SubscriptionStatistics} The subscription statistics for the specified subscription type and identifier.
* @throws ApplicationManagementException Throws when an error is encountered while getting subscription statistics.
*/
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
throws ApplicationManagementException {
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.DEVICE)){
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.DEVICE)) {
return null;
}
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED,
subscriptionInfo.getSubscriptionStatus());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
ConnectionManagerUtil.openDBConnection();
@ -1751,25 +1793,27 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new NotFoundException(msg);
}
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.GROUP)) {
List<Device> devices = HelperUtil.getGroupManagementProviderService().
getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false);
List<Integer> deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList());
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier());
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
} if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.ROLE)){
List<Integer> deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
int allDeviceCount = deviceIdsOwnByRole.size();
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
} if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.USER)){
List<Integer> deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
int allDeviceCount = deviceIdsOwnByUser.size();
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(
subscriptionDAO.getSubscriptionStatistic(
HelperUtil.getGroupManagementProviderService()
.getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false)
.stream().map(Device::getId).collect(Collectors.toList()),
isUnsubscribe, tenantId, applicationReleaseDTO.getId()),
HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier())
);
}
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.ROLE)) {
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionDAO.getSubscriptionStatistic(
getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId), isUnsubscribe, tenantId,
applicationReleaseDTO.getId()
), getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId).size());
}
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.USER)) {
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(
subscriptionDAO.getSubscriptionStatistic(getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()),
isUnsubscribe, tenantId, applicationReleaseDTO.getId()),
getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()).size()
);
} else {
return null;
}
@ -1796,13 +1840,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/**
* Get status based subscription data describes by {@link SubscriptionInfo} entity
*
* @param subscriptionInfo {@link SubscriptionInfo}
* @param limit Limit value
* @param offset Offset value
* @return {@link SubscriptionResponse}
* @throws ApplicationManagementException Throws when error encountered while getting subscription data
*/
@Override
public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
throws ApplicationManagementException {
if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.DEVICE)) {
@ -1810,14 +1855,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} else if (Objects.equals(subscriptionInfo.getSubscriptionType(), SubscriptionMetadata.SubscriptionTypes.GROUP)) {
return getStatusBaseSubscriptionsGroup(subscriptionInfo, limit, offset);
} else {
return getStatusBaseSubscriptionsRoleUser(subscriptionInfo, limit, offset);
return getStatusBaseSubscriptionsRoleAndUser(subscriptionInfo, limit, offset);
}
}
public SubscriptionResponse getStatusBaseSubscriptionsDevice(SubscriptionInfo subscriptionInfo, int limit, int offset)
private SubscriptionResponse getStatusBaseSubscriptionsDevice(SubscriptionInfo subscriptionInfo, int limit, int offset)
throws ApplicationManagementException {
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED,
subscriptionInfo.getSubscriptionStatus());
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
int deviceCount = 0;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -1843,7 +1888,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus
(subscriptionInfo.getDeviceSubscriptionStatus());
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
@ -1862,7 +1908,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
}
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
@ -1879,10 +1924,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
public SubscriptionResponse getStatusBaseSubscriptionsGroup(SubscriptionInfo subscriptionInfo, int limit, int offset)
private SubscriptionResponse getStatusBaseSubscriptionsGroup(SubscriptionInfo subscriptionInfo, int limit, int offset)
throws ApplicationManagementException {
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED,
subscriptionInfo.getSubscriptionStatus());
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
int deviceCount = 0;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -1912,11 +1958,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
GroupDetailsDTO groupDetailsDTO;
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus
(subscriptionInfo.getDeviceSubscriptionStatus());
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
List<Integer> allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
List<Integer> allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices
(subscriptionInfo.getIdentifier(),
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(),
deviceSubscriptionFilterCriteria.getName(),
deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1).getDeviceIds();
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
@ -1964,10 +2013,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
public SubscriptionResponse getStatusBaseSubscriptionsRoleUser(SubscriptionInfo subscriptionInfo, int limit, int offset)
private SubscriptionResponse getStatusBaseSubscriptionsRoleAndUser(SubscriptionInfo subscriptionInfo, int limit, int offset)
throws ApplicationManagementException {
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED,
subscriptionInfo.getSubscriptionStatus());
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
int deviceCount = 0;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -1995,7 +2044,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus
(subscriptionInfo.getDeviceSubscriptionStatus());
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
@ -2021,7 +2071,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.
getDeviceSubscriptionData(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe,
applicationDTO.getDeviceTypeId(), limit, offset);
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
} catch (UserStoreException e) {
@ -2041,7 +2092,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@SuppressWarnings("unchecked")
private List<Integer> getDeviceIdsOwnByRole(String roleName, int tenantId) throws UserStoreException, DeviceManagementException {
UserStoreManager userStoreManager = DataHolder.getInstance().getRealmService().
@ -2076,21 +2126,31 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
return deviceListOwnByUser.stream().map(Device::getId).collect(Collectors.toList());
}
private List<Integer> getAllDeviceIds (SubscriptionInfo subscriptionInfo) throws DeviceManagementException, UserStoreException {
/**
* Retrieves a list of device IDs associated with the subscription described by the {@link SubscriptionInfo}.
* The device IDs are determined based on the subscription type, which could be either a role or a user.
*
* @param subscriptionInfo {@link SubscriptionInfo} containing the subscription details.
* @return A {@link List} of device IDs corresponding to the subscription type, or {@code null} if the type is not recognized.
* @throws DeviceManagementException Thrown when an error occurs while retrieving device IDs.
* @throws UserStoreException Thrown when an error occurs while accessing the user store.
*/
private List<Integer> getAllDeviceIds(SubscriptionInfo subscriptionInfo) throws DeviceManagementException, UserStoreException {
String type = subscriptionInfo.getSubscriptionType();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
if (Objects.equals(type, SubscriptionMetadata.SubscriptionTypes.ROLE)){
return getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(),tenantId);
if (Objects.equals(type, SubscriptionMetadata.SubscriptionTypes.ROLE)) {
return getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
}
if (Objects.equals(type,SubscriptionMetadata.SubscriptionTypes.USER)){
if (Objects.equals(type, SubscriptionMetadata.SubscriptionTypes.USER)) {
return getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
}else
} else {
return null;
}
}
/**
* Get subscription statistics related data describes by the {@link SubscriptionInfo}
*
* @param subscriptionInfo {@link SubscriptionInfo}
* @return {@link SubscriptionStatistics}
* @throws ApplicationManagementException Throws when error encountered while getting statistics
@ -2100,7 +2160,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
return getSubscriptionStatistics(subscriptionInfo);
}
@Override
public List<DeviceOperationDTO> getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid)
throws ApplicationManagementException {

Loading…
Cancel
Save