From 4fdeec89cc6489652ada29b876bb704a7c4fdc0d Mon Sep 17 00:00:00 2001 From: Megala Date: Thu, 2 Mar 2017 15:11:59 +0530 Subject: [PATCH] Revert f3f7635d3b568d7d1c45996e0eb03f31d6ca5c15 --- .../carbon/device/mgt/core/dao/DeviceDAO.java | 7 ------ .../core/dao/impl/AbstractDeviceDAOImpl.java | 22 ------------------- .../DeviceManagementProviderService.java | 5 ----- .../DeviceManagementProviderServiceImpl.java | 15 ------------- .../task/impl/DeviceDetailsRetrieverTask.java | 22 ++++++------------- .../policy/mgt/core/task/MonitoringTask.java | 19 +++++----------- 6 files changed, 13 insertions(+), 77 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index a634fe93b67..1eb39fc5020 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -420,12 +420,5 @@ public interface DeviceDAO { */ List getEnrolmentsByStatus(List deviceIds, Status status, int tenantId) throws DeviceManagementDAOException; - - /** - * Retrieving the tenants which are have device enrolled. - * @return - * @throws DeviceManagementDAOException - */ - List getDeviceEnrolledTenants() throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 7131d973237..ffb9aacc1f1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1062,26 +1062,4 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { return devices; } - public List getDeviceEnrolledTenants() throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List tenants = new ArrayList<>(); - try { - conn = this.getConnection(); - String sql = "SELECT distinct(TENANT_ID) FROM DM_DEVICE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - while (rs.next()) { - tenants.add(rs.getInt("TENANT_ID")); - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while retrieving tenants which have " + - "device registered.", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - return tenants; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index c973cd0afc6..a48cb423c8d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -307,10 +307,6 @@ public interface DeviceManagementProviderService { PolicyMonitoringManager getPolicyMonitoringManager(String deviceType); - - List getDeviceEnrolledTenants() throws DeviceManagementException; - - /** * Change device status. * @@ -321,5 +317,4 @@ public interface DeviceManagementProviderService { */ boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) throws DeviceManagementException; - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 89846e27e5a..b61bafe1def 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1279,21 +1279,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return dms.getPolicyMonitoringManager(); } - @Override - public List getDeviceEnrolledTenants() throws DeviceManagementException { - try { - DeviceManagementDAOFactory.openConnection(); - return deviceDAO.getDeviceEnrolledTenants(); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the tenants " + - "which have device enrolled.", e); - } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); - } finally { - DeviceManagementDAOFactory.closeConnection(); - } - } - @Override public List getDevicesOfUser(String username) throws DeviceManagementException { List devices = new ArrayList<>(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 9040af66544..3337c65c4be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -23,7 +23,6 @@ import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; @@ -34,7 +33,6 @@ import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import java.util.List; -import java.util.List; import java.util.Map; public class DeviceDetailsRetrieverTask implements Task { @@ -66,18 +64,15 @@ public class DeviceDetailsRetrieverTask implements Task { log.debug("Device details retrieving task started to run."); } try { -// Tenant tenants[] = DeviceManagementDataHolder.getInstance(). -// getRealmService().getTenantManager().getAllTenants(); - - List tenants = DeviceManagementDataHolder.getInstance(). - getDeviceManagementProvider().getDeviceEnrolledTenants(); - for (Integer tenant : tenants) { - String tenantDomain = DeviceManagementDataHolder.getInstance(). - getRealmService().getTenantManager().getDomain(tenant); + Tenant tenants[] = DeviceManagementDataHolder.getInstance(). + getRealmService().getTenantManager().getAllTenants(); + + for (Tenant tenant : tenants) { + try { PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain()); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId()); DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, operationMonitoringTaskConfig); //pass the configurations also from here, monitoring tasks @@ -93,9 +88,6 @@ public class DeviceDetailsRetrieverTask implements Task { } } catch (UserStoreException e) { log.error("Error occurred while trying to get the available tenants", e); - } catch (DeviceManagementException e) { - log.error("Error occurred while trying to get the available tenants " + - "from device manager provider service.", e); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index eb195cd8bc2..dce753ba514 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -30,9 +30,8 @@ import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; +import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import java.util.ArrayList; import java.util.List; @@ -62,19 +61,15 @@ public class MonitoringTask implements Task { } try { - - PolicyManagementDataHolder.getInstance(). + Tenant tenants[] = PolicyManagementDataHolder.getInstance(). getRealmService().getTenantManager().getAllTenants(); - DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl(); - List tenants = deviceManagementService.getDeviceEnrolledTenants(); - for (Integer tenant : tenants) { - String tenantDomain = PolicyManagementDataHolder.getInstance(). - getRealmService().getTenantManager().getDomain(tenant); + for (Tenant tenant : tenants) { + try { PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain()); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId()); MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); List deviceTypes = new ArrayList<>(); @@ -147,8 +142,6 @@ public class MonitoringTask implements Task { } catch (UserStoreException e) { log.error("Error occurred while trying to get the available tenants", e); - } catch (DeviceManagementException e) { - log.error("Error occurred while trying to get the available tenants from device manager service ", e); } }