Coverage Report - org.kuali.rice.krad.web.controller.DocumentControllerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentControllerBase
0%
0/137
0%
0/50
2.619
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.controller;
 17  
 
 18  
 import org.apache.commons.lang.ArrayUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.util.RiceKeyConstants;
 21  
 import org.kuali.rice.core.framework.parameter.ParameterConstants;
 22  
 import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
 23  
 import org.kuali.rice.kew.api.WorkflowDocument;
 24  
 import org.kuali.rice.kew.exception.WorkflowException;
 25  
 import org.kuali.rice.kew.util.KEWConstants;
 26  
 import org.kuali.rice.kim.bo.Person;
 27  
 import org.kuali.rice.krad.bo.AdHocRouteRecipient;
 28  
 import org.kuali.rice.krad.bo.Attachment;
 29  
 import org.kuali.rice.krad.bo.Note;
 30  
 import org.kuali.rice.krad.document.Document;
 31  
 import org.kuali.rice.krad.exception.DocumentAuthorizationException;
 32  
 import org.kuali.rice.krad.exception.UnknownDocumentIdException;
 33  
 import org.kuali.rice.krad.exception.ValidationException;
 34  
 import org.kuali.rice.krad.question.ConfirmationQuestion;
 35  
 import org.kuali.rice.krad.service.BusinessObjectService;
 36  
 import org.kuali.rice.krad.service.DataDictionaryService;
 37  
 import org.kuali.rice.krad.service.DocumentHelperService;
 38  
 import org.kuali.rice.krad.service.DocumentService;
 39  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 40  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 41  
 import org.kuali.rice.krad.uif.UifParameters;
 42  
 import org.kuali.rice.krad.uif.container.CollectionGroup;
 43  
 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
 44  
 import org.kuali.rice.krad.util.GlobalVariables;
 45  
 import org.kuali.rice.krad.util.KRADConstants;
 46  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 47  
 import org.kuali.rice.krad.util.SessionTicket;
 48  
 import org.kuali.rice.krad.web.form.DocumentFormBase;
 49  
 import org.kuali.rice.krad.web.form.UifFormBase;
 50  
 import org.springframework.util.FileCopyUtils;
 51  
 import org.springframework.validation.BindingResult;
 52  
 import org.springframework.web.bind.ServletRequestBindingException;
 53  
 import org.springframework.web.bind.annotation.ModelAttribute;
 54  
 import org.springframework.web.bind.annotation.RequestMapping;
 55  
 import org.springframework.web.bind.annotation.RequestMethod;
 56  
 import org.springframework.web.multipart.MultipartFile;
 57  
 import org.springframework.web.servlet.ModelAndView;
 58  
 
 59  
 import javax.servlet.http.HttpServletRequest;
 60  
 import javax.servlet.http.HttpServletResponse;
 61  
 
 62  
 import java.io.FileNotFoundException;
 63  
 import java.io.IOException;
 64  
 import java.io.InputStream;
 65  
 import java.util.ArrayList;
 66  
 import java.util.HashMap;
 67  
 import java.util.Map;
 68  
 
 69  
 /**
 70  
  * Base controller class for all KRAD <code>DocumentView</code> screens working
 71  
  * with <code>Document</code> models
 72  
  * 
 73  
  * <p>
 74  
  * Provides default controller implementations for the standard document actions
 75  
  * including: doc handler (retrieve from doc search and action list), save,
 76  
  * route (and other KEW actions)
 77  
  * </p>
 78  
  * 
 79  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 80  
  */
 81  0
 public abstract class DocumentControllerBase extends UifControllerBase {
 82  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentControllerBase.class);
 83  
 
 84  
         // COMMAND constants which cause docHandler to load an existing document
 85  
         // instead of creating a new one
 86  0
         protected static final String[] DOCUMENT_LOAD_COMMANDS = { KEWConstants.ACTIONLIST_COMMAND,
 87  
                         KEWConstants.DOCSEARCH_COMMAND, KEWConstants.SUPERUSER_COMMAND, KEWConstants.HELPDESK_ACTIONLIST_COMMAND };
 88  
 
 89  
         private BusinessObjectService businessObjectService;
 90  
         private DataDictionaryService dataDictionaryService;
 91  
         private DocumentService documentService;
 92  
         private DocumentHelperService documentHelperService;
 93  
 
 94  
         @Override
 95  
         public abstract DocumentFormBase createInitialForm(HttpServletRequest request);
 96  
 
 97  
         /**
 98  
          * Used to funnel all document handling through, we could do useful things
 99  
          * like log and record various openings and status Additionally it may be
 100  
          * nice to have a single dispatcher that can know how to dispatch to a
 101  
          * redirect url for document specific handling but we may not need that as
 102  
          * all we should need is the document to be able to load itself based on
 103  
          * document id and then which action forward or redirect is pertinent for
 104  
          * the document type.
 105  
          */
 106  
         @RequestMapping(params = "methodToCall=docHandler")
 107  
         public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request,
 108  
                         HttpServletResponse response) throws Exception {
 109  0
                 String command = form.getCommand();
 110  
 
 111  
                 // in all of the following cases we want to load the document
 112  0
                 if (ArrayUtils.contains(DOCUMENT_LOAD_COMMANDS, command) && form.getDocId() != null) {
 113  0
                         loadDocument(form);
 114  
                 }
 115  0
                 else if (KEWConstants.INITIATE_COMMAND.equals(command)) {
 116  0
                         createDocument(form);
 117  
                 }
 118  
                 else {
 119  0
                         LOG.error("docHandler called with invalid parameters");
 120  0
                         throw new IllegalStateException("docHandler called with invalid parameters");
 121  
                 }
 122  
 
 123  
                 // TODO: authorization on document actions
 124  
                 // if (KEWConstants.SUPERUSER_COMMAND.equalsIgnoreCase(command)) {
 125  
                 // form.setSuppressAllButtons(true);
 126  
                 // }
 127  
 
 128  0
                 return getUIFModelAndView(form);
 129  
         }
 130  
 
 131  
         /**
 132  
          * Loads the document by its provided document header id. This has been
 133  
          * abstracted out so that it can be overridden in children if the need
 134  
          * arises.
 135  
          * 
 136  
          * @param form
 137  
          *            - form instance that contains the doc id parameter and where
 138  
          *            the retrieved document instance should be set
 139  
          */
 140  
         protected void loadDocument(DocumentFormBase form) throws WorkflowException {
 141  0
                 String docId = form.getDocId();
 142  
 
 143  0
                 Document doc = null;
 144  0
                 doc = getDocumentService().getByDocumentHeaderId(docId);
 145  0
                 if (doc == null) {
 146  0
                         throw new UnknownDocumentIdException(
 147  
                                         "Document no longer exists.  It may have been cancelled before being saved.");
 148  
                 }
 149  
 
 150  0
                 WorkflowDocument workflowDocument = doc.getDocumentHeader().getWorkflowDocument();
 151  0
                 if (!getDocumentHelperService().getDocumentAuthorizer(doc).canOpen(doc,
 152  
                                 GlobalVariables.getUserSession().getPerson())) {
 153  0
                         throw buildAuthorizationException("open", doc);
 154  
                 }
 155  
 
 156  
                 // re-retrieve the document using the current user's session - remove
 157  
                 // the system user from the WorkflowDcument object
 158  0
                 if (workflowDocument != doc.getDocumentHeader().getWorkflowDocument()) {
 159  0
                         LOG.warn("Workflow document changed via canOpen check");
 160  0
                         doc.getDocumentHeader().setWorkflowDocument(workflowDocument);
 161  
                 }
 162  
 
 163  0
                 form.setDocument(doc);
 164  0
                 WorkflowDocument workflowDoc = doc.getDocumentHeader().getWorkflowDocument();
 165  0
                 form.setDocTypeName(workflowDoc.getDocumentTypeName());
 166  
 
 167  0
                 KRADServiceLocatorWeb.getSessionDocumentService().addDocumentToUserSession(GlobalVariables.getUserSession(), workflowDoc);
 168  0
         }
 169  
 
 170  
         /**
 171  
          * Creates a new document of the type specified by the docTypeName property
 172  
          * of the given form. This has been abstracted out so that it can be
 173  
          * overridden in children if the need arises.
 174  
          * 
 175  
          * @param form
 176  
          *            - form instance that contains the doc type parameter and where
 177  
          *            the new document instance should be set
 178  
          */
 179  
         protected void createDocument(DocumentFormBase form) throws WorkflowException {
 180  0
                 Document doc = getDocumentService().getNewDocument(form.getDocTypeName());
 181  
 
 182  0
                 form.setDocument(doc);
 183  0
                 form.setDocTypeName(doc.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
 184  0
         }
 185  
 
 186  
         /**
 187  
          * Saves the <code>Document</code> instance
 188  
          */
 189  
         @RequestMapping(params = "methodToCall=save")
 190  
         public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request,
 191  
                         HttpServletResponse response) throws Exception {
 192  
 
 193  0
                 doProcessingAfterPost(form, request);
 194  
 
 195  
                 // get any possible changes to to adHocWorkgroups
 196  
                 // TODO turn this back on
 197  
                 // refreshAdHocRoutingWorkgroupLookups(request, form);
 198  
 
 199  0
                 Document document = form.getDocument();
 200  
 
 201  0
                 String viewName = checkAndWarnAboutSensitiveData(form, request, response,
 202  
                                 KRADPropertyConstants.DOCUMENT_EXPLANATION, document.getDocumentHeader().getExplanation(), "save", "");
 203  
                 // TODO if the happens we may need to save form to session or account
 204  
                 // for it
 205  0
                 if (viewName != null) {
 206  0
                         return new ModelAndView(viewName);
 207  
                 }
 208  
 
 209  
                 try {
 210  
                     // save in workflow
 211  0
                     getDocumentService().saveDocument(document);
 212  
 
 213  
             // TODO: should add message to message map
 214  
                     //GlobalVariables.getMessageList().add(RiceKeyConstants.MESSAGE_SAVED);
 215  0
                     form.setAnnotation("");
 216  
                 }
 217  0
                 catch(ValidationException vex) {
 218  
                     // if errors in map, swallow exception so screen will draw with errors
 219  
                         // if not then throw runtime because something bad happened
 220  0
                         if(GlobalVariables.getMessageMap().hasNoErrors()) {
 221  0
                                 throw new RuntimeException("Validation Exception with no error message.", vex);
 222  
                         }
 223  0
                 }
 224  
 
 225  0
                 return getUIFModelAndView(form);
 226  
         }
 227  
 
 228  
         /**
 229  
          * Routes the <code>Document</code> instance using the document service
 230  
          */
 231  
         @RequestMapping(params = "methodToCall=route")
 232  
         public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request,
 233  
                         HttpServletResponse response) throws Exception {
 234  0
                 doProcessingAfterPost(form, request);
 235  
 
 236  
                 // TODO: prerules
 237  
                 // kualiDocumentFormBase.setDerivedValuesOnForm(request);
 238  
                 // ActionForward preRulesForward = promptBeforeValidation(mapping, form,
 239  
                 // request, response);
 240  
                 // if (preRulesForward != null) {
 241  
                 // return preRulesForward;
 242  
                 // }
 243  
 
 244  0
                 Document document = form.getDocument();
 245  
 
 246  0
                 String viewName = checkAndWarnAboutSensitiveData(form, request, response,
 247  
                                 KRADPropertyConstants.DOCUMENT_EXPLANATION, document.getDocumentHeader().getExplanation(), "route", "");
 248  0
                 if (viewName != null) {
 249  0
                         return new ModelAndView(viewName);
 250  
                 }
 251  
 
 252  
                 // TODO: adhoc recipients
 253  
                 // getDocumentService().routeDocument(document, form.getAnnotation(),
 254  
                 // combineAdHocRecipients(kualiDocumentFormBase));
 255  0
                 getDocumentService().routeDocument(document, form.getAnnotation(), new ArrayList<AdHocRouteRecipient>());
 256  
 
 257  
         // TODO: should added message to message map
 258  
                 //GlobalVariables.getMessageList().add(RiceKeyConstants.MESSAGE_ROUTE_SUCCESSFUL);
 259  0
                 form.setAnnotation("");
 260  
 
 261  
                 // GlobalVariables.getUserSession().addObject(DocumentAuthorizerBase.USER_SESSION_METHOD_TO_CALL_COMPLETE_OBJECT_KEY,Boolean.TRUE);
 262  0
                 return getUIFModelAndView(form);
 263  
         }
 264  
 
 265  
     
 266  
     /**
 267  
      * Called by the add note action for adding a note. Method
 268  
      * validates, saves attachment and adds the time stamp and author.
 269  
      * Calls the UifControllerBase.addLine method to handle 
 270  
      * generic actions.
 271  
      *
 272  
      */
 273  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=insertNote")
 274  
     public ModelAndView insertNote(@ModelAttribute("KualiForm") UifFormBase uifForm,
 275  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
 276  
         
 277  
         // TODO : finish method , make sure it aligns with current KNS functionality
 278  
         
 279  
         // Get the note add line
 280  0
         String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
 281  0
         CollectionGroup collectionGroup = uifForm.getPreviousView().getViewIndex().getCollectionGroupByPath(selectedCollectionPath);
 282  0
         String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
 283  0
         Object addLine = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath);
 284  0
         Note newNote = (Note)addLine;
 285  0
         newNote.setNotePostedTimestampToCurrent();
 286  
         
 287  
         // Get the attachment file
 288  0
         String attachmentTypeCode = null;
 289  0
         MultipartFile attachmentFile = uifForm.getAttachmentFile();
 290  0
         if (attachmentFile == null) {
 291  0
             GlobalVariables.getMessageMap().putError(
 292  
                     String.format("%s.%s",
 293  
                             KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME,
 294  
                             KRADConstants.NOTE_ATTACHMENT_FILE_PROPERTY_NAME),
 295  
                     RiceKeyConstants.ERROR_UPLOADFILE_NULL);
 296  
             // This line was removed in order to continue to validates other
 297  
             // return mapping.findForward(RiceConstants.MAPPING_BASIC);
 298  
         }
 299  
         
 300  0
         if (newNote.getAttachment() != null) {
 301  0
             attachmentTypeCode = newNote.getAttachment().getAttachmentTypeCode();
 302  
         }
 303  
 
 304  
         // TODO check authorization for adding notes
 305  
 //        DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(document);
 306  
 //        if (!documentAuthorizer.canAddNoteAttachment(document, attachmentTypeCode, GlobalVariables.getUserSession().getPerson())) {
 307  
 //            throw buildAuthorizationException("annotate", document);
 308  
 //        }
 309  
         
 310  0
         Attachment attachment = null;
 311  0
         if (attachmentFile != null && !StringUtils.isBlank(attachmentFile.getOriginalFilename())) {
 312  0
             if (attachmentFile.getSize() == 0) {
 313  0
                 GlobalVariables.getMessageMap().putError(
 314  
                         String.format("%s.%s",
 315  
                                 KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME,
 316  
                                 KRADConstants.NOTE_ATTACHMENT_FILE_PROPERTY_NAME),
 317  
                         RiceKeyConstants.ERROR_UPLOADFILE_EMPTY,
 318  
                         attachmentFile.getOriginalFilename());
 319  
                 // This line was removed in order to continue to validates other
 320  
 //                return mapping.findForward(RiceConstants.MAPPING_BASIC);
 321  
             } else {
 322  0
                 String attachmentType = null;
 323  
                 try {
 324  0
                     attachment = KRADServiceLocator.getAttachmentService().createAttachment(((DocumentFormBase)uifForm).getDocument().getNoteTarget(), attachmentFile.getOriginalFilename(), attachmentFile.getContentType(), (int)attachmentFile.getSize(), attachmentFile.getInputStream(), "");
 325  0
                     newNote.addAttachment(attachment);
 326  0
                 } catch (IOException e) {
 327  0
                     e.printStackTrace();
 328  0
                 }
 329  
             }
 330  
         }      
 331  
         
 332  
         // Add the author
 333  0
         Person kualiUser = GlobalVariables.getUserSession().getPerson();
 334  0
         if (kualiUser == null) {
 335  0
             throw new IllegalStateException("Current UserSession has a null Person.");
 336  
         }
 337  0
         newNote.setAuthorUniversalIdentifier(kualiUser.getPrincipalId());
 338  
         
 339  0
         Note tmpNote = KRADServiceLocator.getNoteService().createNote(newNote, ((DocumentFormBase)uifForm).getDocument().getNoteTarget(), kualiUser.getPrincipalId());
 340  
         
 341  0
         return addLine(uifForm, result, request, response);
 342  
     }    
 343  
     
 344  
     /**
 345  
      * Called by the delete note action for deleting a note. 
 346  
      * Calls the UifControllerBase.deleteLine method to handle 
 347  
      * generic actions.
 348  
      * 
 349  
      */
 350  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteNote")
 351  
     public ModelAndView deleteNote(@ModelAttribute("KualiForm") UifFormBase uifForm,
 352  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
 353  
         // TODO : add note specific logic
 354  0
         return deleteLine(uifForm, result, request, response);
 355  
     }     
 356  
     
 357  
     /**
 358  
      * Called by the download attachment action on a note. Method
 359  
      * gets the attachment input stream from the AttachmentService
 360  
      * and writes it to the request output stream.
 361  
      * 
 362  
      */
 363  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=downloadAttachment")
 364  
     public ModelAndView downloadAttachment(@ModelAttribute("KualiForm") UifFormBase uifForm,
 365  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) throws ServletRequestBindingException, FileNotFoundException, IOException {
 366  
         // Get the attachment input stream
 367  0
         String selectedLineIndex = uifForm.getActionParamaterValue("selectedLineIndex");
 368  0
         Note note = ((DocumentFormBase)uifForm).getDocument().getNote(Integer.parseInt(selectedLineIndex));
 369  0
         Attachment attachment = note.getAttachment();
 370  0
         InputStream is = KRADServiceLocator.getAttachmentService().retrieveAttachmentContents(attachment);
 371  
         
 372  
         // Set the response headers
 373  0
         response.setContentType(attachment.getAttachmentMimeTypeCode());
 374  0
         response.setContentLength(attachment.getAttachmentFileSize().intValue());
 375  0
         response.setHeader("Expires", "0");
 376  0
         response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
 377  0
         response.setHeader("Pragma", "public");
 378  0
         response.setHeader("Content-Disposition","attachment; filename=\"" + attachment.getAttachmentFileName() + "\"");
 379  
         
 380  
         // Copy the input stream to the response
 381  0
         FileCopyUtils.copy(is, response.getOutputStream());
 382  0
         return null;
 383  
     }     
 384  
 
 385  
     /**
 386  
      * Called by the cancel attachment action on a note. Method
 387  
      * removes the attachment file from the form.
 388  
      * 
 389  
      */
 390  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=cancelAttachment")
 391  
     public ModelAndView cancelAttachment(@ModelAttribute("KualiForm") UifFormBase uifForm,
 392  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
 393  
         // Remove the attached file
 394  0
         uifForm.setAttachmentFile(null);
 395  0
         return getUIFModelAndView(uifForm);
 396  
     }
 397  
             
 398  
         
 399  
         
 400  
         
 401  
         /**
 402  
          * Does all special processing on a document that should happen on each HTTP
 403  
          * post (ie, save, route, approve, etc).
 404  
          * 
 405  
          * @param form
 406  
          * @param request
 407  
          */
 408  
         protected void doProcessingAfterPost(DocumentFormBase form, HttpServletRequest request) {
 409  0
                 getBusinessObjectService().linkUserFields(form.getDocument());
 410  0
         }
 411  
 
 412  
         // TODO this needs more analysis before porting can finish
 413  
         /*
 414  
          * protected void refreshAdHocRoutingWorkgroupLookups(HttpServletRequest
 415  
          * request, DocumentFormBase form) throws WorkflowException { for
 416  
          * (Enumeration<String> i = request.getParameterNames();
 417  
          * i.hasMoreElements();) { String parameterName = i.nextElement();
 418  
          * 
 419  
          * // TODO does this really belong in the loop if
 420  
          * (parameterName.equals("newAdHocRouteWorkgroup.recipientName") &&
 421  
          * !"".equals(request.getParameter(parameterName))) { //check for namespace
 422  
          * String namespace = KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE; if
 423  
          * (request.getParameter("newAdHocRouteWorkgroup.recipientNamespaceCode") !=
 424  
          * null &&
 425  
          * !"".equals(request.getParameter("newAdHocRouteWorkgroup.recipientName"
 426  
          * ).trim())) {
 427  
          * 
 428  
          * namespace =
 429  
          * request.getParameter("newAdHocRouteWorkgroup.recipientNamespaceCode"
 430  
          * ).trim(); } Group group =
 431  
          * getIdentityManagementService().getGroupByName(namespace,
 432  
          * request.getParameter(parameterName)); if (group != null) {
 433  
          * form.getNewAdHocRouteWorkgroup().setId(group.getGroupId());
 434  
          * form.getNewAdHocRouteWorkgroup().setRecipientName(group.getGroupName());
 435  
          * form
 436  
          * .getNewAdHocRouteWorkgroup().setRecipientNamespaceCode(group.getNamespaceCode
 437  
          * ()); } else { throw new
 438  
          * RuntimeException("Invalid workgroup id passed as parameter."); } }
 439  
          * 
 440  
          * // TODO need to look at screen, will most of this just be bound to the
 441  
          * form by spring? if (parameterName.startsWith("adHocRouteWorkgroup[") &&
 442  
          * !"".equals(request.getParameter(parameterName))) { if
 443  
          * (parameterName.endsWith(".recipientName")) { int lineNumber =
 444  
          * Integer.parseInt(StringUtils.substringBetween(parameterName, "[", "]"));
 445  
          * //check for namespace String namespaceParam = "adHocRouteWorkgroup[" +
 446  
          * lineNumber + "].recipientNamespaceCode"; String namespace =
 447  
          * KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE; if
 448  
          * (request.getParameter(namespaceParam) != null &&
 449  
          * !"".equals(request.getParameter(namespaceParam).trim())) { namespace =
 450  
          * request.getParameter(namespaceParam).trim(); } Group group =
 451  
          * getIdentityManagementService().getGroupByName(namespace,
 452  
          * request.getParameter(parameterName)); if (group != null) {
 453  
          * form.getAdHocRouteWorkgroup(lineNumber).setId(group.getGroupId());
 454  
          * form.getAdHocRouteWorkgroup
 455  
          * (lineNumber).setRecipientName(group.getGroupName());
 456  
          * form.getAdHocRouteWorkgroup
 457  
          * (lineNumber).setRecipientNamespaceCode(group.getNamespaceCode()); } else
 458  
          * { throw new
 459  
          * RuntimeException("Invalid workgroup id passed as parameter."); } } } } }
 460  
          */
 461  
 
 462  
         /**
 463  
          * Checks if the given value matches patterns that indicate sensitive data
 464  
          * and if configured to give a warning for sensitive data will prompt the
 465  
          * user to continue.
 466  
          * 
 467  
          * @param form
 468  
          * @param request
 469  
          * @param response
 470  
          * @param fieldName
 471  
          *            - name of field with value being checked
 472  
          * @param fieldValue
 473  
          *            - value to check for sensitive data
 474  
          * @param caller
 475  
          *            - method that should be called back from question
 476  
          * @param context
 477  
          *            - additional context that needs to be passed back with the
 478  
          *            question response
 479  
          * @return - view for spring to forward to, or null if processing should
 480  
          *         continue
 481  
          * @throws Exception
 482  
          */
 483  
         protected String checkAndWarnAboutSensitiveData(DocumentFormBase form, HttpServletRequest request,
 484  
                         HttpServletResponse response, String fieldName, String fieldValue, String caller, String context)
 485  
                         throws Exception {
 486  
 
 487  0
                 String viewName = null;
 488  0
                 Document document = form.getDocument();
 489  
 
 490  
         // TODO: need to move containsSensitiveDataPatternMatch to util class in krad
 491  0
         boolean containsSensitiveData = false;
 492  
                 //boolean containsSensitiveData = WebUtils.containsSensitiveDataPatternMatch(fieldValue);
 493  
 
 494  
                 // check if warning is configured in which case we will prompt, or if
 495  
                 // not business rules will thrown an error
 496  0
                 boolean warnForSensitiveData = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(
 497  
                                 KRADConstants.KRAD_NAMESPACE, ParameterConstants.ALL_COMPONENT,
 498  
                                 KRADConstants.SystemGroupParameterNames.SENSITIVE_DATA_PATTERNS_WARNING_IND);
 499  
 
 500  
                 // determine if the question has been asked yet
 501  0
                 Map<String, String> ticketContext = new HashMap<String, String>();
 502  0
                 ticketContext.put(KRADPropertyConstants.DOCUMENT_NUMBER, document.getDocumentNumber());
 503  0
                 ticketContext.put(KRADConstants.CALLING_METHOD, caller);
 504  0
                 ticketContext.put(KRADPropertyConstants.NAME, fieldName);
 505  
 
 506  0
                 boolean questionAsked = GlobalVariables.getUserSession().hasMatchingSessionTicket(
 507  
                                 KRADConstants.SENSITIVE_DATA_QUESTION_SESSION_TICKET, ticketContext);
 508  
 
 509  
                 // start in logic for confirming the sensitive data
 510  0
                 if (containsSensitiveData && warnForSensitiveData && !questionAsked) {
 511  0
                         Object question = request.getParameter(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME);
 512  0
                         if (question == null || !KRADConstants.DOCUMENT_SENSITIVE_DATA_QUESTION.equals(question)) {
 513  
 
 514  
                                 // TODO not ready for question framework yet
 515  
                                 /*
 516  
                                  * // question hasn't been asked, prompt to continue return
 517  
                                  * this.performQuestionWithoutInput(mapping, form, request,
 518  
                                  * response, KRADConstants.DOCUMENT_SENSITIVE_DATA_QUESTION,
 519  
                                  * getKualiConfigurationService()
 520  
                                  * .getPropertyValueAsString(RiceKeyConstants
 521  
                                  * .QUESTION_SENSITIVE_DATA_DOCUMENT),
 522  
                                  * KRADConstants.CONFIRMATION_QUESTION, caller, context);
 523  
                                  */
 524  0
                                 viewName = "ask_user_questions";
 525  
                         }
 526  
                         else {
 527  0
                                 Object buttonClicked = request.getParameter(KRADConstants.QUESTION_CLICKED_BUTTON);
 528  
 
 529  
                                 // if no button clicked just reload the doc
 530  0
                                 if (ConfirmationQuestion.NO.equals(buttonClicked)) {
 531  
                                         // TODO figure out what to return
 532  0
                                         viewName = "user_says_no";
 533  
                                 }
 534  
 
 535  
                                 // answered yes, create session ticket so we not to ask question
 536  
                                 // again if there are further question requests
 537  0
                                 SessionTicket ticket = new SessionTicket(KRADConstants.SENSITIVE_DATA_QUESTION_SESSION_TICKET);
 538  0
                                 ticket.setTicketContext(ticketContext);
 539  0
                                 GlobalVariables.getUserSession().putSessionTicket(ticket);
 540  
                         }
 541  
                 }
 542  
 
 543  
                 // returning null will indicate processing should continue (no redirect)
 544  0
                 return viewName;
 545  
         }
 546  
 
 547  
         /**
 548  
          * Convenience method for building authorization exceptions
 549  
          * 
 550  
          * @param action
 551  
          *            - the action that was requested
 552  
          * @param document
 553  
          *            - document instance the action was requested for
 554  
          */
 555  
         protected DocumentAuthorizationException buildAuthorizationException(String action, Document document) {
 556  0
                 return new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(),
 557  
                                 action, document.getDocumentNumber());
 558  
         }
 559  
 
 560  
         public BusinessObjectService getBusinessObjectService() {
 561  0
                 if (this.businessObjectService == null) {
 562  0
                         this.businessObjectService = KRADServiceLocator.getBusinessObjectService();
 563  
                 }
 564  0
                 return this.businessObjectService;
 565  
         }
 566  
 
 567  
         public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 568  0
                 this.businessObjectService = businessObjectService;
 569  0
         }
 570  
 
 571  
         public DataDictionaryService getDataDictionaryService() {
 572  0
                 if (this.dataDictionaryService == null) {
 573  0
                         this.dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
 574  
                 }
 575  0
                 return this.dataDictionaryService;
 576  
         }
 577  
 
 578  
         public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 579  0
                 this.dataDictionaryService = dataDictionaryService;
 580  0
         }
 581  
 
 582  
         public DocumentService getDocumentService() {
 583  0
                 if (this.documentService == null) {
 584  0
                         this.documentService = KRADServiceLocatorWeb.getDocumentService();
 585  
                 }
 586  0
                 return this.documentService;
 587  
         }
 588  
 
 589  
         public void setDocumentService(DocumentService documentService) {
 590  0
                 this.documentService = documentService;
 591  0
         }
 592  
 
 593  
         public DocumentHelperService getDocumentHelperService() {
 594  0
                 if (this.documentHelperService == null) {
 595  0
                         this.documentHelperService = KRADServiceLocatorWeb.getDocumentHelperService();
 596  
                 }
 597  0
                 return this.documentHelperService;
 598  
         }
 599  
 
 600  
         public void setDocumentHelperService(DocumentHelperService documentHelperService) {
 601  0
                 this.documentHelperService = documentHelperService;
 602  0
         }
 603  
 }