Project

General

Profile

« Previous | Next » 

Revision 19c39bf4

Added by Cherian Mathew over 8 years ago

#5029 Implement oneclick login for remoting

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java
175 175
        }
176 176
        progressMonitor.worked(1);
177 177

  
178
        progressMonitor.subTask("Starting context ...");
178
        progressMonitor.subTask("Starting application context ...");
179 179
        applicationContext.refresh();
180 180
        applicationContext.start();
181 181
        setApplicationContext(applicationContext);
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmRemoteSourceBase.java
161 161
	 */
162 162
	@Override
163 163
	public String getConnectionMessage() {
164
		return "Conncting to Remote CDM Server " + getName();
164
		return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
165 165
	}
166 166

  
167 167

  
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java
391 391
		if(cdmEntitySession != null) {
392 392
		    cdmEntitySession.dispose();
393 393
		}
394
		CdmApplicationState.getCurrentDataChangeService().unregister(this);
394
		if(CdmApplicationState.getCurrentDataChangeService() != null) {
395
		    CdmApplicationState.getCurrentDataChangeService().unregister(this);
396
		}
395 397
	}
396 398

  
397 399
	/*
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmAuthenticationException.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.store;
11

  
12
/**
13
 * @author cmathew
14
 * @date 24 Jul 2015
15
 *
16
 */
17
public class CdmAuthenticationException extends RuntimeException {
18

  
19
    public CdmAuthenticationException(String message, Throwable t) {
20
        super(message,t);
21
    }
22

  
23
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
47 47
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
48 48
import eu.etaxonomy.taxeditor.session.mock.MockCdmEntitySessionManager;
49 49
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
50
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
50 51
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
51 52

  
52 53
/**
......
63 64
 */
64 65
public class CdmStore {
65 66

  
66
	private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
67
			"/eu/etaxonomy/cdm/editorApplicationContext.xml",
68
			TaxeditorStorePlugin.class);
69
	private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE;
67
    private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
68
            "/eu/etaxonomy/cdm/editorApplicationContext.xml",
69
            TaxeditorStorePlugin.class);
70
    private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE;
70 71

  
71
	private static CdmStore instance;
72
    private static CdmStore instance;
72 73

  
73
	//private final ICdmApplicationConfiguration applicationConfiguration;
74
    //private final ICdmApplicationConfiguration applicationConfiguration;
74 75

  
75
	private static ContextManager contextManager = new ContextManager();
76
    private static ContextManager contextManager = new ContextManager();
76 77

  
77
	private static LoginManager loginManager = new LoginManager();
78
    private static LoginManager loginManager = new LoginManager();
78 79

  
79
	private static TermManager termManager = new TermManager();
80
    private static TermManager termManager = new TermManager();
80 81

  
81
	private static SearchManager searchManager = new SearchManager();
82
    private static SearchManager searchManager = new SearchManager();
82 83

  
83
	private static EditorManager editorManager = new EditorManager();
84

  
85
	private static UseObjectStore useObjectInitializer = new UseObjectStore();
86

  
87
	private static CdmStoreConnector job;
88

  
89
	private Language language;
90

  
91
	private ICdmSource cdmSource;
92

  
93
	private boolean isConnected;
94

  
95

  
96

  
97
	/**
98
	 * <p>
99
	 * getDefault
100
	 * </p>
101
	 *
102
	 * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
103
	 */
104
	protected static CdmStore getDefault() {
105
		if (instance != null && instance.isConnected) {
106
			return instance;
107
		} else{// if (instance == null || !instance.isConnected) {
108

  
109
			MessagingUtils.noDataSourceWarningDialog(instance);
110

  
111
			AbstractUtility.showView(CdmDataSourceViewPart.ID);
112
			return null;
113
		}
114
	}
115

  
116
	/**
117
	 * Initialize the with the last edited datasource
118
	 */
119
	public static void connect() {
120

  
121
		ICdmSource cdmSource;
122
		try {
123

  
124
			cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
125
			connect(cdmSource);
126
		} catch (Exception e) {
127
			MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
128
		}
129

  
130

  
131
	}
132

  
133
	/**
134
	 * Initialize with a specific datasource
135
	 *
136
	 * @param datasource
137
	 *            a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
138
	 */
139
	public static void connect(ICdmSource cdmSource) {
140
		connect(cdmSource, DEFAULT_DB_SCHEMA_VALIDATION,
141
				DEFAULT_APPLICATION_CONTEXT);
142
	}
143

  
144
	/**
145
	 * Initialize and provide
146
	 *
147
	 * @param datasource
148
	 * @param dbSchemaValidation
149
	 * @param applicationContextBean
150
	 */
151
	private static void connect(final ICdmSource cdmSource,
152
			final DbSchemaValidation dbSchemaValidation,
153
			final Resource applicationContextBean) {
154
	    if(isActive()) {
155
	        // before we connect we clear the entity caches and the sessions
156
	        CdmRemoteCacheManager.removeEntityCaches();
157
	        if(getCurrentSessionManager() != null) {
158
	            getCurrentSessionManager().disposeAll();
159
	        }
160
	    }
161
		MessagingUtils.info("Connecting to datasource: " + cdmSource);
162

  
163
		job = new CdmStoreConnector(Display.getDefault(), cdmSource,
164
				dbSchemaValidation, applicationContextBean);
165
		job.setUser(true);
166
		job.setPriority(Job.BUILD);
167
		job.schedule();
168

  
169
	}
170

  
171
	public static boolean isConnecting() {
172
		return job != null && job.getState() == Job.RUNNING;
173
	}
174

  
175
	/**
176
	 * Closes the current application context
177
	 *
178
	 * @param monitor
179
	 *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
180
	 */
