| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| KualiModuleServiceImpl |
|
| 3.0833333333333335;3.083 | ||||
| KualiModuleServiceImpl$1 |
|
| 3.0833333333333335;3.083 |
| 1 | /* | |
| 2 | * Copyright 2006-2007 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.kns.service.impl; | |
| 17 | ||
| 18 | import java.util.ArrayList; | |
| 19 | import java.util.HashMap; | |
| 20 | import java.util.List; | |
| 21 | ||
| 22 | import org.kuali.rice.kns.bo.ExternalizableBusinessObject; | |
| 23 | import org.kuali.rice.kns.bo.Namespace; | |
| 24 | import org.kuali.rice.kns.exception.KualiException; | |
| 25 | import org.kuali.rice.kns.service.KNSServiceLocator; | |
| 26 | import org.kuali.rice.kns.service.KualiModuleService; | |
| 27 | import org.kuali.rice.kns.service.ModuleService; | |
| 28 | import org.kuali.rice.kns.util.KNSPropertyConstants; | |
| 29 | import org.springframework.beans.factory.InitializingBean; | |
| 30 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; | |
| 31 | import org.springframework.context.ApplicationContext; | |
| 32 | import org.springframework.context.ApplicationContextAware; | |
| 33 | ||
| 34 | 0 | public class KualiModuleServiceImpl implements KualiModuleService, InitializingBean, ApplicationContextAware { |
| 35 | ||
| 36 | 0 | private List<ModuleService> installedModuleServices = new ArrayList<ModuleService>();; |
| 37 | private boolean loadRiceInstalledModuleServices; | |
| 38 | private ApplicationContext applicationContext; | |
| 39 | ||
| 40 | /** | |
| 41 | * @param applicationContext the applicationContext to set | |
| 42 | */ | |
| 43 | public void setApplicationContext(ApplicationContext applicationContext) { | |
| 44 | 0 | this.applicationContext = applicationContext; |
| 45 | 0 | } |
| 46 | ||
| 47 | public List<ModuleService> getInstalledModuleServices() { | |
| 48 | 0 | return installedModuleServices; |
| 49 | } | |
| 50 | ||
| 51 | public ModuleService getModuleService(String moduleId) { | |
| 52 | 0 | for (ModuleService moduleService : installedModuleServices) { |
| 53 | 0 | if ( moduleService.getModuleConfiguration().getNamespaceCode().equals( moduleId ) ) { |
| 54 | 0 | return moduleService; |
| 55 | } | |
| 56 | } | |
| 57 | 0 | return null; |
| 58 | } | |
| 59 | ||
| 60 | ||
| 61 | /** | |
| 62 | * @see org.kuali.rice.kns.service.KualiModuleService#getModuleServiceByCode(java.lang.String) | |
| 63 | */ | |
| 64 | public ModuleService getModuleServiceByNamespaceCode(String namespaceCode) { | |
| 65 | 0 | for (ModuleService moduleService : installedModuleServices) { |
| 66 | 0 | if ( moduleService.getModuleConfiguration().getNamespaceCode().equals( namespaceCode ) ) { |
| 67 | 0 | return moduleService; |
| 68 | } | |
| 69 | } | |
| 70 | 0 | return null; |
| 71 | } | |
| 72 | ||
| 73 | public boolean isModuleServiceInstalled(String namespaceCode) { | |
| 74 | 0 | for (ModuleService moduleService : installedModuleServices) { |
| 75 | 0 | if ( moduleService.getModuleConfiguration().getNamespaceCode().equals( namespaceCode ) ) { |
| 76 | 0 | return true; |
| 77 | } | |
| 78 | } | |
| 79 | 0 | return false; |
| 80 | } | |
| 81 | ||
| 82 | public ModuleService getResponsibleModuleService(Class boClass) { | |
| 83 | 0 | if(boClass==null) return null; |
| 84 | 0 | for (ModuleService moduleService : installedModuleServices) { |
| 85 | 0 | if ( moduleService.isResponsibleFor( boClass ) ) { |
| 86 | 0 | return moduleService; |
| 87 | } | |
| 88 | } | |
| 89 | //Throwing exception only for externalizable business objects | |
| 90 | 0 | if(ExternalizableBusinessObject.class.isAssignableFrom(boClass)){ |
| 91 | String message; | |
| 92 | 0 | if(!boClass.isInterface()) |
| 93 | 0 | message = "There is no responsible module for the externalized business object class: "+boClass; |
| 94 | else | |
| 95 | 0 | message = "There is no responsible module for the externalized business object interface: "+boClass; |
| 96 | 0 | throw new KualiException(message); |
| 97 | } | |
| 98 | //Returning null for business objects other than externalizable to keep the framework backward compatible | |
| 99 | 0 | return null; |
| 100 | } | |
| 101 | ||
| 102 | /*** | |
| 103 | * @see org.kuali.core.service.KualiModuleService#getResponsibleModuleServiceForJob(java.lang.String) | |
| 104 | */ | |
| 105 | public ModuleService getResponsibleModuleServiceForJob(String jobName){ | |
| 106 | 0 | for(ModuleService moduleService : installedModuleServices){ |
| 107 | 0 | if(moduleService.isResponsibleForJob(jobName)){ |
| 108 | 0 | return moduleService; |
| 109 | } | |
| 110 | } | |
| 111 | 0 | return null; |
| 112 | } | |
| 113 | ||
| 114 | public void setInstalledModuleServices(List<ModuleService> installedModuleServices) { | |
| 115 | 0 | this.installedModuleServices = installedModuleServices; |
| 116 | 0 | } |
| 117 | ||
| 118 | public List<String> getDataDictionaryPackages() { | |
| 119 | 0 | List<String> packages = new ArrayList<String>(); |
| 120 | 0 | for ( ModuleService moduleService : installedModuleServices ) { |
| 121 | 0 | if ( moduleService.getModuleConfiguration().getDataDictionaryPackages() != null ) { |
| 122 | 0 | packages.addAll( moduleService.getModuleConfiguration().getDataDictionaryPackages() ); |
| 123 | } | |
| 124 | } | |
| 125 | 0 | return packages; |
| 126 | } | |
| 127 | ||
| 128 | /*** | |
| 129 | * | |
| 130 | * This method uses BusinessObjectService to get the namespace name | |
| 131 | * | |
| 132 | * @see org.kuali.core.service.KualiModuleService#getNamespaceName(java.lang.String) | |
| 133 | */ | |
| 134 | public String getNamespaceName(final String namespaceCode){ | |
| 135 | 0 | Namespace parameterNamespace = (Namespace) |
| 136 | KNSServiceLocator.getBusinessObjectService().findByPrimaryKey( | |
| 137 | 0 | Namespace.class, new HashMap() {{put(KNSPropertyConstants.CODE, namespaceCode);}}); |
| 138 | 0 | return parameterNamespace==null ? "" : parameterNamespace.getName(); |
| 139 | } | |
| 140 | ||
| 141 | /** | |
| 142 | * @param loadRiceInstalledModuleServices the loadRiceInstalledModuleServices to set | |
| 143 | */ | |
| 144 | public void setLoadRiceInstalledModuleServices( | |
| 145 | boolean loadRiceInstalledModuleServices) { | |
| 146 | 0 | this.loadRiceInstalledModuleServices = loadRiceInstalledModuleServices; |
| 147 | 0 | } |
| 148 | ||
| 149 | /*** | |
| 150 | * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() | |
| 151 | */ | |
| 152 | public void afterPropertiesSet() throws Exception { | |
| 153 | 0 | if(loadRiceInstalledModuleServices){ |
| 154 | try { | |
| 155 | 0 | installedModuleServices.addAll( |
| 156 | KNSServiceLocator.getNervousSystemContextBean(KualiModuleService.class).getInstalledModuleServices()); | |
| 157 | 0 | } catch ( NoSuchBeanDefinitionException ex ) { |
| 158 | 0 | installedModuleServices.addAll( ((KualiModuleService)applicationContext.getBean( KNSServiceLocator.KUALI_MODULE_SERVICE )).getInstalledModuleServices() ); |
| 159 | 0 | } |
| 160 | } | |
| 161 | 0 | } |
| 162 | ||
| 163 | } | |
| 164 |