Project

General

Profile

Revision 5666c59e

ID5666c59e03073f5bbc982cb681203fb4ba177946
Parent e692bd79
Child 3b929c99

Added by Andreas Kohlbecker 3 months ago

fix #9023 implementing stratup option cdm.forceSchemaCreate with integration test:
- CdmDatabaseException as RuntimeException for all sever db connection problems
- web service for CDM Metadata
- integration test for data base creation as optional maven profile

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/CdmDatabaseException.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.database;
10

  
11
import eu.etaxonomy.cdm.config.CdmSourceException;
12

  
13
/**
14
 * RuntimeException which is thrown in case of severe problems with the configured
15
 * CDM database which prevent the application from starting up. Other less severe problems
16
 * should be reported using {@link CdmSourceException}.
17
 *
18
 * @author a.kohlbecker
19
 * @date May 18, 2020
20
 *
21
 */
22
public class CdmDatabaseException extends RuntimeException {
23

  
24

  
25
    public CdmDatabaseException(String string) {
26
        super(string);
27
    }
28

  
29
    public CdmDatabaseException(String string, Throwable t) {
30
        super(string, t);
31
    }
32

  
33

  
34
    private static final long serialVersionUID = 1L;
35

  
36
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/CaseType.java
13 13
import java.util.regex.Matcher;
14 14
import java.util.regex.Pattern;
15 15

  
16
import eu.etaxonomy.cdm.database.CdmDatabaseException;
16 17
import eu.etaxonomy.cdm.database.ICdmDataSource;
17 18

  
18 19
/**
......
67 68
				try {
68 69
					datasource.executeQuery(sql+ "cdmmetadata");
69 70
				} catch (SQLException e2) {
70
					throw new RuntimeException("Case type (camel, upper, lower) of the database could be defined. Maybe the CdmMetaData table is missing in the datasource", e2);
71
					throw new CdmDatabaseException("Case type (camel, upper, lower) of the database could be defined. Maybe the CdmMetaData table is missing in the datasource", e2);
71 72
				}
72 73
				return CaseType.LowerCase;
73 74
			}
cdmlib-remote-webapp/pom.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 5
  <modelVersion>4.0.0</modelVersion>
4 6
  <parent>
5 7
    <artifactId>cdmlib-parent</artifactId>
......
7 9
    <version>5.15.0-SNAPSHOT</version>
8 10
    <relativePath>../pom.xml</relativePath>
9 11
  </parent>
10

  
11
  <groupId>eu.etaxonomy</groupId>
12
  <artifactId>cdmlib-remote-webapp</artifactId>  
12
  <artifactId>cdmlib-remote-webapp</artifactId>
13 13
  <name>CDM Remote Webapp</name>
14 14
  <packaging>war</packaging>
15 15

  
16 16
  <properties>
17 17
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
    <!-- by default 
19
      no further args by now, see profiles for alternative run configurations -->
18 20
  </properties>
19 21

  
20 22
  <profiles>
......
40 42
        </repository>
41 43
      </repositories>
42 44
    </profile>
45
    <!-- ========================= PROFILE : db-create ========================= -->
46
    <profile>
47
      <id>db-create</id>
48
      <activation>
49
        <property>
50
          <name>db-create</name>
51
        </property>
52
      </activation>
53
      <properties>
54
        <integrationTest.jvmArgs.cdm.datasource>h2_cdm_blank</integrationTest.jvmArgs.cdm.datasource>
55
        <integrationTest.jvmArgs.cdm.forceSchemaCreate>true</integrationTest.jvmArgs.cdm.forceSchemaCreate>
56
        <integrationTest.log4j.configuration>${project.build.directory}/target/test-classes/log4j.properties</integrationTest.log4j.configuration>
57
      </properties>
58
      <build>
59
        <plugins>
60
          <plugin>
61
            <artifactId>maven-failsafe-plugin</artifactId>
62
            <version>2.16</version>
63
            <configuration>
64
              <forkCount>3</forkCount>
65
              <reuseForks>true</reuseForks>
66
            </configuration>
67
            <executions>
68
              <execution>
69
                <goals>
70
                  <goal>integration-test</goal>
71
                  <goal>verify</goal>
72
                </goals>
73
                <configuration>
74
                  <includes>
75
                    <include>**/ForceSchemaCreateIT.java</include>
76
                  </includes>
77
                </configuration>
78
              </execution>
79
            </executions>
80
          </plugin>
81
        </plugins>
82
      </build>
83
    </profile>
84
    <!-- ========================= DEFAULT-PROFILE : db-use ========================= -->
85
     <profile>
86
      <id>db-use</id>
87
      <activation>
88
        <activeByDefault>true</activeByDefault>
89
        <property>
90
          <name>db-use</name>
91
        </property>
92
      </activation>
93
      <properties>
94
        <integrationTest.jvmArgs.cdm.datasource>h2_cdmTest</integrationTest.jvmArgs.cdm.datasource>
95
        <integrationTest.jvmArgs.cdm.forceSchemaCreate>false</integrationTest.jvmArgs.cdm.forceSchemaCreate>
96
        <integrationTest.log4j.configuration>${project.build.directory}/target/test-classes/log4j.properties</integrationTest.log4j.configuration>
97
      </properties>
98
      <build>
99
        <plugins>
100
          <plugin>
101
            <artifactId>maven-failsafe-plugin</artifactId>
102
            <version>2.16</version>
103
            <configuration>
104
              <forkCount>3</forkCount>
105
              <reuseForks>true</reuseForks>
106
            </configuration>
107
            <executions>
108
              <execution>
109
                <goals>
110
                  <goal>integration-test</goal>
111
                  <goal>verify</goal>
112
                </goals>
113
                <configuration>
114
                  <systemPropertyVariables>
115
                    <cdm.datasource>h2_cdmTest</cdm.datasource>
116
                  </systemPropertyVariables>
117
                  <excludes>
118
                    <exclude>**/ForceSchemaCreateIT.java</exclude>
119
                  </excludes>
120
                </configuration>
121
              </execution>
122
            </executions>
123
          </plugin>
124
        </plugins>
125
      </build>
126
    </profile>
43 127
  </profiles>
44

  
45 128
  <dependencies>
46 129
    <dependency>
47 130
      <groupId>eu.etaxonomy</groupId>
48 131
      <artifactId>cdmlib-remote</artifactId>
49 132
      <exclusions>
50
        <!-- 
51
            exclude all jdbc drivers from the war. 
52
            Jdbc drivers must only be added to {APPLICATION_CONTAINER}/lib
53
            see http://dev.e-taxonomy.eu/trac/ticket/4955 
54
            and http://stackoverflow.com/questions/6981564/why-must-the-jdbc-driver-be-put-in-tomcat-home-lib-folder
55
         -->
133
        <!-- exclude all jdbc drivers from the war. Jdbc drivers must only 
134
          be added to {APPLICATION_CONTAINER}/lib see http://dev.e-taxonomy.eu/trac/ticket/4955 
135
          and http://stackoverflow.com/questions/6981564/why-must-the-jdbc-driver-be-put-in-tomcat-home-lib-folder -->
56 136
        <exclusion>
57
            <groupId>eu.etaxonomy</groupId>
58
            <artifactId>cdmlib-db</artifactId>
137
          <groupId>eu.etaxonomy</groupId>
138
          <artifactId>cdmlib-db</artifactId>
59 139
        </exclusion>
60 140
      </exclusions>
61 141
    </dependency>
......
64 144
      <artifactId>commons-io</artifactId>
65 145
    </dependency>
66 146
    <dependency>
67
        <groupId>eu.etaxonomy</groupId>
68
        <artifactId>cdmlib-test</artifactId>      
69
        <scope>test</scope>
147
      <groupId>eu.etaxonomy</groupId>
148
      <artifactId>cdmlib-test</artifactId>
149
      <scope>test</scope>
70 150
    </dependency>
71 151
    <dependency>
72
      <!-- TODO this is also offered by cdmlib-remote, can it be removed?
152
      <!-- TODO this is also offered by cdmlib-remote, can it be removed? 
73 153
        What does provided mean? -->
74 154
      <groupId>javax.servlet</groupId>
75 155
      <artifactId>javax.servlet-api</artifactId>
......
81 161
      <artifactId>xmlunit</artifactId>
82 162
    </dependency>
83 163
    <!-- JsonView -->
84
    <!-- 
85
     -->
164
    <!-- -->
86 165
    <dependency>
87 166
      <groupId>org.springframework</groupId>
88 167
      <artifactId>spring-oxm</artifactId>
89 168
    </dependency>
90 169

  
91
    <!-- XmlView 
92
    -->
170
    <!-- XmlView -->
93 171
    <dependency>
94 172
      <groupId>com.thoughtworks.xstream</groupId>
95 173
      <artifactId>xstream</artifactId>
......
121 199
      <artifactId>springfox-swagger2</artifactId>
122 200
      <scope>test</scope>
123 201
    </dependency>
124
    <!-- 
125
        dependencies for springfox-swagger2, added explicitly to pin the version
126
        these dependencies are also required by the cdmlib!  
127
    -->
202
    <!-- dependencies for springfox-swagger2, added explicitly to pin the 
203
      version these dependencies are also required by the cdmlib! -->
128 204
    <dependency>
129 205
      <groupId>com.fasterxml.jackson.core</groupId>
130 206
      <artifactId>jackson-databind</artifactId>
......
138 214
      <artifactId>jackson-annotations</artifactId>
139 215
    </dependency>
140 216
    <!-- END of dependencies for swagger-springmvc, added explicitely -->
141
    
217

  
142 218
    <!-- testing -->
143 219
    <dependency>
144 220
      <groupId>junit</groupId>
......
152 228
      <artifactId>hibernate-c3p0</artifactId>
153 229
      <scope>test</scope>
154 230
    </dependency>
155
<!--     <dependency> -->
156
<!--         <groupId>com.mchange</groupId> -->
157
<!--         <artifactId>c3p0</artifactId> -->
158
<!--         <scope>test</scope> -->
159
<!--     </dependency> -->
160
      <!-- Profiling -->
161
      <dependency>
231
    <!-- <dependency> -->
232
    <!-- <groupId>com.mchange</groupId> -->
233
    <!-- <artifactId>c3p0</artifactId> -->
234
    <!-- <scope>test</scope> -->
235
    <!-- </dependency> -->
236
    <!-- Profiling -->
237
    <dependency>
162 238
      <groupId>com.yourkit</groupId>
163 239
      <artifactId>yjp-controller-api-redist</artifactId>
164 240
      <scope>test</scope>
......
170 246
      <resource>
171 247
        <!-- replace the place holders like ${...} in datasources.xml -->
172 248
        <filtering>true</filtering>
173
		<directory>src/test/resources</directory>
249
        <directory>src/test/resources</directory>
174 250
        <targetPath>../test-classes</targetPath>
175 251
        <includes>
176 252
          <include>datasources.xml</include>
......
193 269
      <plugin>
194 270
        <artifactId>maven-failsafe-plugin</artifactId>
195 271
        <version>2.16</version>
196
        <configuration>
197
          <forkCount>3</forkCount>
198
          <reuseForks>true</reuseForks>
199
        </configuration>
200
        <executions>
201
          <execution>
202
            <goals>
203
              <goal>integration-test</goal>
204
              <goal>verify</goal>
205
            </goals>
206
          </execution>
207
        </executions>
272
        <!-- configuration per maven profile -->
273
        
274
<!--         <configuration> -->
275
<!--           <forkCount>3</forkCount> -->
276
<!--           <reuseForks>true</reuseForks> -->
277
<!--         </configuration> -->
278
<!--         <executions> -->
279
<!--           <execution> -->
280
<!--             <id>default</id> -->
281
<!--             <goals> -->
282
<!--               <goal>integration-test</goal> -->
283
<!--               <goal>verify</goal> -->
284
<!--             </goals> -->
285
<!--             <configuration> -->
286
<!--               <systemPropertyVariables> -->
287
<!--                 <cdm.datasource>h2_cdmTest</cdm.datasource> -->
288
<!--               </systemPropertyVariables> -->
289
<!--               <excludes> -->
290
<!--                 <exclude>**/ForceSchemaCreateIT.java</exclude> -->
291
<!--               </excludes> -->
292
<!--             </configuration> -->
293
<!--           </execution> -->
294
<!--         </executions> -->
208 295
      </plugin>
209 296
      <plugin>
210 297
        <groupId>org.eclipse.jetty</groupId>
......
215 302
          <stopPort>9199</stopPort>
216 303
          <scanIntervalSeconds>10</scanIntervalSeconds>
217 304
          <useTestScope>true</useTestScope>
218
          <!-- 
219
                jvmArgs will only be used when running mvn jetty:run-forked 
220
          -->
221
          <jvmArgs>-Xmx2000M -Dcdm.datasource=h2_cdmTest -Duser.home=${basedir}/target/target/ -Dcdm.beanDefinitionFile=${project.build.directory}/test-classes/datasources.xml -Dspring.profiles.active=remoting</jvmArgs>
305
          <!-- jvmArgs will only be used when running mvn jetty:run-forked -->
306
          <jvmArgs>-Xmx2000M 
307
            -Dcdm.datasource=${integrationTest.jvmArgs.cdm.datasource}
308
            -Duser.home=${basedir}/target/target/
309
            -Dcdm.beanDefinitionFile=${project.build.directory}/test-classes/datasources.xml
310
            -Dspring.profiles.active=remoting
311
            -Dcdm.forceSchemaCreate=${integrationTest.jvmArgs.cdm.forceSchemaCreate}
312
            -Dlog4j.configuration=${integrationTest.jvmArgs.log4j.configuration}
313
            -Dorg.eclipse.jetty.annotations.AnnotationParser.LEVEL=OFF
314
           </jvmArgs>
222 315
          <jettyXml>${basedir}/src/test/resources/etc/jetty/jetty.xml,${basedir}/src/test/resources/etc/jetty/jetty-http.xml</jettyXml>
223 316
          <!-- <jettyXml>./src/test/resources/etc/jetty/jetty.xml,./src/test/resources/etc/jetty/jetty-http.xml,./src/test/resources/etc/jetty/jetty-ssl.xml,./src/test/resources/etc/jetty/jetty-https.xml</jettyXml> -->
224 317
          <systemProperties>
225 318
            <force>true</force>
226 319
            <systemProperty>
227 320
              <name>cdm.datasource</name>
228
              <value>h2_cdmTest</value>
321
              <value>${integrationTest.jvmArgs.cdm.datasource}</value>
229 322
            </systemProperty>
230 323
            <systemProperty>
231
              <!-- 
232
                The lucene index should be placed into the target folder,
233
                so user.home needs to be set to this folder.
234
                user.home needs to be overriden since it already 
235
                exists, thus the force option is turned on above 
236
              -->
324
              <!-- The lucene index should be placed into the target folder, 
325
                so user.home needs to be set to this folder. user.home needs to be overridden 
326
                since it already exists, thus the force option is turned on above -->
237 327
              <name>user.home</name>
238 328
              <value>${basedir}/target/</value>
239
            </systemProperty>            
329
            </systemProperty>
240 330
            <systemProperty>
241
              <!-- datasources.xml is prepared by <plugins><resources>..</resources>
242
                above -->
331
              <!-- datasources.xml is prepared by <plugins><resources>..</resources> above -->
243 332
              <name>cdm.beanDefinitionFile</name>
244 333
              <value>${project.build.directory}/test-classes/datasources.xml</value>
245 334
            </systemProperty>
246 335
            <systemProperty>
247
                <!--
248
                    start with swagger profile so that the swagger doc 
249
                    can be generated 
250
                 -->
251
                <name>spring.profiles.active</name>
252
                <value>swagger</value>
336
                <name>cdm.forceSchemaCreate</name>
337
                <value>${integrationTest.jvmArgs.cdm.forceSchemaCreate}</value>
338
            </systemProperty>
339
            <systemProperty>
340
              <!-- start with swagger profile so that the swagger doc can 
341
                be generated -->
342
              <name>spring.profiles.active</name>
343
              <value>swagger</value>
344
            </systemProperty>
345
            <systemProperty>
346
                <name>log4j.configuration</name>
347
                <value>${integrationTest.jvmArgs.log4j.configuration}</value>
253 348
            </systemProperty>
254 349
          </systemProperties>
255 350
        </configuration>
......
273 368
            </goals>
274 369
          </execution>
275 370
        </executions>
371
        <dependencies>
372
            <dependency>
373
                    <groupId>org.apache.taglibs</groupId>
374
                    <artifactId>taglibs-standard-impl</artifactId>
375
                    <version>1.2.5</version>
376
            </dependency>
377
        </dependencies>
276 378
      </plugin>
277 379
      <plugin>
278 380
        <groupId>org.apache.maven.plugins</groupId>
279 381
        <artifactId>maven-war-plugin</artifactId>
280 382
        <version>2.6</version>
281 383
        <executions>
282
            <execution>
283
                <!-- 
284
                    The war must be created after running the integration-tests,
285
                    since the SwaggerGroupsIT test populates the classes/api-docs-static/
286
                    folder with static swagger doc files. The are otherwise not packed
287
                     into the war file.
288
                  -->
289
                <phase>verify</phase>
290
                <goals>
291
                  <goal>war</goal>
292
                </goals>
293
            </execution>
384
          <execution>
385
            <!-- The war must be created after running the integration-tests, 
386
              since the SwaggerGroupsIT test populates the classes/api-docs-static/ folder 
387
              with static swagger doc files. The are otherwise not packed into the war 
388
              file. -->
389
            <phase>verify</phase>
390
            <goals>
391
              <goal>war</goal>
392
            </goals>
393
          </execution>
294 394
        </executions>
295 395
      </plugin>
296
	  <plugin>
297
            <artifactId>maven-resources-plugin</artifactId>
298
            <version>2.7</version>
299
            <configuration>
300
                <escapeWindowsPaths>false</escapeWindowsPaths>
301
            </configuration>
302
        </plugin>
396
      <plugin>
397
        <artifactId>maven-resources-plugin</artifactId>
398
        <version>2.7</version>
399
        <configuration>
400
          <escapeWindowsPaths>false</escapeWindowsPaths>
401
        </configuration>
402
      </plugin>
303 403
    </plugins>
304 404
  </build>
305 405
</project>
cdmlib-remote-webapp/src/test/java/eu/etaxonomy/cdm/remote/ClassificationIT.java
24 24
    @Test
25 25
    public void checkInstanceIsOnline(){
26 26
        String response = httpGetJson("classification.json", null);
27
        logger.debug("response: " + response);
27 28
        assertTrue(response.contains("My Classification"));
28 29
    }
29 30

  
cdmlib-remote-webapp/src/test/java/eu/etaxonomy/cdm/remote/ForceSchemaCreateIT.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

  
11
import org.junit.Test;
12

  
13
/**
14
 * @author a.kohlbecker
15
 * @date May 18, 2020
16
 *
17
 */
18
public class ForceSchemaCreateIT extends WebServiceTestBase {
19

  
20
    @Test
21
    public void checkInstanceIsOnline(){
22
        String response = httpGetJson("metadata", null);
23
        logger.debug("response: " + response);
24
        assertTrue(response.contains("DB_SCHEMA_VERSION"));
25
        assertTrue(response.contains("DB_CREATE_DATE"));
26
        // TODO check for DB_CREATE_DATE value no older than 5 minutes
27
    }
28

  
29
}
cdmlib-remote-webapp/src/test/resources/datasources.xml
36 36
        <property name="password" value="" />
37 37
        <property name="jdbcUrl" value="jdbc:h2:file:${project.build.directory}/test-classes/h2/cdmTest"/>
38 38
    </bean>
39
    <bean id="h2_cdm_blank"  lazy-init="true" class="com.mchange.v2.c3p0.ComboPooledDataSource">
40
        <property name="driverClass" value="eu.etaxonomy.cdm.database.LocalH2"/>
41
        <property name="user" value="sa" />
42
        <property name="password" value="" />
43
        <property name="jdbcUrl" value="jdbc:h2:file:${project.build.directory}/test-classes/h2/cdm_blank"/>
44
    </bean>
39 45
</beans>
cdmlib-remote-webapp/src/test/resources/h2/cdm_blank.trace.db
1
2020-05-19 13:51:18 jdbc[3]: exception
2
java.sql.SQLClientInfoException
3
	at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1681)