181
	public static void close(final IProgressMonitor monitor) {
182
		Display.getDefault().asyncExec(new Runnable() {
183
			/*
184
			 * (non-Javadoc)
185
			 *
186
			 * @see java.lang.Runnable#run()
187
			 */
188
			@Override
189
			public void run() {
190
				getContextManager().notifyContextAboutToStop(monitor);
191
				if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
192
					getContextManager().notifyContextStop(monitor);
193
					instance.close();
194
				}
195
			}
196
		});
197
	}
198

  
199
	private void close() {
200
		isConnected = false;
201
		cdmSource = null;
202
		CdmApplicationState.dispose();
203
	}
204

  
205
	static void setInstance(ICdmApplicationConfiguration applicationController,
206
			ICdmSource cdmSource) {
207
		instance = new CdmStore(applicationController, cdmSource);
208
	}
209

  
210
	private CdmStore(ICdmApplicationConfiguration applicationController,
211
			ICdmSource cdmSource) {
212
		CdmApplicationState.setCurrentAppConfig(applicationController);
213
		CdmApplicationState.setCurrentDataChangeService(new CdmUIDataChangeService());
214
		this.cdmSource = cdmSource;
215
		isConnected = true;
216
	}
217

  
218
	/**
219
	 * All calls to the datastore require
220
	 *
221
	 * @return
222
	 */
223
	private ICdmApplicationConfiguration getApplicationConfiguration() {
224
		try {
225
			return CdmApplicationState.getCurrentAppConfig();
226
		} catch (Exception e) {
227
			MessagingUtils.error(CdmStore.class, e);
228
		}
229
		return null;
230
	}
231

  
232
	/**
233
	 * <p>
234
	 * getCurrentApplicationController
235
	 * </p>
236
	 *
237
	 * @return a
238
	 *         {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
239
	 *         object.
240
	 */
241
	public static ICdmApplicationConfiguration getCurrentApplicationConfiguration() {
242
		if (getDefault() != null) {
243
			return getDefault().getApplicationConfiguration();
244
		}
245
		return null;
246
	}
247

  
248
	/*
249
	 * CONVERSATIONS
250
	 */
251

  
252
	/**
253
	 * Creates a new conversation, binds resources to the conversation and start
254
	 * a transaction for this conversation.
255
	 *
256
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
257
	 *         object.
258
	 */
259
	public static ConversationHolder createConversation() {
260
		ConversationHolder conversation = getCurrentApplicationConfiguration()
261
				.NewConversation();
262
		try {
263
			conversation.startTransaction();
264
		}catch(Exception e){
265
			MessagingUtils.messageDialog("No database connection", CdmStore.class, "No database connection available", e);
266
		}
267
		return conversation;
268
	}
269

  
270
	//FIXME:Remoting should be removed after moving completely to remoting
271
	private MockCdmEntitySessionManager mockCdmEntitySessionManager;
272

  
273
	private ICdmEntitySessionManager getSessionManager() {
274
		//FIXME:Remoting we should only have CdmApplicationRemoteConfiguration after move to remoting
275
		//               bad hack which should be finally removed
276
		if(getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteController) {
277
			return ((CdmApplicationRemoteController)getCurrentApplicationConfiguration()).getCdmEntitySessionManager();
278
		} else {
279
			if(mockCdmEntitySessionManager == null) {
280
				mockCdmEntitySessionManager = new MockCdmEntitySessionManager();
281
			}
282
			return mockCdmEntitySessionManager;
283
		}
284
	}
285

  
286
	public static  ICdmEntitySessionManager getCurrentSessionManager() {
287
		if (getDefault() != null) {
288
			return getDefault().getSessionManager();
289
		}
290
		return null;
291

  
292
	}
293

  
294
	/**
295
	 * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service
296
	 * interface. If a matching getter is found the according service implementation is returned by
297
	 * invoking the getter otherwise the method returns <code>null</code>.
298
	 *
299
	 * @param <T>
300
	 * @param serviceClass
301
	 * @return the configured implementation of <code>serviceClass</code> or <code>null</code>
302
	 */
303
	public static <T extends IService> T getService(Class<T> serviceClass) {
304
	    T service = null;
305
	    try {
306
	        service = CdmApplicationState.getService(serviceClass);
307
	    } catch (CdmApplicationException cae) {
308
	        MessagingUtils.error(CdmStore.class, cae);
309
	    }
310

  
311
	    return service;
312
	}
313

  
314
	/**
315
	 * @see #getService(Class)
316
	 * As ICommonService is not extending IService we need a specific request here
317
	 */
318
	public static ICommonService getCommonService() {
319
		return CdmApplicationState.getCommonService();
320

  
321
	}
322

  
323
	/**
324
	 * <p>
325
	 * getAuthenticationManager
326
	 * </p>
327
	 *
328
	 * @return a
329
	 *         {@link org.springframework.security.authentication.ProviderManager}
330
	 *         object.
331
	 */
332
	public static AuthenticationManager getAuthenticationManager() {
333
		return getCurrentApplicationConfiguration().getAuthenticationManager();
334
	}
335

  
336
	/**
337
	 * <p>
338
	 * getAuthenticationManager
339
	 * </p>
340
	 *
341
	 * @return a
342
	 *         {@link ICdmPermissionEvaluator} object.
343
	 */
344
	public static ICdmPermissionEvaluator getPermissionEvaluator() {
345
		return getCurrentApplicationConfiguration().getPermissionEvaluator();
346
	}
347

  
348
	/**
349
	 * <p>
350
	 * getGeoService
351
	 * </p>
352
	 *
353
	 * @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object.
354
	 */
