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