1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
31
32
33 public class PrerequisiteConstraintProcessor extends BasePrerequisiteConstraintProcessor<PrerequisiteConstraint> {
34
35 private static final String CONSTRAINT_NAME = "prerequisite constraint";
36 private static final String FALLBACK_KEY = "prerequisiteFallback";
37
38
39
40
41
42 @Override
43 public ProcessorResult process(DictionaryValidationResult result, Object value, PrerequisiteConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
44
45 if (ValidationUtils.isNullOrEmpty(value))
46 return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
47
48
49 ConstraintValidationResult constraintValidationResult = processPrerequisiteConstraint(constraint, attributeValueReader);
50
51 if(constraint != null){
52 if(StringUtils.isNotBlank(constraint.getLabelKey())){
53 constraintValidationResult.setConstraintLabelKey(constraint.getLabelKey());
54 }
55 else{
56 constraintValidationResult.setConstraintLabelKey(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX +
57 FALLBACK_KEY);
58 }
59 constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
60 }
61
62 result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);
63
64 return new ProcessorResult(constraintValidationResult);
65 }
66
67 @Override
68 public String getName() {
69 return CONSTRAINT_NAME;
70 }
71
72
73
74
75 @Override
76 public Class<? extends Constraint> getConstraintType() {
77 return PrerequisiteConstraint.class;
78 }
79
80 }