From 3340d94acf991fac04f60c7b68edcc8352012182 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Thu, 18 May 2017 16:00:25 +0530 Subject: [PATCH] adding the if condition for only newRoles list iteration. --- .../GroupManagementProviderServiceImpl.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index fa169c58a9..44a5995b55 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -367,7 +367,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void manageGroupSharing(int groupId, List newRoles) throws GroupManagementException, RoleDoesNotExistException { - if (newRoles != null) { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); UserStoreManager userStoreManager; try { @@ -376,15 +375,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid tenantId).getUserStoreManager(); List currentUserRoles = getRoles(groupId); GroupManagementDAOFactory.beginTransaction(); - for (String role : newRoles) { - if (!userStoreManager.isExistingRole(role)) { - throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); - } - // Removing role from current user roles of the group will return true if role exist. - // So we don't need to add it to the db again. - if (!currentUserRoles.remove(role)) { - // If group doesn't have the role, it is adding to the db. - groupDAO.addRole(groupId, role, tenantId); + if (newRoles != null) { + for (String role : newRoles) { + if (!userStoreManager.isExistingRole(role)) { + throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); + } + // Removing role from current user roles of the group will return true if role exist. + // So we don't need to add it to the db again. + if (!currentUserRoles.remove(role)) { + // If group doesn't have the role, it is adding to the db. + groupDAO.addRole(groupId, role, tenantId); + } } } for (String role : currentUserRoles) { @@ -401,9 +402,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid throw new GroupManagementException(e); } finally { GroupManagementDAOFactory.closeConnection(); - } - } else { - throw new GroupManagementException("No roles provided to complete the operation."); } }