TSK-1163 refactored ExampleRestApplication

This commit is contained in:
Mustapha Zorgati 2020-03-17 10:25:46 +01:00
parent bd71b8e104
commit 7eab4d5f2e
2 changed files with 40 additions and 24 deletions

View File

@ -1,18 +1,13 @@
package pro.taskana.rest; package pro.taskana.rest;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
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.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.PlatformTransactionManager;
import pro.taskana.jobs.TransactionalJobsConfiguration; import pro.taskana.jobs.TransactionalJobsConfiguration;
import pro.taskana.ldap.LdapCacheTestImpl; import pro.taskana.ldap.LdapCacheTestImpl;
@ -26,6 +21,7 @@ import pro.taskana.sampledata.SampleDataGenerator;
@ComponentScan(basePackages = "pro.taskana") @ComponentScan(basePackages = "pro.taskana")
@SuppressWarnings("checkstyle:Indentation") @SuppressWarnings("checkstyle:Indentation")
@Import({ @Import({
ExampleRestConfiguration.class,
TransactionalJobsConfiguration.class, TransactionalJobsConfiguration.class,
LdapConfiguration.class, LdapConfiguration.class,
RestConfiguration.class, RestConfiguration.class,
@ -33,34 +29,27 @@ import pro.taskana.sampledata.SampleDataGenerator;
}) })
public class ExampleRestApplication { public class ExampleRestApplication {
@Value("${taskana.schemaName:TASKANA}") private final SampleDataGenerator sampleDataGenerator;
public String schemaName; private final LdapClient ldapClient;
private final LdapCacheTestImpl ldapCacheTest;
@Value("${generateSampleData:true}") @Value("${generateSampleData:true}")
public boolean generateSampleData; public boolean generateSampleData;
@Autowired private SampleDataGenerator sampleDataGenerator; @Autowired
public ExampleRestApplication(
@Autowired private LdapClient ldapClient; SampleDataGenerator sampleDataGenerator,
LdapClient ldapClient,
@Autowired private LdapCacheTestImpl ldapCacheTest; LdapCacheTestImpl ldapCacheTest) {
this.sampleDataGenerator = sampleDataGenerator;
this.ldapClient = ldapClient;
this.ldapCacheTest = ldapCacheTest;
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ExampleRestApplication.class, args); SpringApplication.run(ExampleRestApplication.class, args);
} }
@Bean
public PlatformTransactionManager txManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
public SampleDataGenerator generateSampleData(DataSource dataSource) {
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
return sampleDataGenerator;
}
@PostConstruct @PostConstruct
private void init() { private void init() {
if (!ldapClient.useLdap()) { if (!ldapClient.useLdap()) {

View File

@ -0,0 +1,27 @@
package pro.taskana.rest;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import pro.taskana.sampledata.SampleDataGenerator;
public class ExampleRestConfiguration {
@Value("${taskana.schemaName:TASKANA}")
public String schemaName;
@Bean
public PlatformTransactionManager txManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
public SampleDataGenerator generateSampleData(DataSource dataSource) {
return new SampleDataGenerator(dataSource, schemaName);
}
}