1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary.validation.processor;
17
18 import org.kuali.rice.core.util.RiceKeyConstants;
19 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
20 import org.kuali.rice.kns.datadictionary.validation.AttributeValueReader;
21 import org.kuali.rice.kns.datadictionary.validation.ValidationUtils;
22 import org.kuali.rice.kns.datadictionary.validation.constraint.Constraint;
23 import org.kuali.rice.kns.datadictionary.validation.constraint.ExistenceConstraint;
24 import org.kuali.rice.kns.datadictionary.validation.result.ConstraintValidationResult;
25 import org.kuali.rice.kns.datadictionary.validation.result.DictionaryValidationResult;
26 import org.kuali.rice.kns.datadictionary.validation.result.ProcessorResult;
27
28
29
30
31
32 public class ExistenceConstraintProcessor extends OptionalElementConstraintProcessor<ExistenceConstraint> {
33
34 private static final String CONSTRAINT_NAME = "existence constraint";
35
36
37
38
39 @Override
40 public ProcessorResult process(DictionaryValidationResult result, Object value, ExistenceConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
41
42
43
44
45 return new ProcessorResult(processSingleExistenceConstraint(result, value, constraint, attributeValueReader));
46 }
47
48 @Override
49 public String getName() {
50 return CONSTRAINT_NAME;
51 }
52
53
54
55
56 @Override
57 public Class<? extends Constraint> getConstraintType() {
58 return ExistenceConstraint.class;
59 }
60
61 protected ConstraintValidationResult processSingleExistenceConstraint(DictionaryValidationResult result, Object value, ExistenceConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
62
63 if (constraint.isRequired() == null)
64 return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
65
66 if (constraint.isRequired().booleanValue()) {
67
68 if (ValidationUtils.isNullOrEmpty(value))
69 return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_REQUIRED);
70
71 return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
72 }
73
74 return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
75 }
76
77 }