Coverage Report - org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiDocumentFormBase
0%
0/259
0%
0/96
1.833
 
 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  
 package org.kuali.rice.kns.web.struts.form;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.struts.action.ActionErrors;
 20  
 import org.apache.struts.action.ActionMapping;
 21  
 import org.apache.struts.upload.FormFile;
 22  
 import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
 23  
 import org.kuali.rice.core.util.RiceKeyConstants;
 24  
 import org.kuali.rice.core.web.format.NoOpStringFormatter;
 25  
 import org.kuali.rice.core.web.format.TimestampAMPMFormatter;
 26  
 import org.kuali.rice.kew.exception.WorkflowException;
 27  
 import org.kuali.rice.kim.bo.Person;
 28  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 29  
 import org.kuali.rice.kim.util.KimConstants;
 30  
 import org.kuali.rice.kns.bo.AdHocRoutePerson;
 31  
 import org.kuali.rice.kns.bo.AdHocRouteWorkgroup;
 32  
 import org.kuali.rice.kns.bo.Note;
 33  
 import org.kuali.rice.kns.datadictionary.DataDictionary;
 34  
 import org.kuali.rice.kns.datadictionary.DocumentEntry;
 35  
 import org.kuali.rice.kns.datadictionary.HeaderNavigation;
 36  
 import org.kuali.rice.kns.document.Document;
 37  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 38  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 39  
 import org.kuali.rice.kns.service.ModuleService;
 40  
 import org.kuali.rice.kns.service.SessionDocumentService;
 41  
 import org.kuali.rice.kns.util.GlobalVariables;
 42  
 import org.kuali.rice.kns.util.KNSConstants;
 43  
 import org.kuali.rice.kns.util.MessageMap;
 44  
 import org.kuali.rice.kns.util.ObjectUtils;
 45  
 import org.kuali.rice.kns.util.UrlFactory;
 46  
 import org.kuali.rice.kns.util.WebUtils;
 47  
 import org.kuali.rice.kns.web.derivedvaluesetter.DerivedValuesSetter;
 48  
 import org.kuali.rice.kns.web.ui.HeaderField;
 49  
 import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
 50  
 import org.springframework.util.AutoPopulatingList;
 51  
 
 52  
 import javax.servlet.http.HttpServletRequest;
 53  
 import java.io.Serializable;
 54  
 import java.util.ArrayList;
 55  
 import java.util.HashMap;
 56  
 import java.util.List;
 57  
 import java.util.Map;
 58  
 import java.util.Properties;
 59  
 
 60  
 /**
 61  
  * TODO we should not be referencing kew constants from this class and wedding ourselves to that workflow application This class is
 62  
  * the base action form for all documents.
 63  
  */
 64  
 public abstract class KualiDocumentFormBase extends KualiForm implements Serializable {
 65  
     private static final long serialVersionUID = 916061016201941821L;
 66  
 
 67  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiDocumentFormBase.class);
 68  
 
 69  
     private Document document;
 70  0
     private String annotation = "";
 71  
     private String command;
 72  
 
 73  
     private String docId;
 74  
     private String docTypeName;
 75  
 
 76  
     private List<String> additionalScriptFiles;
 77  
 
 78  
     private AdHocRoutePerson newAdHocRoutePerson;
 79  
     private AdHocRouteWorkgroup newAdHocRouteWorkgroup;
 80  
 
 81  
     private Note newNote;
 82  
     
 83  
     //TODO: is this still needed? I think it's obsolete now
 84  
     private List boNotes;
 85  
     
 86  0
     protected FormFile attachmentFile = new BlankFormFile();
 87  
 
 88  
     protected Map editingMode;
 89  
     protected Map documentActions;
 90  
     protected boolean suppressAllButtons;
 91  
     
 92  
     protected Map adHocActionRequestCodes;
 93  
     private boolean returnToActionList;
 94  
 
 95  
     // for session enhancement
 96  
     private String formKey;
 97  
     private String docNum;
 98  
     
 99  
 
 100  
     
 101  
     /**
 102  
      * Stores the error map from previous requests, so that we can continue to display error messages displayed during a previous request
 103  
      */
 104  
     private MessageMap errorMapFromPreviousRequest;
 105  
     
 106  
         /***
 107  
      * @see org.kuali.rice.kns.web.struts.form.KualiForm#addRequiredNonEditableProperties()
 108  
      */
 109  
     @Override
 110  
     public void addRequiredNonEditableProperties(){
 111  0
             super.addRequiredNonEditableProperties();
 112  0
             registerRequiredNonEditableProperty(KNSConstants.DOCUMENT_TYPE_NAME);
 113  0
             registerRequiredNonEditableProperty(KNSConstants.FORM_KEY);
 114  0
             registerRequiredNonEditableProperty(KNSConstants.NEW_NOTE_NOTE_TYPE_CODE);
 115  0
     }
 116  
 
 117  
         /**
 118  
          * @return the docNum
 119  
          */
 120  
         public String getDocNum() {
 121  0
                 return this.docNum;
 122  
         }
 123  
 
 124  
         /**
 125  
          * @param docNum
 126  
          *            the docNum to set
 127  
          */
 128  
         public void setDocNum(String docNum) {
 129  0
                 this.docNum = docNum;
 130  0
         }
 131  
     
 132  
     /**
 133  
      * no args constructor that just initializes things for us
 134  
      */
 135  
     @SuppressWarnings("unchecked")
 136  
         public KualiDocumentFormBase() {
 137  0
         super();
 138  
         
 139  0
         instantiateDocument();
 140  0
         newNote = new Note();
 141  0
         this.editingMode = new HashMap();
 142  
         //this.additionalScriptFiles = new AutoPopulatingList(String.class);
 143  0
         this.additionalScriptFiles = new AutoPopulatingList<String>(String.class);
 144  
 
 145  
         // set the initial record for persons up
 146  0
         newAdHocRoutePerson = new AdHocRoutePerson();
 147  
 
 148  
         // set the initial record for workgroups up
 149  0
         newAdHocRouteWorkgroup = new AdHocRouteWorkgroup();
 150  
 
 151  
         // to make sure it posts back the correct time
 152  0
         setFormatterType("document.documentHeader.note.finDocNotePostedDttmStamp", TimestampAMPMFormatter.class);
 153  0
         setFormatterType("document.documentHeader.note.attachment.finDocNotePostedDttmStamp", TimestampAMPMFormatter.class);
 154  
         //TODO: Chris - Notes: remove the above and change the below from boNotes when notes are finished
 155  
         //overriding note formatter to make sure they post back the full timestamp
 156  0
         setFormatterType("document.documentHeader.boNote.notePostedTimestamp",TimestampAMPMFormatter.class);
 157  0
         setFormatterType("document.documentBusinessObject.boNote.notePostedTimestamp",TimestampAMPMFormatter.class);
 158  
 
 159  0
         setFormatterType("editingMode", NoOpStringFormatter.class);
 160  0
         setFormatterType("editableAccounts", NoOpStringFormatter.class);
 161  
 
 162  0
         setDocumentActions(new HashMap());
 163  0
         suppressAllButtons = false;
 164  
         
 165  0
         initializeHeaderNavigationTabs();
 166  0
     }
 167  
 
 168  
     /**
 169  
      * Setup workflow doc in the document.
 170  
      */
 171  
     @Override
 172  
     public void populate(HttpServletRequest request) {
 173  0
         super.populate(request);
 174  
 
 175  0
         KualiWorkflowDocument workflowDocument = null;
 176  
 
 177  0
         if (hasDocumentId()) {
 178  
             // populate workflowDocument in documentHeader, if needed
 179  
                 // KULRICE-4444 Obtain Document Header using the Workflow Service to minimize overhead
 180  
             try {
 181  0
                 SessionDocumentService sessionDocumentService = KNSServiceLocatorWeb.getSessionDocumentService();
 182  0
                     workflowDocument = sessionDocumentService.getDocumentFromSession( GlobalVariables.getUserSession(), getDocument().getDocumentNumber());
 183  0
                           if ( workflowDocument == null)
 184  
                           {
 185  
                     // gets the workflow document from doc service, doc service will also set the workflow document in the
 186  
                     // user's session
 187  0
                                   Person person = KIMServiceLocator.getPersonService().getPersonByPrincipalName(KNSConstants.SYSTEM_USER);
 188  0
                                    workflowDocument = KNSServiceLocatorWeb.getWorkflowDocumentService().createWorkflowDocument(Long.valueOf(getDocument().getDocumentNumber()), person);
 189  0
                                    sessionDocumentService.addDocumentToUserSession(GlobalVariables.getUserSession(), workflowDocument);
 190  0
                                    if (workflowDocument == null)
 191  
                                    {
 192  0
                                            throw new WorkflowException("Unable to retrieve workflow document # " + getDocument().getDocumentNumber() + " from workflow document service createWorkflowDocument");
 193  
                                    }
 194  
                                    else
 195  
                                    {
 196  0
                                    LOG.debug("Retrieved workflow Document ID: " + workflowDocument.getRouteHeaderId().toString());
 197  
                                    }
 198  
                           }
 199  
 
 200  0
                 getDocument().getDocumentHeader().setWorkflowDocument(workflowDocument);
 201  0
             } catch (WorkflowException e) {
 202  0
                 LOG.warn("Error while instantiating workflowDoc", e);
 203  0
                 throw new RuntimeException("error populating documentHeader.workflowDocument", e);
 204  0
             }
 205  
         } 
 206  0
         if (workflowDocument != null) {
 207  
                 //Populate Document Header attributes
 208  0
                 populateHeaderFields(workflowDocument);
 209  
         }
 210  0
     }
 211  
     
 212  
     protected String getPersonInquiryUrlLink(Person user, String linkBody) {
 213  0
         StringBuffer urlBuffer = new StringBuffer();
 214  
         
 215  0
         if(user != null && StringUtils.isNotEmpty(linkBody) ) {
 216  0
                 ModuleService moduleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(Person.class);
 217  0
                 Map<String, String[]> parameters = new HashMap<String, String[]>();
 218  0
                 parameters.put(KimConstants.AttributeConstants.PRINCIPAL_ID, new String[] { user.getPrincipalId() });
 219  0
                 String inquiryUrl = moduleService.getExternalizableBusinessObjectInquiryUrl(Person.class, parameters);
 220  0
             if(!StringUtils.equals(KimConstants.EntityTypes.SYSTEM, user.getEntityTypeCode())){
 221  0
                     urlBuffer.append("<a href='");
 222  0
                     urlBuffer.append(inquiryUrl);
 223  0
                     urlBuffer.append("' ");
 224  0
                     urlBuffer.append("target='_blank'");
 225  0
                     urlBuffer.append("title='Person Inquiry'>");
 226  0
                     urlBuffer.append(linkBody);
 227  0
                     urlBuffer.append("</a>");
 228  
             } else{
 229  0
                     urlBuffer.append(linkBody);
 230  
             }
 231  
         }
 232  
         
 233  0
         return urlBuffer.toString();
 234  
     }
 235  
     
 236  
     protected String getDocumentHandlerUrl(String documentId) {
 237  0
         Properties parameters = new Properties();
 238  0
         parameters.put(KNSConstants.PARAMETER_DOC_ID, documentId);
 239  0
         parameters.put(KNSConstants.PARAMETER_COMMAND, KNSConstants.METHOD_DISPLAY_DOC_SEARCH_VIEW);
 240  0
         return UrlFactory.parameterizeUrl(KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.WORKFLOW_URL_KEY) + "/" + KNSConstants.DOC_HANDLER_ACTION, parameters);
 241  
     }
 242  
     
 243  
     protected String buildHtmlLink(String url, String linkBody) {
 244  0
         StringBuffer urlBuffer = new StringBuffer();
 245  
         
 246  0
         if(StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(linkBody) ) {
 247  0
             urlBuffer.append("<a href='").append(url).append("'>").append(linkBody).append("</a>");
 248  
         }
 249  
         
 250  0
         return urlBuffer.toString();
 251  
     }
 252  
     
 253  
     /**
 254  
          * This method is used to populate the list of header field objects (see {@link KualiForm#getDocInfo()}) displayed on
 255  
          * the Kuali document form display pages.
 256  
          * 
 257  
          * @param workflowDocument - the workflow document of the document being displayed (null is allowed)
 258  
          */
 259  
         public void populateHeaderFields(KualiWorkflowDocument workflowDocument) {
 260  0
                 getDocInfo().clear();
 261  0
                 getDocInfo().addAll(getStandardHeaderFields(workflowDocument));
 262  0
         }
 263  
 
 264  
         /**
 265  
          * This method returns a list of {@link HeaderField} objects that are used by default on Kuali document display pages. To
 266  
          * use this list and override an individual {@link HeaderField} object the id constants from
 267  
          * {@link KNSConstants.DocumentFormHeaderFieldIds} can be used to identify items from the list.
 268  
          * 
 269  
          * @param workflowDocument - the workflow document of the document being displayed (null is allowed)
 270  
          * @return a list of the standard fields displayed by default for all Kuali documents
 271  
          */
 272  
     protected List<HeaderField> getStandardHeaderFields(KualiWorkflowDocument workflowDocument) {
 273  0
             List<HeaderField> headerFields = new ArrayList<HeaderField>();
 274  0
             setNumColumns(2);
 275  
             // check for a document template number as that will dictate column numbering
 276  0
             HeaderField docTemplateNumber = null;
 277  0
         if ((ObjectUtils.isNotNull(getDocument())) && (ObjectUtils.isNotNull(getDocument().getDocumentHeader())) && (StringUtils.isNotBlank(getDocument().getDocumentHeader().getDocumentTemplateNumber()))) {
 278  0
                         String templateDocumentNumber = getDocument().getDocumentHeader().getDocumentTemplateNumber();
 279  0
                         docTemplateNumber = new HeaderField(KNSConstants.DocumentFormHeaderFieldIds.DOCUMENT_TEMPLATE_NUMBER, "DataDictionary.DocumentHeader.attributes.documentTemplateNumber", 
 280  
                                         templateDocumentNumber,        buildHtmlLink(getDocumentHandlerUrl(templateDocumentNumber), templateDocumentNumber));
 281  
                 }
 282  
         //Document Number            
 283  0
         HeaderField docNumber = new HeaderField("DataDictionary.DocumentHeader.attributes.documentNumber", workflowDocument != null? getDocument().getDocumentNumber() : null);
 284  0
         docNumber.setId(KNSConstants.DocumentFormHeaderFieldIds.DOCUMENT_NUMBER);
 285  0
         HeaderField docStatus = new HeaderField("DataDictionary.AttributeReferenceDummy.attributes.workflowDocumentStatus", workflowDocument != null? workflowDocument.getStatusDisplayValue() : null);
 286  0
         docStatus.setId(KNSConstants.DocumentFormHeaderFieldIds.DOCUMENT_WORKFLOW_STATUS);
 287  0
         String initiatorNetworkId = null;
 288  0
         Person user = null;
 289  0
             if (workflowDocument != null) {
 290  0
                        if (getInitiator() == null) {
 291  0
                             LOG.warn("User Not Found while attempting to build inquiry link for document header fields");
 292  
                     } else {
 293  0
                             user = getInitiator();
 294  0
                             initiatorNetworkId = getInitiator().getPrincipalName();
 295  
                     }
 296  
             }
 297  0
         String inquiryUrl = getPersonInquiryUrlLink(user, workflowDocument != null? initiatorNetworkId:null);
 298  
 
 299  0
         HeaderField docInitiator = new HeaderField(KNSConstants.DocumentFormHeaderFieldIds.DOCUMENT_INITIATOR, "DataDictionary.AttributeReferenceDummy.attributes.initiatorNetworkId", 
 300  
         workflowDocument != null? initiatorNetworkId : null, workflowDocument != null? inquiryUrl : null);
 301  
         
 302  0
         String createDateStr = null;
 303  0
         if(workflowDocument != null && workflowDocument.getCreateDate() != null) {
 304  0
             createDateStr = KNSServiceLocator.getDateTimeService().toString(workflowDocument.getCreateDate(), "hh:mm a MM/dd/yyyy");
 305  
         }
 306  
         
 307  0
         HeaderField docCreateDate = new HeaderField("DataDictionary.AttributeReferenceDummy.attributes.createDate", createDateStr);
 308  0
         docCreateDate.setId(KNSConstants.DocumentFormHeaderFieldIds.DOCUMENT_CREATE_DATE);
 309  0
         if (ObjectUtils.isNotNull(docTemplateNumber)) {
 310  0
                 setNumColumns(3);
 311  
         }
 312  
         
 313  0
         headerFields.add(docNumber);
 314  0
         headerFields.add(docStatus);
 315  0
         if (ObjectUtils.isNotNull(docTemplateNumber)) {
 316  0
                 headerFields.add(docTemplateNumber);
 317  
         }
 318  0
         headerFields.add(docInitiator);
 319  0
         headerFields.add(docCreateDate);
 320  0
         if (ObjectUtils.isNotNull(docTemplateNumber)) {
 321  
                 // adding an empty field so implementors do not have to worry about additional fields being put on the wrong row
 322  0
                 headerFields.add(HeaderField.EMPTY_FIELD);
 323  
         }
 324  0
             return headerFields;
 325  
     }    
 326  
 
 327  
     /**
 328  
      * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
 329  
      *      javax.servlet.http.HttpServletRequest)
 330  
      */
 331  
     @Override
 332  
     public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
 333  
         // check that annotation does not exceed 2000 characters
 334  0
         setAnnotation(StringUtils.stripToNull(getAnnotation()));
 335  0
         int diff = StringUtils.defaultString(getAnnotation()).length() - KNSConstants.DOCUMENT_ANNOTATION_MAX_LENGTH;
 336  0
         if (diff > 0) {
 337  0
             GlobalVariables.getMessageMap().putError("annotation", RiceKeyConstants.ERROR_DOCUMENT_ANNOTATION_MAX_LENGTH_EXCEEDED, new String[] { Integer.toString(KNSConstants.DOCUMENT_ANNOTATION_MAX_LENGTH), Integer.toString(diff) });
 338  
         }
 339  0
         return super.validate(mapping, request);
 340  
     }
 341  
 
 342  
     /**
 343  
      * @return true if this document was properly initialized with a DocumentHeader and related KualiWorkflowDocument
 344  
      */
 345  
     final public boolean isFormDocumentInitialized() {
 346  0
         boolean initialized = false;
 347  
 
 348  0
         if (document != null) {
 349  0
             if (document.getDocumentHeader() != null) {
 350  0
                 initialized = document.getDocumentHeader().hasWorkflowDocument();
 351  
             }
 352  
         }
 353  
 
 354  0
         return initialized;
 355  
     }
 356  
 
 357  
 
 358  
     /**
 359  
      * @return Map of editingModes for this document, as set during the most recent call to
 360  
      *         populate(javax.servlet.http.HttpServletRequest)
 361  
      */
 362  
     @SuppressWarnings("unchecked")
 363  
         public Map getEditingMode() {
 364  0
         return editingMode;
 365  
     }
 366  
 
 367  
     /**
 368  
      * Set editingMode for this document
 369  
      */
 370  
     @SuppressWarnings("unchecked")
 371  
         public void setEditingMode(Map editingMode) {
 372  0
         this.editingMode = editingMode;
 373  0
     }
 374  
     
 375  
     /**
 376  
          * @return the documentActions
 377  
          */
 378  
         @SuppressWarnings("unchecked")
 379  
         public Map getDocumentActions() {
 380  0
                 return this.documentActions;
 381  
         }
 382  
 
 383  
         /**
 384  
          * @param documentActions the documentActions to set
 385  
          */
 386  
         @SuppressWarnings("unchecked")
 387  
         public void setDocumentActions(Map documentActions) {
 388  0
                 this.documentActions = documentActions;
 389  0
         }
 390  
         
 391  
         
 392  
 
 393  
         /**
 394  
          * @param adHocActionRequestCodes the adHocActionRequestCodes to set
 395  
          */
 396  
         @SuppressWarnings("unchecked")
 397  
         public void setAdHocActionRequestCodes(Map adHocActionRequestCodes) {
 398  0
                 this.adHocActionRequestCodes = adHocActionRequestCodes;
 399  0
         }
 400  
 
 401  
         /**
 402  
      * @return a map of the possible action request codes that takes into account the users context on the document
 403  
      */
 404  
     @SuppressWarnings("unchecked")
 405  
         public Map getAdHocActionRequestCodes() {
 406  
         //Map adHocActionRequestCodes = new HashMap();
 407  
         //KNSServiceLocatorInternal.getDocumentHelperService()
 408  
         /*if (getWorkflowDocument() != null) {
 409  
             if (getWorkflowDocument().isFYIRequested()) {
 410  
                 adHocActionRequestCodes.put(KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 411  
             }
 412  
             else if (getWorkflowDocument().isAcknowledgeRequested()) {
 413  
                 adHocActionRequestCodes.put(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 414  
                 adHocActionRequestCodes.put(KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 415  
             }
 416  
             else if (getWorkflowDocument().isApprovalRequested() || getWorkflowDocument().isCompletionRequested() || getWorkflowDocument().stateIsInitiated() || getWorkflowDocument().stateIsSaved()) {
 417  
                 adHocActionRequestCodes.put(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 418  
                 adHocActionRequestCodes.put(KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 419  
                 adHocActionRequestCodes.put(KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
 420  
             }
 421  
         }*/
 422  0
         return adHocActionRequestCodes;
 423  
     }
 424  
 
 425  
 
 426  
     /**
 427  
      * @return the list of ad hoc routing persons
 428  
      */
 429  
     public List<AdHocRoutePerson> getAdHocRoutePersons() {
 430  0
         return document.getAdHocRoutePersons();
 431  
     }
 432  
 
 433  
 
 434  
     /**
 435  
      * @return attachmentFile
 436  
      */
 437  
     public FormFile getAttachmentFile() {
 438  0
         return attachmentFile;
 439  
     }
 440  
 
 441  
     /**
 442  
      * @param attachmentFile The attachmentFile to set.
 443  
      */
 444  
     public void setAttachmentFile(FormFile attachmentFile) {
 445  0
         this.attachmentFile = attachmentFile;
 446  0
     }
 447  
 
 448  
 
 449  
     /**
 450  
      * set the ad hoc routing persons list
 451  
      *
 452  
      * @param adHocRouteRecipients
 453  
      */
 454  
     public void setAdHocRoutePersons(List<AdHocRoutePerson> adHocRouteRecipients) {
 455  0
         document.setAdHocRoutePersons(adHocRouteRecipients);
 456  0
     }
 457  
 
 458  
     /**
 459  
      * get the ad hoc routing workgroup requests
 460  
      *
 461  
      * @return
 462  
      */
 463  
     public List<AdHocRouteWorkgroup> getAdHocRouteWorkgroups() {
 464  0
         return document.getAdHocRouteWorkgroups();
 465  
     }
 466  
 
 467  
     /**
 468  
      * set the ad hoc routing workgroup requests
 469  
      *
 470  
      * @param adHocRouteWorkgroups
 471  
      */
 472  
     public void setAdHocRouteWorkgroups(List<AdHocRouteWorkgroup> adHocRouteWorkgroups) {
 473  0
         document.setAdHocRouteWorkgroups(adHocRouteWorkgroups);
 474  0
     }
 475  
 
 476  
     /**
 477  
      * Special getter based on index to work with multi rows for ad hoc routing to persons struts page
 478  
      *
 479  
      * @param index
 480  
      * @return
 481  
      */
 482  
     public AdHocRoutePerson getAdHocRoutePerson(int index) {
 483  0
         while (getAdHocRoutePersons().size() <= index) {
 484  0
             getAdHocRoutePersons().add(new AdHocRoutePerson());
 485  
         }
 486  0
         return getAdHocRoutePersons().get(index);
 487  
     }
 488  
 
 489  
     /**
 490  
      * Special getter based on index to work with multi rows for ad hoc routing to workgroups struts page
 491  
      *
 492  
      * @param index
 493  
      * @return
 494  
      */
 495  
     public AdHocRouteWorkgroup getAdHocRouteWorkgroup(int index) {
 496  0
         while (getAdHocRouteWorkgroups().size() <= index) {
 497  0
             getAdHocRouteWorkgroups().add(new AdHocRouteWorkgroup());
 498  
         }
 499  0
         return getAdHocRouteWorkgroups().get(index);
 500  
     }
 501  
 
 502  
     /**
 503  
      * @return the new ad hoc route person object
 504  
      */
 505  
     public AdHocRoutePerson getNewAdHocRoutePerson() {
 506  0
         return newAdHocRoutePerson;
 507  
     }
 508  
 
 509  
     /**
 510  
      * set the new ad hoc route person object
 511  
      *
 512  
      * @param newAdHocRoutePerson
 513  
      */
 514  
     public void setNewAdHocRoutePerson(AdHocRoutePerson newAdHocRoutePerson) {
 515  0
         this.newAdHocRoutePerson = newAdHocRoutePerson;
 516  0
     }
 517  
 
 518  
     /**
 519  
      * @return the new ad hoc route workgroup object
 520  
      */
 521  
     public AdHocRouteWorkgroup getNewAdHocRouteWorkgroup() {
 522  0
         return newAdHocRouteWorkgroup;
 523  
     }
 524  
 
 525  
     /**
 526  
      * set the new ad hoc route workgroup object
 527  
      *
 528  
      * @param newAdHocRouteWorkgroup
 529  
      */
 530  
     public void setNewAdHocRouteWorkgroup(AdHocRouteWorkgroup newAdHocRouteWorkgroup) {
 531  0
         this.newAdHocRouteWorkgroup = newAdHocRouteWorkgroup;
 532  0
     }
 533  
 
 534  
     /**
 535  
      * @return Returns the Document
 536  
      */
 537  
     public Document getDocument() {
 538  0
         return document;
 539  
     }
 540  
 
 541  
     /**
 542  
      * @param document
 543  
      */
 544  
     public void setDocument(Document document) {
 545  0
         this.document = document;
 546  0
         if(document != null && StringUtils.isNotEmpty(document.getDocumentNumber())) {
 547  0
             populateHeaderFields(document.getDocumentHeader().getWorkflowDocument());
 548  
         }
 549  0
     }
 550  
 
 551  
     /**
 552  
      * @return WorkflowDocument for this form's document
 553  
      */
 554  
     public KualiWorkflowDocument getWorkflowDocument() {
 555  0
         return getDocument().getDocumentHeader().getWorkflowDocument();
 556  
     }
 557  
     
 558  
     /**
 559  
          *  Null-safe check to see if the workflow document object exists before attempting to retrieve it.
 560  
      *  (Which, if called, will throw an exception.)
 561  
          */
 562  
     public boolean isHasWorkflowDocument() {
 563  0
             if ( getDocument() == null || getDocument().getDocumentHeader() == null ) {
 564  0
                     return false;
 565  
             }
 566  0
             return getDocument().getDocumentHeader().hasWorkflowDocument();
 567  
     }
 568  
 
 569  
     /**
 570  
      * TODO rk implemented to account for caps coming from kuali user service from workflow
 571  
      */
 572  
     public boolean isUserDocumentInitiator() {
 573  0
         if (getWorkflowDocument() != null) {
 574  0
             return getWorkflowDocument().getRouteHeader().getInitiatorPrincipalId().equalsIgnoreCase(
 575  
                             GlobalVariables.getUserSession().getPrincipalId());
 576  
         }
 577  0
         return false;
 578  
     }
 579  
 
 580  
     public Person getInitiator() {
 581  0
             String initiatorPrincipalId = getWorkflowDocument().getRouteHeader().getInitiatorPrincipalId();
 582  0
             return KIMServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
 583  
     }
 584  
 
 585  
     /**
 586  
      * @return true if the workflowDocument associated with this form is currently enroute
 587  
      */
 588  
     public boolean isDocumentEnRoute() {
 589  0
         return getWorkflowDocument().stateIsEnroute();
 590  
     }
 591  
 
 592  
     /**
 593  
      * @param annotation The annotation to set.
 594  
      */
 595  
     public void setAnnotation(String annotation) {
 596  0
         this.annotation = annotation;
 597  0
     }
 598  
 
 599  
     /**
 600  
      * @return Returns the annotation.
 601  
      */
 602  
     public String getAnnotation() {
 603  0
         return annotation;
 604  
     }
 605  
 
 606  
     /**
 607  
      * @return returns the command that was passed from workflow
 608  
      */
 609  
     public String getCommand() {
 610  0
         return command;
 611  
     }
 612  
 
 613  
     /**
 614  
      * setter for the command that was passed from workflow on the url
 615  
      *
 616  
      * @param command
 617  
      */
 618  
     public void setCommand(String command) {
 619  0
         this.command = command;
 620  0
     }
 621  
 
 622  
     /**
 623  
      * @return returns the docId that was passed from workflow on the url
 624  
      */
 625  
     public String getDocId() {
 626  0
         return docId;
 627  
     }
 628  
 
 629  
     /**
 630  
      * setter for the docId that was passed from workflow on the url
 631  
      *
 632  
      * @param docId
 633  
      */
 634  
     public void setDocId(String docId) {
 635  0
         this.docId = docId;
 636  0
     }
 637  
 
 638  
     /**
 639  
      * getter for the docTypeName that was passed from workflow on the url
 640  
      *
 641  
      * @return
 642  
      */
 643  
     public String getDocTypeName() {
 644  0
         return docTypeName;
 645  
     }
 646  
 
 647  
     /**
 648  
      * setter for the docTypeName that was passed from workflow on the url
 649  
      *
 650  
      * @param docTypeName
 651  
      */
 652  
     public void setDocTypeName(String docTypeName) {
 653  0
         this.docTypeName = docTypeName;
 654  0
     }
 655  
 
 656  
     /**
 657  
      * getter for convenience that will return the initiators network id
 658  
      *
 659  
      * @return
 660  
      */
 661  
     public String getInitiatorNetworkId() {
 662  0
         return this.getWorkflowDocument().getRouteHeader().getInitiatorPrincipalId();
 663  
     }
 664  
 
 665  
     /**
 666  
      * Gets the suppressAllButtons attribute.
 667  
      *
 668  
      * @return Returns the suppressAllButtons.
 669  
      */
 670  
     public final boolean isSuppressAllButtons() {
 671  0
         return suppressAllButtons;
 672  
     }
 673  
 
 674  
     /**
 675  
      * Sets the suppressAllButtons attribute value.
 676  
      *
 677  
      * @param suppressAllButtons The suppressAllButtons to set.
 678  
      */
 679  
     public final void setSuppressAllButtons(boolean suppressAllButtons) {
 680  0
         this.suppressAllButtons = suppressAllButtons;
 681  0
     }
 682  
 
 683  
     /**
 684  
      * @return true if this form's getDocument() method returns a Document, and if that Document's getDocumentHeaderId method
 685  
      *         returns a non-null
 686  
      */
 687  
     public boolean hasDocumentId() {
 688  0
         boolean hasDocId = false;
 689  
 
 690  0
         Document d = getDocument();
 691  0
         if (d != null) {
 692  0
             String docHeaderId = d.getDocumentNumber();
 693  
 
 694  0
             hasDocId = StringUtils.isNotBlank(docHeaderId);
 695  
         }
 696  
 
 697  0
         return hasDocId;
 698  
     }
 699  
 
 700  
     /**
 701  
      * Sets flag indicating whether upon completion of approve, blanketApprove, cancel, or disapprove, the user should be returned
 702  
      * to the actionList instead of to the portal
 703  
      *
 704  
      * @param returnToActionList
 705  
      */
 706  
     public void setReturnToActionList(boolean returnToActionList) {
 707  0
         this.returnToActionList = returnToActionList;
 708  0
     }
 709  
 
 710  
     public boolean isReturnToActionList() {
 711  0
         return returnToActionList;
 712  
     }
 713  
 
 714  
     public List<String> getAdditionalScriptFiles() {
 715  0
         return additionalScriptFiles;
 716  
     }
 717  
 
 718  
     public void setAdditionalScriptFiles(List<String> additionalScriptFiles) {
 719  0
         this.additionalScriptFiles = additionalScriptFiles;
 720  0
     }
 721  
 
 722  
     public void setAdditionalScriptFile( int index, String scriptFile ) {
 723  0
         additionalScriptFiles.set( index, scriptFile );
 724  0
         }
 725  
 
 726  
     public String getAdditionalScriptFile( int index ) {
 727  0
         return additionalScriptFiles.get( index );
 728  
     }
 729  
 
 730  
     public Note getNewNote() {
 731  0
         return newNote;
 732  
     }
 733  
 
 734  
     public void setNewNote(Note newNote) {
 735  0
         this.newNote = newNote;
 736  0
     }
 737  
 
 738  
     /**
 739  
      * Gets the boNotes attribute. 
 740  
      * @return Returns the boNotes.
 741  
      */
 742  
     @SuppressWarnings("unchecked")
 743  
         public List getBoNotes() {
 744  0
         return boNotes;
 745  
     }
 746  
 
 747  
     /**
 748  
      * Sets the boNotes attribute value.
 749  
      * @param boNotes The boNotes to set.
 750  
      */
 751  
     @SuppressWarnings("unchecked")
 752  
         public void setBoNotes(List boNotes) {
 753  0
         this.boNotes = boNotes;
 754  0
     }
 755  
 
 756  
     public String getFormKey() {
 757  0
         return this.formKey;
 758  
     }
 759  
 
 760  
     public void setFormKey(String formKey) {
 761  0
         this.formKey = formKey;
 762  0
     }
 763  
 
 764  
     /* Reset method
 765  
      * This is initially created for session document implementation
 766  
      * @param mapping
 767  
      * @param request
 768  
      */
 769  
     @Override
 770  
     public void reset(ActionMapping mapping, HttpServletRequest request) {
 771  0
             super.reset(mapping, request);
 772  0
         this.setMethodToCall(null);
 773  0
         this.setRefreshCaller(null);
 774  0
         this.setAnchor(null);
 775  0
         this.setCurrentTabIndex(0);
 776  
         
 777  0
     }
 778  
 
 779  
     
 780  
     /**
 781  
      * Adds the attachment file size to the list of max file sizes.
 782  
      * 
 783  
      * @see org.kuali.rice.kns.web.struts.pojo.PojoFormBase#customInitMaxUploadSizes()
 784  
      */
 785  
     @Override
 786  
     protected void customInitMaxUploadSizes() {
 787  0
         super.customInitMaxUploadSizes();
 788  0
         addMaxUploadSize(CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KNSConstants.KNS_NAMESPACE, KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KNSConstants.ATTACHMENT_MAX_FILE_SIZE_PARM_NM));
 789  0
     }
 790  
 
 791  
     
 792  
     
 793  
         /**
 794  
          * This overridden method ...
 795  
          * IMPORTANT: any overrides of this method must ensure that nothing in the HTTP request will be used to determine whether document is in session 
 796  
          * 
 797  
          * @see org.kuali.rice.kns.web.struts.pojo.PojoFormBase#shouldPropertyBePopulatedInForm(java.lang.String, javax.servlet.http.HttpServletRequest)
 798  
          */
 799  
         @Override
 800  
         public boolean shouldPropertyBePopulatedInForm(String requestParameterName, HttpServletRequest request) {
 801  0
                 for ( String prefix : KNSConstants.ALWAYS_VALID_PARAMETER_PREFIXES ) {
 802  0
                         if (requestParameterName.startsWith(prefix)) {
 803  0
                                 return true;
 804  
                         }
 805  
                 }
 806  
 
 807  0
                 if (StringUtils.equalsIgnoreCase(getMethodToCall(), KNSConstants.DOC_HANDLER_METHOD)) {
 808  0
                         return true;
 809  
                 }
 810  0
                 if (WebUtils.isDocumentSession(getDocument(), this)) {
 811  0
                         return isPropertyEditable(requestParameterName) || isPropertyNonEditableButRequired(requestParameterName);
 812  
                 }
 813  0
                 return true;
 814  
         }
 815  
 
 816  
         /**
 817  
          * This overridden method ...
 818  
          * 
 819  
          * @see org.kuali.rice.kns.web.struts.form.KualiForm#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
 820  
          */
 821  
         @Override
 822  
         public boolean shouldMethodToCallParameterBeUsed(
 823  
                         String methodToCallParameterName,
 824  
                         String methodToCallParameterValue, HttpServletRequest request) {
 825  0
                 if (StringUtils.equals(methodToCallParameterName, KNSConstants.DISPATCH_REQUEST_PARAMETER) &&
 826  
                                 StringUtils.equals(methodToCallParameterValue, KNSConstants.DOC_HANDLER_METHOD)) {
 827  0
                         return true;
 828  
                 }
 829  0
                 return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName,
 830  
                                 methodToCallParameterValue, request);
 831  
         }
 832  
         
 833  
         public MessageMap getMessageMapFromPreviousRequest() {
 834  0
                 return this.errorMapFromPreviousRequest;
 835  
         }
 836  
         
 837  
         public void setMessageMapFromPreviousRequest(MessageMap errorMapFromPreviousRequest) {
 838  0
                 this.errorMapFromPreviousRequest = errorMapFromPreviousRequest;
 839  0
         }
 840  
         
 841  
         @Override
 842  
         public void setDerivedValuesOnForm(HttpServletRequest request) {
 843  0
                 super.setDerivedValuesOnForm(request);
 844  
 
 845  0
                 String docTypeName = getDocTypeName();
 846  0
                 if (StringUtils.isNotBlank(docTypeName)) {
 847  0
                         DataDictionary dataDictionary = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary();
 848  0
                         Class<? extends DerivedValuesSetter> derivedValuesSetterClass = dataDictionary.getDocumentEntry(docTypeName).getDerivedValuesSetterClass();
 849  0
                         if (derivedValuesSetterClass != null) {
 850  0
                                 DerivedValuesSetter derivedValuesSetter = null;
 851  
                                 try {
 852  0
                                         derivedValuesSetter = derivedValuesSetterClass.newInstance();
 853  
                                 }
 854  0
                                 catch (Exception e) {
 855  0
                                         LOG.error("Unable to instantiate class " + derivedValuesSetterClass.getName(), e);
 856  0
                                         throw new RuntimeException("Unable to instantiate class " + derivedValuesSetterClass.getName(), e);
 857  0
                                 }
 858  0
                                 derivedValuesSetter.setDerivedValues(this, request);
 859  
                         }
 860  
                 }
 861  0
         }
 862  
         
 863  
         protected String getDefaultDocumentTypeName() {
 864  0
                 return "";
 865  
         }
 866  
         
 867  
         /** will instatiate a new document setting it on the form if {@link KualiDocumentFormBase#getDefaultDocumentTypeName()} is overriden to return a valid value. */
 868  
         protected void instantiateDocument() {
 869  0
                 if (document == null && StringUtils.isNotBlank(getDefaultDocumentTypeName())) {
 870  0
                         Class<? extends Document> documentClass = getDocumentClass();
 871  
                         try {
 872  0
                                 Document document = documentClass.newInstance();
 873  0
                                 setDocument(document);
 874  0
                         } catch (Exception e) {
 875  0
                                 LOG.error("Unable to instantiate document class " + documentClass.getName() + " document type " + getDefaultDocumentTypeName());
 876  0
                                 throw new RuntimeException(e);
 877  0
                         }
 878  
                 }
 879  0
         }
 880  
         
 881  
         /** gets the document class from the datadictionary if {@link KualiDocumentFormBase#getDefaultDocumentTypeName()} is overriden to return a valid value otherwise behavior is nondeterministic. */
 882  
         private Class<? extends Document> getDocumentClass() {
 883  0
                 return KNSServiceLocatorWeb.getDataDictionaryService().getDocumentClassByTypeName(getDefaultDocumentTypeName());
 884  
         }
 885  
         
 886  
         /**initializes the header tabs from what is defined in the datadictionary if {@link KualiDocumentFormBase#getDefaultDocumentTypeName()} is overriden to return a valid value. */
 887  
     protected void initializeHeaderNavigationTabs() {
 888  0
             if (StringUtils.isNotBlank(getDefaultDocumentTypeName())) {
 889  0
                     final DocumentEntry docEntry = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDocumentEntry(getDocumentClass().getName());
 890  0
                     final List<HeaderNavigation> navList = docEntry.getHeaderNavigationList();
 891  0
                     final HeaderNavigation[] list = new HeaderNavigation[navList.size()];
 892  0
                     super.setHeaderNavigationTabs(navList.toArray(list));
 893  
             }
 894  0
     } 
 895  
 }