diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java index 6f50dfca8cb43a3d825137e31a83c63855b5aebd..1157bc220f75db05c02c050c00af6c928a29dea0 100644 --- a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java +++ b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import eu.teraflow.policy.common.Util; +import java.util.ArrayList; import java.util.List; public class PolicyRuleBasic { @@ -30,6 +31,7 @@ public class PolicyRuleBasic { private final List<PolicyRuleCondition> policyRuleConditions; private final BooleanOperator booleanOperator; private final List<PolicyRuleAction> policyRuleActions; + private final Boolean isValid; public PolicyRuleBasic( String policyRuleId, @@ -38,22 +40,52 @@ public class PolicyRuleBasic { List<PolicyRuleCondition> policyRuleConditions, BooleanOperator booleanOperator, List<PolicyRuleAction> policyRuleActions) { - checkNotNull(policyRuleId, "Policy rule ID must not be null."); - checkArgument(!policyRuleId.isBlank(), "Policy rule ID must not be empty."); - this.policyRuleId = policyRuleId; - this.policyRuleState = policyRuleState; - checkArgument(priority >= 0, "Priority value must be greater or equal than zero."); - this.priority = priority; - checkNotNull(policyRuleConditions, "Policy Rule conditions cannot be null."); - checkArgument(!policyRuleConditions.isEmpty(), "Policy Rule conditions cannot be empty."); - this.policyRuleConditions = policyRuleConditions; - checkArgument( - booleanOperator != BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_UNDEFINED, - "Boolean operator cannot be undefined"); - this.booleanOperator = booleanOperator; - checkNotNull(policyRuleActions, "Policy Rule actions cannot be null."); - checkArgument(!policyRuleActions.isEmpty(), "Policy Rule actions cannot be empty."); - this.policyRuleActions = policyRuleActions; + + String policyRuleId_val; + int priority_val; + List<PolicyRuleCondition> policyRuleConditions_val; + BooleanOperator booleanOperator_val; + List<PolicyRuleAction> policyRuleActions_val; + Boolean isValid_val; + + try { + checkNotNull(policyRuleId, "Policy rule ID must not be null."); + checkArgument(!policyRuleId.isBlank(), "Policy rule ID must not be empty."); + policyRuleId_val = policyRuleId; + this.policyRuleState = policyRuleState; + checkArgument(priority >= 0, "Priority value must be greater or equal than zero."); + priority_val = priority; + 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() { diff --git a/src/policy/src/test/java/eu/teraflow/policy/PolicyRuleBasicValidationTest.java b/src/policy/src/test/java/eu/teraflow/policy/PolicyRuleBasicValidationTest.java index e79932fd2496e3896145706955a8b23c3d74edd1..896c842d90111c423cbc117d33e095ef3288a48e 100644 --- a/src/policy/src/test/java/eu/teraflow/policy/PolicyRuleBasicValidationTest.java +++ b/src/policy/src/test/java/eu/teraflow/policy/PolicyRuleBasicValidationTest.java @@ -36,7 +36,7 @@ import java.util.UUID; import org.junit.jupiter.api.Test; @QuarkusTest -class PolicyRuleBasicValidationTest { +class PolicyRuleBasicValidationTestHelper { private PolicyRuleBasic createPolicyRuleBasic( String policyRuleId,