1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.struts.form; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import javax.servlet.http.HttpServletRequest; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.kuali.rice.kim.util.KimConstants; |
26 | |
import org.kuali.rice.kns.document.TransactionalDocument; |
27 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
28 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
29 | |
import org.kuali.rice.kns.util.KNSConstants; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class KualiTransactionalDocumentFormBase extends KualiDocumentFormBase { |
36 | 0 | private static final Logger LOG = Logger.getLogger(KualiTransactionalDocumentFormBase.class); |
37 | |
|
38 | |
|
39 | |
|
40 | |
private static final long serialVersionUID = 6463383454050206811L; |
41 | |
@SuppressWarnings("unchecked") |
42 | |
protected Map forcedReadOnlyFields; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@SuppressWarnings("unchecked") |
48 | |
public KualiTransactionalDocumentFormBase() { |
49 | 0 | super(); |
50 | |
|
51 | |
|
52 | 0 | forcedReadOnlyFields = new HashMap(); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
@SuppressWarnings("unchecked") |
59 | |
@Override |
60 | |
public void populate(HttpServletRequest request) { |
61 | 0 | super.populate(request); |
62 | 0 | populationSpecialEmptyFields (request); |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public TransactionalDocument getTransactionalDocument() { |
71 | 0 | return (TransactionalDocument) getDocument(); |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
protected String discoverDocumentTypeName() { |
81 | 0 | return ((DataDictionaryService) KNSServiceLocator.getDataDictionaryService()).getDataDictionary().getDocumentEntry(getDocument().getClass().getName()).getDocumentTypeName(); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
protected static String formatReversalDate(java.sql.Date reversalDate) { |
92 | 0 | if (reversalDate == null) { |
93 | 0 | return ""; |
94 | |
} |
95 | |
|
96 | 0 | return KNSServiceLocator.getDateTimeService().toString(reversalDate, "MMM d, yyyy"); |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
@SuppressWarnings("unchecked") |
105 | |
public Map getForcedReadOnlyFields() { |
106 | 0 | return forcedReadOnlyFields; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
@SuppressWarnings("unchecked") |
115 | |
public void setForcedReadOnlyFields(Map forcedReadOnlyFields) { |
116 | 0 | this.forcedReadOnlyFields = forcedReadOnlyFields; |
117 | 0 | } |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
protected void populateFalseCheckboxes(HttpServletRequest request) { |
126 | 0 | Map<String, String[]> parameterMap = request.getParameterMap(); |
127 | 0 | if (parameterMap.get("checkboxToReset") != null) { |
128 | 0 | final String[] checkboxesToReset = request.getParameterValues("checkboxToReset"); |
129 | 0 | if(checkboxesToReset != null && checkboxesToReset.length > 0) { |
130 | 0 | for (int i = 0; i < checkboxesToReset.length; i++) { |
131 | 0 | String propertyName = (String) checkboxesToReset[i]; |
132 | 0 | if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) == null ) { |
133 | 0 | populateForProperty(propertyName, KimConstants.KIM_ATTRIBUTE_BOOLEAN_FALSE_STR_VALUE_DISPLAY, parameterMap); |
134 | |
} |
135 | 0 | else if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) != null && parameterMap.get(propertyName).length >= 1 && parameterMap.get(propertyName)[0].equalsIgnoreCase("on") ) { |
136 | 0 | populateForProperty(propertyName, KimConstants.KIM_ATTRIBUTE_BOOLEAN_TRUE_STR_VALUE_DISPLAY, parameterMap); |
137 | |
} |
138 | |
} |
139 | |
} |
140 | |
} |
141 | 0 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
protected void populateEmptyMultiSelect(HttpServletRequest request) { |
150 | 0 | Map<String, String[]> parameterMap = request.getParameterMap(); |
151 | 0 | if (parameterMap.get("multiSelectToReset") != null) { |
152 | 0 | final String[] multiSelectToReset = request.getParameterValues("multiSelectToReset"); |
153 | 0 | if(multiSelectToReset != null && multiSelectToReset.length > 0) { |
154 | 0 | for (int i = 0; i < multiSelectToReset.length; i++) { |
155 | 0 | String propertyName = (String) multiSelectToReset[i]; |
156 | 0 | if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) == null ) { |
157 | 0 | populateForProperty(propertyName, "", parameterMap); |
158 | |
} |
159 | 0 | else if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) != null && parameterMap.get(propertyName).length >= 1 && parameterMap.get(propertyName)[0].equalsIgnoreCase("on") ) { |
160 | 0 | populateForProperty(propertyName, request.getParameter(propertyName), parameterMap); |
161 | |
} |
162 | |
} |
163 | |
} |
164 | |
} |
165 | 0 | } |
166 | |
|
167 | |
protected void populationSpecialEmptyFields (HttpServletRequest request) { |
168 | 0 | populateFalseCheckboxes(request); |
169 | 0 | populateEmptyMultiSelect(request); |
170 | 0 | } |
171 | |
|
172 | |
@SuppressWarnings("unchecked") |
173 | |
protected TransactionalDocument instantiateTransactionalDocumentByDocumentTypeName( String documentTypeName ) { |
174 | 0 | Class<TransactionalDocument> transDocClass = KNSServiceLocator.getTransactionalDocumentDictionaryService().getDocumentClassByName(documentTypeName); |
175 | 0 | if ( transDocClass != null ) { |
176 | |
try { |
177 | 0 | return transDocClass.newInstance(); |
178 | 0 | } catch (Exception ex) { |
179 | 0 | LOG.error( "Unable to instantiate transDocClass: " + transDocClass, ex); |
180 | 0 | } |
181 | |
} else { |
182 | 0 | LOG.error( "Unable to retrieve transactional document class for type: " + documentTypeName); |
183 | |
} |
184 | 0 | return null; |
185 | |
} |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
@Override |
193 | |
public boolean shouldMethodToCallParameterBeUsed( |
194 | |
String methodToCallParameterName, |
195 | |
String methodToCallParameterValue, HttpServletRequest request) { |
196 | 0 | if (methodToCallParameterName.startsWith(KNSConstants.DISPATCH_REQUEST_PARAMETER + "." + KNSConstants.POST_TEXT_AREA_TO_PARENT)) { |
197 | 0 | return true; |
198 | |
} |
199 | 0 | return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request); |
200 | |
} |
201 | |
} |