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 java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.apache.commons.lang.StringUtils; |
22 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
23 | |
import org.kuali.rice.kim.bo.ui.PersonDocumentRole; |
24 | |
import org.kuali.rice.kim.document.IdentityManagementPersonDocument; |
25 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
26 | |
import org.kuali.rice.kim.rule.event.ui.AddRoleEvent; |
27 | |
import org.kuali.rice.kim.rule.ui.AddRoleRule; |
28 | |
import org.kuali.rice.kim.util.KimConstants; |
29 | |
import org.kuali.rice.kns.rules.DocumentRuleBase; |
30 | |
import org.kuali.rice.kns.util.GlobalVariables; |
31 | |
import org.kuali.rice.kns.util.RiceKeyConstants; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class PersonDocumentRoleRule extends DocumentRuleBase implements AddRoleRule { |
40 | |
public static final String ERROR_PATH = "newRole.roleId"; |
41 | |
|
42 | |
public boolean processAddRole(AddRoleEvent addRoleEvent) { |
43 | 0 | PersonDocumentRole newRole = addRoleEvent.getRole(); |
44 | 0 | IdentityManagementPersonDocument document = (IdentityManagementPersonDocument)addRoleEvent.getDocument(); |
45 | 0 | boolean rulePassed = true; |
46 | |
|
47 | |
|
48 | 0 | if (newRole == null || StringUtils.isBlank(newRole.getRoleId())) { |
49 | 0 | rulePassed = false; |
50 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Role"}); |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
} else { |
56 | 0 | for (PersonDocumentRole role : document.getRoles()) { |
57 | 0 | if (role.getRoleId().equals(newRole.getRoleId())) { |
58 | 0 | rulePassed = false; |
59 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Role"}); |
60 | |
|
61 | |
} |
62 | |
} |
63 | |
} |
64 | 0 | return rulePassed; |
65 | |
} |
66 | |
|
67 | |
} |