Add api impl for retrieving app installable devices

appbr1
prathabanKavin 2 months ago
parent 66c9c4f4e6
commit 010ccde84e

@ -180,6 +180,16 @@ public interface SubscriptionManager {
*/
PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID) throws ApplicationManagementException;
/***
* This method used to get the app id ,device ids and pass them to DM service method.
*
* @param appUUID UUID of the application release.
* @param request paginated request object.
* @return deviceDetails - device details for given application release.
* @throws {@link ApplicationManagementException} Exception of the application management
*/
PaginationResult getAppInstallableDevices(PaginationRequest request, String appUUID) throws ApplicationManagementException;
/***
* This method used to get category details.
*
@ -196,6 +206,22 @@ public interface SubscriptionManager {
String subType, Boolean uninstalled, String searchName)
throws ApplicationManagementException;
/***
* This method used to get category details.
*
* @param appUUID UUID of the application release.
* @param subType subscription type of the application.
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param uninstalled a Boolean flag indicating the filter criteria for retrieve subscription data
* @param searchName an optional search term to filter the results by name. If null or empty, no filtering by name is applied.
* @return {@link PaginationResult} pagination result of the category details.
* @throws {@link ApplicationManagementException} Exception of the application management
*/
PaginationResult getAppInstallableSubscribers(int offsetValue, int limitValue, String appUUID,
String subType, Boolean uninstalled, String searchName)
throws ApplicationManagementException;
/**
* This method is responsible to provide application subscription data for given application release UUID.
*

@ -137,6 +137,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
/**
* This is the default implementation for the Subscription Manager.
@ -1497,6 +1498,75 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
public PaginationResult getAppInstallableDevices(PaginationRequest request, String appUUID)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId);
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId, null, null);
if (deviceSubscriptionDTOS.isEmpty()) {
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
return paginationResult;
}
List<Integer> deviceIdList = new ArrayList<>();
deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> {
if ((!deviceSubscriptionDTO.isUnsubscribed() && !Operation.Status.PENDING.toString()
.equalsIgnoreCase(deviceSubscriptionDTO.getStatus())) || (deviceSubscriptionDTO.isUnsubscribed()
&& !Operation.Status.COMPLETED.toString()
.equalsIgnoreCase(deviceSubscriptionDTO.getStatus()))) {
deviceIdList.add(deviceSubscriptionDTO.getDeviceId());
}
});
if (deviceIdList.isEmpty()) {
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(deviceIdList);
paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
return paginationResult;
}
//pass the device id list to device manager service method
try {
PaginationResult deviceDetails = deviceManagementProviderService.getAppSubscribedDevices
(request, deviceIdList);
if (deviceDetails == null) {
String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList;
log.error(msg);
throw new NotFoundException(msg);
}
return deviceDetails;
} catch (DeviceManagementException e) {
String msg = "service error occurred while getting data from the service";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occurred when get application release data for application" + " release UUID: " + appUUID;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while getting device details that " + "given application id";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType,
Boolean uninstalled, String searchName)
@ -1544,6 +1614,61 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
public PaginationResult getAppInstallableSubscribers(int offsetValue, int limitValue, String appUUID, String subType,
Boolean uninstalled, String searchName)
throws ApplicationManagementException, UserStoreException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
PaginationResult paginationResult = new PaginationResult();
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId);
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<String> subscriptionList = new ArrayList<>();
List<String> subscribedList = new ArrayList<>();
List<Device> deviceList = new ArrayList<>();;
int count = 0;
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
subscribedList = subscriptionDAO
.getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName);
count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId, uninstalled, searchName);
for (String user : subscribedList) {
deviceList = deviceManagementProviderService.getDevicesOfUser(user, false)
}
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
subscribedList = subscriptionDAO
.getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName);
count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId, uninstalled, searchName);
for (String role : subscribedList) {
deviceList = deviceManagementProviderService.getAllDevicesOfRole(role, false)
}
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscribedList = subscriptionDAO
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId, uninstalled, searchName);
}
paginationResult.setData(subscriptionList);
paginationResult.setRecordsFiltered(count);
paginationResult.setRecordsTotal(count);
return paginationResult;
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occurred when get application release data for application" + " release UUID: " + appUUID;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while getting category details that " + "given application id";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
String action, String installedVersion) throws ApplicationManagementException {

Loading…
Cancel
Save