Change reactive action

corrective-policy
Pahansith 4 years ago
parent d08f20d90e
commit 3241831ead

@ -55,6 +55,12 @@ public class CorrectiveAction implements Serializable {
)
private List<ProfileFeature> 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;
}
}

@ -25,6 +25,8 @@ import java.util.List;
public class ProfileOperation extends ConfigOperation implements Serializable {
private List<Integer> correctiveActionIds;
private List<Integer> reactiveActionIds;
public Type getType() {
return Type.PROFILE;
}
@ -40,4 +42,12 @@ public class ProfileOperation extends ConfigOperation implements Serializable {
public void setCorrectiveActionIds(List<Integer> correctiveActionIds) {
this.correctiveActionIds = correctiveActionIds;
}
public List<Integer> getReactiveActionIds() {
return reactiveActionIds;
}
public void setReactiveActionIds(List<Integer> reactiveActionIds) {
this.reactiveActionIds = reactiveActionIds;
}
}

@ -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<CorrectiveAction> 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<CorrectiveAction> 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<CorrectiveAction> 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);
}
}

@ -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);

@ -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)

@ -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)

Loading…
Cancel
Save