|
|
|
@ -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
|
|
|
|
@ -495,7 +532,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
* @throws ApplicationManagementException if error occurred while getting Application subscription info
|
|
|
|
|
*/
|
|
|
|
|
private <T> ApplicationSubscriptionInfo getAppSubscriptionInfo(ApplicationDTO applicationDTO, String subType,
|
|
|
|
|
List<T> params) throws ApplicationManagementException {
|
|
|
|
|
List<T> params) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
@ -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)) {
|
|
|
|
@ -608,7 +645,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
* @throws ApplicationManagementException if error occurred while getting or updating subscription data.
|
|
|
|
|
*/
|
|
|
|
|
private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appSubscribingDeviceIds,
|
|
|
|
|
List<Integer> appReSubscribingDeviceIds, List<String> params, String subType, String action)
|
|
|
|
|
List<Integer> appReSubscribingDeviceIds, List<String> params, String subType, String action)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
@ -679,14 +716,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
/**
|
|
|
|
|
* This method perform given action (i.e APP INSTALL or APP UNINSTALL) on given set of devices.
|
|
|
|
|
*
|
|
|
|
|
* @param deviceType Application supported device type.
|
|
|
|
|
* @param devices List of devices that action is triggered.
|
|
|
|
|
* @param applicationDTO Application data
|
|
|
|
|
* @param subType Subscription type (i.e USER, ROLE, GROUP or DEVICE)
|
|
|
|
|
* @param subscribers Subscribers
|
|
|
|
|
* @param action Performing action. (i.e INSTALL or UNINSTALL)
|
|
|
|
|
* @param deviceType Application supported device type.
|
|
|
|
|
* @param devices List of devices that action is triggered.
|
|
|
|
|
* @param applicationDTO Application data
|
|
|
|
|
* @param subType Subscription type (i.e USER, ROLE, GROUP or DEVICE)
|
|
|
|
|
* @param subscribers Subscribers
|
|
|
|
|
* @param action Performing action. (i.e INSTALL or UNINSTALL)
|
|
|
|
|
* @param isOperationReExecutingDisabled To prevent adding the application subscribing operation to devices that are
|
|
|
|
|
* already subscribed application successfully.
|
|
|
|
|
* already subscribed application successfully.
|
|
|
|
|
* @return {@link ApplicationInstallResponse}
|
|
|
|
|
* @throws ApplicationManagementException if error occurred when adding operation on device or updating subscription
|
|
|
|
|
* data.
|
|
|
|
@ -905,7 +942,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
* @throws ApplicationManagementException if error occurred while getting or updating subscription data.
|
|
|
|
|
*/
|
|
|
|
|
private void updateSubscriptions(int applicationReleaseId, List<Activity> activities,
|
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> params, String subType, String action)
|
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> params, String subType, String action)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
@ -981,7 +1018,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
* @throws ApplicationManagementDAOException if error occurred while updating or inserting subscriber entities
|
|
|
|
|
*/
|
|
|
|
|
private void updateBulkSubscribers(int applicationReleaseId, List<String> params, String subType, String action,
|
|
|
|
|
int tenantId, String username) throws ApplicationManagementDAOException {
|
|
|
|
|
int tenantId, String username) throws ApplicationManagementDAOException {
|
|
|
|
|
List<String> subscribedEntities = new ArrayList<>();
|
|
|
|
|
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
|
|
|
|
subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
|
|
|
|
@ -1067,7 +1104,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
* @throws ApplicationManagementException if found an invalid device.
|
|
|
|
|
*/
|
|
|
|
|
private Activity addAppOperationOnDevices(ApplicationDTO applicationDTO,
|
|
|
|
|
List<DeviceIdentifier> deviceIdentifierList, String deviceType, String action, Properties properties)
|
|
|
|
|
List<DeviceIdentifier> deviceIdentifierList, String deviceType, String action, Properties properties)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
@ -1217,10 +1254,11 @@ 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
|
|
|
|
|
* application
|
|
|
|
|
* application
|
|
|
|
|
*/
|
|
|
|
|
private String getBundleId(String appId) throws ApplicationManagementException {
|
|
|
|
|
try {
|
|
|
|
@ -1261,7 +1299,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
throws SubscriptionManagementException {
|
|
|
|
|
try {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
List<Integer> operationIds = getOperationIdsForSubId(subId, tenantId);
|
|
|
|
|
List<Integer> operationIds = getOperationIdsForSubId(subId, tenantId);
|
|
|
|
|
APIUtil.getApplicationManager().updateSubStatus(deviceId, operationIds, status);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while observing the database connection to get operation Ids for " + subId;
|
|
|
|
@ -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) {
|
|
|
|
@ -1346,7 +1384,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
|
|
|
|
|
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
|
|
|
|
|
return HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build();
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
String msg = "Failed while building the http client for EntApp installation. " +
|
|
|
|
|
"Used SSL algorithm not available";
|
|
|
|
|
log.error(msg, 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
|
|
|
|
|
* @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) :
|
|
|
|
@ -1717,7 +1758,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
} else {
|
|
|
|
|
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException | ApplicationManagementDAOException e) {
|
|
|
|
|
} catch (DBConnectionException | ApplicationManagementDAOException e) {
|
|
|
|
|
String msg = "Error encountered while connecting to the database";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
@ -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,29 +1793,31 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
@ -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
|
|
|
|
|
* @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,25 +1888,25 @@ 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.
|
|
|
|
|
getId(), isUnsubscribe, tenantId, null, null,
|
|
|
|
|
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
|
|
|
|
|
|
|
|
|
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
|
|
|
|
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
|
|
|
|
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
|
|
|
|
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
|
|
|
|
getId(), isUnsubscribe, tenantId, null, null,
|
|
|
|
|
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
|
|
|
|
|
|
|
|
|
List<Integer> newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription);
|
|
|
|
|
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
|
|
|
|
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
|
|
|
|
} else {
|
|
|
|
|
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
|
|
|
|
getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null,
|
|
|
|
|
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
|
|
|
|
}
|
|
|
|
|
List<Integer> newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription);
|
|
|
|
|
|
|
|
|
|
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
|
|
|
|
} else {
|
|
|
|
|
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
|
|
|
|
getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null,
|
|
|
|
|
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
|
|
|
|
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
|
|
|
|
@ -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,12 +1958,15 @@ 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(),
|
|
|
|
|
deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1).getDeviceIds();
|
|
|
|
|
List<Integer> allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices
|
|
|
|
|
(subscriptionInfo.getIdentifier(),
|
|
|
|
|
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(),
|
|
|
|
|
deviceSubscriptionFilterCriteria.getName(),
|
|
|
|
|
deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1).getDeviceIds();
|
|
|
|
|
|
|
|
|
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
|
|
|
|
isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, null,
|
|
|
|
@ -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 {
|
|
|
|
|