1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.parameter; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.rice.core.api.parameter.Parameter; |
21 | |
import org.kuali.rice.core.api.parameter.ParameterEvaluator; |
22 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
23 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
24 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
25 | |
import org.kuali.rice.krad.util.GlobalVariables; |
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 | |
public boolean evaluateAndAddError(Class<? extends Object> businessObjectOrDocumentClass, String constrainedPropertyName) { |
55 | 0 | return evaluateAndAddError(businessObjectOrDocumentClass, constrainedPropertyName, constrainedPropertyName); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public boolean evaluateAndAddError(Class<? extends Object> businessObjectOrDocumentClass, |
70 | |
String constrainedPropertyName, String userEditablePropertyName) { |
71 | 0 | if (!evaluationSucceeds()) { |
72 | 0 | GlobalVariables.getMessageMap().putError( |
73 | |
userEditablePropertyName, |
74 | |
constraintIsAllow() ? RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER : RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_DENIED_VALUES_PARAMETER, |
75 | |
new String[] { |
76 | |
getDataDictionaryService().getAttributeLabel( businessObjectOrDocumentClass, constrainedPropertyName), |
77 | |
constrainedValue, |
78 | |
toStringForMessage(), |
79 | |
getParameterValuesForMessage(), |
80 | |
getDataDictionaryService().getAttributeLabel( businessObjectOrDocumentClass, userEditablePropertyName) |
81 | |
} ); |
82 | 0 | return false; |
83 | |
} |
84 | 0 | return true; |
85 | |
} |
86 | |
|
87 | |
public boolean constraintIsAllow() { |
88 | 0 | return constraintIsAllow; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public String getParameterValuesForMessage() { |
97 | 0 | return values.toString().replace("[", "").replace("]", ""); |
98 | |
} |
99 | |
|
100 | |
public String getValue() { |
101 | 0 | return parameter.getValue(); |
102 | |
} |
103 | |
|
104 | |
public String toString() { |
105 | 0 | return new StringBuffer("ParameterEvaluator").append("\n\tParameter: ") |
106 | |
.append("module=").append(parameter.getNamespaceCode()) |
107 | |
.append(", component=").append(parameter.getComponentCode()) |
108 | |
.append(", name=").append(parameter.getName()) |
109 | |
.append(", value=").append(parameter.getValue()) |
110 | |
.append("\n\tConstraint Is Allow: ").append(constraintIsAllow) |
111 | |
.append("\n\tConstrained Value: ").append(constrainedValue) |
112 | |
.append("\n\tValues: ").append(values.toString()) |
113 | |
.toString(); |
114 | |
} |
115 | |
|
116 | |
private String toStringForMessage() { |
117 | 0 | return new StringBuffer("parameter: ").append(parameter.getName()) |
118 | |
.append(", module: ").append(parameter.getNamespaceCode()) |
119 | |
.append(", component: ").append(parameter.getComponentCode()) |
120 | |
.toString(); |
121 | |
} |
122 | |
|
123 | |
public String getModuleAndComponent() { |
124 | 0 | return parameter.getNamespaceCode() + ": " + parameter.getComponentCode(); |
125 | |
} |
126 | |
|
127 | |
public void setConstrainedValue(String constrainedValue) { |
128 | 0 | this.constrainedValue = constrainedValue; |
129 | 0 | } |
130 | |
|
131 | |
public void setConstraintIsAllow(boolean constraintIsAllow) { |
132 | 0 | this.constraintIsAllow = constraintIsAllow; |
133 | 0 | } |
134 | |
|
135 | |
public void setParameter(Parameter parameter) { |
136 | 0 | this.parameter = parameter; |
137 | 0 | } |
138 | |
|
139 | |
public void setValues(List<String> values) { |
140 | 0 | this.values = values; |
141 | 0 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
protected DataDictionaryService getDataDictionaryService() { |
147 | 0 | if ( dataDictionaryService == null ) { |
148 | 0 | dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); |
149 | |
} |
150 | 0 | return dataDictionaryService; |
151 | |
} |
152 | |
} |