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