From f1c783cdb9ddf3fce497bd0b52214a48f6b88210 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 31 May 2019 12:59:27 +0530 Subject: [PATCH] Improve APPm sub storing method --- .../mgt/common/SubscribingDeviceIdHolder.java | 16 ++++----- .../core/impl/SubscriptionManagerImpl.java | 36 +++++++++++-------- 2 files changed, 29 insertions(+), 23 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 82e87c8b680..ac7dc9de7cd 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,7 +26,7 @@ import java.util.Map; public class SubscribingDeviceIdHolder { private Map subscribedDevices = new HashMap<>(); private Map subscribableDevices = new HashMap<>(); - private Map deviceSubscriptions = new HashMap<>(); +// private Map deviceSubscriptions = new HashMap<>(); public Map getSubscribedDevices() { return subscribedDevices; @@ -44,11 +44,11 @@ public class SubscribingDeviceIdHolder { this.subscribableDevices = subscribableDevices; } - public Map getDeviceSubscriptions() { - return deviceSubscriptions; - } - - public void setDeviceSubscriptions(Map deviceSubscriptions) { - this.deviceSubscriptions = deviceSubscriptions; - } +// public Map getDeviceSubscriptions() { +// return deviceSubscriptions; +// } +// +// public void setDeviceSubscriptions(Map deviceSubscriptions) { +// this.deviceSubscriptions = deviceSubscriptions; +// } } 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 1a4d2991e5a..f83a2788f0c 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 @@ -131,7 +131,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); - if (!deviceType.getName().equals(deviceIdentifier.getType())) { String msg = "Found a device identifier which is not matched with the application device Type. " @@ -238,9 +237,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - for (String type : deviceIdentifierMap.keySet()) { + for (Map.Entry> entry : deviceIdentifierMap.entrySet()) { Activity activity = addAppInstallOperationToDevices(applicationDTO, - new ArrayList<>(deviceIdentifierMap.get(type)), type); + new ArrayList<>(entry.getValue()), entry.getKey()); activityList.add(activity); } @@ -259,9 +258,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); //todo - addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, - subscribingDeviceIdHolder.getSubscribableDevices(), - new ArrayList<>(subscribingDeviceIdHolder.getDeviceSubscriptions().keySet()), subscribers, subType); + addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, subscribingDeviceIdHolder, + subscribers, subType, action); return applicationInstallResponse; } @@ -287,7 +285,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder(); subscribingDeviceIdHolder.setSubscribableDevices(subscribableDevices); subscribingDeviceIdHolder.setSubscribedDevices(subscribedDevices); - subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions); +// subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions); return subscribingDeviceIdHolder; } @@ -326,9 +324,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + //todo pass SubscribingDeviceIdHolder and action private void addSubscriptions(int applicationReleaseId, Activity activity, - Map compatibleDevices, List subDeviceIds, List subscribers, - String subType) throws ApplicationManagementException { + SubscribingDeviceIdHolder subscribingDeviceIdHolder, List subscribers, String subType, String action) + throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); try { @@ -337,6 +336,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List deviceSubscriptingIds; if (SubsciptionType.USER.toString().equals(subType)) { + //todo check action List subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId); if (!subscribedUsers.isEmpty()) { subscriptionDAO @@ -352,16 +352,22 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List activityStatuses = activity.getActivityStatus(); for (ActivityStatus status : activityStatuses) { if (status.getStatus().equals(ActivityStatus.Status.PENDING)) { - deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier())); + //todo +// deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier())); } } int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); - if (!subDeviceIds.isEmpty()) { - deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType, - Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); - deviceIds.removeAll(subDeviceIds); - } + //todo if INSTALL get Ids of subscribable devices and update those ids and insert other ids + + + //todo + +// if (!subDeviceIds.isEmpty()) { +// deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType, +// Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); +// deviceIds.removeAll(subDeviceIds); +// } deviceSubscriptingIds = subscriptionDAO .subscribeDeviceToApplication(subscriber, deviceIds, subType, Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);