Coverage Report - org.kuali.rice.core.impl.parameter.ParameterServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterServiceImpl
0%
0/37
0%
0/10
1.15
ParameterServiceImpl$1
0%
0/2
N/A
1.15
ParameterServiceImpl$10
0%
0/2
N/A
1.15
ParameterServiceImpl$11
0%
0/2
N/A
1.15
ParameterServiceImpl$12
0%
0/2
N/A
1.15
ParameterServiceImpl$13
0%
0/2
N/A
1.15
ParameterServiceImpl$14
0%
0/2
N/A
1.15
ParameterServiceImpl$2
0%
0/2
N/A
1.15
ParameterServiceImpl$3
0%
0/2
0%
0/2
1.15
ParameterServiceImpl$4
0%
0/2
0%
0/2
1.15
ParameterServiceImpl$5
0%
0/2
N/A
1.15
ParameterServiceImpl$6
0%
0/2
N/A
1.15
ParameterServiceImpl$7
0%
0/2
N/A
1.15
ParameterServiceImpl$8
0%
0/2
N/A
1.15
ParameterServiceImpl$9
0%
0/2
N/A
1.15
ParameterServiceImpl$Fun
N/A
N/A
1.15
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
     //utilities that act as a poor-man's closure & higher order functions - these help consolidate validation & construction of parameter keys
 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  
 }