355
	public static IEditGeoService getGeoService() {
356
		return (IEditGeoService) getCurrentApplicationConfiguration().getBean(
357
				"editGeoService");
358
	}
359

  
360
	/*
361
	 * SECURITY RELATED CONVENIENCE METHODS
362
	 */
363

  
364
	/**
365
	 * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
84
    private static EditorManager editorManager = new EditorManager();
85

  
86
    private static UseObjectStore useObjectInitializer = new UseObjectStore();
87

  
88
    private static CdmStoreConnector job;
89

  
90
    private Language language;
91

  
92
    private ICdmSource cdmSource;
93

  
94
    private boolean isConnected;
95

  
96

  
97

  
98
    /**
99
     * <p>
100
     * getDefault
101
     * </p>
102
     *
103
     * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
104
     */
105
    protected static CdmStore getDefault() {
106
        if (instance != null && instance.isConnected) {
107
            return instance;
108
        } else{// if (instance == null || !instance.isConnected) {
109

  
110
            MessagingUtils.noDataSourceWarningDialog(instance);
111

  
112
            AbstractUtility.showView(CdmDataSourceViewPart.ID);
113
            return null;
114
        }
115
    }
116

  
117
    /**
118
     * Initialize the with the last edited datasource
119
     */
120
    public static void connect() {
121

  
122
        ICdmSource cdmSource;
123
        try {
124

  
125
            cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
126
            connect(cdmSource);
127
        } catch (Exception e) {
128
            MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
129
        }
130

  
131

  
132
    }
133

  
134
    /**
135
     * Initialize with a specific datasource
136
     *
137
     * @param datasource
138
     *            a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
139
     */
140
    public static void connect(ICdmSource cdmSource) {
141
        connect(cdmSource, DEFAULT_DB_SCHEMA_VALIDATION,
142
                DEFAULT_APPLICATION_CONTEXT);
143
    }
144

  
145
    public static void connect(ICdmSource cdmSource, RemotingLoginDialog loginDialog) {
146
        connect(cdmSource,
147
                DEFAULT_DB_SCHEMA_VALIDATION,
148
                DEFAULT_APPLICATION_CONTEXT,
149
                loginDialog);
150
    }
151

  
152
    /**
153
     * Initialize and provide
154
     *
155
     * @param datasource
156
     * @param dbSchemaValidation
157
     * @param applicationContextBean
158
     */
159
    private static void connect(final ICdmSource cdmSource,
160
            final DbSchemaValidation dbSchemaValidation,
161
            final Resource applicationContextBean) {
162

  
163
        MessagingUtils.info("Connecting to datasource: " + cdmSource);
164

  
165
        job = new CdmStoreConnector(Display.getDefault(), cdmSource,
166
                dbSchemaValidation, applicationContextBean);
167
        job.setUser(true);
168
        job.setPriority(Job.BUILD);
169
        job.schedule();
170

  
171
    }
172

  
173
    private static void connect(final ICdmSource cdmSource,
174
            final DbSchemaValidation dbSchemaValidation,
175
            final Resource applicationContextBean,
176
            RemotingLoginDialog loginDialog) {
177
        if(isActive()) {
178
            // before we connect we clear the entity caches and the sessions
179
            CdmRemoteCacheManager.removeEntityCaches();
180
            if(getCurrentSessionManager() != null) {
181
                getCurrentSessionManager().disposeAll();
182
            }
183
        }
184
        MessagingUtils.info("Connecting to datasource: " + cdmSource);
185
        job = new CdmStoreConnector(Display.getDefault(),
186
                cdmSource,
187
                dbSchemaValidation,
188
                applicationContextBean);
189
        job.start(loginDialog);
190
    }
191

  
192
    public static boolean isConnecting() {
193
        return job != null && job.getState() == Job.RUNNING;
194
    }
195

  
196
    /**
197
     * Closes the current application context
198
     *
199
     * @param monitor
200
     *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
201
     */
202
    public static void close(final IProgressMonitor monitor) {
203
        Display.getDefault().asyncExec(new Runnable() {
204
            /*
205
             * (non-Javadoc)
206
             *
207
             * @see java.lang.Runnable#run()
208
             */
209
            @Override
210
            public void run() {
211
                getContextManager().notifyContextAboutToStop(monitor);
212
                if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
213
                    getContextManager().notifyContextStop(monitor);
214
                    instance.close();
215
                }
216
            }
217
        });
218
    }
219

  
220
    public static void close(IProgressMonitor monitor, boolean async) {
221
        if(async) {
222
            close(monitor);
223
        } else {
224
            getContextManager().notifyContextAboutToStop(monitor);
225
            if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
226
                getContextManager().notifyContextStop(monitor);
227
                instance.close();
228
            }
229
        }
230

  
231
    }
232
    private void close() {
233
        isConnected = false;
234
        cdmSource = null;
235
        CdmApplicationState.dispose();
236
    }
237

  
238
    static void setInstance(ICdmApplicationConfiguration applicationController,
239
            ICdmSource cdmSource) {
240
        instance = new CdmStore(applicationController, cdmSource);
241
    }
242

  
243
    private CdmStore(ICdmApplicationConfiguration applicationController,
244
            ICdmSource cdmSource) {
245
        CdmApplicationState.setCurrentAppConfig(applicationController);
246
        CdmApplicationState.setCurrentDataChangeService(new CdmUIDataChangeService());
247
        this.cdmSource = cdmSource;
248
        isConnected = true;
249
    }
250

  
251
    /**
252
     * All calls to the datastore require
253
     *
254
     * @return
255
     */
256
    private ICdmApplicationConfiguration getApplicationConfiguration() {
257
        try {
258
            return CdmApplicationState.getCurrentAppConfig();
259
        } catch (Exception e) {
260
            MessagingUtils.error(CdmStore.class, e);
261
        }
262
        return null;
263
    }
