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