Coverage Report - org.kuali.rice.kns.workflow.attribute.DataDictionaryQualifierResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryQualifierResolver
0%
0/29
0%
0/14
2.8
 
 1  
 /*
 2  
  * Copyright 2008-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.ArrayList;
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.kuali.rice.core.util.AttributeSet;
 23  
 import org.kuali.rice.kew.engine.RouteContext;
 24  
 import org.kuali.rice.kns.datadictionary.DocumentEntry;
 25  
 import org.kuali.rice.kns.datadictionary.RoutingTypeDefinition;
 26  
 import org.kuali.rice.kns.datadictionary.WorkflowAttributes;
 27  
 import org.kuali.rice.kns.document.Document;
 28  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 29  
 import org.kuali.rice.kns.service.KNSServiceLocatorInternal;
 30  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 31  
 
 32  
 /**
 33  
  * QualifierResolver which uses Data Dictionary defined workflow attributes to gather a collection
 34  
  * of qualifiers to use to determine the responsibility for a document at a given workflow route node.
 35  
  * 
 36  
  * WorkflowAttributes can be defined in the data dictionary like so (this has been abbreviated):
 37  
  * 
 38  
  * <!-- Exported Workflow Attributes -->
 39  
  *   <bean id="DisbursementVoucherDocument-workflowAttributes" parent="DisbursementVoucherDocument-workflowAttributes-parentBean"/>
 40  
  *
 41  
  *   <bean id="DisbursementVoucherDocument-workflowAttributes-parentBean" abstract="true" parent="WorkflowAttributes">
 42  
  *       <property name="routingTypeDefinitions">
 43  
  *           <map>
 44  
  *               <!-- no qualifiers for purchasing node -->
 45  
  *               <entry key="Account" value-ref="RoutingType-AccountingDocument-Account-sourceOnly"/>
 46  
  *               <entry key="AccountingOrganizationHierarchy" value-ref="RoutingType-AccountingDocument-OrganizationHierarchy-sourceOnly"/>
 47  
  *               <entry key="Campus" value-ref="DisbursementVoucherDocument-RoutingType-Campus"/>
 48  
  *               <!-- no qualifiers for tax review -->
 49  
  *               <!-- no qualifiers for travel review -->
 50  
  *               <entry key="PaymentMethod" value-ref="DisbursementVoucherDocument-RoutingType-PaymentMethod"/>
 51  
  *               <entry key="Award" value-ref="RoutingType-AccountingDocument-Award"/>
 52  
  *           </map>
 53  
  *       </property>
 54  
  *   </bean>
 55  
  * 
 56  
  *   <bean id="DisbursementVoucherDocument-RoutingType-PaymentMethod" class="org.kuali.rice.kns.datadictionary.RoutingTypeDefinition">
 57  
  *       <property name="routingAttributes">
 58  
  *           <list>
 59  
  *               <bean class="org.kuali.rice.kns.datadictionary.RoutingAttribute">
 60  
  *                   <property name="qualificationAttributeName" value="disbVchrPaymentMethodCode"/>
 61  
  *               </bean>
 62  
  *           </list>
 63  
  *       </property>
 64  
  *       <property name="documentValuePathGroups">
 65  
  *           <list>
 66  
  *               <bean class="org.kuali.rice.kns.datadictionary.DocumentValuePathGroup">
 67  
  *                   <property name="documentValues">
 68  
  *                       <list>
 69  
  *                           <value>disbVchrPaymentMethodCode</value>
 70  
  *                       </list>
 71  
  *                   </property>
 72  
  *               </bean>
 73  
  *           </list>
 74  
  *       </property>
 75  
  *   </bean> 
 76  
  * 
 77  
  * At the PaymentMethod node of the document, the DisbursementVoucherDocument-RoutingType-PaymentMethod RoutingTypeDefinition will be
 78  
  * consulted; it will pull values from the document (in this case, document.disbVchrPaymentMethodCode) and populate those
 79  
  * into the role qualifier AttributeSet, with the key being the qualificationAttributeName and the value being the value of the property
 80  
  * listed in the documentValuePathGroups in the document.
 81  
  */
 82  0
 public class DataDictionaryQualifierResolver extends QualifierResolverBase {
 83  
 //    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DataDictionaryQualifierResolver.class);
 84  
     
 85  
 
 86  
     /**
 87  
      * Given the RouteContext, determines the document type of the document being routed and the current
 88  
      * route nodes; generates a List of qualifier AttributeSets based on the the contents of the document. 
 89  
      * @see org.kuali.rice.kew.role.QualifierResolver#resolve(org.kuali.rice.kew.engine.RouteContext)
 90  
      */
 91  
     public List<AttributeSet> resolve(RouteContext context) {
 92  0
         final String routeLevel = context.getNodeInstance().getName();
 93  0
         final DocumentEntry documentEntry = getDocumentEntry(context);
 94  0
         final RoutingTypeDefinition routingTypeDefinition = getWorkflowAttributeDefintion(documentEntry, routeLevel);
 95  0
         final Document document = getDocument(context);
 96  0
         List<AttributeSet> qualifiers = null;
 97  
         
 98  0
         if (document != null && routingTypeDefinition != null) {
 99  0
             qualifiers = KNSServiceLocatorInternal.getWorkflowAttributePropertyResolutionService().resolveRoutingTypeQualifiers(document, routingTypeDefinition);
 100  
         } else {
 101  0
             qualifiers = new ArrayList<AttributeSet>();
 102  0
             AttributeSet basicQualifier = new AttributeSet();
 103  0
             qualifiers.add(basicQualifier);
 104  
         }
 105  0
         decorateWithCommonQualifiers(qualifiers, document, documentEntry, routeLevel);
 106  0
         return qualifiers;
 107  
     }
 108  
 
 109  
     /**
 110  
      * Retrieves the data dictionary entry for the document being operated on by the given route context
 111  
      * @param context the current route context
 112  
      * @return the data dictionary document entry
 113  
      */
 114  
     protected DocumentEntry getDocumentEntry(RouteContext context) {
 115  0
         return KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDocumentEntry(context.getDocument().getDocumentType().getName());
 116  
     }
 117  
 
 118  
     /**
 119  
      * Retrieves the proper List of WorkflowAttributes for the given route level from the data dictionary
 120  
      * document entry
 121  
      * @param documentEntry the data dictionary document entry for the currently routed document
 122  
      * @param routeLevelName the name of the route level
 123  
      * @return a WorkflowAttributeDefinition if one could be found for the route level; otherwise, nothing
 124  
      */
 125  
     protected RoutingTypeDefinition getWorkflowAttributeDefintion(DocumentEntry documentEntry, String routeLevelName) {
 126  0
        final WorkflowAttributes workflowAttributes = documentEntry.getWorkflowAttributes();
 127  0
        if ( workflowAttributes == null ) {
 128  0
            return null;
 129  
        }
 130  0
        final Map<String, RoutingTypeDefinition> routingTypeMap = workflowAttributes.getRoutingTypeDefinitions();
 131  0
        if (routingTypeMap.containsKey(routeLevelName)) return routingTypeMap.get(routeLevelName);
 132  0
        return null;
 133  
     }
 134  
     
 135  
     /**
 136  
      * Add common qualifiers to every AttributeSet in the given List of AttributeSet
 137  
      * @param qualifiers a List of AttributeSets to add common qualifiers to
 138  
      * @param document the document currently being routed
 139  
      * @param documentEntry the data dictionary entry of the type of document currently being routed
 140  
      * @param routeLevel the document's current route level
 141  
      */
 142  
     protected void decorateWithCommonQualifiers(List<AttributeSet> qualifiers, Document document, DocumentEntry documentEntry, String routeLevel) {
 143  0
         for (AttributeSet qualifier : qualifiers) {
 144  0
             addCommonQualifiersToAttributeSet(qualifier, document, documentEntry, routeLevel);
 145  
         }
 146  0
     }
 147  
     
 148  
     /**
 149  
      * Adds common qualifiers to a given AttributeSet
 150  
      * @param qualifier an AttributeSet to add common qualifiers to
 151  
      * @param document the document currently being routed
 152  
      * @param documentEntry the data dictionary entry of the type of document currently being routed
 153  
      * @param routeLevel the document's current route level
 154  
      */
 155  
     protected void addCommonQualifiersToAttributeSet(AttributeSet qualifier, Document document, DocumentEntry documentEntry, String routeLevel) {
 156  0
         if ( document != null ) {
 157  0
             qualifier.put(KIM_ATTRIBUTE_DOCUMENT_NUMBER, document.getDocumentNumber());
 158  
         }
 159  0
         if ( documentEntry != null ) {
 160  0
             qualifier.put(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME, documentEntry.getDocumentTypeName());
 161  
         }
 162  0
         qualifier.put(KIM_ATTRIBUTE_ROUTE_LEVEL_NAME, routeLevel);
 163  0
     }
 164  
 }