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