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