|
|
|
@ -636,8 +636,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
List<DeviceGroup> tree = new ArrayList<>();
|
|
|
|
|
for (DeviceGroup deviceGroup : groups) {
|
|
|
|
|
DeviceGroup treeNode = tree.stream().
|
|
|
|
|
filter(node -> deviceGroup.getParentPath().
|
|
|
|
|
contains(Integer.toString(node.getGroupId()))).
|
|
|
|
|
filter(node -> Arrays.stream(deviceGroup.getParentPath().split("/")).
|
|
|
|
|
collect(Collectors.toList()).contains(Integer.toString(node.getGroupId()))).
|
|
|
|
|
findFirst().orElse(null);
|
|
|
|
|
if (treeNode != null) {
|
|
|
|
|
if (Objects.equals(treeNode.getParentPath(), deviceGroup.getParentPath())) {
|
|
|
|
@ -657,6 +657,47 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DeviceGroup findGroupFromTree(List<DeviceGroup> tree, int groupId) {
|
|
|
|
|
for (DeviceGroup node: tree) {
|
|
|
|
|
if (node.getGroupId() == groupId) return node;
|
|
|
|
|
if (node.getChildrenGroups() != null)
|
|
|
|
|
return findGroupFromTree(node.getChildrenGroups(), groupId);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceGroup getUserOwnGroup(int groupId, boolean requireGroupProps, int depth) throws GroupManagementException {
|
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
|
String username = ctx.getUsername();
|
|
|
|
|
int tenantId = ctx.getTenantId();
|
|
|
|
|
List<Integer> userOwnGroupIds = this.getGroupIds(username);
|
|
|
|
|
if (userOwnGroupIds == null) {
|
|
|
|
|
String msg = "Retrieved null when getting group ids for user " + username;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new GroupManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
DeviceGroup deviceGroup = findGroupFromTree(
|
|
|
|
|
getGroups(userOwnGroupIds, tenantId), groupId);
|
|
|
|
|
if (deviceGroup != null && requireGroupProps)
|
|
|
|
|
populateGroupProperties(deviceGroup, tenantId);
|
|
|
|
|
return deviceGroup;
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining group '" + groupId + "'";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new GroupManagementException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source to retrieve all groups "
|
|
|
|
|
+ "with hierarchy";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new GroupManagementException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceGroup> getGroups(String username, boolean requireGroupProps) throws GroupManagementException {
|
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
|
|