1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapKeyConstants;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.kim.api.identity.PersonService;
27 import org.kuali.rice.krad.util.GlobalVariables;
28 import org.kuali.rice.krad.util.MessageMap;
29 import org.kuali.rice.krad.util.ObjectUtils;
30
31 public class PurchaseOrderAssignedUserValidation extends GenericValidation {
32 private PersonService personService;
33
34
35
36
37
38
39 public boolean validate(AttributedDocumentEvent event) {
40 PurchaseOrderDocument poDocument = (PurchaseOrderDocument) event.getDocument();
41 MessageMap errorMap = GlobalVariables.getMessageMap();
42 errorMap.clearErrorPath();
43 errorMap.addToErrorPath(PurapConstants.DETAIL_TAB_ERRORS);
44 boolean valid = true;
45
46
47 String principalName = poDocument.getAssignedUserPrincipalName();
48 if (StringUtils.isEmpty(principalName))
49 return true;
50
51
52
53
54
55 if (ObjectUtils.isNull(poDocument.getAssignedUserPrincipalId())) {
56 valid = false;
57 errorMap.putError(PurapPropertyConstants.ASSIGNED_USER_PRINCIPAL_NAME, PurapKeyConstants.ERROR_NONEXIST_ASSIGNED_USER);
58 }
59
60 errorMap.clearErrorPath();
61 return valid;
62 }
63
64
65
66
67 protected PersonService getPersonService() {
68 if (personService == null)
69 personService = SpringContext.getBean(PersonService.class);
70 return personService;
71 }
72
73 }