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