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