TSK-326: outsourced configuration file
This commit is contained in:
parent
ed9ab35704
commit
6f6d884e02
|
|
@ -1,126 +1,12 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
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.Scope;
|
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
||||||
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
|
|
||||||
|
|
||||||
import pro.taskana.ClassificationService;
|
|
||||||
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.sampledata.SampleDataGenerator;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTransactionManagement
|
|
||||||
public class RestApplication {
|
public class RestApplication {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RestApplication.class);
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(RestApplication.class, args);
|
SpringApplication.run(RestApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
@ConfigurationProperties(prefix = "datasource")
|
|
||||||
public DataSourceProperties dataSourceProperties() {
|
|
||||||
return new DataSourceProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
public DataSource dataSource(DataSourceProperties properties) {
|
|
||||||
DataSource dataSource = properties.initializeDataSourceBuilder().build();
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ClassificationService getClassificationService(TaskanaEngine taskanaEngine) {
|
|
||||||
return taskanaEngine.getClassificationService();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
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
|
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
|
||||||
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) throws SQLException {
|
|
||||||
return taskanaEngineConfiguration.buildTaskanaEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
|
||||||
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource) throws SQLException {
|
|
||||||
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
|
||||||
new SpringTaskanaEngineConfiguration(dataSource, true, true);
|
|
||||||
|
|
||||||
new SampleDataGenerator(dataSource).generateSampleData();
|
|
||||||
|
|
||||||
return taskanaEngineConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Needed to override JSON De-/Serializer in Jackson.
|
|
||||||
*
|
|
||||||
* @param handlerInstantiator
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Jackson2ObjectMapperBuilder jacksonBuilder(HandlerInstantiator handlerInstantiator) {
|
|
||||||
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
|
|
||||||
b.indentOutput(true);
|
|
||||||
b.handlerInstantiator(handlerInstantiator);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Needed for injection into jackson deserilizer.
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public HandlerInstantiator handlerInstantiator(ApplicationContext context) {
|
|
||||||
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
|
||||||
return new DataSourceTransactionManager(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
package pro.taskana.rest;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
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.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
|
||||||
|
|
||||||
|
import pro.taskana.ClassificationService;
|
||||||
|
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.sampledata.SampleDataGenerator;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class RestConfiguration {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(RestApplication.class);
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
@ConfigurationProperties(prefix = "datasource")
|
||||||
|
public DataSourceProperties dataSourceProperties() {
|
||||||
|
return new DataSourceProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public DataSource dataSource(DataSourceProperties properties) {
|
||||||
|
DataSource dataSource = properties.initializeDataSourceBuilder().build();
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ClassificationService getClassificationService(TaskanaEngine taskanaEngine) {
|
||||||
|
return taskanaEngine.getClassificationService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
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
|
||||||
|
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||||
|
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) throws SQLException {
|
||||||
|
return taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||||
|
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource) throws SQLException {
|
||||||
|
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
||||||
|
new SpringTaskanaEngineConfiguration(dataSource, true, true);
|
||||||
|
|
||||||
|
new SampleDataGenerator(dataSource).generateSampleData();
|
||||||
|
|
||||||
|
return taskanaEngineConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needed to override JSON De-/Serializer in Jackson.
|
||||||
|
*
|
||||||
|
* @param handlerInstantiator
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Jackson2ObjectMapperBuilder jacksonBuilder(HandlerInstantiator handlerInstantiator) {
|
||||||
|
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
|
||||||
|
b.indentOutput(true);
|
||||||
|
b.handlerInstantiator(handlerInstantiator);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needed for injection into jackson deserilizer.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public HandlerInstantiator handlerInstantiator(ApplicationContext context) {
|
||||||
|
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||||
|
return new DataSourceTransactionManager(dataSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue