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.PersonDocumentGroup;
24 import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
25 import org.kuali.rice.kim.rule.event.ui.AddGroupEvent;
26 import org.kuali.rice.kim.rule.ui.AddGroupRule;
27 import org.kuali.rice.kim.util.KimConstants;
28 import org.kuali.rice.kns.rules.DocumentRuleBase;
29 import org.kuali.rice.kns.util.GlobalVariables;
30 import org.kuali.rice.kns.util.RiceKeyConstants;
31
32
33
34
35
36
37
38 public class PersonDocumentGroupRule extends DocumentRuleBase implements AddGroupRule {
39 protected static final String NEW_GROUP = "newGroup";
40 protected static final String GROUP_ID_ERROR_PATH = NEW_GROUP+".groupId";
41
42 public boolean processAddGroup(AddGroupEvent addGroupEvent) {
43 IdentityManagementPersonDocument document = (IdentityManagementPersonDocument)addGroupEvent.getDocument();
44 PersonDocumentGroup newGroup = addGroupEvent.getGroup();
45 boolean rulePassed = true;
46 rulePassed = validAssignGroup(document, newGroup);
47
48
49 if (newGroup == null || StringUtils.isBlank(newGroup.getGroupId())) {
50 rulePassed = false;
51 GlobalVariables.getMessageMap().putError(GROUP_ID_ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Group"});
52
53 } else {
54 for (PersonDocumentGroup group : document.getGroups()) {
55 if (group.getGroupId().equals(newGroup.getGroupId())) {
56 rulePassed = false;
57 GlobalVariables.getMessageMap().putError(GROUP_ID_ERROR_PATH, RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Group"});
58
59 }
60 }
61 }
62
63
64
65
66
67
68
69
70
71 return rulePassed;
72 }
73
74 protected boolean validAssignGroup(IdentityManagementPersonDocument document, PersonDocumentGroup newGroup){
75 boolean rulePassed = true;
76 Map<String,String> additionalPermissionDetails = new HashMap<String,String>();
77 additionalPermissionDetails.put(KimAttributes.NAMESPACE_CODE, newGroup.getNamespaceCode());
78 additionalPermissionDetails.put(KimAttributes.GROUP_NAME, newGroup.getGroupName());
79 if(!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate(
80 document, KimConstants.NAMESPACE_CODE, KimConstants.PermissionTemplateNames.POPULATE_GROUP,
81 GlobalVariables.getUserSession().getPrincipalId(), additionalPermissionDetails, null)){
82 GlobalVariables.getMessageMap().putError(GROUP_ID_ERROR_PATH,
83 RiceKeyConstants.ERROR_ASSIGN_GROUP,
84 new String[] {newGroup.getNamespaceCode(), newGroup.getGroupName()});
85 rulePassed = false;
86 }
87 return rulePassed;
88 }
89
90 }