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.kuali.rice.core.util.RiceKeyConstants; |
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.ExistenceConstraint; |
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 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 12 | 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 | 6 | return new ProcessorResult(processSingleExistenceConstraint(result, value, constraint, attributeValueReader)); |
46 | |
} |
47 | |
|
48 | |
@Override |
49 | |
public String getName() { |
50 | 6 | return CONSTRAINT_NAME; |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Override |
57 | |
public Class<? extends Constraint> getConstraintType() { |
58 | 0 | return ExistenceConstraint.class; |
59 | |
} |
60 | |
|
61 | |
protected ConstraintValidationResult processSingleExistenceConstraint(DictionaryValidationResult result, Object value, ExistenceConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException { |
62 | |
|
63 | 6 | if (constraint.isRequired() == null) |
64 | 2 | return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME); |
65 | |
|
66 | 4 | if (constraint.isRequired().booleanValue()) { |
67 | |
|
68 | 2 | if (ValidationUtils.isNullOrEmpty(value)) |
69 | 1 | return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_REQUIRED); |
70 | |
|
71 | 1 | return result.addSuccess(attributeValueReader, CONSTRAINT_NAME); |
72 | |
} |
73 | |
|
74 | 2 | return result.addSkipped(attributeValueReader, CONSTRAINT_NAME); |
75 | |
} |
76 | |
|
77 | |
} |