264

  
265
    /**
266
     * <p>
267
     * getCurrentApplicationController
268
     * </p>
269
     *
270
     * @return a
271
     *         {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
272
     *         object.
273
     */
274
    public static ICdmApplicationConfiguration getCurrentApplicationConfiguration() {
275
        if (getDefault() != null) {
276
            return getDefault().getApplicationConfiguration();
277
        }
278
        return null;
279
    }
280

  
281
    /*
282
     * CONVERSATIONS
283
     */
284

  
285
    /**
286
     * Creates a new conversation, binds resources to the conversation and start
287
     * a transaction for this conversation.
366 288
     *
367
	 * @param targetDomainObject
368
	 * @param permission
369
	 * @return
370
	 */
371
	public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
372
		//TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
373
		SecurityContext context = SecurityContextHolder.getContext();
374
		PermissionEvaluator pe = getPermissionEvaluator();
375
		boolean hasPermission = false;
376
		try {
289
     * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
290
     *         object.
291
     */
292
    public static ConversationHolder createConversation() {
293
        ConversationHolder conversation = getCurrentApplicationConfiguration()
294
                .NewConversation();
295
        try {
296
            conversation.startTransaction();
297
        }catch(Exception e){
298
            MessagingUtils.messageDialog("No database connection", CdmStore.class, "No database connection available", e);
299
        }
300
        return conversation;
301
    }
302

  
303
    //FIXME:Remoting should be removed after moving completely to remoting
304
    private MockCdmEntitySessionManager mockCdmEntitySessionManager;
305

  
306
    private ICdmEntitySessionManager getSessionManager() {
307
        //FIXME:Remoting we should only have CdmApplicationRemoteConfiguration after move to remoting
308
        //               bad hack which should be finally removed
309
        if(getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteController) {
310
            return ((CdmApplicationRemoteController)getCurrentApplicationConfiguration()).getCdmEntitySessionManager();
311
        } else {
312
            if(mockCdmEntitySessionManager == null) {
313
                mockCdmEntitySessionManager = new MockCdmEntitySessionManager();
314
            }
315
            return mockCdmEntitySessionManager;
316
        }
317
    }
318

  
319
    public static  ICdmEntitySessionManager getCurrentSessionManager() {
320
        if (getDefault() != null) {
321
            return getDefault().getSessionManager();
322
        }
323
        return null;
324

  
325
    }
326

  
327
    /**
328
     * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service
329
     * interface. If a matching getter is found the according service implementation is returned by
330
     * invoking the getter otherwise the method returns <code>null</code>.
331
     *
332
     * @param <T>
333
     * @param serviceClass
334
     * @return the configured implementation of <code>serviceClass</code> or <code>null</code>
335
     */
336
    public static <T extends IService> T getService(Class<T> serviceClass) {
337
        T service = null;
338
        try {
339
            service = CdmApplicationState.getService(serviceClass);
340
        } catch (CdmApplicationException cae) {
341
            MessagingUtils.error(CdmStore.class, cae);
342
        }
343

  
344
        return service;
345
    }
346

  
347
    /**
348
     * @see #getService(Class)
349
     * As ICommonService is not extending IService we need a specific request here
350
     */
351
    public static ICommonService getCommonService() {
352
        return CdmApplicationState.getCommonService();
353

  
354
    }
355

  
356
    /**
357
     * <p>
358
     * getAuthenticationManager
359
     * </p>
360
     *
361
     * @return a
362
     *         {@link org.springframework.security.authentication.ProviderManager}
363
     *         object.
364
     */
365
    public static AuthenticationManager getAuthenticationManager() {
366
        return getCurrentApplicationConfiguration().getAuthenticationManager();
367
    }
368

  
369
    /**
370
     * <p>
371
     * getAuthenticationManager
372
     * </p>
373
     *
374
     * @return a
375
     *         {@link ICdmPermissionEvaluator} object.
376
     */
377
    public static ICdmPermissionEvaluator getPermissionEvaluator() {
378
        return getCurrentApplicationConfiguration().getPermissionEvaluator();
379
    }
380

  
381
    /**
382
     * <p>
383
     * getGeoService
384
     * </p>
385
     *
386
     * @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object.
387
     */
388
    public static IEditGeoService getGeoService() {
389
        return (IEditGeoService) getCurrentApplicationConfiguration().getBean(
390
                "editGeoService");
391
    }
392

  
393
    /*
394
     * SECURITY RELATED CONVENIENCE METHODS
395
     */
396

  
397
    /**
398
     * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
399
     *
400
     * @param targetDomainObject
401
     * @param permission
402
     * @return
403
     */
404
    public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
405
        //TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
406
        SecurityContext context = SecurityContextHolder.getContext();
407
        PermissionEvaluator pe = getPermissionEvaluator();
408
        boolean hasPermission = false;
409
        try {
377 410
            hasPermission = getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject,
378 411
                    permission);
379 412
        } catch (org.springframework.security.access.AccessDeniedException e) {
380 413
            /* IGNORE */
381 414
        }
382 415
        return hasPermission;
383
	}
416
    }
384 417

  
385
	/**
386
	 * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
418
    /**
419
     * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
387 420
     *
388
	 * @param targetDomainObject
389
	 * @param permission
390
	 * @return
391
	 */
