|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
|
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
@ -20,7 +20,11 @@ package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.impl
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.DeviceOrganizationDAO;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.DeviceOrganizationDAOFactory;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.util.ConnectionManagerUtil;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.*;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceNodeResult;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.PaginationRequest;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.RootChildrenRequest;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.AdditionResult;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.BadRequestException;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DBConnectionException;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtDAOException;
|
|
|
|
@ -30,7 +34,6 @@ import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -174,15 +177,24 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
PaginationRequest paginationRequest = new PaginationRequest(request.getOffSet(), request.getLimit());
|
|
|
|
|
List<DeviceOrganization> roots = getDeviceOrganizationRoots(paginationRequest);
|
|
|
|
|
|
|
|
|
|
if (roots == null || roots.isEmpty()) {
|
|
|
|
|
log.warn("No root device organizations found.");
|
|
|
|
|
return allDeviceOrganizations; // Return an empty list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Iterate over each root and fetch its children
|
|
|
|
|
for (DeviceOrganization root : roots) {
|
|
|
|
|
DeviceNodeResult childrenResult = getChildrenOfDeviceNode(root.getDeviceId(), request.getMaxDepth(), request.isIncludeDevice());
|
|
|
|
|
allDeviceOrganizations.add(childrenResult);
|
|
|
|
|
if (childrenResult != null) {
|
|
|
|
|
allDeviceOrganizations.add(childrenResult);
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("no children found for roots.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return allDeviceOrganizations;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
} catch (NullPointerException | DeviceOrganizationMgtPluginException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving all device organizations for roots.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|