| 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 | 0 |  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 | 0 |              String applicationNamespace = KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.APPLICATION_CODE); | 
  | 54 | 0 |              if (StringUtils.isEmpty(applicationNamespace)) { | 
  | 55 | 0 |                  applicationNamespace = KNSConstants.DEFAULT_APPLICATION_CODE; | 
  | 56 |  |              } | 
  | 57 | 0 |              Parameter parameter = fetchFromCache(namespaceCode, detailTypeCode, parameterName); | 
  | 58 | 0 |          if (parameter != null) { | 
  | 59 | 0 |              return parameter; | 
  | 60 |  |          } | 
  | 61 | 0 |              HashMap<String, String> crit = new HashMap<String, String>(3); | 
  | 62 | 0 |              crit.put("parameterNamespaceCode", namespaceCode); | 
  | 63 | 0 |              crit.put("parameterDetailTypeCode", detailTypeCode); | 
  | 64 | 0 |              crit.put("parameterName", parameterName); | 
  | 65 |  |               | 
  | 66 |  |               | 
  | 67 | 0 |              List<Parameter> parameters = (List<Parameter>)getBusinessObjectService().findMatching(Parameter.class, crit); | 
  | 68 | 0 |              Parameter parameterDefault = null; | 
  | 69 | 0 |              for (Parameter parm : parameters) { | 
  | 70 | 0 |                  if (StringUtils.equals(applicationNamespace, parm.getParameterApplicationNamespaceCode())) { | 
  | 71 | 0 |                      parameter = parm; | 
  | 72 | 0 |                      break; | 
  | 73 | 0 |                  } else if (StringUtils.equals(KNSConstants.DEFAULT_APPLICATION_CODE, parm.getParameterApplicationNamespaceCode())) { | 
  | 74 | 0 |                      parameterDefault = parm; | 
  | 75 |  |                  } | 
  | 76 |  |              } | 
  | 77 |  |   | 
  | 78 | 0 |              if (parameter == null) { | 
  | 79 | 0 |                  parameter = parameterDefault; | 
  | 80 |  |              } | 
  | 81 |  |               | 
  | 82 | 0 |              insertIntoCache(parameter);  | 
  | 83 |  |               | 
  | 84 |  |               | 
  | 85 |  |               | 
  | 86 |  |               | 
  | 87 |  |               | 
  | 88 | 0 |              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 | 0 |                  Collection<Parameter> results = getLookupService().findCollectionBySearch(Parameter.class, fieldValues); | 
  | 103 | 0 |                  return new ArrayList<Parameter>( results ); | 
  | 104 |  |      }     | 
  | 105 |  |           | 
  | 106 |  |          public List<ParameterDetailType> getNonDatabaseComponents() { | 
  | 107 | 0 |                  return KNSServiceLocator.getRiceApplicationConfigurationMediationService().getNonDatabaseComponents(); | 
  | 108 |  |          } | 
  | 109 |  |           | 
  | 110 |  |          @SuppressWarnings("unchecked") | 
  | 111 |  |          public void setParameterForTesting(Class componentClass, String parameterName, String parameterText) { | 
  | 112 | 0 |              Parameter parameter = (Parameter) getParameter(componentClass, parameterName); | 
  | 113 | 0 |              parameter.setParameterValue(parameterText); | 
  | 114 | 0 |              getBusinessObjectService().save(parameter); | 
  | 115 | 0 |          }  | 
  | 116 |  |           | 
  | 117 |  |          public void setBusinessObjectService(BusinessObjectService businessObjectService) { | 
  | 118 | 0 |              this.businessObjectService = businessObjectService; | 
  | 119 | 0 |          } | 
  | 120 |  |   | 
  | 121 |  |          protected LookupService getLookupService() { | 
  | 122 | 0 |                  if ( lookupService == null ) { | 
  | 123 | 0 |                          lookupService = KNSServiceLocator.getLookupService(); | 
  | 124 |  |                  } | 
  | 125 | 0 |                  return lookupService; | 
  | 126 |  |          } | 
  | 127 |  |   | 
  | 128 |  |          protected BusinessObjectService getBusinessObjectService() { | 
  | 129 | 0 |                  if ( businessObjectService == null ) { | 
  | 130 | 0 |                          businessObjectService = KNSServiceLocator.getBusinessObjectService(); | 
  | 131 |  |                  } | 
  | 132 | 0 |                  return this.businessObjectService; | 
  | 133 |  |          }         | 
  | 134 |  |  } |