TSK-773 Create Wildfly example proyect and refactoring taskana-rest-sprint

This commit is contained in:
Martin Rojas Miguel Angel 2019-01-30 11:18:01 +01:00 committed by BerndBreier
parent d5e42bf53f
commit 867153cbe5
37 changed files with 3326 additions and 51 deletions

View File

@ -16,6 +16,8 @@
<module>taskana-rest-spring</module> <module>taskana-rest-spring</module>
<module>../web</module> <module>../web</module>
<module>taskana-history-rest-spring</module> <module>taskana-history-rest-spring</module>
<module>taskana-rest-configuration</module>
<module>taskana-rest-spring-example</module> <module>taskana-rest-spring-example</module>
<module>taskana-rest-wildfly-example</module>
</modules> </modules>
</project> </project>

View File

@ -0,0 +1,111 @@
<?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">
<parent>
<artifactId>taskana-rest-parent</artifactId>
<groupId>pro.taskana</groupId>
<version>1.0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>taskana-rest-configuration</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring.version>5.0.5.RELEASE</spring.version>
<spring.boot.version>2.0.2.RELEASE</spring.boot.version>
<spring.ldap.version>2.3.2.RELEASE</spring.ldap.version>
</properties>
<dependencies>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-rest-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>${spring.ldap.version}</version>
</dependency>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-test</artifactId>
<version>${spring.ldap.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>${spring.boot.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -61,41 +61,6 @@ public class SampleDataGenerator {
runner = new ScriptRunner(dataSource.getConnection()); runner = new ScriptRunner(dataSource.getConnection());
} }
/**
* This method resolves the custom sql function defined through this regex: {@value RELATIVE_DATE_REGEX}. Its
* parameter is a digit representing the relative offset of a given starting point date.
* <p/>
* Yes, this can be done as an actual sql function, but that'd lead to a little more complexity (and thus we'd have
* to maintain the code for db compatibility ...) Since we're already replacing the boolean attributes of sql files
* this addition is not a huge computational cost.
*
* @param now
* anchor for relative date conversion.
* @param sql
* sql statement which may contain the above declared custom function.
* @return sql statement with the given function resolved, if the 'sql' parameter contained any.
*/
private static String replaceRelativeTimeFunction(LocalDateTime now, String sql) {
Matcher m = RELATIVE_DATE_PATTERN.matcher(sql);
StringBuffer sb = new StringBuffer(sql.length());
while (m.find()) {
m.appendReplacement(sb,
"'" + now.plusDays(Long.parseLong(m.group(1))).format(DATE_TIME_FORMATTER) + "'");
}
m.appendTail(sb);
return sb.toString();
}
private static String parseAndReplace(LocalDateTime now, InputStream stream) {
try (
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
return replaceRelativeTimeFunction(now,
bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void generateSampleData(String schemaName) { public void generateSampleData(String schemaName) {
StringWriter outWriter = new StringWriter(); StringWriter outWriter = new StringWriter();
PrintWriter logWriter = new PrintWriter(outWriter); PrintWriter logWriter = new PrintWriter(outWriter);
@ -134,6 +99,41 @@ public class SampleDataGenerator {
} }
} }
/**
* This method resolves the custom sql function defined through this regex: {@value RELATIVE_DATE_REGEX}. Its
* parameter is a digit representing the relative offset of a given starting point date.
* <p/>
* Yes, this can be done as an actual sql function, but that'd lead to a little more complexity (and thus we'd have
* to maintain the code for db compatibility ...) Since we're already replacing the boolean attributes of sql files
* this addition is not a huge computational cost.
*
* @param now
* anchor for relative date conversion.
* @param sql
* sql statement which may contain the above declared custom function.
* @return sql statement with the given function resolved, if the 'sql' parameter contained any.
*/
private static String replaceRelativeTimeFunction(LocalDateTime now, String sql) {
Matcher m = RELATIVE_DATE_PATTERN.matcher(sql);
StringBuffer sb = new StringBuffer(sql.length());
while (m.find()) {
m.appendReplacement(sb,
"'" + now.plusDays(Long.parseLong(m.group(1))).format(DATE_TIME_FORMATTER) + "'");
}
m.appendTail(sb);
return sb.toString();
}
private static String parseAndReplace(LocalDateTime now, InputStream stream) {
try (
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
return replaceRelativeTimeFunction(now,
bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private StringReader selectSchemaScript(String dbProductName, String schemaName) { private StringReader selectSchemaScript(String dbProductName, String schemaName) {
return new StringReader(TaskanaEngineImpl.isPostgreSQL(dbProductName) return new StringReader(TaskanaEngineImpl.isPostgreSQL(dbProductName)
? "SET search_path TO " + schemaName + ";" ? "SET search_path TO " + schemaName + ";"

View File

@ -24,13 +24,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/** /**
* TODO. * Default basic configuration for taskana web example.
*/ */
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${devMode}") @Value("${devMode:false}")
private boolean devMode; private boolean devMode;
@Override @Override

View File

@ -173,6 +173,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-rest-configuration</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -0,0 +1,124 @@
<?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">
<groupId>pro.taskana</groupId>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<version>1.0.6-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>taskana-rest-wildfly-example</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-rest-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-rest-configuration</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.0.Final</version>
<executions>
<execution>
<id>run-wildfly</id>
<phase>install</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<!-- Deploy the JDBC library -->
<!--<execution>
<id>deploy-driver</id>
<phase>install</phase>
<configuration>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<name>postgresql.jar</name>
</configuration>
<goals>
<goal>deploy-artifact</goal>
</goals>
</execution>-->
<!-- Add a data source -->
<execution>
<id>add-datasource</id>
<phase>install</phase>
<configuration>
<address>subsystem=datasources,data-source=java:/TaskanaDS</address>
<resources>
<resource>
<properties>
<jndi-name>java:/TaskanaDS</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0</connection-url>
<driver-class>org.h2.Driver</driver-class>
<driver-name>h2</driver-name>
<user-name>sa</user-name>
<password>sa</password>
</properties>
</resource>
</resources>
</configuration>
<goals>
<goal>add-resource</goal>
</goals>
</execution>
<!-- Deploy the application on install -->
<execution>
<id>wildfly-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<!-- shutdown the application on install -->
<execution>
<id>wildfly-shutdown</id>
<phase>install</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,117 @@
package pro.taskana;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.PlatformTransactionManager;
import pro.taskana.jobs.TransactionalJobsConfiguration;
import pro.taskana.ldap.LdapCacheTestImpl;
import pro.taskana.ldap.LdapClient;
import pro.taskana.ldap.LdapConfiguration;
import pro.taskana.rest.AccessIdController;
import pro.taskana.rest.RestConfiguration;
import pro.taskana.sampledata.SampleDataGenerator;
/**
* Example Application showing the implementation of taskana-rest-spring for jboss application server.
*/
@SpringBootApplication
@EnableScheduling
@ComponentScan(basePackages = "pro.taskana")
@Import({TransactionalJobsConfiguration.class, LdapConfiguration.class, RestConfiguration.class})
public class TaskanaWildFlyApplication extends SpringBootServletInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaWildFlyApplication.class);
@Value("${taskana.schemaName:TASKANA}")
public String schemaName;
@Value("${generateSampleData:true}")
public boolean generateSampleData;
@Autowired
private SampleDataGenerator sampleDataGenerator;
@Autowired
private LdapClient ldapClient;
@Autowired private LdapCacheTestImpl ldapCacheTest;
public static void main(String[] args) {
SpringApplication.run(TaskanaWildFlyApplication.class, args);
}
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource")
public DataSourceProperties dataSourceProperties() {
DataSourceProperties props = new DataSourceProperties();
props.setUrl("jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS " + schemaName);
return props;
}
@Bean
public DataSource dataSource(DataSourceProperties dsProperties) {
// First try to load Properties and get Datasource via jndi lookup
Context ctx;
DataSource dataSource;
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
try (InputStream propertyStream = classloader.getResourceAsStream("application.properties")) {
Properties properties = new Properties();
ctx = new InitialContext();
properties.load(propertyStream);
dataSource = (DataSource) ctx.lookup(properties.getProperty("datasource.jndi"));
return dataSource;
} catch (Exception e) {
LOGGER.error(
"Caught exception {} when attempting to start Taskana with Datasource from Jndi. Using default H2 datasource. ",
e);
return dsProperties.initializeDataSourceBuilder().build();
}
}
@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) throws SQLException {
sampleDataGenerator = new SampleDataGenerator(dataSource);
return sampleDataGenerator;
}
@PostConstruct
private void init() {
if (!ldapClient.useLdap()) {
AccessIdController.setLdapCache(ldapCacheTest);
}
if (generateSampleData) {
sampleDataGenerator.generateSampleData(schemaName);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
logging.level.pro.taskana=INFO
### logging.level.org.springframework=DEBUG
######## Taskana DB #######
######## h2 configuration ########
datasource.jndi=java:/TaskanaDS
taskana.schemaName=TASKANA
######## h2 console configuration ########
######## spring.h2.console.enabled=true ########
######## spring.h2.console.path=/h2-console ########
######## Postgres configuration ########
######## datasource.url=jdbc:postgresql://localhost/taskana ########
######## datasource.driverClassName=org.postgresql.Driver ########
######## datasource.username=postgres ########
######## datasource.password=1234 ########
####### control LDAP usage
taskana.ldap.useLdap=false
####### properties to connect to LDAP
taskana.ldap.serverUrl=ldap://localhost:10389
taskana.ldap.bindDn=uid=admin,ou=system
taskana.ldap.bindPassword=secret
taskana.ldap.baseDn=o=TaskanaTest
####### properties that control search for users and groups
taskana.ldap.userSearchBase=ou=people
taskana.ldap.userSearchFilterName=objectclass
taskana.ldap.userSearchFilterValue=person
taskana.ldap.userFirstnameAttribute=givenName
taskana.ldap.userLastnameAttribute=sn
taskana.ldap.userIdAttribute=uid
taskana.ldap.groupSearchBase=ou=groups
taskana.ldap.groupSearchFilterName=objectclass
taskana.ldap.groupSearchFilterValue=groupOfUniqueNames
taskana.ldap.groupNameAttribute=cn
taskana.ldap.minSearchForLength=3
taskana.ldap.maxNumberOfReturnedAccessIds=50
taskana.ldap.groupsOfUser=memberUid
####### JobScheduler cron expression that specifies when the JobSchedler runs
taskana.jobscheduler.async.cron=0 * * * * *
####### cache static resources properties
spring.resources.cache.cachecontrol.cache-private=true
####### tomcat is not detecting the x-forward headers from bluemix as a trustworthy proxy
server.tomcat.internal-proxies=.*
server.use-forward-headers=true

View File

@ -0,0 +1,3 @@
taskana {
pro.taskana.rest.security.SampleLoginModule required;
};

View File

@ -0,0 +1,15 @@
taskana.roles.user = group1 | group2|teamlead_1 |teamlead_2 |user_1_1| user_1_1| user_1_2| user_2_1| user_2_2| max|elena|simone
taskana.roles.Admin=name=konrad,Organisation=novatec|admin
taskana.roles.businessadmin=max|Moritz|businessadmin
taskana.roles.monitor=john|teamlead_2 | monitor
taskana.domains=DOMAIN_A,DOMAIN_B,DOMAIN_C
taskana.classification.types=TASK,DOCUMENT
taskana.classification.categories.task= EXTERNAL, manual, autoMAtic, Process
taskana.classification.categories.document= EXTERNAL
taskana.jobs.maxRetries=3
taskana.jobs.batchSize=50
taskana.jobs.cleanup.runEvery=P1D
taskana.jobs.cleanup.firstRunAt=2018-07-25T08:00:00Z
taskana.jobs.cleanup.minimumAge=P14D

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="7.2"
xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_7_2.xsd">
<context-root>/</context-root>
</jboss-web>

View File

@ -0,0 +1,7 @@
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>TaskanaRestWildflySpring</display-name>
</web-app>