1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.store;
|
11
|
|
12
|
import java.util.EnumSet;
|
13
|
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.core.runtime.jobs.Job;
|
16
|
import org.eclipse.swt.widgets.Display;
|
17
|
import org.springframework.core.io.ClassPathResource;
|
18
|
import org.springframework.core.io.Resource;
|
19
|
import org.springframework.security.access.PermissionEvaluator;
|
20
|
import org.springframework.security.authentication.AuthenticationManager;
|
21
|
import org.springframework.security.core.Authentication;
|
22
|
import org.springframework.security.core.GrantedAuthority;
|
23
|
import org.springframework.security.core.context.SecurityContext;
|
24
|
import org.springframework.security.core.context.SecurityContextHolder;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.application.CdmApplicationException;
|
27
|
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
|
28
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
29
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
30
|
import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
|
31
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
32
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
33
|
import eu.etaxonomy.cdm.api.service.IAnnotationService;
|
34
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
35
|
import eu.etaxonomy.cdm.api.service.ICollectionService;
|
36
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
37
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
38
|
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService;
|
39
|
import eu.etaxonomy.cdm.api.service.IEntityValidationService;
|
40
|
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
|
41
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
42
|
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService;
|
43
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
44
|
import eu.etaxonomy.cdm.api.service.IMarkerService;
|
45
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
46
|
import eu.etaxonomy.cdm.api.service.INameService;
|
47
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
48
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
49
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
50
|
import eu.etaxonomy.cdm.api.service.IPreferenceService;
|
51
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
52
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
53
|
import eu.etaxonomy.cdm.api.service.IRightsService;
|
54
|
import eu.etaxonomy.cdm.api.service.IService;
|
55
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
56
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
57
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
58
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
59
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
60
|
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
|
61
|
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
|
62
|
import eu.etaxonomy.cdm.api.service.statistics.Statistics;
|
63
|
import eu.etaxonomy.cdm.config.ICdmSource;
|
64
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
65
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
66
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
67
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
68
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
69
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
70
|
import eu.etaxonomy.cdm.model.common.Group;
|
71
|
import eu.etaxonomy.cdm.model.common.Language;
|
72
|
import eu.etaxonomy.cdm.model.common.Marker;
|
73
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
74
|
import eu.etaxonomy.cdm.model.common.User;
|
75
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
76
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
77
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
78
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
79
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
80
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
81
|
import eu.etaxonomy.cdm.model.media.Media;
|
82
|
import eu.etaxonomy.cdm.model.media.Rights;
|
83
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
84
|
import eu.etaxonomy.cdm.model.molecular.Amplification;
|
85
|
import eu.etaxonomy.cdm.model.molecular.Primer;
|
86
|
import eu.etaxonomy.cdm.model.name.Registration;
|
87
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
88
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
89
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
90
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
91
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
92
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
93
|
import eu.etaxonomy.cdm.model.validation.EntityConstraintViolation;
|
94
|
import eu.etaxonomy.cdm.model.validation.EntityValidation;
|
95
|
import eu.etaxonomy.cdm.model.view.AuditEvent;
|
96
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
97
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
|
98
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
99
|
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
|
100
|
import eu.etaxonomy.taxeditor.io.ExportManager;
|
101
|
import eu.etaxonomy.taxeditor.io.ImportManager;
|
102
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
103
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
104
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
|
105
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
|
106
|
import eu.etaxonomy.taxeditor.session.mock.MockCdmEntitySessionManager;
|
107
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
108
|
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
|
109
|
import eu.etaxonomy.taxeditor.util.ProgressMonitorClientManager;
|
110
|
import eu.etaxonomy.taxeditor.webapp.CDMServer;
|
111
|
|
112
|
/**
|
113
|
* This implementation of ICdmDataRepository depends on hibernate sessions to
|
114
|
* store the data correctly for the current session. No state is held in this
|
115
|
* class.
|
116
|
*
|
117
|
* Only methods that either get or manipulate data are exposed here. So this
|
118
|
* class acts as a facade for the methods in cdmlib-service.
|
119
|
*
|
120
|
* @author n.hoffmann
|
121
|
* @created 17.03.2009
|
122
|
* @version 1.0
|
123
|
*/
|
124
|
public class CdmStore {
|
125
|
|
126
|
private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
|
127
|
"/eu/etaxonomy/cdm/editorApplicationContext.xml",
|
128
|
TaxeditorStorePlugin.class);
|
129
|
private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE;
|
130
|
|
131
|
private static CdmStore instance;
|
132
|
|
133
|
//private final ICdmRepository applicationConfiguration;
|
134
|
|
135
|
private static ContextManager contextManager = new ContextManager();
|
136
|
|
137
|
private static LoginManager loginManager = new LoginManager();
|
138
|
|
139
|
private static TermManager termManager = new TermManager();
|
140
|
|
141
|
private static SearchManager searchManager = new SearchManager();
|
142
|
|
143
|
private static EditorManager editorManager = new EditorManager();
|
144
|
|
145
|
private static UseObjectStore useObjectInitializer = new UseObjectStore();
|
146
|
|
147
|
private static ProgressMonitorClientManager progressMonitorClientManager = new ProgressMonitorClientManager();
|
148
|
|
149
|
private static CdmStoreConnector job;
|
150
|
|
151
|
private static CDMServer managedServer;
|
152
|
|
153
|
private Language language;
|
154
|
|
155
|
private ICdmSource cdmSource;
|
156
|
|
157
|
private boolean isConnected;
|
158
|
|
159
|
|
160
|
|
161
|
/**
|
162
|
* <p>
|
163
|
* getDefault
|
164
|
* </p>
|
165
|
*
|
166
|
* @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
|
167
|
*/
|
168
|
protected static CdmStore getDefault(boolean connecting){
|
169
|
if (instance != null && instance.isConnected) {
|
170
|
return instance;
|
171
|
} else{// if (instance == null || !instance.isConnected) {
|
172
|
if (connecting){
|
173
|
MessagingUtils.dataSourceNotAvailableWarningDialog(instance);
|
174
|
}else{
|
175
|
MessagingUtils.noDataSourceWarningDialog(instance);
|
176
|
}
|
177
|
|
178
|
|
179
|
return null;
|
180
|
}
|
181
|
}
|
182
|
/**
|
183
|
* <p>
|
184
|
* getDefault
|
185
|
* </p>
|
186
|
*
|
187
|
* @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
|
188
|
*/
|
189
|
protected static CdmStore getDefault(){
|
190
|
return getDefault(false);
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* Initialize the with the last edited datasource
|
195
|
*/
|
196
|
public static void connect() {
|
197
|
|
198
|
ICdmSource cdmSource;
|
199
|
try {
|
200
|
|
201
|
cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
|
202
|
connect(cdmSource);
|
203
|
} catch (Exception e) {
|
204
|
MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
|
205
|
}
|
206
|
|
207
|
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* Initialize with a specific datasource
|
212
|
*
|
213
|
* @param datasource
|
214
|
* a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
|
215
|
*/
|
216
|
public static void connect(ICdmSource cdmSource) {
|
217
|
connect(cdmSource, DEFAULT_DB_SCHEMA_VALIDATION,
|
218
|
DEFAULT_APPLICATION_CONTEXT);
|
219
|
}
|
220
|
|
221
|
public static void connect(ICdmSource cdmSource, RemotingLoginDialog loginDialog) {
|
222
|
connect(cdmSource,
|
223
|
DEFAULT_DB_SCHEMA_VALIDATION,
|
224
|
DEFAULT_APPLICATION_CONTEXT,
|
225
|
loginDialog);
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* Initialize and provide
|
230
|
*
|
231
|
* @param datasource
|
232
|
* @param dbSchemaValidation
|
233
|
* @param applicationContextBean
|
234
|
*/
|
235
|
private static void connect(final ICdmSource cdmSource,
|
236
|
final DbSchemaValidation dbSchemaValidation,
|
237
|
final Resource applicationContextBean) {
|
238
|
|
239
|
MessagingUtils.info("Connecting to datasource: " + cdmSource);
|
240
|
|
241
|
job = new CdmStoreConnector(Display.getDefault(), cdmSource,
|
242
|
dbSchemaValidation, applicationContextBean);
|
243
|
job.setUser(true);
|
244
|
job.setPriority(Job.BUILD);
|
245
|
job.schedule();
|
246
|
|
247
|
}
|
248
|
|
249
|
private static void connect(final ICdmSource cdmSource,
|
250
|
final DbSchemaValidation dbSchemaValidation,
|
251
|
final Resource applicationContextBean,
|
252
|
RemotingLoginDialog remotingLoginDialog) {
|
253
|
RemotingLoginDialog loginDialog = remotingLoginDialog;
|
254
|
if(isActive()) {
|
255
|
// before we connect we clear the entity caches and the sessions
|
256
|
CdmRemoteCacheManager.removeEntityCaches();
|
257
|
if(getCurrentSessionManager(true) != null) {
|
258
|
getCurrentSessionManager(true).disposeAll();
|
259
|
}
|
260
|
}
|
261
|
MessagingUtils.info("Connecting to datasource: " + cdmSource);
|
262
|
|
263
|
job = new CdmStoreConnector(Display.getDefault(),
|
264
|
cdmSource,
|
265
|
dbSchemaValidation,
|
266
|
applicationContextBean);
|
267
|
job.start(loginDialog);
|
268
|
|
269
|
}
|
270
|
|
271
|
public static boolean isConnecting() {
|
272
|
return job != null && job.getState() == Job.RUNNING;
|
273
|
}
|
274
|
|
275
|
/**
|
276
|
* Closes the current application context
|
277
|
*
|
278
|
* @param monitor
|
279
|
* a {@link org.eclipse.core.runtime.IProgressMonitor} object.
|
280
|
*/
|
281
|
public static void close(final IProgressMonitor monitor) {
|
282
|
Display.getDefault().asyncExec(new Runnable() {
|
283
|
|
284
|
@Override
|
285
|
public void run() {
|
286
|
getContextManager().notifyContextAboutToStop(monitor);
|
287
|
if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
|
288
|
getContextManager().notifyContextStop(monitor);
|
289
|
instance.close();
|
290
|
}
|
291
|
}
|
292
|
});
|
293
|
}
|
294
|
|
295
|
public static void close(IProgressMonitor monitor, boolean async) {
|
296
|
if(async) {
|
297
|
close(monitor);
|
298
|
} else {
|
299
|
getContextManager().notifyContextAboutToStop(monitor);
|
300
|
if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
|
301
|
getContextManager().notifyContextStop(monitor);
|
302
|
instance.close();
|
303
|
}
|
304
|
}
|
305
|
|
306
|
}
|
307
|
private void close() {
|
308
|
isConnected = false;
|
309
|
cdmSource = null;
|
310
|
CdmApplicationState.dispose();
|
311
|
}
|
312
|
|
313
|
static void setInstance(ICdmRepository applicationController,
|
314
|
ICdmSource cdmSource) {
|
315
|
instance = new CdmStore(applicationController, cdmSource);
|
316
|
CdmApplicationState.setCdmServiceCacher(new CdmServiceCacher());
|
317
|
|
318
|
}
|
319
|
|
320
|
private CdmStore(ICdmRepository repository,
|
321
|
ICdmSource cdmSource) {
|
322
|
CdmApplicationState.setCurrentAppConfig(repository);
|
323
|
CdmApplicationState.setCurrentDataChangeService(new CdmUIDataChangeService());
|
324
|
this.cdmSource = cdmSource;
|
325
|
isConnected = true;
|
326
|
}
|
327
|
|
328
|
/**
|
329
|
* All calls to the datastore require
|
330
|
*
|
331
|
* @return
|
332
|
*/
|
333
|
private ICdmRepository getApplicationConfiguration() {
|
334
|
try {
|
335
|
return CdmApplicationState.getCurrentAppConfig();
|
336
|
} catch (Exception e) {
|
337
|
MessagingUtils.error(CdmStore.class, e);
|
338
|
}
|
339
|
return null;
|
340
|
}
|
341
|
|
342
|
/**
|
343
|
* <p>
|
344
|
* getCurrentApplicationController
|
345
|
* </p>
|
346
|
*
|
347
|
* @return a
|
348
|
* {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
|
349
|
* object.
|
350
|
*/
|
351
|
public static ICdmRepository getCurrentApplicationConfiguration() {
|
352
|
if (getDefault() != null) {
|
353
|
return getDefault().getApplicationConfiguration();
|
354
|
}
|
355
|
return null;
|
356
|
}
|
357
|
|
358
|
/*
|
359
|
* CONVERSATIONS
|
360
|
*/
|
361
|
|
362
|
/**
|
363
|
* Creates a new conversation, binds resources to the conversation and start
|
364
|
* a transaction for this conversation.
|
365
|
*
|
366
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
367
|
* object.
|
368
|
*/
|
369
|
public static ConversationHolder createConversation() {
|
370
|
ConversationHolder conversation = getCurrentApplicationConfiguration()
|
371
|
.NewConversation();
|
372
|
try {
|
373
|
conversation.startTransaction();
|
374
|
}catch(Exception e){
|
375
|
MessagingUtils.messageDialog("No database connection", CdmStore.class, "No database connection available", e);
|
376
|
}
|
377
|
return conversation;
|
378
|
}
|
379
|
|
380
|
//FIXME:Remoting should be removed after moving completely to remoting
|
381
|
private MockCdmEntitySessionManager mockCdmEntitySessionManager;
|
382
|
|
383
|
private ICdmEntitySessionManager getSessionManager() {
|
384
|
//FIXME:Remoting we should only have CdmApplicationRemoteConfiguration after move to remoting
|
385
|
// bad hack which should be finally removed
|
386
|
if(getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteController) {
|
387
|
return ((CdmApplicationRemoteController)getCurrentApplicationConfiguration()).getCdmEntitySessionManager();
|
388
|
} else {
|
389
|
if(mockCdmEntitySessionManager == null) {
|
390
|
mockCdmEntitySessionManager = new MockCdmEntitySessionManager();
|
391
|
}
|
392
|
return mockCdmEntitySessionManager;
|
393
|
}
|
394
|
}
|
395
|
public static ICdmEntitySessionManager getCurrentSessionManager() {
|
396
|
return getCurrentSessionManager(false);
|
397
|
}
|
398
|
|
399
|
|
400
|
public static ICdmEntitySessionManager getCurrentSessionManager(boolean connecting) {
|
401
|
if (getDefault(connecting) != null) {
|
402
|
return getDefault(connecting).getSessionManager();
|
403
|
}
|
404
|
return null;
|
405
|
|
406
|
}
|
407
|
|
408
|
/**
|
409
|
* Generic method that will scan the getters of {@link ICdmRepository} for the given service
|
410
|
* interface. If a matching getter is found the according service implementation is returned by
|
411
|
* invoking the getter otherwise the method returns <code>null</code>.
|
412
|
*
|
413
|
* @param <T>
|
414
|
* @param serviceClass
|
415
|
* @return the configured implementation of <code>serviceClass</code> or <code>null</code>
|
416
|
*/
|
417
|
public static <T extends IService> T getService(Class<T> serviceClass) {
|
418
|
T service = null;
|
419
|
try {
|
420
|
service = CdmApplicationState.getService(serviceClass);
|
421
|
} catch (CdmApplicationException cae) {
|
422
|
MessagingUtils.error(CdmStore.class, cae);
|
423
|
}
|
424
|
|
425
|
return service;
|
426
|
}
|
427
|
|
428
|
/**
|
429
|
* @see #getService(Class)
|
430
|
* As ICommonService is not extending IService we need a specific request here
|
431
|
*/
|
432
|
public static ICommonService getCommonService() {
|
433
|
return CdmApplicationState.getCommonService();
|
434
|
|
435
|
}
|
436
|
|
437
|
/**
|
438
|
* <p>
|
439
|
* getAuthenticationManager
|
440
|
* </p>
|
441
|
*
|
442
|
* @return a
|
443
|
* {@link org.springframework.security.authentication.ProviderManager}
|
444
|
* object.
|
445
|
*/
|
446
|
public static AuthenticationManager getAuthenticationManager() {
|
447
|
return getCurrentApplicationConfiguration().getAuthenticationManager();
|
448
|
}
|
449
|
|
450
|
/**
|
451
|
* <p>
|
452
|
* getAuthenticationManager
|
453
|
* </p>
|
454
|
*
|
455
|
* @return a
|
456
|
* {@link ICdmPermissionEvaluator} object.
|
457
|
*/
|
458
|
public static ICdmPermissionEvaluator getPermissionEvaluator() {
|
459
|
return getCurrentApplicationConfiguration().getPermissionEvaluator();
|
460
|
}
|
461
|
|
462
|
|
463
|
/*
|
464
|
* SECURITY RELATED CONVENIENCE METHODS
|
465
|
*/
|
466
|
|
467
|
/**
|
468
|
* @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
|
469
|
*
|
470
|
* @param targetDomainObject
|
471
|
* @param permission
|
472
|
* @return
|
473
|
*/
|
474
|
public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
|
475
|
//TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
|
476
|
SecurityContext context = SecurityContextHolder.getContext();
|
477
|
PermissionEvaluator pe = getPermissionEvaluator();
|
478
|
boolean hasPermission = false;
|
479
|
try {
|
480
|
hasPermission = getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject,
|
481
|
permission);
|
482
|
} catch (org.springframework.security.access.AccessDeniedException e) {
|
483
|
/* IGNORE */
|
484
|
}
|
485
|
return hasPermission;
|
486
|
}
|
487
|
|
488
|
/**
|
489
|
* @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
|
490
|
*
|
491
|
* @param targetDomainObject
|
492
|
* @param permission
|
493
|
* @return
|
494
|
*/
|
495
|
public static boolean currentAuthentiationHasPermission(Class<? extends CdmBase> targetType, EnumSet<CRUD> permission){
|
496
|
boolean hasPermission = false;
|
497
|
try {
|
498
|
hasPermission = getPermissionEvaluator().hasPermission(getCurrentAuthentiation(), null, targetType.getName(), permission);
|
499
|
} catch (org.springframework.security.access.AccessDeniedException e) {
|
500
|
/* IGNORE */
|
501
|
}
|
502
|
return hasPermission;
|
503
|
}
|
504
|
|
505
|
public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
|
506
|
boolean hasPermission = false;
|
507
|
try {
|
508
|
hasPermission = getPermissionEvaluator().hasOneOfRoles(getCurrentAuthentiation(), roles);
|
509
|
} catch (org.springframework.security.access.AccessDeniedException e) {
|
510
|
/* IGNORE */
|
511
|
}
|
512
|
return hasPermission;
|
513
|
}
|
514
|
|
515
|
public static Authentication getCurrentAuthentiation() {
|
516
|
SecurityContext context = SecurityContextHolder.getContext();
|
517
|
return context.getAuthentication();
|
518
|
}
|
519
|
|
520
|
/*
|
521
|
* LANGUAGE
|
522
|
*/
|
523
|
|
524
|
/**
|
525
|
* Provides access to the global default language set in the application preferences.
|
526
|
*
|
527
|
* @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
|
528
|
*/
|
529
|
public static Language getDefaultLanguage() {
|
530
|
if (getDefault().getLanguage() == null) {
|
531
|
getDefault().setLanguage(PreferencesUtil.getGlobalLanguage());
|
532
|
}
|
533
|
return getDefault().getLanguage();
|
534
|
}
|
535
|
|
536
|
/**
|
537
|
* <p>
|
538
|
* setDefaultLanguage
|
539
|
* </p>
|
540
|
*
|
541
|
* @param language
|
542
|
* a {@link eu.etaxonomy.cdm.model.common.Language} object.
|
543
|
*/
|
544
|
public static void setDefaultLanguage(Language language) {
|
545
|
getDefault().setLanguage(language);
|
546
|
}
|
547
|
|
548
|
/**
|
549
|
* @return the language
|
550
|
*/
|
551
|
private Language getLanguage() {
|
552
|
return language;
|
553
|
}
|
554
|
|
555
|
/**
|
556
|
* @param language
|
557
|
* the language to set
|
558
|
*/
|
559
|
private void setLanguage(Language language) {
|
560
|
this.language = language;
|
561
|
}
|
562
|
|
563
|
/*
|
564
|
* LOGIN
|
565
|
*/
|
566
|
|
567
|
/**
|
568
|
* <p>
|
569
|
* Getter for the field <code>loginManager</code>.
|
570
|
* </p>
|
571
|
*
|
572
|
* @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
|
573
|
*/
|
574
|
public static LoginManager getLoginManager() {
|
575
|
return loginManager;
|
576
|
}
|
577
|
|
578
|
/**
|
579
|
* <p>
|
580
|
* Getter for the field <code>contextManager</code>.
|
581
|
* </p>
|
582
|
*
|
583
|
* @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
|
584
|
*/
|
585
|
public static ContextManager getContextManager() {
|
586
|
return contextManager;
|
587
|
}
|
588
|
|
589
|
public static TermManager getTermManager() {
|
590
|
return termManager;
|
591
|
}
|
592
|
|
593
|
public static SearchManager getSearchManager() {
|
594
|
return searchManager;
|
595
|
}
|
596
|
|
597
|
public static EditorManager getEditorManager() {
|
598
|
return editorManager;
|
599
|
}
|
600
|
|
601
|
public static ProgressMonitorClientManager getProgressMonitorClientManager() {
|
602
|
return progressMonitorClientManager;
|
603
|
}
|
604
|
|
605
|
/*
|
606
|
* IMPORT/EXPORT FACTORIES
|
607
|
*/
|
608
|
|
609
|
/**
|
610
|
* <p>
|
611
|
* Getter for the field <code>importHandler</code>.
|
612
|
* </p>
|
613
|
*
|
614
|
* @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
|
615
|
*/
|
616
|
public static ImportManager getImportManager() {
|
617
|
return ImportManager.NewInstance(getCurrentApplicationConfiguration());
|
618
|
}
|
619
|
|
620
|
/**
|
621
|
* <p>
|
622
|
* Getter for the field <code>exportHandler</code>.
|
623
|
* </p>
|
624
|
*
|
625
|
* @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
|
626
|
*/
|
627
|
public static ExportManager getExportManager() {
|
628
|
return ExportManager.NewInstance(getCurrentApplicationConfiguration());
|
629
|
}
|
630
|
|
631
|
/**
|
632
|
* Whether this CdmStore is currently connected to a datasource
|
633
|
*
|
634
|
* @return a boolean.
|
635
|
*/
|
636
|
public static boolean isActive() {
|
637
|
return instance != null && instance.isConnected;
|
638
|
}
|
639
|
|
640
|
public static ICdmSource getActiveCdmSource() {
|
641
|
if (isActive()) {
|
642
|
return instance.getCdmSource();
|
643
|
}
|
644
|
return null;
|
645
|
}
|
646
|
|
647
|
/**
|
648
|
* <p>
|
649
|
* getDataSource
|
650
|
* </p>
|
651
|
*
|
652
|
* @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
|
653
|
* @deprecated currently retained for backward compatibility - use {@link getActiveCdmSource()} instead
|
654
|
*/
|
655
|
// public static ICdmDataSource getDataSource() {
|
656
|
// if (isActive()) {
|
657
|
// return (ICdmDataSource)instance.getCdmSource();
|
658
|
// }
|
659
|
// return null;
|
660
|
// }
|
661
|
|
662
|
/**
|
663
|
* @return
|
664
|
*/
|
665
|
private ICdmSource getCdmSource() {
|
666
|
return cdmSource;
|
667
|
}
|
668
|
|
669
|
|
670
|
public static <T extends CdmBase> IService<T> getService(T cdmBase){
|
671
|
IService<T> service = null;
|
672
|
if(cdmBase!=null){
|
673
|
//get corresponding service
|
674
|
if(cdmBase.isInstanceOf(Reference.class)){
|
675
|
service = (IService<T>) getService(IReferenceService.class);
|
676
|
}
|
677
|
else if (cdmBase.isInstanceOf(AgentBase.class)){
|
678
|
service = (IService<T>) getService(IAgentService.class);
|
679
|
}
|
680
|
else if (cdmBase instanceof TaxonName) {
|
681
|
service = (IService<T>) getService(INameService.class);
|
682
|
}
|
683
|
else if (cdmBase instanceof TaxonBase) {
|
684
|
service = (IService<T>) getService(ITaxonService.class);
|
685
|
}
|
686
|
else if (cdmBase instanceof SpecimenOrObservationBase) {
|
687
|
service = (IService<T>) getService(IOccurrenceService.class);
|
688
|
}
|
689
|
else if (cdmBase instanceof Media) {
|
690
|
service = (IService<T>) getService(IMediaService.class);
|
691
|
}
|
692
|
else if (cdmBase instanceof Collection) {
|
693
|
service = (IService<T>) getService(ICollectionService.class);
|
694
|
}
|
695
|
else if (cdmBase instanceof User) {
|
696
|
service = (IService<T>) getService(IUserService.class);
|
697
|
}
|
698
|
else if (cdmBase instanceof Group) {
|
699
|
service = (IService<T>) getService(IGroupService.class);
|
700
|
}
|
701
|
else if (cdmBase instanceof WorkingSet) {
|
702
|
service = (IService<T>) getService(IWorkingSetService.class);
|
703
|
}
|
704
|
else if (cdmBase instanceof TermVocabulary<?>) {
|
705
|
service = (IService<T>) getService(IVocabularyService.class);
|
706
|
}
|
707
|
else if (cdmBase instanceof DefinedTermBase<?>) {
|
708
|
service = (IService<T>) getService(ITermService.class);
|
709
|
}
|
710
|
else if (cdmBase instanceof Primer) {
|
711
|
service = (IService<T>) getService(IPrimerService.class);
|
712
|
}
|
713
|
else if (cdmBase instanceof Amplification) {
|
714
|
service = (IService<T>) getService(IAmplificationService.class);
|
715
|
}
|
716
|
else if (cdmBase instanceof PolytomousKey) {
|
717
|
service = (IService<T>) getService(IPolytomousKeyService.class);
|
718
|
}
|
719
|
else if (cdmBase instanceof PolytomousKeyNode) {
|
720
|
service = (IService<T>) getService(IPolytomousKeyNodeService.class);
|
721
|
}
|
722
|
else if (cdmBase instanceof Annotation) {
|
723
|
service = (IService<T>) getService(IAnnotationService.class);
|
724
|
}
|
725
|
else if (cdmBase instanceof Classification) {
|
726
|
service = (IService<T>) getService(IClassificationService.class);
|
727
|
}
|
728
|
else if (cdmBase instanceof DescriptionBase<?>) {
|
729
|
service = (IService<T>) getService(IDescriptionService.class);
|
730
|
}
|
731
|
else if (cdmBase instanceof EntityConstraintViolation) {
|
732
|
service = (IService<T>) getService(IEntityConstraintViolationService.class);
|
733
|
}
|
734
|
else if (cdmBase instanceof EntityValidation) {
|
735
|
service = (IService<T>) getService(IEntityValidationService.class);
|
736
|
}
|
737
|
else if (cdmBase instanceof FeatureNode) {
|
738
|
service = (IService<T>) getService(IFeatureNodeService.class);
|
739
|
}
|
740
|
else if (cdmBase instanceof FeatureTree) {
|
741
|
service = (IService<T>) getService(IFeatureTreeService.class);
|
742
|
}
|
743
|
else if (cdmBase instanceof GrantedAuthority) {
|
744
|
service = (IService<T>) getService(IGrantedAuthorityService.class);
|
745
|
}
|
746
|
else if (cdmBase instanceof Marker) {
|
747
|
service = (IService<T>) getService(IMarkerService.class);
|
748
|
}
|
749
|
else if (cdmBase instanceof Registration) {
|
750
|
service = (IService<T>) getService(IRegistrationService.class);
|
751
|
}
|
752
|
else if (cdmBase instanceof Rights) {
|
753
|
service = (IService<T>) getService(IRightsService.class);
|
754
|
}
|
755
|
// else if (cdmBase instanceof AuditEvent) {
|
756
|
// service = (IService<T>) getService(IAuditEventService.class);
|
757
|
// }
|
758
|
// else if (cdmBase instanceof CdmPreference) {
|
759
|
// service = (IService<T>) getService(IPreferenceService.class);
|
760
|
// }
|
761
|
else{
|
762
|
String message = "Service for entity of class %s not yet implemented in TaxEditor";
|
763
|
message = String.format(message, cdmBase.getClass().getSimpleName());
|
764
|
throw new RuntimeException(message);
|
765
|
}
|
766
|
}
|
767
|
return service;
|
768
|
}
|
769
|
|
770
|
public static void setManagedServer(CDMServer server) {
|
771
|
managedServer = server;
|
772
|
}
|
773
|
|
774
|
public static CDMServer getManagedServer() {
|
775
|
return managedServer;
|
776
|
}
|
777
|
|
778
|
}
|