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.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.constraint.SimpleConstraint;
22  import org.kuali.rice.krad.datadictionary.validation.result.ConstraintValidationResult;
23  import org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult;
24  import org.kuali.rice.krad.datadictionary.validation.result.ProcessorResult;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30   * Processor for simple constraint which takes out each constraining value it contains and calls the appropriate
31   * processor
32   */
33  public class SimpleConstraintProcessor extends MandatoryElementConstraintProcessor<SimpleConstraint> {
34  
35      private static final String CONSTRAINT_NAME = "simple constraint";
36  
37      RangeConstraintProcessor rangeConstraintProcessor = new RangeConstraintProcessor();
38      LengthConstraintProcessor lengthConstraintProcessor = new LengthConstraintProcessor();
39      ExistenceConstraintProcessor existenceConstraintProcessor = new ExistenceConstraintProcessor();
40      DataTypeConstraintProcessor dataTypeConstraintProcessor = new DataTypeConstraintProcessor();
41  
42      /**
43       * Processes the SimpleConstraint by calling process on the other smaller constraints it represents and
44       * putting the results together in ProcessorResult
45       *
46       * @return
47       * @throws AttributeValidationException
48       * @see MandatoryElementConstraintProcessor#process(org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult,
49       *      Object, org.kuali.rice.krad.datadictionary.validation.constraint.Constraint,
50       *      org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
51       */
52      @Override
53      public ProcessorResult process(DictionaryValidationResult result, Object value, final SimpleConstraint constraint,
54              AttributeValueReader attributeValueReader) throws AttributeValidationException {
55  
56          ProcessorResult dataTypePR = dataTypeConstraintProcessor.process(result, value, constraint,
57                  attributeValueReader);
58          ProcessorResult existencePR = existenceConstraintProcessor.process(result, value, constraint,
59                  attributeValueReader);
60          ProcessorResult rangePR = rangeConstraintProcessor.process(result, value, constraint, attributeValueReader);
61          ProcessorResult lengthPR = lengthConstraintProcessor.process(result, value, constraint, attributeValueReader);
62          List<ConstraintValidationResult> cvrList = new ArrayList<ConstraintValidationResult>();
63          cvrList.addAll(existencePR.getConstraintValidationResults());
64          cvrList.addAll(rangePR.getConstraintValidationResults());
65          cvrList.addAll(lengthPR.getConstraintValidationResults());
66          cvrList.addAll(dataTypePR.getConstraintValidationResults());
67          return new ProcessorResult(cvrList);
68      }
69  
70      @Override
71      public String getName() {
72          return CONSTRAINT_NAME;
73      }
74  
75      @Override
76      public Class<? extends Constraint> getConstraintType() {
77          return SimpleConstraint.class;
78      }
79  }