392
	public static boolean currentAuthentiationHasPermission(Class<? extends CdmBase> targetType, EnumSet<CRUD> permission){
393
	    boolean hasPermission = false;
421
     * @param targetDomainObject
422
     * @param permission
423
     * @return
424
     */
425
    public static boolean currentAuthentiationHasPermission(Class<? extends CdmBase> targetType, EnumSet<CRUD> permission){
426
        boolean hasPermission = false;
394 427
        try {
395 428
            hasPermission = getPermissionEvaluator().hasPermission(getCurrentAuthentiation(), null, targetType.getName(), permission);
396 429
        } catch (org.springframework.security.access.AccessDeniedException e) {
397 430
            /* IGNORE */
398 431
        }
399 432
        return hasPermission;
400
	}
433
    }
401 434

  
402
	public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
403
	    boolean hasPermission = false;
435
    public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
436
        boolean hasPermission = false;
404 437
        try {
405 438
            hasPermission =  getPermissionEvaluator().hasOneOfRoles(getCurrentAuthentiation(), roles);
406 439
        } catch (org.springframework.security.access.AccessDeniedException e) {
407 440
            /* IGNORE */
408 441
        }
409 442
        return hasPermission;
410
	}
411

  
412
	public static Authentication getCurrentAuthentiation() {
413
		SecurityContext context = SecurityContextHolder.getContext();
414
		return context.getAuthentication();
415
	}
416

  
417
	/*
418
	 * LANGUAGE
419
	 */
420

  
421
	/**
422
	 * Provides access to the global default language set in the application preferences.
423
	 *
424
	 * @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
425
	 */
426
	public static Language getDefaultLanguage() {
427
		if (getDefault().getLanguage() == null) {
428
			getDefault().setLanguage(PreferencesUtil.getGlobalLanguage());
429
		}
430
		return getDefault().getLanguage();
431
	}
432

  
433
	/**
434
	 * <p>
435
	 * setDefaultLanguage
436
	 * </p>
437
	 *
438
	 * @param language
439
	 *            a {@link eu.etaxonomy.cdm.model.common.Language} object.
440
	 */
441
	public static void setDefaultLanguage(Language language) {
442
		getDefault().setLanguage(language);
443
	}
444

  
445
	/**
446
	 * @return the language
447
	 */
448
	private Language getLanguage() {
449
		return language;
450
	}
451

  
452
	/**
453
	 * @param language
454
	 *            the language to set
455
	 */
456
	private void setLanguage(Language language) {
457
		this.language = language;
458
	}
459

  
460
	/*
461
	 * LOGIN
462
	 */
463

  
464
	/**
465
	 * <p>
466
	 * Getter for the field <code>loginManager</code>.
467
	 * </p>
468
	 *
469
	 * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
470
	 */
471
	public static LoginManager getLoginManager() {
472
		return loginManager;
473
	}
474

  
475
	/**
476
	 * <p>
477
	 * Getter for the field <code>contextManager</code>.
478
	 * </p>
479
	 *
480
	 * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
481
	 */
482
	public static ContextManager getContextManager() {
483
		return contextManager;
484
	}
485

  
486
	public static TermManager getTermManager() {
487
		return termManager;
488
	}
489

  
490
	public static SearchManager getSearchManager() {
491
		return searchManager;
492
	}
493

  
494
	public static EditorManager getEditorManager() {
495
		return editorManager;
496
	}
497

  
498
	/*
499
	 * IMPORT/EXPORT FACTORIES
500
	 */
501

  
502
	/**
503
	 * <p>
504
	 * Getter for the field <code>importHandler</code>.
505
	 * </p>
506
	 *
507
	 * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
508
	 */
509
	public static ImportManager getImportManager() {
510
		return ImportManager.NewInstance(getCurrentApplicationConfiguration());
511
	}
512

  
513
	/**
514
	 * <p>
515
	 * Getter for the field <code>exportHandler</code>.
516
	 * </p>
517
	 *
518
	 * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
519
	 */
520
	public static ExportManager getExportManager() {
521
		return ExportManager.NewInstance(getCurrentApplicationConfiguration());
522
	}
523

  
524
	/**
525
	 * Whether this CdmStore is currently connected to a datasource
526
	 *
527
	 * @return a boolean.
528
	 */
529
	public static boolean isActive() {
530
		return instance != null && instance.isConnected;
531
	}
532

  
533
	public static ICdmSource getActiveCdmSource() {
534
		if (isActive()) {
535
			return instance.getCdmSource();
536
		}
537
		return null;
538
	}
539

  
540
	/**
541
	 * <p>
542
	 * getDataSource
543
	 * </p>
544
	 *
545
	 * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
546
	 * @deprecated currently retained for backward compatibility - use {@link getActiveCdmSource()} instead
547
	 */
548
//	public static ICdmDataSource getDataSource() {
549
//		if (isActive()) {
550
//			return (ICdmDataSource)instance.getCdmSource();
551
//		}
552
//		return null;
553
//	}
554

  
555
	/**
556
	 * @return
557
	 */
558
	private ICdmSource getCdmSource() {
559
		return cdmSource;
560
	}
443
    }
444

  
445
    public static Authentication getCurrentAuthentiation() {
446
        SecurityContext context = SecurityContextHolder.getContext();
447
        return context.getAuthentication();
448
    }
449

  
450
    /*
451
     * LANGUAGE
452
     */
453

  
454
    /**
455
     * Provides access to the global default language set in the application preferences.
456
     *
457
     * @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
458
     */
459
    public static Language getDefaultLanguage() {
460
        if (getDefault().getLanguage() == null) {
461
            getDefault().setLanguage(PreferencesUtil.getGlobalLanguage());
462
        }
463
        return getDefault().getLanguage();
464
    }
465

  
466
    /**
467
     * <p>
468
     * setDefaultLanguage
469
     * </p>
470
     *
471
     * @param language
472
     *            a {@link eu.etaxonomy.cdm.model.common.Language} object.
473
     */
