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 java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
22 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
23 | |
import org.kuali.rice.krad.uif.UifConstants; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 55 | public class FixedPointPatternConstraint extends ValidDataPatternConstraint { |
31 | |
|
32 | |
protected boolean allowNegative; |
33 | |
protected int precision; |
34 | |
protected int scale; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
@Override |
42 | |
protected String getRegexString() { |
43 | 10 | StringBuilder regex = new StringBuilder(); |
44 | |
|
45 | 10 | if (isAllowNegative()) { |
46 | 4 | regex.append("-?"); |
47 | |
} |
48 | |
|
49 | 10 | regex.append("("); |
50 | 10 | regex.append("[0-9]{0," + (getPrecision() - getScale()) + "}"); |
51 | 10 | regex.append("\\."); |
52 | 10 | regex.append("[0-9]{1," + getScale() + "}"); |
53 | 10 | regex.append("|[0-9]{1," + (getPrecision() - getScale()) + "}"); |
54 | 10 | regex.append(")"); |
55 | 10 | return regex.toString(); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public boolean isAllowNegative() { |
62 | 10 | return this.allowNegative; |
63 | |
} |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public void setAllowNegative(boolean allowNegative) { |
69 | 11 | this.allowNegative = allowNegative; |
70 | 11 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public int getPrecision() { |
76 | 20 | return this.precision; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public void setPrecision(int precision) { |
83 | 55 | this.precision = precision; |
84 | 55 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public int getScale() { |
90 | 30 | return this.scale; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public void setScale(int scale) { |
97 | 55 | this.scale = scale; |
98 | 55 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
@Override |
106 | |
public List<String> getValidationMessageParams() { |
107 | 0 | if(validationMessageParams == null){ |
108 | 0 | validationMessageParams = new ArrayList<String>(); |
109 | 0 | ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService(); |
110 | 0 | if (allowNegative) { |
111 | 0 | validationMessageParams.add(configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX |
112 | |
+ "positiveOrNegative")); |
113 | |
} else { |
114 | 0 | validationMessageParams.add(configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX |
115 | |
+ "positive")); |
116 | |
} |
117 | |
|
118 | 0 | validationMessageParams.add(Integer.toString(precision)); |
119 | 0 | validationMessageParams.add(Integer.toString(scale)); |
120 | |
} |
121 | 0 | return validationMessageParams; |
122 | |
} |
123 | |
|
124 | |
} |