replaced simple editor-datasource compatibility check with version comparison check
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 28 May 2015 11:13:24 +0000 (13:13 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 28 May 2015 11:13:24 +0000 (13:13 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java

index e7c5aa0b74c608e7ec35e6b78ce4149637f486af..f174f86773252b951c855dcd41951a105f44c0a9 100644 (file)
@@ -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);
-               } 
+               }
        }
 }