From ac88e3217169cce55b844472c07bb660018e970c Mon Sep 17 00:00:00 2001 From: hasuniea Date: Wed, 30 Sep 2015 18:35:03 +0530 Subject: [PATCH] implimented policyMonitoring service for windows --- .../WindowsPolicyMonitoringService.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java index f1034d4ce..fd14cf3e6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java @@ -18,26 +18,62 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +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.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; +import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; +import java.util.ArrayList; import java.util.List; public class WindowsPolicyMonitoringService implements PolicyMonitoringService { + private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class); + @Override public void notifyDevices(List list) throws PolicyComplianceException { } @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException { - return null; + public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload) + throws PolicyComplianceException { + if (log.isDebugEnabled()) { + log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); + } + ComplianceData complianceData = new ComplianceData(); + if (policy == null || compliancePayload == null) { + return complianceData; + } + List complianceFeatures = new ArrayList(); + + JsonElement jsonElement = new JsonParser().parse(compliancePayload.toString()); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Gson gson = new Gson(); + ComplianceFeature complianceFeature; + for (int x = 0; x < jsonArray.size(); x++) { + complianceFeature = gson.fromJson(jsonArray.get(x), ComplianceFeature.class); + complianceFeatures.add(complianceFeature); + } + complianceData.setComplianceFeatures(complianceFeatures); + + for (ComplianceFeature cf : complianceFeatures) { + if (!cf.isCompliant()) { + complianceData.setStatus(false); + break; + } + } + return complianceData; } @Override