4
	at org.jkiss.dbeaver.ext.generic.model.GenericDataSource.populateClientAppName(GenericDataSource.java:164)
5
	at org.jkiss.dbeaver.ext.generic.model.GenericDataSource.openConnection(GenericDataSource.java:127)
6
	at org.jkiss.dbeaver.ext.h2.model.H2DataSource.openConnection(H2DataSource.java:74)
7
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext.connect(JDBCExecutionContext.java:95)
8
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCRemoteInstance.initializeMainContext(JDBCRemoteInstance.java:91)
9
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCRemoteInstance.<init>(JDBCRemoteInstance.java:57)
10
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.initializeRemoteInstance(JDBCDataSource.java:110)
11
	at org.jkiss.dbeaver.ext.generic.model.GenericDataSource.<init>(GenericDataSource.java:106)
12
	at org.jkiss.dbeaver.ext.h2.model.H2DataSource.<init>(H2DataSource.java:43)
13
	at org.jkiss.dbeaver.ext.h2.model.H2MetaModel.createDataSourceImpl(H2MetaModel.java:47)
14
	at org.jkiss.dbeaver.ext.generic.GenericDataSourceProvider.openDataSource(GenericDataSourceProvider.java:95)
15
	at org.jkiss.dbeaver.registry.DataSourceDescriptor.connect(DataSourceDescriptor.java:806)
