Refactor subscription related methods

master
Ruwin Dissanayake 4 months ago
parent fa24f95a69
commit 00d13c904f

@ -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();
}
} }
/** /**

@ -150,68 +150,78 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
} }
@Override @Override
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException {
throws ApplicationManagementException { return null;
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 @Override
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
throws ApplicationManagementException { return null;
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); }
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { // @Override
ConnectionManagerUtil.openDBConnection(); // public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. // throws ApplicationManagementException {
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); // final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
if (applicationReleaseDTO == null) { // final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String msg = "Couldn't find an application release for application release UUID: " + // try {
subscriptionInfo.getApplicationUUID(); // ConnectionManagerUtil.openDBConnection();
log.error(msg); // ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
throw new NotFoundException(msg); // getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
} // if (applicationReleaseDTO == null) {
List<Device> devices = HelperUtil.getGroupManagementProviderService(). // String msg = "Couldn't find an application release for application release UUID: " +
getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false); // subscriptionInfo.getApplicationUUID();
List<Integer> deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList()); // log.error(msg);
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. // throw new NotFoundException(msg);
getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); // }
int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier()); // List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); // getGroupsSubscriptionDetailsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
} catch (ApplicationManagementDAOException e) { // int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier(); // subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
log.error(msg, e); // return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
throw new ApplicationManagementException(msg, e); // } catch (DBConnectionException | ApplicationManagementDAOException e) {
} catch (GroupManagementException e) { // String msg = "Error encountered while connecting to the database";
String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier(); // log.error(msg, e);
log.error(msg, e); // throw new ApplicationManagementException(msg, e);
throw new ApplicationManagementException(msg, e); // } finally {
} finally { // ConnectionManagerUtil.closeDBConnection();
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 class GroupBasedSubscriptionManagementHelperServiceImplHolder {
private static final GroupBasedSubscriptionManagementHelperServiceImpl INSTANCE private static final GroupBasedSubscriptionManagementHelperServiceImpl INSTANCE

@ -144,61 +144,71 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri
} }
@Override @Override
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException {
throws ApplicationManagementException { return null;
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.
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);
} 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 @Override
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); return null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); }
try {
ConnectionManagerUtil.openDBConnection(); // @Override
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. // public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); // throws ApplicationManagementException {
if (applicationReleaseDTO == null) { // final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
String msg = "Couldn't find an application release for application release UUID: " + // final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
subscriptionInfo.getApplicationUUID(); // try {
log.error(msg); // ConnectionManagerUtil.openDBConnection();
throw new NotFoundException(msg); // ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
} // getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
List<Integer> deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId); // if (applicationReleaseDTO == null) {
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. // String msg = "Couldn't find an application release for application release UUID: " +
getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); // subscriptionInfo.getApplicationUUID();
int allDeviceCount = deviceIdsOwnByRole.size(); // log.error(msg);
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); // throw new NotFoundException(msg);
} catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) { // }
String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier(); // List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
log.error(msg, e); // getRoleSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
throw new ApplicationManagementException(msg, e); // int subscriptionCount = isUnsubscribe ? subscriptionDAO.getRoleUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
} finally { // subscriptionDAO.getRoleSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
ConnectionManagerUtil.closeDBConnection(); // 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<Integer> deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
// SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
// getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
// int allDeviceCount = deviceIdsOwnByRole.size();
// return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
// } catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) {
// String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier();
// log.error(msg, e);
// throw new ApplicationManagementException(msg, e);
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<Integer> getDeviceIdsOwnByRole(String roleName, int tenantId) throws UserStoreException, DeviceManagementException { private List<Integer> getDeviceIdsOwnByRole(String roleName, int tenantId) throws UserStoreException, DeviceManagementException {

@ -135,61 +135,71 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri
} }
@Override @Override
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset) throws ApplicationManagementException {
throws ApplicationManagementException { return null;
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.
getUserSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getUserUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
subscriptionDAO.getUserSubscriptionCount(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 @Override
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException { public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus()); return null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); }
try {
ConnectionManagerUtil.openDBConnection(); // @Override
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO. // public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId); // throws ApplicationManagementException {
if (applicationReleaseDTO == null) { // final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
String msg = "Couldn't find an application release for application release UUID: " + // final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
subscriptionInfo.getApplicationUUID(); // try {
log.error(msg); // ConnectionManagerUtil.openDBConnection();
throw new NotFoundException(msg); // ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
} // getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
List<Integer> deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier()); // if (applicationReleaseDTO == null) {
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO. // String msg = "Couldn't find an application release for application release UUID: " +
getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId()); // subscriptionInfo.getApplicationUUID();
int allDeviceCount = deviceIdsOwnByUser.size(); // log.error(msg);
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount); // throw new NotFoundException(msg);
} catch (DeviceManagementException | ApplicationManagementDAOException e) { // }
String msg = "Error encountered while getting subscription statistics for user: " + subscriptionInfo.getIdentifier(); // List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
log.error(msg, e); // getUserSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
throw new ApplicationManagementException(msg, e); // int subscriptionCount = isUnsubscribe ? subscriptionDAO.getUserUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
} finally { // subscriptionDAO.getUserSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
ConnectionManagerUtil.closeDBConnection(); // 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<Integer> deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
// SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
// getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
// int allDeviceCount = deviceIdsOwnByUser.size();
// return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
// } catch (DeviceManagementException | ApplicationManagementDAOException e) {
// String msg = "Error encountered while getting subscription statistics for user: " + subscriptionInfo.getIdentifier();
// log.error(msg, e);
// throw new ApplicationManagementException(msg, e);
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<Integer> getDeviceIdsOwnByUser(String username) throws DeviceManagementException { private List<Integer> getDeviceIdsOwnByUser(String username) throws DeviceManagementException {

Loading…
Cancel
Save