From 7313ba1e7eead96fb3cec6ae03ba9c7a7a120f71 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 21 Jul 2015 19:43:22 +0530 Subject: [PATCH] Implemented policy monitoring add operation --- .../core/mgt/impl/MonitoringManagerImpl.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 ec6714cb90..4119e3b3e0 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 @@ -23,9 +23,12 @@ 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.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; @@ -53,6 +56,7 @@ public class MonitoringManagerImpl implements MonitoringManager { private ComplianceDecisionPoint complianceDecisionPoint; private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class); + private static final String OPERATION_MONITOR = "MONITOR"; public MonitoringManagerImpl() { this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); @@ -247,13 +251,25 @@ public class MonitoringManagerImpl implements MonitoringManager { String msg = "Error occurred from monitoring dao."; log.error(msg, e); throw new PolicyComplianceException(msg, e); + } catch (OperationManagementException e) { + String msg = "Error occurred while adding monitoring operation to devices"; + log.error(msg, e); + throw new PolicyComplianceException(msg, e); } } - private void addMonitoringOperationsToDatabase(List devices) throws PolicyComplianceException { + private void addMonitoringOperationsToDatabase(List devices) + throws PolicyComplianceException, OperationManagementException { + List deviceIdentifiers = this.getDeviceIdentifiersFromDevices(devices); + CommandOperation monitoringOperation = new CommandOperation(); + monitoringOperation.setEnabled(true); + monitoringOperation.setType(Operation.Type.COMMAND); + monitoringOperation.setCode(OPERATION_MONITOR); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(monitoringOperation, deviceIdentifiers); } private List getDeviceIdentifiersFromDevices(List devices) {