Coverage Report - org.kuali.rice.kns.lookup.DictionaryLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DictionaryLookupableHelperServiceImpl
0%
0/46
0%
0/16
2.833
 
 1  
 /*
 2  
  * Copyright 2006-2008 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.lookup;
 17  
 
 18  
 import java.beans.PropertyDescriptor;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Arrays;
 21  
 import java.util.Collection;
 22  
 import java.util.Collections;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 import java.util.regex.Pattern;
 26  
 
 27  
 import org.apache.commons.beanutils.PropertyUtils;
 28  
 import org.kuali.rice.kns.authorization.BusinessObjectRestrictions;
 29  
 import org.kuali.rice.kns.bo.BusinessObject;
 30  
 import org.kuali.rice.kns.bo.BusinessObjectAttributeEntry;
 31  
 import org.kuali.rice.kns.datadictionary.control.ControlDefinition;
 32  
 import org.kuali.rice.kns.service.DataDictionaryService;
 33  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 34  
 import org.kuali.rice.kns.util.BeanPropertyComparator;
 35  
 import org.kuali.rice.kns.util.KNSConstants;
 36  
 import org.kuali.rice.kns.web.struts.form.LookupForm;
 37  
 
 38  0
 public class DictionaryLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
 39  
     private static final long serialVersionUID = 970484069493741447L;
 40  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DictionaryLookupableHelperServiceImpl.class);
 41  0
     private static final List IGNORED_FIELDS = Arrays.asList(new String[] { "class", "validationNumber" });
 42  
 
 43  
 
 44  
     
 45  
     @Override
 46  
     public List getSearchResults(Map<String, String> fieldValues) {
 47  0
         throw new UnsupportedOperationException("getSearchResults not supported for DictionaryLookupableHelperServiceImpl");
 48  
     }
 49  
 
 50  
 
 51  
     /**
 52  
      * Overrides the default lookupable search to provide a search against the BusinessObjectDictionaryService to retrieve attribute
 53  
      * definitions.
 54  
      */
 55  
     public List getSearchResults(Map fieldValues, Map fieldConversions) {
 56  0
         setBackLocation((String) fieldValues.get(KNSConstants.BACK_LOCATION));
 57  0
         setDocFormKey((String) fieldValues.get(KNSConstants.DOC_FORM_KEY));
 58  
 
 59  0
         List searchResults = new ArrayList();
 60  0
         DataDictionaryService dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
 61  
         try {
 62  0
             String boClassName = (String) fieldValues.get(KNSConstants.DICTIONARY_BO_NAME);
 63  
 
 64  
             // get bo class to query on
 65  0
             Class boClass = Class.forName(boClassName);
 66  
 
 67  
             // use reflection to get the properties for the bo
 68  
             // TODO: Get list of attributes from dictionary service
 69  0
             PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(boClass);
 70  0
             for (int i = 0; i < descriptors.length; ++i) {
 71  0
                 PropertyDescriptor propertyDescriptor = descriptors[i];
 72  
 
 73  
                 // skip fields in IGNORED_FIELDS
 74  0
                 if (IGNORED_FIELDS.contains(propertyDescriptor.getName())) {
 75  0
                     continue;
 76  
                 }
 77  
 
 78  
 
 79  
                 // ignore collection attributes for now
 80  
                 // Set BusinessObjectAttributeEntry by querying dictionary service
 81  0
                 if (!Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
 82  0
                     String propertyName = propertyDescriptor.getName();
 83  
 
 84  0
                     BusinessObjectAttributeEntry attributeEntry = new BusinessObjectAttributeEntry();
 85  0
                     attributeEntry.setAttributeName(propertyName);
 86  0
                     attributeEntry.setAttributeLabel(dataDictionaryService.getAttributeLabel(boClass, propertyName));
 87  0
                     attributeEntry.setAttributeSummary(dataDictionaryService.getAttributeSummary(boClass, propertyName));
 88  
 
 89  0
                     Integer maxLength = dataDictionaryService.getAttributeMaxLength(boClass, propertyName);
 90  0
                     if (maxLength != null) {
 91  0
                         attributeEntry.setAttributeMaxLength(maxLength.toString());
 92  
                     }
 93  
 
 94  0
                     Pattern validationExpression = dataDictionaryService.getAttributeValidatingExpression(boClass, propertyName);
 95  0
                     if (validationExpression != null) {
 96  0
                         attributeEntry.setAttributeValidatingExpression(validationExpression.pattern());
 97  
                     }
 98  0
                     ControlDefinition controlDef = dataDictionaryService.getAttributeControlDefinition(boClass, propertyName);
 99  0
                     if (controlDef != null) {
 100  0
                         attributeEntry.setAttributeControlType(controlDef.toString());
 101  
                     }
 102  0
                     Class formatterClass = dataDictionaryService.getAttributeFormatter(boClass, propertyName);
 103  0
                     if (formatterClass != null) {
 104  0
                         attributeEntry.setAttributeFormatterClassName(formatterClass.getName());
 105  
                     }
 106  
 
 107  
                     // add to result list
 108  0
                     searchResults.add(attributeEntry);
 109  
                 }
 110  
 
 111  
             }
 112  
 
 113  
             // sort list if default sort column given
 114  0
             List defaultSortColumns = getDefaultSortColumns();
 115  0
             if (defaultSortColumns.size() > 0) {
 116  0
                 Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
 117  
             }
 118  
         }
 119  0
         catch (ClassNotFoundException e) {
 120  0
             LOG.error("Class not found for bo search name" + e.getMessage());
 121  0
             throw new RuntimeException("Class not found for bo search name" + e.getMessage());
 122  0
         }
 123  
 
 124  0
         return searchResults;
 125  
     }
 126  
 
 127  
 
 128  
     /**
 129  
      * @see org.kuali.rice.kns.lookup.Lookupable#getReturnUrl(java.lang.Object, java.util.Map, java.lang.String)
 130  
      */
 131  
     @Override
 132  
     public HtmlData getReturnUrl(BusinessObject bo, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions) {
 133  0
         return getEmptyAnchorHtmlData();
 134  
     }
 135  
 
 136  
         /***
 137  
      * TODO: Revisit whether this method is needed here at all
 138  
          * 
 139  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getActionUrlHref(org.kuali.rice.kns.bo.BusinessObject, java.lang.String, java.util.List)
 140  
          */
 141  
     @Override
 142  
     protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){
 143  0
         return KNSConstants.EMPTY_STRING;
 144  
     }
 145  
 
 146  
     /**
 147  
      * @see org.kuali.rice.kns.lookup.Lookupable#getDefaultReturnType()
 148  
      */
 149  
     public List getDefaultReturnType() {
 150  0
         return new ArrayList();
 151  
     }
 152  
 
 153  
     /**
 154  
      * @see org.kuali.rice.kns.lookup.KualiLookupableImpl#getReturnKeys()
 155  
      */
 156  
     @Override
 157  
     public List getReturnKeys() {
 158  0
         return new ArrayList();
 159  
     }
 160  
 }