001/** 002 * Copyright 2005-2016 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.result; 017 018import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader; 019import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable; 020import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint; 021import org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor; 022 023import java.util.Arrays; 024import java.util.Collections; 025import java.util.List; 026 027/** 028 * defines the information expected when a processor has processed a constraint 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 * @see ConstraintProcessor 032 */ 033public class ProcessorResult { 034 035 private final transient List<Constraint> constraints; 036 private final transient Constrainable definition; 037 private final transient AttributeValueReader attributeValueReader; 038 039 private final List<ConstraintValidationResult> constraintValidationResults; 040 041 /** 042 * creates a processor result from the provided constraint validation result 043 * 044 * @param constraintValidationResult - the constraint validation result 045 */ 046 public ProcessorResult(ConstraintValidationResult constraintValidationResult) { 047 this(constraintValidationResult, null, null); 048 } 049 050 /** 051 * creates a processor result from the parameters provided 052 * 053 * @param constraintValidationResult - the constraint validation result 054 * @param definition - a Data Dictionary definition e.g. {@code ComplexAttributeDefinition} or {@code 055 * CollectionDefinition} 056 * @param attributeValueReader - provides access to the attribute being validated 057 * @param constraints - optional constraints to use 058 */ 059 public ProcessorResult(ConstraintValidationResult constraintValidationResult, Constrainable definition, 060 AttributeValueReader attributeValueReader, Constraint... constraints) { 061 this.constraintValidationResults = Collections.singletonList(constraintValidationResult); 062 this.definition = definition; 063 this.attributeValueReader = attributeValueReader; 064 this.constraints = Arrays.asList(constraints); 065 } 066 067 /** 068 * creates a processor result from the parameters provided 069 * 070 * @param constraintValidationResult - the constraint validation result 071 * @param definition - a Data Dictionary definition e.g. {@code ComplexAttributeDefinition} or {@code 072 * CollectionDefinition} 073 * @param attributeValueReader - provides access to the attribute being validated 074 * @param constraints - the list of constraints to use 075 */ 076 public ProcessorResult(ConstraintValidationResult constraintValidationResult, Constrainable definition, 077 AttributeValueReader attributeValueReader, List<Constraint> constraints) { 078 this.constraintValidationResults = Collections.singletonList(constraintValidationResult); 079 this.definition = definition; 080 this.attributeValueReader = attributeValueReader; 081 this.constraints = constraints; 082 } 083 084 /** 085 * creates a processor result from the provided constraint validation results 086 * 087 * @param constraintValidationResults - the constraint validation results to use 088 */ 089 public ProcessorResult(List<ConstraintValidationResult> constraintValidationResults) { 090 this(constraintValidationResults, null, null); 091 } 092 093 /** 094 * creates a processor result from the parameters provided 095 * 096 * @param constraintValidationResults - the constraint validation results 097 * @param definition - a Data Dictionary definition e.g. {@code ComplexAttributeDefinition} or {@code 098 * CollectionDefinition} 099 * @param attributeValueReader - provides access to the attribute being validated 100 * @param constraints - optional constraints to use 101 */ 102 public ProcessorResult(List<ConstraintValidationResult> constraintValidationResults, Constrainable definition, 103 AttributeValueReader attributeValueReader, Constraint... constraints) { 104 this.constraintValidationResults = constraintValidationResults; 105 this.definition = definition; 106 this.attributeValueReader = attributeValueReader; 107 this.constraints = Arrays.asList(constraints); 108 } 109 110 /** 111 * checks whether this object has a single constraint validation result 112 * 113 * @return true if only one result found, false if not 114 */ 115 public boolean isSingleConstraintResult() { 116 return this.constraintValidationResults.size() == 1; 117 } 118 119 /** 120 * checks whether a Data Dictionary definition is present 121 * 122 * @return true if definition is present, false otherwise 123 */ 124 public boolean isDefinitionProvided() { 125 return definition != null; 126 } 127 128 /** 129 * checks whether an attribute value reader is present 130 * 131 * @return true if reader is present, false otherwise 132 */ 133 public boolean isAttributeValueReaderProvided() { 134 return attributeValueReader != null; 135 } 136 137 /** 138 * gets the first constraint validation result 139 * 140 * @return null if there are no results 141 */ 142 public ConstraintValidationResult getFirstConstraintValidationResult() { 143 return this.constraintValidationResults.isEmpty() ? null : this.constraintValidationResults.get(0); 144 } 145 146 /** 147 * @return the constraintValidationResults 148 */ 149 public List<ConstraintValidationResult> getConstraintValidationResults() { 150 return this.constraintValidationResults; 151 } 152 153 /** 154 * @return the definition 155 */ 156 public Constrainable getDefinition() { 157 return this.definition; 158 } 159 160 /** 161 * @return the attributeValueReader 162 */ 163 public AttributeValueReader getAttributeValueReader() { 164 return this.attributeValueReader; 165 } 166 167 /** 168 * @return the constraints 169 */ 170 public List<Constraint> getConstraints() { 171 return this.constraints; 172 } 173 174}