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