View Javadoc

1   /**
2    * Copyright 2005-2012 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.result;
17  
18  import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader;
19  import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
20  import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
21  import org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor;
22  
23  import java.util.Arrays;
24  import java.util.Collections;
25  import java.util.List;
26  
27  /**
28   *  defines the information expected when a processor has processed a constraint
29   *
30   *  @see ConstraintProcessor
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class ProcessorResult {
34  
35  	private final transient List<Constraint> constraints;
36  	private final transient Constrainable definition;
37  	private final transient AttributeValueReader attributeValueReader;
38  	
39  	private final List<ConstraintValidationResult> constraintValidationResults;
40  
41      /**
42       * creates a processor result from the provided constraint validation result
43       *
44       * @param constraintValidationResult - the constraint validation result
45       */
46  	public ProcessorResult(ConstraintValidationResult constraintValidationResult) {
47  		this(constraintValidationResult, null, null);
48  	}
49  
50      /**
51       *  creates a processor result from the parameters provided
52       *
53       * @param constraintValidationResult - the constraint validation result
54       * @param definition - a Data Dictionary definition e.g. {@code ComplexAttributeDefinition} or {@code CollectionDefinition}
55       * @param attributeValueReader - provides access to the attribute being validated
56       * @param constraints - optional constraints to use
57       */
58  	public ProcessorResult(ConstraintValidationResult constraintValidationResult, Constrainable definition, AttributeValueReader attributeValueReader, Constraint... constraints) {
59  		this.constraintValidationResults = Collections.singletonList(constraintValidationResult);
60  		this.definition = definition;
61  		this.attributeValueReader = attributeValueReader;
62  		this.constraints = Arrays.asList(constraints);
63  	}
64  
65      /**
66       *  creates a processor result from the parameters provided
67       *
68       * @param constraintValidationResult - the constraint validation result
69       * @param definition - a Data Dictionary definition e.g. {@code ComplexAttributeDefinition} or {@code CollectionDefinition}
70       * @param attributeValueReader - provides access to the attribute being validated
71       * @param constraints - the list of constraints to use
72       */
73      public ProcessorResult(ConstraintValidationResult constraintValidationResult, Constrainable definition, AttributeValueReader attributeValueReader, List<Constraint> constraints) {
74          this.constraintValidationResults = Collections.singletonList(constraintValidationResult);
75          this.definition = definition;
76          this.attributeValueReader = attributeValueReader;
77          this.constraints = constraints;
78      }
79  
80      /**
81       * creates a processor result from the provided constraint validation results
82       *
83       * @param constraintValidationResults - the constraint validation results to use
84       */
85  	public ProcessorResult(List<ConstraintValidationResult> constraintValidationResults) {
86  		this(constraintValidationResults, null, null);
87  	}
88  
89      /**
90       *  creates a processor result from the parameters provided
91       *
92       * @param constraintValidationResults - the constraint validation results
93       * @param definition - a Data Dictionary definition e.g. {@code ComplexAttributeDefinition} or {@code CollectionDefinition}
94       * @param attributeValueReader - provides access to the attribute being validated
95       * @param constraints - optional constraints to use
96       */
97  	public ProcessorResult(List<ConstraintValidationResult> constraintValidationResults, Constrainable definition, AttributeValueReader attributeValueReader, Constraint... constraints) {
98  		this.constraintValidationResults = constraintValidationResults;
99  		this.definition = definition;
100 		this.attributeValueReader = attributeValueReader;
101 		this.constraints = Arrays.asList(constraints);
102 	}
103 
104     /**
105      * checks whether this object has a single constraint validation result
106      *
107      * @return true if only one result found, false if not
108      */
109 	public boolean isSingleConstraintResult() {
110 		return this.constraintValidationResults.size() == 1;
111 	}
112 
113     /**
114      * checks whether a Data Dictionary definition is present
115      *
116      * @return true if definition is present, false otherwise
117      */
118 	public boolean isDefinitionProvided() {
119 		return definition != null;
120 	}
121 
122     /**
123      * checks whether an attribute value reader is present
124      *
125      * @return true if reader is present, false otherwise
126      */
127 	public boolean isAttributeValueReaderProvided() {
128 		return attributeValueReader != null;
129 	}
130 
131     /**
132      * gets the first constraint validation result
133      *
134      * @return null if there are no results
135      */
136 	public ConstraintValidationResult getFirstConstraintValidationResult() {
137 		return this.constraintValidationResults.isEmpty() ? null : this.constraintValidationResults.get(0);
138 	}
139 	
140 	/**
141 	 * @return the constraintValidationResults
142 	 */
143 	public List<ConstraintValidationResult> getConstraintValidationResults() {
144 		return this.constraintValidationResults;
145 	}
146 
147 	/**
148 	 * @return the definition
149 	 */
150 	public Constrainable getDefinition() {
151 		return this.definition;
152 	}
153 
154 	/**
155 	 * @return the attributeValueReader
156 	 */
157 	public AttributeValueReader getAttributeValueReader() {
158 		return this.attributeValueReader;
159 	}
160 
161 	/**
162 	 * @return the constraints
163 	 */
164 	public List<Constraint> getConstraints() {
165 		return this.constraints;
166 	}
167 		
168 }