Skip to content
Snippets Groups Projects
Commit 615038ca authored by Vasilis Katopodis's avatar Vasilis Katopodis
Browse files

Catch exceptions in PolicyRuleBasic constructor

parent 0c4c5b1c
No related branches found
No related tags found
1 merge request!3feat(policy): policy rule add/update/delete RPCs
...@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import eu.teraflow.policy.common.Util; import eu.teraflow.policy.common.Util;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class PolicyRuleBasic { public class PolicyRuleBasic {
...@@ -30,6 +31,7 @@ public class PolicyRuleBasic { ...@@ -30,6 +31,7 @@ public class PolicyRuleBasic {
private final List<PolicyRuleCondition> policyRuleConditions; private final List<PolicyRuleCondition> policyRuleConditions;
private final BooleanOperator booleanOperator; private final BooleanOperator booleanOperator;
private final List<PolicyRuleAction> policyRuleActions; private final List<PolicyRuleAction> policyRuleActions;
private final Boolean isValid;
public PolicyRuleBasic( public PolicyRuleBasic(
String policyRuleId, String policyRuleId,
...@@ -38,22 +40,52 @@ public class PolicyRuleBasic { ...@@ -38,22 +40,52 @@ public class PolicyRuleBasic {
List<PolicyRuleCondition> policyRuleConditions, List<PolicyRuleCondition> policyRuleConditions,
BooleanOperator booleanOperator, BooleanOperator booleanOperator,
List<PolicyRuleAction> policyRuleActions) { List<PolicyRuleAction> policyRuleActions) {
checkNotNull(policyRuleId, "Policy rule ID must not be null.");
checkArgument(!policyRuleId.isBlank(), "Policy rule ID must not be empty."); String policyRuleId_val;
this.policyRuleId = policyRuleId; int priority_val;
this.policyRuleState = policyRuleState; List<PolicyRuleCondition> policyRuleConditions_val;
checkArgument(priority >= 0, "Priority value must be greater or equal than zero."); BooleanOperator booleanOperator_val;
this.priority = priority; List<PolicyRuleAction> policyRuleActions_val;
checkNotNull(policyRuleConditions, "Policy Rule conditions cannot be null."); Boolean isValid_val;
checkArgument(!policyRuleConditions.isEmpty(), "Policy Rule conditions cannot be empty.");
this.policyRuleConditions = policyRuleConditions; try {
checkArgument( checkNotNull(policyRuleId, "Policy rule ID must not be null.");
booleanOperator != BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_UNDEFINED, checkArgument(!policyRuleId.isBlank(), "Policy rule ID must not be empty.");
"Boolean operator cannot be undefined"); policyRuleId_val = policyRuleId;
this.booleanOperator = booleanOperator; this.policyRuleState = policyRuleState;
checkNotNull(policyRuleActions, "Policy Rule actions cannot be null."); checkArgument(priority >= 0, "Priority value must be greater or equal than zero.");
checkArgument(!policyRuleActions.isEmpty(), "Policy Rule actions cannot be empty."); priority_val = priority;
this.policyRuleActions = policyRuleActions; checkNotNull(policyRuleConditions, "Policy Rule conditions cannot be null.");
checkArgument(!policyRuleConditions.isEmpty(), "Policy Rule conditions cannot be empty.");
policyRuleConditions_val = policyRuleConditions;
checkArgument(
booleanOperator != BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_UNDEFINED,
"Boolean operator cannot be undefined");
booleanOperator_val = booleanOperator;
checkNotNull(policyRuleActions, "Policy Rule actions cannot be null.");
checkArgument(!policyRuleActions.isEmpty(), "Policy Rule actions cannot be empty.");
policyRuleActions_val = policyRuleActions;
isValid_val = true;
} catch (Exception e) {
policyRuleId_val = "";
priority_val = 0;
policyRuleConditions_val = new ArrayList<PolicyRuleCondition>();
booleanOperator_val = BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_UNDEFINED;
policyRuleActions_val = new ArrayList<PolicyRuleAction>();
isValid_val = false;
}
this.isValid = isValid_val;
this.policyRuleId = policyRuleId_val;
this.priority = priority_val;
this.policyRuleConditions = policyRuleConditions_val;
this.booleanOperator = booleanOperator_val;
this.policyRuleActions = policyRuleActions_val;
}
public boolean isValid() {
return isValid;
} }
public String getPolicyRuleId() { public String getPolicyRuleId() {
......
...@@ -36,7 +36,7 @@ import java.util.UUID; ...@@ -36,7 +36,7 @@ import java.util.UUID;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@QuarkusTest @QuarkusTest
class PolicyRuleBasicValidationTest { class PolicyRuleBasicValidationTestHelper {
private PolicyRuleBasic createPolicyRuleBasic( private PolicyRuleBasic createPolicyRuleBasic(
String policyRuleId, String policyRuleId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment