1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation.constraint;
17
18 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
19 import org.kuali.rice.krad.datadictionary.validator.TracerToken;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class MustOccurConstraint extends BaseConstraint {
48
49 private List<PrerequisiteConstraint> prerequisiteConstraints;
50 private List<MustOccurConstraint> mustOccurConstraints;
51 private Integer min;
52 private Integer max;
53
54 public List<PrerequisiteConstraint> getPrerequisiteConstraints() {
55 return prerequisiteConstraints;
56 }
57
58 public void setPrerequisiteConstraints(List<PrerequisiteConstraint> prerequisiteConstraints) {
59 this.prerequisiteConstraints = prerequisiteConstraints;
60 }
61
62 public List<MustOccurConstraint> getMustOccurConstraints() {
63 return mustOccurConstraints;
64 }
65
66 public void setMustOccurConstraints(List<MustOccurConstraint> occurs) {
67 this.mustOccurConstraints = occurs;
68 }
69
70 public Integer getMin() {
71 return min;
72 }
73
74 public void setMin(Integer min) {
75 this.min = min;
76 }
77
78 public Integer getMax() {
79 return max;
80 }
81
82 public void setMax(Integer max) {
83 this.max = max;
84 }
85
86
87
88
89
90
91
92
93 @Override
94 public ArrayList<ErrorReport> completeValidation(TracerToken tracer){
95 ArrayList<ErrorReport> reports=new ArrayList<ErrorReport>();
96 tracer.addBean("MustOccurConstraint", getMessageKey());
97
98 if(getMax()<=0){
99 ErrorReport error = new ErrorReport(ErrorReport.ERROR);
100 error.setValidationFailed("Max must be greater than 0");
101 error.setBeanLocation(tracer.getBeanLocation());
102 error.addCurrentValue("max ="+getMax());
103 reports.add(error);
104 }
105
106 if(getPrerequisiteConstraints()==null){
107 ErrorReport error = new ErrorReport(ErrorReport.ERROR);
108 error.setValidationFailed("PrerequisiteConstraints cannot be null or empty");
109 error.setBeanLocation(tracer.getBeanLocation());
110 error.addCurrentValue("prerequisiteConstraints ="+getPrerequisiteConstraints());
111 reports.add(error);
112 }else if(getPrerequisiteConstraints().size()==0){
113 ErrorReport error = new ErrorReport(ErrorReport.ERROR);
114 error.setValidationFailed("PrerequisiteConstraints cannot be null or empty");
115 error.setBeanLocation(tracer.getBeanLocation());
116 error.addCurrentValue("prerequisiteConstraints.size ="+getPrerequisiteConstraints().size());
117 reports.add(error);
118 }else{
119 for(int i=0;i<getPrerequisiteConstraints().size();i++){
120 reports.addAll(getPrerequisiteConstraints().get(i).completeValidation(tracer.getCopy()));
121 }
122 }
123
124 if(getMustOccurConstraints()==null){
125 ErrorReport error = new ErrorReport(ErrorReport.ERROR);
126 error.setValidationFailed("MustOccurConstraints cannot be null or empty");
127 error.setBeanLocation(tracer.getBeanLocation());
128 error.addCurrentValue("mustOccurConstraints ="+getMustOccurConstraints());
129 reports.add(error);
130 }else if(getMustOccurConstraints().size()==0){
131 ErrorReport error = new ErrorReport(ErrorReport.ERROR);
132 error.setValidationFailed("MustOccurConstraints cannot be null or empty");
133 error.setBeanLocation(tracer.getBeanLocation());
134 error.addCurrentValue("mustOccurConstraints.size ="+getMustOccurConstraints().size());
135 reports.add(error);
136 }else{
137 for(int i=0;i<getMustOccurConstraints().size();i++){
138 reports.addAll(getMustOccurConstraints().get(i).completeValidation(tracer.getCopy()));
139 }
140 }
141
142 reports.addAll(super.completeValidation(tracer.getCopy()));
143
144 return reports;
145 }
146 }