From 5a3d9c455a10bc76c60f30097dc5d9432e13ca89 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Mon, 28 Oct 2019 20:43:01 +0530 Subject: [PATCH] improve uninstall API for Google EMM APIs --- .../common/services/SubscriptionManager.java | 5 +++-- .../core/impl/SubscriptionManagerImpl.java | 20 +++++++++++-------- .../services/SubscriptionManagementAPI.java | 14 +++++++++++-- .../impl/SubscriptionManagementAPIImpl.java | 11 ++++++---- .../mgt/core/util/MDMIOSOperationUtil.java | 4 ++-- 5 files changed, 36 insertions(+), 18 deletions(-) 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 3c8a1d844ee..0382d33516d 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 @@ -92,13 +92,14 @@ public interface SubscriptionManager { * @param subType subscription type. E.g. DEVICE, USER, ROLE, GROUP {@see { * @param action subscription action. E.g. INSTALL/UNINSTALL {@see { * @param generic type of the method. + * @param requiresUpdatingExternal should an external server be updated. Such as Google EMM APIs * @return {@link ApplicationInstallResponse} * @throws ApplicationManagementException ApplicationManagementException if error occurs when subscribing to the * given application * @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}} */ - void performEntAppSubscription(String applicationUUID, List params, String subType, String action) - throws ApplicationManagementException; + void performEntAppSubscription(String applicationUUID, List params, String subType, String action, + boolean requiresUpdatingExternal) throws ApplicationManagementException; /*** * This method used to get the app id ,device ids and pass them to DM service method. 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 51409bef708..d5633471c2a 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 @@ -319,7 +319,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public void performEntAppSubscription(String applicationUUID, List params, String subType, String action) + public void performEntAppSubscription(String applicationUUID, List params, String subType, String action, + boolean requiresUpdatingExternal) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Google Ent app Install operation is received to application which has UUID " @@ -347,7 +348,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List categories = getApplicationCategories(applicationDTO.getId()); if (!categories.contains("GooglePlaySyncedApp")) { - String msg = "This is not google play store synced application. Hence can't perform enteprise app " + String msg = "This is not google play store synced application. Hence can't perform enterprise app " + "installation."; log.error(msg); throw new BadRequestException(msg); @@ -424,12 +425,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { }); } - //Installing the application - ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); - applicationPolicyDTO.setApplicationDTO(applicationDTO); - applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); - applicationPolicyDTO.setAction(action); - installEnrollmentApplications(applicationPolicyDTO); + if (requiresUpdatingExternal) { + //Installing the application + ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); + applicationPolicyDTO.setApplicationDTO(applicationDTO); + applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); + applicationPolicyDTO.setAction(action.toUpperCase()); + installEnrollmentApplications(applicationPolicyDTO); + } appSubscribingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); Map deviceSubscriptions = getDeviceSubscriptions(appSubscribingDeviceIds, @@ -972,6 +975,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Properties properties = new Properties(); properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, application.getPackageName()); app.setProperties(properties); return MDMIOSOperationUtil.createInstallAppOperation(app); } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java index 897154efc3e..f885d79c867 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java @@ -229,7 +229,12 @@ public interface SubscriptionManagementAPI { name = "timestamp", value = "Timestamp of scheduled ent. install operation" ) - @QueryParam("timestamp") String timestamp + @QueryParam("timestamp") String timestamp, + @ApiParam( + name = "requiresUpdatingExternal", + value = "Should external system such as Google EMM APIs need to be updated." + ) + @QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal ); @POST @@ -282,7 +287,12 @@ public interface SubscriptionManagementAPI { name = "timestamp", value = "Timestamp of scheduled ent app install operation" ) - @QueryParam("timestamp") String timestamp + @QueryParam("timestamp") String timestamp, + @ApiParam( + name = "requiresUpdatingExternal", + value = "Should external system such as Google EMM APIs need to be updated." + ) + @QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal ); @GET diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java index ba83ba655fa..56824c17c67 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java @@ -155,12 +155,14 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @PathParam("uuid") String uuid, @PathParam("action") String action, @Valid List deviceIdentifiers, - @QueryParam("timestamp") String timestamp) { + @QueryParam("timestamp") String timestamp, + @QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal) { try { if (StringUtils.isEmpty(timestamp)) { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); subscriptionManager - .performEntAppSubscription(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), action); + .performEntAppSubscription(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), + action, requiresUpdatingExternal); String msg = "Application release which has UUID " + uuid + " is installed to given valid device " + "identifiers."; return Response.status(Response.Status.OK).entity(msg).build(); @@ -200,11 +202,12 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @PathParam("subType") String subType, @PathParam("action") String action, @Valid List subscribers, - @QueryParam("timestamp") String timestamp) { + @QueryParam("timestamp") String timestamp, + @QueryParam("requiresUpdatingExternal") boolean requiresUpdatingExternal) { try { if (StringUtils.isEmpty(timestamp)) { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - subscriptionManager.performEntAppSubscription(uuid, subscribers, subType, action); + subscriptionManager.performEntAppSubscription(uuid, subscribers, subType, action, requiresUpdatingExternal); String msg = "Application release which has UUID " + uuid + " is installed to subscriber's valid device" + " identifiers."; return Response.status(Response.Status.OK).entity(msg).build(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java index d769cc6e64b..13538ccea88 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java @@ -67,8 +67,8 @@ public class MDMIOSOperationUtil { appStoreApplication.setPreventBackupOfAppData((Boolean) application.getProperties(). get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP)); appStoreApplication.setBundleId(application.getId()); - appStoreApplication.setiTunesStoreID((Integer) application.getProperties(). - get(MDMAppConstants.IOSConstants.I_TUNES_ID)); + appStoreApplication.setiTunesStoreID(Integer.parseInt(application.getProperties(). + get(MDMAppConstants.IOSConstants.I_TUNES_ID).toString())); operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_STORE_APPLICATION); operation.setType(Operation.Type.COMMAND); operation.setPayLoad(appStoreApplication.toJSON());