Coverage Report - org.kuali.rice.kew.service.impl.DocumentTypeResponsibilityTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypeResponsibilityTypeServiceImpl
0%
0/20
0%
0/14
4.5
 
 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 permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.service.impl;
 17  
 
 18  
 
 19  
 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
 20  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 21  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 22  
 import org.kuali.rice.kim.impl.responsibility.KimResponsibilityTypeService;
 23  
 import org.kuali.rice.kim.impl.responsibility.KimResponsibilityTypeServiceBase;
 24  
 import org.kuali.rice.kim.util.KimConstants;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.HashMap;
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 
 31  
 /**
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  0
 public class DocumentTypeResponsibilityTypeServiceImpl extends
 35  
         KimResponsibilityTypeServiceBase implements KimResponsibilityTypeService {
 36  
         DocumentTypeService documentTypeService;
 37  
         protected String exactMatchStringAttributeName;
 38  
 
 39  
         {
 40  0
                 requiredAttributes.add( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME );
 41  0
                 checkRequiredAttributes = true;
 42  0
         }
 43  
         
 44  
         @Override
 45  
         protected List<Responsibility> performResponsibilityMatches(
 46  
                         Map<String, String> requestedDetails,
 47  
                         List<Responsibility> responsibilitiesList) {
 48  0
                 Map<String, List<Responsibility>> potentialDocumentTypeMatches = new HashMap<String, List<Responsibility>>();
 49  0
                 for (Responsibility responsibility : responsibilitiesList) {
 50  0
                         if ((exactMatchStringAttributeName == null)
 51  
                                         || responsibility
 52  
                                                         .getAttributes()
 53  
                                                         .get(exactMatchStringAttributeName)
 54  
                                                         .equals(
 55  
                                                                         requestedDetails
 56  
                                                                                         .get(exactMatchStringAttributeName))) {
 57  0
                                 if (!potentialDocumentTypeMatches.containsKey(responsibility
 58  
                                                 .getAttributes().get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) {
 59  0
                                         potentialDocumentTypeMatches.put(
 60  
                                                         responsibility.getAttributes().get(
 61  
                                                                         KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME),
 62  
                                                         new ArrayList<Responsibility>());
 63  
                                 }
 64  0
                                 potentialDocumentTypeMatches.get(
 65  
                                                 responsibility.getAttributes().get(
 66  
                                                                 KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)).add(
 67  
                                                 responsibility);
 68  
                         }
 69  
                 }
 70  0
                 List<Responsibility> matchingResponsibilities = new ArrayList<Responsibility>();
 71  0
                 if (potentialDocumentTypeMatches.containsKey(requestedDetails
 72  
                                 .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) {
 73  0
                         matchingResponsibilities
 74  
                                         .addAll(potentialDocumentTypeMatches.get(requestedDetails
 75  
                                                         .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)));
 76  
                 } else {
 77  0
                         String closestParentDocumentTypeName = getClosestParentDocumentTypeName(
 78  
                                         getDocumentTypeService().findByName(
 79  
                                                         requestedDetails
 80  
                                                                         .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)),
 81  
                                         potentialDocumentTypeMatches.keySet());
 82  0
                         if (closestParentDocumentTypeName != null) {
 83  0
                                 matchingResponsibilities.addAll(potentialDocumentTypeMatches
 84  
                                                 .get(closestParentDocumentTypeName));
 85  
                         }
 86  
                 }
 87  0
                 return matchingResponsibilities;
 88  
         }
 89  
 
 90  
         public DocumentTypeService getDocumentTypeService() {
 91  0
                 if (documentTypeService == null) {
 92  0
                         documentTypeService = KEWServiceLocator.getDocumentTypeService();
 93  
                 }
 94  0
                 return this.documentTypeService;
 95  
         }
 96  
 }