16
	at org.jkiss.dbeaver.runtime.jobs.ConnectJob.run(ConnectJob.java:70)
17
	at org.jkiss.dbeaver.runtime.jobs.ConnectJob.runSync(ConnectJob.java:98)
18
	at org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler.connectToDataSource(DataSourceHandler.java:106)
19
	at org.jkiss.dbeaver.ui.actions.datasource.UIServiceConnectionsImpl.initConnection(UIServiceConnectionsImpl.java:64)
20
	at org.jkiss.dbeaver.model.navigator.DBNDataSource.initializeNode(DBNDataSource.java:150)
21
	at org.jkiss.dbeaver.model.navigator.DBNDatabaseNode.getChildren(DBNDatabaseNode.java:198)
22
	at org.jkiss.dbeaver.model.navigator.DBNDatabaseNode.getChildren(DBNDatabaseNode.java:1)
23
	at org.jkiss.dbeaver.model.navigator.DBNUtils.getNodeChildrenFiltered(DBNUtils.java:70)
24
	at org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadService.evaluate(TreeLoadService.java:49)
25
	at org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadService.evaluate(TreeLoadService.java:1)
26
	at org.jkiss.dbeaver.ui.LoadingJob.run(LoadingJob.java:86)
27
	at org.jkiss.dbeaver.ui.LoadingJob.run(LoadingJob.java:71)
