|
|
@ -19,19 +19,27 @@ package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.DeviceApplicationMapping;
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.DeviceApplicationMapping;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -45,106 +53,103 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
private static final String INSTALL_APPLICATION = "INSTALL_APPLICATION";
|
|
|
|
private static final String INSTALL_APPLICATION = "INSTALL_APPLICATION";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID, String versionName,
|
|
|
|
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID,
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
List<DeviceIdentifier> deviceList) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
return installApplication(applicationUUID, deviceList, versionName);
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + deviceList.size() + "devices.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> installApplicationForUsers(String applicationUUID, List<String> userList,
|
|
|
|
public List<DeviceIdentifier> installApplicationForUsers(String applicationUUID, List<String> userList)
|
|
|
|
String versionName) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users.");
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + userList.size() + " users.");
|
|
|
|
|
|
|
|
}
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
for (String user : userList) {
|
|
|
|
for (String user : userList) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<Device> devicesOfUser = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user);
|
|
|
|
List<Device> devicesOfUser = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user);
|
|
|
|
for (Device device : devicesOfUser) {
|
|
|
|
for (Device device : devicesOfUser) {
|
|
|
|
deviceList.add(new DeviceIdentifier(device
|
|
|
|
deviceList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
.getDeviceIdentifier(), device.getType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(devicesOfUser.size() + " found for the provided user list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
log.error("Error when extracting the device list from user[" + user + "].", e);
|
|
|
|
throw new ApplicationManagementException("Error when extracting the device list of user[" + user + "].",
|
|
|
|
|
|
|
|
e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return installApplication(applicationUUID, deviceList, versionName);
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> installApplicationForRoles(String applicationUUID, List<String> roleList,
|
|
|
|
public List<DeviceIdentifier> installApplicationForRoles(String applicationUUID, List<String> roleList)
|
|
|
|
String versionName) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " roles.");
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + roleList.size() + " roles.");
|
|
|
|
|
|
|
|
}
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
for (String role : roleList) {
|
|
|
|
for (String role : roleList) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<Device> devicesOfRole = HelperUtil.getDeviceManagementProviderService().getAllDevicesOfRole(role);
|
|
|
|
List<Device> devicesOfRole = HelperUtil.getDeviceManagementProviderService().getAllDevicesOfRole(role);
|
|
|
|
for (Device device : devicesOfRole) {
|
|
|
|
for (Device device : devicesOfRole) {
|
|
|
|
deviceList.add(new DeviceIdentifier(device
|
|
|
|
deviceList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
.getDeviceIdentifier(), device.getType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(devicesOfRole.size() + " found for role: " + role);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
log.error("Error when extracting the device list from role[" + role + "].", e);
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
"Error when extracting the device list from role[" + role + "].", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceIdentifier> installApplicationForGroups(String applicationUUID, List<String> deviceGroupList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + deviceGroupList.size() + " groups.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String groupName : deviceGroupList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(groupName);
|
|
|
|
|
|
|
|
int deviceCount = groupManagementProviderService.getDeviceCount(deviceGroup.getGroupId());
|
|
|
|
|
|
|
|
List<Device> devicesOfGroups = groupManagementProviderService
|
|
|
|
|
|
|
|
.getDevices(deviceGroup.getGroupId(), 0, deviceCount);
|
|
|
|
|
|
|
|
for (Device device : devicesOfGroups) {
|
|
|
|
|
|
|
|
deviceList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
"Error when extracting the device list from group[" + groupName + "].", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return installApplication(applicationUUID, deviceList, versionName);
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
|
|
|
|
public List<DeviceIdentifier> uninstallApplication(String applicationUUID, List<DeviceIdentifier> deviceList)
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList,
|
|
|
|
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList)
|
|
|
|
String versionName) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
//todo: 1. get application and release.
|
|
|
|
|
|
|
|
ApplicationReleaseManager applicationReleaseManager = ApplicationManagementUtil
|
|
|
|
|
|
|
|
.getApplicationReleaseManagerInstance();
|
|
|
|
|
|
|
|
ApplicationRelease applicationRelease = applicationReleaseManager.getReleaseByUuid(applicationUUID);
|
|
|
|
|
|
|
|
//todo: 2. check type and filter devices.
|
|
|
|
|
|
|
|
//todo: 3. generate url based on application attributes and app release attributes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Todo: check if app type is installable for all the device types: apk -> android, ipa -> ios, webclip -> both
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
// List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
|
|
|
|
|
|
|
|
// // Todo: try whether we can optimise this by sending bulk inserts to db
|
|
|
|
|
|
|
|
// // Todo: atomicity is not maintained as deveice managment provider service uses separate db connection. fix this??
|
|
|
|
|
|
|
|
// log.info("Install application: " + applicationUUID + "[" + versionName + "]" + " to: "
|
|
|
|
|
|
|
|
// + deviceList.size() + " devices.");
|
|
|
|
|
|
|
|
// for (DeviceIdentifier device : deviceList) {
|
|
|
|
|
|
|
|
// org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt
|
|
|
|
|
|
|
|
// .common.DeviceIdentifier(device.getId(), device.getType());
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService();
|
|
|
|
|
|
|
|
// if (!dmpService.isEnrolled(deviceIdentifier)) {
|
|
|
|
|
|
|
|
// log.error("Device with ID: [" + device.getId() + "] is not enrolled to install the application.");
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
// log.debug("Installing application to : " + device.getId());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// //Todo: generating one time download link for the application and put install operation to device.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // put app install operation to the device
|
|
|
|
|
|
|
|
// ProfileOperation operation = new ProfileOperation();
|
|
|
|
|
|
|
|
// operation.setCode(INSTALL_APPLICATION);
|
|
|
|
|
|
|
|
// operation.setType(Operation.Type.PROFILE);
|
|
|
|
|
|
|
|
// operation.setPayLoad("{'type':'enterprise', 'url':'http://10.100.5.76:8000/app-debug.apk', 'app':'"
|
|
|
|
|
|
|
|
// + applicationUUID + "'}");
|
|
|
|
|
|
|
|
// List<org.wso2.carbon.device.mgt.common.DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
// deviceIdentifiers.add(deviceIdentifier);
|
|
|
|
|
|
|
|
// dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
|
|
|
|
|
|
|
|
// operation, deviceIdentifiers);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// DeviceApplicationMapping deviceApp = new DeviceApplicationMapping();
|
|
|
|
|
|
|
|
// deviceApp.setDeviceIdentifier(device.getId());
|
|
|
|
|
|
|
|
// deviceApp.setApplicationUUID(applicationUUID);
|
|
|
|
|
|
|
|
// deviceApp.setVersionName(versionName);
|
|
|
|
|
|
|
|
// deviceApp.setInstalled(false);
|
|
|
|
|
|
|
|
// dmpService.addDeviceApplicationMapping(deviceApp);
|
|
|
|
|
|
|
|
//// DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
//// ApplicationManagementDAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
|
|
|
|
|
|
|
// failedDeviceList.remove(device);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) {
|
|
|
|
|
|
|
|
// log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// finally {
|
|
|
|
|
|
|
|
// DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return failedDeviceList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|