1 |
e8409423
|
n.hoffmann
|
/**
|
2 |
eed65ec6
|
n.hoffmann
|
* Copyright (C) 2007 EDIT
|
3 |
fcbc1c42
|
Andreas Kohlbecker
|
* European Distributed Institute of Taxonomy
|
4 |
eed65ec6
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
fcbc1c42
|
Andreas Kohlbecker
|
*
|
6 |
eed65ec6
|
n.hoffmann
|
* 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 |
e8409423
|
n.hoffmann
|
|
10 |
|
|
package eu.etaxonomy.taxeditor.store;
|
11 |
|
|
|
12 |
63e1618b
|
Andreas Kohlbecker
|
import java.util.EnumSet;
|
13 |
db5e366d
|
n.hoffmann
|
|
14 |
5b9cdd56
|
Katja Luther
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15 |
143e2f91
|
n.hoffmann
|
import org.eclipse.core.runtime.jobs.Job;
|
16 |
|
|
import org.eclipse.swt.widgets.Display;
|
17 |
c23bc5b0
|
Katja Luther
|
import org.slf4j.Marker;
|
18 |
9da44030
|
n.hoffmann
|
import org.springframework.core.io.ClassPathResource;
|
19 |
|
|
import org.springframework.core.io.Resource;
|
20 |
63e1618b
|
Andreas Kohlbecker
|
import org.springframework.security.access.PermissionEvaluator;
|
21 |
95b6f6f5
|
Cherian Mathew
|
import org.springframework.security.authentication.AuthenticationManager;
|
22 |
45716169
|
Andreas Kohlbecker
|
import org.springframework.security.core.Authentication;
|
23 |
b2e81e61
|
Andreas Müller
|
import org.springframework.security.core.GrantedAuthority;
|
24 |
63e1618b
|
Andreas Kohlbecker
|
import org.springframework.security.core.context.SecurityContext;
|
25 |
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
26 |
c23bc5b0
|
Katja Luther
|
|
27 |
ae7e2680
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.application.CdmApplicationException;
|
28 |
c53a25ad
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
|
29 |
04f2494e
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
30 |
2da9ade2
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
31 |
f4f5cd63
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
|
32 |
e8409423
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
33 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
34 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IAnnotationService;
|
35 |
|
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
36 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.ICollectionService;
|
37 |
0219b768
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
38 |
b2e81e61
|
Andreas Müller
|
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 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.INameService;
|
48 |
|
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
49 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
50 |
2387a634
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
51 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
52 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
53 |
|
|
import eu.etaxonomy.cdm.api.service.IRightsService;
|
54 |
db5e366d
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.service.IService;
|
55 |
a6fc1476
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
56 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
57 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
58 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
59 |
652496d7
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
|
60 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
|
61 |
|
|
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
|
62 |
26b93df0
|
Katja Luther
|
import eu.etaxonomy.cdm.cache.CdmRemoteCacheManager;
|
63 |
9bd84319
|
Cherian Mathew
|
import eu.etaxonomy.cdm.config.ICdmSource;
|
64 |
e8409423
|
n.hoffmann
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
65 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
66 |
5b9cdd56
|
Katja Luther
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
67 |
63e1618b
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
68 |
b9dc6bb1
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
69 |
5b9cdd56
|
Katja Luther
|
import eu.etaxonomy.cdm.model.common.Group;
|
70 |
3717e93f
|
Katja Luther
|
import eu.etaxonomy.cdm.model.common.Language;
|
71 |
b9dc6bb1
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
72 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
73 |
19ff6869
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.term.FeatureNode;
|
74 |
|
|
import eu.etaxonomy.cdm.model.term.FeatureTree;
|
75 |
2387a634
|
Katja Luther
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
76 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
77 |
652496d7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
78 |
5b9cdd56
|
Katja Luther
|
import eu.etaxonomy.cdm.model.media.Media;
|
79 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.media.Rights;
|
80 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.molecular.Amplification;
|
81 |
|
|
import eu.etaxonomy.cdm.model.molecular.Primer;
|
82 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.Registration;
|
83 |
e3a4a3ff
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
84 |
5b9cdd56
|
Katja Luther
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
85 |
a0af0095
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
86 |
5b9cdd56
|
Katja Luther
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
87 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
88 |
a6fc1476
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
89 |
b2e81e61
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.validation.EntityConstraintViolation;
|
90 |
|
|
import eu.etaxonomy.cdm.model.validation.EntityValidation;
|
91 |
63e1618b
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
92 |
4eb57b3c
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
|
93 |
258a236f
|
Katja Luther
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
94 |
9766a939
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
|
95 |
db5e366d
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.io.ExportManager;
|
96 |
|
|
import eu.etaxonomy.taxeditor.io.ImportManager;
|
97 |
41e2f693
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
98 |
ea781c57
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
99 |
c53a25ad
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
|
100 |
|
|
import eu.etaxonomy.taxeditor.session.mock.MockCdmEntitySessionManager;
|
101 |
9da44030
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
102 |
19c39bf4
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
|
103 |
93590159
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.util.ProgressMonitorClientManager;
|
104 |
7a96337f
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.webapp.CDMServer;
|
105 |
e8409423
|
n.hoffmann
|
|
106 |
|
|
/**
|
107 |
eed65ec6
|
n.hoffmann
|
* 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 |
fcbc1c42
|
Andreas Kohlbecker
|
*
|
111 |
eed65ec6
|
n.hoffmann
|
* 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 |
fcbc1c42
|
Andreas Kohlbecker
|
*
|
114 |
e8409423
|
n.hoffmann
|
* @author n.hoffmann
|
115 |
|
|
* @created 17.03.2009
|
116 |
|
|
* @version 1.0
|
117 |
|
|
*/
|
118 |
eed65ec6
|
n.hoffmann
|
public class CdmStore {
|
119 |
|
|
|
120 |
19c39bf4
|
Cherian Mathew
|
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 |
eed65ec6
|
n.hoffmann
|
|
125 |
19c39bf4
|
Cherian Mathew
|
private static CdmStore instance;
|
126 |
eed65ec6
|
n.hoffmann
|
|
127 |
2da9ade2
|
Andreas Kohlbecker
|
//private final ICdmRepository applicationConfiguration;
|
128 |
eed65ec6
|
n.hoffmann
|
|
129 |
19c39bf4
|
Cherian Mathew
|
private static ContextManager contextManager = new ContextManager();
|
130 |
eed65ec6
|
n.hoffmann
|
|
131 |
19c39bf4
|
Cherian Mathew
|
private static LoginManager loginManager = new LoginManager();
|
132 |
eed65ec6
|
n.hoffmann
|
|
133 |
19c39bf4
|
Cherian Mathew
|
private static TermManager termManager = new TermManager();
|
134 |
eed65ec6
|
n.hoffmann
|
|
135 |
19c39bf4
|
Cherian Mathew
|
private static SearchManager searchManager = new SearchManager();
|
136 |
eed65ec6
|
n.hoffmann
|
|
137 |
19c39bf4
|
Cherian Mathew
|
private static EditorManager editorManager = new EditorManager();
|
138 |
|
|
|
139 |
|
|
private static UseObjectStore useObjectInitializer = new UseObjectStore();
|
140 |
|
|
|
141 |
93590159
|
Cherian Mathew
|
private static ProgressMonitorClientManager progressMonitorClientManager = new ProgressMonitorClientManager();
|
142 |
|
|
|
143 |
19c39bf4
|
Cherian Mathew
|
private static CdmStoreConnector job;
|
144 |
|
|
|
145 |
7a96337f
|
Cherian Mathew
|
private static CDMServer managedServer;
|
146 |
|
|
|
147 |
19c39bf4
|
Cherian Mathew
|
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 |
0bd095d9
|
Katja Luther
|
protected static CdmStore getDefault(boolean connecting){
|
163 |
19c39bf4
|
Cherian Mathew
|
if (instance != null && instance.isConnected) {
|
164 |
|
|
return instance;
|
165 |
|
|
} else{// if (instance == null || !instance.isConnected) {
|
166 |
0bd095d9
|
Katja Luther
|
if (connecting){
|
167 |
|
|
MessagingUtils.dataSourceNotAvailableWarningDialog(instance);
|
168 |
|
|
}else{
|
169 |
|
|
MessagingUtils.noDataSourceWarningDialog(instance);
|
170 |
|
|
}
|
171 |
af45abb8
|
Katja Luther
|
|
172 |
19c39bf4
|
Cherian Mathew
|
|
173 |
|
|
return null;
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
0bd095d9
|
Katja Luther
|
/**
|
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 |
19c39bf4
|
Cherian Mathew
|
|
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 |
1b626d51
|
Cherian Mathew
|
RemotingLoginDialog remotingLoginDialog) {
|
247 |
|
|
RemotingLoginDialog loginDialog = remotingLoginDialog;
|
248 |
19c39bf4
|
Cherian Mathew
|
if(isActive()) {
|
249 |
|
|
// before we connect we clear the entity caches and the sessions
|
250 |
26b93df0
|
Katja Luther
|
CdmRemoteCacheManager.removeEntityCaches();
|
251 |
0bd095d9
|
Katja Luther
|
if(getCurrentSessionManager(true) != null) {
|
252 |
|
|
getCurrentSessionManager(true).disposeAll();
|
253 |
19c39bf4
|
Cherian Mathew
|
}
|
254 |
|
|
}
|
255 |
cfb00eab
|
Cherian Mathew
|
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 |
19c39bf4
|
Cherian Mathew
|
}
|
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 |
b2e81e61
|
Andreas Müller
|
|
278 |
19c39bf4
|
Cherian Mathew
|
@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 |
2da9ade2
|
Andreas Kohlbecker
|
static void setInstance(ICdmRepository applicationController,
|
308 |
19c39bf4
|
Cherian Mathew
|
ICdmSource cdmSource) {
|
309 |
|
|
instance = new CdmStore(applicationController, cdmSource);
|
310 |
d85cfdf3
|
Katja Luther
|
CdmApplicationState.setCdmServiceCacher(new CdmServiceCacher());
|
311 |
af45abb8
|
Katja Luther
|
|
312 |
19c39bf4
|
Cherian Mathew
|
}
|
313 |
|
|
|
314 |
da948591
|
Katja Luther
|
private CdmStore(ICdmRepository repository,
|
315 |
19c39bf4
|
Cherian Mathew
|
ICdmSource cdmSource) {
|
316 |
da948591
|
Katja Luther
|
CdmApplicationState.setCurrentAppConfig(repository);
|
317 |
19c39bf4
|
Cherian Mathew
|
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 |
2da9ade2
|
Andreas Kohlbecker
|
private ICdmRepository getApplicationConfiguration() {
|
328 |
19c39bf4
|
Cherian Mathew
|
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 |
2da9ade2
|
Andreas Kohlbecker
|
public static ICdmRepository getCurrentApplicationConfiguration() {
|
346 |
19c39bf4
|
Cherian Mathew
|
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 |
63e1618b
|
Andreas Kohlbecker
|
*
|
360 |
19c39bf4
|
Cherian Mathew
|
* @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 |
0bd095d9
|
Katja Luther
|
return getCurrentSessionManager(false);
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
public static ICdmEntitySessionManager getCurrentSessionManager(boolean connecting) {
|
395 |
|
|
if (getDefault(connecting) != null) {
|
396 |
|
|
return getDefault(connecting).getSessionManager();
|
397 |
19c39bf4
|
Cherian Mathew
|
}
|
398 |
|
|
return null;
|
399 |
|
|
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
/**
|
403 |
2da9ade2
|
Andreas Kohlbecker
|
* Generic method that will scan the getters of {@link ICdmRepository} for the given service
|
404 |
19c39bf4
|
Cherian Mathew
|
* 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 |
fcbc1c42
|
Andreas Kohlbecker
|
hasPermission = getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject,
|
475 |
|
|
permission);
|
476 |
|
|
} catch (org.springframework.security.access.AccessDeniedException e) {
|
477 |
|
|
/* IGNORE */
|
478 |
|
|
}
|
479 |
|
|
return hasPermission;
|
480 |
19c39bf4
|
Cherian Mathew
|
}
|
481 |
eed65ec6
|
n.hoffmann
|
|
482 |
19c39bf4
|
Cherian Mathew
|
/**
|
483 |
|
|
* @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
|
484 |
5b850621
|
Andreas Kohlbecker
|
*
|
485 |
19c39bf4
|
Cherian Mathew
|
* @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 |
fcbc1c42
|
Andreas Kohlbecker
|
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 |
19c39bf4
|
Cherian Mathew
|
}
|
498 |
fcbc1c42
|
Andreas Kohlbecker
|
|
499 |
19c39bf4
|
Cherian Mathew
|
public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
|
500 |
|
|
boolean hasPermission = false;
|
501 |
fcbc1c42
|
Andreas Kohlbecker
|
try {
|
502 |
|
|
hasPermission = getPermissionEvaluator().hasOneOfRoles(getCurrentAuthentiation(), roles);
|
503 |
|
|
} catch (org.springframework.security.access.AccessDeniedException e) {
|
504 |
|
|
/* IGNORE */
|
505 |
|
|
}
|
506 |
|
|
return hasPermission;
|
507 |
19c39bf4
|
Cherian Mathew
|
}
|
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 |
93590159
|
Cherian Mathew
|
public static ProgressMonitorClientManager getProgressMonitorClientManager() {
|
596 |
|
|
return progressMonitorClientManager;
|
597 |
|
|
}
|
598 |
|
|
|
599 |
19c39bf4
|
Cherian Mathew
|
/*
|
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 |
f211dd28
|
n.hoffmann
|
|
663 |
7a96337f
|
Cherian Mathew
|
|
664 |
a0af0095
|
Patrick Plitzner
|
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 |
e3a4a3ff
|
Andreas Müller
|
else if (cdmBase instanceof TaxonName) {
|
675 |
a0af0095
|
Patrick Plitzner
|
service = (IService<T>) getService(INameService.class);
|
676 |
|
|
}
|
677 |
a6fc1476
|
Patrick Plitzner
|
else if (cdmBase instanceof TaxonBase) {
|
678 |
|
|
service = (IService<T>) getService(ITaxonService.class);
|
679 |
|
|
}
|
680 |
a0af0095
|
Patrick Plitzner
|
else if (cdmBase instanceof SpecimenOrObservationBase) {
|
681 |
|
|
service = (IService<T>) getService(IOccurrenceService.class);
|
682 |
|
|
}
|
683 |
b2e81e61
|
Andreas Müller
|
else if (cdmBase instanceof Media) {
|
684 |
|
|
service = (IService<T>) getService(IMediaService.class);
|
685 |
|
|
}
|
686 |
a0af0095
|
Patrick Plitzner
|
else if (cdmBase instanceof Collection) {
|
687 |
|
|
service = (IService<T>) getService(ICollectionService.class);
|
688 |
|
|
}
|
689 |
5b9cdd56
|
Katja Luther
|
else if (cdmBase instanceof eu.etaxonomy.cdm.model.common.User) {
|
690 |
a0af0095
|
Patrick Plitzner
|
service = (IService<T>) getService(IUserService.class);
|
691 |
|
|
}
|
692 |
b2e81e61
|
Andreas Müller
|
else if (cdmBase instanceof Group) {
|
693 |
|
|
service = (IService<T>) getService(IGroupService.class);
|
694 |
|
|
}
|
695 |
652496d7
|
Andreas Müller
|
else if (cdmBase instanceof DescriptiveDataSet) {
|
696 |
|
|
service = (IService<T>) getService(IDescriptiveDataSetService.class);
|
697 |
b2e81e61
|
Andreas Müller
|
}
|
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 |
a0af0095
|
Patrick Plitzner
|
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 |
803c3b8e
|
Katja Luther
|
}
|
710 |
b2e81e61
|
Andreas Müller
|
else if (cdmBase instanceof PolytomousKey) {
|
711 |
2387a634
|
Katja Luther
|
service = (IService<T>) getService(IPolytomousKeyService.class);
|
712 |
a0af0095
|
Patrick Plitzner
|
}
|
713 |
b2e81e61
|
Andreas Müller
|
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 |
a0af0095
|
Patrick Plitzner
|
}
|
755 |
|
|
return service;
|
756 |
|
|
}
|
757 |
|
|
|
758 |
7a96337f
|
Cherian Mathew
|
public static void setManagedServer(CDMServer server) {
|
759 |
|
|
managedServer = server;
|
760 |
|
|
}
|
761 |
|
|
|
762 |
|
|
public static CDMServer getManagedServer() {
|
763 |
|
|
return managedServer;
|
764 |
|
|
}
|
765 |
|
|
|
766 |
e8409423
|
n.hoffmann
|
}
|