28
	at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:103)
29
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/opt/config/DataSourceConfigurer.java
15 15
import java.sql.Connection;
16 16
import java.sql.ResultSet;
17 17
import java.sql.SQLException;
18
import java.util.Objects;
18 19
import java.util.Properties;
19 20

  
20 21
import javax.naming.NamingException;
......
42 43

  
43 44
import eu.etaxonomy.cdm.api.config.CdmConfigurationKeys;
44 45
import eu.etaxonomy.cdm.config.ConfigFileUtil;
46
import eu.etaxonomy.cdm.database.CdmDatabaseException;
45 47
import eu.etaxonomy.cdm.database.WrappedCdmDataSource;
46 48
import eu.etaxonomy.cdm.database.update.CdmUpdater;
47 49
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
......
129 131
     */
130 132
    public static final String ATTRIBUTE_FORCE_SCHEMA_UPDATE = "cdm.forceSchemaUpdate";
131 133

  
134
    /**
135
     * <b>WARNING!!!!!!!!!!!!!!!</b> Using this option will will the existing data base followed by database creation.
136
     * <p>
137
     * Force a schema creation when the cdmlib-remote-webapp instance is starting up. Will set the hibernate property
138
     * {@code hibernate.hbm2ddl.auto} to {@code create}
139
     * <p>
140
     * This option will inactivate {@link #ATTRIBUTE_FORCE_SCHEMA_UPDATE} even if this is set.
141
     * <p>
142
     * This attribute has no equivalent in <code>eu.etaxonomy.cdm.server.instance.SharedAttributes</code> and never must
143
     * have any since this setting this attribute for any database listed for a server is far too dangerous. It must only
144
     * be possible to set this option per data base individually.
145
     */
