|
|
@ -57,11 +57,7 @@ import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -564,24 +560,18 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
throw new GroupManagementException(msg);
|
|
|
|
throw new GroupManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Get groups with hierarchy " + request.toString());
|
|
|
|
log.debug("Get groups with hierarchy " + request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean isWithParentPath = false;
|
|
|
|
|
|
|
|
DeviceManagerUtil.validateGroupListPageSize(request);
|
|
|
|
DeviceManagerUtil.validateGroupListPageSize(request);
|
|
|
|
List<DeviceGroup> rootGroups;
|
|
|
|
List<DeviceGroup> rootGroups;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
|
|
|
|
request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
|
|
|
|
|
|
|
|
String parentPath;
|
|
|
|
|
|
|
|
List<DeviceGroup> childrenGroups;
|
|
|
|
if (StringUtils.isBlank(username)) {
|
|
|
|
if (StringUtils.isBlank(username)) {
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
rootGroups = groupDAO.getGroups(request, tenantId);
|
|
|
|
rootGroups = groupDAO.getGroups(request, tenantId);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<Integer> allDeviceGroupIdsOfUser = getGroupIds(username);
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId, isWithParentPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String parentPath;
|
|
|
|
|
|
|
|
List<DeviceGroup> childrenGroups;
|
|
|
|
|
|
|
|
for (DeviceGroup rootGroup : rootGroups) {
|
|
|
|
for (DeviceGroup rootGroup : rootGroups) {
|
|
|
|
parentPath = DeviceManagerUtil.createParentPath(rootGroup);
|
|
|
|
parentPath = DeviceManagerUtil.createParentPath(rootGroup);
|
|
|
|
childrenGroups = groupDAO.getChildrenGroups(parentPath, tenantId);
|
|
|
|
childrenGroups = groupDAO.getChildrenGroups(parentPath, tenantId);
|
|
|
@ -591,6 +581,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
populateGroupProperties(rootGroup, tenantId);
|
|
|
|
populateGroupProperties(rootGroup, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<Integer> allDeviceGroupIdsOfUser = getGroupIds(username);
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
rootGroups = this.getGroups(allDeviceGroupIdsOfUser, tenantId);
|
|
|
|
|
|
|
|
if (requireGroupProps) {
|
|
|
|
|
|
|
|
for (DeviceGroup rootGroup : rootGroups) {
|
|
|
|
|
|
|
|
populateGroupProperties(rootGroup, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
String msg = "Error occurred while retrieving all groups with hierarchy";
|
|
|
|
String msg = "Error occurred while retrieving all groups with hierarchy";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
@ -613,6 +614,49 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
return groupResult;
|
|
|
|
return groupResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceGroup> getGroups(List<Integer> groupIds, int tenantId) throws GroupManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<DeviceGroup >groups = groupDAO.getGroups(groupIds, tenantId);
|
|
|
|
|
|
|
|
if (groups == null) {
|
|
|
|
|
|
|
|
String msg = "Retrieved null when getting groups for group ids " + groupIds.toString();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new GroupManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groups.isEmpty()) return groups;
|
|
|
|
|
|
|
|
groups.sort(Comparator.comparing(DeviceGroup::getGroupId));
|
|
|
|
|
|
|
|
return getTree(groups);
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException ex) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting groups for group ids " + groupIds.toString();
|
|
|
|
|
|
|
|
log.error(msg, ex);
|
|
|
|
|
|
|
|
throw new GroupManagementException(msg, ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceGroup> getTree(List<DeviceGroup> groups) {
|
|
|
|
|
|
|
|
List<DeviceGroup> tree = new ArrayList<>();
|
|
|
|
|
|
|
|
for (DeviceGroup deviceGroup : groups) {
|
|
|
|
|
|
|
|
DeviceGroup treeNode = tree.stream().
|
|
|
|
|
|
|
|
filter(node -> deviceGroup.getParentPath().
|
|
|
|
|
|
|
|
contains(Integer.toString(node.getGroupId()))).
|
|
|
|
|
|
|
|
findFirst().orElse(null);
|
|
|
|
|
|
|
|
if (treeNode != null) {
|
|
|
|
|
|
|
|
if (Objects.equals(treeNode.getParentPath(), deviceGroup.getParentPath())) {
|
|
|
|
|
|
|
|
tree.add(deviceGroup);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<DeviceGroup> tempGroups = treeNode.getChildrenGroups();
|
|
|
|
|
|
|
|
if (tempGroups == null) {
|
|
|
|
|
|
|
|
tempGroups = new ArrayList<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tempGroups.add(deviceGroup);
|
|
|
|
|
|
|
|
treeNode.setChildrenGroups(getTree(tempGroups));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tree.add(deviceGroup);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceGroup> getGroups(String username, boolean requireGroupProps) throws GroupManagementException {
|
|
|
|
public List<DeviceGroup> getGroups(String username, boolean requireGroupProps) throws GroupManagementException {
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
|