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