146
    public static final String ATTRIBUTE_FORCE_SCHEMA_CREATE = "cdm.forceSchemaCreate";
147

  
132 148
    private static String beanDefinitionFile = null;
133 149

  
134 150

  
......
191 207
        props.setProperty(CDM_DATA_SOURCE_ID, dataSourceId);
192 208
        sources.addFirst(new PropertiesPropertySource("cdm-datasource",  props));
193 209

  
194
        // validate correct schema version
195
        Connection connection  = null;
196
        try {
197

  
198
            connection = dataSource.getConnection();
199
            String metadataTableName = "CdmMetaData";
200
            if(inferHibernateDialectName(dataSource).equals(H2CorrectedDialect.class.getName())){
201
                metadataTableName = metadataTableName.toUpperCase();
202
            }
203
            ResultSet tables = connection.getMetaData().getTables(connection.getCatalog(), null, metadataTableName, null);
204
            if(tables.first()){
205
                ResultSet resultSet;
206
                try {
207
                    resultSet = connection.createStatement().executeQuery(CdmMetaDataPropertyName.DB_SCHEMA_VERSION.getSqlQuery());
208
                } catch (Exception e) {
210
        if(!isForceSchemaCreate()) {
211
            // validate correct schema version
212
            Connection connection  = null;
213
            try {
214
                connection = dataSource.getConnection();
215
                String metadataTableName = "CdmMetaData";
216
                if(inferHibernateDialectName(dataSource).equals(H2CorrectedDialect.class.getName())){
217
                    metadataTableName = metadataTableName.toUpperCase();
218
                }
219
                ResultSet tables = connection.getMetaData().getTables(connection.getCatalog(), null, metadataTableName, null);
220
                if(tables.first()){
221
                    ResultSet resultSet;
209 222
                    try {
210
                        resultSet = connection.createStatement().executeQuery(CdmMetaDataPropertyName.DB_SCHEMA_VERSION.getSqlQueryOld());
211
                    } catch (Exception e1) {
212
                        throw e1;
223
                        resultSet = connection.createStatement().executeQuery(CdmMetaDataPropertyName.DB_SCHEMA_VERSION.getSqlQuery());
224
                    } catch (Exception e) {
225
                        try {
226
                            resultSet = connection.createStatement().executeQuery(CdmMetaDataPropertyName.DB_SCHEMA_VERSION.getSqlQueryOld());
227
                        } catch (Exception e1) {
228
                            throw e1;
229
                        }
230
                    }
231
                    String version = null;
232
                    if(resultSet.next()){
233
                        version = resultSet.getString(1);
234
                    } else {
235
                        CdmDatabaseException cde = new CdmDatabaseException("Unable to retrieve version info from data source " + dataSource.toString()
236
                        + " -  the database may have been corrupted or is not a cdm database");
237
                        addErrorMessageToServletContextAttributes(cde.getMessage());
238
                        throw cde;
239
                    }
240

  
241
                    connection.close();
242

  
243
                    if(!CdmMetaData.isDbSchemaVersionCompatible(version)){
244
                        /*
245
                         * any exception thrown here would be nested into a spring
246
                         * BeanException which can not be caught in the servlet
247
                         * container, so we post the information into the
248
                         * ServletContext
249
                         */
250
                        String errorMessage = "Incompatible version [" + (beanName != null ? beanName : jndiName) + "] expected version: " + CdmMetaData.getDbSchemaVersion() + ",  data base version  " + version;
251
                        addErrorMessageToServletContextAttributes(errorMessage);
213 252
                    }
214
                }
215
                String version = null;
216
                if(resultSet.next()){
217
                    version = resultSet.getString(1);
218 253
                } else {
219
                    throw new RuntimeException("Unable to retrieve version info from data source " + dataSource.toString());
254
                    CdmDatabaseException cde = new CdmDatabaseException("database " + dataSource.toString() + " is empty or not a cdm database");
255
                    logger.error(cde.getMessage());
256
                    // throw cde; // TODO: No exception was thrown here before. Is this correct behavior or
220 257
                }
221 258

  
222
                connection.close();
223

  
224
                if(!CdmMetaData.isDbSchemaVersionCompatible(version)){
225
                    /*
226
                     * any exception thrown here would be nested into a spring
227
                     * BeanException which can not be caught in the servlet
228
                     * container, so we post the information into the
229
                     * ServletContext
230
                     */
231
                    String errorMessage = "Incompatible version [" + (beanName != null ? beanName : jndiName) + "] expected version: " + CdmMetaData.getDbSchemaVersion() + ",  data base version  " + version;
232
                    addErrorMessageToServletContextAttributes(errorMessage);
233
                }
234
            } else {
235
//            	throw new RuntimeException("database " + dataSource.toString() + " is empty or not a cdm database");
236
                logger.error("database " + dataSource.toString() + " is empty or not a cdm database");
237
            }
238 259

  
239 260

  
240
        } catch (SQLException e) {
241
            RuntimeException re =   new RuntimeException("Unable to connect or to retrieve version info from data source " + dataSource.toString() , e);
242
            addErrorMessageToServletContextAttributes(re.getMessage());
243
            throw re;
244
        } finally {
245
            if(connection != null){
246
                try {
247
                    connection.close();
248
                } catch (SQLException e) {
249
                    // IGNORE //
261
            } catch (SQLException e) {
262
                CdmDatabaseException re = new CdmDatabaseException("Unable to connect or to retrieve version info from data source " + dataSource.toString() , e);
263
                addErrorMessageToServletContextAttributes(re.getMessage());
264
                throw re;
265
            } finally {
266
                if(connection != null){
267
                    try {
268
                        connection.close();
269
                    } catch (SQLException e) {
270
                        // IGNORE //
271
                    }
250 272
                }
251
            }
252
        }
273
            } // END // validate correct schema version
274
        } // END !isForceSchemaCreate()
253 275

  
254 276

  
255 277
        String forceSchemaUpdate = findProperty(ATTRIBUTE_FORCE_SCHEMA_UPDATE, false);
256 278
        if(forceSchemaUpdate != null){
257
            logger.info("Update of data source requested by property '" + ATTRIBUTE_FORCE_SCHEMA_UPDATE + "'");
258

  
259
            CdmUpdater updater = CdmUpdater.NewInstance();
260
            WrappedCdmDataSource cdmDataSource = new WrappedCdmDataSource(dataSource);
261
            updater.updateToCurrentVersion(cdmDataSource, null);
262
            cdmDataSource.closeOpenConnections();
279
            if(!isForceSchemaCreate()) {
280
                logger.info("Update of data source requested by property '" + ATTRIBUTE_FORCE_SCHEMA_UPDATE + "'");
281
                CdmUpdater updater = CdmUpdater.NewInstance();
282
                WrappedCdmDataSource cdmDataSource = new WrappedCdmDataSource(dataSource);
283
                updater.updateToCurrentVersion(cdmDataSource, null);
284
                cdmDataSource.closeOpenConnections();
285
            } else {
286
                logger.info("Update of data source requested by property '" + ATTRIBUTE_FORCE_SCHEMA_UPDATE + "' but overwritten by " + ATTRIBUTE_FORCE_SCHEMA_CREATE);
287
            }
263 288
        }
264 289

  
265 290
        return dataSource;
......
358 383
                searchPath +
359 384
                "/index/".replace("/", File.separator) +
360 385
                findProperty(ATTRIBUTE_DATASOURCE_NAME, true));
386
        if(isForceSchemaCreate()) {
387
            props.setProperty("hibernate.hbm2ddl.auto", "create");
388
        }
361 389
        logger.debug("hibernateProperties: " + props.toString());
362 390
        return props;
363 391
    }
