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.uif.RemotableAttributeError; |
20 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
21 | |
import org.kuali.rice.kim.api.type.KimTypeService; |
22 | |
import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember; |
23 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
24 | |
import org.kuali.rice.kim.document.rule.AttributeValidationHelper; |
25 | |
import org.kuali.rice.kim.rule.event.ui.AddDelegationMemberEvent; |
26 | |
import org.kuali.rice.kim.rule.ui.AddDelegationMemberRule; |
27 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
28 | |
import org.kuali.rice.krad.rules.DocumentRuleBase; |
29 | |
import org.kuali.rice.krad.util.GlobalVariables; |
30 | |
|
31 | |
import java.util.ArrayList; |
32 | |
import java.util.HashMap; |
33 | |
import java.util.List; |
34 | |
import java.util.Map; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class RoleDocumentDelegationMemberRule extends DocumentRuleBase implements AddDelegationMemberRule { |
43 | |
|
44 | |
public static final String ERROR_PATH = "document.delegationMember.memberId"; |
45 | |
|
46 | 0 | protected AttributeValidationHelper attributeValidationHelper = new AttributeValidationHelper(); |
47 | |
|
48 | |
public boolean processAddDelegationMember(AddDelegationMemberEvent addDelegationMemberEvent){ |
49 | 0 | RoleDocumentDelegationMember newMember = addDelegationMemberEvent.getDelegationMember(); |
50 | 0 | IdentityManagementRoleDocument document = (IdentityManagementRoleDocument)addDelegationMemberEvent.getDocument(); |
51 | 0 | boolean rulePassed = true; |
52 | 0 | if(newMember == null || StringUtils.isBlank(newMember.getMemberId())){ |
53 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Delegation Member"}); |
54 | 0 | return false; |
55 | |
} |
56 | 0 | if(StringUtils.isBlank(newMember.getRoleMemberId())){ |
57 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Role Member"}); |
58 | 0 | return false; |
59 | |
} |
60 | 0 | List<Map<String, String>> mapListToValidate = new ArrayList<Map<String, String>>(); |
61 | |
Map<String, String> mapToValidate; |
62 | 0 | List<RemotableAttributeError> validationErrors = new ArrayList<RemotableAttributeError>(); |
63 | 0 | KimTypeService kimTypeService = KIMServiceLocatorWeb.getKimTypeService(document.getKimType()); |
64 | |
|
65 | 0 | for(RoleDocumentDelegationMember roleMember: document.getDelegationMembers()) { |
66 | 0 | mapToValidate = attributeValidationHelper.convertQualifiersToMap(roleMember.getQualifiers()); |
67 | 0 | mapListToValidate.add(mapToValidate); |
68 | |
} |
69 | |
|
70 | |
|
71 | 0 | int i = 0; |
72 | 0 | for (RoleDocumentDelegationMember member: document.getDelegationMembers()){ |
73 | 0 | List<RemotableAttributeError> localErrors = kimTypeService.validateAttributesAgainstExisting( |
74 | |
document.getKimType().getId(), |
75 | |
attributeValidationHelper.convertQualifiersToMap(newMember.getQualifiers()), |
76 | |
attributeValidationHelper.convertQualifiersToMap(member.getQualifiers())); |
77 | 0 | if (!localErrors.isEmpty() && (member.getMemberId().equals(newMember.getMemberId()) && |
78 | |
member.getMemberTypeCode().equals(newMember.getMemberTypeCode()))){ |
79 | 0 | rulePassed = false; |
80 | 0 | GlobalVariables.getMessageMap().putError("delegationMember.memberId", RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Delegation Member"}); |
81 | 0 | break; |
82 | |
} |
83 | 0 | i++; |
84 | 0 | } |
85 | |
|
86 | 0 | if ( kimTypeService != null && !newMember.isRole()) { |
87 | 0 | List<RemotableAttributeError> localErrors = kimTypeService.validateAttributes( document.getKimType().getId(), attributeValidationHelper.convertQualifiersToMap( newMember.getQualifiers() ) ); |
88 | 0 | validationErrors.addAll( attributeValidationHelper.convertErrors("delegationMember", |
89 | |
attributeValidationHelper.convertQualifiersToAttrIdxMap(newMember.getQualifiers()), localErrors) ); |
90 | |
} |
91 | 0 | if (!validationErrors.isEmpty()) { |
92 | 0 | attributeValidationHelper.moveValidationErrorsToErrorMap(validationErrors); |
93 | 0 | rulePassed = false; |
94 | |
} |
95 | 0 | return rulePassed; |
96 | |
} |
97 | |
|
98 | |
} |