Coverage Report - org.kuali.rice.kim.rules.ui.RoleDocumentDelegationMemberRule
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleDocumentDelegationMemberRule
0%
0/32
0%
0/22
14
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing members and
 14  
  * limitations under the License.
 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  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 37  
  * 
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
 }