mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add new feature to install applications for device
This commit is contained in:
parent
05055937e7
commit
1919fbde16
@ -21,6 +21,7 @@ import org.wso2.carbon.device.application.mgt.common.ExecutionStatus;
|
||||
import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDTO;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.SubscriptionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
|
||||
import java.util.List;
|
||||
@ -101,6 +102,18 @@ public interface SubscriptionManager {
|
||||
<T> void performEntAppSubscription(String applicationUUID, List<T> params, String subType, String action,
|
||||
boolean requiresUpdatingExternal) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Install given application releases for given device. If application is already installed that application skips.
|
||||
* This is used in enterprise app installing policy.
|
||||
*
|
||||
* @param deviceIdentifier Device identifiers
|
||||
* @param releaseUUID UUIs of applicatios
|
||||
* @throws ApplicationManagementException if error occurred while installing given applications into the given
|
||||
* device
|
||||
*/
|
||||
void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<String> releaseUUID)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/***
|
||||
* This method used to get the app id ,device ids and pass them to DM service method.
|
||||
*
|
||||
|
||||
@ -94,6 +94,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -261,7 +262,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
log.error(msg, e);
|
||||
throw new SubscriptionManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection";
|
||||
String msg = "Error occurred while retrieving the database connection to clean the scheduled subscriptions";
|
||||
log.error(msg, e);
|
||||
throw new SubscriptionManagementException(msg, e);
|
||||
} finally {
|
||||
@ -454,6 +455,70 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<String> releaseUUIDs)
|
||||
throws ApplicationManagementException {
|
||||
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
Device device;
|
||||
try {
|
||||
device = DataHolder.getInstance().getDeviceManagementService().getDevice(deviceIdentifier, false);
|
||||
if (device == null) {
|
||||
String msg = "Invalid device identifier is received and couldn't find an deveice for the requested "
|
||||
+ "device identifier. Device UUID: " + deviceIdentifier.getId() + " Device Type: "
|
||||
+ deviceIdentifier.getType();
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occured while getting device data for given device identifier.Device UUID: "
|
||||
+ deviceIdentifier.getId() + " Device Type: " + deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
|
||||
List<DeviceIdentifier> appInstallingDevices = new ArrayList<>();
|
||||
|
||||
for (String releaseUUID : releaseUUIDs) {
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUUID, tenantId);
|
||||
if (applicationDTO != null) {
|
||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = this.subscriptionDAO
|
||||
.getDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
|
||||
tenantId);
|
||||
AtomicBoolean isAppSubscribable = new AtomicBoolean(true);
|
||||
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
|
||||
if (device.getId() == deviceSubscriptionDTO.getDeviceId() && !deviceSubscriptionDTO
|
||||
.isUnsubscribed()) {
|
||||
isAppSubscribable.set(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isAppSubscribable.get()) {
|
||||
appInstallingDevices.add(deviceIdentifier);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = " Error occurred while getting DB connection to retrieve app data data from DB. Device "
|
||||
+ "UUID: " + deviceIdentifier.getId() + " Device Type: " + deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = " Error occurred while getting application data from DB. Device UUID: " + deviceIdentifier
|
||||
.getId() + " Device Type: " + deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
|
||||
if (!appInstallingDevices.isEmpty()) {
|
||||
performBulkAppOperation(releaseUUID, appInstallingDevices, SubscriptionType.DEVICE.toString(),
|
||||
SubAction.INSTALL.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is responsible to update subscription data for google enterprise install.
|
||||
*
|
||||
@ -584,13 +649,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
List<DeviceIdentifier> identifiers;
|
||||
if (!deviceIdentifierMap.containsKey(identifier.getType())) {
|
||||
identifiers = new ArrayList<>();
|
||||
identifiers.add(identifier);
|
||||
deviceIdentifierMap.put(identifier.getType(), identifiers);
|
||||
} else {
|
||||
identifiers = deviceIdentifierMap.get(identifier.getType());
|
||||
identifiers.add(identifier);
|
||||
deviceIdentifierMap.put(identifier.getType(), identifiers);
|
||||
}
|
||||
identifiers.add(identifier);
|
||||
deviceIdentifierMap.put(identifier.getType(), identifiers);
|
||||
}
|
||||
for (Map.Entry<String, List<DeviceIdentifier>> entry : deviceIdentifierMap.entrySet()) {
|
||||
Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()),
|
||||
|
||||
@ -930,9 +930,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
try {
|
||||
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
||||
} catch (DeviceManagementException e) {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
||||
deviceIdentifier.getId() + ")", e);
|
||||
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
int deviceId = device.getId();
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user