From 4790de94ef06fe1a55658351f4f995119e5e9bf3 Mon Sep 17 00:00:00 2001 From: mharindu Date: Fri, 21 Aug 2015 16:46:45 +0530 Subject: [PATCH] Implemented policy compliance checking function for Android plugin --- .../pom.xml | 7 +++++- .../AndroidPolicyMonitoringService.java | 25 ++++++++++++++++--- .../pom.xml | 4 +++ pom.xml | 6 +++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index b72c5b8e0..05201d015 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -76,7 +76,8 @@ org.wso2.carbon.registry.core.service, org.wso2.carbon.registry.core.session, org.wso2.carbon.registry.api, - org.wso2.carbon.device.mgt.extensions.license.mgt.registry + org.wso2.carbon.device.mgt.extensions.license.mgt.registry, + com.google.gson.* !org.wso2.carbon.device.mgt.mobile.internal, @@ -165,5 +166,9 @@ h2-database-engine test + + com.google.code.gson + gson + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java index de37861c8..c9dee0dae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java @@ -19,6 +19,10 @@ package org.wso2.carbon.device.mgt.mobile.impl.android; +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; @@ -43,15 +47,28 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService { } @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException { - ComplianceData complianceData = new ComplianceData(); - if (log.isDebugEnabled()) { + public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) + throws PolicyComplianceException { + if (log.isDebugEnabled()) { log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); } if (o == null || policy == null) { return null; } - List complianceFeatures = (List) o; + ComplianceData complianceData = new ComplianceData(); + List complianceFeatures = new ArrayList(); + + // Parsing json string to get compliance features. + JsonElement jsonElement = new JsonParser().parse((String) o); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Gson gson = new Gson(); + ComplianceFeature complianceFeature; + + for (int i = 0; i < jsonArray.size(); i++) { + complianceFeature = gson.fromJson(jsonArray.get(i), ComplianceFeature.class); + complianceFeatures.add(complianceFeature); + } + complianceData.setComplianceFeatures(complianceFeatures); for (ComplianceFeature cf : complianceFeatures) { diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml index 92c956437..6be1ceae2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml @@ -58,6 +58,10 @@ org.wso2.carbon.device.mgt.extensions.feature zip + + com.google.code.gson + gson + diff --git a/pom.xml b/pom.xml index b5a35ee11..34409e1cd 100644 --- a/pom.xml +++ b/pom.xml @@ -511,6 +511,11 @@ axis2 ${axis2.orbit.version} + + com.google.code.gson + gson + ${google.gson.version} + @@ -577,6 +582,7 @@ 1.49 2.0.0 3.0.21 + 2.2.4