| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PropertyConditionalServiceBusExporter | 
  | 
  | 2.375;2.375 | 
| 1 |  /* | |
| 2 |   * Copyright 2006-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 | ||
| 17 |  package org.kuali.rice.ksb.api.bus.support; | |
| 18 | ||
| 19 |  import java.util.ArrayList; | |
| 20 |  import java.util.List; | |
| 21 | ||
| 22 |  import org.apache.commons.lang.StringUtils; | |
| 23 |  import org.kuali.rice.core.api.config.property.ConfigContext; | |
| 24 | ||
| 25 |  /** | |
| 26 |   * A ServiceBusExporter which only exports the service if the specified property is set | |
| 27 |   * to true. | |
| 28 |   *  | |
| 29 |   * @author Kuali Rice Team (kuali-rice@googlegroups.com) | |
| 30 |   */ | |
| 31 | 0 |  public class PropertyConditionalServiceBusExporter extends ServiceBusExporter { | 
| 32 | ||
| 33 | 0 |          private List<String> exportIf = new ArrayList<String>(); | 
| 34 | 0 |          private List<String> exportUnless = new ArrayList<String>(); | 
| 35 | 0 |          private boolean exportIfPropertyNotSet = true; | 
| 36 | ||
| 37 | public void afterPropertiesSet() {  | |
| 38 | 0 |                  if (shouldRemoteThisService()) { | 
| 39 | 0 |                          super.afterPropertiesSet(); | 
| 40 | }  | |
| 41 | 0 |          } | 
| 42 | ||
| 43 | protected boolean shouldRemoteThisService() {  | |
| 44 | 0 |                  if (exportIf.isEmpty() && exportUnless.isEmpty()) { | 
| 45 | 0 |                          return true; | 
| 46 | }  | |
| 47 | 0 |                  boolean remoteThisService = false; | 
| 48 | 0 |                  String serviceValue = null; | 
| 49 |                  // Check the value in the clients config file for services in the list | |
| 50 |                  // of property named 'exportIf' loaded by Spring. | |
| 51 |                  // if any are ="true" then set boolean to true and exit loop, so far the | |
| 52 |                  // service will be published. | |
| 53 | 0 |                  for (String expIf : exportIf) { | 
| 54 | 0 |                          serviceValue = ConfigContext.getCurrentContextConfig().getProperty(expIf); | 
| 55 |                          // if any are true, set boolean and exit loop. | |
| 56 | 0 |                          if (!StringUtils.isBlank(serviceValue)) { | 
| 57 | 0 |                                  remoteThisService = new Boolean(serviceValue); | 
| 58 | 0 |                                  if (remoteThisService) { | 
| 59 | 0 |                                          break; | 
| 60 | }  | |
| 61 | 0 |                          } else if (exportIfPropertyNotSet) { | 
| 62 | 0 |                                  remoteThisService = true; | 
| 63 | 0 |                                  break; | 
| 64 | }  | |
| 65 | }  | |
| 66 |                  // Check a second list, if any are ="true" DON"T publish the service. | |
| 67 | 0 |                  for (String expUnless : exportUnless) { | 
| 68 | 0 |                          serviceValue = ConfigContext.getCurrentContextConfig() | 
| 69 | .getProperty(expUnless);  | |
| 70 |                          // if any are true, set boolean and exit loop. | |
| 71 | 0 |                          if (!StringUtils.isBlank(serviceValue)) { | 
| 72 | 0 |                                  remoteThisService = new Boolean(serviceValue); | 
| 73 | 0 |                                  if (remoteThisService) { | 
| 74 | 0 |                                          remoteThisService = new Boolean("false"); | 
| 75 | 0 |                                          break; | 
| 76 | }  | |
| 77 | }  | |
| 78 | }  | |
| 79 | 0 |                  return remoteThisService; | 
| 80 | }  | |
| 81 | ||
| 82 |          public List<String> getExportIf() { | |
| 83 | 0 |                  return this.exportIf; | 
| 84 | }  | |
| 85 | ||
| 86 | public void setExportIf(List<String> exportIf) {  | |
| 87 | 0 |                  this.exportIf = exportIf; | 
| 88 | 0 |          } | 
| 89 | ||
| 90 |          public List<String> getExportUnless() { | |
| 91 | 0 |                  return this.exportUnless; | 
| 92 | }  | |
| 93 | ||
| 94 | public void setExportUnless(List<String> exportUnless) {  | |
| 95 | 0 |                  this.exportUnless = exportUnless; | 
| 96 | 0 |          } | 
| 97 | ||
| 98 | public boolean isExportIfPropertyNotSet() {  | |
| 99 | 0 |                  return this.exportIfPropertyNotSet; | 
| 100 | }  | |
| 101 | ||
| 102 | public void setExportIfPropertyNotSet(boolean exportIfPropertyNotSet) {  | |
| 103 | 0 |                  this.exportIfPropertyNotSet = exportIfPropertyNotSet; | 
| 104 | 0 |          } | 
| 105 | ||
| 106 | }  |