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 public class KeyValuesServiceImpl implements KeyValuesService {
36 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 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(clazz);
47 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(clazz)){
48 return (Collection<T>) responsibleModuleService.getExternalizableBusinessObjectsList((Class<ExternalizableBusinessObject>) clazz, Collections.<String, Object>emptyMap());
49 }
50 if (containsActiveIndicator(clazz)) {
51 return businessObjectDao.findAllActive(clazz);
52 }
53 if (LOG.isDebugEnabled()) {
54 LOG.debug("Active indicator not found for class " + clazz.getName());
55 }
56 return businessObjectDao.findAll(clazz);
57 }
58
59 public static <E> Collection<E> createUnmodifiableUpcastList(Collection<? extends E> list, Class<E> type) {
60 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 if (containsActiveIndicator(clazz)) {
69 return businessObjectDao.findAllActiveOrderBy(clazz, sortField, sortAscending);
70 }
71 if (LOG.isDebugEnabled()) {
72 LOG.debug("Active indicator not found for class " + clazz.getName());
73 }
74 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 if (containsActiveIndicator(clazz)) {
83 return businessObjectDao.findMatchingActive(clazz, fieldValues);
84 }
85 if (LOG.isDebugEnabled()) {
86 LOG.debug("Active indicator not found for class " + clazz.getName());
87 }
88 return businessObjectDao.findMatching(clazz, fieldValues);
89 }
90
91
92
93
94
95
96 public BusinessObjectDao getBusinessObjectDao() {
97 return businessObjectDao;
98 }
99
100
101
102
103 public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
104 this.businessObjectDao = businessObjectDao;
105 }
106
107
108
109
110
111
112 public PersistenceStructureService getPersistenceStructureService() {
113 return persistenceStructureService;
114 }
115
116
117
118
119
120
121 public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
122 this.persistenceStructureService = persistenceStructureService;
123 }
124
125
126
127
128
129
130
131 private <T extends BusinessObject> boolean containsActiveIndicator(Class<T> clazz) {
132 boolean containsActive = false;
133
134 if (persistenceStructureService.listFieldNames(clazz).contains(KRADPropertyConstants.ACTIVE)) {
135 containsActive = true;
136 }
137
138 return containsActive;
139 }
140
141
142
143
144 @Override
145 public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz) {
146 if (LOG.isDebugEnabled()) {
147 LOG.debug("Active indicator not found for class " + clazz.getName());
148 }
149 return businessObjectDao.findAllInactive(clazz);
150 }
151
152 }