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