Coverage Report - org.kuali.rice.kim.rules.ui.RoleDocumentDelegationMemberRule
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleDocumentDelegationMemberRule
0%
0/33
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.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  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
 }