From 48a2062f64be0feb002b3d28b32ce6a97dd445d9 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 22 May 2015 02:32:04 +0530 Subject: [PATCH] Add operations for effective policy --- .../operation/mgt/OperationManagerImpl.java | 13 +------ .../mgt/dao/impl/OperationDAOImpl.java | 6 +-- .../mgt/core/PolicyManagerServiceImpl.java | 39 ++++++++++--------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 1458999505..530ca559d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -349,18 +349,7 @@ public class OperationManagerImpl implements OperationManager { PolicyOperation policyOperation; for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) { - - if (dtoOperation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation){ - policyOperation = (PolicyOperation)dtoOperation; - for(org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation - profileOperation:policyOperation.getProfileOperations()){ - operation = OperationDAOUtil.convertOperation(profileOperation); - } - }else{ - operation = OperationDAOUtil.convertOperation(dtoOperation); - } - - + operation = OperationDAOUtil.convertOperation(dtoOperation); operations.add(operation); } return operations; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index 8e5efe3c5f..bdb380bae0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -277,11 +277,7 @@ public class OperationDAOImpl implements OperationDAO { operationDetails = rs.getBytes("OPERATION_DETAILS"); bais = new ByteArrayInputStream(operationDetails); ois = new ObjectInputStream(bais); - if (ois.readObject() instanceof PolicyOperation){ - operation = (PolicyOperation) ois.readObject(); - }else{ - operation = (PolicyOperation) ois.readObject(); - } + operation = (ProfileOperation) ois.readObject(); } else { operation = new Operation(); operation.setId(rs.getInt("ID")); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index 77b61e75ea..fdbdeff5fa 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.Feature; +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.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; @@ -93,27 +94,26 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { getEffectivePolicy(deviceIdentifier); if (policy != null) { + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); - PolicyOperation policyOperation = new PolicyOperation(); - - List profileOperationList = new ArrayList(); for (ProfileFeature feature : effectiveFeatures) { ProfileOperation operation = new ProfileOperation(); operation.setCode(feature.getFeatureCode()); + operation.setEnabled(true); + operation.setStatus(Operation.Status.PENDING); + operation.setType(Operation.Type.PROFILE); operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(operation, deviceIdentifiers); } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + + } else { return null; } @@ -140,25 +140,26 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { List effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). getEffectiveFeatures(deviceIdentifier); + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); + if (!effectiveFeatures.isEmpty()) { PolicyOperation policyOperation = new PolicyOperation(); - List profileOperationList = new ArrayList(); for (ProfileFeature feature : effectiveFeatures) { ProfileOperation operation = new ProfileOperation(); operation.setCode(feature.getFeatureCode()); operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); + operation.setStatus(Operation.Status.PENDING); + operation.setType(Operation.Type.PROFILE); + operation.setEnabled(true); - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(policyOperation, deviceIdentifiers); + } + } else { return null; }