Coverage Report - org.kuali.rice.kns.service.impl.DocumentTypePermissionTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypePermissionTypeServiceImpl
0%
0/22
0%
0/16
5
 
 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.kns.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashSet;
 20  
 import java.util.List;
 21  
 import java.util.Set;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 25  
 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
 26  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 27  
 import org.kuali.rice.kim.bo.impl.KimAttributes;
 28  
 import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo;
 29  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 30  
 import org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase;
 31  
 import org.kuali.rice.kim.util.KimCommonUtils;
 32  
 
 33  
 /**
 34  
  * This is a description of what this class does - mpham don't forget to fill
 35  
  * this in.
 36  
  * 
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  * 
 39  
  */
 40  0
 public class DocumentTypePermissionTypeServiceImpl extends KimPermissionTypeServiceBase {
 41  
         protected transient DocumentTypeService documentTypeService;
 42  
         
 43  
         {
 44  0
                 requiredAttributes.add( KimAttributes.DOCUMENT_TYPE_NAME );
 45  0
                 checkRequiredAttributes = true;
 46  0
         }
 47  
         /**
 48  
          * Loops over the given permissions and returns the most specific permission that matches.
 49  
          * 
 50  
          * That is, if a permission exists for the document type, then the permission for any 
 51  
          * parent document will not be considered/returned.
 52  
          * 
 53  
          * @see org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase#performPermissionMatches(org.kuali.rice.kim.bo.types.dto.AttributeSet, java.util.List)
 54  
          */
 55  
         @Override
 56  
         protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails,
 57  
                         List<KimPermissionInfo> permissionsList) {
 58  
                 // pull all the potential parent doc type names from the permission list
 59  0
                 Set<String> permissionDocTypeNames = new HashSet<String>( permissionsList.size() );
 60  0
                 for ( KimPermissionInfo kpi : permissionsList ) {
 61  0
                         String docTypeName = kpi.getDetails().get( KimAttributes.DOCUMENT_TYPE_NAME );
 62  0
                         if ( StringUtils.isNotBlank( docTypeName ) ) {
 63  0
                                 permissionDocTypeNames.add( docTypeName );
 64  
                         }
 65  0
                 }
 66  
                 // find the parent documents which match
 67  0
                 DocumentType docType = getDocumentTypeService().findByName(requestedDetails.get(KimAttributes.DOCUMENT_TYPE_NAME));
 68  0
                 String matchingDocTypeName = KimCommonUtils.getClosestParentDocumentTypeName(docType, permissionDocTypeNames);
 69  
                 // re-loop over the permissions and build a new list of the ones which have the
 70  
                 // matching document type names in their details
 71  0
                 List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>();
 72  0
                 for ( KimPermissionInfo kpi : permissionsList ) {
 73  0
                         String docTypeName = kpi.getDetails().get( KimAttributes.DOCUMENT_TYPE_NAME );
 74  
                         // only allow a match on the "*" type if no matching document types were found
 75  0
                         if((StringUtils.isEmpty(matchingDocTypeName) && StringUtils.equals(docTypeName,"*")) 
 76  
                                 || (StringUtils.isNotEmpty(matchingDocTypeName) && matchingDocTypeName.equals(docTypeName))) {
 77  0
                                 matchingPermissions.add( kpi );
 78  
                         }
 79  0
                 }
 80  
 
 81  0
                 return matchingPermissions;
 82  
         }
 83  
         
 84  
         protected DocumentTypeService getDocumentTypeService() {
 85  0
                 if ( documentTypeService == null ) {
 86  0
                         documentTypeService = KEWServiceLocator.getDocumentTypeService();
 87  
                 }
 88  0
                 return this.documentTypeService;
 89  
         }
 90  
 
 91  
 }