474
    public static void setDefaultLanguage(Language language) {
475
        getDefault().setLanguage(language);
476
    }
477

  
478
    /**
479
     * @return the language
480
     */
481
    private Language getLanguage() {
482
        return language;
483
    }
484

  
485
    /**
486
     * @param language
487
     *            the language to set
488
     */
489
    private void setLanguage(Language language) {
490
        this.language = language;
491
    }
492

  
493
    /*
494
     * LOGIN
495
     */
496

  
497
    /**
498
     * <p>
499
     * Getter for the field <code>loginManager</code>.
500
     * </p>
501
     *
502
     * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
503
     */
504
    public static LoginManager getLoginManager() {
505
        return loginManager;
506
    }
507

  
508
    /**
509
     * <p>
510
     * Getter for the field <code>contextManager</code>.
511
     * </p>
512
     *
513
     * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
514
     */
515
    public static ContextManager getContextManager() {
516
        return contextManager;
517
    }
518

  
519
    public static TermManager getTermManager() {
520
        return termManager;
521
    }
522

  
523
    public static SearchManager getSearchManager() {
524
        return searchManager;
525
    }
526

  
527
    public static EditorManager getEditorManager() {
528
        return editorManager;
529
    }
530

  
531
    /*
532
     * IMPORT/EXPORT FACTORIES
533
     */
534

  
535
    /**
536
     * <p>
537
     * Getter for the field <code>importHandler</code>.
538
     * </p>
539
     *
540
     * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
541
     */
542
    public static ImportManager getImportManager() {
543
        return ImportManager.NewInstance(getCurrentApplicationConfiguration());
544
    }
545

  
546
    /**
547
     * <p>
548
     * Getter for the field <code>exportHandler</code>.
549
     * </p>
550
     *
551
     * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
552
     */
553
    public static ExportManager getExportManager() {
554
        return ExportManager.NewInstance(getCurrentApplicationConfiguration());
555
    }
556

  
557
    /**
558
     * Whether this CdmStore is currently connected to a datasource
559
     *
560
     * @return a boolean.
561
     */
562
    public static boolean isActive() {
563
        return instance != null && instance.isConnected;
564
    }
565

  
566
    public static ICdmSource getActiveCdmSource() {
567
        if (isActive()) {
568
            return instance.getCdmSource();
569
        }
570
        return null;
571
    }
572

  
573
    /**
574
     * <p>
575
     * getDataSource
576
     * </p>
577
     *
578
     * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
579
     * @deprecated currently retained for backward compatibility - use {@link getActiveCdmSource()} instead
580
     */
581
    //	public static ICdmDataSource getDataSource() {
582
    //		if (isActive()) {
583
    //			return (ICdmDataSource)instance.getCdmSource();
584
    //		}
585
    //		return null;
586
    //	}
587

  
588
    /**
589
     * @return
590
     */
591
    private ICdmSource getCdmSource() {
592
        return cdmSource;
593
    }
561 594

  
562 595
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java
10 10

  
11 11
package eu.etaxonomy.taxeditor.store;
12 12

  
13
import java.lang.reflect.InvocationTargetException;
13 14
import java.sql.SQLException;
14 15
import java.util.concurrent.CancellationException;
15 16

  
......
17 18
import org.eclipse.core.runtime.IStatus;
18 19
import org.eclipse.core.runtime.Status;
19 20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
22
import org.eclipse.jface.operation.IRunnableWithProgress;
20 23
import org.eclipse.swt.widgets.Display;
21 24
import org.springframework.core.io.Resource;
22 25

  
......
32 35
import eu.etaxonomy.taxeditor.model.MessagingUtils;
33 36
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
34 37
import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
38
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
35 39
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
36 40

  
41

  
37 42
/**
38 43
 * @author n.hoffmann
39 44
 * @created Dec 8, 2010
40 45
 * @version 1.0
41 46
 */
