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