mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix issues with pending ops validation
This commit is contained in:
parent
ad2a558d5c
commit
79c3837d8a
@ -180,7 +180,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
||||
ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType,
|
||||
params);
|
||||
validatePendingAppSubscription(applicationSubscriptionInfo, applicationDTO);
|
||||
performExternalStoreSubscription(applicationDTO, applicationSubscriptionInfo);
|
||||
ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(
|
||||
applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(),
|
||||
@ -708,35 +707,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void validatePendingAppSubscription(ApplicationSubscriptionInfo applicationSubscriptionInfo, ApplicationDTO applicationDTO) throws BadRequestException, ApplicationManagementException{
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
|
||||
try {
|
||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
||||
.getDeviceSubscriptions(applicationReleaseId, tenantId, null, null);
|
||||
List<Integer> deviceIdList = new ArrayList<>();
|
||||
deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> {
|
||||
if (!deviceSubscriptionDTO.isUnsubscribed() &&
|
||||
Operation.Status.PENDING.toString().equalsIgnoreCase(deviceSubscriptionDTO.getStatus())) {
|
||||
deviceIdList.add(deviceSubscriptionDTO.getDeviceId());
|
||||
}
|
||||
});
|
||||
|
||||
List<Integer> subscriptionDeviceIds = applicationSubscriptionInfo.getDevices().stream()
|
||||
.map(Device::getId)
|
||||
.collect(Collectors.toList());
|
||||
boolean allDevicesPending = subscriptionDeviceIds.stream()
|
||||
.allMatch(deviceIdList::contains);
|
||||
if (allDevicesPending) {
|
||||
String msg = "All devices in the subscription have pending operations for this application.";
|
||||
private <T> void validatePendingAppSubscription(List<Device> devices, SubscribingDeviceIdHolder subscribingDeviceIdHolder) throws BadRequestException{
|
||||
Set<DeviceIdentifier> deviceIdentifiers = devices.stream()
|
||||
.map(device -> new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))
|
||||
.collect(Collectors.toSet());
|
||||
Set<DeviceIdentifier> skippedDevices = subscribingDeviceIdHolder.getSkippedDevices().keySet();
|
||||
if (skippedDevices.containsAll(deviceIdentifiers) && deviceIdentifiers.containsAll(skippedDevices)) {
|
||||
String msg = "All devices in the subscription have pending operations for this application.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error while retrieving device subscriptions";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException("Error while validating application subscription", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -773,6 +753,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
Map<String, List<DeviceIdentifier>> deviceIdentifierMap = new HashMap<>();
|
||||
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
validatePendingAppSubscription(devices, subscribingDeviceIdHolder);
|
||||
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
|
||||
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet()));
|
||||
if (!isOperationReExecutingDisabled) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user