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.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
@ -21,8 +20,7 @@ public final class TaskanaEngineTestConfiguration {
|
|||
private static String schemaName = null;
|
||||
|
||||
static {
|
||||
String userHomeDirectroy = System.getProperty("user.home");
|
||||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
||||
String propertiesFileName = System.getProperty("user.home") + "/taskanaUnitTest.properties";
|
||||
File f = new File(propertiesFileName);
|
||||
if (f.exists() && !f.isDirectory()) {
|
||||
DATA_SOURCE = createDataSourceFromProperties(propertiesFileName);
|
||||
|
@ -60,8 +58,7 @@ public final class TaskanaEngineTestConfiguration {
|
|||
*/
|
||||
public static String getSchemaName() {
|
||||
if (schemaName == null) {
|
||||
String userHomeDirectroy = System.getProperty("user.home");
|
||||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
||||
String propertiesFileName = System.getProperty("user.home") + "/taskanaUnitTest.properties";
|
||||
File f = new File(propertiesFileName);
|
||||
if (f.exists() && !f.isDirectory()) {
|
||||
schemaName = getSchemaNameFromPropertiesObject(propertiesFileName);
|
||||
|
@ -117,13 +114,13 @@ public final class TaskanaEngineTestConfiguration {
|
|||
((PooledDataSource) ds)
|
||||
.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||
} else {
|
||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
||||
LOGGER.warn("propertiesFile {} is incomplete {}", propertiesFileName, warningMessage);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
ds = createDefaultDataSource();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
||||
LOGGER.warn("createDataSourceFromProperties caught Exception ", e);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
ds = createDefaultDataSource();
|
||||
}
|
||||
|
@ -145,33 +142,20 @@ public final class TaskanaEngineTestConfiguration {
|
|||
}
|
||||
|
||||
if (!propertiesFileIsComplete) {
|
||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
||||
LOGGER.warn("propertiesFile {} is incomplete {}", propertiesFileName, warningMessage);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
schemaName = "TASKANA";
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
LOGGER.warn("getSchemaNameFromPropertiesObject caught Exception " + e);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Caught Exception ", e);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* create Default Datasource for in-memory database.
|
||||
*
|
||||
* @return the default datasource.
|
||||
*/
|
||||
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 jdbcUrl =
|
||||
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;"
|
||||
|
|
|
@ -161,59 +161,6 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
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) {
|
||||
if (isDigit) {
|
||||
buf = stripLeadingZeroes(buf);
|
||||
|
@ -303,7 +250,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
switch (item.getType()) {
|
||||
case INT_ITEM:
|
||||
int itemValue = ((IntItem) item).value;
|
||||
return (value < itemValue) ? -1 : ((value == itemValue) ? 0 : 1);
|
||||
return Integer.compare(value, itemValue);
|
||||
case LONG_ITEM:
|
||||
case BIGINTEGER_ITEM:
|
||||
return -1;
|
||||
|
@ -373,7 +320,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
return 1;
|
||||
case LONG_ITEM:
|
||||
long itemValue = ((LongItem) item).value;
|
||||
return (value < itemValue) ? -1 : ((value == itemValue) ? 0 : 1);
|
||||
return Long.compare(value, itemValue);
|
||||
case BIGINTEGER_ITEM:
|
||||
return -1;
|
||||
|
||||
|
@ -642,7 +589,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
Item r = right.hasNext() ? right.next() : null;
|
||||
|
||||
// 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) {
|
||||
return result;
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
package pro.taskana.common.internal.util;
|
||||
|
||||
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 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;
|
||||
File f = new File(fileToLoad);
|
||||
if (f.exists() && !f.isDirectory()) {
|
||||
|
@ -13,4 +26,24 @@ public class FileLoaderUtil {
|
|||
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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
|
@ -48,6 +44,7 @@ import pro.taskana.common.internal.util.Pair;
|
|||
* <br>
|
||||
* Security is enabled by default.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
|
||||
public class TaskanaEngineConfiguration {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfiguration.class);
|
||||
|
@ -368,6 +365,10 @@ public class TaskanaEngineConfiguration {
|
|||
return true;
|
||||
}
|
||||
|
||||
public Properties readPropertiesFromFile() {
|
||||
return readPropertiesFromFile(this.propertiesFileName);
|
||||
}
|
||||
|
||||
private <T> Optional<T> parseProperty(
|
||||
Properties props, String key, CheckedFunction<String, T> function) {
|
||||
String property = props.getProperty(key, "");
|
||||
|
@ -556,29 +557,12 @@ public class TaskanaEngineConfiguration {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Properties readPropertiesFromFile() {
|
||||
return readPropertiesFromFile(this.propertiesFileName);
|
||||
}
|
||||
|
||||
|
||||
private Properties readPropertiesFromFile(String propertiesFile) {
|
||||
Properties props = new Properties();
|
||||
boolean loadFromClasspath = FileLoaderUtil.loadFromClasspath(propertiesFile);
|
||||
try {
|
||||
if (loadFromClasspath) {
|
||||
InputStream inputStream =
|
||||
TaskanaEngineConfiguration.class.getResourceAsStream(propertiesFile);
|
||||
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);
|
||||
try (InputStream stream =
|
||||
FileLoaderUtil.openFileFromClasspathOrSystem(propertiesFile, getClass())) {
|
||||
props.load(stream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("caught IOException when processing properties file {}.", propertiesFile);
|
||||
|
@ -587,13 +571,4 @@ public class TaskanaEngineConfiguration {
|
|||
}
|
||||
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.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import pro.taskana.TaskanaEngineConfiguration;
|
||||
import pro.taskana.common.internal.TaskanaEngineImpl;
|
||||
|
||||
/** Test taskana configuration without roles. */
|
||||
class TaskanaConfigAccTest extends TaskanaEngineImpl {
|
||||
class TaskanaConfigAccTest {
|
||||
|
||||
@TempDir Path tempDir;
|
||||
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
|
||||
TaskanaConfigAccTest() throws Exception {
|
||||
super(
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
true,
|
||||
TaskanaEngineTestConfiguration.getSchemaName()));
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDomains() {
|
||||
assertThat(getConfiguration().getDomains()).containsExactlyInAnyOrder("DOMAIN_A", "DOMAIN_B");
|
||||
void should_ConfigureDomains_For_DefaultPropertiesFile() {
|
||||
assertThat(taskanaEngineConfiguration.getDomains())
|
||||
.containsExactlyInAnyOrder("DOMAIN_A", "DOMAIN_B");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassificationTypes() {
|
||||
assertThat(getConfiguration().getClassificationTypes())
|
||||
void should_ConfigureClassificationTypes_For_DefaultPropertiesFile() {
|
||||
assertThat(taskanaEngineConfiguration.getClassificationTypes())
|
||||
.containsExactlyInAnyOrder("TASK", "DOCUMENT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassificationCategories() {
|
||||
assertThat(getConfiguration().getClassificationCategoriesByType("TASK"))
|
||||
void should_ConfigureClassificationCategories_For_DefaultPropertiesFile() {
|
||||
assertThat(taskanaEngineConfiguration.getClassificationCategoriesByType("TASK"))
|
||||
.containsExactlyInAnyOrder("EXTERNAL", "MANUAL", "AUTOMATIC", "PROCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoesNotExistPropertyClassificationTypeOrItIsEmpty() throws Exception {
|
||||
taskanaEngineConfiguration.setClassificationTypes(new ArrayList<>());
|
||||
String propertiesFileName = createNewConfigFile("dummyTestConfig.properties", false, true);
|
||||
void should_NotConfigureClassificationTypes_When_PropertiesAreNotDefined() throws Exception {
|
||||
String propertiesFileName = createNewConfigFile("dummyTestConfig1.properties", false, true);
|
||||
String delimiter = ";";
|
||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
||||
taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
true,
|
||||
true,
|
||||
propertiesFileName,
|
||||
delimiter,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
assertThat(taskanaEngineConfiguration.getClassificationTypes()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoesNotExistPropertyClassificationCategoryOrItIsEmpty() throws Exception {
|
||||
taskanaEngineConfiguration.setClassificationTypes(new ArrayList<>());
|
||||
taskanaEngineConfiguration.setClassificationCategoriesByType(new HashMap<>());
|
||||
String propertiesFileName = createNewConfigFile("dummyTestConfig.properties", true, false);
|
||||
void should_NotConfigureClassificationCategories_When_PropertiesAreNotDefined() throws Exception {
|
||||
String propertiesFileName = createNewConfigFile("dummyTestConfig2.properties", true, false);
|
||||
String delimiter = ";";
|
||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
||||
assertThat(
|
||||
taskanaEngineConfiguration.getClassificationCategoriesByType(
|
||||
taskanaEngineConfiguration.getClassificationTypes().get(0)))
|
||||
.isEmpty();
|
||||
taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
true,
|
||||
true,
|
||||
propertiesFileName,
|
||||
delimiter,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
assertThat(taskanaEngineConfiguration.getClassificationCategoriesByTypeMap())
|
||||
.containsExactly(
|
||||
Map.entry("TASK", Collections.emptyList()),
|
||||
Map.entry("DOCUMENT", Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithCategoriesAndClassificationFilled() throws Exception {
|
||||
taskanaEngineConfiguration.setClassificationTypes(new ArrayList<>());
|
||||
taskanaEngineConfiguration.setClassificationCategoriesByType(new HashMap<>());
|
||||
String propertiesFileName = createNewConfigFile("dummyTestConfig.properties", true, true);
|
||||
void should_ApplyClassificationProperties_When_PropertiesAreDefined() throws Exception {
|
||||
String propertiesFileName = createNewConfigFile("dummyTestConfig3.properties", true, true);
|
||||
String delimiter = ";";
|
||||
getConfiguration().initTaskanaProperties(propertiesFileName, delimiter);
|
||||
assertThat(taskanaEngineConfiguration.getClassificationTypes().isEmpty()).isFalse();
|
||||
assertThat(
|
||||
taskanaEngineConfiguration
|
||||
.getClassificationCategoriesByType(
|
||||
taskanaEngineConfiguration.getClassificationTypes().get(0))
|
||||
.isEmpty())
|
||||
.isFalse();
|
||||
assertThat(taskanaEngineConfiguration.getClassificationTypes()).hasSize(2);
|
||||
assertThat(
|
||||
taskanaEngineConfiguration
|
||||
.getClassificationCategoriesByType(
|
||||
taskanaEngineConfiguration.getClassificationTypes().get(0))
|
||||
.size())
|
||||
.isEqualTo(4);
|
||||
assertThat(
|
||||
taskanaEngineConfiguration
|
||||
.getClassificationCategoriesByType(
|
||||
taskanaEngineConfiguration.getClassificationTypes().get(1))
|
||||
.size())
|
||||
.isEqualTo(1);
|
||||
taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
true,
|
||||
true,
|
||||
propertiesFileName,
|
||||
delimiter,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
assertThat(taskanaEngineConfiguration.getClassificationCategoriesByTypeMap())
|
||||
.containsExactly(
|
||||
Map.entry("TASK", List.of("EXTERNAL", "MANUAL", "AUTOMATIC", "PROCESS")),
|
||||
Map.entry("DOCUMENT", List.of("EXTERNAL")));
|
||||
}
|
||||
|
||||
private String createNewConfigFile(
|
||||
|
|
|
@ -64,7 +64,7 @@ class TaskanaEngineConfigTest {
|
|||
ds,
|
||||
false,
|
||||
true,
|
||||
"/custom_holiday_With_Wrong_format_taskana.properties",
|
||||
"/custom_holiday_with_wrong_format_taskana.properties",
|
||||
"|",
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
assertThat(taskEngineConfiguration.getCustomHolidays()).isEmpty();
|
||||
|
|
|
@ -8,32 +8,35 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import pro.taskana.TaskanaEngineConfiguration;
|
||||
import pro.taskana.common.api.TaskanaRole;
|
||||
import pro.taskana.common.internal.TaskanaEngineImpl;
|
||||
|
||||
/** Test taskana's role configuration. */
|
||||
class TaskanaRoleConfigAccTest extends TaskanaEngineImpl {
|
||||
class TaskanaRoleConfigAccTest {
|
||||
|
||||
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
|
||||
@TempDir Path tempDir;
|
||||
|
||||
TaskanaRoleConfigAccTest() throws Exception {
|
||||
super(
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
true,
|
||||
TaskanaEngineTestConfiguration.getSchemaName()));
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStandardConfig() {
|
||||
Set<TaskanaRole> rolesConfigured = getConfiguration().getRoleMap().keySet();
|
||||
void should_ApplyDefaultConfiguration_For_DefaultPropertiesFile() {
|
||||
Set<TaskanaRole> rolesConfigured = taskanaEngineConfiguration.getRoleMap().keySet();
|
||||
assertThat(rolesConfigured).containsExactlyInAnyOrder(TaskanaRole.values());
|
||||
|
||||
Set<String> users = getConfiguration().getRoleMap().get(TaskanaRole.USER);
|
||||
Set<String> users = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.USER);
|
||||
assertThat(users)
|
||||
.containsExactlyInAnyOrder(
|
||||
"teamlead-1",
|
||||
|
@ -45,63 +48,82 @@ class TaskanaRoleConfigAccTest extends TaskanaEngineImpl {
|
|||
"user-b-1",
|
||||
"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");
|
||||
|
||||
Set<String> taskAdmins = getConfiguration().getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||
Set<String> taskAdmins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||
assertThat(taskAdmins).containsExactlyInAnyOrder("taskadmin");
|
||||
|
||||
Set<String> businessAdmins = getConfiguration().getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||
Set<String> businessAdmins =
|
||||
taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||
assertThat(businessAdmins)
|
||||
.containsExactlyInAnyOrder(
|
||||
"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)
|
||||
.containsExactlyInAnyOrder("monitor", "cn=monitor-users,cn=groups,ou=test,o=taskana");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOtherConfigFileSameDelimiter() throws Exception {
|
||||
void should_ApplyDifferentConfiguration_For_DifferentFile() throws Exception {
|
||||
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());
|
||||
|
||||
Set<String> users = getConfiguration().getRoleMap().get(TaskanaRole.USER);
|
||||
Set<String> users = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.USER);
|
||||
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");
|
||||
|
||||
Set<String> businessAdmins = getConfiguration().getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||
Set<String> businessAdmins =
|
||||
taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.BUSINESS_ADMIN);
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOtherConfigFileDifferentDelimiter() throws Exception {
|
||||
void should_ApplyConfiguration_When_UsingDifferentDelimiter() throws Exception {
|
||||
String delimiter = ";";
|
||||
String propertiesFileName =
|
||||
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());
|
||||
|
||||
Set<String> users = getConfiguration().getRoleMap().get(TaskanaRole.USER);
|
||||
Set<String> users = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.USER);
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
Set<String> taskAdmins = getConfiguration().getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||
Set<String> taskAdmins = taskanaEngineConfiguration.getRoleMap().get(TaskanaRole.TASK_ADMIN);
|
||||
assertThat(taskAdmins).contains("taskadmin");
|
||||
}
|
||||
|
||||
|
|
|
@ -112,12 +112,7 @@ public class TaskRepresentationModelAssembler
|
|||
|
||||
public Task toEntityModel(TaskRepresentationModel repModel) throws InvalidArgumentException {
|
||||
verifyCorrectCustomAttributesFormat(repModel);
|
||||
TaskImpl task;
|
||||
if (repModel.getWorkbasketSummary() != null) {
|
||||
task = (TaskImpl) taskService.newTask(repModel.getWorkbasketSummary().getWorkbasketId());
|
||||
} else {
|
||||
task = (TaskImpl) taskService.newTask();
|
||||
}
|
||||
TaskImpl task = (TaskImpl) taskService.newTask();
|
||||
task.setId(repModel.getTaskId());
|
||||
task.setExternalId(repModel.getExternalId());
|
||||
task.setCreated(repModel.getCreated());
|
||||
|
|
|
@ -2,11 +2,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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>taskana-routing-parent</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
|
@ -23,5 +20,4 @@
|
|||
<module>taskana-spi-routing-dmn-router</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
@ -2,14 +2,18 @@
|
|||
<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">
|
||||
<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>
|
||||
<artifactId>taskana-routing-parent</artifactId>
|
||||
<groupId>pro.taskana</groupId>
|
||||
<version>4.5.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>taskana-spi-routing-dmn-router</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -58,6 +62,4 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- test dependencies end -->
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package pro.taskana.routing.dmn;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,22 +32,18 @@ import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
|||
public class DmnTaskRouter implements TaskRoutingProvider {
|
||||
|
||||
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_VARIABLE_MAP_NAME = "task";
|
||||
private static final String OUTPUT_WORKBASKET_KEY = "workbasketKey";
|
||||
private static final String OUTPUT_DOMAIN = "domain";
|
||||
private static final String DMN_TABLE_PROPERTY = "taskana.routing.dmn";
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private DmnEngine dmnEngine;
|
||||
private DmnDecision decision;
|
||||
|
||||
@Override
|
||||
public void initialize(TaskanaEngine taskanaEngine) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Entering initialize()");
|
||||
}
|
||||
|
||||
this.taskanaEngine = taskanaEngine;
|
||||
dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();
|
||||
|
||||
|
@ -57,19 +52,10 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
|||
decision = dmnEngine.parseDecision(DECISION_ID, dmnModel);
|
||||
|
||||
validateOutputs(dmnModel);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Exiting initialize()");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String determineWorkbasketId(Task task) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Entering determineWorkbasketId(task = {})", task);
|
||||
}
|
||||
|
||||
VariableMap variables = Variables.putValue(DECISION_VARIABLE_MAP_NAME, task);
|
||||
|
||||
DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);
|
||||
|
@ -83,13 +69,7 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
|||
|
||||
try {
|
||||
|
||||
String determinedWorkbasketId =
|
||||
taskanaEngine.getWorkbasketService().getWorkbasket(workbasketKey, domain).getId();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
String.format("Exiting determineWorkbasketId, returning %s", determinedWorkbasketId));
|
||||
}
|
||||
return determinedWorkbasketId;
|
||||
return taskanaEngine.getWorkbasketService().getWorkbasket(workbasketKey, domain).getId();
|
||||
} catch (WorkbasketNotFoundException e) {
|
||||
throw new SystemException(
|
||||
String.format(
|
||||
|
@ -105,11 +85,6 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
|||
}
|
||||
|
||||
protected Set<Pair<String, String>> getAllWorkbasketAndDomainOutputs(DmnModelInstance dmnModel) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Entering getAllWorkbasketAndDomainOutputs()");
|
||||
}
|
||||
|
||||
Set<Pair<String, String>> allWorkbasketAndDomainOutputs = new HashSet<>();
|
||||
|
||||
for (Rule rule : dmnModel.getModelElementsByType(Rule.class)) {
|
||||
|
@ -120,67 +95,29 @@ public class DmnTaskRouter implements TaskRoutingProvider {
|
|||
|
||||
allWorkbasketAndDomainOutputs.add(Pair.of(workbasketKey, domain));
|
||||
}
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Exiting getAllWorkbasketAndDomainOutputs()");
|
||||
}
|
||||
|
||||
return allWorkbasketAndDomainOutputs;
|
||||
}
|
||||
|
||||
protected DmnModelInstance readModelFromDmnTable() {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Entering readModelFromDmnTable()");
|
||||
}
|
||||
|
||||
String pathToDmn =
|
||||
taskanaEngine.getConfiguration().readPropertiesFromFile().getProperty(DMN_TABLE_PROPERTY);
|
||||
|
||||
if (FileLoaderUtil.loadFromClasspath(pathToDmn)) {
|
||||
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);
|
||||
try (InputStream stream = FileLoaderUtil.openFileFromClasspathOrSystem(pathToDmn, getClass())) {
|
||||
return Dmn.readModelFromStream(stream);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("caught IOException when processing dmn file {}.", pathToDmn);
|
||||
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) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Entering validateOutputs()");
|
||||
}
|
||||
|
||||
Set<Pair<String, String>> allWorkbasketAndDomainOutputs =
|
||||
getAllWorkbasketAndDomainOutputs(dmnModel);
|
||||
|
||||
validate(allWorkbasketAndDomainOutputs);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Exiting validateOutputs()");
|
||||
}
|
||||
}
|
||||
|
||||
private void validate(Set<Pair<String, String>> allWorkbasketAndDomainOutputs) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"Entering validate(allWorkbasketAndDomainOutputs = {}", allWorkbasketAndDomainOutputs);
|
||||
}
|
||||
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
|
||||
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;
|
||||
|
||||
@ExtendWith(JaasExtension.class)
|
||||
public class DmnTaskRouterTest extends AbstractAccTest {
|
||||
class DmnTaskRouterTest extends AbstractAccTest {
|
||||
|
||||
private final TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
|
|
Loading…
Reference in New Issue