From 3241831eadc1ed8d42edbe7308aef15384204f49 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Mon, 21 Sep 2020 11:27:46 +0530 Subject: [PATCH] Change reactive action --- .../mgt/common/policy/mgt/CorrectiveAction.java | 14 ++++++++++++++ .../mgt/core/operation/mgt/ProfileOperation.java | 10 ++++++++++ .../policy/mgt/core/dao/impl/PolicyDAOImpl.java | 8 +++++--- .../policy/mgt/core/util/PolicyManagerUtil.java | 13 ++++++++++--- .../src/main/resources/dbscripts/cdm/h2.sql | 1 + .../src/main/resources/dbscripts/cdm/mysql.sql | 1 + 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java index 022fc7d082..dd0a017952 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java @@ -55,6 +55,12 @@ public class CorrectiveAction implements Serializable { ) private List operations; + @ApiModelProperty( + name = "isReactive", + value = "Declare the action as a reactive action" + ) + private boolean isReactive; + private Integer featureId; private Integer associatedGeneralPolicyId; @@ -98,4 +104,12 @@ public class CorrectiveAction implements Serializable { public void setAssociatedGeneralPolicyId(Integer associatedGeneralPolicyId) { this.associatedGeneralPolicyId = associatedGeneralPolicyId; } + + public boolean isReactive() { + return isReactive; + } + + public void setReactive(boolean reactive) { + isReactive = reactive; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java index 21d41f3aed..03efcd8ded 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java @@ -25,6 +25,8 @@ import java.util.List; public class ProfileOperation extends ConfigOperation implements Serializable { private List correctiveActionIds; + private List reactiveActionIds; + public Type getType() { return Type.PROFILE; } @@ -40,4 +42,12 @@ public class ProfileOperation extends ConfigOperation implements Serializable { public void setCorrectiveActionIds(List correctiveActionIds) { this.correctiveActionIds = correctiveActionIds; } + + public List getReactiveActionIds() { + return reactiveActionIds; + } + + public void setReactiveActionIds(List reactiveActionIds) { + this.reactiveActionIds = reactiveActionIds; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index e99cd3da9d..bf3635cd95 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -280,7 +280,7 @@ public class PolicyDAOImpl implements PolicyDAO { String query = "INSERT INTO DM_POLICY_CORRECTIVE_ACTION " + "(ACTION_TYPE, " + "CORRECTIVE_POLICY_ID, " + - "POLICY_ID, FEATURE_ID) VALUES (?, ?, ?, ?)"; + "POLICY_ID, FEATURE_ID, IS_REACTIVE) VALUES (?, ?, ?, ?, ?)"; try (PreparedStatement insertStmt = conn.prepareStatement(query)) { for (CorrectiveAction correctiveAction : correctiveActions) { insertStmt.setString(1, correctiveAction.getActionType()); @@ -291,6 +291,7 @@ public class PolicyDAOImpl implements PolicyDAO { } else { insertStmt.setInt(4, featureId); } + insertStmt.setBoolean(5, correctiveAction.isReactive()); insertStmt.addBatch(); } insertStmt.executeBatch(); @@ -306,7 +307,7 @@ public class PolicyDAOImpl implements PolicyDAO { public List getCorrectiveActionsOfPolicy(int policyId) throws PolicyManagerDAOException { try { Connection conn = this.getConnection(); - String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID " + + String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " + "FROM DM_POLICY_CORRECTIVE_ACTION " + "WHERE POLICY_ID = ?"; try (PreparedStatement selectStmt = conn.prepareStatement(query)) { @@ -324,7 +325,7 @@ public class PolicyDAOImpl implements PolicyDAO { public List getAllCorrectiveActions() throws PolicyManagerDAOException { try { Connection conn = this.getConnection(); - String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID " + + String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " + "FROM DM_POLICY_CORRECTIVE_ACTION "; try (PreparedStatement stmt = conn.prepareStatement(query)) { List correctiveActions = new ArrayList<>(); @@ -353,6 +354,7 @@ public class PolicyDAOImpl implements PolicyDAO { correctiveAction.setPolicyId(rs.getInt("CORRECTIVE_POLICY_ID")); correctiveAction.setFeatureId(rs.getInt("FEATURE_ID")); correctiveAction.setAssociatedGeneralPolicyId(rs.getInt("POLICY_ID")); + correctiveAction.setReactive(rs.getBoolean("IS_REACTIVE")); correctiveActions.add(correctiveAction); } } 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 a431fd8744..62306b0ec9 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,10 +304,17 @@ public class PolicyManagerUtil { profileOperation.setPayLoad(feature.getContent()); if (feature.getCorrectiveActions() != null) { for (CorrectiveAction correctiveAction : feature.getCorrectiveActions()) { - if (profileOperation.getCorrectiveActionIds() == null) { - profileOperation.setCorrectiveActionIds(new ArrayList<>()); + if (correctiveAction.isReactive()) { + if (profileOperation.getReactiveActionIds() == null) { + profileOperation.setCorrectiveActionIds(new ArrayList<>()); + } + profileOperation.getReactiveActionIds().add(correctiveAction.getPolicyId()); + } else { + if (profileOperation.getCorrectiveActionIds() == null) { + profileOperation.setCorrectiveActionIds(new ArrayList<>()); + } + profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId()); } - profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId()); } } profileOperations.add(profileOperation); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index f69ea8b0f6..0390a8fee4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -247,6 +247,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL, POLICY_ID INT(11) NOT NULL, FEATURE_ID INT(11) DEFAULT NULL, + IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID), CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION FOREIGN KEY (POLICY_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 9f11167c76..2c09c84670 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -284,6 +284,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL, POLICY_ID INT(11) NOT NULL, FEATURE_ID INT(11) DEFAULT NULL, + IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID), CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION FOREIGN KEY (POLICY_ID)