Fix for ticket #4519
authorCherian Mathew <c.mathew@bgbm.org>
Wed, 10 Dec 2014 11:13:17 +0000 (11:13 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Wed, 10 Dec 2014 11:13:17 +0000 (11:13 +0000)
CdmDataSourceRepository : added a new method to create default h2 data source
eu.etaxonomy.taxeditor.cdmlib : updated build paths to output test classes in test-classes dir and moved resources package to avoid conflict
ApplicationWorkbenchWindowAdvisor : added call to the new method (above) to create a default H2 db

.gitattributes
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
eu.etaxonomy.taxeditor.cdmlib/.classpath
eu.etaxonomy.taxeditor.cdmlib/src/test/resources/eu/etaxonomy/cdm/datasources/cdm.datasources.xml [moved from eu.etaxonomy.taxeditor.cdmlib/src/test/resources/eu/etaxonomy/cdm/cdm.datasources.xml with 100% similarity]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java

index 71c5387eb332675aaaadad5f6d39c940770363d6..69b4e54cd9af2d5e10ad64ca1f94d5de2027ed31 100644 (file)
@@ -345,7 +345,7 @@ eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/localApplicati
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_persistence_security.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_services_security.xml -text
-eu.etaxonomy.taxeditor.cdmlib/src/test/resources/eu/etaxonomy/cdm/cdm.datasources.xml -text
+eu.etaxonomy.taxeditor.cdmlib/src/test/resources/eu/etaxonomy/cdm/datasources/cdm.datasources.xml -text
 eu.etaxonomy.taxeditor.editor/.classpath -text
 eu.etaxonomy.taxeditor.editor/.project -text
 eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF -text
index 5e597395afce03c467d8f912fc5c1d0419fa6869..a4d2e6816dc5452ab1f36ae1b54eeadeb5d4852f 100644 (file)
@@ -7,6 +7,7 @@ import org.eclipse.ui.application.IActionBarConfigurer;
 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
 
+import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
@@ -48,6 +49,8 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
                configurer.setShowPerspectiveBar(true);
                configurer.setTitle("EDIT Taxonomic Editor " + ApplicationUtil.getVersion());
                configurer.setShowProgressIndicator(true);
+
+               CdmDataSourceRepository.createDefaultH2DataSource();
        }
 
        /**
@@ -57,6 +60,8 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
     public void postWindowOpen() {
                PreferencesUtil.checkNomenclaturalCode();
 
+
+
                if(PreferencesUtil.shouldConnectAtStartUp()) {
             CdmStore.connect();
         }
index e2ce3e2f35b640b8802f33f80c2209f4ca15a792..b6b790eab0f0048770a9a2bf5ff715fadc59eee3 100644 (file)
@@ -2,10 +2,10 @@
 <classpath>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-       <classpathentry kind="src" path="src/main/java"/>
-       <classpathentry kind="src" path="src/test/java"/>
-       <classpathentry kind="src" path="src/main/resources"/>
-       <classpathentry kind="src" path="src/test/resources"/>
+       <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+       <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
+       <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
+       <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
        <classpathentry exported="true" kind="lib" path="lib/activation-1.1.1.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/antlr-2.7.7.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/aopalliance-1.0.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.4.0-SNAPSHOT-sources.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.4.0-SNAPSHOT.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.4.0-SNAPSHOT-sources.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.4.0-SNAPSHOT.jar" />
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.4.0-SNAPSHOT.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-print-3.4.0-SNAPSHOT-sources.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-print-3.4.0-SNAPSHOT.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-remote-3.4.0-SNAPSHOT-sources.jar"/>
index da13e5e869cc8c62ba2fa8091682835fcd7df862..d676ca2a2ace038346efb62bceadab981bee56e5 100644 (file)
@@ -45,18 +45,18 @@ public class CdmDataSourceRepository{
        private static final String CURRENT_DATASOURCE = "currentDataSource";
        private static final String CURRENT_DATASOURCE_POSTFIX = "currentDataSourcePostFix";
        private static final String DEFAULT_DATASOURCE_STATE_FILENAME = "datasource.xml";
-       
+
        private static final String DEFAULT_DATASOURCE_NAME = "cdm";
        private static final String DEFAULT_DATASOURCE_POSTFIX = CdmPersistentDataSource.DATASOURCE_BEAN_POSTFIX;
-       
+
        private static ICdmSource currentCdmSource;
        private static IMemento memento;
-       
+
        private static String lastUsedCdmSourceName;
        private static String lastUsedCdmSourcePostFix;
-       
-       
-       
+
+
+
        /**
         * <p>Getter for the field <code>lastUsedDataSourceName</code>.</p>
         *
@@ -64,12 +64,12 @@ public class CdmDataSourceRepository{
         */
        public static void updateLastUsedDataSource(){
                if(lastUsedCdmSourceName == null){
-                       memento = readMemento();                
+                       memento = readMemento();
                        lastUsedCdmSourceName = memento != null ? memento.getString(CURRENT_DATASOURCE) : DEFAULT_DATASOURCE_NAME;
                        lastUsedCdmSourcePostFix = memento != null ? memento.getString(CURRENT_DATASOURCE_POSTFIX) : DEFAULT_DATASOURCE_POSTFIX;
-                       
+
                }
-               
+
        }
 
        /**
@@ -83,7 +83,7 @@ public class CdmDataSourceRepository{
                return true;
        }
 
-       
+
        /**
         * <p>getAll</p>
         *
@@ -91,7 +91,7 @@ public class CdmDataSourceRepository{
         */
        public static List<ICdmSource> getAll() {
                List<ICdmSource> remoteSources = new ArrayList<ICdmSource>();
-               
+
                for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){
                        try {
                                remoteSources.add(CdmPersistentDataSource.NewInstance(dataSource.getName()));
@@ -99,20 +99,20 @@ public class CdmDataSourceRepository{
                                MessagingUtils.error(CdmDataSourceRepository.class, "Could not find dataSource", e);
                        }
                }
-               
+
                try {
-                       for(ICdmRemoteSource remoteSource : CdmPersistentRemoteSource.getAllRemoteSources()){                   
+                       for(ICdmRemoteSource remoteSource : CdmPersistentRemoteSource.getAllRemoteSources()){
                                remoteSources.add(remoteSource);
                        }
                } catch (CdmRemoteSourceException e) {
                        MessagingUtils.error(CdmDataSourceRepository.class, "Error retrieving remote sources", e);
                }
-               
+
                // TODO sort by database name
-               
+
                return remoteSources;
        }
-       
+
        /**
         * <p>getDataSource</p>
         *
@@ -120,7 +120,7 @@ public class CdmDataSourceRepository{
         * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
         */
        public static ICdmDataSource getDataSource(String name){
-               
+
                for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){
                        try {
                                if(dataSource.getName().equals(name)){
@@ -130,22 +130,22 @@ public class CdmDataSourceRepository{
                                MessagingUtils.error(CdmDataSourceRepository.class, "Could not find dataSource", e);
                        }
                }
-               
+
                return null;
        }
-       
-               
+
+
        /**
         * <p>Getter for the field <code>currentDataSource</code>.</p>
         *
         * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
-        * @throws CdmRemoteSourceException 
+        * @throws CdmRemoteSourceException
         */
        public static ICdmSource getCurrentCdmSource() throws CdmRemoteSourceException {
-               
+
                if (currentCdmSource == null) {
                        updateLastUsedDataSource();
-                       
+
                        if(lastUsedCdmSourceName == null) {
                                return null;
                        }
@@ -155,12 +155,9 @@ public class CdmDataSourceRepository{
                                        currentCdmSource = CdmPersistentDataSource.NewInstance(lastUsedCdmSourceName);
                                } catch (DataSourceNotFoundException e) {
                                        // fallback creates a new default
-                                       ICdmDataSource h2DataSource = CdmDataSource.NewH2EmbeddedInstance(
-                                                       DEFAULT_DATASOURCE_NAME, "sa", "", PreferencesUtil.getPreferredNomenclaturalCode());
-                                       save(h2DataSource.getName(), h2DataSource);
-                                       setCurrentCdmSource(h2DataSource);
+                                       setCurrentCdmSource(createDefaultH2DataSource());
                                }
-                       } else if (lastUsedCdmSourcePostFix.equals(CdmPersistentRemoteSource.REMOTESOURCE_BEAN_POSTFIX)) {                              
+                       } else if (lastUsedCdmSourcePostFix.equals(CdmPersistentRemoteSource.REMOTESOURCE_BEAN_POSTFIX)) {
                                currentCdmSource = CdmPersistentRemoteSource.NewInstance(lastUsedCdmSourceName);
                        } else {
                                throw new CdmRemoteSourceException("Unkown Cdm Source Type");
@@ -168,7 +165,19 @@ public class CdmDataSourceRepository{
                }
                return currentCdmSource;
        }
-       
+
+       /**
+        * Creates a default H2 CDM Data Source
+        *
+        * @return the newly created data source
+        */
+       public static ICdmDataSource createDefaultH2DataSource() {
+           ICdmDataSource h2DataSource = CdmDataSource.NewH2EmbeddedInstance(
+                DEFAULT_DATASOURCE_NAME, "sa", "", PreferencesUtil.getPreferredNomenclaturalCode());
+        save(h2DataSource.getName(), h2DataSource);
+        return h2DataSource;
+       }
+
        /**
         * <p>Setter for the field <code>currentDataSource</code>.</p>
         *
@@ -179,7 +188,7 @@ public class CdmDataSourceRepository{
                currentCdmSource = cdmSource;
                NomenclaturalCode dataSourceNomenclaturalCode = cdmSource.getNomenclaturalCode();
                NomenclaturalCode applicationNomenclaturalCode = PreferencesUtil.getPreferredNomenclaturalCode();
-               
+
                if( dataSourceNomenclaturalCode != null && ! dataSourceNomenclaturalCode.equals(applicationNomenclaturalCode)){
                        PreferencesUtil.setPreferredNomenclaturalCode(dataSourceNomenclaturalCode);
                        MessagingUtils.informationDialog("Nomenclatural Code Change", "The Datasource that was just " +
@@ -187,8 +196,8 @@ public class CdmDataSourceRepository{
                                        "The nomenclatural code was changed in the application.");
                }
                return true;
-       }       
-               
+       }
+
        /**
         * <p>changeDataSource</p>
         *
@@ -196,9 +205,9 @@ public class CdmDataSourceRepository{
         * @return a boolean.
         */
        public static boolean changeDataSource(final ICdmSource cdmSource) {
-               saveAsCurrentDatabaseToMemento(cdmSource);              
+               saveAsCurrentDatabaseToMemento(cdmSource);
                CdmStore.connect(cdmSource);
-               
+
                return true;
        }
 
@@ -208,24 +217,24 @@ public class CdmDataSourceRepository{
         * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
         * @param strDataSourceName a {@link java.lang.String} object.
         * @return a {@link eu.etaxonomy.cdm.database.CdmPersistentDataSource} object.
-        * @throws CdmRemoteSourceException 
+        * @throws CdmRemoteSourceException
         */
        public static ICdmPersistentSource save(String strCdmSourceName, ICdmRemoteSource cdmSource) throws CdmRemoteSourceException {
-               return CdmPersistentRemoteSource.save(strCdmSourceName, cdmSource);             
+               return CdmPersistentRemoteSource.save(strCdmSourceName, cdmSource);
        }
-       
+
        /**
         * <p>save</p>
         *
         * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
         * @param strDataSourceName a {@link java.lang.String} object.
         * @return a {@link eu.etaxonomy.cdm.database.CdmPersistentDataSource} object.
-        * @throws CdmRemoteSourceException 
+        * @throws CdmRemoteSourceException
         */
-       public static ICdmPersistentSource save(String strCdmSourceName, ICdmDataSource cdmSource)  {           
-               return CdmPersistentDataSource.save(strCdmSourceName, cdmSource);                               
+       public static ICdmPersistentSource save(String strCdmSourceName, ICdmDataSource cdmSource)  {
+               return CdmPersistentDataSource.save(strCdmSourceName, cdmSource);
        }
-       
+
        /**
         * <p>update</p>
         *
@@ -241,7 +250,7 @@ public class CdmDataSourceRepository{
                }
                return null;
        }
-       
+
        public static ICdmPersistentSource replace(String strCdmSourceName, ICdmDataSource cdmSource){
                try {
                        return CdmPersistentDataSource.replace(strCdmSourceName, cdmSource);
@@ -250,7 +259,7 @@ public class CdmDataSourceRepository{
                }
                return null;
        }
-       
+
        /**
         * <p>update</p>
         *
@@ -260,35 +269,35 @@ public class CdmDataSourceRepository{
         */
        public static ICdmPersistentSource update(String strCdmSourceName, ICdmRemoteSource cdmSource){
                try {
-                       return CdmPersistentRemoteSource.update(strCdmSourceName, cdmSource);   
+                       return CdmPersistentRemoteSource.update(strCdmSourceName, cdmSource);
                } catch (Exception e) {
                        MessagingUtils.error(CdmDataSourceRepository.class, "Error updating CDM Source", e);
-                       
+
                }
                return null;
        }
-       
+
        /*********************************************************
         * Memento Handling                                                                              *
         *********************************************************/
-       
+
        private static void saveAsCurrentDatabaseToMemento(ICdmSource cdmSource){
                if(memento == null) {
                        memento = readMemento();
                }
                memento.putString(CURRENT_DATASOURCE, cdmSource.getName());
-               
+
                // Set postfix to distinguish between data and remote sources
                if(cdmSource instanceof CdmPersistentRemoteSource) {
                        memento.putString(CURRENT_DATASOURCE_POSTFIX, CdmPersistentRemoteSource.REMOTESOURCE_BEAN_POSTFIX);
                } else {
                        memento.putString(CURRENT_DATASOURCE_POSTFIX, CdmPersistentDataSource.DATASOURCE_BEAN_POSTFIX);
                }
-               
-               
+
+
                saveMementoToFile(memento);
        }
-       
+
        /*
         * Answer the workbench state file.
         */
@@ -300,7 +309,7 @@ public class CdmDataSourceRepository{
                path = path.append(DEFAULT_DATASOURCE_STATE_FILENAME);
                return path.toFile();
        }
-       
+
        private static IMemento readMemento(){
                try {
                        return MementoHelper.readMementoFromFile(getCdmSourceStateFile());
@@ -308,14 +317,14 @@ public class CdmDataSourceRepository{
                        return initializeMemento();
                }
        }
-       
+
 
        private static IMemento initializeMemento() {
-               
+
                XMLMemento memento = XMLMemento.createWriteRoot(TAG_DATASOURCE);
                memento.putString(CURRENT_DATASOURCE, DEFAULT_DATASOURCE_NAME);
                saveMementoToFile(memento);
-               
+
                return readMemento();
        }
 
@@ -324,5 +333,5 @@ public class CdmDataSourceRepository{
         */
        private static IMemento saveMementoToFile(IMemento memento) {
                return MementoHelper.saveMementoToFile(memento, getCdmSourceStateFile());
-       }       
+       }
 }