|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
   package org.kuali.rice.kns.service.impl;  | 
  |  13 |     | 
     | 
  |  14 |     | 
   import java.util.Collection;  | 
  |  15 |     | 
   import java.util.Iterator;  | 
  |  16 |     | 
   import java.util.List;  | 
  |  17 |     | 
   import java.util.Map;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  20 |     | 
   import org.kuali.rice.core.api.config.property.ConfigurationService;  | 
  |  21 |     | 
   import org.kuali.rice.kns.dao.LookupDao;  | 
  |  22 |     | 
   import org.kuali.rice.kns.service.KNSServiceLocatorWeb;  | 
  |  23 |     | 
   import org.kuali.rice.kns.service.LookupService;  | 
  |  24 |     | 
   import org.kuali.rice.kns.util.KNSConstants;  | 
  |  25 |     | 
     | 
  |  26 |     | 
     | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |    0 |    public class LookupServiceImpl implements LookupService { | 
  |  34 |    0 |        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupServiceImpl.class);  | 
  |  35 |     | 
     | 
  |  36 |     | 
       private LookupDao lookupDao;  | 
  |  37 |     | 
       private ConfigurationService kualiConfigurationService;  | 
  |  38 |     | 
     | 
  |  39 |     | 
       public <T extends Object> Collection<T> findCollectionBySearchUnbounded(Class<T> example,  | 
  |  40 |     | 
               Map<String, String> formProps) { | 
  |  41 |    0 |            return findCollectionBySearchHelper(example, formProps, true);  | 
  |  42 |     | 
       }  | 
  |  43 |     | 
     | 
  |  44 |     | 
         | 
  |  45 |     | 
     | 
  |  46 |     | 
     | 
  |  47 |     | 
     | 
  |  48 |     | 
     | 
  |  49 |     | 
       public <T extends Object> Collection<T> findCollectionBySearch(Class<T> example, Map<String, String> formProps) { | 
  |  50 |    0 |            return findCollectionBySearchHelper(example, formProps, false);  | 
  |  51 |     | 
       }  | 
  |  52 |     | 
     | 
  |  53 |     | 
       public <T extends Object> Collection<T> findCollectionBySearchHelper(Class<T> example,  | 
  |  54 |     | 
               Map<String, String> formProps, boolean unbounded) { | 
  |  55 |    0 |            return lookupDao.findCollectionBySearchHelper(example, formProps, unbounded,  | 
  |  56 |     | 
                   allPrimaryKeyValuesPresentAndNotWildcard(example, formProps));  | 
  |  57 |     | 
       }  | 
  |  58 |     | 
     | 
  |  59 |     | 
         | 
  |  60 |     | 
     | 
  |  61 |     | 
     | 
  |  62 |     | 
     | 
  |  63 |     | 
     | 
  |  64 |     | 
     | 
  |  65 |     | 
       public <T extends Object> T findObjectBySearch(Class<T> example, Map<String, String> formProps) { | 
  |  66 |    0 |            if (example == null || formProps == null) { | 
  |  67 |    0 |                throw new IllegalArgumentException("Object and Map must not be null"); | 
  |  68 |     | 
           }  | 
  |  69 |     | 
     | 
  |  70 |    0 |            T obj = null;  | 
  |  71 |     | 
           try { | 
  |  72 |    0 |                obj = example.newInstance();  | 
  |  73 |    0 |            } catch (IllegalAccessException e) { | 
  |  74 |    0 |                throw new RuntimeException("Cannot get new instance of " + example.getName(), e); | 
  |  75 |    0 |            } catch (InstantiationException e) { | 
  |  76 |    0 |                throw new RuntimeException("Cannot instantiate " + example.getName(), e); | 
  |  77 |    0 |            }  | 
  |  78 |     | 
     | 
  |  79 |    0 |            return lookupDao.findObjectByMap(obj, formProps);  | 
  |  80 |     | 
       }  | 
  |  81 |     | 
     | 
  |  82 |     | 
       public boolean allPrimaryKeyValuesPresentAndNotWildcard(Class<?> boClass, Map<String, String> formProps) { | 
  |  83 |    0 |            List<String> pkFields = KNSServiceLocatorWeb.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(  | 
  |  84 |     | 
                   boClass);  | 
  |  85 |    0 |            Iterator<String> pkIter = pkFields.iterator();  | 
  |  86 |    0 |            boolean returnVal = true;  | 
  |  87 |    0 |            while (returnVal && pkIter.hasNext()) { | 
  |  88 |    0 |                String pkName = (String) pkIter.next();  | 
  |  89 |    0 |                String pkValue = (String) formProps.get(pkName);  | 
  |  90 |     | 
     | 
  |  91 |    0 |                if (StringUtils.isBlank(pkValue)) { | 
  |  92 |    0 |                    returnVal = false;  | 
  |  93 |    0 |                } else if (StringUtils.indexOfAny(pkValue, KNSConstants.QUERY_CHARACTERS) != -1) { | 
  |  94 |    0 |                    returnVal = false;  | 
  |  95 |     | 
               }  | 
  |  96 |    0 |            }  | 
  |  97 |    0 |            return returnVal;  | 
  |  98 |     | 
       }  | 
  |  99 |     | 
     | 
  |  100 |     | 
         | 
  |  101 |     | 
     | 
  |  102 |     | 
     | 
  |  103 |     | 
       public LookupDao getLookupDao() { | 
  |  104 |    0 |            return lookupDao;  | 
  |  105 |     | 
       }  | 
  |  106 |     | 
     | 
  |  107 |     | 
         | 
  |  108 |     | 
     | 
  |  109 |     | 
     | 
  |  110 |     | 
       public void setLookupDao(LookupDao lookupDao) { | 
  |  111 |    0 |            this.lookupDao = lookupDao;  | 
  |  112 |    0 |        }  | 
  |  113 |     | 
     | 
  |  114 |     | 
       public ConfigurationService getKualiConfigurationService() { | 
  |  115 |    0 |            return kualiConfigurationService;  | 
  |  116 |     | 
       }  | 
  |  117 |     | 
     | 
  |  118 |     | 
       public void setKualiConfigurationService(ConfigurationService kualiConfigurationService) { | 
  |  119 |    0 |            this.kualiConfigurationService = kualiConfigurationService;  | 
  |  120 |    0 |        }  | 
  |  121 |     | 
   }  |