|
|
@ -19,32 +19,13 @@
|
|
|
|
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
|
|
|
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.*;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.*;
|
|
|
|
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.DeviceSubscriptionData;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
|
|
|
|
|
|
|
|
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.SubscriptionType;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
|
|
|
|
|
|
|
|
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.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.common.services.VPPApplicationManager;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
|
|
|
|
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.dao.VppApplicationDAO;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
|
|
|
|
|
|
|
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.SubscriptionManagementServiceProvider;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementServiceProvider;
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
|
|
|
|
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.PaginationRequest;
|
|
|
@ -122,14 +103,7 @@ import java.net.URL;
|
|
|
|
import java.security.KeyManagementException;
|
|
|
|
import java.security.KeyManagementException;
|
|
|
|
import java.security.KeyStoreException;
|
|
|
|
import java.security.KeyStoreException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -1709,9 +1683,72 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|
|
|
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
SubscriptionManagementHelperService subscriptionManagementHelperService =
|
|
|
|
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
|
|
|
SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo);
|
|
|
|
final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
return subscriptionManagementHelperService.getSubscriptions(subscriptionInfo, limit, offset);
|
|
|
|
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<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
|
|
|
|
|
|
|
|
getGroupsSubscriptionDetailsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
|
|
|
|
|
|
|
|
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
|
|
|
|
|
|
|
|
subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
|
|
|
|
|
|
|
|
} catch (DBConnectionException | ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error encountered while connecting to the database";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
// public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|
|
|
|
|
|
|
// throws ApplicationManagementException {
|
|
|
|
|
|
|
|
// SubscriptionManagementHelperService subscriptionManagementHelperService =
|
|
|
|
|
|
|
|
// SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo);
|
|
|
|
|
|
|
|
// return subscriptionManagementHelperService.getSubscriptions(subscriptionInfo, limit, offset);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
|
|
|
|
|
|
|
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<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);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|