|
|
@ -19,10 +19,14 @@ 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.context.PrivilegedCarbonContext;
|
|
|
|
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.SubscriptionManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
|
|
|
|
|
|
|
@ -42,7 +46,60 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + deviceList.size() + " devices.");
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + deviceList.size() + " devices.");
|
|
|
|
|
|
|
|
List<DeviceIdentifier> failedDevices = installApplication(applicationUUID, deviceList);
|
|
|
|
|
|
|
|
return failedDevices;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceIdentifier> installApplicationForUsers(String applicationUUID, List<String> userList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users.");
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
for (String user : userList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Device> devicesOfUser = DeviceManagementDAOFactory.getDeviceDAO().getDevicesOfUser(user, tenantId);
|
|
|
|
|
|
|
|
for (Device device : devicesOfUser) {
|
|
|
|
|
|
|
|
deviceList.add(new DeviceIdentifier(device
|
|
|
|
|
|
|
|
.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
log.error("Error when extracting the device list from user[" + user + "].", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceIdentifier> installApplicationForRoles(String applicationUUID, List<String> roleList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " roles.");
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String role : roleList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Device> devicesOfRole = DataHolder.getInstance().getDeviceManagementService().getAllDevicesOfRole(role);
|
|
|
|
|
|
|
|
for (Device device : devicesOfRole) {
|
|
|
|
|
|
|
|
deviceList.add(new DeviceIdentifier(device
|
|
|
|
|
|
|
|
.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error when extracting the device list from role[" + role + "].", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
|
|
|
|
List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
|
|
|
|
|
|
|
|
List<org.wso2.carbon.device.mgt.common.DeviceIdentifier> activeDeviceList = new ArrayList<>();
|
|
|
|
for (DeviceIdentifier device : deviceList) {
|
|
|
|
for (DeviceIdentifier device : deviceList) {
|
|
|
|
org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt
|
|
|
|
org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt
|
|
|
|
.common.DeviceIdentifier(device.getId(), device.getType());
|
|
|
|
.common.DeviceIdentifier(device.getId(), device.getType());
|
|
|
@ -52,9 +109,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
log.error("Device with ID: " + device.getId() + " not found to install the application.");
|
|
|
|
log.error("Device with ID: " + device.getId() + " not found to install the application.");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Installing application to : " + device.getId());
|
|
|
|
log.debug("Prepare application install to : " + device.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Todo: generating one time download link for the application and put install operation to device.
|
|
|
|
activeDeviceList.add(deviceIdentifier);
|
|
|
|
DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
|
|
|
DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
|
|
|
failedDeviceList.remove(device);
|
|
|
|
failedDeviceList.remove(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,35 +121,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Todo: generating one time download link for the application and put install operation to devices.
|
|
|
|
return failedDeviceList;
|
|
|
|
return failedDeviceList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<String> installApplicationForUsers(String applicationUUID, List<String> userList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users.");
|
|
|
|
|
|
|
|
for (String user : userList) {
|
|
|
|
|
|
|
|
//Todo: implementation
|
|
|
|
|
|
|
|
//Todo: get the device list and call installApplicationForDevices
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return userList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<String> installApplicationForRoles(String applicationUUID, List<String> roleList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " users.");
|
|
|
|
|
|
|
|
for (String role : roleList) {
|
|
|
|
|
|
|
|
//Todo: implementation
|
|
|
|
|
|
|
|
//Todo: get the device list and call installApplicationForDevices
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return roleList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|