TSK-1628: cleanup of code smells & refactoring (#1571)
* TSK-1628: Fixed Code-Smells * TSK-1628: FileLoaderUtil Refactoring * TSK-1628: Increased readabilty of some tests * TSK-1628: Fixed pom and tidying up
This commit is contained in:
parent
542ca3d7eb
commit
37cfcae92b
|
|
@ -2,7 +2,6 @@ package pro.taskana.common.test.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
@ -21,8 +20,7 @@ public final class TaskanaEngineTestConfiguration {
|
||||||
private static String schemaName = null;
|
private static String schemaName = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String userHomeDirectroy = System.getProperty("user.home");
|
String propertiesFileName = System.getProperty("user.home") + "/taskanaUnitTest.properties";
|
||||||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
|
||||||
File f = new File(propertiesFileName);
|
File f = new File(propertiesFileName);
|
||||||
if (f.exists() && !f.isDirectory()) {
|
if (f.exists() && !f.isDirectory()) {
|
||||||
DATA_SOURCE = createDataSourceFromProperties(propertiesFileName);
|
DATA_SOURCE = createDataSourceFromProperties(propertiesFileName);
|
||||||
|
|
@ -60,8 +58,7 @@ public final class TaskanaEngineTestConfiguration {
|
||||||
*/
|
*/
|
||||||
public static String getSchemaName() {
|
public static String getSchemaName() {
|
||||||
if (schemaName == null) {
|
if (schemaName == null) {
|
||||||
String userHomeDirectroy = System.getProperty("user.home");
|
String propertiesFileName = System.getProperty("user.home") + "/taskanaUnitTest.properties";
|
||||||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
|
||||||
File f = new File(propertiesFileName);
|
File f = new File(propertiesFileName);
|
||||||
if (f.exists() && !f.isDirectory()) {
|
if (f.exists() && !f.isDirectory()) {
|
||||||
schemaName = getSchemaNameFromPropertiesObject(propertiesFileName);
|
schemaName = getSchemaNameFromPropertiesObject(propertiesFileName);
|
||||||
|
|
@ -117,13 +114,13 @@ public final class TaskanaEngineTestConfiguration {
|
||||||
((PooledDataSource) ds)
|
((PooledDataSource) ds)
|
||||||
.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
LOGGER.warn("propertiesFile {} is incomplete {}", propertiesFileName, warningMessage);
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
LOGGER.warn("Using default Datasource for Test");
|
||||||
ds = createDefaultDataSource();
|
ds = createDefaultDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
LOGGER.warn("createDataSourceFromProperties caught Exception ", e);
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
LOGGER.warn("Using default Datasource for Test");
|
||||||
ds = createDefaultDataSource();
|
ds = createDefaultDataSource();
|
||||||
}
|
}
|
||||||
|
|
@ -145,33 +142,20 @@ public final class TaskanaEngineTestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!propertiesFileIsComplete) {
|
if (!propertiesFileIsComplete) {
|
||||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
LOGGER.warn("propertiesFile {} is incomplete {}", propertiesFileName, warningMessage);
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
LOGGER.warn("Using default Datasource for Test");
|
||||||
schemaName = "TASKANA";
|
schemaName = "TASKANA";
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn("getSchemaNameFromPropertiesObject caught Exception " + e);
|
LOGGER.warn("Caught Exception ", e);
|
||||||
LOGGER.warn("Using default schemaName for Test");
|
LOGGER.warn("Using default schemaName for Test");
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return schemaName;
|
return schemaName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* create Default Datasource for in-memory database.
|
|
||||||
*
|
|
||||||
* @return the default datasource.
|
|
||||||
*/
|
|
||||||
private static DataSource createDefaultDataSource() {
|
private static DataSource createDefaultDataSource() {
|
||||||
// JdbcDataSource ds = new JdbcDataSource();
|
|
||||||
// ds.setURL("jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0");
|
|
||||||
// ds.setPassword("sa");
|
|
||||||
// ds.setUser("sa");
|
|
||||||
|
|
||||||
String jdbcDriver = "org.h2.Driver";
|
String jdbcDriver = "org.h2.Driver";
|
||||||
String jdbcUrl =
|
String jdbcUrl =
|
||||||
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;"
|
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;"
|
||||||
|
|
|
||||||
|
|
@ -161,59 +161,6 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||||
return canonical;
|
return canonical;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Main to test version parsing and comparison.
|
|
||||||
*
|
|
||||||
* <p>To check how "1.2.7" compares to "1.2-SNAPSHOT", for example, you can issue
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* java -jar ${maven.repo.local}/org/apache/maven/maven-artifact/
|
|
||||||
* ${maven.version}/maven-artifact-${maven.version}.jar "1.2.7" "1.2-SNAPSHOT"
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* <p>command to command line. Result of given command will be something like this:
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* Display parameters as parsed by Maven (in canonical form) and comparison result:
|
|
||||||
* 1. 1.2.7 == 1.2.7
|
|
||||||
* 1.2.7 > 1.2-SNAPSHOT
|
|
||||||
* 2. 1.2-SNAPSHOT == 1.2-snapshot
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param args the version strings to parse and compare. You can pass arbitrary number of version
|
|
||||||
* strings and always two adjacent will be compared
|
|
||||||
*/
|
|
||||||
// CHECKSTYLE_ON: LineLength
|
|
||||||
public static void main(String... args) {
|
|
||||||
/* System.out.println(
|
|
||||||
"Display parameters as parsed by Maven (in canonical form) and comparison result:");*/
|
|
||||||
if (args.length == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ComparableVersion prev = null;
|
|
||||||
int i = 1;
|
|
||||||
for (String version : args) {
|
|
||||||
ComparableVersion c = new ComparableVersion(version);
|
|
||||||
|
|
||||||
if (prev != null) {
|
|
||||||
int compare = prev.compareTo(c);
|
|
||||||
/* System.out.println(
|
|
||||||
" "
|
|
||||||
+ prev.toString()
|
|
||||||
+ ' '
|
|
||||||
+ ((compare == 0) ? "==" : ((compare < 0) ? "<" : ">"))
|
|
||||||
+ ' '
|
|
||||||
+ version);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// System.out.println(String.valueOf(i++) + ". " + version + " == " + c.getCanonical());
|
|
||||||
|
|
||||||
prev = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Item parseItem(boolean isDigit, String buf) {
|
private static Item parseItem(boolean isDigit, String buf) {
|
||||||
if (isDigit) {
|
if (isDigit) {
|
||||||
buf = stripLeadingZeroes(buf);
|
buf = stripLeadingZeroes(buf);
|
||||||
|
|
@ -303,7 +250,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||||
switch (item.getType()) {
|
switch (item.getType()) {
|
||||||
case INT_ITEM:
|
case INT_ITEM:
|
||||||
int itemValue = ((IntItem) item).value;
|
int itemValue = ((IntItem) item).value;
|
||||||
return (value < itemValue) ? -1 : ((value == itemValue) ? 0 : 1);
|
return Integer.compare(value, itemValue);
|
||||||
case LONG_ITEM:
|
case LONG_ITEM:
|
||||||
case BIGINTEGER_ITEM:
|
case BIGINTEGER_ITEM:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -373,7 +320,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||||
return 1;
|
return 1;
|
||||||
case LONG_ITEM:
|
case LONG_ITEM:
|
||||||
long itemValue = ((LongItem) item).value;
|
long itemValue = ((LongItem) item).value;
|
||||||
return (value < itemValue) ? -1 : ((value == itemValue) ? 0 : 1);
|
return Long.compare(value, itemValue);
|
||||||
case BIGINTEGER_ITEM:
|
case BIGINTEGER_ITEM:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
@ -642,7 +589,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||||
Item r = right.hasNext() ? right.next() : null;
|
Item r = right.hasNext() ? right.next() : null;
|
||||||
|
|
||||||
// if this is shorter, then invert the compare and mul with -1
|
// if this is shorter, then invert the compare and mul with -1
|
||||||
int result = l == null ? (r == null ? 0 : -1 * r.compareTo(l)) : l.compareTo(r);
|
int result = l == null ? (r == null ? 0 : -1 * r.compareTo(null)) : l.compareTo(r);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,23 @@
|
||||||
package pro.taskana.common.internal.util;
|
package pro.taskana.common.internal.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import pro.taskana.common.api.exceptions.SystemException;
|
||||||
|
|
||||||
public class FileLoaderUtil {
|
public class FileLoaderUtil {
|
||||||
|
|
||||||
public static boolean loadFromClasspath(String fileToLoad) {
|
private static final Logger LOGGER = LoggerFactory.getLogger(FileLoaderUtil.class);
|
||||||
|
|
||||||
|
private FileLoaderUtil() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInClasspath(String fileToLoad) {
|
||||||
boolean loadFromClasspath = true;
|
boolean loadFromClasspath = true;
|
||||||
File f = new File(fileToLoad);
|
File f = new File(fileToLoad);
|
||||||
if (f.exists() && !f.isDirectory()) {
|
if (f.exists() && !f.isDirectory()) {
|
||||||
|
|
@ -13,4 +26,24 @@ public class FileLoaderUtil {
|
||||||
return loadFromClasspath;
|
return loadFromClasspath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InputStream openFileFromClasspathOrSystem(String fileToLoad, Class<?> clazz) {
|
||||||
|
if (isInClasspath(fileToLoad)) {
|
||||||
|
InputStream inputStream = clazz.getResourceAsStream(fileToLoad);
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw new SystemException(
|
||||||
|
String.format("Could not find a file in the classpath %s", fileToLoad));
|
||||||
|
}
|
||||||
|
LOGGER.debug("Load file {} from classpath", fileToLoad);
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileInputStream inputStream = new FileInputStream(fileToLoad);
|
||||||
|
LOGGER.debug("Load file {} from path", fileToLoad);
|
||||||
|
return inputStream;
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new SystemException(
|
||||||
|
String.format("Could not find a file with provided path %s", fileToLoad));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
taskana.roles.user=teamlead-1 | teamlead-2 | user-1-1 | user-1-2 | user-2-1 | user-2-2 | user-b-1 | user-b-2
|
||||||
|
taskana.roles.admin=admin | uid=admin,cn=users,OU=Test,O=TASKANA
|
||||||
|
taskana.roles.businessadmin=businessadmin | cn=business-admins,cn=groups,OU=Test,O=TASKANA
|
||||||
|
taskana.roles.monitor=monitor | cn=monitor-users,cn=groups,OU=Test,O=TASKANA
|
||||||
|
taskana.roles.taskadmin=taskadmin
|
||||||
|
taskana.domains=Domain_A , DOMAIN_B
|
||||||
|
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
|
||||||
|
taskana.german.holidays.enabled=true
|
||||||
|
taskana.german.holidays.corpus-christi.enabled=false
|
||||||
|
taskana.history.deletion.on.task.deletion.enabled=true
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
package pro.taskana;
|
package pro.taskana;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
@ -48,6 +44,7 @@ import pro.taskana.common.internal.util.Pair;
|
||||||
* <br>
|
* <br>
|
||||||
* Security is enabled by default.
|
* Security is enabled by default.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
|
||||||
public class TaskanaEngineConfiguration {
|
public class TaskanaEngineConfiguration {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfiguration.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfiguration.class);
|
||||||
|
|
@ -368,6 +365,10 @@ public class TaskanaEngineConfiguration {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Properties readPropertiesFromFile() {
|
||||||
|
return readPropertiesFromFile(this.propertiesFileName);
|
||||||
|
}
|
||||||
|
|
||||||
private <T> Optional<T> parseProperty(
|
private <T> Optional<T> parseProperty(
|
||||||
Properties props, String key, CheckedFunction<String, T> function) {
|
Properties props, String key, CheckedFunction<String, T> function) {
|
||||||
String property = props.getProperty(key, "");
|
String property = props.getProperty(key, "");
|
||||||
|
|
@ -556,29 +557,12 @@ public class TaskanaEngineConfiguration {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties readPropertiesFromFile() {
|
|
||||||
return readPropertiesFromFile(this.propertiesFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Properties readPropertiesFromFile(String propertiesFile) {
|
private Properties readPropertiesFromFile(String propertiesFile) {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
boolean loadFromClasspath = FileLoaderUtil.loadFromClasspath(propertiesFile);
|
|
||||||
try {
|
try {
|
||||||
if (loadFromClasspath) {
|
try (InputStream stream =
|
||||||
InputStream inputStream =
|
FileLoaderUtil.openFileFromClasspathOrSystem(propertiesFile, getClass())) {
|
||||||
TaskanaEngineConfiguration.class.getResourceAsStream(propertiesFile);
|
props.load(stream);
|
||||||
if (inputStream == null) {
|
|
||||||
LOGGER.error("taskana properties file {} was not found on classpath.", propertiesFile);
|
|
||||||
} else {
|
|
||||||
props.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
|
||||||
LOGGER.debug("Role properties were loaded from file {} from classpath.", propertiesFile);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try (FileInputStream stream = new FileInputStream(propertiesFile)) {
|
|
||||||
props.load(stream);
|
|
||||||
}
|
|
||||||
LOGGER.debug("Role properties were loaded from file {}.", propertiesFile);
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("caught IOException when processing properties file {}.", propertiesFile);
|
LOGGER.error("caught IOException when processing properties file {}.", propertiesFile);
|
||||||
|
|
@ -587,13 +571,4 @@ public class TaskanaEngineConfiguration {
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadFromClasspath(String propertiesFile) {
|
|
||||||
boolean loadFromClasspath = true;
|
|
||||||
File f = new File(propertiesFile);
|
|
||||||
if (f.exists() && !f.isDirectory()) {
|
|
||||||
loadFromClasspath = false;
|
|
||||||
}
|
|
||||||
return loadFromClasspath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,96 +6,99 @@ import acceptance.TaskanaEngineTestConfiguration;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngineConfiguration;
|
import pro.taskana.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.common.internal.TaskanaEngineImpl;
|
|
||||||
|
|
||||||
/** Test taskana configuration without roles. */
|
/** Test taskana configuration without roles. */
|
||||||
class TaskanaConfigAccTest extends TaskanaEngineImpl {
|
class TaskanaConfigAccTest {
|
||||||
|
|
||||||
@TempDir Path tempDir;
|
@TempDir Path tempDir;
|
||||||
|
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
|
||||||
TaskanaConfigAccTest() throws Exception {
|
@BeforeEach
|
||||||
super(
|
void setup() {
|
||||||
|
taskanaEngineConfiguration =
|
||||||
new TaskanaEngineConfiguration(
|
new TaskanaEngineConfiguration(
|
||||||
TaskanaEngineTestConfiguration.getDataSource(),
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
true,
|
true,
|
||||||
TaskanaEngineTestConfiguration.getSchemaName()));
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDomains() {
|
void should_ConfigureDomains_For_DefaultPropertiesFile() {
|
||||||
assertThat(getConfiguration().getDomains()).containsExactlyInAnyOrder("DOMAIN_A", "DOMAIN_B");
|
assertThat(taskanaEngineConfiguration.getDomains())
|
||||||
|
.containsExactlyInAnyOrder("DOMAIN_A", "DOMAIN_B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testClassificationTypes() {
|
void should_ConfigureClassificationTypes_For_DefaultPropertiesFile() {
|
||||||
assertThat(getConfiguration().getClassificationTypes())
|
assertThat(taskanaEngineConfiguration.getClassificationTypes())
|
||||||
.containsExactlyInAnyOrder("TASK", "DOCUMENT");
|
.containsExactlyInAnyOrder("TASK", "DOCUMENT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testClassificationCategories() {
|
void should_ConfigureClassificationCategories_For_DefaultPropertiesFile() {
|
||||||
assertThat(getConfiguration().getClassificationCategoriesByType("TASK"))
|
assertThat(taskanaEngineConfiguration.getClassificationCategoriesByType("TASK"))
|
||||||
.containsExactlyInAnyOrder("EXTERNAL", "MANUAL", "AUTOMATIC", "PROCESS");
|
.containsExactlyInAnyOrder("EXTERNAL", "MANUAL", "AUTOMATIC", "PROCESS");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDoesNotExistPropertyClassificationTypeOrItIsEmpty() throws Exception {
|
void should_NotConfigureClassificationTypes_When_PropertiesAreNotDefined() throws Exception {
|
||||||
taskanaEngineConfiguration.setClassificationTypes(new ArrayList<>());
|
String propertiesFileName = createNewConfigFile("dummyTestConfig1.properties", false, true);
|
||||||
String propertiesFileName = createNewConfigFile("dummyTestConfig.properties", false, true);
|
|
||||||
String delimiter = ";";
|
String delimiter = ";";
|
||||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
taskanaEngineConfiguration =
|
||||||
|
new TaskanaEngineConfiguration(
|
||||||
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
propertiesFileName,
|
||||||
|
delimiter,
|
||||||
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
assertThat(taskanaEngineConfiguration.getClassificationTypes()).isEmpty();
|
assertThat(taskanaEngineConfiguration.getClassificationTypes()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDoesNotExistPropertyClassificationCategoryOrItIsEmpty() throws Exception {
|
void should_NotConfigureClassificationCategories_When_PropertiesAreNotDefined() throws Exception {
|
||||||
taskanaEngineConfiguration.setClassificationTypes(new ArrayList<>());
|
String propertiesFileName = createNewConfigFile("dummyTestConfig2.properties", true, false);
|
||||||
taskanaEngineConfiguration.setClassificationCategoriesByType(new HashMap<>());
|
|
||||||
String propertiesFileName = createNewConfigFile("dummyTestConfig.properties", true, false);
|
|
||||||
String delimiter = ";";
|
String delimiter = ";";
|
||||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
taskanaEngineConfiguration =
|
||||||
assertThat(
|
new TaskanaEngineConfiguration(
|
||||||
taskanaEngineConfiguration.getClassificationCategoriesByType(
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
taskanaEngineConfiguration.getClassificationTypes().get(0)))
|
true,
|
||||||
.isEmpty();
|
true,
|
||||||
|
propertiesFileName,
|
||||||
|
delimiter,
|
||||||
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
|
assertThat(taskanaEngineConfiguration.getClassificationCategoriesByTypeMap())
|
||||||
|
.containsExactly(
|
||||||
|
Map.entry("TASK", Collections.emptyList()),
|
||||||
|
Map.entry("DOCUMENT", Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWithCategoriesAndClassificationFilled() throws Exception {
|
void should_ApplyClassificationProperties_When_PropertiesAreDefined() throws Exception {
|
||||||
taskanaEngineConfiguration.setClassificationTypes(new ArrayList<>());
|
String propertiesFileName = createNewConfigFile("dummyTestConfig3.properties", true, true);
|
||||||
taskanaEngineConfiguration.setClassificationCategoriesByType(new HashMap<>());
|
|
||||||
String propertiesFileName = createNewConfigFile("dummyTestConfig.properties", true, true);
|
|
||||||
String delimiter = ";";
|
String delimiter = ";";
|
||||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
taskanaEngineConfiguration =
|
||||||
assertThat(taskanaEngineConfiguration.getClassificationTypes().isEmpty()).isFalse();
|
new TaskanaEngineConfiguration(
|
||||||
assertThat(
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
taskanaEngineConfiguration
|
true,
|
||||||
.getClassificationCategoriesByType(
|
true,
|
||||||
taskanaEngineConfiguration.getClassificationTypes().get(0))
|
propertiesFileName,
|
||||||
.isEmpty())
|
delimiter,
|
||||||
.isFalse();
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
assertThat(taskanaEngineConfiguration.getClassificationTypes()).hasSize(2);
|
assertThat(taskanaEngineConfiguration.getClassificationCategoriesByTypeMap())
|
||||||
assertThat(
|
.containsExactly(
|
||||||
taskanaEngineConfiguration
|
Map.entry("TASK", List.of("EXTERNAL", "MANUAL", "AUTOMATIC", "PROCESS")),
|
||||||
.getClassificationCategoriesByType(
|
Map.entry("DOCUMENT", List.of("EXTERNAL")));
|
||||||
taskanaEngineConfiguration.getClassificationTypes().get(0))
|
|
||||||
.size())
|
|
||||||
.isEqualTo(4);
|
|
||||||
assertThat(
|
|
||||||
taskanaEngineConfiguration
|
|
||||||
.getClassificationCategoriesByType(
|
|
||||||
taskanaEngineConfiguration.getClassificationTypes().get(1))
|
|
||||||
.size())
|
|
||||||
.isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createNewConfigFile(
|
private String createNewConfigFile(
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class TaskanaEngineConfigTest {
|
||||||
ds,
|
ds,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
"/custom_holiday_With_Wrong_format_taskana.properties",
|
"/custom_holiday_with_wrong_format_taskana.properties",
|
||||||
"|",
|
"|",
|
||||||
TaskanaEngineTestConfiguration.getSchemaName());
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
assertThat(taskEngineConfiguration.getCustomHolidays()).isEmpty();
|
assertThat(taskEngineConfiguration.getCustomHolidays()).isEmpty();
|
||||||
|
|
|
||||||
|
|
@ -8,32 +8,35 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngineConfiguration;
|
import pro.taskana.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.common.api.TaskanaRole;
|
import pro.taskana.common.api.TaskanaRole;
|
||||||
import pro.taskana.common.internal.TaskanaEngineImpl;
|
|
||||||
|
|
||||||
/** Test taskana's role configuration. */
|
/** Test taskana's role configuration. */
|
||||||
class TaskanaRoleConfigAccTest extends TaskanaEngineImpl {
|
class TaskanaRoleConfigAccTest {
|
||||||
|
|
||||||
|
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
|
||||||
@TempDir Path tempDir;
|
@TempDir Path tempDir;
|
||||||
|
|
||||||
TaskanaRoleConfigAccTest() throws Exception {
|
@BeforeEach
|
||||||
super(
|
void setup() {
|
||||||
|
taskanaEngineConfiguration =
|
||||||
new TaskanaEngineConfiguration(
|
new TaskanaEngineConfiguration(
|
||||||
TaskanaEngineTestConfiguration.getDataSource(),
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
true,
|
true,
|
||||||
TaskanaEngineTestConfiguration.getSchemaName()));
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testStandardConfig() {
|
void should_ApplyDefaultConfiguration_For_DefaultPropertiesFile() {
|
||||||
Set<TaskanaRole> rolesConfigured = getConfiguration().getRoleMap().keySet();
|
Set<TaskanaRole> rolesConfigured = taskanaEngineConfiguration.getRoleMap().keySet();
|
||||||
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
||||||
|
|
||||||
Set<String> users = getConfiguration().getRoleMap().get(TaskanaRole.USER);
|
Set<String> users = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.USER);
|
||||||
assertThat(users)
|
assertThat(users)
|
||||||
.containsExactlyInAnyOrder(
|
.containsExactlyInAnyOrder(
|
||||||
"teamlead-1",
|
"teamlead-1",
|
||||||
|
|
@ -45,63 +48,82 @@ class TaskanaRoleConfigAccTest extends TaskanaEngineImpl {
|
||||||
"user-b-1",
|
"user-b-1",
|
||||||
"user-b-2");
|
"user-b-2");
|
||||||
|
|
||||||
Set<String> admins = getConfiguration().getRoleMap().get(TaskanaRole.ADMIN);
|
Set<String> admins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.ADMIN);
|
||||||
assertThat(admins).containsExactlyInAnyOrder("uid=admin,cn=users,ou=test,o=taskana", "admin");
|
assertThat(admins).containsExactlyInAnyOrder("uid=admin,cn=users,ou=test,o=taskana", "admin");
|
||||||
|
|
||||||
Set<String> taskAdmins = getConfiguration().getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
Set<String> taskAdmins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||||
assertThat(taskAdmins).containsExactlyInAnyOrder("taskadmin");
|
assertThat(taskAdmins).containsExactlyInAnyOrder("taskadmin");
|
||||||
|
|
||||||
Set<String> businessAdmins = getConfiguration().getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
Set<String> businessAdmins =
|
||||||
|
taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||||
assertThat(businessAdmins)
|
assertThat(businessAdmins)
|
||||||
.containsExactlyInAnyOrder(
|
.containsExactlyInAnyOrder(
|
||||||
"businessadmin", "cn=business-admins,cn=groups,ou=test,o=taskana");
|
"businessadmin", "cn=business-admins,cn=groups,ou=test,o=taskana");
|
||||||
|
|
||||||
Set<String> monitorAccessIds = getConfiguration().getRoleMap().get(TaskanaRole.MONITOR);
|
Set<String> monitorAccessIds = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.MONITOR);
|
||||||
assertThat(monitorAccessIds)
|
assertThat(monitorAccessIds)
|
||||||
.containsExactlyInAnyOrder("monitor", "cn=monitor-users,cn=groups,ou=test,o=taskana");
|
.containsExactlyInAnyOrder("monitor", "cn=monitor-users,cn=groups,ou=test,o=taskana");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOtherConfigFileSameDelimiter() throws Exception {
|
void should_ApplyDifferentConfiguration_For_DifferentFile() throws Exception {
|
||||||
String propertiesFileName = createNewConfigFileWithSameDelimiter("dummyTestConfig.properties");
|
String propertiesFileName = createNewConfigFileWithSameDelimiter("dummyTestConfig.properties");
|
||||||
getConfiguration().initTaskanaProperties(propertiesFileName, "|");
|
String delimiter = "|";
|
||||||
|
taskanaEngineConfiguration =
|
||||||
|
new TaskanaEngineConfiguration(
|
||||||
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
propertiesFileName,
|
||||||
|
delimiter,
|
||||||
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
|
|
||||||
Set<TaskanaRole> rolesConfigured = getConfiguration().getRoleMap().keySet();
|
Set<TaskanaRole> rolesConfigured = taskanaEngineConfiguration.getRoleMap().keySet();
|
||||||
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
||||||
|
|
||||||
Set<String> users = getConfiguration().getRoleMap().get(TaskanaRole.USER);
|
Set<String> users = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.USER);
|
||||||
assertThat(users).containsExactly("nobody");
|
assertThat(users).containsExactly("nobody");
|
||||||
|
|
||||||
Set<String> admins = getConfiguration().getRoleMap().get(TaskanaRole.ADMIN);
|
Set<String> admins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.ADMIN);
|
||||||
assertThat(admins).containsExactlyInAnyOrder("user", "username");
|
assertThat(admins).containsExactlyInAnyOrder("user", "username");
|
||||||
|
|
||||||
Set<String> businessAdmins = getConfiguration().getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
Set<String> businessAdmins =
|
||||||
|
taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||||
assertThat(businessAdmins).containsExactlyInAnyOrder("user2", "user3");
|
assertThat(businessAdmins).containsExactlyInAnyOrder("user2", "user3");
|
||||||
|
|
||||||
Set<String> taskAdmins = getConfiguration().getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
Set<String> taskAdmins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||||
assertThat(taskAdmins).containsExactlyInAnyOrder("taskadmin");
|
assertThat(taskAdmins).containsExactlyInAnyOrder("taskadmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOtherConfigFileDifferentDelimiter() throws Exception {
|
void should_ApplyConfiguration_When_UsingDifferentDelimiter() throws Exception {
|
||||||
String delimiter = ";";
|
String delimiter = ";";
|
||||||
String propertiesFileName =
|
String propertiesFileName =
|
||||||
createNewConfigFileWithDifferentDelimiter("dummyTestConfig.properties", delimiter);
|
createNewConfigFileWithDifferentDelimiter("dummyTestConfig.properties", delimiter);
|
||||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
|
||||||
|
|
||||||
Set<TaskanaRole> rolesConfigured = getConfiguration().getRoleMap().keySet();
|
taskanaEngineConfiguration =
|
||||||
|
new TaskanaEngineConfiguration(
|
||||||
|
TaskanaEngineTestConfiguration.getDataSource(),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
propertiesFileName,
|
||||||
|
delimiter,
|
||||||
|
TaskanaEngineTestConfiguration.getSchemaName());
|
||||||
|
|
||||||
|
Set<TaskanaRole> rolesConfigured = taskanaEngineConfiguration.getRoleMap().keySet();
|
||||||
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
||||||
|
|
||||||
Set<String> users = getConfiguration().getRoleMap().get(TaskanaRole.USER);
|
Set<String> users = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.USER);
|
||||||
assertThat(users).isEmpty();
|
assertThat(users).isEmpty();
|
||||||
|
|
||||||
Set<String> admins = getConfiguration().getRoleMap().get(TaskanaRole.ADMIN);
|
Set<String> admins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.ADMIN);
|
||||||
assertThat(admins).containsExactlyInAnyOrder("user", "name=username,organisation=novatec");
|
assertThat(admins).containsExactlyInAnyOrder("user", "name=username,organisation=novatec");
|
||||||
|
|
||||||
Set<String> businessAdmins = getConfiguration().getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
Set<String> businessAdmins =
|
||||||
|
taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||||
assertThat(businessAdmins).containsExactlyInAnyOrder("name=user2, ou = bpm", "user3");
|
assertThat(businessAdmins).containsExactlyInAnyOrder("name=user2, ou = bpm", "user3");
|
||||||
|
|
||||||
Set<String> taskAdmins = getConfiguration().getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
Set<String> taskAdmins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||||
assertThat(taskAdmins).contains("taskadmin");
|
assertThat(taskAdmins).contains("taskadmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,12 +112,7 @@ public class TaskRepresentationModelAssembler
|
||||||
|
|
||||||
public Task toEntityModel(TaskRepresentationModel repModel) throws InvalidArgumentException {
|
public Task toEntityModel(TaskRepresentationModel repModel) throws InvalidArgumentException {
|
||||||
verifyCorrectCustomAttributesFormat(repModel);
|
verifyCorrectCustomAttributesFormat(repModel);
|
||||||
TaskImpl task;
|
TaskImpl task = (TaskImpl) taskService.newTask();
|
||||||
if (repModel.getWorkbasketSummary() != null) {
|
|
||||||
task = (TaskImpl) taskService.newTask(repModel.getWorkbasketSummary().getWorkbasketId());
|
|
||||||
} else {
|
|
||||||
task = (TaskImpl) taskService.newTask();
|
|
||||||
}
|
|
||||||
task.setId(repModel.getTaskId());
|
task.setId(repModel.getTaskId());
|
||||||
task.setExternalId(repModel.getExternalId());
|
task.setExternalId(repModel.getExternalId());
|
||||||
task.setCreated(repModel.getCreated());
|
task.setCreated(repModel.getCreated());
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,8 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>taskana-routing-parent</artifactId>
|
<artifactId>taskana-routing-parent</artifactId>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>${project.groupId}:${project.artifactId}</name>
|
<name>${project.groupId}:${project.artifactId}</name>
|
||||||
|
|
@ -23,5 +20,4 @@
|
||||||
<module>taskana-spi-routing-dmn-router</module>
|
<module>taskana-spi-routing-dmn-router</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,18 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
||||||
|
<artifactId>taskana-spi-routing-dmn-router</artifactId>
|
||||||
|
|
||||||
|
<name>${project.groupId}:${project.artifactId}</name>
|
||||||
|
<description>TaskRouter implementation using dmn tables.</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>taskana-routing-parent</artifactId>
|
<artifactId>taskana-routing-parent</artifactId>
|
||||||
<groupId>pro.taskana</groupId>
|
<groupId>pro.taskana</groupId>
|
||||||
<version>4.5.2-SNAPSHOT</version>
|
<version>4.5.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>taskana-spi-routing-dmn-router</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
@ -58,6 +62,4 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- test dependencies end -->
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package pro.taskana.routing.dmn;
|
package pro.taskana.routing.dmn;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -33,22 +32,18 @@ import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
||||||
public class DmnTaskRouter implements TaskRoutingProvider {
|
public class DmnTaskRouter implements TaskRoutingProvider {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DmnTaskRouter.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DmnTaskRouter.class);
|
||||||
|
private static final String DMN_TABLE_PROPERTY = "taskana.routing.dmn";
|
||||||
|
|
||||||
private static final String DECISION_ID = "workbasketRouting";
|
private static final String DECISION_ID = "workbasketRouting";
|
||||||
private static final String DECISION_VARIABLE_MAP_NAME = "task";
|
private static final String DECISION_VARIABLE_MAP_NAME = "task";
|
||||||
private static final String OUTPUT_WORKBASKET_KEY = "workbasketKey";
|
private static final String OUTPUT_WORKBASKET_KEY = "workbasketKey";
|
||||||
private static final String OUTPUT_DOMAIN = "domain";
|
private static final String OUTPUT_DOMAIN = "domain";
|
||||||
private static final String DMN_TABLE_PROPERTY = "taskana.routing.dmn";
|
|
||||||
private TaskanaEngine taskanaEngine;
|
private TaskanaEngine taskanaEngine;
|
||||||
private DmnEngine dmnEngine;
|
private DmnEngine dmnEngine;
|
||||||
private DmnDecision decision;
|
private DmnDecision decision;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(TaskanaEngine taskanaEngine) {
|
public void initialize(TaskanaEngine taskanaEngine) {
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Entering initialize()");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.taskanaEngine = taskanaEngine;
|
this.taskanaEngine = taskanaEngine;
|
||||||
dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();
|
dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();
|
||||||
|
|
||||||
|
|
@ -57,19 +52,10 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
||||||
decision = dmnEngine.parseDecision(DECISION_ID, dmnModel);
|
decision = dmnEngine.parseDecision(DECISION_ID, dmnModel);
|
||||||
|
|
||||||
validateOutputs(dmnModel);
|
validateOutputs(dmnModel);
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Exiting initialize()");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String determineWorkbasketId(Task task) {
|
public String determineWorkbasketId(Task task) {
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Entering determineWorkbasketId(task = {})", task);
|
|
||||||
}
|
|
||||||
|
|
||||||
VariableMap variables = Variables.putValue(DECISION_VARIABLE_MAP_NAME, task);
|
VariableMap variables = Variables.putValue(DECISION_VARIABLE_MAP_NAME, task);
|
||||||
|
|
||||||
DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);
|
DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);
|
||||||
|
|
@ -83,13 +69,7 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String determinedWorkbasketId =
|
return taskanaEngine.getWorkbasketService().getWorkbasket(workbasketKey, domain).getId();
|
||||||
taskanaEngine.getWorkbasketService().getWorkbasket(workbasketKey, domain).getId();
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug(
|
|
||||||
String.format("Exiting determineWorkbasketId, returning %s", determinedWorkbasketId));
|
|
||||||
}
|
|
||||||
return determinedWorkbasketId;
|
|
||||||
} catch (WorkbasketNotFoundException e) {
|
} catch (WorkbasketNotFoundException e) {
|
||||||
throw new SystemException(
|
throw new SystemException(
|
||||||
String.format(
|
String.format(
|
||||||
|
|
@ -105,11 +85,6 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<Pair<String, String>> getAllWorkbasketAndDomainOutputs(DmnModelInstance dmnModel) {
|
protected Set<Pair<String, String>> getAllWorkbasketAndDomainOutputs(DmnModelInstance dmnModel) {
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Entering getAllWorkbasketAndDomainOutputs()");
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Pair<String, String>> allWorkbasketAndDomainOutputs = new HashSet<>();
|
Set<Pair<String, String>> allWorkbasketAndDomainOutputs = new HashSet<>();
|
||||||
|
|
||||||
for (Rule rule : dmnModel.getModelElementsByType(Rule.class)) {
|
for (Rule rule : dmnModel.getModelElementsByType(Rule.class)) {
|
||||||
|
|
@ -120,67 +95,29 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
||||||
|
|
||||||
allWorkbasketAndDomainOutputs.add(Pair.of(workbasketKey, domain));
|
allWorkbasketAndDomainOutputs.add(Pair.of(workbasketKey, domain));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Exiting getAllWorkbasketAndDomainOutputs()");
|
|
||||||
}
|
|
||||||
|
|
||||||
return allWorkbasketAndDomainOutputs;
|
return allWorkbasketAndDomainOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DmnModelInstance readModelFromDmnTable() {
|
protected DmnModelInstance readModelFromDmnTable() {
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Entering readModelFromDmnTable()");
|
|
||||||
}
|
|
||||||
|
|
||||||
String pathToDmn =
|
String pathToDmn =
|
||||||
taskanaEngine.getConfiguration().readPropertiesFromFile().getProperty(DMN_TABLE_PROPERTY);
|
taskanaEngine.getConfiguration().readPropertiesFromFile().getProperty(DMN_TABLE_PROPERTY);
|
||||||
|
try (InputStream stream = FileLoaderUtil.openFileFromClasspathOrSystem(pathToDmn, getClass())) {
|
||||||
if (FileLoaderUtil.loadFromClasspath(pathToDmn)) {
|
return Dmn.readModelFromStream(stream);
|
||||||
try (InputStream inputStream = DmnTaskRouter.class.getResourceAsStream(pathToDmn)) {
|
|
||||||
if (inputStream == null) {
|
|
||||||
LOGGER.error("dmn file {} was not found on classpath.", pathToDmn);
|
|
||||||
} else {
|
|
||||||
return Dmn.readModelFromStream(inputStream);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.error("caught IOException when processing dmn file");
|
|
||||||
throw new SystemException("Internal System error when processing dmn file", e.getCause());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try (FileInputStream inputStream = new FileInputStream(pathToDmn)) {
|
|
||||||
return Dmn.readModelFromStream(inputStream);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("caught IOException when processing dmn file {}.", pathToDmn);
|
||||||
throw new SystemException(
|
throw new SystemException(
|
||||||
String.format("Could not find a dmn file with provided path %s", pathToDmn));
|
"internal System error when processing dmn file " + pathToDmn, e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateOutputs(DmnModelInstance dmnModel) {
|
private void validateOutputs(DmnModelInstance dmnModel) {
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Entering validateOutputs()");
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Pair<String, String>> allWorkbasketAndDomainOutputs =
|
Set<Pair<String, String>> allWorkbasketAndDomainOutputs =
|
||||||
getAllWorkbasketAndDomainOutputs(dmnModel);
|
getAllWorkbasketAndDomainOutputs(dmnModel);
|
||||||
|
|
||||||
validate(allWorkbasketAndDomainOutputs);
|
validate(allWorkbasketAndDomainOutputs);
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Exiting validateOutputs()");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate(Set<Pair<String, String>> allWorkbasketAndDomainOutputs) {
|
private void validate(Set<Pair<String, String>> allWorkbasketAndDomainOutputs) {
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug(
|
|
||||||
"Entering validate(allWorkbasketAndDomainOutputs = {}", allWorkbasketAndDomainOutputs);
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
|
||||||
for (Pair<String, String> pair : allWorkbasketAndDomainOutputs) {
|
for (Pair<String, String> pair : allWorkbasketAndDomainOutputs) {
|
||||||
|
|
@ -203,9 +140,5 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Exiting validate()");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import pro.taskana.task.api.models.ObjectReference;
|
||||||
import pro.taskana.task.api.models.Task;
|
import pro.taskana.task.api.models.Task;
|
||||||
|
|
||||||
@ExtendWith(JaasExtension.class)
|
@ExtendWith(JaasExtension.class)
|
||||||
public class DmnTaskRouterTest extends AbstractAccTest {
|
class DmnTaskRouterTest extends AbstractAccTest {
|
||||||
|
|
||||||
private final TaskService taskService = taskanaEngine.getTaskService();
|
private final TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue