1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.responsibility; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
20 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
21 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibility; |
22 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
23 | |
import org.kuali.rice.kim.util.KimConstants; |
24 | |
import org.kuali.rice.krad.rules.DocumentRuleBase; |
25 | |
import org.kuali.rice.krad.util.GlobalVariables; |
26 | |
|
27 | |
import java.util.HashMap; |
28 | |
import java.util.Map; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class KimDocumentResponsibilityRule extends DocumentRuleBase implements AddResponsibilityRule { |
37 | |
|
38 | |
public static final String ERROR_PATH = "document.responsibility.responsibilityId"; |
39 | |
|
40 | |
public boolean processAddResponsibility(AddResponsibilityEvent addResponsibilityEvent) { |
41 | 0 | KimDocumentRoleResponsibility newResponsibility = addResponsibilityEvent.getResponsibility(); |
42 | 0 | if(newResponsibility==null){ |
43 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Responsibility"}); |
44 | 0 | return false; |
45 | |
} |
46 | |
|
47 | 0 | ResponsibilityBo kimResponsibilityImpl = newResponsibility.getKimResponsibility(); |
48 | 0 | if(kimResponsibilityImpl==null){ |
49 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Responsibility"}); |
50 | 0 | return false; |
51 | |
} |
52 | |
|
53 | 0 | IdentityManagementRoleDocument document = (IdentityManagementRoleDocument)addResponsibilityEvent.getDocument(); |
54 | 0 | boolean rulePassed = true; |
55 | 0 | if (!hasPermissionToGrantResponsibility(ResponsibilityBo.to(kimResponsibilityImpl), document)) { |
56 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_RESPONSIBILITY, |
57 | |
new String[] {kimResponsibilityImpl.getNamespaceCode(), kimResponsibilityImpl.getTemplate().getName()}); |
58 | 0 | return false; |
59 | |
} |
60 | |
|
61 | 0 | if (newResponsibility == null || StringUtils.isBlank(newResponsibility.getResponsibilityId())) { |
62 | 0 | rulePassed = false; |
63 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Responsibility"}); |
64 | |
} else { |
65 | 0 | int i = 0; |
66 | 0 | for (KimDocumentRoleResponsibility responsibility: document.getResponsibilities()) { |
67 | 0 | if (responsibility.getResponsibilityId().equals(newResponsibility.getResponsibilityId())) { |
68 | 0 | rulePassed = false; |
69 | 0 | GlobalVariables.getMessageMap().putError("document.responsibilities["+i+"].responsibilityId", RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Responsibility"}); |
70 | |
} |
71 | 0 | i++; |
72 | |
} |
73 | |
} |
74 | 0 | return rulePassed; |
75 | |
} |
76 | |
|
77 | |
public boolean hasPermissionToGrantResponsibility(Responsibility kimResponsibilityInfo, IdentityManagementRoleDocument document){ |
78 | 0 | Map<String,String> responsibilityDetails = new HashMap<String,String>(); |
79 | 0 | responsibilityDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, kimResponsibilityInfo.getNamespaceCode()); |
80 | 0 | responsibilityDetails.put(KimConstants.AttributeConstants.RESPONSIBILITY_NAME, kimResponsibilityInfo.getName()); |
81 | 0 | if (!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate( |
82 | |
document, |
83 | |
KimConstants.NAMESPACE_CODE, |
84 | |
KimConstants.PermissionTemplateNames.GRANT_RESPONSIBILITY, |
85 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId(), |
86 | |
responsibilityDetails, null)) { |
87 | 0 | return false; |
88 | |
} |
89 | 0 | return true; |
90 | |
} |
91 | |
} |