From 48e1241de64f09f6f897603f6deacb3ffee465a7 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 30 Sep 2020 21:44:03 +0530 Subject: [PATCH] Add email type corrective action transform --- .../core/util/PolicyManagementConstants.java | 3 ++ .../mgt/core/util/PolicyManagerUtil.java | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java index 3cf993c25c..2af19a9694 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java @@ -69,6 +69,9 @@ public final class PolicyManagementConstants { public static final String POLICY_ACTIONS = "POLICY_ACTIONS"; public static final String CORRECTIVE_POLICY_FEATURE_CODE = "CORRECTIVE_POLICY"; public static final String GEOFENCE_POLICY = "GEOFENCE_POLICY"; + public static final String EMAIL_CORRECTIVE_ACTION_TYPE = "EMAIL"; + public static final String EMAIL_FEATURE_CODE = "EMAIL_ACTION"; + public static final Integer EMAIL_ACTION_ID = 450; /** Caller would reference the constants using PolicyManagementConstants.DEVICE_CONFIG_XML_NAME, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index a71e247ff8..d42a9d5c86 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -304,6 +304,9 @@ public class PolicyManagerUtil { if (PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE .equals(correctiveAction.getActionType())) { correctivePolicyIdSet.add(correctiveAction.getPolicyId()); + } else if (PolicyManagementConstants.EMAIL_CORRECTIVE_ACTION_TYPE + .equals(correctiveAction.getActionType())) { + createEmailCorrectiveActions(correctiveProfileOperation); } //Add check for another action type in future implementation } @@ -328,6 +331,20 @@ public class PolicyManagerUtil { } } + private static void createEmailCorrectiveActions(ProfileOperation correctiveProfileOperation) { + ProfileOperation profileOperation = new ProfileOperation(); + profileOperation.setId(PolicyManagementConstants.EMAIL_ACTION_ID); + profileOperation.setCode(PolicyManagementConstants.EMAIL_FEATURE_CODE); + profileOperation.setEnabled(true); + profileOperation.setStatus(Operation.Status.PENDING); + profileOperation.setType(Operation.Type.PROFILE); + List profileOperations = new ArrayList<>(); + profileOperation.setPayLoad(profileOperations); + List payLoad = new ArrayList<>(); + payLoad.add(profileOperation); + correctiveProfileOperation.setPayLoad(payLoad); + } + /** * This method is using for generate profile operations list which to be sent to the device. * this method is only using multiple corrective actions @@ -376,12 +393,20 @@ public class PolicyManagerUtil { if (profileOperation.getReactiveActionIds() == null) { profileOperation.setReactiveActionIds(new ArrayList<>()); } - profileOperation.getReactiveActionIds().add(correctiveAction.getPolicyId()); + if (correctiveAction.getActionType().equals(PolicyManagementConstants.EMAIL_CORRECTIVE_ACTION_TYPE)) { + profileOperation.getReactiveActionIds().add(PolicyManagementConstants.EMAIL_ACTION_ID); + } else if (correctiveAction.getActionType().equals(PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE)){ + profileOperation.getReactiveActionIds().add(correctiveAction.getPolicyId()); + } } else { if (profileOperation.getCorrectiveActionIds() == null) { profileOperation.setCorrectiveActionIds(new ArrayList<>()); } - profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId()); + if (correctiveAction.getActionType().equals(PolicyManagementConstants.EMAIL_CORRECTIVE_ACTION_TYPE)) { + profileOperation.getCorrectiveActionIds().add(PolicyManagementConstants.EMAIL_ACTION_ID); + } else if (correctiveAction.getActionType().equals(PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE)){ + profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId()); + } } } }