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 java.util.Collection;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.kuali.rice.core.api.CoreConstants;
24 import org.kuali.rice.core.api.mo.common.active.Inactivatable;
25 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
26 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27 import org.kuali.rice.krad.service.KeyValuesService;
28 import org.kuali.rice.krad.service.ModuleService;
29
30
31
32
33 @Deprecated
34 public class KeyValuesServiceImpl implements KeyValuesService {
35 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KeyValuesServiceImpl.class);
36
37
38
39
40 @Override
41 public <T> Collection<T> findAll(Class<T> clazz) {
42 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(clazz);
43 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(clazz)){
44 return (Collection<T>) responsibleModuleService.getExternalizableBusinessObjectsList((Class<ExternalizableBusinessObject>) clazz, Collections.<String, Object>emptyMap());
45 }
46 if (containsActiveIndicator(clazz)) {
47 return KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(clazz, Collections.singletonMap(CoreConstants.CommonElements.ACTIVE, true));
48 }
49 if (LOG.isDebugEnabled()) {
50 LOG.debug("Active indicator not found for class " + clazz.getName());
51 }
52 return KRADServiceLocatorWeb.getLegacyDataAdapter().findAll(clazz);
53 }
54
55
56
57
58 @Override
59 public <T> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {
60 if (containsActiveIndicator(clazz)) {
61 return KRADServiceLocatorWeb.getLegacyDataAdapter().findMatchingOrderBy(clazz, Collections.singletonMap(CoreConstants.CommonElements.ACTIVE, true), sortField, sortAscending);
62 }
63 if (LOG.isDebugEnabled()) {
64 LOG.debug("Active indicator not found for class " + clazz.getName());
65 }
66 return KRADServiceLocatorWeb.getLegacyDataAdapter().findMatchingOrderBy(clazz, new HashMap<String,Object>(), sortField, sortAscending);
67 }
68
69
70
71
72 @Override
73 public <T> Collection<T> findMatching(Class<T> clazz, Map<String, Object> fieldValues) {
74 if (containsActiveIndicator(clazz)) {
75
76 Map<String,Object> criteria = new HashMap<String, Object>( fieldValues );
77 criteria.put(CoreConstants.CommonElements.ACTIVE, true);
78 return KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(clazz, criteria);
79 }
80 if (LOG.isDebugEnabled()) {
81 LOG.debug("Active indicator not found for class " + clazz.getName());
82 }
83 return KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(clazz, fieldValues);
84 }
85
86
87
88
89
90
91
92
93
94
95 private <T> boolean containsActiveIndicator(Class<T> clazz) {
96 return Inactivatable.class.isAssignableFrom(clazz);
97 }
98
99 @Override
100 public <T> Collection<T> findAllInactive(Class<T> clazz) {
101 if (containsActiveIndicator(clazz)) {
102 return KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(clazz, Collections.singletonMap(CoreConstants.CommonElements.ACTIVE, false));
103 }
104 LOG.warn("Active indicator not found for class. Assuming all are active. " + clazz.getName());
105 return Collections.emptyList();
106 }
107
108 }