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.ArrayList;
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.log4j.Logger;
27 import org.kuali.rice.kns.bo.Parameter;
28 import org.kuali.rice.kns.bo.ParameterDetailType;
29 import org.kuali.rice.kns.service.BusinessObjectService;
30 import org.kuali.rice.kns.service.KNSServiceLocator;
31 import org.kuali.rice.kns.service.LookupService;
32 import org.kuali.rice.kns.service.ParameterServerService;
33 import org.kuali.rice.kns.util.KNSConstants;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class ParameterServiceImpl extends ParameterServiceBase implements ParameterServerService {
49 protected BusinessObjectService businessObjectService;
50 protected LookupService lookupService;
51
52 public Parameter retrieveParameter(String namespaceCode, String detailTypeCode, String parameterName) {
53 String applicationNamespace = KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.APPLICATION_CODE);
54 if (StringUtils.isEmpty(applicationNamespace)) {
55 applicationNamespace = KNSConstants.DEFAULT_APPLICATION_CODE;
56 }
57 Parameter parameter = fetchFromCache(namespaceCode, detailTypeCode, parameterName);
58 if (parameter != null) {
59 return parameter;
60 }
61 HashMap<String, String> crit = new HashMap<String, String>(3);
62 crit.put("parameterNamespaceCode", namespaceCode);
63 crit.put("parameterDetailTypeCode", detailTypeCode);
64 crit.put("parameterName", parameterName);
65
66
67 List<Parameter> parameters = (List<Parameter>)getBusinessObjectService().findMatching(Parameter.class, crit);
68 Parameter parameterDefault = null;
69 for (Parameter parm : parameters) {
70 if (StringUtils.equals(applicationNamespace, parm.getParameterApplicationNamespaceCode())) {
71 parameter = parm;
72 break;
73 } else if (StringUtils.equals(KNSConstants.DEFAULT_APPLICATION_CODE, parm.getParameterApplicationNamespaceCode())) {
74 parameterDefault = parm;
75 }
76 }
77
78 if (parameter == null) {
79 parameter = parameterDefault;
80 }
81
82 insertIntoCache(parameter);
83
84
85
86
87
88 return parameter;
89 }
90
91
92
93
94
95
96
97
98
99
100 @SuppressWarnings("unchecked")
101 public List<Parameter> retrieveParametersGivenLookupCriteria(Map<String, String> fieldValues) {
102 Collection<Parameter> results = getLookupService().findCollectionBySearch(Parameter.class, fieldValues);
103 return new ArrayList<Parameter>( results );
104 }
105
106 public List<ParameterDetailType> getNonDatabaseComponents() {
107 return KNSServiceLocator.getRiceApplicationConfigurationMediationService().getNonDatabaseComponents();
108 }
109
110 @SuppressWarnings("unchecked")
111 public void setParameterForTesting(Class componentClass, String parameterName, String parameterText) {
112 Parameter parameter = (Parameter) getParameter(componentClass, parameterName);
113 parameter.setParameterValue(parameterText);
114 getBusinessObjectService().save(parameter);
115 }
116
117 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
118 this.businessObjectService = businessObjectService;
119 }
120
121 protected LookupService getLookupService() {
122 if ( lookupService == null ) {
123 lookupService = KNSServiceLocator.getLookupService();
124 }
125 return lookupService;
126 }
127
128 protected BusinessObjectService getBusinessObjectService() {
129 if ( businessObjectService == null ) {
130 businessObjectService = KNSServiceLocator.getBusinessObjectService();
131 }
132 return this.businessObjectService;
133 }
134 }