001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.datadictionary.validation.processor; 017 018import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; 019import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader; 020import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint; 021import org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult; 022import org.kuali.rice.krad.datadictionary.validation.result.ProcessorResult; 023 024/** 025 * ConstraintProcessor must be implemented by constraint processors, which validate individual constraints in the 026 * data dictionary 027 * 028 * <p>The idea is that each constraint has its own processor, and that the validation service can be configured 029 * via dependency injection with a list of processors. This gives institutions the ability to easily modify how 030 * validation 031 * should be handled and to add arbitrary new constraints and constraint processors.</p> 032 * 033 * <p>An alternative might have been to put 034 * the process() method into the Constraint marker interface and have each Constraint define its own processing, but 035 * that would 036 * have forced business logic into what are naturally API classes (classes that implement Constraint). This strategy 037 * separates 038 * the two functions.</p> 039 * 040 * @param <T> constrainable data type 041 * @param <C> constraint type 042 * @author Kuali Rice Team (rice.collab@kuali.org) 043 */ 044public interface ConstraintProcessor<T, C extends Constraint> { 045 046 /** 047 * process the provided constraint 048 * 049 * @param result - holds dictionary validation results 050 * @param value - the value of the attribute 051 * @param constraint - the constraint to process 052 * @param attributeValueReader - - provides access to the attribute being validated 053 * @return the result of the constraint processing 054 * @throws AttributeValidationException 055 */ 056 public ProcessorResult process(DictionaryValidationResult result, T value, C constraint, 057 AttributeValueReader attributeValueReader) throws AttributeValidationException; 058 059 /** 060 * gets a descriptive name of this constraint processor 061 * 062 * <p>e.g. @see CollectionSizeConstraintProcessor.CONSTRAINT_NAME</p> 063 * 064 * @return a descriptive name 065 */ 066 public String getName(); 067 068 /** 069 * gets the java class type of the constraint that this contraint processor handles 070 * 071 * @return an instance of {@code Constraint} 072 */ 073 public Class<? extends Constraint> getConstraintType(); 074 075 /** 076 * returns true if the processing of this constraint is something that can be opted out of by some pieces of code. 077 * The only example of this in the version under development (1.1) is the existence constraint. 078 * 079 * @return true if this processor can be turned off by some pieces of code, false otherwise 080 */ 081 public boolean isOptional(); 082 083}