1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.state;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreApiServiceLocator;
20 import org.kuali.rice.core.api.config.property.ConfigurationService;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
24 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Map;
30
31
32
33
34
35
36
37
38 @BeanTags({@BeanTag(name = "stateMapping", parent = "StateMapping"),
39 @BeanTag(name = "workflowStateMapping", parent = "workflowStateMapping")})
40 public class StateMappingBase implements StateMapping {
41
42 private Map<String, String> stateNameMessageKeyMap;
43 private List<String> states;
44 private String statePropertyName;
45 private Map<String, String> customClientSideValidationStates;
46
47
48
49
50 @Override
51 public String getStateNameMessage(String state) {
52 String message = null;
53 if (StringUtils.isNotBlank(state) && this.getStates().contains(state)) {
54 if (this.getStateNameMessageKeyMap() != null) {
55 ConfigurationService configService = CoreApiServiceLocator.getKualiConfigurationService();
56 String key = this.getStateNameMessageKeyMap().get(state);
57 message = configService.getPropertyValueAsString(key);
58 }
59
60 if (message == null) {
61 message = state;
62 }
63 }
64 return message;
65 }
66
67
68
69
70 @Override
71 public String getCurrentState(Object object) {
72 return ObjectPropertyUtils.getPropertyValue(object, this.getStatePropertyName());
73 }
74
75
76
77
78 @Override
79 public String getNextState(Object object) {
80 int currentStateIndex = this.getStates().indexOf(this.getCurrentState(object));
81 if (currentStateIndex != -1) {
82 int index = currentStateIndex + 1;
83 if (index == this.getStates().size()) {
84 return this.getCurrentState(object);
85 } else {
86 return this.getStates().get(index);
87 }
88 } else {
89 return this.getCurrentState(object);
90 }
91 }
92
93
94
95
96 @Override
97 @BeanTagAttribute(name = "stateNameMessageKeyMap", type = BeanTagAttribute.AttributeType.MAPVALUE)
98 public Map<String, String> getStateNameMessageKeyMap() {
99 return stateNameMessageKeyMap;
100 }
101
102
103
104
105 @Override
106 public void setStateNameMessageKeyMap(Map<String, String> stateNameMessageKeyMap) {
107 this.stateNameMessageKeyMap = stateNameMessageKeyMap;
108 }
109
110
111
112
113 @Override
114 @BeanTagAttribute(name = "states", type = BeanTagAttribute.AttributeType.LISTVALUE)
115 public List<String> getStates() {
116 if (states == null) {
117 states = new ArrayList<String>();
118 }
119 return states;
120 }
121
122
123
124
125 @Override
126 public void setStates(List<String> states) {
127 this.states = states;
128 }
129
130
131
132
133 @Override
134 @BeanTagAttribute(name = "statePropertyName")
135 public String getStatePropertyName() {
136 return statePropertyName;
137 }
138
139
140
141
142 @Override
143 public void setStatePropertyName(String statePropertyName) {
144 this.statePropertyName = statePropertyName;
145 }
146
147
148
149
150 @BeanTagAttribute(name = "customClientSideValidationStates", type = BeanTagAttribute.AttributeType.MAPVALUE)
151 public Map<String, String> getCustomClientSideValidationStates() {
152 return customClientSideValidationStates;
153 }
154
155
156
157
158 public void setCustomClientSideValidationStates(Map<String, String> customClientSideValidationStates) {
159 this.customClientSideValidationStates = customClientSideValidationStates;
160 }
161
162
163
164
165 public void completeValidation(ValidationTrace tracer) {
166 tracer.addBean("StateMappingBase", getStatePropertyName());
167
168
169 if (getStatePropertyName() == null) {
170 String currentValues[] = {"statePropertyName = null"};
171 tracer.createWarning("The State Property Name must be set", currentValues);
172 }
173
174
175 if (getStates() == null) {
176 String currentValues[] = {"states = null"};
177 tracer.createWarning("States should be set", currentValues);
178 }
179 }
180 }