TSK-325 replaced taskana-core with taskana-spring to gain transaction management

This commit is contained in:
Mustapha Zorgati 2018-02-22 12:28:24 +01:00 committed by Marcel Lengl
parent 36974006af
commit 351d9654a2
3 changed files with 64 additions and 31 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pro.taskana</groupId>
@ -33,10 +33,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-core</artifactId>
<artifactId>taskana-spring</artifactId>
<version>${project.version}</version>
</dependency>
@ -56,12 +64,12 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.16.0.RELEASE</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.16.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -2,18 +2,23 @@ package pro.taskana.rest;
import java.sql.SQLException;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.SpringHandlerInstantiator;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
@ -22,6 +27,7 @@ import pro.taskana.TaskMonitorService;
import pro.taskana.TaskService;
import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketService;
import pro.taskana.configuration.SpringTaskanaEngineConfiguration;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.rest.resource.mapper.ClassificationMapper;
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemMapper;
@ -31,6 +37,8 @@ import pro.taskana.rest.resource.mapper.WorkbasketSummaryMapper;
import pro.taskana.sampledata.SampleDataGenerator;
@SpringBootApplication
@PropertySource("classpath:datasource.properties")
@EnableTransactionManagement
public class RestApplication {
private static final Logger logger = LoggerFactory.getLogger(RestApplication.class);
@ -40,23 +48,40 @@ public class RestApplication {
}
@Bean
public ClassificationService getClassificationService() throws Exception {
return getTaskanaEngine().getClassificationService();
@Primary
@ConfigurationProperties(prefix = "datasource")
public DataSourceProperties dataSourceProperties() {
return new DataSourceProperties();
}
@Bean
public TaskService getTaskService() throws Exception {
return getTaskanaEngine().getTaskService();
@Primary
public DataSource dataSource(DataSourceProperties properties) {
DataSource dataSource = properties.initializeDataSourceBuilder().build();
// if TaskanaEngineImpl runs with SpringManagedTransactionFactory, then
// there is no need to wrap the dataSource into TransactionAwareDataSourceProxy ...
// return new TransactionAwareDataSourceProxy(dataSource);
return dataSource;
}
@Bean
public TaskMonitorService getTaskMonitorService() throws Exception {
return getTaskanaEngine().getTaskMonitorService();
public ClassificationService getClassificationService(TaskanaEngine taskanaEngine) {
return taskanaEngine.getClassificationService();
}
@Bean
public WorkbasketService getWorkbasketService() throws Exception {
return getTaskanaEngine().getWorkbasketService();
public TaskService getTaskService(TaskanaEngine taskanaEngine) {
return taskanaEngine.getTaskService();
}
@Bean
public TaskMonitorService getTaskMonitorService(TaskanaEngine taskanaEngine) {
return taskanaEngine.getTaskMonitorService();
}
@Bean
public WorkbasketService getWorkbasketService(TaskanaEngine taskanaEngine) {
return taskanaEngine.getWorkbasketService();
}
@Bean
@ -86,14 +111,18 @@ public class RestApplication {
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public TaskanaEngine getTaskanaEngine() throws SQLException {
return getTaskanaEngineConfiguration().buildTaskanaEngine();
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) throws SQLException {
return taskanaEngineConfiguration.buildTaskanaEngine();
}
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public TaskanaEngineConfiguration getTaskanaEngineConfiguration() throws SQLException {
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, true);
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource) throws SQLException {
TaskanaEngineConfiguration taskanaEngineConfiguration =
new SpringTaskanaEngineConfiguration(dataSource, true, true);
new SampleDataGenerator(dataSource).generateSampleData();
return taskanaEngineConfiguration;
}
@ -122,13 +151,4 @@ public class RestApplication {
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
}
@PostConstruct
public void createSampleData() {
try {
new SampleDataGenerator(getTaskanaEngineConfiguration().createDefaultDataSource()).generateSampleData();
} catch (SQLException e) {
logger.error("Could not create sample data.", e);
}
}
}

View File

@ -0,0 +1,5 @@
######## Taskana DB #######
datasource.url=jdbc:h2:mem:taskana;IGNORECASE=TRUE
datasource.driverClassName=org.h2.Driver
datasource.username=sa
datasource.password=sa