Coverage Report - org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase
 
Classes in this File Line Coverage Branch Coverage Complexity
KimRoleTypeServiceBase
0%
0/40
0%
0/24
2.545
 
 1  
 /*
 2  
  * Copyright 2007-2008 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 permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.service.support.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.apache.log4j.Logger;
 23  
 import org.kuali.rice.core.util.AttributeSet;
 24  
 import org.kuali.rice.kim.bo.Role;
 25  
 import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
 26  
 import org.kuali.rice.kim.framework.type.KimDelegationTypeService;
 27  
 import org.kuali.rice.kim.framework.type.KimRoleTypeService;
 28  
 
 29  
 /**
 30  
  * This is a description of what this class does - jonathan don't forget to fill this in. 
 31  
  * 
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public class KimRoleTypeServiceBase extends KimTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService {
 36  
 
 37  0
         private static final Logger LOG = Logger.getLogger(KimRoleTypeServiceBase.class);
 38  
         
 39  
         /**
 40  
          * Performs a simple check that the qualifier on the role matches the qualification.
 41  
          * Extra qualification attributes are ignored.
 42  
          * 
 43  
          * @see KimRoleTypeService#doesRoleQualifierMatchQualification(AttributeSet, AttributeSet)
 44  
          */
 45  
         public boolean doesRoleQualifierMatchQualification(AttributeSet qualification, AttributeSet roleQualifier) {
 46  0
                 AttributeSet translatedQualification = translateInputAttributeSet(qualification);
 47  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 48  0
                 return performMatch(translatedQualification, roleQualifier);
 49  
         }
 50  
         
 51  
         /**
 52  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#doRoleQualifiersMatchQualification(AttributeSet, List)
 53  
          */
 54  
         public List<RoleMembershipInfo> doRoleQualifiersMatchQualification(AttributeSet qualification, List<RoleMembershipInfo> roleMemberList) {
 55  0
                 AttributeSet translatedQualification = translateInputAttributeSet(qualification);
 56  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 57  0
                 List<RoleMembershipInfo> matchingMemberships = new ArrayList<RoleMembershipInfo>();
 58  0
                 for ( RoleMembershipInfo rmi : roleMemberList ) {
 59  0
                         if ( performMatch( translatedQualification, rmi.getQualifier() ) ) {
 60  0
                                 matchingMemberships.add( rmi );
 61  
                         }
 62  
                 }
 63  0
                 return matchingMemberships;
 64  
         }
 65  
 
 66  
         /**
 67  
          * Return an empty list since this method should not be called by the role service for this service type.
 68  
          * Subclasses which are application role types should override this method.
 69  
          * 
 70  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#getRoleMembersFromApplicationRole(String, String, AttributeSet)
 71  
          */
 72  
         public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet qualification) {
 73  0
                 validateRequiredAttributesAgainstReceived(qualification);
 74  0
                 if ( !isApplicationRoleType() ) {
 75  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." );
 76  
                 } else {
 77  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is an application role type but has not overridden this method." );
 78  
                 }
 79  
         }
 80  
 
 81  
         /**
 82  
          * This simple initial implementation just calls  
 83  
          * {@link #getRoleMembersFromApplicationRole(String, String, AttributeSet)} and checks the results.
 84  
          * 
 85  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#hasApplicationRole(java.lang.String, java.util.List, java.lang.String, java.lang.String, org.kuali.rice.core.util.AttributeSet)
 86  
          */
 87  
         public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, AttributeSet qualification) {
 88  0
                 if ( !isApplicationRoleType() ) {
 89  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." );
 90  
                 }
 91  
                 // if principal ID given, check if it is in the list generated from the getPrincipalIdsFromApplicationRole method
 92  0
                 if ( StringUtils.isNotBlank( principalId ) ) {
 93  0
                     List<RoleMembershipInfo> members = getRoleMembersFromApplicationRole(namespaceCode, roleName, qualification);
 94  0
                     for ( RoleMembershipInfo rm : members ) {
 95  0
                             if ( StringUtils.isBlank( rm.getMemberId() ) ) {
 96  0
                                     continue;
 97  
                             }
 98  0
                         if ( rm.getMemberTypeCode().equals( Role.PRINCIPAL_MEMBER_TYPE ) ) {
 99  0
                             if ( rm.getMemberId().equals( principalId ) ) {
 100  0
                                 return true;
 101  
                             }
 102  
                         } else { // groups
 103  0
                             if ( groupIds != null 
 104  
                                     && groupIds.contains(rm.getMemberId())) {
 105  0
                                 return true;
 106  
                             }
 107  
                         }
 108  
                         }
 109  
                 }
 110  0
                 return false;
 111  
         }
 112  
         
 113  
         /**
 114  
          * Default to not being an application role type.  Always returns false.
 115  
          * 
 116  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#isApplicationRoleType()
 117  
          */
 118  
         public boolean isApplicationRoleType() {
 119  0
                 return false;
 120  
         }
 121  
                 
 122  
         /**
 123  
          * This base implementation simply returns the passed in AttributeSet.
 124  
          * 
 125  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#convertQualificationForMemberRoles(String, String, String, String, AttributeSet)
 126  
          */
 127  
         public AttributeSet convertQualificationForMemberRoles(String namespaceCode, String roleName, String memberRoleNamespaceCode, String memberRoleName, AttributeSet qualification) {
 128  0
                 return qualification;
 129  
         }
 130  
         
 131  
         /**
 132  
          * Base implementation: no sorting.  Just returns the input list.
 133  
          * 
 134  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#sortRoleMembers(java.util.List)
 135  
          */
 136  
         public List<RoleMembershipInfo> sortRoleMembers(List<RoleMembershipInfo> roleMembers) {
 137  0
                 return roleMembers;
 138  
         }
 139  
         
 140  
         /**
 141  
          * This base implementation does nothing but log that the method was called.
 142  
          * 
 143  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#principalInactivated(java.lang.String, java.lang.String, java.lang.String)
 144  
          */
 145  
         public void principalInactivated(String principalId, String namespaceCode,
 146  
                         String roleName) {
 147  0
                 if ( LOG.isDebugEnabled() ) {
 148  0
                         LOG.debug( "Principal Inactivated called: principalId="+principalId+" role=" + namespaceCode + "/" + roleName );
 149  
                 }
 150  
                 // base implementation - do nothing
 151  0
         }
 152  
         
 153  
         /**
 154  
          * Performs a simple check that the qualifier on the delegation matches the qualification.
 155  
          * Extra qualification attributes are ignored.
 156  
          * 
 157  
          * @see org.kuali.rice.kim.framework.type.KimDelegationTypeService#doesDelegationQualifierMatchQualification(org.kuali.rice.core.util.AttributeSet, org.kuali.rice.core.util.AttributeSet)
 158  
          */
 159  
         public boolean doesDelegationQualifierMatchQualification(AttributeSet qualification, AttributeSet roleQualifier) {
 160  0
                 AttributeSet translatedQualification = translateInputAttributeSet(qualification);
 161  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 162  0
                 return performMatch(translatedQualification, roleQualifier);
 163  
         }
 164  
 
 165  
         /**
 166  
          * Returns true as a default
 167  
          * 
 168  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#shouldCacheRoleMembershipResults(java.lang.String, java.lang.String)
 169  
          */
 170  
         public boolean shouldCacheRoleMembershipResults(String namespaceCode,
 171  
                         String roleName) {
 172  0
                 return true;
 173  
         }
 174  
 
 175  
         public List<String> getQualifiersForExactMatch() {    
 176  0
                 return new ArrayList<String>(); 
 177  
         }
 178  
         
 179  
 }