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