1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.service.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.rice.kns.bo.Parameter; |
21 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
22 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
23 | |
import org.kuali.rice.kns.service.ParameterEvaluator; |
24 | |
import org.kuali.rice.kns.util.GlobalVariables; |
25 | |
import org.kuali.rice.kns.util.RiceKeyConstants; |
26 | |
|
27 | 0 | public class ParameterEvaluatorImpl implements ParameterEvaluator { |
28 | |
private static final long serialVersionUID = -758645169354452022L; |
29 | |
private Parameter parameter; |
30 | |
private boolean constraintIsAllow; |
31 | |
private String constrainedValue; |
32 | |
private List<String> values; |
33 | |
|
34 | |
private static DataDictionaryService dataDictionaryService; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public boolean evaluationSucceeds() { |
47 | 0 | if (constraintIsAllow()) { |
48 | 0 | return values.contains(constrainedValue); |
49 | |
} else { |
50 | 0 | return !values.contains(constrainedValue); |
51 | |
} |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public boolean evaluateAndAddError(Class<? extends Object> businessObjectOrDocumentClass, String constrainedPropertyName) { |
60 | 0 | return evaluateAndAddError(businessObjectOrDocumentClass, constrainedPropertyName, constrainedPropertyName); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public boolean evaluateAndAddError(Class<? extends Object> businessObjectOrDocumentClass, |
77 | |
String constrainedPropertyName, String userEditablePropertyName) { |
78 | 0 | if (!evaluationSucceeds()) { |
79 | 0 | GlobalVariables.getMessageMap().putError( |
80 | |
userEditablePropertyName, |
81 | |
constraintIsAllow() ? RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER : RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_DENIED_VALUES_PARAMETER, |
82 | |
new String[] { |
83 | |
getDataDictionaryService().getAttributeLabel( businessObjectOrDocumentClass, constrainedPropertyName), |
84 | |
constrainedValue, |
85 | |
toStringForMessage(), |
86 | |
getParameterValuesForMessage(), |
87 | |
getDataDictionaryService().getAttributeLabel( businessObjectOrDocumentClass, userEditablePropertyName) |
88 | |
} ); |
89 | 0 | return false; |
90 | |
} |
91 | 0 | return true; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
public boolean constraintIsAllow() { |
98 | 0 | return constraintIsAllow; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public String getParameterValuesForMessage() { |
107 | 0 | return values.toString().replace("[", "").replace("]", ""); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public String getValue() { |
114 | 0 | return parameter.getParameterValue(); |
115 | |
} |
116 | |
|
117 | |
public String toString() { |
118 | 0 | return new StringBuffer("ParameterEvaluator").append("\n\tParameter: ") |
119 | |
.append("module=").append(parameter.getParameterNamespaceCode()) |
120 | |
.append(", component=").append(parameter.getParameterDetailTypeCode()) |
121 | |
.append(", name=").append(parameter.getParameterName()) |
122 | |
.append(", value=").append(parameter.getParameterValue()) |
123 | |
.append("\n\tConstraint Is Allow: ").append(constraintIsAllow) |
124 | |
.append("\n\tConstrained Value: ").append(constrainedValue) |
125 | |
.append("\n\tValues: ").append(values.toString()) |
126 | |
.toString(); |
127 | |
} |
128 | |
|
129 | |
private String toStringForMessage() { |
130 | 0 | return new StringBuffer("parameter: ").append(parameter.getParameterName()) |
131 | |
.append(", module: ").append(parameter.getParameterNamespaceCode()) |
132 | |
.append(", component: ").append(parameter.getParameterDetailTypeCode()) |
133 | |
.toString(); |
134 | |
} |
135 | |
|
136 | |
public String getModuleAndComponent() { |
137 | 0 | return parameter.getParameterNamespaceCode() + ": " + parameter.getParameterDetailTypeCode(); |
138 | |
} |
139 | |
|
140 | |
public void setConstrainedValue(String constrainedValue) { |
141 | 0 | this.constrainedValue = constrainedValue; |
142 | 0 | } |
143 | |
|
144 | |
public void setConstraintIsAllow(boolean constraintIsAllow) { |
145 | 0 | this.constraintIsAllow = constraintIsAllow; |
146 | 0 | } |
147 | |
|
148 | |
public void setParameter(Parameter parameter) { |
149 | 0 | this.parameter = parameter; |
150 | 0 | } |
151 | |
|
152 | |
public void setValues(List<String> values) { |
153 | 0 | this.values = values; |
154 | 0 | } |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
protected DataDictionaryService getDataDictionaryService() { |
160 | 0 | if ( dataDictionaryService == null ) { |
161 | 0 | dataDictionaryService = KNSServiceLocator.getDataDictionaryService(); |
162 | |
} |
163 | 0 | return dataDictionaryService; |
164 | |
} |
165 | |
} |