From ed087e2a0cfd9ac055a4b0a0da588f24c97a9739 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Thu, 15 Jul 2021 21:37:36 +0530 Subject: [PATCH] Update all children groups when updating a group --- .../GroupManagementProviderServiceImpl.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 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 35f4915481..808a355cbe 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 @@ -177,6 +177,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid GroupManagementDAOFactory.beginTransaction(); DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId); if (existingGroup != null) { + List groupsToUpdate = new ArrayList<>(); + String immediateParentID = StringUtils.substringAfterLast(existingGroup.getParentPath(), "/"); + String parentPath = ""; if (deviceGroup.getParentGroupId() == 0) { deviceGroup.setParentPath("/"); } else { @@ -188,10 +191,20 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg); throw new GroupManagementException(msg); } - String parentPath = DeviceManagerUtil.createParentPath(immediateParentGroup); + parentPath = DeviceManagerUtil.createParentPath(immediateParentGroup); deviceGroup.setParentPath(parentPath); } - this.groupDAO.updateGroup(deviceGroup, groupId, tenantId); + deviceGroup.setGroupId(groupId); + groupsToUpdate.add(deviceGroup); + if (StringUtils.isNotBlank(immediateParentID)) { + List childrenGroups = groupDAO.getChildrenGroups(DeviceManagerUtil.createParentPath(existingGroup), tenantId); + for (DeviceGroup childrenGroup : childrenGroups) { + childrenGroup.setParentPath(childrenGroup.getParentPath() + .replace(existingGroup.getParentPath(), parentPath)); + groupsToUpdate.add(childrenGroup); + } + } + this.groupDAO.updateGroups(groupsToUpdate, tenantId); if (deviceGroup.getGroupProperties() != null && deviceGroup.getGroupProperties().size() > 0) { this.groupDAO.updateGroupProperties(deviceGroup, groupId, tenantId); }