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.core.api.config.property.ConfigurationService;
19 import org.kuali.rice.krad.service.KRADServiceLocator;
20 import org.kuali.rice.krad.uif.UifConstants;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26
27
28
29
30 public class IntegerPatternConstraint extends ValidDataPatternConstraint{
31 protected boolean allowNegative;
32 protected boolean onlyNegative;
33 protected boolean omitZero;
34
35
36
37
38 @Override
39 protected String getRegexString() {
40 StringBuffer regex = new StringBuffer();
41
42 if (isAllowNegative() && !onlyNegative) {
43 regex.append("((-?");
44 }
45 else if(onlyNegative){
46 regex.append("((-");
47 }
48 else {
49 regex.append("((");
50 }
51 if(omitZero){
52 regex.append("[1-9][0-9]*))");
53 }
54 else{
55 regex.append("[1-9][0-9]*)|[0]*)");
56 }
57
58 return regex.toString();
59 }
60
61
62
63
64 public boolean isAllowNegative() {
65 return this.allowNegative;
66 }
67
68
69
70
71 public void setAllowNegative(boolean allowNegative) {
72 this.allowNegative = allowNegative;
73 }
74
75 public boolean isOnlyNegative() {
76 return onlyNegative;
77 }
78
79
80
81
82
83 public void setOnlyNegative(boolean onlyNegative) {
84 this.onlyNegative = onlyNegative;
85 }
86
87 public boolean isOmitZero() {
88 return omitZero;
89 }
90
91
92
93
94
95 public void setOmitZero(boolean omitZero) {
96 this.omitZero = omitZero;
97 }
98
99
100
101
102
103
104 @Override
105 public List<String> getValidationMessageParams() {
106 if (validationMessageParams == null) {
107 validationMessageParams = new ArrayList<String>();
108 ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
109 if (allowNegative && !onlyNegative) {
110 if(omitZero){
111 validationMessageParams.add(configService
112 .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
113 + "positiveOrNegative"));
114 }
115 else{
116 validationMessageParams.add(configService
117 .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
118 + "positiveOrNegativeOrZero"));
119 }
120 }
121 else if(onlyNegative){
122 if(omitZero){
123 validationMessageParams.add(configService
124 .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negative"));
125 }
126 else{
127 validationMessageParams.add(configService
128 .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negativeOrZero"));
129 }
130 }
131 else {
132 if(omitZero){
133 validationMessageParams.add(configService
134 .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
135 }
136 else{
137 validationMessageParams.add(configService
138 .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrZero"));
139 }
140 }
141 }
142 return validationMessageParams;
143 }
144 }