|
|
@ -137,6 +137,7 @@ import java.util.Properties;
|
|
|
|
import java.util.Set;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This is the default implementation for the Subscription Manager.
|
|
|
|
* 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
|
|
|
|
@Override
|
|
|
|
public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType,
|
|
|
|
public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType,
|
|
|
|
Boolean uninstalled, String searchName)
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
public CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
|
|
|
|
public CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
|
|
|
|
String action, String installedVersion) throws ApplicationManagementException {
|
|
|
|
String action, String installedVersion) throws ApplicationManagementException {
|
|
|
|