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