Coverage Report - org.kuali.rice.kim.rules.ui.GroupDocumentMemberRule
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupDocumentMemberRule
0%
0/29
0%
0/18
7
 
 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 java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.core.util.RiceKeyConstants;
 23  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 24  
 import org.kuali.rice.kim.bo.ui.GroupDocumentMember;
 25  
 import org.kuali.rice.kim.document.IdentityManagementGroupDocument;
 26  
 import org.kuali.rice.kim.rule.event.ui.AddGroupMemberEvent;
 27  
 import org.kuali.rice.kim.rule.ui.AddGroupMemberRule;
 28  
 import org.kuali.rice.kim.api.group.GroupService;
 29  
 //import org.kuali.rice.kim.api.group.GroupServiceBase;
 30  
 import org.kuali.rice.kim.util.KimConstants;
 31  
 import org.kuali.rice.krad.rules.DocumentRuleBase;
 32  
 import org.kuali.rice.krad.util.GlobalVariables;
 33  
 
 34  
 /**
 35  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 36  
  * 
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  *
 39  
  */
 40  0
 public class GroupDocumentMemberRule extends DocumentRuleBase implements AddGroupMemberRule {
 41  
 
 42  
         private static final String ERROR_PATH = "document.member.memberId";
 43  
 
 44  
         public boolean processAddGroupMember(AddGroupMemberEvent addGroupMemberEvent){
 45  0
                 GroupDocumentMember newMember = addGroupMemberEvent.getMember();
 46  0
                 IdentityManagementGroupDocument document = (IdentityManagementGroupDocument)addGroupMemberEvent.getDocument();
 47  0
             boolean rulePassed = true;
 48  
 
 49  0
         if (newMember == null || StringUtils.isBlank(newMember.getMemberId())){
 50  0
             GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Member"});
 51  0
             return false;
 52  
         }
 53  0
             if(!validAssignGroup(newMember, document))
 54  0
                     return false;
 55  
 
 56  0
             int i = 0;
 57  0
             for (GroupDocumentMember member: document.getMembers()){
 58  0
                     if (member.getMemberId().equals(newMember.getMemberId()) && member.getMemberTypeCode().equals(newMember.getMemberTypeCode())){
 59  0
                     rulePassed = false;
 60  0
                     GlobalVariables.getMessageMap().putError("document.members["+i+"].memberId", RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Member"});
 61  
                     }
 62  0
                     i++;
 63  
             }
 64  
             
 65  
             // check for circular reference
 66  0
                 GroupService groupService = KimApiServiceLocator.getGroupService();
 67  0
                 if (groupService.isGroupMemberOfGroup(document.getGroupId(),newMember.getMemberId())){
 68  0
             GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_GROUP_MEMBER_CIRCULAR, new String[] {newMember.getMemberId()});
 69  0
                         return false;
 70  
                 }
 71  
             
 72  0
                 return rulePassed;
 73  
         } 
 74  
 
 75  
         protected boolean validAssignGroup(GroupDocumentMember groupMember, IdentityManagementGroupDocument document){
 76  0
         boolean rulePassed = true;
 77  0
                 if(StringUtils.isNotEmpty(document.getGroupNamespace())){
 78  0
                         Map<String,String> roleDetails = new HashMap<String,String>();
 79  0
                         roleDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, document.getGroupNamespace());
 80  0
                         roleDetails.put(KimConstants.AttributeConstants.GROUP_NAME, document.getGroupName());
 81  0
                         if (!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate(
 82  
                                         document, 
 83  
                                         KimConstants.NAMESPACE_CODE, 
 84  
                                         KimConstants.PermissionTemplateNames.POPULATE_GROUP, 
 85  
                                         GlobalVariables.getUserSession().getPerson().getPrincipalId(), 
 86  
                                         roleDetails, null)){
 87  0
                     GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_GROUP, 
 88  
                                     new String[] {document.getGroupNamespace(), document.getGroupName()});
 89  0
                     rulePassed = false;
 90  
                         }
 91  
                 }
 92  0
                 return rulePassed;
 93  
         }
 94  
 
 95  
 }