|
|
|
@ -150,68 +150,78 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
|
|
|
|
final 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<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();
|
|
|
|
|
}
|
|
|
|
|
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|
|
|
|
// throws ApplicationManagementException {
|
|
|
|
|
// final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
|
|
|
|
// final 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<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 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();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private static class GroupBasedSubscriptionManagementHelperServiceImplHolder {
|
|
|
|
|
private static final GroupBasedSubscriptionManagementHelperServiceImpl INSTANCE
|
|
|
|
|