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