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