Coverage Report - org.kuali.rice.kns.workflow.attribute.QualifierResolverBase
 
Classes in this File Line Coverage Branch Coverage Complexity
QualifierResolverBase
0%
0/24
0%
0/12
2.8
 
 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.kns.workflow.attribute;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.core.util.AttributeSet;
 22  
 import org.kuali.rice.kew.engine.RouteContext;
 23  
 import org.kuali.rice.kew.exception.WorkflowException;
 24  
 import org.kuali.rice.kew.role.QualifierResolver;
 25  
 import org.kuali.rice.kim.util.KimConstants;
 26  
 import org.kuali.rice.kns.document.Document;
 27  
 import org.kuali.rice.kns.service.DocumentService;
 28  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 29  
 
 30  
 /**
 31  
  * This is a description of what this class does - kellerj don't forget to fill this in. 
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  0
 public abstract class QualifierResolverBase implements QualifierResolver {
 37  0
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(QualifierResolverBase.class);
 38  
 
 39  
     protected static final String KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME = KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME;
 40  
     protected static final String KIM_ATTRIBUTE_DOCUMENT_NUMBER = KimConstants.AttributeConstants.DOCUMENT_NUMBER;
 41  
     protected static final String KIM_ATTRIBUTE_ROUTE_LEVEL_NAME = KimConstants.AttributeConstants.ROUTE_NODE_NAME;
 42  
 
 43  
     private static DocumentService documentService;
 44  
     
 45  
     /**
 46  
      * Retrieves the document that the current route context is operating on
 47  
      * @param context the current route context
 48  
      * @return the document
 49  
      */
 50  
     protected Document getDocument(RouteContext context) {
 51  0
         String documentID = getDocumentId(context);
 52  
         
 53  0
         if (documentID != null) {
 54  
             try {
 55  0
                 return getDocumentService().getByDocumentHeaderIdSessionless(documentID);
 56  
             }
 57  0
             catch (WorkflowException e) {
 58  0
                 LOG.error("Unable to retrieve document with system user.", e);
 59  0
                 return null;
 60  
             }
 61  
         }
 62  0
         return null;
 63  
     }
 64  
 
 65  
     
 66  
     /**
 67  
      * Retrieves the id of the current document from the RouteContext
 68  
      * @param context the current route context
 69  
      * @return the id of the document
 70  
      */
 71  
     protected String getDocumentId(RouteContext context) {
 72  0
         final String documentID = context.getNodeInstance().getDocumentId();
 73  0
         return documentID != null ? documentID.toString() : null;
 74  
     }
 75  
 
 76  
 
 77  
         public DocumentService getDocumentService() {
 78  0
                 if ( documentService == null ) {
 79  0
                         documentService = KNSServiceLocatorWeb.getDocumentService();
 80  
                 }
 81  0
                 return documentService;
 82  
         }
 83  
         
 84  
     /**
 85  
      * Add common qualifiers to every AttributeSet in the given List of AttributeSet
 86  
      * @param qualifiers a List of AttributeSets to add common qualifiers to
 87  
      * @param document the document currently being routed
 88  
      * @param documentEntry the data dictionary entry of the type of document currently being routed
 89  
      * @param routeLevel the document's current route level
 90  
      */
 91  
     protected void decorateWithCommonQualifiers(List<AttributeSet> qualifiers, RouteContext context, String customDocTypeName) {
 92  0
         for (AttributeSet qualifier : qualifiers) {
 93  0
             addCommonQualifiersToAttributeSet(qualifier, context, customDocTypeName);
 94  
         }
 95  0
     }
 96  
     
 97  
     /**
 98  
      * Adds common qualifiers to a given AttributeSet
 99  
      * @param qualifier an AttributeSet to add common qualifiers to
 100  
      * @param document the document currently being routed
 101  
      * @param documentEntry the data dictionary entry of the type of document currently being routed
 102  
      * @param routeLevel the document's current route level
 103  
      */
 104  
     protected void addCommonQualifiersToAttributeSet(AttributeSet qualifier, RouteContext context, String customDocTypeName) {            
 105  0
         qualifier.put(KIM_ATTRIBUTE_DOCUMENT_NUMBER, context.getDocument().getDocumentId() );
 106  0
         if ( !qualifier.containsKey(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME) ) {
 107  0
                 if ( StringUtils.isBlank(customDocTypeName)) {
 108  0
                         qualifier.put(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME, 
 109  
                                         context.getDocument().getDocumentType().getName() );
 110  
                 } else {
 111  0
                         qualifier.put(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME, customDocTypeName );                
 112  
                 }
 113  
         }
 114  0
         qualifier.put(KIM_ATTRIBUTE_ROUTE_LEVEL_NAME, context.getNodeInstance().getName());
 115  0
     }
 116  
         
 117  
 }