From 7b8e68220fd7e828421516d75ce50deed2119823 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 23 May 2019 14:16:08 +0530 Subject: [PATCH] Add minor fixes in APP subscription flow --- .../core/impl/SubscriptionManagerImpl.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 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 0b97838dd2..c7c6c46a3d 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 @@ -129,9 +129,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { applicationInstallResponse.setActivity(activity); applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers); - int operationId = Integer - .parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]); - addDeviceSubscriptionForUser(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), +// int operationId = Integer +// .parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]); + int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); + addDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), operationTriggeredDeviceIds, new ArrayList<>(deviceSubscriptions.keySet()), null, operationId, SubsciptionType.DEVICE.toString()); return applicationInstallResponse; @@ -271,15 +272,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager { applicationInstallResponse.setActivity(activity); applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers); - int operationId = Integer - .parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]); - addDeviceSubscriptionForUser(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), +// int operationId = Integer +// .parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]); + int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); + + addDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), operationTriggeredDeviceIds, new ArrayList<>(deviceSubscriptions.keySet()), userList, operationId, SubsciptionType.USER.toString()); return applicationInstallResponse; } - private void addDeviceSubscriptionForUser(int applicationReleaseId, List deviceIds, - List subDeviceIds, List userList, int operationId, String subType) + private void addDeviceSubscriptions(int applicationReleaseId, List deviceIds, + List subDeviceIds, List subscribers, int operationId, String subType) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); @@ -289,13 +292,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List deviceSubscriptingIds; if (SubsciptionType.USER.toString().equals(subType)){ - List subscribedUsers = subscriptionDAO.getSubscribedUsernames(userList, tenantId); + List subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId); if (!subscribedUsers.isEmpty()) { subscriptionDAO .updateUserSubscription(tenantId, subscriber, false, subscribedUsers, applicationReleaseId); - userList.removeAll(subscribedUsers); + subscribers.removeAll(subscribedUsers); } - subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, userList, applicationReleaseId); + subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, subscribers, applicationReleaseId); } if (!subDeviceIds.isEmpty()) {