Coverage Report - org.kuali.rice.kew.service.impl.DocumentTypeResponsibilityTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypeResponsibilityTypeServiceImpl
0%
0/21
0%
0/14
2.75
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  
 import org.kuali.rice.kew.api.KewApiServiceLocator;
 19  
 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
 20  
 import org.kuali.rice.kim.api.KimConstants;
 21  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 22  
 import org.kuali.rice.kim.framework.responsibility.ResponsibilityTypeService;
 23  
 import org.kuali.rice.kns.kim.responsibility.KimResponsibilityTypeServiceBase;
 24  
 
 25  
 import java.util.ArrayList;
 26  
 import java.util.Collections;
 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 ResponsibilityTypeService {
 36  
         DocumentTypeService documentTypeService;
 37  
         protected String exactMatchStringAttributeName;
 38  
 
 39  
     @Override
 40  
     protected List<String> getRequiredAttributes() {
 41  0
         final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes());
 42  0
         attrs.add(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME);
 43  0
         return Collections.unmodifiableList(attrs);
 44  
     }
 45  
 
 46  
     @Override
 47  
     protected boolean isCheckRequiredAttributes() {
 48  0
         return true;
 49  
     }
 50  
         
 51  
         @Override
 52  
         protected List<Responsibility> performResponsibilityMatches(
 53  
                         Map<String, String> requestedDetails,
 54  
                         List<Responsibility> responsibilitiesList) {
 55  0
                 Map<String, List<Responsibility>> potentialDocumentTypeMatches = new HashMap<String, List<Responsibility>>();
 56  0
                 for (Responsibility responsibility : responsibilitiesList) {
 57  0
                         if ((exactMatchStringAttributeName == null)
 58  
                                         || responsibility
 59  
                                                         .getAttributes()
 60  
                                                         .get(exactMatchStringAttributeName)
 61  
                                                         .equals(
 62  
                                                                         requestedDetails
 63  
                                                                                         .get(exactMatchStringAttributeName))) {
 64  0
                                 if (!potentialDocumentTypeMatches.containsKey(responsibility
 65  
                                                 .getAttributes().get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) {
 66  0
                                         potentialDocumentTypeMatches.put(
 67  
                                                         responsibility.getAttributes().get(
 68  
                                                                         KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME),
 69  
                                                         new ArrayList<Responsibility>());
 70  
                                 }
 71  0
                                 potentialDocumentTypeMatches.get(
 72  
                                                 responsibility.getAttributes().get(
 73  
                                                                 KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)).add(
 74  
                                                 responsibility);
 75  
                         }
 76  
                 }
 77  0
                 List<Responsibility> matchingResponsibilities = new ArrayList<Responsibility>();
 78  0
                 if (potentialDocumentTypeMatches.containsKey(requestedDetails
 79  
                                 .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) {
 80  0
                         matchingResponsibilities
 81  
                                         .addAll(potentialDocumentTypeMatches.get(requestedDetails
 82  
                                                         .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)));
 83  
                 } else {
 84  0
                         String closestParentDocumentTypeName = getClosestParentDocumentTypeName(
 85  
                                         getDocumentTypeService().getDocumentTypeByName(
 86  
                                                         requestedDetails
 87  
                                                                         .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)),
 88  
                                         potentialDocumentTypeMatches.keySet());
 89  0
                         if (closestParentDocumentTypeName != null) {
 90  0
                                 matchingResponsibilities.addAll(potentialDocumentTypeMatches
 91  
                                                 .get(closestParentDocumentTypeName));
 92  
                         }
 93  
                 }
 94  0
                 return matchingResponsibilities;
 95  
         }
 96  
 
 97  
         public DocumentTypeService getDocumentTypeService() {
 98  0
                 if (documentTypeService == null) {
 99  0
                         documentTypeService = KewApiServiceLocator.getDocumentTypeService();
 100  
                 }
 101  0
                 return this.documentTypeService;
 102  
         }
 103  
 }