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