1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krms.impl.validation;
17
18 import org.kuali.rice.krms.framework.engine.Action;
19 import org.kuali.rice.krms.framework.engine.BasicRule;
20 import org.kuali.rice.krms.framework.engine.Proposition;
21 import org.kuali.rice.krms.framework.type.ValidationRuleType;
22
23 import java.util.List;
24
25 /**
26 *
27 * A {@link org.kuali.rice.krms.framework.engine.Rule} that executes a {@link org.kuali.rice.krms.framework.engine.Action} when the {@link Proposition} is false,
28 * as opposed to {@link BasicRule} which executes its action when the proposition is true.
29 *
30 * @author Kuali Rice Team (rice.collab@kuali.org)
31 */
32 public class ValidationRule extends BasicRule {
33 private ValidationRuleType type = null;
34
35 /**
36 *
37 * @param type ValidationRuleType
38 * @param name Rule name
39 * @param proposition Proposition
40 * @param actions Rule Actions
41 * @throws IllegalArgumentException if type is null
42 */
43 public ValidationRule(ValidationRuleType type, String name, Proposition proposition, List<Action> actions) {
44 super(name, proposition, actions);
45 if (type == null) throw new IllegalArgumentException("type must not be null");
46 this.type = type;
47 }
48
49 /**
50 * Valid Validation Rules execute when the ruleExecutionResult is false.
51 * Invalid Validation Rules execute when the ruleExecutionResult is true.
52 * @param ruleExecutionResult result of the rules execution
53 * @return should the actions be executed
54 */
55 @Override
56 protected boolean shouldExecuteAction(boolean ruleExecutionResult) {
57 if (type == null || type.equals(ValidationRuleType.VALID)) {
58 return !ruleExecutionResult;
59 }
60 return ruleExecutionResult;
61 }
62 }