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.api.group.GroupService; |
21 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
22 | |
import org.kuali.rice.kim.bo.ui.GroupDocumentMember; |
23 | |
import org.kuali.rice.kim.document.IdentityManagementGroupDocument; |
24 | |
import org.kuali.rice.kim.rule.event.ui.AddGroupMemberEvent; |
25 | |
import org.kuali.rice.kim.rule.ui.AddGroupMemberRule; |
26 | |
import org.kuali.rice.kim.util.KimConstants; |
27 | |
import org.kuali.rice.krad.rules.DocumentRuleBase; |
28 | |
import org.kuali.rice.krad.util.GlobalVariables; |
29 | |
|
30 | |
import java.util.HashMap; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class GroupDocumentMemberRule extends DocumentRuleBase implements AddGroupMemberRule { |
42 | |
|
43 | |
private static final String ERROR_PATH = "document.member.memberId"; |
44 | |
|
45 | |
public boolean processAddGroupMember(AddGroupMemberEvent addGroupMemberEvent){ |
46 | 0 | GroupDocumentMember newMember = addGroupMemberEvent.getMember(); |
47 | 0 | IdentityManagementGroupDocument document = (IdentityManagementGroupDocument)addGroupMemberEvent.getDocument(); |
48 | 0 | boolean rulePassed = true; |
49 | |
|
50 | 0 | if (newMember == null || StringUtils.isBlank(newMember.getMemberId())){ |
51 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Member"}); |
52 | 0 | return false; |
53 | |
} |
54 | 0 | if(!validAssignGroup(newMember, document)) |
55 | 0 | return false; |
56 | |
|
57 | 0 | int i = 0; |
58 | 0 | for (GroupDocumentMember member: document.getMembers()){ |
59 | 0 | if (member.getMemberId().equals(newMember.getMemberId()) && member.getMemberTypeCode().equals(newMember.getMemberTypeCode())){ |
60 | 0 | rulePassed = false; |
61 | 0 | GlobalVariables.getMessageMap().putError("document.members["+i+"].memberId", RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Member"}); |
62 | |
} |
63 | 0 | i++; |
64 | |
} |
65 | |
|
66 | |
|
67 | 0 | GroupService groupService = KimApiServiceLocator.getGroupService(); |
68 | 0 | if (groupService.isGroupMemberOfGroup(document.getGroupId(),newMember.getMemberId())){ |
69 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_GROUP_MEMBER_CIRCULAR, new String[] {newMember.getMemberId()}); |
70 | 0 | return false; |
71 | |
} |
72 | |
|
73 | 0 | return rulePassed; |
74 | |
} |
75 | |
|
76 | |
protected boolean validAssignGroup(GroupDocumentMember groupMember, IdentityManagementGroupDocument document){ |
77 | 0 | boolean rulePassed = true; |
78 | 0 | if(StringUtils.isNotEmpty(document.getGroupNamespace())){ |
79 | 0 | Map<String,String> roleDetails = new HashMap<String,String>(); |
80 | 0 | roleDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, document.getGroupNamespace()); |
81 | 0 | roleDetails.put(KimConstants.AttributeConstants.GROUP_NAME, document.getGroupName()); |
82 | 0 | if (!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate( |
83 | |
document, |
84 | |
KimConstants.NAMESPACE_CODE, |
85 | |
KimConstants.PermissionTemplateNames.POPULATE_GROUP, |
86 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId(), |
87 | |
roleDetails, null)){ |
88 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_GROUP, |
89 | |
new String[] {document.getGroupNamespace(), document.getGroupName()}); |
90 | 0 | rulePassed = false; |
91 | |
} |
92 | |
} |
93 | 0 | return rulePassed; |
94 | |
} |
95 | |
|
96 | |
} |