364 392

  
393
    private boolean isForceSchemaCreate() {
394
        String propVal = findProperty(ATTRIBUTE_FORCE_SCHEMA_CREATE, false);
395
        logger.debug("System property " + ATTRIBUTE_FORCE_SCHEMA_CREATE +  " = " + Objects.toString(propVal, "[NULL]"));
396
        return propVal != null && !(propVal.toLowerCase().equals("false") || propVal.equals("0"));
397
    }
398

  
365 399
    /**
366 400
     * Returns the full class name of the according {@link org.hibernate.dialect.Dialect} implementation
367 401
     *
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/MetadataController.java
1
// $Id$
2
/**
3
* Copyright (C) 2020 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.cdm.remote.controller;
11

  
12
import java.util.Map;
13

  
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RestController;
18

  
19
import eu.etaxonomy.cdm.api.service.IMetadataService;
20
import eu.etaxonomy.cdm.config.CdmSourceException;
21
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
22
import io.swagger.annotations.Api;
23

  
24
/**
25
 * @author a.kohlbecker
26
 * @date May 19, 2020
27
 *
28
 */
29
@RestController
30
@Api("metadata")
31
@RequestMapping(value = {"/metadata"})
32
public class MetadataController {
33

  
34
    @Autowired
35
    private IMetadataService service;
36

  
37

  
38
    @RequestMapping(method = RequestMethod.GET)
39
    public Map<CdmMetaDataPropertyName, String> getMetadata() throws CdmSourceException {
40
        return service.getCdmMetadataMap();
41
    }
42

  
43
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/MetadataController.java
8 8
*/
9 9
package eu.etaxonomy.cdm.remote.service;
10 10

  
11
import io.swagger.annotations.Api;
12

  
13 11
import java.util.StringTokenizer;
14 12
import java.util.Vector;
15 13

  
......
30 28
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
31 29
import eu.etaxonomy.cdm.model.common.LSID;
32 30
import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
31
import io.swagger.annotations.Api;
33 32

  
34 33
/**
35 34
 * Controller which accepts requests for the metadata representation of an object
......
39 38
 * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
40 39
 * @see com.ibm.lsid.server.servlet.MetadataServlet
41 40
 */
42
@Controller
41
@Controller(value = "lsidMetadataController")
43 42
@Api(value="lsid_authority_metadata",
44 43
description="Controller which accepts incoming requests to the LSIDMetadataService.")
45 44
public class MetadataController {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)