1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.rules.ui;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.RiceKeyConstants;
20 import org.kuali.rice.kim.bo.ui.PersonDocumentRole;
21 import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
22 import org.kuali.rice.kim.rule.event.ui.AddRoleEvent;
23 import org.kuali.rice.kim.rule.ui.AddRoleRule;
24 import org.kuali.rice.kns.rules.DocumentRuleBase;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.springframework.util.CollectionUtils;
27
28
29
30
31
32
33
34 public class PersonDocumentRoleRule extends DocumentRuleBase implements AddRoleRule {
35 public static final String ERROR_PATH = "newRole.roleId";
36
37 public boolean processAddRole(AddRoleEvent addRoleEvent) {
38 PersonDocumentRole newRole = addRoleEvent.getRole();
39 IdentityManagementPersonDocument document = (IdentityManagementPersonDocument)addRoleEvent.getDocument();
40 boolean rulePassed = true;
41
42
43 if (newRole == null || StringUtils.isBlank(newRole.getRoleId())) {
44 rulePassed = false;
45 GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Role"});
46
47
48
49
50 } else {
51 for (PersonDocumentRole role : document.getRoles()) {
52 if (role.getRoleId().equals(newRole.getRoleId())) {
53 rulePassed = false;
54 GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Role"});
55
56 }
57 }
58 }
59
60
61 if(!CollectionUtils.isEmpty(GlobalVariables.getMessageMap().getErrorMessagesForProperty("newRole.*", true))) {
62 rulePassed = false;
63 }
64
65 return rulePassed;
66 }
67
68 }