Update all children groups when updating a group

(cherry picked from commit ed087e2a0c)
4.x.x
Saad Sahibjan 3 years ago committed by Pahansith
parent dabc0dc8ec
commit 996309f063

@ -177,6 +177,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.beginTransaction(); GroupManagementDAOFactory.beginTransaction();
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId); DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
if (existingGroup != null) { if (existingGroup != null) {
List<DeviceGroup> groupsToUpdate = new ArrayList<>();
String immediateParentID = StringUtils.substringAfterLast(existingGroup.getParentPath(), "/");
String parentPath = "";
if (deviceGroup.getParentGroupId() == 0) { if (deviceGroup.getParentGroupId() == 0) {
deviceGroup.setParentPath("/"); deviceGroup.setParentPath("/");
} else { } else {
@ -188,10 +191,20 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
String parentPath = DeviceManagerUtil.createParentPath(immediateParentGroup); parentPath = DeviceManagerUtil.createParentPath(immediateParentGroup);
deviceGroup.setParentPath(parentPath); deviceGroup.setParentPath(parentPath);
} }
this.groupDAO.updateGroup(deviceGroup, groupId, tenantId); deviceGroup.setGroupId(groupId);
groupsToUpdate.add(deviceGroup);
if (StringUtils.isNotBlank(immediateParentID)) {
List<DeviceGroup> 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) { if (deviceGroup.getGroupProperties() != null && deviceGroup.getGroupProperties().size() > 0) {
this.groupDAO.updateGroupProperties(deviceGroup, groupId, tenantId); this.groupDAO.updateGroupProperties(deviceGroup, groupId, tenantId);
} }

Loading…
Cancel
Save