1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.parameter; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.parameter.Parameter; |
20 | |
import org.kuali.rice.core.api.parameter.ParameterKey; |
21 | |
import org.kuali.rice.core.api.parameter.ParameterRepositoryService; |
22 | |
import org.kuali.rice.core.framework.parameter.ParameterService; |
23 | |
import org.kuali.rice.krad.service.KualiModuleService; |
24 | |
import org.kuali.rice.krad.util.KRADConstants; |
25 | |
|
26 | |
import java.util.Collection; |
27 | |
|
28 | 0 | public class ParameterServiceImpl implements ParameterService { |
29 | |
private KualiModuleService kualiModuleService; |
30 | |
private ParameterRepositoryService parameterRepositoryService; |
31 | 0 | private String applicationId = KRADConstants.DEFAULT_PARAMETER_APPLICATION_ID; |
32 | |
|
33 | |
@Override |
34 | |
public Parameter createParameter(Parameter parameter) { |
35 | 0 | return parameterRepositoryService.createParameter(parameter); |
36 | |
} |
37 | |
|
38 | |
@Override |
39 | |
public Parameter updateParameter(Parameter parameter) { |
40 | 0 | return parameterRepositoryService.updateParameter(parameter); |
41 | |
} |
42 | |
|
43 | |
@Override |
44 | |
public Parameter getParameter(String namespaceCode, String componentCode, String parameterName) { |
45 | 0 | return exec(new Fun<Parameter>() { |
46 | |
@Override public Parameter f(ParameterKey key) { |
47 | 0 | return parameterRepositoryService.getParameter(key); |
48 | |
} |
49 | |
}, namespaceCode, componentCode, parameterName); |
50 | |
} |
51 | |
|
52 | |
@Override |
53 | |
public Parameter getParameter(Class<?> componentClass, String parameterName) { |
54 | 0 | return exec(new Fun<Parameter>() { |
55 | |
@Override public Parameter f(ParameterKey key) { |
56 | 0 | return parameterRepositoryService.getParameter(key); |
57 | |
} |
58 | |
}, componentClass, parameterName); |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public Boolean parameterExists(String namespaceCode, String componentCode, String parameterName) { |
63 | 0 | return exec(new Fun<Boolean>() { |
64 | |
@Override |
65 | |
public Boolean f(ParameterKey key) { |
66 | 0 | return Boolean.valueOf(parameterRepositoryService.getParameter(key) != null); |
67 | |
} |
68 | |
}, namespaceCode, componentCode, parameterName); |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
public Boolean parameterExists(Class<?> componentClass, String parameterName) { |
73 | 0 | return exec(new Fun<Boolean>() { |
74 | |
@Override |
75 | |
public Boolean f(ParameterKey key) { |
76 | 0 | return Boolean.valueOf(parameterRepositoryService.getParameter(key) != null); |
77 | |
} |
78 | |
}, componentClass, parameterName); |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public Boolean getParameterValueAsBoolean(String namespaceCode, String componentCode, String parameterName) { |
83 | 0 | return exec(new Fun<Boolean>() { |
84 | |
@Override |
85 | |
public Boolean f(ParameterKey key) { |
86 | 0 | return parameterRepositoryService.getParameterValueAsBoolean(key); |
87 | |
} |
88 | |
}, namespaceCode, componentCode, parameterName); |
89 | |
} |
90 | |
|
91 | |
@Override |
92 | |
public Boolean getParameterValueAsBoolean(String namespaceCode, String componentCode, String parameterName, Boolean defaultValue) { |
93 | 0 | final Boolean value = getParameterValueAsBoolean(namespaceCode, componentCode, parameterName); |
94 | 0 | return (value != null) ? value : defaultValue; |
95 | |
} |
96 | |
|
97 | |
@Override |
98 | |
public Boolean getParameterValueAsBoolean(Class<?> componentClass, String parameterName) { |
99 | 0 | return exec(new Fun<Boolean>() { |
100 | |
@Override |
101 | |
public Boolean f(ParameterKey key) { |
102 | 0 | return parameterRepositoryService.getParameterValueAsBoolean(key); |
103 | |
} |
104 | |
}, componentClass, parameterName); |
105 | |
} |
106 | |
|
107 | |
@Override |
108 | |
public Boolean getParameterValueAsBoolean(Class<?> componentClass, String parameterName, Boolean defaultValue) { |
109 | 0 | final Boolean value = getParameterValueAsBoolean(componentClass, parameterName); |
110 | 0 | return (value != null) ? value : defaultValue; |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public String getParameterValueAsString(String namespaceCode, String componentCode, String parameterName) { |
115 | 0 | return exec(new Fun<String>() { |
116 | |
@Override |
117 | |
public String f(ParameterKey key) { |
118 | 0 | return parameterRepositoryService.getParameterValueAsString(key); |
119 | |
} |
120 | |
}, namespaceCode, componentCode, parameterName); |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
public String getParameterValueAsString(String namespaceCode, String componentCode, String parameterName, String defaultValue) { |
125 | 0 | final String value = getParameterValueAsString(namespaceCode, componentCode, parameterName); |
126 | 0 | return (value != null) ? value : defaultValue; |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public String getParameterValueAsString(Class<?> componentClass, String parameterName) { |
131 | 0 | return exec(new Fun<String>() { |
132 | |
@Override public String f(ParameterKey key) { |
133 | 0 | return parameterRepositoryService.getParameterValueAsString(key); |
134 | |
} |
135 | |
}, componentClass, parameterName); |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public String getParameterValueAsString(Class<?> componentClass, String parameterName, String defaultValue) { |
140 | 0 | final String value = getParameterValueAsString(componentClass, parameterName); |
141 | 0 | return (value != null) ? value : defaultValue; |
142 | |
} |
143 | |
|
144 | |
@Override |
145 | |
public Collection<String> getParameterValuesAsString(String namespaceCode, String componentCode, String parameterName) { |
146 | 0 | return exec(new Fun<Collection<String>>() { |
147 | |
@Override public Collection<String> f(ParameterKey key) { |
148 | 0 | return parameterRepositoryService.getParameterValuesAsString(key); |
149 | |
} |
150 | |
}, namespaceCode, componentCode, parameterName); |
151 | |
} |
152 | |
|
153 | |
@Override |
154 | |
public Collection<String> getParameterValuesAsString(Class<?> componentClass, String parameterName) { |
155 | 0 | return exec(new Fun<Collection<String>>() { |
156 | |
@Override public Collection<String> f(ParameterKey key) { |
157 | 0 | return parameterRepositoryService.getParameterValuesAsString(key); |
158 | |
} |
159 | |
}, componentClass, parameterName); |
160 | |
} |
161 | |
|
162 | |
@Override |
163 | |
public Collection<String> getSubParameterValuesAsString(String namespaceCode, String componentCode, String parameterName, final String constrainingValue) { |
164 | 0 | return exec(new Fun<Collection<String>>() { |
165 | |
@Override public Collection<String> f(ParameterKey key) { |
166 | 0 | return parameterRepositoryService.getSubParameterValuesAsString(key, constrainingValue); |
167 | |
} |
168 | |
}, namespaceCode, componentCode, parameterName); |
169 | |
} |
170 | |
|
171 | |
@Override |
172 | |
public Collection<String> getSubParameterValuesAsString(Class<?> componentClass, String parameterName, final String constrainingValue) { |
173 | 0 | return exec(new Fun<Collection<String>>() { |
174 | |
@Override public Collection<String> f(ParameterKey key) { |
175 | 0 | return parameterRepositoryService.getSubParameterValuesAsString(key, constrainingValue); |
176 | |
} |
177 | |
}, componentClass, parameterName); |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public String getSubParameterValueAsString(String namespaceCode, String componentCode, String parameterName, final String constrainingValue) { |
182 | 0 | return exec(new Fun<String>() { |
183 | |
@Override public String f(ParameterKey key) { |
184 | 0 | return parameterRepositoryService.getSubParameterValueAsString(key, constrainingValue); |
185 | |
} |
186 | |
}, namespaceCode, componentCode, parameterName); |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public String getSubParameterValueAsString(Class<?> componentClass, String parameterName, final String constrainingValue) { |
191 | 0 | return exec(new Fun<String>() { |
192 | |
@Override public String f(ParameterKey key) { |
193 | 0 | return parameterRepositoryService.getSubParameterValueAsString(key, constrainingValue); |
194 | |
} |
195 | |
}, componentClass, parameterName); |
196 | |
} |
197 | |
|
198 | |
public void setKualiModuleService(KualiModuleService kualiModuleService) { |
199 | 0 | this.kualiModuleService = kualiModuleService; |
200 | 0 | } |
201 | |
|
202 | |
public void setParameterRepositoryService(ParameterRepositoryService parameterRepositoryService) { |
203 | 0 | this.parameterRepositoryService = parameterRepositoryService; |
204 | 0 | } |
205 | |
|
206 | |
public void setApplicationId(String applicationId) { |
207 | 0 | this.applicationId = applicationId; |
208 | 0 | } |
209 | |
|
210 | |
|
211 | |
private <R> R exec(Fun<R> fun, String namespaceCode, String componentCode, String parameterName) { |
212 | 0 | if (StringUtils.isBlank(applicationId)) { |
213 | 0 | throw new IllegalStateException("applicationId is blank - this service is not configured correctly"); |
214 | |
} |
215 | |
|
216 | 0 | return fun.f(ParameterKey.create(applicationId, namespaceCode, componentCode, parameterName)); |
217 | |
} |
218 | |
|
219 | |
private <R> R exec(Fun<R> fun, Class<?> componentClass, String parameterName) { |
220 | 0 | return exec(fun, kualiModuleService.getNamespaceCode(componentClass), kualiModuleService.getComponentCode(componentClass), parameterName); |
221 | |
} |
222 | |
|
223 | 0 | private interface Fun<R> { |
224 | |
R f(ParameterKey key); |
225 | |
} |
226 | |
} |