| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.web.spring.controller; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.Map; |
| 21 | |
|
| 22 | |
import javax.servlet.http.HttpServletRequest; |
| 23 | |
import javax.servlet.http.HttpServletResponse; |
| 24 | |
|
| 25 | |
import org.apache.commons.lang.ArrayUtils; |
| 26 | |
import org.kuali.rice.core.framework.parameter.ParameterConstants; |
| 27 | |
import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator; |
| 28 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
| 29 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 30 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 31 | |
import org.kuali.rice.kns.bo.AdHocRouteRecipient; |
| 32 | |
import org.kuali.rice.kns.document.Document; |
| 33 | |
import org.kuali.rice.kns.exception.DocumentAuthorizationException; |
| 34 | |
import org.kuali.rice.kns.exception.UnknownDocumentIdException; |
| 35 | |
import org.kuali.rice.kns.exception.ValidationException; |
| 36 | |
import org.kuali.rice.kns.question.ConfirmationQuestion; |
| 37 | |
import org.kuali.rice.kns.service.BusinessObjectAuthorizationService; |
| 38 | |
import org.kuali.rice.kns.service.BusinessObjectMetaDataService; |
| 39 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
| 40 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
| 41 | |
import org.kuali.rice.kns.service.DocumentHelperService; |
| 42 | |
import org.kuali.rice.kns.service.DocumentService; |
| 43 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 44 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 45 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 46 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 47 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
| 48 | |
import org.kuali.rice.kns.util.SessionTicket; |
| 49 | |
import org.kuali.rice.kns.util.WebUtils; |
| 50 | |
import org.kuali.rice.kns.web.spring.form.DocumentFormBase; |
| 51 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; |
| 52 | |
import org.springframework.validation.BindingResult; |
| 53 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
| 54 | |
import org.springframework.web.bind.annotation.RequestMapping; |
| 55 | |
import org.springframework.web.servlet.ModelAndView; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 0 | public abstract class DocumentControllerBase extends UifControllerBase { |
| 70 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentControllerBase.class); |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | 0 | protected static final String[] DOCUMENT_LOAD_COMMANDS = { KEWConstants.ACTIONLIST_COMMAND, |
| 75 | |
KEWConstants.DOCSEARCH_COMMAND, KEWConstants.SUPERUSER_COMMAND, KEWConstants.HELPDESK_ACTIONLIST_COMMAND }; |
| 76 | |
|
| 77 | |
private BusinessObjectService businessObjectService; |
| 78 | |
private BusinessObjectAuthorizationService businessObjectAuthorizationService; |
| 79 | |
private BusinessObjectMetaDataService businessObjectMetaDataService; |
| 80 | |
private DataDictionaryService dataDictionaryService; |
| 81 | |
private DocumentService documentService; |
| 82 | |
private DocumentHelperService documentHelperService; |
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public abstract DocumentFormBase createInitialForm(HttpServletRequest request); |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
@RequestMapping(params = "methodToCall=docHandler") |
| 97 | |
public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request, |
| 98 | |
HttpServletResponse response) throws Exception { |
| 99 | 0 | String command = form.getCommand(); |
| 100 | |
|
| 101 | |
|
| 102 | 0 | if (ArrayUtils.contains(DOCUMENT_LOAD_COMMANDS, command) && form.getDocId() != null) { |
| 103 | 0 | loadDocument(form); |
| 104 | |
} |
| 105 | 0 | else if (KEWConstants.INITIATE_COMMAND.equals(command)) { |
| 106 | 0 | createDocument(form); |
| 107 | |
} |
| 108 | |
else { |
| 109 | 0 | LOG.error("docHandler called with invalid parameters"); |
| 110 | 0 | throw new IllegalStateException("docHandler called with invalid parameters"); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | 0 | return getUIFModelAndView(form); |
| 119 | |
} |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
protected void loadDocument(DocumentFormBase form) throws WorkflowException { |
| 131 | 0 | String docId = form.getDocId(); |
| 132 | |
|
| 133 | 0 | Document doc = null; |
| 134 | 0 | doc = getDocumentService().getByDocumentHeaderId(docId); |
| 135 | 0 | if (doc == null) { |
| 136 | 0 | throw new UnknownDocumentIdException( |
| 137 | |
"Document no longer exists. It may have been cancelled before being saved."); |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | KualiWorkflowDocument workflowDocument = doc.getDocumentHeader().getWorkflowDocument(); |
| 141 | 0 | if (!getDocumentHelperService().getDocumentAuthorizer(doc).canOpen(doc, |
| 142 | |
GlobalVariables.getUserSession().getPerson())) { |
| 143 | 0 | throw buildAuthorizationException("open", doc); |
| 144 | |
} |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | 0 | if (workflowDocument != doc.getDocumentHeader().getWorkflowDocument()) { |
| 149 | 0 | LOG.warn("Workflow document changed via canOpen check"); |
| 150 | 0 | doc.getDocumentHeader().setWorkflowDocument(workflowDocument); |
| 151 | |
} |
| 152 | |
|
| 153 | 0 | form.setDocument(doc); |
| 154 | 0 | KualiWorkflowDocument workflowDoc = doc.getDocumentHeader().getWorkflowDocument(); |
| 155 | 0 | form.setDocTypeName(workflowDoc.getDocumentType()); |
| 156 | |
|
| 157 | 0 | KNSServiceLocatorWeb.getSessionDocumentService().addDocumentToUserSession(GlobalVariables.getUserSession(), workflowDoc); |
| 158 | 0 | } |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
protected void createDocument(DocumentFormBase form) throws WorkflowException { |
| 170 | 0 | Document doc = getDocumentService().getNewDocument(form.getDocTypeName()); |
| 171 | |
|
| 172 | 0 | form.setDocument(doc); |
| 173 | 0 | form.setDocTypeName(doc.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
| 174 | 0 | } |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
@RequestMapping(params = "methodToCall=save") |
| 180 | |
public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request, |
| 181 | |
HttpServletResponse response) throws Exception { |
| 182 | |
|
| 183 | 0 | doProcessingAfterPost(form, request); |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | 0 | Document document = form.getDocument(); |
| 190 | |
|
| 191 | 0 | String viewName = checkAndWarnAboutSensitiveData(form, request, response, |
| 192 | |
KNSPropertyConstants.DOCUMENT_EXPLANATION, document.getDocumentHeader().getExplanation(), "save", ""); |
| 193 | |
|
| 194 | |
|
| 195 | 0 | if (viewName != null) { |
| 196 | 0 | return new ModelAndView(viewName); |
| 197 | |
} |
| 198 | |
|
| 199 | |
try { |
| 200 | |
|
| 201 | 0 | getDocumentService().saveDocument(document); |
| 202 | |
|
| 203 | 0 | GlobalVariables.getMessageList().add(RiceKeyConstants.MESSAGE_SAVED); |
| 204 | 0 | form.setAnnotation(""); |
| 205 | |
} |
| 206 | 0 | catch(ValidationException vex) { |
| 207 | |
|
| 208 | 0 | } |
| 209 | |
|
| 210 | 0 | return getUIFModelAndView(form); |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
@RequestMapping(params = "methodToCall=route") |
| 217 | |
public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request, |
| 218 | |
HttpServletResponse response) throws Exception { |
| 219 | 0 | doProcessingAfterPost(form, request); |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | 0 | Document document = form.getDocument(); |
| 230 | |
|
| 231 | 0 | String viewName = checkAndWarnAboutSensitiveData(form, request, response, |
| 232 | |
KNSPropertyConstants.DOCUMENT_EXPLANATION, document.getDocumentHeader().getExplanation(), "route", ""); |
| 233 | 0 | if (viewName != null) { |
| 234 | 0 | return new ModelAndView(viewName); |
| 235 | |
} |
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | 0 | getDocumentService().routeDocument(document, form.getAnnotation(), new ArrayList<AdHocRouteRecipient>()); |
| 241 | |
|
| 242 | 0 | GlobalVariables.getMessageList().add(RiceKeyConstants.MESSAGE_ROUTE_SUCCESSFUL); |
| 243 | 0 | form.setAnnotation(""); |
| 244 | |
|
| 245 | |
|
| 246 | 0 | return getUIFModelAndView(form); |
| 247 | |
} |
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
protected void doProcessingAfterPost(DocumentFormBase form, HttpServletRequest request) { |
| 257 | 0 | getBusinessObjectService().linkUserFields(form.getDocument()); |
| 258 | 0 | } |
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
protected String checkAndWarnAboutSensitiveData(DocumentFormBase form, HttpServletRequest request, |
| 332 | |
HttpServletResponse response, String fieldName, String fieldValue, String caller, String context) |
| 333 | |
throws Exception { |
| 334 | |
|
| 335 | 0 | String viewName = null; |
| 336 | 0 | Document document = form.getDocument(); |
| 337 | |
|
| 338 | 0 | boolean containsSensitiveData = WebUtils.containsSensitiveDataPatternMatch(fieldValue); |
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | 0 | boolean warnForSensitiveData = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean( |
| 343 | |
KNSConstants.KNS_NAMESPACE, ParameterConstants.ALL_COMPONENT, |
| 344 | |
KNSConstants.SystemGroupParameterNames.SENSITIVE_DATA_PATTERNS_WARNING_IND); |
| 345 | |
|
| 346 | |
|
| 347 | 0 | Map<String, String> ticketContext = new HashMap<String, String>(); |
| 348 | 0 | ticketContext.put(KNSPropertyConstants.DOCUMENT_NUMBER, document.getDocumentNumber()); |
| 349 | 0 | ticketContext.put(KNSConstants.CALLING_METHOD, caller); |
| 350 | 0 | ticketContext.put(KNSPropertyConstants.NAME, fieldName); |
| 351 | |
|
| 352 | 0 | boolean questionAsked = GlobalVariables.getUserSession().hasMatchingSessionTicket( |
| 353 | |
KNSConstants.SENSITIVE_DATA_QUESTION_SESSION_TICKET, ticketContext); |
| 354 | |
|
| 355 | |
|
| 356 | 0 | if (containsSensitiveData && warnForSensitiveData && !questionAsked) { |
| 357 | 0 | Object question = request.getParameter(KNSConstants.QUESTION_INST_ATTRIBUTE_NAME); |
| 358 | 0 | if (question == null || !KNSConstants.DOCUMENT_SENSITIVE_DATA_QUESTION.equals(question)) { |
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | 0 | viewName = "ask_user_questions"; |
| 371 | |
} |
| 372 | |
else { |
| 373 | 0 | Object buttonClicked = request.getParameter(KNSConstants.QUESTION_CLICKED_BUTTON); |
| 374 | |
|
| 375 | |
|
| 376 | 0 | if (ConfirmationQuestion.NO.equals(buttonClicked)) { |
| 377 | |
|
| 378 | 0 | viewName = "user_says_no"; |
| 379 | |
} |
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | 0 | SessionTicket ticket = new SessionTicket(KNSConstants.SENSITIVE_DATA_QUESTION_SESSION_TICKET); |
| 384 | 0 | ticket.setTicketContext(ticketContext); |
| 385 | 0 | GlobalVariables.getUserSession().putSessionTicket(ticket); |
| 386 | |
} |
| 387 | |
} |
| 388 | |
|
| 389 | |
|
| 390 | 0 | return viewName; |
| 391 | |
} |
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
protected DocumentAuthorizationException buildAuthorizationException(String action, Document document) { |
| 402 | 0 | return new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), |
| 403 | |
action, document.getDocumentNumber()); |
| 404 | |
} |
| 405 | |
|
| 406 | |
public BusinessObjectService getBusinessObjectService() { |
| 407 | 0 | if (this.businessObjectService == null) { |
| 408 | 0 | this.businessObjectService = KNSServiceLocator.getBusinessObjectService(); |
| 409 | |
} |
| 410 | 0 | return this.businessObjectService; |
| 411 | |
} |
| 412 | |
|
| 413 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
| 414 | 0 | this.businessObjectService = businessObjectService; |
| 415 | 0 | } |
| 416 | |
|
| 417 | |
public BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
| 418 | 0 | if (this.businessObjectAuthorizationService == null) { |
| 419 | 0 | this.businessObjectAuthorizationService = KNSServiceLocatorWeb.getBusinessObjectAuthorizationService(); |
| 420 | |
} |
| 421 | 0 | return this.businessObjectAuthorizationService; |
| 422 | |
} |
| 423 | |
|
| 424 | |
public void setBusinessObjectAuthorizationService( |
| 425 | |
BusinessObjectAuthorizationService businessObjectAuthorizationService) { |
| 426 | 0 | this.businessObjectAuthorizationService = businessObjectAuthorizationService; |
| 427 | 0 | } |
| 428 | |
|
| 429 | |
public BusinessObjectMetaDataService getBusinessObjectMetaDataService() { |
| 430 | 0 | if (this.businessObjectMetaDataService == null) { |
| 431 | 0 | this.businessObjectMetaDataService = KNSServiceLocatorWeb.getBusinessObjectMetaDataService(); |
| 432 | |
} |
| 433 | 0 | return this.businessObjectMetaDataService; |
| 434 | |
} |
| 435 | |
|
| 436 | |
public void setBusinessObjectMetaDataService(BusinessObjectMetaDataService businessObjectMetaDataService) { |
| 437 | 0 | this.businessObjectMetaDataService = businessObjectMetaDataService; |
| 438 | 0 | } |
| 439 | |
|
| 440 | |
public DataDictionaryService getDataDictionaryService() { |
| 441 | 0 | if (this.dataDictionaryService == null) { |
| 442 | 0 | this.dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
| 443 | |
} |
| 444 | 0 | return this.dataDictionaryService; |
| 445 | |
} |
| 446 | |
|
| 447 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
| 448 | 0 | this.dataDictionaryService = dataDictionaryService; |
| 449 | 0 | } |
| 450 | |
|
| 451 | |
public DocumentService getDocumentService() { |
| 452 | 0 | if (this.documentService == null) { |
| 453 | 0 | this.documentService = KNSServiceLocatorWeb.getDocumentService(); |
| 454 | |
} |
| 455 | 0 | return this.documentService; |
| 456 | |
} |
| 457 | |
|
| 458 | |
public void setDocumentService(DocumentService documentService) { |
| 459 | 0 | this.documentService = documentService; |
| 460 | 0 | } |
| 461 | |
|
| 462 | |
public DocumentHelperService getDocumentHelperService() { |
| 463 | 0 | if (this.documentHelperService == null) { |
| 464 | 0 | this.documentHelperService = KNSServiceLocatorWeb.getDocumentHelperService(); |
| 465 | |
} |
| 466 | 0 | return this.documentHelperService; |
| 467 | |
} |
| 468 | |
|
| 469 | |
public void setDocumentHelperService(DocumentHelperService documentHelperService) { |
| 470 | 0 | this.documentHelperService = documentHelperService; |
| 471 | 0 | } |
| 472 | |
} |