1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kns.web.struts.form; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.struts.upload.FormFile; |
21 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
22 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
23 | |
import org.kuali.rice.core.web.format.FormatException; |
24 | |
import org.kuali.rice.core.web.format.Formatter; |
25 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
26 | |
import org.kuali.rice.kns.bo.BusinessObject; |
27 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
28 | |
import org.kuali.rice.kns.datadictionary.exception.UnknownDocumentTypeException; |
29 | |
import org.kuali.rice.kns.document.Document; |
30 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
31 | |
import org.kuali.rice.kns.document.MaintenanceDocumentBase; |
32 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions; |
33 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
34 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
35 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
36 | |
import org.kuali.rice.kns.util.FieldUtils; |
37 | |
import org.kuali.rice.kns.util.GlobalVariables; |
38 | |
import org.kuali.rice.kns.util.KNSConstants; |
39 | |
import org.kuali.rice.kns.util.ObjectUtils; |
40 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; |
41 | |
|
42 | |
import javax.servlet.http.HttpServletRequest; |
43 | |
import java.lang.reflect.Constructor; |
44 | |
import java.lang.reflect.InvocationTargetException; |
45 | |
import java.util.Enumeration; |
46 | |
import java.util.HashMap; |
47 | |
import java.util.Iterator; |
48 | |
import java.util.List; |
49 | |
import java.util.Map; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 0 | public class KualiMaintenanceForm extends KualiDocumentFormBase { |
58 | 0 | protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiMaintenanceForm.class); |
59 | |
|
60 | |
protected static final long serialVersionUID = 1L; |
61 | |
|
62 | |
protected String businessObjectClassName; |
63 | |
protected String description; |
64 | |
protected boolean readOnly; |
65 | |
protected Map<String, String> oldMaintainableValues; |
66 | |
protected Map<String, String> newMaintainableValues; |
67 | |
protected String maintenanceAction; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
@Override |
73 | |
public void addRequiredNonEditableProperties(){ |
74 | 0 | super.addRequiredNonEditableProperties(); |
75 | 0 | registerRequiredNonEditableProperty(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE); |
76 | 0 | registerRequiredNonEditableProperty(KNSConstants.LOOKUP_RESULTS_BO_CLASS_NAME); |
77 | 0 | registerRequiredNonEditableProperty(KNSConstants.LOOKED_UP_COLLECTION_NAME); |
78 | 0 | registerRequiredNonEditableProperty(KNSConstants.LOOKUP_RESULTS_SEQUENCE_NUMBER); |
79 | 0 | registerRequiredNonEditableProperty(KNSConstants.FIELD_NAME_TO_FOCUS_ON_AFTER_SUBMIT); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
protected String lookupResultsSequenceNumber; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
protected String lookupResultsBOClassName; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
protected String lookedUpCollectionName; |
97 | |
|
98 | |
protected MaintenanceDocumentRestrictions authorizations; |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
@Override |
108 | |
public void postprocessRequestParameters(Map requestParameters) { |
109 | 0 | super.postprocessRequestParameters(requestParameters); |
110 | |
|
111 | 0 | String docTypeName = null; |
112 | 0 | String[] docTypeNames = (String[]) requestParameters.get(KNSConstants.DOCUMENT_TYPE_NAME); |
113 | 0 | if ((docTypeNames != null) && (docTypeNames.length > 0)) { |
114 | 0 | docTypeName = docTypeNames[0]; |
115 | |
} |
116 | |
|
117 | 0 | if (StringUtils.isNotBlank(docTypeName)) { |
118 | 0 | if(this.getDocument() == null){ |
119 | 0 | setDocTypeName(docTypeName); |
120 | 0 | Class documentClass = KNSServiceLocatorWeb.getDataDictionaryService().getDocumentClassByTypeName(docTypeName); |
121 | 0 | if (documentClass == null) { |
122 | 0 | throw new UnknownDocumentTypeException("unable to get class for unknown documentTypeName '" + docTypeName + "'"); |
123 | |
} |
124 | 0 | if (!MaintenanceDocumentBase.class.isAssignableFrom(documentClass)) { |
125 | 0 | throw new ConfigurationException("Document class '" + documentClass + "' is not assignable to '" + MaintenanceDocumentBase.class + "'"); |
126 | |
} |
127 | 0 | Document document = null; |
128 | |
try { |
129 | 0 | Class[] defaultConstructor = new Class[]{String.class}; |
130 | 0 | Constructor cons = documentClass.getConstructor(defaultConstructor); |
131 | 0 | if (ObjectUtils.isNull(cons)) { |
132 | 0 | throw new ConfigurationException("Could not find constructor with document type name parameter needed for Maintenance Document Base class"); |
133 | |
} |
134 | 0 | document = (Document) cons.newInstance(docTypeName); |
135 | 0 | } catch (SecurityException e) { |
136 | 0 | throw new RuntimeException("Error instantiating Maintenance Document", e); |
137 | 0 | } catch (NoSuchMethodException e) { |
138 | 0 | throw new RuntimeException("Error instantiating Maintenance Document: No constructor with String parameter found", e); |
139 | 0 | } catch (IllegalAccessException e) { |
140 | 0 | throw new RuntimeException("Error instantiating Maintenance Document", e); |
141 | 0 | } catch (InstantiationException e) { |
142 | 0 | throw new RuntimeException("Error instantiating Maintenance Document", e); |
143 | 0 | } catch (IllegalArgumentException e) { |
144 | 0 | throw new RuntimeException("Error instantiating Maintenance Document", e); |
145 | 0 | } catch (InvocationTargetException e) { |
146 | 0 | throw new RuntimeException("Error instantiating Maintenance Document", e); |
147 | 0 | } |
148 | 0 | if (document == null) { |
149 | 0 | throw new RuntimeException("Unable to instantiate document with type name '" + docTypeName + "' and document class '" + documentClass + "'"); |
150 | |
} |
151 | 0 | setDocument(document); |
152 | |
} |
153 | |
} |
154 | |
|
155 | 0 | MaintenanceDocumentBase maintenanceDocument = (MaintenanceDocumentBase) getDocument(); |
156 | |
|
157 | |
|
158 | 0 | for ( Object obj : requestParameters.entrySet() ) { |
159 | 0 | String parameter = (String)((Map.Entry)obj).getKey(); |
160 | 0 | if (parameter.toUpperCase().startsWith(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.toUpperCase())) { |
161 | 0 | String propertyName = parameter.substring(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.length()); |
162 | 0 | Object propertyValue = requestParameters.get(parameter); |
163 | |
|
164 | 0 | if(propertyValue != null && propertyValue instanceof FormFile) { |
165 | 0 | if(StringUtils.isNotEmpty(((FormFile)propertyValue).getFileName())) { |
166 | 0 | maintenanceDocument.setFileAttachment((FormFile) propertyValue); |
167 | |
} |
168 | 0 | maintenanceDocument.setAttachmentPropertyName(propertyName); |
169 | |
} |
170 | |
} |
171 | 0 | } |
172 | 0 | } |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
@Override |
178 | |
public void populate(HttpServletRequest request) { |
179 | 0 | super.populate(request); |
180 | |
|
181 | |
|
182 | |
|
183 | 0 | if (StringUtils.isNotBlank(getDocTypeName())) { |
184 | 0 | Map<String, String> localOldMaintainableValues = new HashMap<String, String>(); |
185 | 0 | Map<String, String> localNewMaintainableValues = new HashMap<String, String>(); |
186 | 0 | Map<String,String> localNewCollectionValues = new HashMap<String,String>(); |
187 | 0 | for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) { |
188 | 0 | String parameter = (String) i.nextElement(); |
189 | 0 | if (parameter.toUpperCase().startsWith(KNSConstants.MAINTENANCE_OLD_MAINTAINABLE.toUpperCase())) { |
190 | 0 | if (shouldPropertyBePopulatedInForm(parameter, request)) { |
191 | 0 | String propertyName = parameter.substring(KNSConstants.MAINTENANCE_OLD_MAINTAINABLE.length()); |
192 | 0 | localOldMaintainableValues.put(propertyName, request.getParameter(parameter)); |
193 | |
} |
194 | |
} |
195 | 0 | if (parameter.toUpperCase().startsWith(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.toUpperCase())) { |
196 | 0 | if (shouldPropertyBePopulatedInForm(parameter, request)) { |
197 | 0 | String propertyName = parameter.substring(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.length()); |
198 | 0 | localNewMaintainableValues.put(propertyName, request.getParameter(parameter)); |
199 | |
} |
200 | |
} |
201 | 0 | } |
202 | |
|
203 | |
|
204 | |
|
205 | 0 | for ( Map.Entry<String, String> entry : localNewMaintainableValues.entrySet() ) { |
206 | 0 | String key = entry.getKey(); |
207 | 0 | if ( key.startsWith( KNSConstants.MAINTENANCE_ADD_PREFIX ) ) { |
208 | 0 | localNewCollectionValues.put( key.substring( KNSConstants.MAINTENANCE_ADD_PREFIX.length() ), |
209 | |
entry.getValue() ); |
210 | |
} |
211 | 0 | } |
212 | 0 | if ( LOG.isDebugEnabled() ) { |
213 | 0 | LOG.debug( "checked for add line parameters - got: " + localNewCollectionValues ); |
214 | |
} |
215 | |
|
216 | 0 | this.newMaintainableValues = localNewMaintainableValues; |
217 | 0 | this.oldMaintainableValues = localOldMaintainableValues; |
218 | |
|
219 | 0 | MaintenanceDocumentBase maintenanceDocument = (MaintenanceDocumentBase) getDocument(); |
220 | |
|
221 | 0 | GlobalVariables.getMessageMap().addToErrorPath("document.oldMaintainableObject"); |
222 | 0 | maintenanceDocument.getOldMaintainableObject().populateBusinessObject(localOldMaintainableValues, maintenanceDocument, getMethodToCall()); |
223 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.oldMaintainableObject"); |
224 | |
|
225 | 0 | GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject"); |
226 | |
|
227 | 0 | Map cachedValues = |
228 | |
maintenanceDocument.getNewMaintainableObject().populateBusinessObject(localNewMaintainableValues, maintenanceDocument, getMethodToCall()); |
229 | |
|
230 | 0 | if(maintenanceDocument.getFileAttachment() != null) { |
231 | 0 | populateAttachmentPropertyForBO(maintenanceDocument); |
232 | |
} |
233 | |
|
234 | |
|
235 | 0 | localNewCollectionValues = KimApiServiceLocator.getPersonService().resolvePrincipalNamesToPrincipalIds((BusinessObject)maintenanceDocument.getNewMaintainableObject().getBusinessObject(), localNewCollectionValues); |
236 | 0 | cachedValues.putAll( maintenanceDocument.getNewMaintainableObject().populateNewCollectionLines( localNewCollectionValues, maintenanceDocument, getMethodToCall() ) ); |
237 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject"); |
238 | |
|
239 | 0 | if (cachedValues.size() > 0) { |
240 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_FORMATTING_ERROR); |
241 | 0 | for (Iterator iter = cachedValues.keySet().iterator(); iter.hasNext();) { |
242 | 0 | String propertyName = (String) iter.next(); |
243 | 0 | String value = (String) cachedValues.get(propertyName); |
244 | 0 | cacheUnconvertedValue(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE + propertyName, value); |
245 | 0 | } |
246 | |
} |
247 | |
} |
248 | 0 | } |
249 | |
|
250 | |
protected void populateAttachmentPropertyForBO(MaintenanceDocumentBase maintenanceDocument) { |
251 | |
try { |
252 | 0 | Class type = ObjectUtils.easyGetPropertyType(maintenanceDocument.getNewMaintainableObject().getBusinessObject(), maintenanceDocument.getAttachmentPropertyName()); |
253 | 0 | ObjectUtils.setObjectProperty(maintenanceDocument.getNewMaintainableObject().getBusinessObject(), maintenanceDocument.getAttachmentPropertyName(), type, maintenanceDocument.getFileAttachment()); |
254 | 0 | } catch (FormatException e) { |
255 | 0 | throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e); |
256 | 0 | } catch (IllegalAccessException e) { |
257 | 0 | throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e); |
258 | 0 | } catch (NoSuchMethodException e) { |
259 | 0 | throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e); |
260 | 0 | } catch (InvocationTargetException e) { |
261 | 0 | throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e); |
262 | 0 | } |
263 | 0 | } |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
public List getSections() { |
272 | 0 | if (getDocument() == null) { |
273 | 0 | throw new RuntimeException("Document not set in maintenance form."); |
274 | |
} |
275 | 0 | if (((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject() == null) { |
276 | 0 | throw new RuntimeException("New maintainable not set in document."); |
277 | |
} |
278 | 0 | if ((KNSConstants.MAINTENANCE_EDIT_ACTION.equals(this.getMaintenanceAction()) |
279 | |
|| KNSConstants.MAINTENANCE_COPY_ACTION.equals(this.getMaintenanceAction()) |
280 | |
|| KNSConstants.MAINTENANCE_DELETE_ACTION.equals(this.getMaintenanceAction())) |
281 | |
&& ((MaintenanceDocumentBase) getDocument()).getOldMaintainableObject() == null) { |
282 | 0 | throw new RuntimeException("Old maintainable not set in document."); |
283 | |
} |
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | 0 | List keyFieldNames = KNSServiceLocatorWeb.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject().getBusinessObject().getClass()); |
293 | |
|
294 | |
|
295 | 0 | Maintainable oldMaintainable = ((MaintenanceDocumentBase) getDocument()).getOldMaintainableObject(); |
296 | 0 | oldMaintainable.setMaintenanceAction(getMaintenanceAction()); |
297 | 0 | List oldMaintSections = oldMaintainable.getSections((MaintenanceDocument) getDocument(), null); |
298 | |
|
299 | 0 | Maintainable newMaintainable = ((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject(); |
300 | 0 | newMaintainable.setMaintenanceAction(getMaintenanceAction()); |
301 | 0 | List newMaintSections = newMaintainable.getSections((MaintenanceDocument) getDocument(), oldMaintainable); |
302 | 0 | KualiWorkflowDocument workflowDocument = this.getDocument().getDocumentHeader().getWorkflowDocument(); |
303 | 0 | String documentStatus = workflowDocument.getRouteHeader().getDocRouteStatus(); |
304 | 0 | String documentInitiatorPrincipalId = workflowDocument.getInitiatorPrincipalId(); |
305 | |
|
306 | |
|
307 | |
|
308 | 0 | List meshedSections = FieldUtils.meshSections(oldMaintSections, newMaintSections, keyFieldNames, getMaintenanceAction(), isReadOnly(), authorizations, documentStatus, documentInitiatorPrincipalId); |
309 | |
|
310 | 0 | return meshedSections; |
311 | |
} |
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
public String getMaintenanceAction() { |
317 | 0 | return maintenanceAction; |
318 | |
} |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
public String getBusinessObjectClassName() { |
324 | 0 | return businessObjectClassName; |
325 | |
} |
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
public void setBusinessObjectClassName(String businessObjectClassName) { |
331 | 0 | this.businessObjectClassName = businessObjectClassName; |
332 | 0 | } |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
public String getDescription() { |
338 | 0 | return description; |
339 | |
} |
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
public void setDescription(String description) { |
345 | 0 | this.description = description; |
346 | 0 | } |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
public boolean isReadOnly() { |
352 | 0 | return readOnly; |
353 | |
} |
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
public void setReadOnly(boolean readOnly) { |
359 | 0 | this.readOnly = readOnly; |
360 | 0 | } |
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
public Map getNewMaintainableValues() { |
366 | 0 | return newMaintainableValues; |
367 | |
} |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
public Map getOldMaintainableValues() { |
373 | 0 | return oldMaintainableValues; |
374 | |
} |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
public void setMaintenanceAction(String maintenanceAction) { |
380 | 0 | this.maintenanceAction = maintenanceAction; |
381 | 0 | } |
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
public MaintenanceDocumentRestrictions getAuthorizations() { |
389 | 0 | return authorizations; |
390 | |
} |
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
public void setAuthorizations(MaintenanceDocumentRestrictions authorizations) { |
398 | 0 | this.authorizations = authorizations; |
399 | 0 | } |
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
public void setNewMaintainableValues(Map newMaintainableValues) { |
407 | 0 | this.newMaintainableValues = newMaintainableValues; |
408 | 0 | } |
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
public void setOldMaintainableValues(Map oldMaintainableValues) { |
417 | 0 | this.oldMaintainableValues = oldMaintainableValues; |
418 | 0 | } |
419 | |
|
420 | |
|
421 | |
public String getLookupResultsSequenceNumber() { |
422 | 0 | return lookupResultsSequenceNumber; |
423 | |
} |
424 | |
|
425 | |
|
426 | |
public void setLookupResultsSequenceNumber(String lookupResultsSequenceNumber) { |
427 | 0 | this.lookupResultsSequenceNumber = lookupResultsSequenceNumber; |
428 | 0 | } |
429 | |
|
430 | |
|
431 | |
public String getLookupResultsBOClassName() { |
432 | 0 | return lookupResultsBOClassName; |
433 | |
} |
434 | |
|
435 | |
|
436 | |
public void setLookupResultsBOClassName(String lookupResultsBOClassName) { |
437 | 0 | this.lookupResultsBOClassName = lookupResultsBOClassName; |
438 | 0 | } |
439 | |
|
440 | |
|
441 | |
public String getLookedUpCollectionName() { |
442 | 0 | return lookedUpCollectionName; |
443 | |
} |
444 | |
|
445 | |
|
446 | |
public void setLookedUpCollectionName(String lookedUpCollectionName) { |
447 | 0 | this.lookedUpCollectionName = lookedUpCollectionName; |
448 | 0 | } |
449 | |
|
450 | |
public String getAdditionalSectionsFile() { |
451 | 0 | if ( businessObjectClassName != null ) { |
452 | |
try { |
453 | 0 | MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService(); |
454 | 0 | String docTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(Class.forName(businessObjectClassName)); |
455 | 0 | return maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(businessObjectClassName).getAdditionalSectionsFile(); |
456 | 0 | } catch ( ClassNotFoundException ex ) { |
457 | 0 | LOG.error( "Unable to resolve business object class", ex); |
458 | 0 | } |
459 | |
}else{ |
460 | 0 | MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService(); |
461 | 0 | return maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(this.getDocTypeName()).getAdditionalSectionsFile(); |
462 | |
} |
463 | 0 | return null; |
464 | |
} |
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
@Override |
472 | |
public String retrieveFormValueForLookupInquiryParameters(String parameterName, String parameterValueLocation) { |
473 | 0 | MaintenanceDocument maintDoc = (MaintenanceDocument) getDocument(); |
474 | 0 | if (parameterValueLocation.toLowerCase().startsWith(KNSConstants.MAINTENANCE_OLD_MAINTAINABLE.toLowerCase())) { |
475 | 0 | String propertyName = parameterValueLocation.substring(KNSConstants.MAINTENANCE_OLD_MAINTAINABLE.length()); |
476 | 0 | if (maintDoc.getOldMaintainableObject() != null && maintDoc.getOldMaintainableObject().getBusinessObject() != null) { |
477 | 0 | Object parameterValue = ObjectUtils.getPropertyValue(maintDoc.getOldMaintainableObject().getBusinessObject(), propertyName); |
478 | 0 | if (parameterValue == null) { |
479 | 0 | return null; |
480 | |
} |
481 | 0 | if (parameterValue instanceof String) { |
482 | 0 | return (String) parameterValue; |
483 | |
} |
484 | 0 | Formatter formatter = Formatter.getFormatter(parameterValue.getClass()); |
485 | 0 | return (String) formatter.format(parameterValue); |
486 | |
} |
487 | |
} |
488 | 0 | if (parameterValueLocation.toLowerCase().startsWith(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.toLowerCase())) { |
489 | |
|
490 | 0 | String propertyName = parameterValueLocation.substring(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.length()); |
491 | 0 | String addPrefix = KNSConstants.ADD_PREFIX.toLowerCase() + "."; |
492 | |
|
493 | 0 | if (propertyName.toLowerCase().startsWith(addPrefix)) { |
494 | 0 | propertyName = propertyName.substring(addPrefix.length()); |
495 | 0 | String collectionName = parseAddCollectionName(propertyName); |
496 | 0 | propertyName = propertyName.substring(collectionName.length()); |
497 | 0 | if (propertyName.startsWith(".")) { propertyName = propertyName.substring(1); } |
498 | 0 | PersistableBusinessObject newCollectionLine = |
499 | |
maintDoc.getNewMaintainableObject().getNewCollectionLine(collectionName); |
500 | 0 | Object parameterValue = ObjectUtils.getPropertyValue(newCollectionLine, propertyName); |
501 | 0 | if (parameterValue == null) { |
502 | 0 | return null; |
503 | |
} |
504 | 0 | if (parameterValue instanceof String) { |
505 | 0 | return (String) parameterValue; |
506 | |
} |
507 | 0 | Formatter formatter = Formatter.getFormatter(parameterValue.getClass()); |
508 | 0 | return (String) formatter.format(parameterValue); |
509 | 0 | } else if (maintDoc.getNewMaintainableObject() != null && maintDoc.getNewMaintainableObject().getBusinessObject() != null) { |
510 | 0 | Object parameterValue = ObjectUtils.getPropertyValue(maintDoc.getNewMaintainableObject().getBusinessObject(), propertyName); |
511 | 0 | if (parameterValue == null) { |
512 | 0 | return null; |
513 | |
} |
514 | 0 | if (parameterValue instanceof String) { |
515 | 0 | return (String) parameterValue; |
516 | |
} |
517 | 0 | Formatter formatter = Formatter.getFormatter(parameterValue.getClass()); |
518 | 0 | return (String) formatter.format(parameterValue); |
519 | |
} |
520 | |
} |
521 | 0 | return super.retrieveFormValueForLookupInquiryParameters(parameterName, parameterValueLocation); |
522 | |
} |
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
protected String parseAddCollectionName(String propertyName) { |
532 | 0 | StringBuilder collectionNameBuilder = new StringBuilder(); |
533 | |
|
534 | 0 | boolean firstPathElement = true; |
535 | 0 | for (String pathElement : propertyName.split("\\.")) if (!StringUtils.isBlank(pathElement)) { |
536 | 0 | if (firstPathElement) { |
537 | 0 | firstPathElement = false; |
538 | |
} else { |
539 | 0 | collectionNameBuilder.append("."); |
540 | |
} |
541 | 0 | collectionNameBuilder.append(pathElement); |
542 | 0 | if (!(pathElement.endsWith("]") && pathElement.contains("["))) break; |
543 | |
} |
544 | 0 | String collectionName = collectionNameBuilder.toString(); |
545 | 0 | return collectionName; |
546 | |
} |
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
@Override |
555 | |
public boolean shouldPropertyBePopulatedInForm( |
556 | |
String requestParameterName, HttpServletRequest request) { |
557 | |
|
558 | |
|
559 | 0 | String methodToCallActionName = request.getParameter(KNSConstants.DISPATCH_REQUEST_PARAMETER); |
560 | 0 | if (StringUtils.equals(methodToCallActionName, KNSConstants.MAINTENANCE_COPY_METHOD_TO_CALL) || |
561 | |
StringUtils.equals(methodToCallActionName, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL) || |
562 | |
StringUtils.equals(methodToCallActionName, KNSConstants.MAINTENANCE_NEW_METHOD_TO_CALL) || |
563 | |
StringUtils.equals(methodToCallActionName, KNSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION) || |
564 | |
StringUtils.equals(methodToCallActionName, KNSConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) { |
565 | 0 | return true; |
566 | |
} |
567 | 0 | if ( StringUtils.indexOf(methodToCallActionName, KNSConstants.TOGGLE_INACTIVE_METHOD ) == 0 ) { |
568 | 0 | return true; |
569 | |
} |
570 | 0 | return super.shouldPropertyBePopulatedInForm(requestParameterName, request); |
571 | |
} |
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | |
@Override |
579 | |
public boolean shouldMethodToCallParameterBeUsed( |
580 | |
String methodToCallParameterName, |
581 | |
String methodToCallParameterValue, HttpServletRequest request) { |
582 | |
|
583 | 0 | if (StringUtils.equals(methodToCallParameterValue, KNSConstants.MAINTENANCE_COPY_METHOD_TO_CALL) || |
584 | |
StringUtils.equals(methodToCallParameterValue, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL) || |
585 | |
StringUtils.equals(methodToCallParameterValue, KNSConstants.MAINTENANCE_NEW_METHOD_TO_CALL) || |
586 | |
StringUtils.equals(methodToCallParameterValue, KNSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION) || |
587 | |
StringUtils.equals(methodToCallParameterValue, KNSConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) { |
588 | 0 | return true; |
589 | |
} |
590 | 0 | if ( StringUtils.indexOf(methodToCallParameterName, KNSConstants.DISPATCH_REQUEST_PARAMETER + "." + KNSConstants.TOGGLE_INACTIVE_METHOD ) == 0 ) { |
591 | 0 | return true; |
592 | |
} |
593 | 0 | return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, |
594 | |
methodToCallParameterValue, request); |
595 | |
} |
596 | |
} |
597 | |
|
598 | |
|