1 /**
2 * Copyright 2005-2016 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.krad.datadictionary.validation.processor;
17
18 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
19 import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader;
20 import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
21 import org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult;
22 import org.kuali.rice.krad.datadictionary.validation.result.ProcessorResult;
23
24 /**
25 * ConstraintProcessor must be implemented by constraint processors, which validate individual constraints in the
26 * data dictionary
27 *
28 * <p>The idea is that each constraint has its own processor, and that the validation service can be configured
29 * via dependency injection with a list of processors. This gives institutions the ability to easily modify how
30 * validation
31 * should be handled and to add arbitrary new constraints and constraint processors.</p>
32 *
33 * <p>An alternative might have been to put
34 * the process() method into the Constraint marker interface and have each Constraint define its own processing, but
35 * that would
36 * have forced business logic into what are naturally API classes (classes that implement Constraint). This strategy
37 * separates
38 * the two functions.</p>
39 *
40 * @param <T> constrainable data type
41 * @param <C> constraint type
42 * @author Kuali Rice Team (rice.collab@kuali.org)
43 */
44 public interface ConstraintProcessor<T, C extends Constraint> {
45
46 /**
47 * process the provided constraint
48 *
49 * @param result - holds dictionary validation results
50 * @param value - the value of the attribute
51 * @param constraint - the constraint to process
52 * @param attributeValueReader - - provides access to the attribute being validated
53 * @return the result of the constraint processing
54 * @throws AttributeValidationException
55 */
56 public ProcessorResult process(DictionaryValidationResult result, T value, C constraint,
57 AttributeValueReader attributeValueReader) throws AttributeValidationException;
58
59 /**
60 * gets a descriptive name of this constraint processor
61 *
62 * <p>e.g. @see CollectionSizeConstraintProcessor.CONSTRAINT_NAME</p>
63 *
64 * @return a descriptive name
65 */
66 public String getName();
67
68 /**
69 * gets the java class type of the constraint that this contraint processor handles
70 *
71 * @return an instance of {@code Constraint}
72 */
73 public Class<? extends Constraint> getConstraintType();
74
75 /**
76 * returns true if the processing of this constraint is something that can be opted out of by some pieces of code.
77 * The only example of this in the version under development (1.1) is the existence constraint.
78 *
79 * @return true if this processor can be turned off by some pieces of code, false otherwise
80 */
81 public boolean isOptional();
82
83 }