mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
App-mgt-store Adding version name and code simplification
This commit is contained in:
parent
f45ba70b66
commit
89495d9c77
@ -59,10 +59,10 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
|
||||
result = subscriptionManager.installApplicationForDevices(applicationUUTD, versionName, deviceList);
|
||||
} else if (!installationDetails.getUserNameList().isEmpty()) {
|
||||
List<String> userList = installationDetails.getUserNameList();
|
||||
result = subscriptionManager.installApplicationForUsers(applicationUUTD, userList);
|
||||
result = subscriptionManager.installApplicationForUsers(applicationUUID, userList, versionName);
|
||||
} else if (!installationDetails.getRoleNameList().isEmpty()) {
|
||||
List<String> roleList = installationDetails.getRoleNameList();
|
||||
result = subscriptionManager.installApplicationForRoles(applicationUUTD, roleList);
|
||||
result = subscriptionManager.installApplicationForRoles(applicationUUID, roleList, versionName);
|
||||
} else {
|
||||
result = "Missing request data!";
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(result).build();
|
||||
|
||||
@ -46,7 +46,7 @@ public interface SubscriptionManager {
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
List<DeviceIdentifier> installApplicationForUsers(String applicationUUID,
|
||||
List<String> userList)
|
||||
List<String> userList, String versionName)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
@ -57,7 +57,7 @@ public interface SubscriptionManager {
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
List<DeviceIdentifier> installApplicationForRoles(String applicationUUID,
|
||||
List<String> roleList)
|
||||
List<String> roleList, String versionName)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
|
||||
@ -52,18 +52,67 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID, String versionName,
|
||||
List<DeviceIdentifier> deviceList)
|
||||
throws ApplicationManagementException {
|
||||
return installApplication(applicationUUID, deviceList, versionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceIdentifier> installApplicationForUsers(String applicationUUID, List<String> userList, String versionName)
|
||||
throws ApplicationManagementException {
|
||||
log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users.");
|
||||
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
||||
for (String user : userList) {
|
||||
try {
|
||||
List<Device> devicesOfUser = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user);
|
||||
for (Device device : devicesOfUser) {
|
||||
deviceList.add(new DeviceIdentifier(device
|
||||
.getDeviceIdentifier(), device.getType()));
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Error when extracting the device list from user[" + user + "].", e);
|
||||
}
|
||||
}
|
||||
return installApplication(applicationUUID, deviceList, versionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceIdentifier> installApplicationForRoles(String applicationUUID, List<String> roleList, String versionName)
|
||||
throws ApplicationManagementException {
|
||||
log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " roles.");
|
||||
List<DeviceIdentifier> deviceList = new ArrayList<>();
|
||||
for (String role : roleList) {
|
||||
try {
|
||||
List<Device> devicesOfRole = HelperUtil.getDeviceManagementProviderService().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, versionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
|
||||
List<DeviceIdentifier> deviceList)
|
||||
throws ApplicationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList, String versionName)
|
||||
throws ApplicationManagementException {
|
||||
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 + " to: " + deviceList.size() + " devices.");
|
||||
List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
|
||||
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 = DataHolder.getInstance().getDeviceManagementService();
|
||||
DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService();
|
||||
if (!dmpService.isEnrolled(deviceIdentifier)) {
|
||||
log.error("Device with ID: " + device.getId() + " is not enrolled to install the application.");
|
||||
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());
|
||||
@ -77,8 +126,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
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,
|
||||
dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
|
||||
operation, deviceIdentifiers);
|
||||
|
||||
DeviceApplicationMapping deviceApp = new DeviceApplicationMapping();
|
||||
@ -86,88 +134,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
deviceApp.setApplicationUUID(applicationUUID);
|
||||
deviceApp.setVersionName(versionName);
|
||||
deviceApp.setInstalled(false);
|
||||
deviceManagementProviderService.addDeviceApplicationMapping(deviceApp);
|
||||
dmpService.addDeviceApplicationMapping(deviceApp);
|
||||
// DeviceManagementDAOFactory.openConnection();
|
||||
// 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);
|
||||
log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e);
|
||||
}
|
||||
// finally {
|
||||
// DeviceManagementDAOFactory.closeConnection();
|
||||
// }
|
||||
}
|
||||
return failedDeviceList;
|
||||
}
|
||||
|
||||
@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<>();
|
||||
for (String user : userList) {
|
||||
try {
|
||||
List<Device> devicesOfUser = DataHolder.getInstance().getDeviceManagementService().getDevicesOfUser(user);
|
||||
for (Device device : devicesOfUser) {
|
||||
deviceList.add(new DeviceIdentifier(device
|
||||
.getDeviceIdentifier(), device.getType()));
|
||||
}
|
||||
} catch (DeviceManagementException 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<org.wso2.carbon.device.mgt.common.DeviceIdentifier> activeDeviceList = new ArrayList<>();
|
||||
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 {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
if (DeviceManagementDAOFactory.getDeviceDAO().getDevice(deviceIdentifier).isEmpty()) {
|
||||
log.error("Device with ID: " + device.getId() + " not found to install the application.");
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Prepare application install to : " + device.getId());
|
||||
}
|
||||
activeDeviceList.add(deviceIdentifier);
|
||||
DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
|
||||
failedDeviceList.remove(device);
|
||||
}
|
||||
} catch (DeviceManagementDAOException | SQLException e) {
|
||||
throw new ApplicationManagementException("Error locating device.", e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
//Todo: generating one time download link for the application and put install operation to devices.
|
||||
return failedDeviceList;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user