From 2128f086585d54e404e2bf7491ff77d07ed42903 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 13 Oct 2016 10:00:08 +0530 Subject: [PATCH] fixing EMM-1750 --- .../config/policy/PolicyConfiguration.java | 13 ++++++++++ .../policy/mgt/core/task/MonitoringTask.java | 25 ++++++++++++++++++- .../src/main/resources/conf/cdm-config.xml | 5 ++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java index 2f419755c4..73d3517d83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java @@ -19,7 +19,9 @@ package org.wso2.carbon.device.mgt.core.config.policy; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; @XmlRootElement(name = "PolicyConfiguration") public class PolicyConfiguration { @@ -30,6 +32,7 @@ public class PolicyConfiguration { private int maxRetries; private int minRetriesToMarkUnreachable; private int minRetriesToMarkInactive; + private List platforms; @XmlElement(name = "MonitoringClass", required = true) public String getMonitoringClass() { @@ -85,4 +88,14 @@ public class PolicyConfiguration { this.monitoringFrequency = monitoringFrequency; } + @XmlElementWrapper(name = "Platforms", required = true) + @XmlElement(name = "Platform", required = true) + public List getPlatforms() { + return platforms; + } + + public void setPlatforms(List platforms) { + this.platforms = platforms; + } + } 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 6e3f8408bd..17b314865e 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 @@ -23,6 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; @@ -59,8 +61,14 @@ public class MonitoringTask implements Task { MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); List deviceTypes = new ArrayList<>(); + List configDeviceTypes = new ArrayList<>(); try { deviceTypes = monitoringManager.getDeviceTypes(); + for (String deviceType : deviceTypes) { + if (isPlatformExist(deviceType)) { + configDeviceTypes.add(deviceType); + } + } } catch (PolicyComplianceException e) { log.error("Error occurred while getting the device types."); } @@ -68,7 +76,7 @@ public class MonitoringTask implements Task { try { DeviceManagementProviderService deviceManagementProviderService = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); - for (String deviceType : deviceTypes) { + for (String deviceType : configDeviceTypes) { if (log.isDebugEnabled()) { log.debug("Running task for device type : " + deviceType); } @@ -82,6 +90,7 @@ public class MonitoringTask implements Task { deviceType); } for (Device device : devices) { + EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus(); if (status.equals(EnrolmentInfo.Status.BLOCKED) || status.equals(EnrolmentInfo.Status.REMOVED) || @@ -116,4 +125,18 @@ public class MonitoringTask implements Task { } } + + /** + * Check whether Device platform (ex: android) is exist in the cdm-config.xml file before adding a + * Monitoring operation to a specific device type. + * + * @param deviceType available device types. + * @return return platform is exist(true) or not (false). + */ + + private boolean isPlatformExist(String deviceType) { + PolicyConfiguration policyConfiguration = + DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration(); + return (policyConfiguration.getPlatforms().contains(deviceType)); + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index fdd4a42710..6fe961cc36 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -42,6 +42,11 @@ 5 8 20 + + android + ios + windows + true