|
|
@ -47,64 +47,23 @@ import java.util.List;
|
|
|
|
public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class);
|
|
|
|
|
|
|
|
private static final String INSTALL_APPLICATION = "INSTALL_APPLICATION";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID, String versionName,
|
|
|
|
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID, String versionName,
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
List<DeviceIdentifier> deviceList)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
return installApplication(applicationUUID, deviceList, versionName);
|
|
|
|
// 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 + " to: " + deviceList.size() + " devices.");
|
|
|
|
|
|
|
|
List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
|
|
|
|
|
|
|
|
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 = DataHolder.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
|
|
|
|
|
|
|
deviceManagementProviderService.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);
|
|
|
|
|
|
|
|
deviceManagementProviderService.addDeviceApplicationMapping(deviceApp);
|
|
|
|
|
|
|
|
// DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
|
|
|
|
|
|
|
failedDeviceList.remove(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException("Failed to install application " + applicationUUID + " on device " + deviceIdentifier, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return failedDeviceList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> installApplicationForUsers(String applicationUUID, List<String> userList)
|
|
|
|
public List<DeviceIdentifier> installApplicationForUsers(String applicationUUID, List<String> userList,
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
String versionName) throws ApplicationManagementException {
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users.");
|
|
|
|
log.info("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 = DataHolder.getInstance().getDeviceManagementService().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()));
|
|
|
@ -113,17 +72,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
log.error("Error when extracting the device list from user[" + user + "].", e);
|
|
|
|
log.error("Error when extracting the device list from user[" + user + "].", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
return installApplication(applicationUUID, deviceList, versionName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceIdentifier> installApplicationForRoles(String applicationUUID, List<String> roleList)
|
|
|
|
public List<DeviceIdentifier> installApplicationForRoles(String applicationUUID, List<String> roleList,
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
String versionName) throws ApplicationManagementException {
|
|
|
|
log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " roles.");
|
|
|
|
log.info("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 = DataHolder.getInstance().getDeviceManagementService().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()));
|
|
|
@ -132,7 +91,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
log.error("Error when extracting the device list from role[" + role + "].", e);
|
|
|
|
log.error("Error when extracting the device list from role[" + role + "].", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return installApplication(applicationUUID, deviceList);
|
|
|
|
return installApplication(applicationUUID, deviceList, versionName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -142,32 +101,54 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList)
|
|
|
|
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList,
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
String versionName) 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<>();
|
|
|
|
// 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) {
|
|
|
|
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());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService();
|
|
|
|
if (DeviceManagementDAOFactory.getDeviceDAO().getDevice(deviceIdentifier).isEmpty()) {
|
|
|
|
if (!dmpService.isEnrolled(deviceIdentifier)) {
|
|
|
|
log.error("Device with ID: " + device.getId() + " not found to install the application.");
|
|
|
|
log.error("Device with ID: [" + device.getId() + "] is not enrolled to install the application.");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Prepare application install to : " + device.getId());
|
|
|
|
log.debug("Installing application to : " + device.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activeDeviceList.add(deviceIdentifier);
|
|
|
|
//Todo: generating one time download link for the application and put install operation to device.
|
|
|
|
DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
|
|
|
failedDeviceList.remove(device);
|
|
|
|
failedDeviceList.remove(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
} catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) {
|
|
|
|
throw new ApplicationManagementException("Error locating device.", e);
|
|
|
|
log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e);
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally {
|
|
|
|
|
|
|
|
// DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Todo: generating one time download link for the application and put install operation to devices.
|
|
|
|
|
|
|
|
return failedDeviceList;
|
|
|
|
return failedDeviceList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|