From 2757d96c33f761cb85a2f211df61af7c56c695ea Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 24 Oct 2019 19:24:55 +0530 Subject: [PATCH 1/4] Add new service to update APPM DB for enterprise install --- .../common/services/SubscriptionManager.java | 17 ++ .../core/impl/SubscriptionManagerImpl.java | 166 +++++++++++++++++- 2 files changed, 180 insertions(+), 3 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 b4b55e6edb..f5af8db02a 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 @@ -83,6 +83,23 @@ public interface SubscriptionManager { */ void updateScheduledSubscriptionStatus(int id, ExecutionStatus status) throws SubscriptionManagementException; + /** + * Perform google enterprise app install + * @param applicationUUID UUID of the application to subscribe/unsubscribe + * @param params list of subscribers. This list can be of either + * {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal + * to DEVICE or {@link String} if {@param subType} is USER, ROLE or GROUP + * @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. + * @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 performEntAppInstall(String applicationUUID, List params, String subType) + 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 9dc7a152db..3f5c6e34a2 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 @@ -38,6 +38,7 @@ import org.wso2.carbon.device.application.mgt.common.SubscriptionType; import org.wso2.carbon.device.application.mgt.common.SubscribingDeviceIdHolder; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationPolicyDTO; +import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; @@ -316,6 +317,166 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + @Override + public void performEntAppInstall(String applicationUUID, List params, String subType) + throws ApplicationManagementException { + if (log.isDebugEnabled()) { + log.debug("Google Ent app Install operation is received to application which has UUID " + + applicationUUID + " to perform on " + params.size() + " params."); + } + try { + if (params.isEmpty()) { + String msg = "In order to subscribe/unsubscribe application release, you should provide list of " + + "subscribers. But found an empty list of subscribers."; + log.error(msg); + throw new BadRequestException(msg); + } + + ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); + ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + int applicationReleaseId = applicationReleaseDTO.getId(); + if (!ApplicationType.PUBLIC.toString().equals(applicationDTO.getType())) { + String msg = "Application type is not public. Hence you can't perform google ent.install operation on " + + "this application. Application name " + applicationDTO.getName() + " Application Type " + + applicationDTO.getType(); + log.error(msg); + throw new BadRequestException(msg); + } + + DeviceManagementProviderService deviceManagementProviderService = HelperUtil + .getDeviceManagementProviderService(); + + List devices = new ArrayList<>(); + List subscribers = new ArrayList<>(); + List appInstallingDeviceIds; + List appReInstallingDeviceIds = new ArrayList<>(); + + //todo validate users, groups and roles + if (SubscriptionType.DEVICE.toString().equals(subType)) { + for (T param : params) { + DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param; + if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils + .isEmpty(deviceIdentifier.getType())) { + log.warn("Found a device identifier which has either empty identity of the device or empty" + + " device type. Hence ignoring the device identifier. "); + continue; + } + devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); + } + } else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { + for (T param : params) { + String username = (String) param; + subscribers.add(username); + devices.addAll(deviceManagementProviderService.getDevicesOfUser(username)); + } + } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { + for (T param : params) { + String roleName = (String) param; + subscribers.add(roleName); + devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName)); + } + } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { + GroupManagementProviderService groupManagementProviderService = HelperUtil + .getGroupManagementProviderService(); + for (T param : params) { + String groupName = (String) param; + subscribers.add(groupName); + devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName)); + } + } else { + String msg = "Found invalid subscription type " + subType+ " to install application release" ; + log.error(msg); + throw new BadRequestException(msg); + } + + appInstallingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); + Map deviceSubscriptions = getDeviceSubscriptions(appInstallingDeviceIds, + applicationReleaseId); + for (Map.Entry deviceSubscription: deviceSubscriptions.entrySet()){ + appReInstallingDeviceIds.add(deviceSubscription.getKey()); + appInstallingDeviceIds.remove(deviceSubscription.getKey()); + } + + updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds, + subscribers, subType); + } catch (DeviceManagementException e) { + String msg = "Error occurred while getting devices of given users or given roles."; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (GroupManagementException e) { + String msg = "Error occurred while getting devices of given groups"; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } + } + + /** + * This method is responsible to update subscription data for google enterprise install. + * + * @param applicationReleaseId Application release Id + * @param params subscribers. If subscription is performed via user, group or role, params is a list of + * {@link String} + * @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE + * @throws ApplicationManagementException if error occurred while getting or updating subscription data. + */ + private void updateSubscriptionsForEntInstall(int applicationReleaseId, List appInstallingDeviceIds, + List appReInstallingDeviceIds, List params, String subType) + throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + try { + ConnectionManagerUtil.beginDBTransaction(); + List subscribedEntities = new ArrayList<>(); + if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { + subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId); + } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { + subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId); + } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { + subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId); + } + + params.removeAll(subscribedEntities); + if (!params.isEmpty()) { + subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId); + } + if (!subscribedEntities.isEmpty()) { + subscriptionDAO + .updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, + SubAction.INSTALL.toString()); + } + + if (!appInstallingDeviceIds.isEmpty()) { + subscriptionDAO.addDeviceSubscription(username, appInstallingDeviceIds, subType, + Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId); + } + if (!appReInstallingDeviceIds.isEmpty()) { + subscriptionDAO + .updateDeviceSubscription(username, appReInstallingDeviceIds, SubAction.INSTALL.toString(), + subType, Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId); + } + ConnectionManagerUtil.commitDBTransaction(); + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = + "Error occurred when adding subscription data for application release ID: " + applicationReleaseId; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred when getting database connection to add new device subscriptions to application."; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "SQL Error occurred when adding new device subscription to application release which has ID: " + + applicationReleaseId; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + + /** * THis method is responsible to validate application install or uninstall request. * @@ -327,8 +488,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { */ private void validateRequest(List params, String subType, String action) throws BadRequestException { if (params.isEmpty()) { - String msg = "In order to install application release, you should provide list of subscribers. " - + "But found an empty list of users."; + String msg = "In order to subscribe/unsubscribe application release, you should provide list of " + + "subscribers. But found an empty list of subscribers."; log.error(msg); throw new BadRequestException(msg); } @@ -601,7 +762,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribingDeviceIdHolder.getAppReInstallableDevices())); subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subscribingDeviceIdHolder.getAppInstallableDevices())); - } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subscribingDeviceIdHolder.getAppInstalledDevices())); From 4989ac2d0cd0eb33b31a51bed5133f2cf97aa69f Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 25 Oct 2019 08:39:41 +0530 Subject: [PATCH 2/4] Add new API to perform ent. app installation --- .../core/impl/SubscriptionManagerImpl.java | 58 ++++++-- .../services/SubscriptionManagementAPI.java | 88 ++++++++++++ .../impl/SubscriptionManagementAPIImpl.java | 129 +++++++++++++++--- 3 files changed, 239 insertions(+), 36 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 3f5c6e34a2..ffe74120bb 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 @@ -175,7 +175,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { + if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !SubscriptionType.DEVICE + .toString().equals(subType)) { DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); deviceTypeName = deviceType.getName(); //filter devices by device type @@ -334,6 +335,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + //todo need to check application release status if it is not in installable state send forbidden exception int applicationReleaseId = applicationReleaseDTO.getId(); if (!ApplicationType.PUBLIC.toString().equals(applicationDTO.getType())) { String msg = "Application type is not public. Hence you can't perform google ent.install operation on " @@ -343,6 +345,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { throw new BadRequestException(msg); } + 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 " + + "installation."; + log.error(msg); + throw new BadRequestException(msg); + } + DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); @@ -350,9 +360,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List subscribers = new ArrayList<>(); List appInstallingDeviceIds; List appReInstallingDeviceIds = new ArrayList<>(); + List deviceIdentifiers = new ArrayList<>(); //todo validate users, groups and roles if (SubscriptionType.DEVICE.toString().equals(subType)) { + DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); for (T param : params) { DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param; if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils @@ -361,6 +373,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { + " device type. Hence ignoring the device identifier. "); continue; } + if (!deviceType.getName().equals(deviceIdentifier.getType())) { + log.warn("Found a device identifier which is not matched with the supported device type " + + "of the application release which has UUID " + applicationUUID + " Application " + + "supported device type is " + deviceType.getName() + " and the " + + "identifier of which has a different device type is " + deviceIdentifier.getId()); + continue; + } + deviceIdentifiers.add(deviceIdentifier); devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); } } else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { @@ -397,6 +417,28 @@ public class SubscriptionManagerImpl implements SubscriptionManager { appInstallingDeviceIds.remove(deviceSubscription.getKey()); } + /*If subscription type is not device we need to crete device identifiers object list by referring retrieved + list of devices.*/ + if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) { + DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); + String deviceTypeName = deviceType.getName(); + //filter devices by device type + devices.removeIf(device -> !deviceTypeName.equals(device.getType())); + devices.forEach(device -> { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + deviceIdentifiers.add(deviceIdentifier); + }); + } + + //Installing the application + ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); + applicationPolicyDTO.setApplicationDTO(applicationDTO); + applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); + applicationPolicyDTO.setAction(SubAction.INSTALL.toString()); + installEnrollmentApplications(applicationPolicyDTO); + updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds, subscribers, subType); } catch (DeviceManagementException e) { @@ -569,18 +611,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { entry.getKey(), action); activityList.add(activity); } - } else if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) { - List categories = getApplicationCategories(applicationDTO.getId()); - if (categories.contains("GooglePlaySyncedApp")) { - ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); - applicationPolicyDTO.setApplicationDTO(applicationDTO); - applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); - applicationPolicyDTO.setAction(action); - installEnrollmentApplications(applicationPolicyDTO); - } else { - Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); - activityList.add(activity); - } } else { Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); activityList.add(activity); @@ -982,7 +1012,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { String payload = gson.toJson(applicationPolicyDTO); StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON - , Constants.ApplicationInstall.ENCODING);; + , Constants.ApplicationInstall.ENCODING); httpClient = new HttpClient(); request = new PostMethod(requestUrl); request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION 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 95edf14420..6d60abc4f7 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 @@ -185,6 +185,94 @@ public interface SubscriptionManagementAPI { @QueryParam("timestamp") String timestamp ); + @POST + @Path("/{uuid}/devices/ent-app-install") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Install an application for devices via google enterprise app installing service", + notes = "This will install an application to a given list of devices", + tags = "Subscription Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install") + }) + } + ) + @ApiResponses( + value = { + + }) + Response performEntAppInstallationOnDevices( + @ApiParam( + name = "UUID", + value = "The application UUID", + required = true + ) + @PathParam("uuid") String uuid, + @ApiParam( + name = "installationDetails", + value = "The list of device identifiers", + required = true + ) + @Valid List deviceIdentifiers, + @ApiParam( + name = "timestamp", + value = "Timestamp of scheduled ent. install operation" + ) + @QueryParam("timestamp") String timestamp + ); + + @POST + @Path("/{uuid}/{subType}/ent-app-install") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Install an application for subscription type via google enterprise install.", + notes = "This will install an application to a given subscription type and this is bulk app installation.", + tags = "Subscription Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install") + }) + } + ) + @ApiResponses( + value = { + + }) + Response performBulkEntAppInstallation( + @ApiParam( + name = "uuid", + value = "The application release UUID", + required = true + ) + @PathParam("uuid") String uuid, + @ApiParam( + name = "subType", + value = "Subscription type of the app installing operation.", + required = true + ) + @PathParam("subType") String subType, + @ApiParam( + name = "subscribers", + value = "Subscriber list of the application release.", + required = true + ) + @Valid List subscribers, + @ApiParam( + name = "timestamp", + value = "Timestamp of scheduled ent app install operation" + ) + @QueryParam("timestamp") String timestamp + ); + @GET @Path("/{uuid}/devices") @Produces(MediaType.APPLICATION_JSON) 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 62af127d18..8eaae60374 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 @@ -89,13 +89,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for installing application which has UUID: " + uuid - + ". Hence verify the payload"; + String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify " + + "the payload"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { - String msg = "Application release is not in the installable state. Hence you are not permitted to install " - + "the application."; + String msg = "Application release is not in the installable state. Hence you are not permitted to perform " + + "the action on the application."; log.error(msg, e); return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -132,13 +132,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for installing application which has UUID: " + uuid - + ". Hence verify the payload"; + String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify " + + "the payload"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { - String msg = "Application release is not in the installable state. Hence you are not permitted to install " - + "the application."; + String msg = "Application release is not in the installable state. Hence you are not permitted to perform " + + "the action on the application."; log.error(msg, e); return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -149,6 +149,91 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ } } + @Override + @POST + @Path("/{uuid}/devices/ent-app-install") + public Response performEntAppInstallationOnDevices( + @PathParam("uuid") String uuid, + @Valid List deviceIdentifiers, + @QueryParam("timestamp") String timestamp) { + try { + if (StringUtils.isEmpty(timestamp)) { + SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); + subscriptionManager + .performEntAppInstall(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString()); + String msg = "Application release which has UUID " + uuid + " is installed to given valid device " + + "identifiers."; + return Response.status(Response.Status.OK).entity(msg).build(); + } else { + return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE, + SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp); + } + } catch (NotFoundException e) { + String msg = "Couldn't found an application release for UUI: " + uuid + " to perform ent app installation " + + "on subscriber's devices"; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (BadRequestException e) { + String msg = "Found invalid payload when performing ent app installation on application which has UUID: " + + uuid + ". Hence verify the payload of the request."; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } catch (ForbiddenException e) { + String msg = "Application release is not in the installable state. Hence you are not permitted to install " + + "the application."; + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = + "Error occurred while performing ent app installation on the application release which has UUID: " + + uuid + " for devices"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @Override + @POST + @Path("/{uuid}/{subType}/ent-app-install") + public Response performBulkEntAppInstallation( + @PathParam("uuid") String uuid, + @PathParam("subType") String subType, + @Valid List subscribers, + @QueryParam("timestamp") String timestamp) { + try { + if (StringUtils.isEmpty(timestamp)) { + SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); + subscriptionManager.performEntAppInstall(uuid, subscribers, subType); + 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(); + } else { + return scheduleApplicationOperationTask(uuid, subscribers, + SubscriptionType.valueOf(subType.toUpperCase()), + SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp); + } + } catch (NotFoundException e) { + String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (BadRequestException e) { + String msg = "Found invalid payload when performing ent app installation on application which has UUID: " + + uuid + ". Hence verify the payload of the request."; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } catch (ForbiddenException e) { + String msg = "Application release is not in the installable state. Hence you are not permitted to install " + + "the application."; + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while performing ent app installation on the application release which has " + + "UUID: " + uuid + " for user devices"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + /** * Schedule the application subscription for the given timestamp * @@ -183,13 +268,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Consumes("application/json") @Produces("application/json") @Path("/{uuid}/devices") - public Response getAppInstalledDevices(@PathParam("uuid") String uuid, - @DefaultValue("0") - @QueryParam("offset") int offset, - @DefaultValue("5") - @QueryParam("limit") int limit, - @QueryParam("status") String status) { - + public Response getAppInstalledDevices( + @PathParam("uuid") String uuid, + @DefaultValue("0") + @QueryParam("offset") int offset, + @DefaultValue("5") + @QueryParam("limit") int limit, + @QueryParam("status") String status) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); @@ -228,13 +313,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Consumes("application/json") @Produces("application/json") @Path("/{uuid}/{subType}") - public Response getAppInstalledCategories(@PathParam("uuid") String uuid, - @PathParam("subType") String subType, - @DefaultValue("0") - @QueryParam("offset") int offset, - @DefaultValue("5") - @QueryParam("limit") int limit) { - + public Response getAppInstalledCategories( + @PathParam("uuid") String uuid, + @PathParam("subType") String subType, + @DefaultValue("0") + @QueryParam("offset") int offset, + @DefaultValue("5") + @QueryParam("limit") int limit) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); From 7eb3a5d762fe41c3e865b5605651c15bf0bc1001 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sat, 26 Oct 2019 03:01:02 +0530 Subject: [PATCH 3/4] Fix issues in APPM subscription flow --- .../mgt/common/SubscribingDeviceIdHolder.java | 9 ++ .../common/services/SubscriptionManager.java | 18 +-- .../mgt/core/dao/SubscriptionDAO.java | 11 +- .../GenericSubscriptionDAOImpl.java | 44 +++--- .../SQLServerSubscriptionDAOImpl.java | 54 ------- .../mgt/core/impl/ApplicationManagerImpl.java | 2 +- .../core/impl/SubscriptionManagerImpl.java | 147 +++++++++--------- ...ApplicationManagementPublisherAPIImpl.java | 2 +- .../services/SubscriptionManagementAPI.java | 20 ++- .../admin/SubscriptionManagementAdminAPI.java | 2 +- .../impl/SubscriptionManagementAPIImpl.java | 21 ++- 11 files changed, 149 insertions(+), 181 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java index eb92f07bc0..0dd283b3fe 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java @@ -26,6 +26,7 @@ public class SubscribingDeviceIdHolder { private Map appInstalledDevices = new HashMap<>(); private Map appInstallableDevices = new HashMap<>(); private Map appReInstallableDevices = new HashMap<>(); + private Map appReUnInstallableDevices = new HashMap<>(); private Map skippedDevices = new HashMap<>(); public Map getAppInstalledDevices() { @@ -57,4 +58,12 @@ public class SubscribingDeviceIdHolder { public void setSkippedDevices(Map skippedDevices) { this.skippedDevices = skippedDevices; } + + public Map getAppReUnInstallableDevices() { + return appReUnInstallableDevices; + } + + public void setAppReUnInstallableDevices(Map appReUnInstallableDevices) { + this.appReUnInstallableDevices = appReUnInstallableDevices; + } } 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 f5af8db02a..3c8a1d844e 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 @@ -85,19 +85,19 @@ public interface SubscriptionManager { /** * Perform google enterprise app install - * @param applicationUUID UUID of the application to subscribe/unsubscribe + * @param applicationUUID UUID of the application to subscribe/unsubscribe * @param params list of subscribers. This list can be of either * {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal * to DEVICE or {@link String} if {@param subType} is USER, ROLE or GROUP * @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. - * @return {@link ApplicationInstallResponse} - * @throws ApplicationManagementException ApplicationManagementException if error occurs when subscribing to the - * given application - * @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}} + * @param action subscription action. E.g. INSTALL/UNINSTALL {@see { + * @param generic type of the method. + * @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 performEntAppInstall(String applicationUUID, List params, String subType) + void performEntAppSubscription(String applicationUUID, List params, String subType, String action) throws ApplicationManagementException; /*** @@ -123,7 +123,7 @@ public interface SubscriptionManager { * @return {@link PaginationResult} pagination result of the category details. * @throws {@link ApplicationManagementException} Exception of the application management */ - PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, String appUUID, + PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType) 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/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 33fafe57db..5b7f9a00cb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -33,7 +33,7 @@ import java.util.Map; */ public interface SubscriptionDAO { - List addDeviceSubscription(String subscribedBy, List deviceIds, String subscribedFrom, + void addDeviceSubscription(String subscribedBy, List deviceIds, String subscribedFrom, String installStatus, int releaseId, int tenantId ) throws ApplicationManagementDAOException; void updateDeviceSubscription(String updateBy, List deviceIds, String action, String actionTriggeredFrom, @@ -66,13 +66,13 @@ public interface SubscriptionDAO { Map getDeviceSubscriptions(List deviceIds, int appReleaseId, int tenantId) throws ApplicationManagementDAOException; - List getSubscribedUserNames(List users, int tenantId) throws + List getAppSubscribedUserNames(List users, int appReleaseId, int tenantId) throws ApplicationManagementDAOException; - List getSubscribedRoleNames(List roles, int tenantId) throws + List getAppSubscribedRoleNames(List roles, int appReleaseId, int tenantId) throws ApplicationManagementDAOException; - List getSubscribedGroupNames(List groups, int tenantId) throws + List getAppSubscribedGroupNames(List groups, int appReleaseId, int tenantId) throws ApplicationManagementDAOException; void updateSubscriptions(int tenantId, String updateBy, List paramList, @@ -81,7 +81,8 @@ public interface SubscriptionDAO { List getDeviceSubIds(List deviceIds, int applicationReleaseId, int tenantId) throws ApplicationManagementDAOException; - List getDeviceSubIdsForOperation (int operationId, int tenantId) throws ApplicationManagementDAOException; + List getDeviceSubIdsForOperation(int operationId, int deviceID, int tenantId) + throws ApplicationManagementDAOException; boolean updateDeviceSubStatus(int deviceId, List deviceSubIds, String status, int tenantcId) throws ApplicationManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 444445a288..46621cb9d4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -49,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc private static Log log = LogFactory.getLog(GenericSubscriptionDAOImpl.class); @Override - public List addDeviceSubscription(String subscribedBy, List deviceIds, + public void addDeviceSubscription(String subscribedBy, List deviceIds, String subscribedFrom, String installStatus, int releaseId, int tenantId) throws ApplicationManagementDAOException { String sql = "INSERT INTO " @@ -82,13 +82,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } stmt.executeBatch(); - try (ResultSet rs = stmt.getGeneratedKeys()) { - List deviceSubIds = new ArrayList<>(); - while (rs.next()) { - deviceSubIds.add(rs.getInt(1)); - } - return deviceSubIds; - } } } catch (DBConnectionException e) { String msg = "Error occured while obtaining database connection to add device subscription for application " @@ -425,8 +418,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } - @Override - public List getSubscribedUserNames(List users, int tenantId) + public List getAppSubscribedUserNames(List users, int appReleaseId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get already subscribed users for given list of user names."); @@ -438,13 +430,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc StringJoiner joiner = new StringJoiner(",", "SELECT US.USER_NAME AS USER_NAME " + "FROM AP_USER_SUBSCRIPTION US " - + "WHERE US.USER_NAME IN (", ") AND TENANT_ID = ?"); + + "WHERE US.USER_NAME IN (", ") AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"); users.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { for (String username : users) { ps.setObject(index++, username); } + ps.setInt(index++, appReleaseId); ps.setInt(index, tenantId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -465,8 +458,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } - @Override - public List getSubscribedRoleNames(List roles, int tenantId) + public List getAppSubscribedRoleNames(List roles, int appReleaseId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get already subscribed role names for given list of roles."); @@ -478,13 +470,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc StringJoiner joiner = new StringJoiner(",", "SELECT RS.ROLE_NAME AS ROLE " + "FROM AP_ROLE_SUBSCRIPTION RS " - + "WHERE RS.ROLE_NAME IN (", ") AND TENANT_ID = ?"); + + "WHERE RS.ROLE_NAME IN (", ") AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"); roles.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { for (String roleName : roles) { ps.setObject(index++, roleName); } + ps.setInt(index++, appReleaseId); ps.setInt(index, tenantId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -506,7 +499,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getSubscribedGroupNames(List groups, int tenantId) + public List getAppSubscribedGroupNames(List groups, int appReleaseId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get already subscribed groups for given list of groups."); @@ -518,13 +511,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc StringJoiner joiner = new StringJoiner(",", "SELECT GS.GROUP_NAME AS GROUP_NAME " + "FROM AP_GROUP_SUBSCRIPTION GS " - + "WHERE GS.GROUP_NAME IN (", ") AND TENANT_ID = ?"); + + "WHERE GS.GROUP_NAME IN (", ") AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"); groups.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { for (String groupName : groups) { ps.setObject(index++, groupName); } + ps.setInt(index++, appReleaseId); ps.setInt(index, tenantId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -647,20 +641,22 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getDeviceSubIdsForOperation(int operationId, int tenantId) + public List getDeviceSubIdsForOperation(int operationId, int deviceId, int tenantId) throws ApplicationManagementDAOException { try { Connection conn = this.getDBConnection(); List deviceSubIds = new ArrayList<>(); - String sql = "SELECT " - + "AP_DEVICE_SUBSCRIPTION_ID " - + "FROM AP_APP_SUB_OP_MAPPING " - + "WHERE " - + "OPERATION_ID = ? AND " - + "TENANT_ID = ?"; + String sql = "SELECT AP_APP_SUB_OP_MAPPING.AP_DEVICE_SUBSCRIPTION_ID " + + "FROM " + + "AP_APP_SUB_OP_MAPPING INNER JOIN AP_DEVICE_SUBSCRIPTION " + + "ON AP_APP_SUB_OP_MAPPING.AP_DEVICE_SUBSCRIPTION_ID = AP_DEVICE_SUBSCRIPTION.ID " + + "WHERE AP_APP_SUB_OP_MAPPING.OPERATION_ID = ? AND " + + "AP_DEVICE_SUBSCRIPTION.DM_DEVICE_ID = ? AND " + + "AP_APP_SUB_OP_MAPPING.TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, operationId); - stmt.setInt(2, tenantId); + stmt.setInt(2, deviceId); + stmt.setInt(3, tenantId); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { deviceSubIds.add(rs.getInt("AP_DEVICE_SUBSCRIPTION_ID")); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java index 2c725dde07..26a498af1b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java @@ -159,58 +159,4 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { throw new ApplicationManagementDAOException(msg, e); } } - - @Override - public List addDeviceSubscription(String subscribedBy, List deviceIds, - String subscribedFrom, String installStatus, int releaseId, int tenantId) - throws ApplicationManagementDAOException { - String sql = "INSERT INTO " - + "AP_DEVICE_SUBSCRIPTION(" - + "SUBSCRIBED_BY, " - + "SUBSCRIBED_TIMESTAMP, " - + "ACTION_TRIGGERED_FROM, " - + "STATUS, " - + "DM_DEVICE_ID, " - + "AP_APP_RELEASE_ID," - + "TENANT_ID) " - + "VALUES (?, ?, ?, ?, ?, ?, ?)"; - try { - Connection conn = this.getDBConnection(); - try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { - Calendar calendar = Calendar.getInstance(); - Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); - List deviceSubIds = new ArrayList<>(); - for (Integer deviceId : deviceIds) { - stmt.setString(1, subscribedBy); - stmt.setTimestamp(2, timestamp); - stmt.setString(3, subscribedFrom); - stmt.setString(4, installStatus); - stmt.setInt(5, deviceId); - stmt.setInt(6, releaseId); - stmt.setInt(7, tenantId); - if (log.isDebugEnabled()) { - log.debug("Adding a device subscription for device id " + deviceId + " and application " - + "release which has release id" + releaseId); - } - stmt.executeUpdate(); - try (ResultSet rs = stmt.getGeneratedKeys()) { - if (rs.next()) { - deviceSubIds.add(rs.getInt(1)); - } - } - } - return deviceSubIds; - } - } catch (DBConnectionException e) { - String msg = "Error occured while obtaining database connection to add device subscription for application " - + "release which has release Id" + releaseId; - log.error(msg, e); - throw new ApplicationManagementDAOException(msg, e); - } catch (SQLException e) { - String msg = "Error occured when processing SQL to add device subscription for application release which" - + " has release Id " + releaseId; - log.error(msg, e); - throw new ApplicationManagementDAOException(msg, e); - } - } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index b7f63a1f79..a937169b83 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -3163,7 +3163,7 @@ public class ApplicationManagerImpl implements ApplicationManager { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { ConnectionManagerUtil.beginDBTransaction(); - List deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, tenantId); + List deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId); if (deviceSubIds.isEmpty()){ ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Couldn't find device subscription for operation id " + operationId; 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 ffe74120bb..51409bef70 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,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public void performEntAppInstall(String applicationUUID, List params, String subType) + public void performEntAppSubscription(String applicationUUID, List params, String subType, String action) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Google Ent app Install operation is received to application which has UUID " @@ -358,8 +358,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List devices = new ArrayList<>(); List subscribers = new ArrayList<>(); - List appInstallingDeviceIds; - List appReInstallingDeviceIds = new ArrayList<>(); + List appSubscribingDeviceIds; + List appReSubscribingDeviceIds = new ArrayList<>(); List deviceIdentifiers = new ArrayList<>(); //todo validate users, groups and roles @@ -409,14 +409,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { throw new BadRequestException(msg); } - appInstallingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); - Map deviceSubscriptions = getDeviceSubscriptions(appInstallingDeviceIds, - applicationReleaseId); - for (Map.Entry deviceSubscription: deviceSubscriptions.entrySet()){ - appReInstallingDeviceIds.add(deviceSubscription.getKey()); - appInstallingDeviceIds.remove(deviceSubscription.getKey()); - } - /*If subscription type is not device we need to crete device identifiers object list by referring retrieved list of devices.*/ if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) { @@ -436,11 +428,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); applicationPolicyDTO.setApplicationDTO(applicationDTO); applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); - applicationPolicyDTO.setAction(SubAction.INSTALL.toString()); + applicationPolicyDTO.setAction(action); installEnrollmentApplications(applicationPolicyDTO); - updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds, - subscribers, subType); + appSubscribingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); + Map deviceSubscriptions = getDeviceSubscriptions(appSubscribingDeviceIds, + applicationReleaseId); + for (Map.Entry deviceSubscription: deviceSubscriptions.entrySet()){ + appReSubscribingDeviceIds.add(deviceSubscription.getKey()); + appSubscribingDeviceIds.remove(deviceSubscription.getKey()); + } + + updateSubscriptionsForEntInstall(applicationReleaseId, appSubscribingDeviceIds, appReSubscribingDeviceIds, + subscribers, subType, action); } catch (DeviceManagementException e) { String msg = "Error occurred while getting devices of given users or given roles."; log.error(msg, e); @@ -459,10 +459,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { * @param params subscribers. If subscription is performed via user, group or role, params is a list of * {@link String} * @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE + * @param action Performing action. (i.e INSTALL or UNINSTALL) * @throws ApplicationManagementException if error occurred while getting or updating subscription data. */ - private void updateSubscriptionsForEntInstall(int applicationReleaseId, List appInstallingDeviceIds, - List appReInstallingDeviceIds, List params, String subType) + private void updateSubscriptionsForEntInstall(int applicationReleaseId, List appSubscribingDeviceIds, + List appReSubscribingDeviceIds, List params, String subType, String action) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); @@ -470,11 +471,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.beginDBTransaction(); List subscribedEntities = new ArrayList<>(); if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { - subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId); + subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId); } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { - subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId); + subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId); } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { - subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId); + subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId); } params.removeAll(subscribedEntities); @@ -484,17 +485,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (!subscribedEntities.isEmpty()) { subscriptionDAO .updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, - SubAction.INSTALL.toString()); + action); } - if (!appInstallingDeviceIds.isEmpty()) { - subscriptionDAO.addDeviceSubscription(username, appInstallingDeviceIds, subType, + if (SubAction.INSTALL.toString().equalsIgnoreCase(action) && !appSubscribingDeviceIds.isEmpty()) { + subscriptionDAO.addDeviceSubscription(username, appSubscribingDeviceIds, subType, Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId); } - if (!appReInstallingDeviceIds.isEmpty()) { - subscriptionDAO - .updateDeviceSubscription(username, appReInstallingDeviceIds, SubAction.INSTALL.toString(), - subType, Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId); + if (!appReSubscribingDeviceIds.isEmpty()) { + subscriptionDAO.updateDeviceSubscription(username, appReSubscribingDeviceIds, action, subType, + Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId); } ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { @@ -578,10 +578,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet())); - ignoredDeviceIdentifiers - .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); + deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); + deviceIdentifiers + .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet())); ignoredDeviceIdentifiers .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); } @@ -636,10 +637,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { */ private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List devices, int appReleaseId) throws ApplicationManagementException { - Map appInstalledDevices = new HashMap<>(); - Map appInstallableDevices = new HashMap<>(); - Map appReInstallableDevices = new HashMap<>(); - Map skippedDevices = new HashMap<>(); + + SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder(); + subscribingDeviceIdHolder.setAppInstallableDevices(new HashMap<>()); + subscribingDeviceIdHolder.setAppInstalledDevices(new HashMap<>()); + subscribingDeviceIdHolder.setAppReInstallableDevices(new HashMap<>()); + subscribingDeviceIdHolder.setAppReUnInstallableDevices(new HashMap<>()); + subscribingDeviceIdHolder.setSkippedDevices(new HashMap<>()); List deviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); //get device subscriptions for given device id list. @@ -650,23 +654,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (deviceSubscriptionDTO != null) { if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString() .equals(deviceSubscriptionDTO.getStatus())) { - appInstalledDevices.put(deviceIdentifier, device.getId()); + subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId()); + } else if (deviceSubscriptionDTO.isUnsubscribed() && !Operation.Status.COMPLETED.toString() + .equals(deviceSubscriptionDTO.getStatus())) { + subscribingDeviceIdHolder.getAppReUnInstallableDevices().put(deviceIdentifier, device.getId()); } else if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus()) || Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) { - skippedDevices.put(deviceIdentifier, device.getId()); + subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId()); } else { - appReInstallableDevices.put(deviceIdentifier, device.getId()); + subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId()); } } else { - appInstallableDevices.put(deviceIdentifier, device.getId()); + subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId()); } } - - SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder(); - subscribingDeviceIdHolder.setAppInstallableDevices(appInstallableDevices); - subscribingDeviceIdHolder.setAppInstalledDevices(appInstalledDevices); - subscribingDeviceIdHolder.setAppReInstallableDevices(appReInstallableDevices); - subscribingDeviceIdHolder.setSkippedDevices(skippedDevices); return subscribingDeviceIdHolder; } @@ -756,7 +757,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { try { ConnectionManagerUtil.beginDBTransaction(); if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { - List subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId); + List subscribedEntities = subscriptionDAO + .getAppSubscribedUserNames(params, applicationReleaseId, tenantId); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { params.removeAll(subscribedEntities); subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId); @@ -764,7 +766,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, action); } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { - List subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId); + List subscribedEntities = subscriptionDAO + .getAppSubscribedRoleNames(params, applicationReleaseId, tenantId); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { params.removeAll(subscribedEntities); subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId); @@ -772,7 +775,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, action); } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { - List subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId); + List subscribedEntities = subscriptionDAO + .getAppSubscribedGroupNames(params, applicationReleaseId, tenantId); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { params.removeAll(subscribedEntities); subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId); @@ -785,11 +789,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager { int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); List subUpdatingDeviceIds = new ArrayList<>(); List subInsertingDeviceIds = new ArrayList<>(); - List deviceSubIds = new ArrayList<>(); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subscribingDeviceIdHolder.getAppReInstallableDevices())); + subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, + subscribingDeviceIdHolder.getAppInstalledDevices())); subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subscribingDeviceIdHolder.getAppInstallableDevices())); } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { @@ -797,19 +802,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager { subscribingDeviceIdHolder.getAppInstalledDevices())); } - List subscribingDevices = subscriptionDAO - .addDeviceSubscription(username, subInsertingDeviceIds, subType, + subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType, Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); - subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType, - Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); - if (!subUpdatingDeviceIds.isEmpty()) { - deviceSubIds.addAll(subscriptionDAO - .getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId)); + subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType, + Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); + } + subUpdatingDeviceIds.addAll(subInsertingDeviceIds); + if (!subUpdatingDeviceIds.isEmpty()) { + List deviceSubIds = new ArrayList<>( + subscriptionDAO.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId)); + subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId); } - deviceSubIds.addAll(subscribingDevices); - - subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId); } ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { @@ -1059,14 +1063,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List deviceSubscriptionDTOS = subscriptionDAO .getDeviceSubscriptions(applicationReleaseId, tenantId); if (deviceSubscriptionDTOS.isEmpty()) { - String msg = "Couldn't found an subscribed devices for application release id: " - + applicationReleaseId; - log.info(msg); + PaginationResult paginationResult = new PaginationResult(); + paginationResult.setData(new ArrayList<>()); + paginationResult.setRecordsFiltered(0); + paginationResult.setRecordsTotal(0); + return paginationResult; } List deviceIdList = new ArrayList<>(); - for (DeviceSubscriptionDTO deviceIds : deviceSubscriptionDTOS) { - deviceIdList.add(deviceIds.getDeviceId()); - } + deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> { + if ((!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString() + .equalsIgnoreCase(deviceSubscriptionDTO.getStatus())) || (deviceSubscriptionDTO.isUnsubscribed() + && !Operation.Status.COMPLETED.toString() + .equalsIgnoreCase(deviceSubscriptionDTO.getStatus()))) { + deviceIdList.add(deviceSubscriptionDTO.getDeviceId()); + } + }); if (deviceIdList.isEmpty()){ PaginationResult paginationResult = new PaginationResult(); @@ -1109,7 +1120,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, String appUUID, String subType) + public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -1178,18 +1189,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List deviceSubscriptionDTOS = subscriptionDAO .getDeviceSubscriptions(applicationReleaseId, tenantId); if (deviceSubscriptionDTOS.isEmpty()) { - String msg = "Couldn't found an subscribed devices for application release id: " + applicationReleaseId; - log.info(msg); - } - List deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId) - .collect(Collectors.toList()); - if (deviceIdList.isEmpty()) { PaginationResult paginationResult = new PaginationResult(); - paginationResult.setData(deviceIdList); + paginationResult.setData(new ArrayList<>()); paginationResult.setRecordsFiltered(0); paginationResult.setRecordsTotal(0); return paginationResult; } + List deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId) + .collect(Collectors.toList()); try { //pass the device id list to device manager service method PaginationResult paginationResult = deviceManagementProviderService diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 5e0e765239..ae864cb52e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -954,7 +954,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg); throw new BadRequestException(msg); } - applicationArtifact.setInstallerName(installerFileName); + applicationArtifact.setInstallerName(installerFileName.replaceAll("\\s", "")); applicationArtifact.setInstallerStream(installerStream); } 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 6d60abc4f7..897154efc3 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 @@ -186,7 +186,7 @@ public interface SubscriptionManagementAPI { ); @POST - @Path("/{uuid}/devices/ent-app-install") + @Path("/{uuid}/devices/ent-app-install/{action}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -206,13 +206,19 @@ public interface SubscriptionManagementAPI { value = { }) - Response performEntAppInstallationOnDevices( + Response performEntAppSubscriptionOnDevices( @ApiParam( name = "UUID", value = "The application UUID", required = true ) @PathParam("uuid") String uuid, + @ApiParam( + name = "action", + value = "Performing action.", + required = true + ) + @PathParam("action") String action, @ApiParam( name = "installationDetails", value = "The list of device identifiers", @@ -227,7 +233,7 @@ public interface SubscriptionManagementAPI { ); @POST - @Path("/{uuid}/{subType}/ent-app-install") + @Path("/{uuid}/{subType}/ent-app-install/{action}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -247,7 +253,7 @@ public interface SubscriptionManagementAPI { value = { }) - Response performBulkEntAppInstallation( + Response performBulkEntAppSubscription( @ApiParam( name = "uuid", value = "The application release UUID", @@ -260,6 +266,12 @@ public interface SubscriptionManagementAPI { required = true ) @PathParam("subType") String subType, + @ApiParam( + name = "action", + value = "Performing action.", + required = true + ) + @PathParam("action") String action, @ApiParam( name = "subscribers", value = "Subscriber list of the application release.", 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/admin/SubscriptionManagementAdminAPI.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/admin/SubscriptionManagementAdminAPI.java index 904e6acdd6..7fb357e4fe 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/admin/SubscriptionManagementAdminAPI.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/admin/SubscriptionManagementAdminAPI.java @@ -92,7 +92,7 @@ public interface SubscriptionManagementAdminAPI { tags = "Subscription Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:view") + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:subscription:view") }) } ) 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 8eaae60374..ba83ba655f 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 @@ -106,7 +106,6 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ } } - @Override @POST @Path("/{uuid}/{subType}/{action}") @@ -151,16 +150,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Override @POST - @Path("/{uuid}/devices/ent-app-install") - public Response performEntAppInstallationOnDevices( + @Path("/{uuid}/devices/ent-app-install/{action}") + public Response performEntAppSubscriptionOnDevices( @PathParam("uuid") String uuid, + @PathParam("action") String action, @Valid List deviceIdentifiers, @QueryParam("timestamp") String timestamp) { try { if (StringUtils.isEmpty(timestamp)) { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); subscriptionManager - .performEntAppInstall(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString()); + .performEntAppSubscription(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), action); String msg = "Application release which has UUID " + uuid + " is installed to given valid device " + "identifiers."; return Response.status(Response.Status.OK).entity(msg).build(); @@ -194,16 +194,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Override @POST - @Path("/{uuid}/{subType}/ent-app-install") - public Response performBulkEntAppInstallation( + @Path("/{uuid}/{subType}/ent-app-install/{action}") + public Response performBulkEntAppSubscription( @PathParam("uuid") String uuid, @PathParam("subType") String subType, + @PathParam("action") String action, @Valid List subscribers, @QueryParam("timestamp") String timestamp) { try { if (StringUtils.isEmpty(timestamp)) { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - subscriptionManager.performEntAppInstall(uuid, subscribers, subType); + subscriptionManager.performEntAppSubscription(uuid, subscribers, subType, action); 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(); @@ -277,15 +278,11 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @QueryParam("status") String status) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - PaginationResult subscribedDeviceDetails = subscriptionManager .getAppInstalledDevices(offset, limit, uuid, status); - DeviceList devices = new DeviceList(); - devices.setList((List) subscribedDeviceDetails.getData()); devices.setCount(subscribedDeviceDetails.getRecordsTotal()); - return Response.status(Response.Status.OK).entity(devices).build(); } catch (NotFoundException e) { String msg = "Application with application release UUID: " + uuid + " is not found"; @@ -324,7 +321,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); PaginationResult subscribedCategoryDetails = subscriptionManager - .getAppInstalledCategories(offset, limit, uuid, subType); + .getAppInstalledSubscribers(offset, limit, uuid, subType); if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { BasicUserInfoList users = new BasicUserInfoList(); From 1e3ac362b8f3adbbbb1aa6227cfa282f4f6e1300 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sat, 26 Oct 2019 08:06:20 +0530 Subject: [PATCH 4/4] Remove super admin tenant domain from /user API response --- .../java/io/entgra/ui/request/interceptor/UserHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java index 81041d9e9c..6f59f28fe8 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java @@ -103,7 +103,8 @@ public class UserHandler extends HttpServlet { } ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setCode(HttpStatus.SC_OK); - proxyResponse.setData(jTokenResultAsJsonObject.get("username").getAsString()); + proxyResponse.setData( + jTokenResultAsJsonObject.get("username").getAsString().replaceAll("@carbon.super", "")); HandlerUtil.handleSuccess(req, resp, serverUrl, platform, proxyResponse); } } catch (IOException e) {