From 5eaf7c899477a46fdca7ee667a3b82b058221904 Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Thu, 28 May 2015 13:13:24 +0200 Subject: [PATCH] replaced simple editor-datasource compatibility check with version comparison check --- .../taxeditor/store/CdmStoreConnector.java | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java index e7c5aa0b7..f174f8677 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java @@ -1,9 +1,9 @@ // $Id$ /** * Copyright (C) 2007 EDIT - * European Distributed Institute of Taxonomy + * European Distributed Institute of Taxonomy * http://www.e-taxonomy.eu - * + * * The contents of this file are subject to the Mozilla Public License Version 1.1 * See LICENSE.TXT at the top of this package for the full license terms. */ @@ -64,7 +64,7 @@ class CdmStoreConnector extends Job { public IStatus run(final IProgressMonitor monitor) { monitor.beginTask(getConnectionMessage(), 10); - + // check if database is up and running checkDatabaseReachable(monitor); @@ -106,8 +106,8 @@ class CdmStoreConnector extends Job { Thread.currentThread().setPriority(oldPriority); } } - - + + if (!monitor.isCanceled()) { CdmStore.setInstance(applicationController, cdmSource); @@ -115,7 +115,7 @@ class CdmStoreConnector extends Job { display.asyncExec(new Runnable() { /* * (non-Javadoc) - * + * * @see java.lang.Runnable#run() */ @Override @@ -133,7 +133,7 @@ class CdmStoreConnector extends Job { display.asyncExec(new Runnable() { /* * (non-Javadoc) - * + * * @see java.lang.Runnable#run() */ @Override @@ -148,14 +148,14 @@ class CdmStoreConnector extends Job { private ICdmApplicationConfiguration getApplicationController(ICdmSource cdmSource, CdmProgressMonitorAdapter subprogressMonitor) { if(cdmSource instanceof ICdmDataSource) { - return CdmApplicationController.NewInstance(applicationContextBean, - (ICdmDataSource)cdmSource, + return CdmApplicationController.NewInstance(applicationContextBean, + (ICdmDataSource)cdmSource, dbSchemaValidation, - false, + false, subprogressMonitor); } else if(cdmSource instanceof ICdmRemoteSource) { - return CdmApplicationRemoteController.NewInstance((ICdmRemoteSource)cdmSource, - false, + return CdmApplicationRemoteController.NewInstance((ICdmRemoteSource)cdmSource, + false, subprogressMonitor, null); } else { @@ -185,29 +185,39 @@ class CdmStoreConnector extends Job { private void checkDbSchemaVersionCompatibility(IProgressMonitor monitor) { monitor.subTask("Checking if datasource is compatible with this editor."); String dbSchemaVersion; - boolean result = false; + + String message = null; try { dbSchemaVersion = cdmSource.getDbSchemaVersion(); // we assume that empty dbSchemaVersion means an empty database and // skip version checking - result = dbSchemaVersion == null ? true : CdmMetaData - .isDbSchemaVersionCompatible(dbSchemaVersion); + + if(dbSchemaVersion != null) { + int compareVersion = CdmMetaData.compareVersion(dbSchemaVersion, CdmMetaData.getDbSchemaVersion(), 3, null); + // if the datasource version is greater than the taxeditor compatible version then the taxeditor needs to + // be updated else the datasource needs to be updated + if(compareVersion > 0) { + message = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible datasource"; + } else if (compareVersion < 0) { + message = "Please update the chosen datasource or choose a new data source to connect to in the Datasource View."; + } + } monitor.worked(1); } catch (CdmSourceException e) { // } - if (!result) { + if (message != null) { // Show an error message MessagingUtils .messageDialog( - "DatabaseCompatibilityCheck failed", + "Datasource Compatibility Check failed", this, "The database schema for the chosen " + "datasource '" + cdmSource - + "' \n is not valid for this version of the taxonomic editor. \n" - + "Please update the chosen datasource or choose a new data source to connect to in the Datasource View.", + + "' \n is not compatible for this version of the taxonomic editor. \n\n" + + message, null); monitor.setCanceled(true); @@ -237,7 +247,7 @@ class CdmStoreConnector extends Job { return causeIsCancelationExceptionRecursive(throwable.getCause()); } } - + private void checkDatabaseReachable(IProgressMonitor monitor) { try { monitor.subTask("Checking if datasource is reachable."); @@ -247,6 +257,6 @@ class CdmStoreConnector extends Job { MessagingUtils.messageDialog("Could not connect to chosen datasource", this, "Reason: " + e.getMessage(), e); monitor.setCanceled(true); - } + } } } -- 2.34.1