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.kuali.rice.krad.bo.BusinessObject; |
19 | |
import org.kuali.rice.krad.bo.ExternalizableBusinessObject; |
20 | |
import org.kuali.rice.krad.dao.BusinessObjectDao; |
21 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
22 | |
import org.kuali.rice.krad.service.KeyValuesService; |
23 | |
import org.kuali.rice.krad.service.ModuleService; |
24 | |
import org.kuali.rice.krad.service.PersistenceStructureService; |
25 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
26 | |
|
27 | |
import java.util.ArrayList; |
28 | |
import java.util.Collection; |
29 | |
import java.util.Collections; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class KeyValuesServiceImpl implements KeyValuesService { |
36 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KeyValuesServiceImpl.class); |
37 | |
|
38 | |
private BusinessObjectDao businessObjectDao; |
39 | |
private PersistenceStructureService persistenceStructureService; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz) { |
46 | 0 | ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(clazz); |
47 | 0 | if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(clazz)){ |
48 | 0 | return (Collection<T>) responsibleModuleService.getExternalizableBusinessObjectsList((Class<ExternalizableBusinessObject>) clazz, Collections.<String, Object>emptyMap()); |
49 | |
} |
50 | 0 | if (containsActiveIndicator(clazz)) { |
51 | 0 | return businessObjectDao.findAllActive(clazz); |
52 | |
} |
53 | 0 | if (LOG.isDebugEnabled()) { |
54 | 0 | LOG.debug("Active indicator not found for class " + clazz.getName()); |
55 | |
} |
56 | 0 | return businessObjectDao.findAll(clazz); |
57 | |
} |
58 | |
|
59 | |
public static <E> Collection<E> createUnmodifiableUpcastList(Collection<? extends E> list, Class<E> type) { |
60 | 0 | return new ArrayList<E>(list); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
@Override |
67 | |
public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending) { |
68 | 0 | if (containsActiveIndicator(clazz)) { |
69 | 0 | return businessObjectDao.findAllActiveOrderBy(clazz, sortField, sortAscending); |
70 | |
} |
71 | 0 | if (LOG.isDebugEnabled()) { |
72 | 0 | LOG.debug("Active indicator not found for class " + clazz.getName()); |
73 | |
} |
74 | 0 | return businessObjectDao.findAllOrderBy(clazz, sortField, sortAscending); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
@Override |
81 | |
public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, Object> fieldValues) { |
82 | 0 | if (containsActiveIndicator(clazz)) { |
83 | 0 | return businessObjectDao.findMatchingActive(clazz, fieldValues); |
84 | |
} |
85 | 0 | if (LOG.isDebugEnabled()) { |
86 | 0 | LOG.debug("Active indicator not found for class " + clazz.getName()); |
87 | |
} |
88 | 0 | return businessObjectDao.findMatching(clazz, fieldValues); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public BusinessObjectDao getBusinessObjectDao() { |
97 | 0 | return businessObjectDao; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) { |
104 | 0 | this.businessObjectDao = businessObjectDao; |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public PersistenceStructureService getPersistenceStructureService() { |
113 | 0 | return persistenceStructureService; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) { |
122 | 0 | this.persistenceStructureService = persistenceStructureService; |
123 | 0 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
private <T extends BusinessObject> boolean containsActiveIndicator(Class<T> clazz) { |
132 | 0 | boolean containsActive = false; |
133 | |
|
134 | 0 | if (persistenceStructureService.listFieldNames(clazz).contains(KRADPropertyConstants.ACTIVE)) { |
135 | 0 | containsActive = true; |
136 | |
} |
137 | |
|
138 | 0 | return containsActive; |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
@Override |
145 | |
public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz) { |
146 | 0 | if (LOG.isDebugEnabled()) { |
147 | 0 | LOG.debug("Active indicator not found for class " + clazz.getName()); |
148 | |
} |
149 | 0 | return businessObjectDao.findAllInactive(clazz); |
150 | |
} |
151 | |
|
152 | |
} |