42 47
class CdmStoreConnector extends Job {
43
	private final Display display;
44
	private final ICdmSource cdmSource;
45
	private DbSchemaValidation dbSchemaValidation;
46
	private final Resource applicationContextBean;
47

  
48
	/**
49
	 * @param datasource
50
	 * @param dbSchemaValidation
51
	 * @param applicationContextBean
52
	 */
53
	public CdmStoreConnector(Display display, ICdmSource cdmSource,
54
			DbSchemaValidation dbSchemaValidation,
55
			Resource applicationContextBean) {
56
		super("Connecting to datasource: " + cdmSource);
57
		this.display = display;
58
		this.cdmSource = cdmSource;
59
		this.dbSchemaValidation = dbSchemaValidation;
60
		this.applicationContextBean = applicationContextBean;
61
	}
62

  
63
	@Override
64
	public IStatus run(final IProgressMonitor monitor) {
65

  
66
		monitor.beginTask(getConnectionMessage(), 10);
67

  
68
		// check if database is up and running
69
		checkDatabaseReachable(monitor);
70

  
71
		if (!monitor.isCanceled()) {
72
			// check if the datasource actually holds data
73
			checkIsNonEmptyCdmDatabase(monitor);
74
		}
75

  
76
		if (dbSchemaValidation != DbSchemaValidation.CREATE
77
				&& !monitor.isCanceled()) {
78
			// if we do not create the datasource, we want to check if the
79
			// datasource is compatible with this editor
80
			checkDbSchemaVersionCompatibility(monitor);
81
		}
82

  
83
		// we are done with our low level checking and will free resources now
84
		cdmSource.closeOpenConnections();
85

  
86
		if (!monitor.isCanceled()) {
87
			CdmStore.close(monitor);
88
		}
89

  
90
		ICdmApplicationConfiguration applicationController = null;
91

  
92
		if (!monitor.isCanceled()) {
93
			CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
94
					.CreateSubMonitor(monitor, 7);
95
			// This is where we instantiate the application controller
96
			int oldPriority = Thread.currentThread().getPriority();
97
			try {
98
				Thread.currentThread().setPriority(10);
99
				applicationController = getApplicationController(cdmSource,subprogressMonitor);
100
			} catch (Exception e) {
101
				if(! causeIsCancelationExceptionRecursive(e)){
102
					return new Status(IStatus.ERROR, "Could not connect to CDM Store", "An error occurred while trying to connect to datasource: " + cdmSource.getName(), e);
103
				}
104
			} finally {
105
				monitor.done();
106
				Thread.currentThread().setPriority(oldPriority);
107
			}
108
		}
109

  
110

  
111

  
112
		if (!monitor.isCanceled()) {
113
			CdmStore.setInstance(applicationController, cdmSource);
114

  
115
			display.asyncExec(new Runnable() {
116
				/*
117
				 * (non-Javadoc)
118
				 *
119
				 * @see java.lang.Runnable#run()
120
				 */
121
				@Override
122
				public void run() {
123
					authenticate();
124

  
125
					startContext();
126
				}
127
			});
128

  
129
			MessagingUtils.info("Application context initialized.");
130
			return Status.OK_STATUS;
131
		} else {
132
			// Show datasource view if not shown yet
133
			display.asyncExec(new Runnable() {
134
				/*
135
				 * (non-Javadoc)
136
				 *
137
				 * @see java.lang.Runnable#run()
138
				 */
139
				@Override
140
				public void run() {
141
					StoreUtil.showView(CdmDataSourceViewPart.ID);
142
				}
143
			});
144
			return Status.CANCEL_STATUS;
145
		}
146

  
147
	}
148

  
149
	private ICdmApplicationConfiguration getApplicationController(ICdmSource cdmSource, CdmProgressMonitorAdapter subprogressMonitor) {
150
		if(cdmSource instanceof ICdmDataSource) {
151
			return  CdmApplicationController.NewInstance(applicationContextBean,
152
					(ICdmDataSource)cdmSource,
153
					dbSchemaValidation,
154
					false,
155
					subprogressMonitor);
156
		} else if(cdmSource instanceof ICdmRemoteSource) {
157
			return CdmApplicationRemoteController.NewInstance((ICdmRemoteSource)cdmSource,
158
							subprogressMonitor,
159
							null);
160
		} else {
161
			throw new UnsupportedOperationException("Cannot create application controller for " + cdmSource.getName());
162
		}
163
	}
164
	private void authenticate() {
165
		LoginDialog loginDialog = new LoginDialog(StoreUtil.getShell());
166
		loginDialog.open();
167
	}
168

  
169
	private void startContext() {
170
		CdmStore.getContextManager().notifyContextStart();
171
	}
172

  
173
	/**
174
	 * @return
175
	 */
176
	private String getConnectionMessage() {
177
		return cdmSource.getConnectionMessage();
178
	}
179

  
180
	/**
181
	 * @return
182
	 * @throws SQLException
183
	 */
184
	private void checkDbSchemaVersionCompatibility(IProgressMonitor monitor) {
185
		monitor.subTask("Checking if datasource is compatible with this editor.");
186
		String dbSchemaVersion;
187

  
188
		String message = null;
189
		try {
190
			dbSchemaVersion = cdmSource.getDbSchemaVersion();
191
			// we assume that empty dbSchemaVersion means an empty database and
192
			// skip version checking
193

  
194
			if(dbSchemaVersion != null) {
195
			    int compareVersion = CdmMetaData.compareVersion(dbSchemaVersion, CdmMetaData.getDbSchemaVersion(), 3, null);
196
			    // if the datasource version is greater than the taxeditor compatible version then the taxeditor needs to
197
			    // be updated else the datasource needs to be updated
198
			    if(compareVersion > 0) {
199
			        message = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible datasource";
200
			    } else if (compareVersion < 0) {
201
			        message = "Please update the chosen datasource or choose a new data source to connect to in the Datasource View.";
202
			    }
203
			}
204
			monitor.worked(1);
205
		} catch (CdmSourceException e) {
206
			//
207
		}
208

  
209
		if (message != null) {
210
			// Show an error message
211
			MessagingUtils
212
					.messageDialog(
213
							"Datasource Compatibility Check failed",
214
							this,
215
							"The database schema for the chosen "
216
									+ "datasource '"
217
									+ cdmSource
218
									+ "' \n is not compatible for this version of the taxonomic editor. \n\n"
219
									+ message,
220
							null);
221

  
222
			monitor.setCanceled(true);
223
		}
224

  
225
	}
226

  
227
	private void checkIsNonEmptyCdmDatabase(IProgressMonitor monitor) {
228
		monitor.subTask("Checking if datasource is a non empty CDM database.");
229
		boolean isDbEmpty = false;
230
		try {
231
			isDbEmpty = cdmSource.isDbEmpty();
232
		} catch (CdmSourceException e) {
233
			isDbEmpty = true;
234
		}
235
		if(isDbEmpty) {
236
			dbSchemaValidation = DbSchemaValidation.CREATE;
237
		}
238
	}
239

  
240
	private boolean causeIsCancelationExceptionRecursive(Throwable throwable){
241
		if(throwable == null){
242
			return false;
243
		}else if(throwable instanceof CancellationException){
244
			return true;
245
		}else{
246
			return causeIsCancelationExceptionRecursive(throwable.getCause());
247
		}
248
	}
249

  
250
	private void checkDatabaseReachable(IProgressMonitor monitor) {
251
		try {
252
			monitor.subTask("Checking if datasource is reachable.");
253
			cdmSource.checkConnection();
254
			monitor.worked(1);
255
		} catch (CdmSourceException e) {
256
			MessagingUtils.messageDialog("Could not connect to chosen datasource",
257
					this, "Reason: " + e.getMessage(), e);
258
			monitor.setCanceled(true);
259
		}
260
	}
48
    private final Display display;
49
    private final ICdmSource cdmSource;
50
    private DbSchemaValidation dbSchemaValidation;
51
    private final Resource applicationContextBean;
52

  
53

  
54
    /**
55
     * @param datasource
56
     * @param dbSchemaValidation
57
     * @param applicationContextBean
58
     */
59
    public CdmStoreConnector(Display display,
60
            ICdmSource cdmSource,
61
            DbSchemaValidation dbSchemaValidation,
62
            Resource applicationContextBean) {
63
        super("Connecting to datasource: " + cdmSource);
64
        this.display = display;
65
        this.cdmSource = cdmSource;
66
        this.dbSchemaValidation = dbSchemaValidation;
67
        this.applicationContextBean = applicationContextBean;
68
    }
69

  
70

  
71

  
72
    @Override
73
    public IStatus run(final IProgressMonitor monitor) {
74

  
75
        monitor.beginTask(getConnectionMessage(), 10);
76

  
77
        // check if database is up and running
78
        checkDatabaseReachable(monitor);
79

  
80
        if (!monitor.isCanceled()) {
81
            // check if the datasource actually holds data
82
            checkIsNonEmptyCdmDatabase(monitor);
83
        }
84

  
85
        if (dbSchemaValidation != DbSchemaValidation.CREATE
86
                && !monitor.isCanceled()) {
87
            // if we do not create the datasource, we want to check if the
88
            // datasource is compatible with this editor
89
            checkDbSchemaVersionCompatibility(monitor);
90
        }
91

  
92
        // we are done with our low level checking and will free resources now
93
        cdmSource.closeOpenConnections();
94

  
95
        if (!monitor.isCanceled()) {
96
            CdmStore.close(monitor);
97
        }
98

  
99
        ICdmApplicationConfiguration applicationController = null;
100

  
101
        if (!monitor.isCanceled()) {
102
            CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
103
                    .CreateSubMonitor(monitor, 7);
104
            // This is where we instantiate the application controller
105
            int oldPriority = Thread.currentThread().getPriority();
106
            try {
107
                Thread.currentThread().setPriority(10);
108
                applicationController = getApplicationController(cdmSource,subprogressMonitor);
109
            } catch (Exception e) {
110
                if(! causeIsCancelationExceptionRecursive(e)){
111
                    return new Status(IStatus.ERROR, "Could not connect to CDM Store", "An error occurred while trying to connect to datasource: " + cdmSource.getName(), e);
112
                }
113
            } finally {
114
                monitor.done();
115
                Thread.currentThread().setPriority(oldPriority);
116
            }
117
        }
118

  
119

  
120

  
121
        if (!monitor.isCanceled()) {
122
            CdmStore.setInstance(applicationController, cdmSource);
123

  
124
            display.asyncExec(new Runnable() {
125
                /*
126
                 * (non-Javadoc)
127
                 *
128
                 * @see java.lang.Runnable#run()
129
                 */
130
                @Override
131
                public void run() {
132
                    authenticate();
133

  
134
                    startContext();
135
                }
136
            });
137

  
138
            MessagingUtils.info("Application context initialized.");
139
            return Status.OK_STATUS;
140
        } else {
141
            // Show datasource view if not shown yet
142
            display.asyncExec(new Runnable() {
143
                /*
144
                 * (non-Javadoc)
145
                 *
146
                 * @see java.lang.Runnable#run()
147
                 */
148
                @Override
149
                public void run() {
150
                    StoreUtil.showView(CdmDataSourceViewPart.ID);
151
                }
152
            });
153
            return Status.CANCEL_STATUS;
154
        }
155

  
156
    }
157

  
158
    public void start(final RemotingLoginDialog loginDialog) {
159
        // hide login dialog and start connection dialog
160
        loginDialog.setMessage(null);
161
        loginDialog.hide(true);
162

  
163

  
164
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
165

  
166
        try {
167
            dialog.run(true, true, new IRunnableWithProgress() {
168
                @Override
169
                public void run(final IProgressMonitor monitor) {
170
                    try {
171
                        monitor.beginTask(getConnectionMessage(), 7);
172

  
173
                        // check if database is up and running
174
                        checkDatabaseReachable(monitor);
175

  
176
                        // check if the datasource actually holds data
177
                        checkIsNonEmptyCdmDatabase(monitor);
178

  
179
                        if (dbSchemaValidation != DbSchemaValidation.CREATE) {
180
                            // if we do not create the datasource, we want to check if the
181
                            // datasource is compatible with this editor
182
                            checkDbSchemaVersionCompatibility(monitor);
183
                        }
184

  
185
                        // we are done with our low level checking and will free resources now
186
                        cdmSource.closeOpenConnections();
187

  
188
                        display.syncExec(new Runnable() {
189
                            /*
190
                             * (non-Javadoc)
191
                             *
192
                             * @see java.lang.Runnable#run()
193
                             */
194
                            @Override
195
                            public void run() {
196
                                // close the current context
197
                                CdmStore.close(monitor, false);
198
                            }
199
                        });
200

  
201
                        ICdmApplicationConfiguration applicationController = null;
202

  
203
                        if (!monitor.isCanceled()) {
204
                            CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
205
                                    .CreateSubMonitor(monitor, 3);
206
                            // genrerate new application controller
207
                            applicationController = getApplicationController(cdmSource,subprogressMonitor);
208
                        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff