From 6b228ee73e1132b8c0f063396856d360d3dc90ca Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Fri, 13 Nov 2020 01:30:21 +0530 Subject: [PATCH] Fix monitoring re-applying issue when policy revoking --- .../core/mgt/impl/MonitoringManagerImpl.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 65394c7138..29878e05c0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -267,14 +267,20 @@ public class MonitoringManagerImpl implements MonitoringManager { int enrollmentId; for (Device device : devices) { enrollmentId = device.getEnrolmentInfo().getId(); - if (persistedComplianceData.containsKey(enrollmentId)) { - notifiableDeviceEnrollments.put(enrollmentId, device); - } else if (appliedPolicyIds.containsKey(enrollmentId)){ - PolicyDeviceWrapper policyDeviceWrapper = new PolicyDeviceWrapper(); - policyDeviceWrapper.setDeviceId(device.getId()); - policyDeviceWrapper.setEnrolmentId(device.getEnrolmentInfo().getId()); - policyDeviceWrapper.setPolicyId(appliedPolicyIds.get(enrollmentId)); - firstTimeComplianceData.add(policyDeviceWrapper); + /* + When a policy has applied to the device, and the first monitoring operation runs on the policy, then it + is considered as a compliance policy and adds monitoring operation on the applied policy. + If the device has identified the applied policy as either compliance or non-compliance policy then + adds monitoring operation on the applied policy. + .*/ + if (appliedPolicyIds.containsKey(enrollmentId)) { + if (!persistedComplianceData.containsKey(enrollmentId)) { + PolicyDeviceWrapper policyDeviceWrapper = new PolicyDeviceWrapper(); + policyDeviceWrapper.setDeviceId(device.getId()); + policyDeviceWrapper.setEnrolmentId(device.getEnrolmentInfo().getId()); + policyDeviceWrapper.setPolicyId(appliedPolicyIds.get(enrollmentId)); + firstTimeComplianceData.add(policyDeviceWrapper); + } notifiableDeviceEnrollments.put(enrollmentId, device); } }