From 852fa3ad393db2ae76a789ccd878fa6a01688cde Mon Sep 17 00:00:00 2001 From: inoshperera Date: Mon, 22 Nov 2021 12:28:39 +0530 Subject: [PATCH] Remove duplicate app subscriptions When there are multiple groups on the list, there is a possibility to create multiple subscriptions. The fix is to address this problem. Fixes https://gitlab.com/entgra/product-iots/-/issues/1189 (cherry picked from commit b6c41eabb914b20312a02fa4b2427a1906ba8fe9) --- .../mgt/core/impl/SubscriptionManagerImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 2de1094c1f..7ddd76c6cd 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 @@ -97,9 +97,11 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -434,7 +436,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService(); - List devices = new ArrayList<>(); + Set devices = new HashSet<>(); List subscribers = new ArrayList<>(); List errorDeviceIdentifiers = new ArrayList<>(); String deviceTypeName = null; @@ -511,8 +513,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { devices.removeIf(device -> !tmpDeviceTypeName.equals(device.getType())); } + List deviceList = new ArrayList<>(); + deviceList.addAll(devices); ApplicationSubscriptionInfo applicationSubscriptionInfo = new ApplicationSubscriptionInfo(); - applicationSubscriptionInfo.setDevices(devices); + applicationSubscriptionInfo.setDevices(deviceList); applicationSubscriptionInfo.setSubscribers(subscribers); applicationSubscriptionInfo.setErrorDeviceIdentifiers(errorDeviceIdentifiers); applicationSubscriptionInfo.setAppSupportingDeviceTypeName(deviceTypeName);