View Javadoc

1   /**
2    * Copyright 2005-2014 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.krad.bo;
17  
18  import org.kuali.rice.krad.datadictionary.DataDictionaryLocationConfigurer;
19  import org.kuali.rice.krad.service.DataDictionaryService;
20  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.service.PersistenceService;
22  import org.springframework.beans.factory.InitializingBean;
23  import org.springframework.context.ApplicationContext;
24  import org.springframework.context.ApplicationContextAware;
25  
26  import javax.persistence.EntityManager;
27  import java.lang.reflect.Modifier;
28  import java.util.ArrayList;
29  import java.util.Collections;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * This is a description of what this class does - bhargavp don't forget to fill this in.
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  public class ModuleConfiguration implements InitializingBean, ApplicationContextAware {
40  
41  	//protected static Logger LOG = Logger.getLogger(ModuleConfiguration.class);
42  
43  	protected String namespaceCode;
44  	protected ApplicationContext applicationContext;
45  
46  	protected List<String> packagePrefixes;
47  
48  	protected List<String> databaseRepositoryFilePaths;
49  
50  	protected List<String> dataDictionaryPackages;
51  
52  	protected List<String> scriptConfigurationFilePaths;
53  
54  	protected List<String> jobNames;
55  
56  	protected List<String> triggerNames;
57  
58  	//optional
59  	protected String dataSourceName;
60  
61  	//optional
62  	protected EntityManager entityManager;
63  
64  	protected Map<Class, Class> externalizableBusinessObjectImplementations;
65  
66  	protected boolean initializeDataDictionary;
67  
68  	protected PersistenceService persistenceService;
69  
70  	protected DataDictionaryService dataDictionaryService;
71  
72  	public ModuleConfiguration() {
73  		databaseRepositoryFilePaths = new ArrayList<String>();
74  		dataDictionaryPackages = new ArrayList<String>();
75  		scriptConfigurationFilePaths = new ArrayList<String>();
76  		jobNames = new ArrayList<String>();
77  		triggerNames = new ArrayList<String>();
78  	}
79  
80  	/**
81  	 * @return the databaseRepositoryFilePaths
82  	 */
83  	public List<String> getDatabaseRepositoryFilePaths() {
84  		return this.databaseRepositoryFilePaths;
85  	}
86  
87  	/**
88  	 * @param databaseRepositoryFilePaths the databaseRepositoryFilePaths to set
89  	 */
90  	public void setDatabaseRepositoryFilePaths(
91  			List<String> databaseRepositoryFilePaths) {
92  		this.trimList(databaseRepositoryFilePaths);	
93  		this.databaseRepositoryFilePaths = databaseRepositoryFilePaths;
94  	}
95  
96  	/**
97  	 * @return the dataDictionaryPackages
98  	 */
99  	public List<String> getDataDictionaryPackages() {
100 		return this.dataDictionaryPackages;
101 	}
102 
103 	/**
104 	 * @param dataDictionaryPackages the dataDictionaryPackages to set
105 	 */
106 	public void setDataDictionaryPackages(List<String> dataDictionaryPackages) {
107 		this.trimList(dataDictionaryPackages);			
108 		this.dataDictionaryPackages = dataDictionaryPackages;		
109 	}	
110 	
111 	/**
112 	 * @return the externalizableBusinessObjectImplementations
113 	 */
114 	public Map<Class, Class> getExternalizableBusinessObjectImplementations() {
115 		if (this.externalizableBusinessObjectImplementations == null)
116 			return null;
117 		return Collections.unmodifiableMap(this.externalizableBusinessObjectImplementations);
118 	}
119 
120 	/**
121 	 * @param externalizableBusinessObjectImplementations the externalizableBusinessObjectImplementations to set
122 	 */
123 	public void setExternalizableBusinessObjectImplementations(
124 			Map<Class, Class> externalizableBusinessObjectImplementations) {
125 		if (externalizableBusinessObjectImplementations != null) {
126 			for (Class implClass : externalizableBusinessObjectImplementations.values()) {
127 				int implModifiers = implClass.getModifiers();
128 				if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) {
129 					throw new RuntimeException("Externalizable business object implementation class " +
130 							implClass.getName() + " must be a non-interface, non-abstract class");
131 				}
132 			}
133 		}
134 		this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations;
135 	}
136 
137 	public List<String> getPackagePrefixes(){
138 		return this.packagePrefixes;
139 	}
140 
141 	public void setPackagePrefixes(List<String> packagePrefixes){
142 		this.trimList(packagePrefixes);
143 		this.packagePrefixes = packagePrefixes;
144 	}
145 
146 	public void setInitializeDataDictionary(boolean initializeDataDictionary){
147 		this.initializeDataDictionary = initializeDataDictionary;
148 	}
149 
150 	public List<String> getScriptConfigurationFilePaths(){
151 		return this.scriptConfigurationFilePaths;
152 	}
153 
154 	/**
155 	 * @return the jobNames
156 	 */
157 	public List<String> getJobNames() {
158 		return this.jobNames;
159 	}
160 
161 	/**
162 	 * @param jobNames the jobNames to set
163 	 */
164 	public void setJobNames(List<String> jobNames) {
165 		this.jobNames = jobNames;
166 	}
167 
168 
169 	/**
170 	 * @return the triggerNames
171 	 */
172 	public List<String> getTriggerNames() {
173 		return this.triggerNames;
174 	}
175 
176 	/**
177 	 * @param triggerNames the triggerNames to set
178 	 */
179 	public void setTriggerNames(List<String> triggerNames) {
180 		this.triggerNames = triggerNames;
181 	}
182 
183 	/**
184 	 * @return the initializeDataDictionary
185 	 */
186 	public boolean isInitializeDataDictionary() {
187 		return this.initializeDataDictionary;
188 	}
189 
190 	/**
191 	 * @param scriptConfigurationFilePaths the scriptConfigurationFilePaths to set
192 	 */
193 	public void setScriptConfigurationFilePaths(
194 			List<String> scriptConfigurationFilePaths) {
195 		this.scriptConfigurationFilePaths = scriptConfigurationFilePaths;
196 	}
197 
198 	@Override
199 	public void afterPropertiesSet() throws Exception {
200 		if (isInitializeDataDictionary() && getDataDictionaryPackages() != null && !getDataDictionaryPackages().isEmpty() ) {
201 			if ( getDataDictionaryService() == null ) {
202 				setDataDictionaryService(KRADServiceLocatorWeb.getDataDictionaryService());
203 			}
204 			if ( getDataDictionaryService() == null ) {
205 				setDataDictionaryService((DataDictionaryService)applicationContext.getBean( KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE ));
206 			}
207 			DataDictionaryLocationConfigurer ddl = new DataDictionaryLocationConfigurer( getDataDictionaryService() );
208 			ddl.setDataDictionaryPackages(getDataDictionaryPackages());
209 			ddl.afterPropertiesSet();
210 		}
211 		if (getDatabaseRepositoryFilePaths() != null) {
212 		    for (String repositoryLocation : getDatabaseRepositoryFilePaths()) {
213 				// Need the OJB persistence service because it is the only one ever using the database repository files
214 		    	if (getPersistenceService() == null) {
215 		    		setPersistenceService(KRADServiceLocatorWeb.getPersistenceServiceOjb());
216 		    	}
217 		    	if ( persistenceService == null ) {
218 		    		setPersistenceService((PersistenceService)applicationContext.getBean( KRADServiceLocatorWeb.PERSISTENCE_SERVICE_OJB  ));
219 		    	}
220 		    	getPersistenceService().loadRepositoryDescriptor( repositoryLocation );
221 			}
222 		}
223 	}
224 
225 	/**
226 	 * @return the namespaceCode
227 	 */
228 	public String getNamespaceCode() {
229 		return this.namespaceCode;
230 	}
231 
232 	/**
233 	 * @param namespaceCode the namespaceCode to set
234 	 */
235 	public void setNamespaceCode(String namespaceCode) {
236 		this.namespaceCode = namespaceCode;
237 	}
238 
239 	@Override
240 	public void setApplicationContext(ApplicationContext applicationContext) {
241 		this.applicationContext = applicationContext;
242 	}
243 
244 	/**
245 	 * @return the dataDictionaryService
246 	 */
247 	public DataDictionaryService getDataDictionaryService() {
248 		return this.dataDictionaryService;
249 	}
250 
251 	/**
252 	 * @param dataDictionaryService the dataDictionaryService to set
253 	 */
254 	public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
255 		this.dataDictionaryService = dataDictionaryService;
256 	}
257 
258 	/**
259 	 * @return the persistenceService
260 	 */
261 	public PersistenceService getPersistenceService() {
262 		return this.persistenceService;
263 	}
264 
265 	/**
266 	 * @param persistenceService the persistenceService to set
267 	 */
268 	public void setPersistenceService(PersistenceService persistenceService) {
269 		this.persistenceService = persistenceService;
270 	}
271 
272     public String getDataSourceName() {
273         return this.dataSourceName;
274     }
275 
276     public void setDataSourceName(String dataSourceName) {
277         this.dataSourceName = dataSourceName;
278     }
279 
280     public EntityManager getEntityManager() {
281         return this.entityManager;
282     }
283 
284     public void setEntityManager(EntityManager entityManager) {
285         this.entityManager = entityManager;
286     }
287     
288     /**
289 	 * 
290 	 * This method passes by reference. It will alter the list passed in.
291 	 * 
292 	 * @param stringList
293 	 */
294 	protected void trimList(List<String> stringList){
295 		if(stringList != null){
296 			// we need to trim whitespace from the stringList. Because trim() creates a new string 
297 			// we have to explicitly put the new string back into the list
298 			for(int i=0; i<stringList.size(); i++){
299 				String elmt = stringList.get(i);				
300 				elmt = elmt.trim();
301 				stringList.set(i, elmt);
302 			}			
303 		}
304 	}
305 
306 }