View Javadoc

1   /**
2    * Copyright 2005-2014 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.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20  import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader;
21  import org.kuali.rice.krad.datadictionary.validation.ValidationUtils;
22  import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
23  import org.kuali.rice.krad.datadictionary.validation.constraint.PrerequisiteConstraint;
24  import org.kuali.rice.krad.datadictionary.validation.result.ConstraintValidationResult;
25  import org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult;
26  import org.kuali.rice.krad.datadictionary.validation.result.ProcessorResult;
27  import org.kuali.rice.krad.uif.UifConstants;
28  
29  /**
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class PrerequisiteConstraintProcessor extends BasePrerequisiteConstraintProcessor<PrerequisiteConstraint> {
33  
34      private static final String CONSTRAINT_NAME = "prerequisite constraint";
35      private static final String FALLBACK_KEY = "prerequisiteFallback";
36  
37      /**
38       * @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(DictionaryValidationResult,
39       *      Object, org.kuali.rice.krad.datadictionary.validation.capability.Validatable,
40       *      org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
41       */
42      @Override
43      public ProcessorResult process(DictionaryValidationResult result, Object value, PrerequisiteConstraint constraint,
44              AttributeValueReader attributeValueReader) throws AttributeValidationException {
45  
46          if (ValidationUtils.isNullOrEmpty(value)) {
47              return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
48          }
49  
50          ConstraintValidationResult constraintValidationResult = processPrerequisiteConstraint(constraint,
51                  attributeValueReader);
52  
53          if (constraint != null) {
54              if (StringUtils.isNotBlank(constraint.getMessageKey())) {
55                  constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
56              } else {
57                  constraintValidationResult.setConstraintLabelKey(
58                          UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
59              }
60              constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
61          }
62  
63          result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);
64  
65          return new ProcessorResult(constraintValidationResult);
66      }
67  
68      @Override
69      public String getName() {
70          return CONSTRAINT_NAME;
71      }
72  
73      /**
74       * @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#getConstraintType()
75       */
76      @Override
77      public Class<? extends Constraint> getConstraintType() {
78          return PrerequisiteConstraint.class;
79      }
80  
81  }