From 89495d9c77c5c5ffd5dc7fb06da1d148ced0377d Mon Sep 17 00:00:00 2001 From: amalhub Date: Mon, 9 Oct 2017 18:53:40 +0530 Subject: [PATCH 1/3] App-mgt-store Adding version name and code simplification --- .../impl/SubscriptionManagementAPIImpl.java | 4 +- .../common/services/SubscriptionManager.java | 4 +- .../core/impl/SubscriptionManagerImpl.java | 102 +++++++----------- 3 files changed, 44 insertions(+), 66 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java index cf0de355b5..5eac81699b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java @@ -59,10 +59,10 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ result = subscriptionManager.installApplicationForDevices(applicationUUTD, versionName, deviceList); } else if (!installationDetails.getUserNameList().isEmpty()) { List userList = installationDetails.getUserNameList(); - result = subscriptionManager.installApplicationForUsers(applicationUUTD, userList); + result = subscriptionManager.installApplicationForUsers(applicationUUID, userList, versionName); } else if (!installationDetails.getRoleNameList().isEmpty()) { List 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(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index 5f21cb2a98..603ac48015 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -46,7 +46,7 @@ public interface SubscriptionManager { * @throws ApplicationManagementException Application Management Exception */ List installApplicationForUsers(String applicationUUID, - List userList) + List userList, String versionName) throws ApplicationManagementException; /** @@ -57,7 +57,7 @@ public interface SubscriptionManager { * @throws ApplicationManagementException Application Management Exception */ List installApplicationForRoles(String applicationUUID, - List roleList) + List roleList, String versionName) throws ApplicationManagementException; /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 3667e0953d..17fce50c57 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -52,59 +52,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager { public List installApplicationForDevices(String applicationUUID, String versionName, List deviceList) throws ApplicationManagementException { - - // 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 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 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; + return installApplication(applicationUUID, deviceList, versionName); } @Override - public List installApplicationForUsers(String applicationUUID, List userList) + public List installApplicationForUsers(String applicationUUID, List userList, String versionName) throws ApplicationManagementException { log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users."); List deviceList = new ArrayList<>(); for (String user : userList) { try { - List devicesOfUser = DataHolder.getInstance().getDeviceManagementService().getDevicesOfUser(user); + List devicesOfUser = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user); for (Device device : devicesOfUser) { deviceList.add(new DeviceIdentifier(device .getDeviceIdentifier(), device.getType())); @@ -113,17 +71,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error("Error when extracting the device list from user[" + user + "].", e); } } - return installApplication(applicationUUID, deviceList); + return installApplication(applicationUUID, deviceList, versionName); } @Override - public List installApplicationForRoles(String applicationUUID, List roleList) + public List installApplicationForRoles(String applicationUUID, List roleList, String versionName) throws ApplicationManagementException { log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " roles."); List deviceList = new ArrayList<>(); for (String role : roleList) { try { - List devicesOfRole = DataHolder.getInstance().getDeviceManagementService().getAllDevicesOfRole(role); + List devicesOfRole = HelperUtil.getDeviceManagementProviderService().getAllDevicesOfRole(role); for (Device device : devicesOfRole) { deviceList.add(new DeviceIdentifier(device .getDeviceIdentifier(), device.getType())); @@ -132,7 +90,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error("Error when extracting the device list from role[" + role + "].", e); } } - return installApplication(applicationUUID, deviceList); + return installApplication(applicationUUID, deviceList, versionName); } @Override @@ -142,32 +100,52 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return null; } - private List installApplication(String applicationUUID, List deviceList) + private List installApplication(String applicationUUID, List deviceList, String versionName) throws ApplicationManagementException { List failedDeviceList = new ArrayList<>(deviceList); - List 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) { 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."); + 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("Prepare application install to : " + device.getId()); + log.debug("Installing application to : " + device.getId()); } - activeDeviceList.add(deviceIdentifier); - DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false); + //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 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); } - } catch (DeviceManagementDAOException | SQLException e) { - throw new ApplicationManagementException("Error locating device.", e); - } finally { - DeviceManagementDAOFactory.closeConnection(); + } catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) { + log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e); } +// finally { +// DeviceManagementDAOFactory.closeConnection(); +// } } - //Todo: generating one time download link for the application and put install operation to devices. return failedDeviceList; } } From c0ffb0242056cfa6fcab9e5d4428a0dc2afe9913 Mon Sep 17 00:00:00 2001 From: amalhub Date: Tue, 10 Oct 2017 11:14:51 +0530 Subject: [PATCH 2/3] Code formatting --- .../mgt/core/impl/SubscriptionManagerImpl.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 17fce50c57..bfe7a13e2a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -56,8 +56,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public List installApplicationForUsers(String applicationUUID, List userList, String versionName) - throws ApplicationManagementException { + public List installApplicationForUsers(String applicationUUID, List userList, + String versionName) throws ApplicationManagementException { log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users."); List deviceList = new ArrayList<>(); for (String user : userList) { @@ -75,8 +75,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public List installApplicationForRoles(String applicationUUID, List roleList, String versionName) - throws ApplicationManagementException { + public List installApplicationForRoles(String applicationUUID, List roleList, + String versionName) throws ApplicationManagementException { log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " roles."); List deviceList = new ArrayList<>(); for (String role : roleList) { @@ -100,12 +100,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return null; } - private List installApplication(String applicationUUID, List deviceList, String versionName) - throws ApplicationManagementException { + private List installApplication(String applicationUUID, List deviceList, + String versionName) throws ApplicationManagementException { List 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."); + 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()); @@ -123,7 +124,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { 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 + "'}"); + operation.setPayLoad("{'type':'enterprise', 'url':'http://10.100.5.76:8000/app-debug.apk', 'app':'" + + applicationUUID + "'}"); List deviceIdentifiers = new ArrayList<>(); deviceIdentifiers.add(deviceIdentifier); dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, From 659713b59348bff41ba1fda1a990b02f425fcd2b Mon Sep 17 00:00:00 2001 From: amalhub Date: Tue, 10 Oct 2017 11:22:37 +0530 Subject: [PATCH 3/3] Code formatting --- .../application/mgt/core/impl/SubscriptionManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index bfe7a13e2a..0331630f34 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -47,6 +47,7 @@ import java.util.List; public class SubscriptionManagerImpl implements SubscriptionManager { private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class); + private static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; @Override public List installApplicationForDevices(String applicationUUID, String versionName, @@ -122,7 +123,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // put app install operation to the device ProfileOperation operation = new ProfileOperation(); - operation.setCode("INSTALL_APPLICATION"); + 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 + "'}");