#5302 Add cdm version and services version check
authorCherian Mathew <c.mathew@bgbm.org>
Wed, 7 Oct 2015 14:43:53 +0000 (16:43 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 8 Oct 2015 15:19:28 +0000 (17:19 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/DefaultNewEntityListener.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/operation/TaxonNameEditorTest.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmApplicationStateTest.java [new file with mode: 0644]

index bcd6dff64c1f299e085c1b9a705f8715b7daf988..e9e489a53666ed112d83fa96a41385b61e67c993 100644 (file)
@@ -9,10 +9,24 @@
 */
 package eu.etaxonomy.cdm.api.application;
 
+import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
-
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.ManifestElement;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
 import org.springframework.security.core.context.SecurityContext;
 
 import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
@@ -41,6 +55,8 @@ public class CdmApplicationState {
 
     private static CdmServiceCacher cdmServiceCacher;
 
+    private static String cdmlibVersion = null;
+    private static String cdmlibLastModified = null;
 
     public static CdmApplicationState getInstance() {
         if(cdmApplicationState == null) {
@@ -129,6 +145,8 @@ public class CdmApplicationState {
         getInstance().setSecurityContext(null);
         cdmApplicationState = null;
         cdmServiceCacher = null;
+        cdmlibVersion = null;
+        cdmlibLastModified = null;
     }
 
 
@@ -211,5 +229,59 @@ public class CdmApplicationState {
         cdmServiceCacher = cacher;
     }
 
+    public static void updateCdmlibManifestInfo() {
+        cdmlibVersion = null;
+        cdmlibLastModified = null;
+        String cdmlibPathPrefix = "lib/cdmlib-services-";
+        String jarSuffix = ".jar";
+        Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.cdmlib");
+        Dictionary<String, String> headers = bundle.getHeaders();
+        String bundleClasspath = headers.get(Constants.BUNDLE_CLASSPATH);
+        try {
+            ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, bundleClasspath);
+            for (ManifestElement manifestElement : elements) {
+                String jar =  manifestElement.getValue();
+                if(jar.startsWith(cdmlibPathPrefix) && jar.endsWith(jarSuffix)) {
+                    URL fileURL = bundle.getEntry(jar);
+                    File file = null;
+                    try {
+                        file = new File(FileLocator.resolve(fileURL).toURI());
+                        JarFile jarFile = new JarFile(file);
+                        Manifest manifest = jarFile.getManifest();
+                        Attributes attributes = manifest.getMainAttributes();
+                        // from the OSGI spec the LastModified value is " the number of milliseconds
+                        // since midnight Jan. 1, 1970 UTC with the condition that a change must
+                        // always result in a higher value than the previous last modified time
+                        // of any bundle"
+                        cdmlibVersion = attributes.getValue("Bundle-Version");
+                        cdmlibLastModified = attributes.getValue("Bnd-LastModified");
+
+                        if(cdmlibVersion == null || cdmlibLastModified == null) {
+                            throw new IllegalStateException("Invalid cdmlib manifest info");
+                        }
+                    } catch (URISyntaxException urise) {
+                        throw new IllegalStateException(urise);
+                    } catch (IOException ioe) {
+                        throw new IllegalStateException(ioe);
+                    }
+                }
+            }
+        } catch (BundleException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    public static String getCdmlibVersion() {
+        if(cdmlibVersion == null) {
+            updateCdmlibManifestInfo();
+        }
+        return cdmlibVersion;
+    }
 
+    public static String getCdmlibLastModified() {
+        if(cdmlibLastModified == null) {
+            updateCdmlibManifestInfo();
+        }
+        return cdmlibLastModified;
+    }
 }
index d6fce9ba007ef4625d4764547e45abda5d9ff4a8..e5822e9eb35c0adc32620448ac50957b098888b5 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
@@ -23,15 +24,19 @@ import org.apache.http.client.HttpClient;
 import org.apache.http.client.ResponseHandler;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
 import org.apache.http.util.EntityUtils;
 import org.apache.log4j.Logger;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.config.CdmSourceException;
 import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
 
 /**
@@ -75,11 +80,16 @@ public class CdmServerInfo {
 
     private static List<CdmServerInfo> cdmServerInfoList;
 
+    private String cdmlibServicesVersion = "";
+    private String cdmlibServicesLastModified = "";
+
+
     public CdmServerInfo(String name, String server, int port) {
         this.name = name;
         this.server = server;
         this.port = port;
         instances = new ArrayList<CdmInstanceInfo>();
+
     }
 
 
@@ -98,6 +108,14 @@ public class CdmServerInfo {
         return NAME_LOCALHOST_MGD.equals(name);
     }
 
+    public String getCdmlibServicesVersion() {
+        return cdmlibServicesVersion;
+    }
+
+    public String getCdmlibLastModified() {
+        return cdmlibServicesLastModified;
+    }
+
     public void refreshInstances() throws CDMServerException {
         instances.clear();
         if(isLocalhostMgd()) {
@@ -114,10 +132,54 @@ public class CdmServerInfo {
         });
     }
 
+    public void updateInfo() throws CDMServerException {
+        String url = "http://" + server + ":" + String.valueOf(port) + "/" + CDMSERVER_PREFIX + "/info.jsp";
+        String responseBody = getResponse(url);
+        if(responseBody != null) {
+            try {
+                JSONObject info = new JSONObject(responseBody);
+                cdmlibServicesVersion =  info.getString("cdmlibServicesVersion");
+                cdmlibServicesLastModified = info.getString("cdmlibServicesLastModified");
+            } catch (JSONException e) {
+                throw new CDMServerException(e);
+            }
+        }
+    }
+
     public void addInstancesViaHttp() throws CDMServerException {
+        updateInfo();
         String url = "http://" + server + ":" + String.valueOf(port) + "/" + CDMSERVER_PREFIX + "/instances.jsp";
+        String responseBody = getResponse(url);
+        if(responseBody != null) {
+            try {
+                JSONArray array = new JSONArray(responseBody);
+                for(int i=0;i<array.length();i++) {
+                    JSONObject instance = (JSONObject)array.get(i);
+                    if(instance != null) {
+                        JSONObject conf = (JSONObject)instance.get("configuration");
+                        if(conf != null) {
+                            String instanceName = conf.getString("instanceName");
+                            // we need to remove the first (char) forward slash from
+                            // the base path
+                            String basePath = conf.getString("basePath").substring(1);
+                            addInstance(instanceName, basePath);
+                            logger.info("Added instance with name : " + instanceName + ", basePath : " + basePath);
+                        }
+                    }
+                }
+            } catch (JSONException e) {
+                throw new CDMServerException(e);
+            }
+        }
+    }
 
+    private String getResponse(String url) throws CDMServerException {
         HttpClient client = new DefaultHttpClient();
+        HttpParams params = client.getParams();
+
+        HttpConnectionParams.setConnectionTimeout(params, 5000);
+        HttpConnectionParams.setSoTimeout(params, 5000);
+
         HttpGet httpGet = new HttpGet(url);
 
         logger.info("Executing request " + httpGet.getRequestLine());
@@ -146,29 +208,7 @@ public class CdmServerInfo {
         } catch (IOException e) {
             throw new CDMServerException(e);
         }
-
-
-        if(responseBody != null) {
-            try {
-                JSONArray array = new JSONArray(responseBody);
-                for(int i=0;i<array.length();i++) {
-                    JSONObject instance = (JSONObject)array.get(i);
-                    if(instance != null) {
-                        JSONObject conf = (JSONObject)instance.get("configuration");
-                        if(conf != null) {
-                            String instanceName = conf.getString("instanceName");
-                            // we need to remove the first (char) forward slash from
-                            // the base path
-                            String basePath = conf.getString("basePath").substring(1);
-                            addInstance(instanceName, basePath);
-                            logger.info("Added instance with name : " + instanceName + ", basePath : " + basePath);
-                        }
-                    }
-                }
-            } catch (JSONException e) {
-                throw new CDMServerException(e);
-            }
-        }
+        return responseBody;
     }
 
     public void addInstancesFromDataSourcesConfig() {
@@ -208,13 +248,16 @@ public class CdmServerInfo {
         return null;
     }
 
-    public boolean pingServer(){
+    public boolean pingServer() {
         try {
             Socket s = new Socket(server, port);
             logger.info("[CDM-Server] Available @ " + server + ":" + port );
+            updateInfo();
             return true;
         } catch (IOException ioe) {
 
+        } catch (CDMServerException e) {
+
         }
         return false;
     }
@@ -234,6 +277,69 @@ public class CdmServerInfo {
         return false;
     }
 
+    public int compareDbSchemaVersion(CdmInstanceInfo instance, int port) throws CDMServerException {
+
+        ICdmRemoteSource crs = getCdmRemoteSource(instance, port);
+        String dbSchemaVersion;
+        try {
+            dbSchemaVersion = crs.getDbSchemaVersion();
+        } catch (CdmSourceException e) {
+            throw new CDMServerException(e);
+        }
+
+
+        if(dbSchemaVersion != null) {
+            return CdmMetaData.compareVersion(dbSchemaVersion, CdmMetaData.getDbSchemaVersion(), 3, null);
+        } else {
+            throw new CDMServerException("Cannot determine editor db. schema version");
+        }
+    }
+
+    public int compareCdmlibServicesVersion() throws CdmSourceException {
+        int result = 0;
+        String serverVersion = cdmlibServicesVersion;
+        String editorVersion = CdmApplicationState.getCdmlibVersion();
+
+        if(StringUtils.isBlank(serverVersion) || StringUtils.isBlank(editorVersion)) {
+            throw new CdmSourceException("cdmlib-services server or editor version is empty");
+        }
+
+        String[] serverVersionSplit = serverVersion.split("\\.");
+        String[] editorVersionSplit = editorVersion.split("\\.");
+
+        if(serverVersionSplit.length < 3 || editorVersionSplit.length < 3 || serverVersionSplit.length > 4 || editorVersionSplit.length > 4) {
+            throw new CdmSourceException("cdmlib-services server or editor version is invalid");
+        }
+
+        Integer serverVersionPart;
+        Integer editorVersionPart;
+
+        for(int i=0 ; i<3 ; i++) {
+            serverVersionPart = Integer.valueOf(serverVersionSplit[i]);
+            editorVersionPart = Integer.valueOf(editorVersionSplit[i]);
+
+            int partCompare = serverVersionPart.compareTo(editorVersionPart);
+            if (partCompare != 0){
+                return partCompare;
+            }
+        }
+        // at this point major, minor and patch versions are matching
+
+        if(StringUtils.isBlank(cdmlibServicesLastModified) || StringUtils.isBlank(CdmApplicationState.getCdmlibLastModified())) {
+            throw new CdmSourceException("cdmlib-services server or editor version is empty");
+        }
+
+        String cdmServerIgnoreVersion = System.getProperty("cdm.server.version.lm.ignore");
+        if(StringUtils.isBlank(cdmServerIgnoreVersion) || !cdmServerIgnoreVersion.equals("true")) {
+            Long serverLastModified = Long.valueOf(cdmlibServicesLastModified);
+            Long editorLastModified = Long.valueOf(CdmApplicationState.getCdmlibLastModified());
+            return serverLastModified.compareTo(editorLastModified);
+        }
+
+        return 0;
+
+    }
+
     public static List<CdmServerInfo> getCdmServers() {
         if(cdmServerInfoList == null) {
             cdmServerInfoList = new ArrayList<CdmServerInfo>();
index aaf23e9ef04c5d4bcc811f0d4d028b445acd3719..7ce1808ac77d4a8e4b82d6a9c678e0472c412c04 100644 (file)
@@ -30,7 +30,7 @@ public class DefaultNewEntityListener implements NewEntityListener {
      */
     @Override
     public void onCreate(CdmBase cdmBase) {
-        logger.warn("New Entity created : " + cdmBase);
+        logger.info("New Entity created : " + cdmBase);
         if(CdmApplicationState.getCurrentAppConfig() instanceof CdmApplicationRemoteController){
             ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession().addNewCdmEntity(cdmBase);
         }
index 9d56c4da20b24f83f9f42584aad443c123ce5b97..0a6b84b3227e8a074ab213156fa04e37ea7e2579 100644 (file)
@@ -9,10 +9,13 @@
  */
 package eu.etaxonomy.taxeditor.ui.dialog;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
@@ -44,6 +47,8 @@ import org.eclipse.wb.swt.SWTResourceManager;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
@@ -76,6 +81,11 @@ public class RemotingLoginDialog extends Dialog {
     private final static String STATUS_NO_INSTANCES = "No Instances Found";
     private final static String STATUS_ERROR = "Error";
     private final static String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
+    private final static String STATUS_NOT_COMPATIBLE = "Not Compatible";
+
+    private final static String MESG_COMPATIBLE_EDITOR_OLD = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server";
+    private final static String MESG_COMPATIBLE_SERVER_OLD = "Please update the chosen cdm-server or choose a compatible cdm-server";
+
     private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store";
 
     private final static String LOGIN_NODE = "login";
@@ -108,7 +118,7 @@ public class RemotingLoginDialog extends Dialog {
 
     private final int MIN_WIDTH = 530;
     private final int MIN_HEIGHT = 220;
-    private final int MIN_EXP_HEIGHT = 350;
+    private final int MIN_EXP_HEIGHT = 380;
     private final int MESSAGE_HEIGHT = 25;
     private Label lblEditorVersion;
     private Text txtEditorVersion;
@@ -163,6 +173,7 @@ public class RemotingLoginDialog extends Dialog {
             readPrefLastServerInstance();
         }
 
+        setEditorInfo();
         populateCdmServerCombo();
         shlConnect.open();
         shlConnect.layout();
@@ -385,11 +396,10 @@ public class RemotingLoginDialog extends Dialog {
 
         lblServerVersion = new Label(compAdvanced, SWT.CENTER);
         lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
-        lblServerVersion.setText("Server Version :");
+        lblServerVersion.setText("Server Cdmlib Version :");
         lblServerVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
 
         txtServerVersion = new Text(compAdvanced, SWT.BORDER);
-        txtServerVersion.setEnabled(false);
         txtServerVersion.setEditable(false);
         txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
         new Label(compAdvanced, SWT.NONE);
@@ -397,11 +407,10 @@ public class RemotingLoginDialog extends Dialog {
 
         lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
         lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
-        lblEditorVersion.setText("Editor Version :");
+        lblEditorVersion.setText("Editor Cdmlib Version :");
         lblEditorVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
 
         txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
-        txtEditorVersion.setEnabled(false);
         txtEditorVersion.setEditable(false);
         txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
         new Label(compAdvanced, SWT.NONE);
@@ -413,7 +422,6 @@ public class RemotingLoginDialog extends Dialog {
         lblServerCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
 
         txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
-        txtServerCDMVersion.setEnabled(false);
         txtServerCDMVersion.setEditable(false);
         txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
         new Label(compAdvanced, SWT.NONE);
@@ -425,7 +433,6 @@ public class RemotingLoginDialog extends Dialog {
         lblEditorCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
 
         txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
-        txtEditorCDMVersion.setEnabled(false);
         txtEditorCDMVersion.setEditable(false);
         txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
 
@@ -511,9 +518,7 @@ public class RemotingLoginDialog extends Dialog {
 
     private void checkSelectedCdmServer() {
 
-        txtCdmInstanceStatus.setText("");
-        txtPort.setEditable(false);
-        txtPort.setEnabled(false);
+        clearOnServerChange();
         emptyCredentials();
 
         if(selectedCsii != null) {
@@ -524,6 +529,8 @@ public class RemotingLoginDialog extends Dialog {
             if(selectedCsii.pingServer()) {
                 txtCdmServerStatus.setText(STATUS_AVAILABLE);
                 populateCdmInstanceCombo(true);
+                txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion());
+                txtServerVersion.setToolTipText(generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified()));
 
             } else {
                 txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
@@ -538,6 +545,7 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmInstance.setEnabled(false);
         btnConnect.setEnabled(false);
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
+        txtCdmInstanceStatus.setToolTipText("");
 
         Job job = new Job("Retrieve Server Instances") {
             @Override
@@ -579,12 +587,13 @@ public class RemotingLoginDialog extends Dialog {
                             }
                         });
                     }
-                } catch (CDMServerException e) {
+                } catch (final CDMServerException e) {
                     MessagingUtils.warn(getClass(), e);
                     Display.getDefault().asyncExec(new Runnable() {
                         @Override
                         public void run() {
-                            txtCdmInstanceStatus.setText(STATUS_REMOTING_NOT_ACTIVATED);
+                            txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
+                            txtCdmInstanceStatus.setToolTipText(e.getMessage());
                             comboCdmInstance.setEnabled(false);
                             btnConnect.setEnabled(false);
                         }
@@ -603,6 +612,7 @@ public class RemotingLoginDialog extends Dialog {
 
     private void refreshCdmInstance() {
         txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
+        clearOnInstanceChange();
         updateSelectedCdmInstance();
         checkSelectedCdmInstance();
     }
@@ -618,19 +628,52 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private void checkSelectedCdmInstance() {
+        boolean available = false;
+        String status = STATUS_NOT_AVAILABLE;
+        String message = null;
+
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
             try {
                 if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
-                    txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
-                    btnConnect.setEnabled(true);
+                    status = STATUS_AVAILABLE;
+                    available = true;
                 } else {
-                    txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                    btnConnect.setEnabled(false);
+                    status = STATUS_NOT_AVAILABLE;
+                    available = false;
+                }
+
+                if(available) {
+                    txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
+                    int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
+                    int compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
+
+                    if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
+                        status =  STATUS_NOT_COMPATIBLE;
+                        available = false;
+                        message = MESG_COMPATIBLE_EDITOR_OLD;
+                    } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
+                        status = STATUS_NOT_COMPATIBLE;
+                        available = false;
+                        message = MESG_COMPATIBLE_SERVER_OLD;
+                    } else {
+                        status =  STATUS_AVAILABLE;
+                        available = true;
+                        message = "";
+                    }
+
+
                 }
+
             } catch (Exception e) {
-                txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
                 txtCdmInstanceStatus.setToolTipText(e.getMessage());
+            } finally {
+                btnConnect.setEnabled(available);
+                txtCdmInstanceStatus.setText(status);
+                if(!StringUtils.isBlank(message)) {
+                    setMessage(message);
+                }
             }
+
         }
 
     }
@@ -751,18 +794,25 @@ public class RemotingLoginDialog extends Dialog {
             styledTxtMessage.setText(message);
             styledTxtMessage.setVisible(true);
             ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
-            shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
-            shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
+            shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
         } else {
             styledTxtMessage.setText("");
             styledTxtMessage.setVisible(false);
             ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
-            shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
-            shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
+            shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
+            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
         }
         remotingComposite.layout();
     }
 
+    private int getHeightWithoutMessage() {
+        if(xpndblcmpstAdvanced.isExpanded()) {
+            return MIN_EXP_HEIGHT;
+        } else {
+            return MIN_HEIGHT;
+        }
+    }
 
 
     public void hide(boolean isHidden) {
@@ -790,4 +840,41 @@ public class RemotingLoginDialog extends Dialog {
             }
         });
     }
+
+    private String generateLastModifiedTooltip(String cdmlibLastModified) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
+        Date cdmlibLastModifiedDate;
+        String cdmlibLastModifiedTimestamp = "";
+
+        cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
+        cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
+
+        return "last modified : " + cdmlibLastModifiedTimestamp;
+    }
+
+    private void setEditorInfo() {
+        txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
+        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion());
+        txtEditorVersion.setToolTipText(generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified()));
+    }
+
+    private void clearOnServerChange() {
+        setMessage("");
+        txtServerCDMVersion.setText("");
+        txtServerVersion.setText("");
+        txtServerVersion.setToolTipText("");
+        txtServerCDMVersion.setText("");
+        txtPort.setEditable(false);
+        txtPort.setEnabled(false);
+    }
+
+    private void clearOnInstanceChange() {
+        setMessage("");
+        txtServerCDMVersion.setText("");
+    }
+
+    private void updateOnServerChange(String serverVersion, String serverVersionTooltip) {
+
+    }
+
 }
index baafa0718bc7ad2f5f105601127ab043aad17b5a..77fc90f0c62a1d8358dcab51a69af5e7df339fc6 100644 (file)
@@ -193,7 +193,6 @@ public class TaxonNameEditorTest extends BaseOperationTest {
         Taxon grandChildTaxon = Taxon.NewInstance(null, null);
         TaxonNode grandChildTaxonNode = childTaxonNode.addChildTaxon(grandChildTaxon, null, null);
 
-
         CdmStore.getService(ITaxonNodeService.class).merge(taxonNode,true);
 
         Assert.assertEquals(taxonNode.getChildNodes().get(0).getId(), childTaxonNode.getId());
diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmApplicationStateTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmApplicationStateTest.java
new file mode 100644 (file)
index 0000000..f09d37a
--- /dev/null
@@ -0,0 +1,31 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* 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.
+*/
+package eu.etaxonomy.taxeditor.session;
+
+import org.junit.Test;
+import org.springframework.util.Assert;
+import org.unitils.UnitilsJUnit4;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+
+/**
+ * @author cmathew
+ * @date 5 Oct 2015
+ *
+ */
+public class CdmApplicationStateTest extends UnitilsJUnit4 {
+
+    @Test
+    public void testCdmlibManifestInfoUpdate() {
+        CdmApplicationState.updateCdmlibManifestInfo();
+        Assert.notNull(CdmApplicationState.getCdmlibVersion());
+        Assert.notNull(CdmApplicationState.getCdmlibLastModified());
+    }
+}