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