Coverage Report - org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiMaintenanceForm
0%
0/227
0%
0/126
4.533
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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.api.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.MaintenanceDocument;
 28  
 import org.kuali.rice.kns.document.MaintenanceDocumentBase;
 29  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions;
 30  
 import org.kuali.rice.kns.maintenance.Maintainable;
 31  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 32  
 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
 33  
 import org.kuali.rice.kns.util.FieldUtils;
 34  
 import org.kuali.rice.krad.bo.BusinessObject;
 35  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 36  
 import org.kuali.rice.krad.datadictionary.exception.UnknownDocumentTypeException;
 37  
 import org.kuali.rice.krad.document.Document;
 38  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 39  
 import org.kuali.rice.krad.util.GlobalVariables;
 40  
 import org.kuali.rice.krad.util.KRADConstants;
 41  
 import org.kuali.rice.krad.util.ObjectUtils;
 42  
 
 43  
 import javax.servlet.http.HttpServletRequest;
 44  
 import java.lang.reflect.Constructor;
 45  
 import java.lang.reflect.InvocationTargetException;
 46  
 import java.util.Enumeration;
 47  
 import java.util.HashMap;
 48  
 import java.util.Iterator;
 49  
 import java.util.List;
 50  
 import java.util.Map;
 51  
 
 52  
 
 53  
 /**
 54  
  * This class is the base action form for all maintenance documents.
 55  
  * 
 56  
  * 
 57  
  */
 58  0
 public class KualiMaintenanceForm extends KualiDocumentFormBase {
 59  0
     protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiMaintenanceForm.class);
 60  
 
 61  
     protected static final long serialVersionUID = 1L;
 62  
 
 63  
     protected String businessObjectClassName;
 64  
     protected String description;
 65  
     protected boolean readOnly;
 66  
     protected Map<String, String> oldMaintainableValues;
 67  
     protected Map<String, String> newMaintainableValues;
 68  
     protected String maintenanceAction;
 69  
 
 70  
         /**
 71  
      * @see KualiDocumentFormBase#addRequiredNonEditableProperties()
 72  
      */
 73  
     @Override
 74  
     public void addRequiredNonEditableProperties(){
 75  0
             super.addRequiredNonEditableProperties();
 76  0
             registerRequiredNonEditableProperty(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE);
 77  0
             registerRequiredNonEditableProperty(KRADConstants.LOOKUP_RESULTS_BO_CLASS_NAME);
 78  0
             registerRequiredNonEditableProperty(KRADConstants.LOOKED_UP_COLLECTION_NAME);
 79  0
             registerRequiredNonEditableProperty(KRADConstants.LOOKUP_RESULTS_SEQUENCE_NUMBER);
 80  0
             registerRequiredNonEditableProperty(KRADConstants.FIELD_NAME_TO_FOCUS_ON_AFTER_SUBMIT);
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Used to indicate which result set we're using when refreshing/returning from a multi-value lookup
 85  
      */
 86  
     protected String lookupResultsSequenceNumber;
 87  
     /**
 88  
      * The type of result returned by the multi-value lookup
 89  
      * 
 90  
      * TODO: to be persisted in the lookup results service instead?
 91  
      */
 92  
     protected String lookupResultsBOClassName;
 93  
     
 94  
     /**
 95  
      * The name of the collection looked up (by a multiple value lookup)
 96  
      */
 97  
     protected String lookedUpCollectionName;
 98  
     
 99  
     protected MaintenanceDocumentRestrictions authorizations;
 100  
     
 101  
     /**
 102  
      * Override the default method to add the if statement which can't be called until after parameters from a multipart request
 103  
      * have been made accessible, but which must be called before the parameter values are used to instantiate and populate business
 104  
      * objects.
 105  
      * 
 106  
      * @param requestParameters
 107  
      */
 108  
     @Override
 109  
     public void postprocessRequestParameters(Map requestParameters) {
 110  0
         super.postprocessRequestParameters(requestParameters);
 111  
 
 112  0
         String docTypeName = null;
 113  0
         String[] docTypeNames = (String[]) requestParameters.get(KRADConstants.DOCUMENT_TYPE_NAME);
 114  0
         if ((docTypeNames != null) && (docTypeNames.length > 0)) {
 115  0
             docTypeName = docTypeNames[0];
 116  
         }
 117  
 
 118  0
         if (StringUtils.isNotBlank(docTypeName)) {          
 119  0
                 if(this.getDocument() == null){
 120  0
             setDocTypeName(docTypeName);
 121  0
             Class documentClass = KRADServiceLocatorWeb.getDataDictionaryService().getDocumentClassByTypeName(docTypeName);
 122  0
             if (documentClass == null) {
 123  0
                 throw new UnknownDocumentTypeException("unable to get class for unknown documentTypeName '" + docTypeName + "'");
 124  
             }
 125  0
             if (!MaintenanceDocumentBase.class.isAssignableFrom(documentClass)) {
 126  0
                 throw new ConfigurationException("Document class '" + documentClass + "' is not assignable to '" + MaintenanceDocumentBase.class + "'");
 127  
             }
 128  0
             Document document = null;
 129  
             try {
 130  0
                 Class[] defaultConstructor = new Class[]{String.class};
 131  0
                 Constructor cons = documentClass.getConstructor(defaultConstructor);
 132  0
                 if (ObjectUtils.isNull(cons)) {
 133  0
                     throw new ConfigurationException("Could not find constructor with document type name parameter needed for Maintenance Document Base class");
 134  
                 }
 135  0
                 document = (Document) cons.newInstance(docTypeName);
 136  0
             } catch (SecurityException e) {
 137  0
                 throw new RuntimeException("Error instantiating Maintenance Document", e);
 138  0
             } catch (NoSuchMethodException e) {
 139  0
                 throw new RuntimeException("Error instantiating Maintenance Document: No constructor with String parameter found", e);
 140  0
             } catch (IllegalAccessException e) {
 141  0
                 throw new RuntimeException("Error instantiating Maintenance Document", e);
 142  0
             } catch (InstantiationException e) {
 143  0
                 throw new RuntimeException("Error instantiating Maintenance Document", e);
 144  0
             } catch (IllegalArgumentException e) {
 145  0
                 throw new RuntimeException("Error instantiating Maintenance Document", e);
 146  0
             } catch (InvocationTargetException e) {
 147  0
                 throw new RuntimeException("Error instantiating Maintenance Document", e);
 148  0
             }
 149  0
             if (document == null) {
 150  0
                 throw new RuntimeException("Unable to instantiate document with type name '" + docTypeName + "' and document class '" + documentClass + "'");
 151  
             }
 152  0
             setDocument(document);
 153  
           } 
 154  
        }
 155  
         
 156  0
         MaintenanceDocumentBase maintenanceDocument = (MaintenanceDocumentBase) getDocument();
 157  
         
 158  
         //Handling the Multi-Part Attachment
 159  0
         for ( Object obj : requestParameters.entrySet() ) {
 160  0
             String parameter = (String)((Map.Entry)obj).getKey(); 
 161  0
             if (parameter.toUpperCase().startsWith(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.toUpperCase())) {
 162  0
                 String propertyName = parameter.substring(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.length());
 163  0
                 Object propertyValue = requestParameters.get(parameter);
 164  
                 
 165  0
                 if(propertyValue != null && propertyValue instanceof FormFile) {
 166  0
                     if(StringUtils.isNotEmpty(((FormFile)propertyValue).getFileName())) {
 167  0
                         maintenanceDocument.setFileAttachment((FormFile) propertyValue);
 168  
                     }
 169  0
                     maintenanceDocument.setAttachmentPropertyName(propertyName);
 170  
                 }
 171  
             }
 172  0
         }
 173  0
     }
 174  
 
 175  
     /**
 176  
      * Hook into populate so we can set the maintenance documents and feed the field values to its maintainables.
 177  
      */
 178  
     @Override
 179  
     public void populate(HttpServletRequest request) {
 180  0
         super.populate(request);
 181  
 
 182  
 
 183  
         // document type name is null on start, otherwise should be here
 184  0
         if (StringUtils.isNotBlank(getDocTypeName())) {
 185  0
             Map<String, String> localOldMaintainableValues = new HashMap<String, String>();
 186  0
             Map<String, String> localNewMaintainableValues = new HashMap<String, String>();
 187  0
             Map<String,String> localNewCollectionValues = new HashMap<String,String>();
 188  0
             for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
 189  0
                 String parameter = (String) i.nextElement();
 190  0
                 if (parameter.toUpperCase().startsWith(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE.toUpperCase())) {
 191  0
                         if (shouldPropertyBePopulatedInForm(parameter, request)) {
 192  0
                         String propertyName = parameter.substring(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE.length());
 193  0
                         localOldMaintainableValues.put(propertyName, request.getParameter(parameter));
 194  
                     }
 195  
                 }
 196  0
                 if (parameter.toUpperCase().startsWith(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.toUpperCase())) {
 197  0
                         if (shouldPropertyBePopulatedInForm(parameter, request)) {
 198  0
                         String propertyName = parameter.substring(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.length());
 199  0
                         localNewMaintainableValues.put(propertyName, request.getParameter(parameter));
 200  
                     }
 201  
                 }
 202  0
             }
 203  
             
 204  
             // now, get all add lines and store them to a separate map
 205  
             // for use in a separate call to the maintainable
 206  0
             for ( Map.Entry<String, String> entry : localNewMaintainableValues.entrySet() ) {
 207  0
                 String key = entry.getKey(); 
 208  0
                 if ( key.startsWith( KRADConstants.MAINTENANCE_ADD_PREFIX ) ) {
 209  0
                     localNewCollectionValues.put( key.substring( KRADConstants.MAINTENANCE_ADD_PREFIX.length() ),
 210  
                             entry.getValue() );
 211  
                 }
 212  0
             }
 213  0
             if ( LOG.isDebugEnabled() ) {
 214  0
                 LOG.debug( "checked for add line parameters - got: " + localNewCollectionValues );
 215  
             }
 216  
             
 217  0
             this.newMaintainableValues = localNewMaintainableValues;
 218  0
             this.oldMaintainableValues = localOldMaintainableValues;
 219  
 
 220  0
             MaintenanceDocumentBase maintenanceDocument = (MaintenanceDocumentBase) getDocument();
 221  
 
 222  0
             GlobalVariables.getMessageMap().addToErrorPath("document.oldMaintainableObject");
 223  0
             maintenanceDocument.getOldMaintainableObject().populateBusinessObject(localOldMaintainableValues, maintenanceDocument, getMethodToCall());
 224  0
             GlobalVariables.getMessageMap().removeFromErrorPath("document.oldMaintainableObject");
 225  
 
 226  0
             GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject");
 227  
             // update the main object
 228  0
             Map cachedValues = 
 229  
                     maintenanceDocument.getNewMaintainableObject().populateBusinessObject(localNewMaintainableValues, maintenanceDocument, getMethodToCall());
 230  
             
 231  0
             if(maintenanceDocument.getFileAttachment() != null) {
 232  0
                 populateAttachmentPropertyForBO(maintenanceDocument);
 233  
             }
 234  
             
 235  
             // update add lines
 236  0
             localNewCollectionValues = KimApiServiceLocator.getPersonService().resolvePrincipalNamesToPrincipalIds((BusinessObject)maintenanceDocument.getNewMaintainableObject().getBusinessObject(), localNewCollectionValues);
 237  0
             cachedValues.putAll( maintenanceDocument.getNewMaintainableObject().populateNewCollectionLines( localNewCollectionValues, maintenanceDocument, getMethodToCall() ) );
 238  0
             GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject");
 239  
 
 240  0
             if (cachedValues.size() > 0) {
 241  0
                 GlobalVariables.getMessageMap().putError(KRADConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_FORMATTING_ERROR);
 242  0
                 for (Iterator iter = cachedValues.keySet().iterator(); iter.hasNext();) {
 243  0
                     String propertyName = (String) iter.next();
 244  0
                     String value = (String) cachedValues.get(propertyName);
 245  0
                     cacheUnconvertedValue(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + propertyName, value);
 246  0
                 }
 247  
             }
 248  
         }
 249  0
     }
 250  
 
 251  
     protected void populateAttachmentPropertyForBO(MaintenanceDocumentBase maintenanceDocument) {
 252  
         try {
 253  0
             Class type = ObjectUtils.easyGetPropertyType(maintenanceDocument.getNewMaintainableObject().getBusinessObject(), maintenanceDocument.getAttachmentPropertyName());
 254  0
             ObjectUtils.setObjectProperty(maintenanceDocument.getNewMaintainableObject().getBusinessObject(), maintenanceDocument.getAttachmentPropertyName(), type, maintenanceDocument.getFileAttachment());
 255  0
         } catch (FormatException e) {
 256  0
             throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e);
 257  0
         } catch (IllegalAccessException e) {
 258  0
             throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e);
 259  0
         } catch (NoSuchMethodException e) {
 260  0
             throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e);
 261  0
         } catch (InvocationTargetException e) {
 262  0
             throw new RuntimeException("Exception occurred while setting attachment property on NewMaintainable bo", e);
 263  0
         }
 264  0
     }
 265  
     
 266  
     /**
 267  
      * Merges rows of old and new for each section (tab) of the ui. Also, renames fields to prevent naming conflicts and does
 268  
      * setting of read only fields.
 269  
      * 
 270  
      * @return Returns the maintenanceSections.
 271  
      */
 272  
     public List getSections() {
 273  0
         if (getDocument() == null) {
 274  0
             throw new RuntimeException("Document not set in maintenance form.");
 275  
         }
 276  0
         if (((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject() == null) {
 277  0
             throw new RuntimeException("New maintainable not set in document.");
 278  
         }
 279  0
         if ((KRADConstants.MAINTENANCE_EDIT_ACTION.equals(this.getMaintenanceAction())
 280  
                         || KRADConstants.MAINTENANCE_COPY_ACTION.equals(this.getMaintenanceAction())
 281  
                         || KRADConstants.MAINTENANCE_DELETE_ACTION.equals(this.getMaintenanceAction()))
 282  
                         && ((MaintenanceDocumentBase) getDocument()).getOldMaintainableObject() == null) {
 283  0
             throw new RuntimeException("Old maintainable not set in document.");
 284  
         }
 285  
 
 286  
         // if the authorization stuff hasnt been applied yet, then apply it
 287  
         //if (authorizations == null) {
 288  
         //    applyAuthorizations();
 289  
         //}
 290  
 
 291  
         
 292  
         // get business object being maintained and its keys
 293  0
         List keyFieldNames = KNSServiceLocator.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject().getBusinessObject().getClass());
 294  
 
 295  
         // sections for maintenance document
 296  0
         Maintainable oldMaintainable = ((MaintenanceDocumentBase) getDocument()).getOldMaintainableObject();
 297  0
         oldMaintainable.setMaintenanceAction(getMaintenanceAction());
 298  0
         List oldMaintSections = oldMaintainable.getSections((MaintenanceDocument) getDocument(), null);
 299  
         
 300  0
         Maintainable newMaintainable = ((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject();
 301  0
         newMaintainable.setMaintenanceAction(getMaintenanceAction());
 302  0
         List newMaintSections = newMaintainable.getSections((MaintenanceDocument) getDocument(), oldMaintainable);
 303  0
         WorkflowDocument workflowDocument = this.getDocument().getDocumentHeader().getWorkflowDocument();
 304  0
         String documentStatus =  workflowDocument.getStatus().getCode();
 305  0
         String documentInitiatorPrincipalId = workflowDocument.getInitiatorPrincipalId();
 306  
         
 307  
 
 308  
         // mesh sections for proper jsp display
 309  0
         List meshedSections = FieldUtils
 310  
                 .meshSections(oldMaintSections, newMaintSections, keyFieldNames, getMaintenanceAction(), isReadOnly(),
 311  
                         authorizations, documentStatus, documentInitiatorPrincipalId);
 312  
 
 313  0
         return meshedSections;
 314  
     }    
 315  
 
 316  
     /**
 317  
      * @return Returns the maintenanceAction.
 318  
      */
 319  
     public String getMaintenanceAction() {
 320  0
         return maintenanceAction;
 321  
     }
 322  
 
 323  
     /**
 324  
      * @return Returns the businessObjectClassName.
 325  
      */
 326  
     public String getBusinessObjectClassName() {
 327  0
         return businessObjectClassName;
 328  
     }
 329  
 
 330  
     /**
 331  
      * @param businessObjectClassName The businessObjectClassName to set.
 332  
      */
 333  
     public void setBusinessObjectClassName(String businessObjectClassName) {
 334  0
         this.businessObjectClassName = businessObjectClassName;
 335  0
     }
 336  
 
 337  
     /**
 338  
      * @return Returns the description.
 339  
      */
 340  
     public String getDescription() {
 341  0
         return description;
 342  
     }
 343  
 
 344  
     /**
 345  
      * @param description The description to set.
 346  
      */
 347  
     public void setDescription(String description) {
 348  0
         this.description = description;
 349  0
     }
 350  
 
 351  
     /**
 352  
      * @return Returns the isReadOnly.
 353  
      */
 354  
     public boolean isReadOnly() {
 355  0
         return readOnly;
 356  
     }
 357  
 
 358  
     /**
 359  
      * @param readOnly The isReadOnly to set.
 360  
      */
 361  
     public void setReadOnly(boolean readOnly) {
 362  0
         this.readOnly = readOnly;
 363  0
     }
 364  
 
 365  
     /**
 366  
      * @return Returns the newMaintainableValues.
 367  
      */
 368  
     public Map getNewMaintainableValues() {
 369  0
         return newMaintainableValues;
 370  
     }
 371  
 
 372  
     /**
 373  
      * @return Returns the oldMaintainableValues.
 374  
      */
 375  
     public Map getOldMaintainableValues() {
 376  0
         return oldMaintainableValues;
 377  
     }
 378  
 
 379  
     /**
 380  
      * @param maintenanceAction The maintenanceAction to set.
 381  
      */
 382  
     public void setMaintenanceAction(String maintenanceAction) {
 383  0
         this.maintenanceAction = maintenanceAction;
 384  0
     }
 385  
 
 386  
     /**
 387  
      * Gets the authorizations attribute.
 388  
      * 
 389  
      * @return Returns the authorizations.
 390  
      */
 391  
     public MaintenanceDocumentRestrictions getAuthorizations() {
 392  0
         return authorizations;
 393  
     }
 394  
 
 395  
     /**
 396  
      * Sets the authorizations attribute value.
 397  
      * 
 398  
      * @param authorizations The authorizations to set.
 399  
      */
 400  
     public void setAuthorizations(MaintenanceDocumentRestrictions authorizations) {
 401  0
         this.authorizations = authorizations;
 402  0
     }
 403  
 
 404  
     /**
 405  
      * Sets the newMaintainableValues attribute value.
 406  
      * 
 407  
      * @param newMaintainableValues The newMaintainableValues to set.
 408  
      */
 409  
     public void setNewMaintainableValues(Map newMaintainableValues) {
 410  0
         this.newMaintainableValues = newMaintainableValues;
 411  0
     }
 412  
 
 413  
 
 414  
     /**
 415  
      * Sets the oldMaintainableValues attribute value.
 416  
      * 
 417  
      * @param oldMaintainableValues The oldMaintainableValues to set.
 418  
      */
 419  
     public void setOldMaintainableValues(Map oldMaintainableValues) {
 420  0
         this.oldMaintainableValues = oldMaintainableValues;
 421  0
     }
 422  
 
 423  
 
 424  
     public String getLookupResultsSequenceNumber() {
 425  0
         return lookupResultsSequenceNumber;
 426  
     }
 427  
 
 428  
 
 429  
     public void setLookupResultsSequenceNumber(String lookupResultsSequenceNumber) {
 430  0
         this.lookupResultsSequenceNumber = lookupResultsSequenceNumber;
 431  0
     }
 432  
 
 433  
 
 434  
     public String getLookupResultsBOClassName() {
 435  0
         return lookupResultsBOClassName;
 436  
     }
 437  
 
 438  
 
 439  
     public void setLookupResultsBOClassName(String lookupResultsBOClassName) {
 440  0
         this.lookupResultsBOClassName = lookupResultsBOClassName;
 441  0
     }
 442  
 
 443  
 
 444  
     public String getLookedUpCollectionName() {
 445  0
         return lookedUpCollectionName;
 446  
     }
 447  
 
 448  
 
 449  
     public void setLookedUpCollectionName(String lookedUpCollectionName) {
 450  0
         this.lookedUpCollectionName = lookedUpCollectionName;
 451  0
     }
 452  
 
 453  
     public String getAdditionalSectionsFile() {
 454  0
         if ( businessObjectClassName != null ) {
 455  
             try {
 456  0
                 MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = KNSServiceLocator
 457  
                         .getMaintenanceDocumentDictionaryService();
 458  0
                 String docTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(Class.forName(businessObjectClassName));
 459  0
                 return maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(businessObjectClassName).getAdditionalSectionsFile();
 460  0
             } catch ( ClassNotFoundException ex ) {
 461  0
                 LOG.error( "Unable to resolve business object class", ex);
 462  0
             }
 463  
         }else{
 464  0
             MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = KNSServiceLocator
 465  
                     .getMaintenanceDocumentDictionaryService();
 466  0
             return maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(this.getDocTypeName()).getAdditionalSectionsFile();
 467  
         }
 468  0
         return null;
 469  
     }
 470  
 
 471  
         /**
 472  
          * This overridden method handles the case where maint doc properties do not reflect the true nature of the 
 473  
          * 
 474  
          * @see KualiForm#retrieveFormValueForLookupInquiryParameters(java.lang.String, java.lang.String)
 475  
          */
 476  
         @Override
 477  
         public String retrieveFormValueForLookupInquiryParameters(String parameterName, String parameterValueLocation) {
 478  0
                 MaintenanceDocument maintDoc = (MaintenanceDocument) getDocument();
 479  0
                 if (parameterValueLocation.toLowerCase().startsWith(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE.toLowerCase())) {
 480  0
                         String propertyName = parameterValueLocation.substring(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE.length());
 481  0
                         if (maintDoc.getOldMaintainableObject() != null && maintDoc.getOldMaintainableObject().getBusinessObject() != null) {
 482  0
                                 Object parameterValue = ObjectUtils.getPropertyValue(maintDoc.getOldMaintainableObject().getBusinessObject(), propertyName);
 483  0
                                 if (parameterValue == null) {
 484  0
                                         return null;
 485  
                                 }
 486  0
                                 if (parameterValue instanceof String) {
 487  0
                                         return (String) parameterValue;
 488  
                                 }
 489  0
                                 Formatter formatter = Formatter.getFormatter(parameterValue.getClass());
 490  0
                                 return (String) formatter.format(parameterValue); 
 491  
                         }
 492  
                 }
 493  0
                 if (parameterValueLocation.toLowerCase().startsWith(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.toLowerCase())) {
 494  
                         // remove MAINT_NEW_MAINT from the pVL
 495  0
                         String propertyName = parameterValueLocation.substring(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.length());
 496  0
                         String addPrefix = KRADConstants.ADD_PREFIX.toLowerCase() + ".";
 497  
 
 498  0
                         if (propertyName.toLowerCase().startsWith(addPrefix)) { // 
 499  0
                                 propertyName = propertyName.substring(addPrefix.length()); // remove addPrefix from the propertyName
 500  0
                                 String collectionName = parseAddCollectionName(propertyName);
 501  0
                                 propertyName = propertyName.substring(collectionName.length()); // remove collectionName from pN
 502  0
                                 if (propertyName.startsWith(".")) { propertyName = propertyName.substring(1); } // strip beginning "."
 503  0
                                 PersistableBusinessObject newCollectionLine = 
 504  
                                         maintDoc.getNewMaintainableObject().getNewCollectionLine(collectionName);
 505  0
                                 Object parameterValue = ObjectUtils.getPropertyValue(newCollectionLine, propertyName);
 506  0
                                 if (parameterValue == null) {
 507  0
                                         return null;
 508  
                                 }
 509  0
                                 if (parameterValue instanceof String) {
 510  0
                                         return (String) parameterValue;
 511  
                                 }
 512  0
                                 Formatter formatter = Formatter.getFormatter(parameterValue.getClass());
 513  0
                                 return (String) formatter.format(parameterValue);
 514  0
                         } else if (maintDoc.getNewMaintainableObject() != null && maintDoc.getNewMaintainableObject().getBusinessObject() != null) {
 515  0
                                 Object parameterValue = ObjectUtils.getPropertyValue(maintDoc.getNewMaintainableObject().getBusinessObject(), propertyName);
 516  0
                                 if (parameterValue == null) {
 517  0
                                         return null;
 518  
                                 }
 519  0
                                 if (parameterValue instanceof String) {
 520  0
                                         return (String) parameterValue;
 521  
                                 }
 522  0
                                 Formatter formatter = Formatter.getFormatter(parameterValue.getClass());
 523  0
                                 return (String) formatter.format(parameterValue); 
 524  
                         }
 525  
                 }
 526  0
                 return super.retrieveFormValueForLookupInquiryParameters(parameterName, parameterValueLocation);
 527  
         }
 528  
 
 529  
         /**
 530  
          * This method returns the collection name (including nested collections) from a propertyName string
 531  
          * 
 532  
          * @param propertyName a parameterValueLocation w/ KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +
 533  
          * KRADConstants.ADD_PREFIX + "." stripped off the front
 534  
          * @return the collectionName
 535  
          */
 536  
         protected String parseAddCollectionName(String propertyName) {
 537  0
                 StringBuilder collectionNameBuilder = new StringBuilder();
 538  
 
 539  0
                 boolean firstPathElement = true;
 540  0
                 for (String pathElement : propertyName.split("\\.")) if (!StringUtils.isBlank(pathElement)) {
 541  0
                         if (firstPathElement) {
 542  0
                                 firstPathElement = false;
 543  
                         } else {
 544  0
                                 collectionNameBuilder.append(".");
 545  
                         }
 546  0
                         collectionNameBuilder.append(pathElement);
 547  0
                         if (!(pathElement.endsWith("]") && pathElement.contains("["))) break; 
 548  
                 }
 549  0
                 String collectionName = collectionNameBuilder.toString();
 550  0
                 return collectionName;
 551  
         }
 552  
 
 553  
 
 554  
         /**
 555  
          * This overridden method ...
 556  
          * 
 557  
          * @see KualiDocumentFormBase#shouldPropertyBePopulatedInForm(java.lang.String, javax.servlet.http.HttpServletRequest)
 558  
          */
 559  
         @Override
 560  
         public boolean shouldPropertyBePopulatedInForm(
 561  
                         String requestParameterName, HttpServletRequest request) {
 562  
                 // the user clicked on a document initiation link
 563  
                 //add delete check for 3070
 564  0
                 String methodToCallActionName = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
 565  0
                 if (StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL) ||
 566  
                                 StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL) ||
 567  
                                 StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL) ||
 568  
                                 StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION) ||
 569  
                                 StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) {
 570  0
                         return true;
 571  
                 }
 572  0
                 if ( StringUtils.indexOf(methodToCallActionName, KRADConstants.TOGGLE_INACTIVE_METHOD ) == 0 ) {
 573  0
                         return true;
 574  
                 }
 575  0
                 return super.shouldPropertyBePopulatedInForm(requestParameterName, request);
 576  
         }
 577  
 
 578  
         /**
 579  
          * This overridden method ...
 580  
          * 
 581  
          * @see KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
 582  
          */
 583  
         @Override
 584  
         public boolean shouldMethodToCallParameterBeUsed(
 585  
                         String methodToCallParameterName,
 586  
                         String methodToCallParameterValue, HttpServletRequest request) {
 587  
                 // the user clicked on a document initiation link
 588  0
                 if (StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL) ||
 589  
                                 StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL) ||
 590  
                                 StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL) ||
 591  
                                 StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION) ||
 592  
                                 StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) {
 593  0
                         return true;
 594  
                 }
 595  0
                 if ( StringUtils.indexOf(methodToCallParameterName, KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TOGGLE_INACTIVE_METHOD ) == 0 ) {
 596  0
                         return true;
 597  
                 }
 598  0
                 return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName,
 599  
                                 methodToCallParameterValue, request);
 600  
         }
 601  
 }
 602  
 
 603