Coverage Report - org.kuali.rice.kew.attribute.XMLAttributeUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
XMLAttributeUtils
0%
0/43
0%
0/20
5
 
 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.attribute;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.core.api.config.ConfigurationException;
 21  
 import org.kuali.rice.core.api.uif.RemotableAttributeField;
 22  
 import org.kuali.rice.core.api.uif.RemotableQuickFinder;
 23  
 import org.kuali.rice.kns.lookup.LookupUtils;
 24  
 import org.kuali.rice.kns.web.ui.Field;
 25  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 26  
 import org.w3c.dom.NamedNodeMap;
 27  
 import org.w3c.dom.Node;
 28  
 
 29  
 import java.util.HashMap;
 30  
 import java.util.Map;
 31  
 
 32  
 /**
 33  
  * This class provides some common shared utility methods shared by the XML-based
 34  
  * attribute implementations. 
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  *
 38  
  */
 39  
 public final class XMLAttributeUtils {
 40  
 
 41  0
     private static final Logger LOG = Logger.getLogger(XMLAttributeUtils.class);
 42  
 
 43  0
         private XMLAttributeUtils() {
 44  0
                 throw new UnsupportedOperationException("do not call");
 45  
         }
 46  
 
 47  
         public static void establishFieldLookup(Field field, Node lookupNode) {
 48  0
                 NamedNodeMap quickfinderAttributes = lookupNode.getAttributes();
 49  0
                 String businessObjectClass = quickfinderAttributes.getNamedItem("businessObjectClass").getNodeValue();
 50  0
                 field.setQuickFinderClassNameImpl(businessObjectClass);
 51  0
                 for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) {
 52  0
                         Map<String, String> fieldConversionsMap = new HashMap<String, String>();
 53  0
                         Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex);
 54  0
                         if ("fieldConversions".equals(fieldConversionsChildNode)) {
 55  0
                                 for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) {
 56  0
                                         Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex);
 57  0
                                         if ("fieldConversion".equals(fieldConversionChildNode)) {
 58  0
                                                 NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes();
 59  0
                                                 String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName").getNodeValue();
 60  0
                                                 String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName").getNodeValue();
 61  0
                                                 fieldConversionsMap.put(lookupFieldName, localFieldName);
 62  
                                         }
 63  
                                 }
 64  
                         }
 65  0
                         field.setFieldConversions(fieldConversionsMap);
 66  
                 }
 67  0
         }
 68  
 
 69  
     public static void establishFieldLookup(RemotableAttributeField.Builder fieldBuilder, Node lookupNode) {
 70  0
                 NamedNodeMap quickfinderAttributes = lookupNode.getAttributes();
 71  0
         Node dataObjectNode = quickfinderAttributes.getNamedItem("dataObjectClass");
 72  0
         if (dataObjectNode == null) {
 73  
             // for legacy compatibility, though businessObjectClass is deprecated
 74  0
             dataObjectNode = quickfinderAttributes.getNamedItem("businessObjectClass");
 75  0
             if (dataObjectNode != null) {
 76  0
                 LOG.warn("Field is using deprecated 'businessObjectClass' instead of 'dataObjectClass' for lookup definition, field name is: " + fieldBuilder.getName());
 77  
             } else {
 78  0
                 throw new ConfigurationException("Failed to locate 'dataObjectClass' for lookup definition.");
 79  
             }
 80  
         }
 81  0
         String dataObjectClass = dataObjectNode.getNodeValue();
 82  0
         String baseLookupUrl = LookupUtils.getBaseLookupUrl(false);
 83  0
         RemotableQuickFinder.Builder quickFinderBuilder = RemotableQuickFinder.Builder.create(baseLookupUrl, dataObjectClass);
 84  0
                 for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) {
 85  0
                         Map<String, String> fieldConversionsMap = new HashMap<String, String>();
 86  0
                         Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex);
 87  0
                         if ("fieldConversions".equals(fieldConversionsChildNode)) {
 88  0
                                 for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) {
 89  0
                                         Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex);
 90  0
                                         if ("fieldConversion".equals(fieldConversionChildNode)) {
 91  0
                                                 NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes();
 92  0
                                                 String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName").getNodeValue();
 93  0
                                                 String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName").getNodeValue();
 94  0
                                                 fieldConversionsMap.put(lookupFieldName, localFieldName);
 95  
                                         }
 96  
                                 }
 97  
                         }
 98  0
             quickFinderBuilder.setFieldConversions(fieldConversionsMap);
 99  0
                         fieldBuilder.getWidgets().add(quickFinderBuilder);
 100  
                 }
 101  0
         }
 102  
         
 103  
 }