Revision f9656765
Added by Andreas Müller over 8 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationController.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.api.application; |
|
12 |
|
|
13 |
import java.util.EnumSet; |
|
14 |
import java.util.List; |
|
15 |
import java.util.UUID; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
18 |
import org.hibernate.SessionFactory; |
|
19 |
import org.springframework.beans.MutablePropertyValues; |
|
20 |
import org.springframework.beans.factory.config.BeanDefinition; |
|
21 |
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
|
22 |
import org.springframework.context.ApplicationListener; |
|
23 |
import org.springframework.context.support.AbstractApplicationContext; |
|
24 |
import org.springframework.core.io.ClassPathResource; |
|
25 |
import org.springframework.core.io.Resource; |
|
26 |
import org.springframework.security.authentication.ProviderManager; |
|
27 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
28 |
import org.springframework.security.core.Authentication; |
|
29 |
import org.springframework.security.core.context.SecurityContext; |
|
30 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
31 |
import org.springframework.transaction.PlatformTransactionManager; |
|
32 |
import org.springframework.transaction.TransactionStatus; |
|
33 |
|
|
34 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
35 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
|
36 |
import eu.etaxonomy.cdm.api.service.IAnnotationService; |
|
37 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
38 |
import eu.etaxonomy.cdm.api.service.ICollectionService; |
|
39 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
|
40 |
import eu.etaxonomy.cdm.api.service.IDatabaseService; |
|
41 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
42 |
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService; |
|
43 |
import eu.etaxonomy.cdm.api.service.IEntityValidationService; |
|
44 |
import eu.etaxonomy.cdm.api.service.IFeatureNodeService; |
|
45 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService; |
|
46 |
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService; |
|
47 |
import eu.etaxonomy.cdm.api.service.IGroupService; |
|
48 |
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService; |
|
49 |
import eu.etaxonomy.cdm.api.service.ILocationService; |
|
50 |
import eu.etaxonomy.cdm.api.service.IMediaService; |
|
51 |
import eu.etaxonomy.cdm.api.service.INameService; |
|
52 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
53 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService; |
|
54 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService; |
|
55 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
|
56 |
import eu.etaxonomy.cdm.api.service.IService; |
|
57 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
58 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
59 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
60 |
import eu.etaxonomy.cdm.api.service.IUserService; |
|
61 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
62 |
import eu.etaxonomy.cdm.api.service.IWorkingSetService; |
|
63 |
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService; |
|
64 |
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService; |
|
65 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
|
66 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
|
67 |
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor; |
|
68 |
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor; |
|
69 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
70 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
71 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
72 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
73 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
74 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
75 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
|
76 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator; |
|
77 |
|
|
78 |
/** |
|
79 |
* @author a.mueller |
|
80 |
*/ |
|
81 |
public class CdmApplicationController implements ICdmApplicationConfiguration { |
|
82 |
private static final Logger logger = Logger.getLogger(CdmApplicationController.class); |
|
83 |
|
|
84 |
public static final String DEFAULT_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/defaultApplicationContext.xml"; |
|
85 |
|
|
86 |
public AbstractApplicationContext applicationContext; |
|
87 |
protected ICdmApplicationConfiguration configuration; |
|
88 |
private final Resource applicationContextResource; |
|
89 |
|
|
90 |
private final IProgressMonitor progressMonitor; |
|
91 |
|
|
92 |
final protected static DbSchemaValidation defaultDbSchemaValidation = DbSchemaValidation.VALIDATE; |
|
93 |
|
|
94 |
|
|
95 |
/** |
|
96 |
* Constructor, opens a spring ApplicationContext by using the default data source |
|
97 |
* |
|
98 |
* @throws DataSourceNotFoundException |
|
99 |
*/ |
|
100 |
public static CdmApplicationController NewInstance() throws DataSourceNotFoundException{ |
|
101 |
logger.info("Start CdmApplicationController with default data source"); |
|
102 |
CdmPersistentDataSource dataSource = getDefaultDatasource(); |
|
103 |
DbSchemaValidation dbSchemaValidation = defaultDbSchemaValidation; |
|
104 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, false); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
/** |
|
109 |
* Constructor, opens a spring ApplicationContext by using the default data source |
|
110 |
* |
|
111 |
* @param dbSchemaValidation |
|
112 |
* validation type for database schema |
|
113 |
* @throws DataSourceNotFoundException |
|
114 |
*/ |
|
115 |
public static CdmApplicationController NewInstance(DbSchemaValidation dbSchemaValidation) throws DataSourceNotFoundException{ |
|
116 |
logger.info("Start CdmApplicationController with default data source"); |
|
117 |
CdmPersistentDataSource dataSource = getDefaultDatasource(); |
|
118 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, false); |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
/** |
|
123 |
* Constructor, opens an spring ApplicationContext by using the according data source |
|
124 |
* and the default database schema validation type |
|
125 |
* |
|
126 |
* @param dataSource |
|
127 |
*/ |
|
128 |
public static CdmApplicationController NewInstance(ICdmDataSource dataSource){ |
|
129 |
return CdmApplicationController.NewInstance(null, dataSource, defaultDbSchemaValidation, false); |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
public static CdmApplicationController NewInstance(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation){ |
|
134 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, false); |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
public static CdmApplicationController NewInstance(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading){ |
|
139 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, omitTermLoading); |
|
140 |
} |
|
141 |
|
|
142 |
public static CdmApplicationController NewInstance(Resource applicationContextResource, ICdmDataSource dataSource, |
|
143 |
DbSchemaValidation dbSchemaValidation, boolean omitTermLoading){ |
|
144 |
return CdmApplicationController.NewInstance(applicationContextResource, dataSource, dbSchemaValidation, omitTermLoading, null); |
|
145 |
} |
|
146 |
|
|
147 |
public static CdmApplicationController NewInstance(Resource applicationContextResource, ICdmDataSource dataSource, |
|
148 |
DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, IProgressMonitor progressMonitor){ |
|
149 |
return new CdmApplicationController(applicationContextResource, dataSource, dbSchemaValidation, omitTermLoading, progressMonitor, null); |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
//TODO discuss need for listeners before commit to trunk |
|
154 |
// public static CdmApplicationController NewInstance(Resource applicationContextResource, ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, IProgressMonitor progressMonitor, List<ApplicationListener> listeners) { |
|
155 |
// return new CdmApplicationController(applicationContextResource, dataSource, dbSchemaValidation, omitTermLoading, progressMonitor,listeners); |
|
156 |
// } |
|
157 |
|
|
158 |
/** |
|
159 |
* @return |
|
160 |
*/ |
|
161 |
protected static ClassPathResource getClasspathResource(){ |
|
162 |
return new ClassPathResource(DEFAULT_APPLICATION_CONTEXT_RESOURCE); |
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
/** |
|
167 |
* @return |
|
168 |
* @throws DataSourceNotFoundException |
|
169 |
*/ |
|
170 |
protected static CdmPersistentDataSource getDefaultDatasource() throws DataSourceNotFoundException{ |
|
171 |
CdmPersistentDataSource dataSource = CdmPersistentDataSource.NewDefaultInstance(); |
|
172 |
return dataSource; |
|
173 |
} |
|
174 |
|
|
175 |
|
|
176 |
/** |
|
177 |
* |
|
178 |
* FIXME:Remoting this constructor is added only to allow extension of this cntroller |
|
179 |
* class. and should be removed after refactoring |
|
180 |
*/ |
|
181 |
protected CdmApplicationController(){ |
|
182 |
applicationContextResource = null; |
|
183 |
progressMonitor = null; |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
/** |
|
188 |
* Constructor, opens an spring 2.5 ApplicationContext by using the according data |
|
189 |
* source |
|
190 |
* |
|
191 |
* @param dataSource |
|
192 |
* @param dbSchemaValidation |
|
193 |
* @param omitTermLoading |
|
194 |
*/ |
|
195 |
protected CdmApplicationController(Resource applicationContextResource, ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, |
|
196 |
boolean omitTermLoading, IProgressMonitor progressMonitor, List<ApplicationListener> listeners){ |
|
197 |
logger.info("Start CdmApplicationController with datasource: " + dataSource.getName()); |
|
198 |
|
|
199 |
if (dbSchemaValidation == null) { |
|
200 |
dbSchemaValidation = defaultDbSchemaValidation; |
|
201 |
} |
|
202 |
this.applicationContextResource = applicationContextResource != null ? applicationContextResource : getClasspathResource(); |
|
203 |
this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor(); |
|
204 |
|
|
205 |
setNewDataSource(dataSource, dbSchemaValidation, omitTermLoading, listeners); |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
/** |
|
210 |
* Sets the application context to a new spring ApplicationContext by using the |
|
211 |
* according data source and initializes the Controller. |
|
212 |
* |
|
213 |
* @param dataSource |
|
214 |
*/ |
|
215 |
private boolean setNewDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, |
|
216 |
List<ApplicationListener> listeners){ |
|
217 |
|
|
218 |
if (dbSchemaValidation == null) { |
|
219 |
dbSchemaValidation = defaultDbSchemaValidation; |
|
220 |
} |
|
221 |
logger.info("Connecting to '" + dataSource.getName() + "'"); |
|
222 |
|
|
223 |
MonitoredGenericApplicationContext applicationContext = new MonitoredGenericApplicationContext(); |
|
224 |
int refreshTasks = 45; |
|
225 |
int nTasks = 5 + refreshTasks; |
|
226 |
// nTasks += applicationContext.countTasks(); |
|
227 |
progressMonitor.beginTask("Connecting to '" + dataSource.getName() + "'", nTasks); |
|
228 |
|
|
229 |
// progressMonitor.worked(1); |
|
230 |
|
|
231 |
BeanDefinition datasourceBean = dataSource.getDatasourceBean(); |
|
232 |
datasourceBean.setAttribute("isLazy", false); |
|
233 |
progressMonitor.subTask("Registering datasource."); |
|
234 |
applicationContext.registerBeanDefinition("dataSource", datasourceBean); |
|
235 |
progressMonitor.worked(1); |
|
236 |
|
|
237 |
BeanDefinition hibernatePropBean = dataSource.getHibernatePropertiesBean(dbSchemaValidation); |
|
238 |
applicationContext.registerBeanDefinition("hibernateProperties", hibernatePropBean); |
|
239 |
|
|
240 |
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); |
|
241 |
progressMonitor.subTask("Registering resources."); |
|
242 |
xmlReader.loadBeanDefinitions(applicationContextResource); |
|
243 |
progressMonitor.worked(1); |
|
244 |
|
|
245 |
//omitTerms |
|
246 |
if (omitTermLoading == true) { |
|
247 |
String initializerName = "persistentTermInitializer"; |
|
248 |
BeanDefinition beanDef = applicationContext.getBeanDefinition(initializerName); |
|
249 |
MutablePropertyValues values = beanDef.getPropertyValues(); |
|
250 |
values.addPropertyValue("omit", omitTermLoading); |
|
251 |
} |
|
252 |
|
|
253 |
if (listeners != null) { |
|
254 |
for (ApplicationListener listener : listeners) { |
|
255 |
applicationContext.addApplicationListener(listener); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
// String message = "Start application context. This might take a while ..."; |
|
260 |
//// progressMonitor.subTask(message); |
|
261 |
// SubProgressMonitor subMonitor= new SubProgressMonitor(progressMonitor, 10); |
|
262 |
// subMonitor.beginTask(message, 2); |
|
263 |
// applicationContext.setProgressMonitor(subMonitor); |
|
264 |
|
|
265 |
applicationContext.refresh(new SubProgressMonitor(progressMonitor, refreshTasks)); |
|
266 |
applicationContext.start(); |
|
267 |
// progressMonitor.worked(1); |
|
268 |
|
|
269 |
progressMonitor.subTask("Cleaning up."); |
|
270 |
setApplicationContext(applicationContext); |
|
271 |
progressMonitor.worked(1); |
|
272 |
|
|
273 |
progressMonitor.done(); |
|
274 |
return true; |
|
275 |
} |
|
276 |
|
|
277 |
|
|
278 |
/** |
|
279 |
* Tests if some DefinedTermsAreMissing. |
|
280 |
* |
|
281 |
* @return true, if at least one is missing, else false |
|
282 |
*/ |
|
283 |
public boolean testDefinedTermsAreMissing(){ |
|
284 |
UUID englishUuid = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523"); |
|
285 |
DefinedTermBase<?> english = this.getTermService().load(englishUuid); |
|
286 |
if (english == null || !english.getUuid().equals(englishUuid)) { |
|
287 |
return true; |
|
288 |
} |
|
289 |
else { |
|
290 |
return false; |
|
291 |
} |
|
292 |
} |
|
293 |
|
|
294 |
|
|
295 |
/** |
|
296 |
* Changes the ApplicationContext to the new dataSource |
|
297 |
* |
|
298 |
* @param dataSource |
|
299 |
*/ |
|
300 |
public boolean changeDataSource(ICdmDataSource dataSource){ |
|
301 |
//logger.info("Change datasource to : " + dataSource); |
|
302 |
return setNewDataSource(dataSource, DbSchemaValidation.VALIDATE, false, null); |
|
303 |
} |
|
304 |
|
|
305 |
|
|
306 |
/** |
|
307 |
* Changes the ApplicationContext to the new dataSource |
|
308 |
* |
|
309 |
* @param dataSource |
|
310 |
* @param dbSchemaValidation |
|
311 |
*/ |
|
312 |
public boolean changeDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation){ |
|
313 |
//logger.info("Change datasource to : " + dataSource); |
|
314 |
return setNewDataSource(dataSource, dbSchemaValidation, false, null); |
|
315 |
} |
|
316 |
|
|
317 |
|
|
318 |
/** |
|
319 |
* Changes the ApplicationContext to the new dataSource |
|
320 |
* |
|
321 |
* @param dataSource |
|
322 |
* @param dbSchemaValidation |
|
323 |
* @param omitTermLoading |
|
324 |
*/ |
|
325 |
public boolean changeDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading){ |
|
326 |
logger.info("Change datasource to : " + dataSource); |
|
327 |
return setNewDataSource(dataSource, dbSchemaValidation, omitTermLoading, null); |
|
328 |
} |
|
329 |
|
|
330 |
|
|
331 |
/** |
|
332 |
* Changes the ApplicationContext to the new dataSource |
|
333 |
* |
|
334 |
* @param dataSource |
|
335 |
* @param dbSchemaValidation |
|
336 |
* @param omitTermLoading |
|
337 |
*/ |
|
338 |
public boolean changeDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, |
|
339 |
List<ApplicationListener> listeners){ |
|
340 |
logger.info("Change datasource to : " + dataSource); |
|
341 |
return setNewDataSource(dataSource, dbSchemaValidation, omitTermLoading, listeners); |
|
342 |
} |
|
343 |
|
|
344 |
|
|
345 |
/** |
|
346 |
* Sets a new application Context. |
|
347 |
* |
|
348 |
* @param ac |
|
349 |
*/ |
|
350 |
public void setApplicationContext(AbstractApplicationContext ac){ |
|
351 |
closeApplicationContext(); //closes old application context if necessary |
|
352 |
applicationContext = ac; |
|
353 |
applicationContext.registerShutdownHook(); |
|
354 |
init(); |
|
355 |
} |
|
356 |
|
|
357 |
|
|
358 |
/* |
|
359 |
* (non-Javadoc) |
|
360 |
* |
|
361 |
* @see java.lang.Object#finalize() |
|
362 |
*/ |
|
363 |
@Override |
|
364 |
public void finalize(){ |
|
365 |
close(); |
|
366 |
} |
|
367 |
|
|
368 |
|
|
369 |
/** |
|
370 |
* closes the application |
|
371 |
*/ |
|
372 |
public void close(){ |
|
373 |
closeApplicationContext(); |
|
374 |
} |
|
375 |
|
|
376 |
|
|
377 |
/** |
|
378 |
* closes the application context |
|
379 |
*/ |
|
380 |
protected void closeApplicationContext(){ |
|
381 |
if (applicationContext != null) { |
|
382 |
logger.info("Close ApplicationContext"); |
|
383 |
applicationContext.close(); |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
|
|
388 |
protected void init(){ |
|
389 |
logger.debug("Init " + this.getClass().getName() + " ... "); |
|
390 |
if (logger.isDebugEnabled()) { |
|
391 |
for (String beanName : applicationContext.getBeanDefinitionNames()) { |
|
392 |
logger.debug(beanName); |
|
393 |
} |
|
394 |
} |
|
395 |
//TODO delete next row (was just for testing) |
|
396 |
if (logger.isInfoEnabled()) { |
|
397 |
logger.info("Registered Beans: "); |
|
398 |
String[] beanNames = applicationContext.getBeanDefinitionNames(); |
|
399 |
for (String beanName : beanNames) { |
|
400 |
logger.info(beanName); |
|
401 |
} |
|
402 |
} |
|
403 |
configuration = (ICdmApplicationConfiguration) applicationContext.getBean("cdmApplicationDefaultConfiguration"); |
|
404 |
try { |
|
405 |
//FIXME:Remoting catching exection to allow for remoting |
|
406 |
getDatabaseService().setApplicationController(this); |
|
407 |
} |
|
408 |
catch (UnsupportedOperationException uoe) { |
|
409 |
logger.warn("getDatabaseService() is not implmented for current application context"); |
|
410 |
} |
|
411 |
} |
|
412 |
|
|
413 |
|
|
414 |
/* ****** Services ******** */ |
|
415 |
@Override |
|
416 |
public final IAnnotationService getAnnotationService(){ |
|
417 |
return configuration.getAnnotationService(); |
|
418 |
} |
|
419 |
|
|
420 |
@Override |
|
421 |
public final INameService getNameService(){ |
|
422 |
return configuration.getNameService(); |
|
423 |
} |
|
424 |
|
|
425 |
|
|
426 |
@Override |
|
427 |
public final ITaxonService getTaxonService(){ |
|
428 |
return configuration.getTaxonService(); |
|
429 |
} |
|
430 |
|
|
431 |
|
|
432 |
@Override |
|
433 |
public final IClassificationService getClassificationService(){ |
|
434 |
return configuration.getClassificationService(); |
|
435 |
} |
|
436 |
|
|
437 |
|
|
438 |
@Override |
|
439 |
public final ITaxonNodeService getTaxonNodeService(){ |
|
440 |
return configuration.getTaxonNodeService(); |
|
441 |
} |
|
442 |
|
|
443 |
|
|
444 |
@Override |
|
445 |
public final IReferenceService getReferenceService(){ |
|
446 |
return configuration.getReferenceService(); |
|
447 |
} |
|
448 |
|
|
449 |
|
|
450 |
@Override |
|
451 |
public final IAgentService getAgentService(){ |
|
452 |
return configuration.getAgentService(); |
|
453 |
} |
|
454 |
|
|
455 |
|
|
456 |
@Override |
|
457 |
public final IDatabaseService getDatabaseService(){ |
|
458 |
return configuration.getDatabaseService(); |
|
459 |
} |
|
460 |
|
|
461 |
|
|
462 |
@Override |
|
463 |
public final ITermService getTermService(){ |
|
464 |
return configuration.getTermService(); |
|
465 |
} |
|
466 |
|
|
467 |
|
|
468 |
@Override |
|
469 |
public final IDescriptionService getDescriptionService(){ |
|
470 |
return configuration.getDescriptionService(); |
|
471 |
} |
|
472 |
|
|
473 |
|
|
474 |
@Override |
|
475 |
public final IOccurrenceService getOccurrenceService(){ |
|
476 |
return configuration.getOccurrenceService(); |
|
477 |
} |
|
478 |
|
|
479 |
@Override |
|
480 |
public IAmplificationService getAmplificationService(){ |
|
481 |
return configuration.getAmplificationService(); |
|
482 |
} |
|
483 |
|
|
484 |
@Override |
|
485 |
public ISequenceService getSequenceService(){ |
|
486 |
return configuration.getSequenceService(); |
|
487 |
} |
|
488 |
|
|
489 |
|
|
490 |
@Override |
|
491 |
public final IPrimerService getPrimerService(){ |
|
492 |
return configuration.getPrimerService(); |
|
493 |
} |
|
494 |
|
|
495 |
|
|
496 |
@Override |
|
497 |
public final IMediaService getMediaService(){ |
|
498 |
return configuration.getMediaService(); |
|
499 |
} |
|
500 |
|
|
501 |
|
|
502 |
@Override |
|
503 |
public final ICommonService getCommonService(){ |
|
504 |
return configuration.getCommonService(); |
|
505 |
} |
|
506 |
|
|
507 |
|
|
508 |
@Override |
|
509 |
public final ILocationService getLocationService(){ |
|
510 |
return configuration.getLocationService(); |
|
511 |
} |
|
512 |
|
|
513 |
|
|
514 |
@Override |
|
515 |
public final IUserService getUserService(){ |
|
516 |
return configuration.getUserService(); |
|
517 |
} |
|
518 |
|
|
519 |
|
|
520 |
@Override |
|
521 |
public final IGrantedAuthorityService getGrantedAuthorityService(){ |
|
522 |
return configuration.getGrantedAuthorityService(); |
|
523 |
} |
|
524 |
|
|
525 |
|
|
526 |
@Override |
|
527 |
public IGroupService getGroupService(){ |
|
528 |
return configuration.getGroupService(); |
|
529 |
} |
|
530 |
|
|
531 |
|
|
532 |
@Override |
|
533 |
public final ICollectionService getCollectionService(){ |
|
534 |
return configuration.getCollectionService(); |
|
535 |
} |
|
536 |
|
|
537 |
|
|
538 |
@Override |
|
539 |
public final IFeatureTreeService getFeatureTreeService(){ |
|
540 |
return configuration.getFeatureTreeService(); |
|
541 |
} |
|
542 |
|
|
543 |
|
|
544 |
@Override |
|
545 |
public final IFeatureNodeService getFeatureNodeService(){ |
|
546 |
return configuration.getFeatureNodeService(); |
|
547 |
} |
|
548 |
|
|
549 |
|
|
550 |
@Override |
|
551 |
public final IVocabularyService getVocabularyService(){ |
|
552 |
return configuration.getVocabularyService(); |
|
553 |
} |
|
554 |
|
|
555 |
|
|
556 |
@Override |
|
557 |
public final IIdentificationKeyService getIdentificationKeyService(){ |
|
558 |
return configuration.getIdentificationKeyService(); |
|
559 |
} |
|
560 |
|
|
561 |
|
|
562 |
@Override |
|
563 |
public final IPolytomousKeyService getPolytomousKeyService(){ |
|
564 |
return configuration.getPolytomousKeyService(); |
|
565 |
} |
|
566 |
|
|
567 |
|
|
568 |
@Override |
|
569 |
public final IPolytomousKeyNodeService getPolytomousKeyNodeService(){ |
|
570 |
return configuration.getPolytomousKeyNodeService(); |
|
571 |
} |
|
572 |
|
|
573 |
|
|
574 |
@Override |
|
575 |
public IEntityValidationService getEntityValidationService(){ |
|
576 |
return configuration.getEntityValidationService(); |
|
577 |
} |
|
578 |
|
|
579 |
|
|
580 |
@Override |
|
581 |
public IEntityConstraintViolationService getEntityConstraintViolationService(){ |
|
582 |
return configuration.getEntityConstraintViolationService(); |
|
583 |
} |
|
584 |
|
|
585 |
|
|
586 |
@Override |
|
587 |
public final IService<CdmBase> getMainService(){ |
|
588 |
return configuration.getMainService(); |
|
589 |
} |
|
590 |
|
|
591 |
|
|
592 |
@Override |
|
593 |
public final IWorkingSetService getWorkingSetService(){ |
|
594 |
return configuration.getWorkingSetService(); |
|
595 |
} |
|
596 |
|
|
597 |
|
|
598 |
@Override |
|
599 |
public final ConversationHolder NewConversation(){ |
|
600 |
//return (ConversationHolder)applicationContext.getBean("conversationHolder"); |
|
601 |
return configuration.NewConversation(); |
|
602 |
} |
|
603 |
|
|
604 |
|
|
605 |
/* **** Security ***** */ |
|
606 |
|
|
607 |
@Override |
|
608 |
public void authenticate(String username, String password){ |
|
609 |
UsernamePasswordAuthenticationToken tokenForUser = new UsernamePasswordAuthenticationToken(username, password); |
|
610 |
Authentication authentication = this.getAuthenticationManager().authenticate(tokenForUser); |
|
611 |
SecurityContext context = SecurityContextHolder.getContext(); |
|
612 |
context.setAuthentication(authentication); |
|
613 |
} |
|
614 |
|
|
615 |
@Override |
|
616 |
public final ProviderManager getAuthenticationManager(){ |
|
617 |
return configuration.getAuthenticationManager(); |
|
618 |
} |
|
619 |
|
|
620 |
|
|
621 |
@Override |
|
622 |
public ICdmPermissionEvaluator getPermissionEvaluator(){ |
|
623 |
return configuration.getPermissionEvaluator(); |
|
624 |
} |
|
625 |
|
|
626 |
|
|
627 |
/** |
|
628 |
* @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, |
|
629 |
* java.lang.Object, java.lang.Object) |
|
630 |
* |
|
631 |
* @param targetDomainObject |
|
632 |
* @param permission |
|
633 |
* @return |
|
634 |
*/ |
|
635 |
public boolean currentAuthentiationHasPermissions(CdmBase targetDomainObject, EnumSet<CRUD> permission){ |
|
636 |
SecurityContext context = SecurityContextHolder.getContext(); |
|
637 |
return getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject, permission); |
|
638 |
} |
|
639 |
|
|
640 |
|
|
641 |
@Override |
|
642 |
public final PlatformTransactionManager getTransactionManager(){ |
|
643 |
return configuration.getTransactionManager(); |
|
644 |
} |
|
645 |
|
|
646 |
|
|
647 |
@Override |
|
648 |
public final Object getBean(String name){ |
|
649 |
return this.applicationContext.getBean(name); |
|
650 |
} |
|
651 |
|
|
652 |
|
|
653 |
/* |
|
654 |
* OLD TRANSACTION STUFF |
|
655 |
*/ |
|
656 |
|
|
657 |
/* **** flush ********** */ |
|
658 |
public void flush(){ |
|
659 |
SessionFactory sf = (SessionFactory) applicationContext.getBean("sessionFactory"); |
|
660 |
sf.getCurrentSession().flush(); |
|
661 |
} |
|
662 |
|
|
663 |
|
|
664 |
public SessionFactory getSessionFactory(){ |
|
665 |
return (SessionFactory) applicationContext.getBean("sessionFactory"); |
|
666 |
} |
|
667 |
|
|
668 |
|
|
669 |
@Override |
|
670 |
public TransactionStatus startTransaction(){ |
|
671 |
return startTransaction(false); |
|
672 |
} |
|
673 |
|
|
674 |
|
|
675 |
@Override |
|
676 |
public TransactionStatus startTransaction(Boolean readOnly){ |
|
677 |
return configuration.startTransaction(readOnly); |
|
678 |
} |
|
679 |
|
|
680 |
@Override |
|
681 |
public void commitTransaction(TransactionStatus txStatus){ |
|
682 |
PlatformTransactionManager txManager = configuration.getTransactionManager(); |
|
683 |
txManager.commit(txStatus); |
|
684 |
return; |
|
685 |
} |
|
686 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.api.application; |
|
12 |
|
|
13 |
import java.util.EnumSet; |
|
14 |
import java.util.List; |
|
15 |
import java.util.UUID; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
18 |
import org.hibernate.SessionFactory; |
|
19 |
import org.springframework.beans.MutablePropertyValues; |
|
20 |
import org.springframework.beans.factory.config.BeanDefinition; |
|
21 |
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
|
22 |
import org.springframework.context.ApplicationListener; |
|
23 |
import org.springframework.context.support.AbstractApplicationContext; |
|
24 |
import org.springframework.core.io.ClassPathResource; |
|
25 |
import org.springframework.core.io.Resource; |
|
26 |
import org.springframework.security.authentication.ProviderManager; |
|
27 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
28 |
import org.springframework.security.core.Authentication; |
|
29 |
import org.springframework.security.core.context.SecurityContext; |
|
30 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
31 |
import org.springframework.transaction.PlatformTransactionManager; |
|
32 |
import org.springframework.transaction.TransactionStatus; |
|
33 |
|
|
34 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
35 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
|
36 |
import eu.etaxonomy.cdm.api.service.IAnnotationService; |
|
37 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
38 |
import eu.etaxonomy.cdm.api.service.ICollectionService; |
|
39 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
|
40 |
import eu.etaxonomy.cdm.api.service.IDatabaseService; |
|
41 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
42 |
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService; |
|
43 |
import eu.etaxonomy.cdm.api.service.IEntityValidationService; |
|
44 |
import eu.etaxonomy.cdm.api.service.IFeatureNodeService; |
|
45 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService; |
|
46 |
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService; |
|
47 |
import eu.etaxonomy.cdm.api.service.IGroupService; |
|
48 |
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService; |
|
49 |
import eu.etaxonomy.cdm.api.service.ILocationService; |
|
50 |
import eu.etaxonomy.cdm.api.service.IMediaService; |
|
51 |
import eu.etaxonomy.cdm.api.service.INameService; |
|
52 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
53 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService; |
|
54 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService; |
|
55 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
|
56 |
import eu.etaxonomy.cdm.api.service.IService; |
|
57 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
58 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
59 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
60 |
import eu.etaxonomy.cdm.api.service.IUserService; |
|
61 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
62 |
import eu.etaxonomy.cdm.api.service.IWorkingSetService; |
|
63 |
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService; |
|
64 |
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService; |
|
65 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
|
66 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
|
67 |
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor; |
|
68 |
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor; |
|
69 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
70 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
71 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
72 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
73 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
74 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
75 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
|
76 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator; |
|
77 |
|
|
78 |
/** |
|
79 |
* @author a.mueller |
|
80 |
*/ |
|
81 |
public class CdmApplicationController implements ICdmApplicationConfiguration { |
|
82 |
private static final Logger logger = Logger.getLogger(CdmApplicationController.class); |
|
83 |
|
|
84 |
public static final String DEFAULT_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/defaultApplicationContext.xml"; |
|
85 |
|
|
86 |
public AbstractApplicationContext applicationContext; |
|
87 |
protected ICdmApplicationConfiguration configuration; |
|
88 |
private final Resource applicationContextResource; |
|
89 |
|
|
90 |
private final IProgressMonitor progressMonitor; |
|
91 |
|
|
92 |
final protected static DbSchemaValidation defaultDbSchemaValidation = DbSchemaValidation.VALIDATE; |
|
93 |
|
|
94 |
|
|
95 |
/** |
|
96 |
* Constructor, opens a spring ApplicationContext by using the default data source |
|
97 |
* |
|
98 |
* @throws DataSourceNotFoundException |
|
99 |
*/ |
|
100 |
public static CdmApplicationController NewInstance() throws DataSourceNotFoundException{ |
|
101 |
logger.info("Start CdmApplicationController with default data source"); |
|
102 |
CdmPersistentDataSource dataSource = getDefaultDatasource(); |
|
103 |
DbSchemaValidation dbSchemaValidation = defaultDbSchemaValidation; |
|
104 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, false); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
/** |
|
109 |
* Constructor, opens a spring ApplicationContext by using the default data source |
|
110 |
* |
|
111 |
* @param dbSchemaValidation |
|
112 |
* validation type for database schema |
|
113 |
* @throws DataSourceNotFoundException |
|
114 |
*/ |
|
115 |
public static CdmApplicationController NewInstance(DbSchemaValidation dbSchemaValidation) throws DataSourceNotFoundException{ |
|
116 |
logger.info("Start CdmApplicationController with default data source"); |
|
117 |
CdmPersistentDataSource dataSource = getDefaultDatasource(); |
|
118 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, false); |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
/** |
|
123 |
* Constructor, opens an spring ApplicationContext by using the according data source |
|
124 |
* and the default database schema validation type |
|
125 |
* |
|
126 |
* @param dataSource |
|
127 |
*/ |
|
128 |
public static CdmApplicationController NewInstance(ICdmDataSource dataSource){ |
|
129 |
return CdmApplicationController.NewInstance(null, dataSource, defaultDbSchemaValidation, false); |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
public static CdmApplicationController NewInstance(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation){ |
|
134 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, false); |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
public static CdmApplicationController NewInstance(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading){ |
|
139 |
return CdmApplicationController.NewInstance(null, dataSource, dbSchemaValidation, omitTermLoading); |
|
140 |
} |
|
141 |
|
|
142 |
public static CdmApplicationController NewInstance(Resource applicationContextResource, ICdmDataSource dataSource, |
|
143 |
DbSchemaValidation dbSchemaValidation, boolean omitTermLoading){ |
|
144 |
return CdmApplicationController.NewInstance(applicationContextResource, dataSource, dbSchemaValidation, omitTermLoading, null); |
|
145 |
} |
|
146 |
|
|
147 |
public static CdmApplicationController NewInstance(Resource applicationContextResource, ICdmDataSource dataSource, |
|
148 |
DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, IProgressMonitor progressMonitor){ |
|
149 |
return new CdmApplicationController(applicationContextResource, dataSource, dbSchemaValidation, omitTermLoading, progressMonitor, null); |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
//TODO discuss need for listeners before commit to trunk |
|
154 |
// public static CdmApplicationController NewInstance(Resource applicationContextResource, ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, IProgressMonitor progressMonitor, List<ApplicationListener> listeners) { |
|
155 |
// return new CdmApplicationController(applicationContextResource, dataSource, dbSchemaValidation, omitTermLoading, progressMonitor,listeners); |
|
156 |
// } |
|
157 |
|
|
158 |
/** |
|
159 |
* @return |
|
160 |
*/ |
|
161 |
protected static ClassPathResource getClasspathResource(){ |
|
162 |
return new ClassPathResource(DEFAULT_APPLICATION_CONTEXT_RESOURCE); |
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
/** |
|
167 |
* @return |
|
168 |
* @throws DataSourceNotFoundException |
|
169 |
*/ |
|
170 |
protected static CdmPersistentDataSource getDefaultDatasource() throws DataSourceNotFoundException{ |
|
171 |
CdmPersistentDataSource dataSource = CdmPersistentDataSource.NewDefaultInstance(); |
|
172 |
return dataSource; |
|
173 |
} |
|
174 |
|
|
175 |
|
|
176 |
/** |
|
177 |
* |
|
178 |
* FIXME:Remoting this constructor is added only to allow extension of this cntroller |
|
179 |
* class. and should be removed after refactoring |
|
180 |
*/ |
|
181 |
protected CdmApplicationController(){ |
|
182 |
applicationContextResource = null; |
|
183 |
progressMonitor = null; |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
/** |
|
188 |
* Constructor, opens an spring 2.5 ApplicationContext by using the according data |
|
189 |
* source |
|
190 |
* |
|
191 |
* @param dataSource |
|
192 |
* @param dbSchemaValidation |
|
193 |
* @param omitTermLoading |
|
194 |
*/ |
|
195 |
protected CdmApplicationController(Resource applicationContextResource, ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, |
|
196 |
boolean omitTermLoading, IProgressMonitor progressMonitor, List<ApplicationListener> listeners){ |
|
197 |
logger.info("Start CdmApplicationController with datasource: " + dataSource.getName()); |
|
198 |
|
|
199 |
if (dbSchemaValidation == null) { |
|
200 |
dbSchemaValidation = defaultDbSchemaValidation; |
|
201 |
} |
|
202 |
this.applicationContextResource = applicationContextResource != null ? applicationContextResource : getClasspathResource(); |
|
203 |
this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor(); |
|
204 |
|
|
205 |
setNewDataSource(dataSource, dbSchemaValidation, omitTermLoading, listeners); |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
/** |
|
210 |
* Sets the application context to a new spring ApplicationContext by using the |
|
211 |
* according data source and initializes the Controller. |
|
212 |
* |
|
213 |
* @param dataSource |
|
214 |
*/ |
|
215 |
private boolean setNewDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, |
|
216 |
List<ApplicationListener> listeners){ |
|
217 |
|
|
218 |
if (dbSchemaValidation == null) { |
|
219 |
dbSchemaValidation = defaultDbSchemaValidation; |
|
220 |
} |
|
221 |
logger.info("Connecting to '" + dataSource.getName() + "'"); |
|
222 |
|
|
223 |
MonitoredGenericApplicationContext applicationContext = new MonitoredGenericApplicationContext(); |
|
224 |
int refreshTasks = 45; |
|
225 |
int nTasks = 5 + refreshTasks; |
|
226 |
// nTasks += applicationContext.countTasks(); |
|
227 |
progressMonitor.beginTask("Connecting to '" + dataSource.getName() + "'", nTasks); |
|
228 |
|
|
229 |
// progressMonitor.worked(1); |
|
230 |
|
|
231 |
BeanDefinition datasourceBean = dataSource.getDatasourceBean(); |
|
232 |
datasourceBean.setAttribute("isLazy", false); |
|
233 |
progressMonitor.subTask("Registering datasource."); |
|
234 |
applicationContext.registerBeanDefinition("dataSource", datasourceBean); |
|
235 |
progressMonitor.worked(1); |
|
236 |
|
|
237 |
BeanDefinition hibernatePropBean = dataSource.getHibernatePropertiesBean(dbSchemaValidation); |
|
238 |
applicationContext.registerBeanDefinition("hibernateProperties", hibernatePropBean); |
|
239 |
|
|
240 |
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); |
|
241 |
progressMonitor.subTask("Registering resources."); |
|
242 |
xmlReader.loadBeanDefinitions(applicationContextResource); |
|
243 |
progressMonitor.worked(1); |
|
244 |
|
|
245 |
//omitTerms |
|
246 |
if (omitTermLoading == true) { |
|
247 |
String initializerName = "persistentTermInitializer"; |
|
248 |
BeanDefinition beanDef = applicationContext.getBeanDefinition(initializerName); |
|
249 |
MutablePropertyValues values = beanDef.getPropertyValues(); |
|
250 |
values.addPropertyValue("omit", omitTermLoading); |
|
251 |
} |
|
252 |
|
|
253 |
if (listeners != null) { |
|
254 |
for (ApplicationListener listener : listeners) { |
|
255 |
applicationContext.addApplicationListener(listener); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
// String message = "Start application context. This might take a while ..."; |
|
260 |
//// progressMonitor.subTask(message); |
|
261 |
// SubProgressMonitor subMonitor= new SubProgressMonitor(progressMonitor, 10); |
|
262 |
// subMonitor.beginTask(message, 2); |
|
263 |
// applicationContext.setProgressMonitor(subMonitor); |
|
264 |
|
|
265 |
applicationContext.refresh(new SubProgressMonitor(progressMonitor, refreshTasks)); |
|
266 |
applicationContext.start(); |
|
267 |
// progressMonitor.worked(1); |
|
268 |
|
|
269 |
progressMonitor.subTask("Cleaning up."); |
|
270 |
setApplicationContext(applicationContext); |
|
271 |
progressMonitor.worked(1); |
|
272 |
|
|
273 |
progressMonitor.done(); |
|
274 |
return true; |
|
275 |
} |
|
276 |
|
|
277 |
|
|
278 |
/** |
|
279 |
* Tests if some DefinedTermsAreMissing. |
|
280 |
* |
|
281 |
* @return true, if at least one is missing, else false |
|
282 |
*/ |
|
283 |
public boolean testDefinedTermsAreMissing(){ |
|
284 |
UUID englishUuid = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523"); |
|
285 |
DefinedTermBase<?> english = this.getTermService().load(englishUuid); |
|
286 |
if (english == null || !english.getUuid().equals(englishUuid)) { |
|
287 |
return true; |
|
288 |
} |
|
289 |
else { |
|
290 |
return false; |
|
291 |
} |
|
292 |
} |
|
293 |
|
|
294 |
|
|
295 |
/** |
|
296 |
* Changes the ApplicationContext to the new dataSource |
|
297 |
* |
|
298 |
* @param dataSource |
|
299 |
*/ |
|
300 |
public boolean changeDataSource(ICdmDataSource dataSource){ |
|
301 |
//logger.info("Change datasource to : " + dataSource); |
|
302 |
return setNewDataSource(dataSource, DbSchemaValidation.VALIDATE, false, null); |
|
303 |
} |
|
304 |
|
|
305 |
|
|
306 |
/** |
|
307 |
* Changes the ApplicationContext to the new dataSource |
|
308 |
* |
|
309 |
* @param dataSource |
|
310 |
* @param dbSchemaValidation |
|
311 |
*/ |
|
312 |
public boolean changeDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation){ |
|
313 |
//logger.info("Change datasource to : " + dataSource); |
|
314 |
return setNewDataSource(dataSource, dbSchemaValidation, false, null); |
|
315 |
} |
|
316 |
|
|
317 |
|
|
318 |
/** |
|
319 |
* Changes the ApplicationContext to the new dataSource |
|
320 |
* |
|
321 |
* @param dataSource |
|
322 |
* @param dbSchemaValidation |
|
323 |
* @param omitTermLoading |
|
324 |
*/ |
|
325 |
public boolean changeDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading){ |
|
326 |
logger.info("Change datasource to : " + dataSource); |
|
327 |
return setNewDataSource(dataSource, dbSchemaValidation, omitTermLoading, null); |
|
328 |
} |
|
329 |
|
|
330 |
|
|
331 |
/** |
|
332 |
* Changes the ApplicationContext to the new dataSource |
|
333 |
* |
|
334 |
* @param dataSource |
|
335 |
* @param dbSchemaValidation |
|
336 |
* @param omitTermLoading |
|
337 |
*/ |
|
338 |
public boolean changeDataSource(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading, |
|
339 |
List<ApplicationListener> listeners){ |
|
340 |
logger.info("Change datasource to : " + dataSource); |
|
341 |
return setNewDataSource(dataSource, dbSchemaValidation, omitTermLoading, listeners); |
|
342 |
} |
|
343 |
|
|
344 |
|
|
345 |
/** |
|
346 |
* Sets a new application Context. |
|
347 |
* |
|
348 |
* @param ac |
|
349 |
*/ |
|
350 |
public void setApplicationContext(AbstractApplicationContext ac){ |
|
351 |
closeApplicationContext(); //closes old application context if necessary |
|
352 |
applicationContext = ac; |
|
353 |
applicationContext.registerShutdownHook(); |
|
354 |
init(); |
|
355 |
} |
|
356 |
|
|
357 |
|
|
358 |
/* |
|
359 |
* (non-Javadoc) |
|
360 |
* |
|
361 |
* @see java.lang.Object#finalize() |
|
362 |
*/ |
|
363 |
@Override |
|
364 |
public void finalize(){ |
|
365 |
close(); |
|
366 |
} |
|
367 |
|
|
368 |
|
|
369 |
/** |
|
370 |
* closes the application |
|
371 |
*/ |
|
372 |
public void close(){ |
|
373 |
closeApplicationContext(); |
|
374 |
} |
|
375 |
|
|
376 |
|
|
377 |
/** |
|
378 |
* closes the application context |
|
379 |
*/ |
|
380 |
protected void closeApplicationContext(){ |
|
381 |
if (applicationContext != null) { |
|
382 |
logger.info("Close ApplicationContext"); |
|
383 |
applicationContext.close(); |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
|
|
388 |
protected void init(){ |
|
389 |
logger.debug("Init " + this.getClass().getName() + " ... "); |
|
390 |
if (logger.isDebugEnabled()) { |
|
391 |
for (String beanName : applicationContext.getBeanDefinitionNames()) { |
|
392 |
logger.debug(beanName); |
|
393 |
} |
|
394 |
} |
|
395 |
//TODO delete next row (was just for testing) |
|
396 |
if (logger.isInfoEnabled()) { |
|
397 |
logger.info("Registered Beans: "); |
|
398 |
String[] beanNames = applicationContext.getBeanDefinitionNames(); |
|
399 |
for (String beanName : beanNames) { |
|
400 |
logger.info(beanName); |
|
401 |
} |
|
402 |
} |
|
403 |
configuration = (ICdmApplicationConfiguration) applicationContext.getBean("cdmApplicationDefaultConfiguration"); |
|
404 |
try { |
|
405 |
//FIXME:Remoting catching exection to allow for remoting |
|
406 |
getDatabaseService().setApplicationController(this); |
|
407 |
} |
|
408 |
catch (UnsupportedOperationException uoe) { |
|
409 |
logger.warn("getDatabaseService() is not implmented for current application context"); |
|
410 |
} |
|
411 |
} |
|
412 |
|
|
413 |
|
|
414 |
/* ****** Services ******** */ |
|
415 |
@Override |
|
416 |
public final IAnnotationService getAnnotationService(){ |
|
417 |
return configuration.getAnnotationService(); |
|
418 |
} |
|
419 |
|
|
420 |
@Override |
|
421 |
public final INameService getNameService(){ |
|
422 |
return configuration.getNameService(); |
|
423 |
} |
|
424 |
|
|
425 |
|
|
426 |
@Override |
|
427 |
public final ITaxonService getTaxonService(){ |
|
428 |
return configuration.getTaxonService(); |
|
429 |
} |
|
430 |
|
|
431 |
|
|
432 |
@Override |
|
433 |
public final IClassificationService getClassificationService(){ |
|
434 |
return configuration.getClassificationService(); |
|
435 |
} |
|
436 |
|
|
437 |
|
|
438 |
@Override |
|
439 |
public final ITaxonNodeService getTaxonNodeService(){ |
|
440 |
return configuration.getTaxonNodeService(); |
|
441 |
} |
|
442 |
|
|
443 |
|
|
444 |
@Override |
|
445 |
public final IReferenceService getReferenceService(){ |
|
446 |
return configuration.getReferenceService(); |
|
447 |
} |
|
448 |
|
|
449 |
|
|
450 |
@Override |
|
451 |
public final IAgentService getAgentService(){ |
|
452 |
return configuration.getAgentService(); |
|
453 |
} |
|
454 |
|
|
455 |
|
|
456 |
@Override |
|
457 |
public final IDatabaseService getDatabaseService(){ |
|
458 |
return configuration.getDatabaseService(); |
|
459 |
} |
|
460 |
|
|
461 |
|
|
462 |
@Override |
|
463 |
public final ITermService getTermService(){ |
|
464 |
return configuration.getTermService(); |
|
465 |
} |
|
466 |
|
|
467 |
|
|
468 |
@Override |
|
469 |
public final IDescriptionService getDescriptionService(){ |
|
470 |
return configuration.getDescriptionService(); |
|
471 |
} |
|
472 |
|
|
473 |
|
|
474 |
@Override |
|
475 |
public final IOccurrenceService getOccurrenceService(){ |
|
476 |
return configuration.getOccurrenceService(); |
|
477 |
} |
|
478 |
|
|
479 |
@Override |
|
480 |
public IAmplificationService getAmplificationService(){ |
|
481 |
return configuration.getAmplificationService(); |
|
482 |
} |
|
483 |
|
|
484 |
@Override |
|
485 |
public ISequenceService getSequenceService(){ |
|
486 |
return configuration.getSequenceService(); |
|
487 |
} |
|
488 |
|
|
489 |
|
|
490 |
@Override |
|
491 |
public final IPrimerService getPrimerService(){ |
|
492 |
return configuration.getPrimerService(); |
|
493 |
} |
|
494 |
|
|
495 |
|
|
496 |
@Override |
|
497 |
public final IMediaService getMediaService(){ |
|
498 |
return configuration.getMediaService(); |
|
499 |
} |
|
500 |
|
|
501 |
|
|
502 |
@Override |
|
503 |
public final ICommonService getCommonService(){ |
|
504 |
return configuration.getCommonService(); |
|
505 |
} |
|
506 |
|
|
507 |
|
|
508 |
@Override |
|
509 |
public final ILocationService getLocationService(){ |
|
510 |
return configuration.getLocationService(); |
|
511 |
} |
|
512 |
|
|
513 |
|
|
514 |
@Override |
|
515 |
public final IUserService getUserService(){ |
|
516 |
return configuration.getUserService(); |
|
517 |
} |
|
518 |
|
|
519 |
|
|
520 |
@Override |
|
521 |
public final IGrantedAuthorityService getGrantedAuthorityService(){ |
|
522 |
return configuration.getGrantedAuthorityService(); |
|
523 |
} |
|
524 |
|
|
525 |
|
|
526 |
@Override |
|
527 |
public IGroupService getGroupService(){ |
|
528 |
return configuration.getGroupService(); |
|
529 |
} |
|
530 |
|
|
531 |
|
|
532 |
@Override |
|
533 |
public final ICollectionService getCollectionService(){ |
|
534 |
return configuration.getCollectionService(); |
|
535 |
} |
|
536 |
|
|
537 |
|
|
538 |
@Override |
|
539 |
public final IFeatureTreeService getFeatureTreeService(){ |
|
540 |
return configuration.getFeatureTreeService(); |
|
541 |
} |
|
542 |
|
|
543 |
|
|
544 |
@Override |
|
545 |
public final IFeatureNodeService getFeatureNodeService(){ |
|
546 |
return configuration.getFeatureNodeService(); |
|
547 |
} |
|
548 |
|
|
549 |
|
|
550 |
@Override |
|
551 |
public final IVocabularyService getVocabularyService(){ |
|
552 |
return configuration.getVocabularyService(); |
|
553 |
} |
|
554 |
|
|
555 |
|
|
556 |
@Override |
|
557 |
public final IIdentificationKeyService getIdentificationKeyService(){ |
|
558 |
return configuration.getIdentificationKeyService(); |
|
559 |
} |
|
560 |
|
|
561 |
|
|
562 |
@Override |
|
563 |
public final IPolytomousKeyService getPolytomousKeyService(){ |
|
564 |
return configuration.getPolytomousKeyService(); |
|
565 |
} |
|
566 |
|
|
567 |
|
|
568 |
@Override |
|
569 |
public final IPolytomousKeyNodeService getPolytomousKeyNodeService(){ |
|
570 |
return configuration.getPolytomousKeyNodeService(); |
|
571 |
} |
|
572 |
|
|
573 |
|
|
574 |
@Override |
|
575 |
public IEntityValidationService getEntityValidationService(){ |
|
576 |
return configuration.getEntityValidationService(); |
|
577 |
} |
|
578 |
|
|
579 |
|
|
580 |
@Override |
|
581 |
public IEntityConstraintViolationService getEntityConstraintViolationService(){ |
|
582 |
return configuration.getEntityConstraintViolationService(); |
|
583 |
} |
|
584 |
|
|
585 |
|
|
586 |
@Override |
|
587 |
public final IService<CdmBase> getMainService(){ |
|
588 |
return configuration.getMainService(); |
|
589 |
} |
|
590 |
|
|
591 |
|
|
592 |
@Override |
|
593 |
public final IWorkingSetService getWorkingSetService(){ |
|
594 |
return configuration.getWorkingSetService(); |
|
595 |
} |
|
596 |
|
|
597 |
|
|
598 |
@Override |
|
599 |
public final ConversationHolder NewConversation(){ |
|
600 |
//return (ConversationHolder)applicationContext.getBean("conversationHolder"); |
|
601 |
return configuration.NewConversation(); |
|
602 |
} |
|
603 |
|
|
604 |
|
|
605 |
/* **** Security ***** */ |
|
606 |
|
|
607 |
@Override |
|
608 |
public void authenticate(String username, String password){ |
|
609 |
UsernamePasswordAuthenticationToken tokenForUser = new UsernamePasswordAuthenticationToken(username, password); |
|
610 |
Authentication authentication = this.getAuthenticationManager().authenticate(tokenForUser); |
|
611 |
SecurityContext context = SecurityContextHolder.getContext(); |
|
612 |
context.setAuthentication(authentication); |
|
613 |
} |
|
614 |
|
|
615 |
@Override |
|
616 |
public final ProviderManager getAuthenticationManager(){ |
|
617 |
return configuration.getAuthenticationManager(); |
|
618 |
} |
|
619 |
|
|
620 |
|
|
621 |
@Override |
|
622 |
public ICdmPermissionEvaluator getPermissionEvaluator(){ |
|
623 |
return configuration.getPermissionEvaluator(); |
|
624 |
} |
|
625 |
|
|
626 |
|
|
627 |
/** |
|
628 |
* @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, |
|
629 |
* java.lang.Object, java.lang.Object) |
|
630 |
* |
|
631 |
* @param targetDomainObject |
|
632 |
* @param permission |
|
633 |
* @return |
|
634 |
*/ |
|
635 |
public boolean currentAuthentiationHasPermissions(CdmBase targetDomainObject, EnumSet<CRUD> permission){ |
|
636 |
SecurityContext context = SecurityContextHolder.getContext(); |
|
637 |
return getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject, permission); |
|
638 |
} |
|
639 |
|
|
640 |
|
|
641 |
@Override |
|
642 |
public final PlatformTransactionManager getTransactionManager(){ |
|
643 |
return configuration.getTransactionManager(); |
|
644 |
} |
|
645 |
|
|
646 |
|
|
647 |
@Override |
|
648 |
public final Object getBean(String name){ |
|
649 |
return this.applicationContext.getBean(name); |
|
650 |
} |
|
651 |
|
|
652 |
|
|
653 |
/* |
|
654 |
* OLD TRANSACTION STUFF |
|
655 |
*/ |
|
656 |
|
|
657 |
/* **** flush ********** */ |
|
658 |
public void flush(){ |
|
659 |
SessionFactory sf = (SessionFactory) applicationContext.getBean("sessionFactory"); |
|
660 |
sf.getCurrentSession().flush(); |
|
661 |
} |
|
662 |
|
|
663 |
|
|
664 |
public SessionFactory getSessionFactory(){ |
|
665 |
return (SessionFactory) applicationContext.getBean("sessionFactory"); |
|
666 |
} |
|
667 |
|
|
668 |
|
|
669 |
@Override |
|
670 |
public TransactionStatus startTransaction(){ |
|
671 |
return startTransaction(false); |
|
672 |
} |
|
673 |
|
|
674 |
|
|
675 |
@Override |
|
676 |
public TransactionStatus startTransaction(Boolean readOnly){ |
|
677 |
return configuration.startTransaction(readOnly); |
|
678 |
} |
|
679 |
|
|
680 |
@Override |
|
681 |
public void commitTransaction(TransactionStatus txStatus){ |
|
682 |
PlatformTransactionManager txManager = configuration.getTransactionManager(); |
|
683 |
txManager.commit(txStatus); |
|
684 |
return; |
|
685 |
} |
|
686 |
} |
Also available in: Unified diff
Minor cleanup