TSK-1337: removed some code smells

This commit is contained in:
Mustapha Zorgati 2020-07-25 14:01:25 +02:00
parent f79f7587a9
commit 41973183bc
29 changed files with 259 additions and 380 deletions

View File

@ -1,5 +1,5 @@
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.admin=name=konrad,Organisation=novatec|admin
taskana.roles.businessadmin=max|Moritz|businessadmin
taskana.roles.monitor=john|teamlead_2 | monitor
taskana.roles.taskadmin=peter | taskadmin

View File

@ -3,6 +3,5 @@ package pro.taskana;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/** TODO Why does this test exist?. */
@ApplicationPath("/rest")
public class RestApplication extends Application {}

View File

@ -18,11 +18,10 @@ import pro.taskana.task.api.models.Task;
import pro.taskana.workbasket.api.WorkbasketType;
import pro.taskana.workbasket.api.models.Workbasket;
/** TODO. */
@Path("/test")
public class TaskanaRestTest {
public class TaskanaCdiTestRestController {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaRestTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaCdiTestRestController.class);
@EJB private TaskanaEjb taskanaEjb;

View File

@ -14,7 +14,6 @@ import pro.taskana.task.api.models.Task;
import pro.taskana.workbasket.api.WorkbasketService;
import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
/** TODO. */
@Stateless
public class TaskanaEjb {

View File

@ -15,7 +15,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.swarm.undertow.WARArchive;
/** TODO. */
@RunWith(Arquillian.class)
public class TaskanaProducersTest {

View File

@ -18,9 +18,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.sql.DataSource;
@ -37,6 +41,8 @@ import pro.taskana.common.internal.TaskanaEngineImpl;
import pro.taskana.common.internal.configuration.DB;
import pro.taskana.common.internal.configuration.DbSchemaCreator;
import pro.taskana.common.internal.configuration.SecurityVerifier;
import pro.taskana.common.internal.util.CheckedFunction;
import pro.taskana.common.internal.util.Pair;
/**
* This central class creates the TaskanaEngine and holds all the information about DB and Security.
@ -82,7 +88,7 @@ public class TaskanaEngineConfiguration {
protected String schemaName;
// Taskana role configuration
protected String propertiesSeparator = TASKANA_PROPERTY_SEPARATOR;
protected Map<TaskanaRole, Set<String>> roleMap = new HashMap<>();
protected Map<TaskanaRole, Set<String>> roleMap;
// global switch to enable JAAS based authentication and Taskana
// authorizations
protected boolean securityEnabled;
@ -163,21 +169,24 @@ public class TaskanaEngineConfiguration {
securityVerifier.checkSecureAccess(securityEnabled);
}
public void initTaskanaProperties(String propertiesFile, String rolesSeparator) {
public void initTaskanaProperties(String propertiesFile, String separator) {
LOGGER.debug(
"Reading taskana configuration from {} with role separator {}",
propertiesFile,
rolesSeparator);
"Reading taskana configuration from {} with separator {}", propertiesFile, separator);
Properties props = readPropertiesFromFile(propertiesFile);
initTaskanaRoles(props, rolesSeparator);
initTaskanaRoles(props, separator);
initJobParameters(props);
initDomains(props);
initClassificationTypes(props);
initClassificationCategories(props);
initBooleanFlag(props, TASKANA_GERMAN_HOLIDAYS_ENABLED);
initBooleanFlag(props, TASKANA_GERMAN_HOLIDAYS_CORPUS_CHRISTI_ENABLED);
initBooleanFlag(props, TASKANA_HISTORY_DELETION_ON_TASK_DELETION_ENABLED);
initCustomHolidays(props);
initBooleanProperty(
props, TASKANA_GERMAN_HOLIDAYS_ENABLED, this::setGermanPublicHolidaysEnabled);
initBooleanProperty(
props, TASKANA_GERMAN_HOLIDAYS_CORPUS_CHRISTI_ENABLED, this::setCorpusChristiEnabled);
initBooleanProperty(
props,
TASKANA_HISTORY_DELETION_ON_TASK_DELETION_ENABLED,
this::setDeleteHistoryOnTaskDeletionEnabled);
initCustomHolidays(props, separator);
}
public static DataSource createDefaultDataSource() {
@ -232,28 +241,20 @@ public class TaskanaEngineConfiguration {
return this.useManagedTransactions;
}
public String getPropertiesFileName() {
return this.propertiesFileName;
}
public void setPropertiesFileName(String propertiesFileName) {
this.propertiesFileName = propertiesFileName;
}
public int getMaxNumberOfUpdatesPerTransaction() {
return jobBatchSize;
}
public void setMaxNumberOfUpdatesPerTransaction(int jobBatchSize) {
this.jobBatchSize = jobBatchSize;
}
public int getMaxNumberOfJobRetries() {
return maxNumberOfJobRetries;
}
public String getPropertiesSeparator() {
return this.propertiesSeparator;
}
public void setPropertiesSeparator(String propertiesSeparator) {
this.propertiesSeparator = propertiesSeparator;
public void setMaxNumberOfJobRetries(int maxNumberOfJobRetries) {
this.maxNumberOfJobRetries = maxNumberOfJobRetries;
}
public boolean isCorpusChristiEnabled() {
@ -292,6 +293,7 @@ public class TaskanaEngineConfiguration {
return roleMap;
}
@SuppressWarnings("unused")
public void setRoleMap(Map<TaskanaRole, Set<String>> roleMap) {
this.roleMap = roleMap;
}
@ -338,14 +340,26 @@ public class TaskanaEngineConfiguration {
return cleanupJobFirstRun;
}
public void setCleanupJobFirstRun(Instant cleanupJobFirstRun) {
this.cleanupJobFirstRun = cleanupJobFirstRun;
}
public Duration getCleanupJobRunEvery() {
return cleanupJobRunEvery;
}
public void setCleanupJobRunEvery(Duration cleanupJobRunEvery) {
this.cleanupJobRunEvery = cleanupJobRunEvery;
}
public Duration getCleanupJobMinimumAge() {
return cleanupJobMinimumAge;
}
public void setCleanupJobMinimumAge(Duration cleanupJobMinimumAge) {
this.cleanupJobMinimumAge = cleanupJobMinimumAge;
}
public boolean isTaskCleanupJobAllCompletedSameParentBusiness() {
return taskCleanupJobAllCompletedSameParentBusiness;
}
@ -374,99 +388,45 @@ public class TaskanaEngineConfiguration {
return true;
}
private void initBooleanFlag(Properties props, String propName) {
String enabled = props.getProperty(propName);
if (enabled != null && !enabled.isEmpty()) {
boolean isEnabled = Boolean.parseBoolean(enabled);
if (propName.equals(TASKANA_GERMAN_HOLIDAYS_ENABLED)) {
germanPublicHolidaysEnabled = isEnabled;
} else if (propName.equals(TASKANA_GERMAN_HOLIDAYS_CORPUS_CHRISTI_ENABLED)) {
corpusChristiEnabled = isEnabled;
} else if (propName.equals(TASKANA_HISTORY_DELETION_ON_TASK_DELETION_ENABLED)) {
deleteHistoryOnTaskDeletionEnabled = isEnabled;
private <T> Optional<T> parseProperty(
Properties props, String key, CheckedFunction<String, T> function) {
String property = props.getProperty(key, "");
if (!property.isEmpty()) {
try {
return Optional.ofNullable(function.apply(property));
} catch (Throwable t) {
LOGGER.warn(
"Could not parse property {} ({}). Using default. Exception: {}",
key,
property,
t.getMessage());
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("%s = %b", propName, Boolean.parseBoolean(enabled)));
}
return Optional.empty();
}
private void initJobParameters(Properties props) {
String jobBatchSizeProperty = props.getProperty(TASKANA_JOB_BATCH_SIZE);
if (jobBatchSizeProperty != null && !jobBatchSizeProperty.isEmpty()) {
try {
jobBatchSize = Integer.parseInt(jobBatchSizeProperty);
} catch (Exception e) {
LOGGER.warn(
"Could not parse jobBatchSizeProperty ({}). Using default. Exception: {} ",
jobBatchSizeProperty,
e.getMessage());
}
}
String maxNumberOfJobRetriesProperty = props.getProperty(TASKANA_JOB_RETRIES);
if (maxNumberOfJobRetriesProperty != null && !maxNumberOfJobRetriesProperty.isEmpty()) {
try {
maxNumberOfJobRetries = Integer.parseInt(maxNumberOfJobRetriesProperty);
} catch (Exception e) {
LOGGER.warn(
"Could not parse maxNumberOfJobRetriesProperty ({}). Using default. Exception: {} ",
maxNumberOfJobRetriesProperty,
e.getMessage());
}
}
parseProperty(props, TASKANA_JOB_BATCH_SIZE, Integer::parseInt)
.ifPresent(this::setMaxNumberOfUpdatesPerTransaction);
String taskCleanupJobFirstRunProperty = props.getProperty(TASKANA_JOB_CLEANUP_FIRST_RUN);
if (taskCleanupJobFirstRunProperty != null && !taskCleanupJobFirstRunProperty.isEmpty()) {
try {
cleanupJobFirstRun = Instant.parse(taskCleanupJobFirstRunProperty);
} catch (Exception e) {
LOGGER.warn(
"Could not parse taskCleanupJobFirstRunProperty ({}). Using default. Exception: {} ",
taskCleanupJobFirstRunProperty,
e.getMessage());
}
}
parseProperty(props, TASKANA_JOB_RETRIES, Integer::parseInt)
.ifPresent(this::setMaxNumberOfJobRetries);
String taskCleanupJobRunEveryProperty = props.getProperty(TASKANA_JOB_CLEANUP_RUN_EVERY);
if (taskCleanupJobRunEveryProperty != null && !taskCleanupJobRunEveryProperty.isEmpty()) {
try {
cleanupJobRunEvery = Duration.parse(taskCleanupJobRunEveryProperty);
} catch (Exception e) {
LOGGER.warn(
"Could not parse taskCleanupJobRunEveryProperty ({}). Using default. Exception: {} ",
taskCleanupJobRunEveryProperty,
e.getMessage());
}
}
parseProperty(props, TASKANA_JOB_CLEANUP_FIRST_RUN, Instant::parse)
.ifPresent(this::setCleanupJobFirstRun);
String taskCleanupJobMinimumAgeProperty = props.getProperty(TASKANA_JOB_CLEANUP_MINIMUM_AGE);
if (taskCleanupJobMinimumAgeProperty != null && !taskCleanupJobMinimumAgeProperty.isEmpty()) {
try {
cleanupJobMinimumAge = Duration.parse(taskCleanupJobMinimumAgeProperty);
} catch (Exception e) {
LOGGER.warn(
"Could not parse taskCleanupJobMinimumAgeProperty ({}). Using default. Exception: {} ",
taskCleanupJobMinimumAgeProperty,
e.getMessage());
}
}
parseProperty(props, TASKANA_JOB_CLEANUP_RUN_EVERY, Duration::parse)
.ifPresent(this::setCleanupJobRunEvery);
String taskCleanupJobAllCompletedSameParentBusinessProperty =
props.getProperty(TASKANA_JOB_TASK_CLEANUP_ALL_COMPLETED_SAME_PARENT_BUSINESS);
if (taskCleanupJobAllCompletedSameParentBusinessProperty != null
&& !taskCleanupJobAllCompletedSameParentBusinessProperty.isEmpty()) {
try {
taskCleanupJobAllCompletedSameParentBusiness =
Boolean.parseBoolean(taskCleanupJobAllCompletedSameParentBusinessProperty);
} catch (Exception e) {
LOGGER.warn(
"Could not parse taskCleanupJobAllCompletedSameParentBusinessProperty "
+ "({}). Using default. Exception: {} ",
taskCleanupJobAllCompletedSameParentBusinessProperty,
e.getMessage());
}
}
parseProperty(props, TASKANA_JOB_CLEANUP_MINIMUM_AGE, Duration::parse)
.ifPresent(this::setCleanupJobMinimumAge);
parseProperty(
props,
TASKANA_JOB_TASK_CLEANUP_ALL_COMPLETED_SAME_PARENT_BUSINESS,
Boolean::parseBoolean)
.ifPresent(this::setTaskCleanupJobAllCompletedSameParentBusiness);
LOGGER.debug(
"Configured number of task and workbasket updates per transaction: {}", jobBatchSize);
@ -483,51 +443,45 @@ public class TaskanaEngineConfiguration {
}
private void initDomains(Properties props) {
String domainNames = props.getProperty(TASKANA_DOMAINS_PROPERTY);
if (domainNames != null && !domainNames.isEmpty()) {
StringTokenizer st = new StringTokenizer(domainNames, ",");
while (st.hasMoreTokens()) {
domains.add(st.nextToken().trim().toUpperCase());
}
}
CheckedFunction<String, List<String>> parseFunction =
p -> splitStringAndTrimElements(p, ",", String::toUpperCase);
parseProperty(props, TASKANA_DOMAINS_PROPERTY, parseFunction).ifPresent(this::setDomains);
LOGGER.debug("Configured domains: {}", domains);
}
private void initClassificationTypes(Properties props) {
String classificationTypesNames = props.getProperty(TASKANA_CLASSIFICATION_TYPES_PROPERTY);
if (classificationTypesNames != null && !classificationTypesNames.isEmpty()) {
StringTokenizer st = new StringTokenizer(classificationTypesNames, ",");
while (st.hasMoreTokens()) {
classificationTypes.add(st.nextToken().trim().toUpperCase());
}
} else {
LOGGER.warn("Configuration issue. Classification type is missing");
}
CheckedFunction<String, List<String>> parseFunction =
p -> splitStringAndTrimElements(p, ",", String::toUpperCase);
parseProperty(props, TASKANA_CLASSIFICATION_TYPES_PROPERTY, parseFunction)
.ifPresent(this::setClassificationTypes);
LOGGER.debug("Configured classificationTypes: {}", classificationTypes);
}
private void initClassificationCategories(Properties props) {
if (classificationTypes != null && !classificationTypes.isEmpty()) {
String classificationCategoryNames;
StringTokenizer st;
List<String> classificationCategoriesAux;
for (String type : classificationTypes) {
classificationCategoriesAux = new ArrayList<>();
classificationCategoryNames =
props.getProperty(
TASKANA_CLASSIFICATION_CATEGORIES_PROPERTY + "." + type.toLowerCase());
if (classificationCategoryNames != null && !classificationCategoryNames.isEmpty()) {
st = new StringTokenizer(classificationCategoryNames, ",");
while (st.hasMoreTokens()) {
classificationCategoriesAux.add(st.nextToken().trim().toUpperCase());
}
classificationCategoriesByTypeMap.put(type, classificationCategoriesAux);
} else {
LOGGER.warn("Configuration issue. Classification categories by type is missing");
}
}
}
LOGGER.debug("Configured classification categories : {}", domains);
Function<String, List<String>> getClassificationCategoriesForType =
type -> {
CheckedFunction<String, List<String>> parseFunction =
s -> splitStringAndTrimElements(s, ",", String::toUpperCase);
return parseProperty(
props,
TASKANA_CLASSIFICATION_CATEGORIES_PROPERTY + "." + type.toLowerCase(),
parseFunction)
.orElseGet(ArrayList::new);
};
classificationCategoriesByTypeMap =
classificationTypes.stream()
.map(type -> Pair.of(type, getClassificationCategoriesForType.apply(type)))
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
LOGGER.debug("Configured classification categories : {}", classificationCategoriesByTypeMap);
}
private void initBooleanProperty(
Properties props, String propertyName, Consumer<Boolean> consumer) {
parseProperty(props, propertyName, Boolean::parseBoolean).ifPresent(consumer);
}
private void initSchemaName(String schemaName) {
@ -552,45 +506,54 @@ public class TaskanaEngineConfiguration {
}
private void initTaskanaRoles(Properties props, String rolesSeparator) {
List<String> validPropertyNames = TaskanaRole.getValidPropertyNames();
Function<TaskanaRole, Set<String>> getAccessIdsForRole =
role -> {
List<String> accessIds =
splitStringAndTrimElements(
props.getProperty(role.getPropertyName().toLowerCase(), ""),
rolesSeparator,
shouldUseLowerCaseForAccessIds()
? String::toLowerCase
: UnaryOperator.identity());
return new HashSet<>(accessIds);
};
props.keySet().stream()
.map(String::valueOf)
.filter(propertyName -> validPropertyNames.contains(propertyName.toLowerCase().trim()))
.forEach(
validPropertyName ->
roleMap.put(
TaskanaRole.fromPropertyName(validPropertyName),
getTokensWithCollection(props.getProperty(validPropertyName), rolesSeparator)));
ensureRoleMapIsFullyInitialized();
roleMap =
Arrays.stream(TaskanaRole.values())
.map(role -> Pair.of(role, getAccessIdsForRole.apply(role)))
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
if (LOGGER.isDebugEnabled()) {
roleMap.forEach((k, v) -> LOGGER.debug("Found Taskana RoleConfig {} : {} ", k, v));
}
}
private void initCustomHolidays(Properties props) {
if (props.getProperty(TASKANA_CUSTOM_HOLIDAY) != null) {
Arrays.asList(
props.getProperty(TASKANA_CUSTOM_HOLIDAY).split(Pattern.quote(propertiesSeparator)))
.forEach(
entry -> {
try {
customHolidays.add(createCustomHolidayFromPropsEntry(entry));
} catch (WrongCustomHolidayFormatException e) {
LOGGER.warn(e.getMessage());
}
});
}
private void initCustomHolidays(Properties props, String separator) {
CheckedFunction<String, List<CustomHoliday>> parseFunction =
s ->
splitStringAndTrimElements(s, separator).stream()
.map(
str -> {
try {
return createCustomHolidayFromPropsEntry(str);
} catch (WrongCustomHolidayFormatException e) {
LOGGER.warn(e.getMessage());
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
parseProperty(props, TASKANA_CUSTOM_HOLIDAY, parseFunction).ifPresent(this::addCustomHolidays);
LOGGER.debug("Configured custom Holidays : {}", customHolidays);
}
private CustomHoliday createCustomHolidayFromPropsEntry(String customHolidayEntry)
throws WrongCustomHolidayFormatException {
String[] parts =
customHolidayEntry.split(Pattern.quote(TASKANA_CUSTOM_HOLIDAY_DAY_MONTH_SEPARATOR));
if (parts.length == 2) {
return CustomHoliday.of(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]));
List<String> parts =
splitStringAndTrimElements(customHolidayEntry, TASKANA_CUSTOM_HOLIDAY_DAY_MONTH_SEPARATOR);
if (parts.size() == 2) {
return CustomHoliday.of(Integer.valueOf(parts.get(0)), Integer.valueOf(parts.get(1)));
}
throw new WrongCustomHolidayFormatException(
String.format(
@ -599,10 +562,17 @@ public class TaskanaEngineConfiguration {
customHolidayEntry));
}
private HashSet<String> getTokensWithCollection(String str, String rolesSeparator) {
return Collections.list(new StringTokenizer(str, rolesSeparator)).stream()
.map(token -> String.valueOf(token).toLowerCase().trim())
.collect(Collectors.toCollection(HashSet::new));
private List<String> splitStringAndTrimElements(String str, String separator) {
return splitStringAndTrimElements(str, separator, UnaryOperator.identity());
}
private List<String> splitStringAndTrimElements(
String str, String separator, UnaryOperator<String> modifier) {
return Arrays.stream(str.split(Pattern.quote(separator)))
.filter(s -> !s.isEmpty())
.map(String::trim)
.map(modifier)
.collect(Collectors.toList());
}
private Properties readPropertiesFromFile(String propertiesFile) {
@ -638,9 +608,4 @@ public class TaskanaEngineConfiguration {
}
return loadFromClasspath;
}
private void ensureRoleMapIsFullyInitialized() {
// make sure that roleMap does not return null for any role
Arrays.stream(TaskanaRole.values()).forEach(role -> roleMap.putIfAbsent(role, new HashSet<>()));
}
}

View File

@ -54,7 +54,7 @@ public interface BaseQuery<T, U extends Enum<U> & QueryColumnName> {
*/
default List<T> listPage(int pageNumber, int pageSize) {
int offset = (pageNumber < 1) ? 0 : ((pageNumber - 1) * pageSize);
int limit = (pageSize < 0) ? 0 : pageSize;
int limit = Math.max(pageSize, 0);
return list(offset, limit);
}

View File

@ -57,124 +57,56 @@ public class TaskEvent extends TaskanaHistoryEvent {
}
}
public String getBusinessProcessId() {
return businessProcessId;
}
public void setBusinessProcessId(String businessProcessId) {
this.businessProcessId = businessProcessId;
}
public String getParentBusinessProcessId() {
return parentBusinessProcessId;
}
public void setParentBusinessProcessId(String parentBusinessProcessId) {
this.parentBusinessProcessId = parentBusinessProcessId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getWorkbasketKey() {
return workbasketKey;
}
public void setWorkbasketKey(String workbasketKey) {
this.workbasketKey = workbasketKey;
}
public String getPorCompany() {
return porCompany;
}
public void setPorCompany(String porCompany) {
this.porCompany = porCompany;
}
public String getPorSystem() {
return porSystem;
}
public void setPorSystem(String porSystem) {
this.porSystem = porSystem;
}
public String getPorInstance() {
return porInstance;
}
public void setPorInstance(String porInstance) {
this.porInstance = porInstance;
}
public String getPorType() {
return porType;
}
public void setPorType(String porType) {
this.porType = porType;
}
public String getPorValue() {
return porValue;
}
public void setPorValue(String porValue) {
this.porValue = porValue;
}
public String getTaskClassificationKey() {
return taskClassificationKey;
}
public void setTaskClassificationKey(String taskClassificationKey) {
this.taskClassificationKey = taskClassificationKey;
}
public String getTaskClassificationCategory() {
return taskClassificationCategory;
}
public void setTaskClassificationCategory(String taskClassificationCategory) {
this.taskClassificationCategory = taskClassificationCategory;
}
public String getAttachmentClassificationKey() {
return attachmentClassificationKey;
}
public void setAttachmentClassificationKey(String attachmentClassificationKey) {
this.attachmentClassificationKey = attachmentClassificationKey;
}
@Override
public String toString() {
return "TaskEvent [taskId= "
+ this.taskId
+ ", businessProcessId= "
+ this.businessProcessId
+ ", parentBusinessProcessId= "
+ this.parentBusinessProcessId
+ ", domain= "
+ this.domain
+ ", workbasketKey= "
+ this.workbasketKey
+ ", details= "
+ this.details
return "TaskEvent [id="
+ id
+ ", businessProcessId="
+ businessProcessId
+ ", parentBusinessProcessId="
+ parentBusinessProcessId
+ ", taskId="
+ taskId
+ ", eventType="
+ eventType
+ ", created="
+ created
+ ", userId="
+ userId
+ ", domain="
+ domain
+ ", workbasketKey="
+ workbasketKey
+ ", porCompany="
+ porCompany
+ ", porSystem="
+ porSystem
+ ", porInstance="
+ porInstance
+ ", porType="
+ porType
+ ", porValue="
+ porValue
+ ", taskClassificationKey="
+ taskClassificationKey
+ ", taskClassificationCategory="
+ taskClassificationCategory
+ ", attachmentClassificationKey="
+ attachmentClassificationKey
+ ", oldValue="
+ oldValue
+ ", newValue="
+ newValue
+ ", custom1="
+ custom1
+ ", custom2="
+ custom2
+ ", custom3="
+ custom3
+ ", custom4="
+ custom4
+ ", details="
+ details
+ "]";
}
}

View File

@ -1,16 +1,11 @@
package pro.taskana.spi.history.api.events.task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.task.api.models.Task;
import pro.taskana.workbasket.api.models.WorkbasketSummary;
/** Event fired if a task is transferred. */
public class TransferredEvent extends TaskEvent {
private static final Logger LOGGER = LoggerFactory.getLogger(TransferredEvent.class);
public TransferredEvent(
String id,
Task task,

View File

@ -28,14 +28,14 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
private static final String LINK_TO_VALUEMAPPER =
"pro.taskana.task.internal.TaskQueryMapper.queryObjectReferenceColumnValues";
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectReferenceQueryImpl.class);
private InternalTaskanaEngine taskanaEngine;
private final InternalTaskanaEngine taskanaEngine;
private final List<String> orderBy;
private ObjectReferenceQueryColumnName columnName;
private String[] company;
private String[] system;
private String[] systemInstance;
private String[] type;
private String[] value;
private List<String> orderBy;
ObjectReferenceQueryImpl(InternalTaskanaEngine taskanaEngine) {
this.taskanaEngine = taskanaEngine;
@ -98,15 +98,13 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
RowBounds rowBounds = new RowBounds(offset, limit);
result = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
} catch (Exception e) {
if (e instanceof PersistenceException) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex =
new TaskanaRuntimeException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
} catch (PersistenceException e) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex =
new TaskanaRuntimeException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
throw e;
} finally {

View File

@ -105,7 +105,7 @@ class ServiceLevelHandler {
boolean onlyPriority = false;
if (newTaskImpl.getClassificationSummary() == null
|| newTaskImpl.getClassificationSummary().getServiceLevel() == null) {
newTaskImpl = setPlannedDueOnMissingServiceLevel(newTaskImpl);
setPlannedDueOnMissingServiceLevel(newTaskImpl);
onlyPriority = true;
}
@ -154,7 +154,7 @@ class ServiceLevelHandler {
return getFinalPrioDurationOfTask(resolvedClassifications, onlyPriority);
}
private TaskImpl setPlannedDueOnMissingServiceLevel(TaskImpl task) {
private void setPlannedDueOnMissingServiceLevel(TaskImpl task) {
Instant now = Instant.now();
if (task.getDue() == null && task.getPlanned() == null) {
task.setDue(now);
@ -164,7 +164,6 @@ class ServiceLevelHandler {
} else {
task.setPlanned(task.getDue());
}
return task;
}
private void updateTaskPriorityOnClassificationUpdate(

View File

@ -1585,7 +1585,7 @@ public class TaskQueryImpl implements TaskQuery {
joinWithAttachments = true;
joinWithAttachmentClassifications = true;
}
if (joinWithAttachments || joinWithClassifications || joinWithAttachmentClassifications) {
if (joinWithAttachments || joinWithClassifications) {
useDistinctKeyword = true;
}
}
@ -1597,7 +1597,7 @@ public class TaskQueryImpl implements TaskQuery {
} else if (this.accessIdIn == null) {
String[] accessIds = new String[0];
List<String> ucAccessIds = CurrentUserContext.getAccessIds();
if (ucAccessIds != null && !ucAccessIds.isEmpty()) {
if (!ucAccessIds.isEmpty()) {
accessIds = new String[ucAccessIds.size()];
accessIds = ucAccessIds.toArray(accessIds);
}

View File

@ -63,6 +63,7 @@ public class AttachmentImpl extends AttachmentSummaryImpl implements Attachment
return new AttachmentImpl(this);
}
@Override
protected boolean canEqual(Object other) {
return (!(other instanceof AttachmentImpl));
}

View File

@ -270,6 +270,7 @@ public class TaskImpl extends TaskSummaryImpl implements Task {
((ClassificationSummaryImpl) this.classificationSummary).setCategory(classificationCategory);
}
@Override
protected boolean canEqual(Object other) {
return (other instanceof TaskImpl);
}

View File

@ -436,7 +436,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
throws InvalidArgumentException, NotAuthorizedException,
WorkbasketAccessItemAlreadyExistException {
LOGGER.debug(
"entry to setWorkbasketAccessItems(workbasketAccessItems = {})", wbAccessItems.toString());
"entry to setWorkbasketAccessItems(workbasketAccessItems = {})", wbAccessItems);
taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
Set<String> ids = new HashSet<>();

View File

@ -119,7 +119,7 @@ class TaskanaConfigAccTest extends TaskanaEngineImpl {
Path file = Files.createFile(Paths.get(System.getProperty("user.home") + filename));
List<String> lines =
Stream.of(
"taskana.roles.Admin =Holger|Stefan",
"taskana.roles.admin =Holger|Stefan",
"taskana.roles.businessadmin = ebe | konstantin ",
"taskana.roles.user = nobody")
.collect(Collectors.toList());

View File

@ -125,9 +125,10 @@ class TaskanaRoleConfigAccTest extends TaskanaEngineImpl {
Path file = Files.createFile(Paths.get(System.getProperty("user.home") + filename));
List<String> lines =
Arrays.asList(
"taskana.roles.Admin =uSeR " + delimiter + "name=Username,Organisation=novatec",
"taskana.roles.admin =uSeR " + delimiter + "name=Username,Organisation=novatec",
" taskana.roles.businessadmin = name=user2, ou = bpm " + delimiter + " user3 ",
" taskana.roles.user = ");
" taskana.roles.user = ",
"taskana.roles.taskadmin= taskadmin");
Files.write(file, lines, StandardCharsets.UTF_8);
return file.toString();
}
@ -143,9 +144,10 @@ class TaskanaRoleConfigAccTest extends TaskanaEngineImpl {
Path file = Files.createFile(Paths.get(System.getProperty("user.home") + filename));
List<String> lines =
Arrays.asList(
"taskana.roles.Admin =uSeR|Username",
"taskana.roles.admin =uSeR|Username",
" taskana.roles.businessadmin = user2 | user3 ",
" taskana.roles.user = nobody");
" taskana.roles.user = nobody",
"taskana.roles.taskadmin= taskadmin");
Files.write(file, lines, StandardCharsets.UTF_8);

View File

@ -10,7 +10,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.TaskanaEngineProxyForTest;
import pro.taskana.common.internal.TaskanaEngineProxy;
import pro.taskana.common.internal.security.JaasExtension;
import pro.taskana.common.internal.security.WithAccessId;
@ -36,7 +36,7 @@ class TaskEngineAccTest extends AbstractAccTest {
assertThat(taskanaEngine.isUserInRole(TaskanaRole.BUSINESS_ADMIN)).isTrue();
assertThat(taskanaEngine.isUserInRole(TaskanaRole.ADMIN)).isFalse();
new TaskanaEngineProxyForTest(taskanaEngine)
new TaskanaEngineProxy(taskanaEngine)
.getEngine()
.runAsAdmin(() -> assertThat(taskanaEngine.isUserInRole(TaskanaRole.ADMIN)).isTrue());

View File

@ -179,7 +179,7 @@ class CompleteTaskAccTest extends AbstractAccTest {
Task createdTask = TASK_SERVICE.createTask(newTask);
assertThat(createdTask).isNotNull();
assertThat("other_user").isEqualTo(createdTask.getOwner());
assertThat(createdTask.getOwner()).isEqualTo("other_user");
Instant beforeForceClaim = Instant.now();
Task taskAfterClaim = TASK_SERVICE.forceClaim(createdTask.getId());
@ -233,12 +233,12 @@ class CompleteTaskAccTest extends AbstractAccTest {
Task createdTask = TASK_SERVICE.createTask(newTask);
assertThat(createdTask).isNotNull();
assertThat(TaskState.READY).isEqualTo(createdTask.getState());
assertThat(createdTask.getState()).isSameAs(TaskState.READY);
createdTask = TASK_SERVICE.cancelClaim(createdTask.getId());
assertThat(createdTask).isNotNull();
assertThat(TaskState.READY).isEqualTo(createdTask.getState());
assertThat(createdTask.getState()).isSameAs(TaskState.READY);
}
@WithAccessId(user = "admin")

View File

@ -17,7 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.TaskanaEngineProxyForTest;
import pro.taskana.common.internal.TaskanaEngineProxy;
import pro.taskana.common.internal.security.CurrentUserContext;
import pro.taskana.common.internal.security.JaasExtension;
import pro.taskana.common.internal.security.WithAccessId;
@ -196,7 +196,7 @@ class CreateTaskAccTest extends AbstractAccTest {
assertThat(createdTask.isRead()).isFalse();
assertThat(createdTask.isTransferred()).isFalse();
// verify that the database content is as expected
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine);
TaskanaEngineProxy engineProxy = new TaskanaEngineProxy(taskanaEngine);
try {
SqlSession session = engineProxy.getSqlSession();
Configuration config = session.getConfiguration();
@ -258,7 +258,7 @@ class CreateTaskAccTest extends AbstractAccTest {
assertThat(createdTask.getCreator()).isEqualTo(CurrentUserContext.getUserid());
// verify that the database content is as expected
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine);
TaskanaEngineProxy engineProxy = new TaskanaEngineProxy(taskanaEngine);
try {
SqlSession session = engineProxy.getSqlSession();
AttachmentMapper mapper = session.getMapper(AttachmentMapper.class);

View File

@ -15,7 +15,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.BulkOperationResults;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.TaskanaEngineProxyForTest;
import pro.taskana.common.internal.TaskanaEngineProxy;
import pro.taskana.common.internal.security.JaasExtension;
import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.task.api.TaskService;
@ -50,7 +50,7 @@ class DeleteTaskAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine);
TaskanaEngineProxy engineProxy = new TaskanaEngineProxy(taskanaEngine);
AttachmentMapper attachmentMapper =
engineProxy.getEngine().getSqlSession().getMapper(AttachmentMapper.class);
@ -92,7 +92,7 @@ class DeleteTaskAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine);
TaskanaEngineProxy engineProxy = new TaskanaEngineProxy(taskanaEngine);
AttachmentMapper attachmentMapper =
engineProxy.getSqlSession().getMapper(AttachmentMapper.class);

View File

@ -35,7 +35,7 @@ import pro.taskana.classification.api.models.ClassificationSummary;
import pro.taskana.common.api.BaseQuery.SortDirection;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.internal.TaskanaEngineProxyForTest;
import pro.taskana.common.internal.TaskanaEngineProxy;
import pro.taskana.common.internal.security.JaasExtension;
import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.common.internal.util.Triplet;
@ -353,7 +353,7 @@ class QueryTasksAccTest extends AbstractAccTest {
assertThat(createdTask).isNotNull();
// query the task by custom attributes
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine);
TaskanaEngineProxy engineProxy = new TaskanaEngineProxy(taskanaEngine);
try {
SqlSession session = engineProxy.getSqlSession();
Configuration config = session.getConfiguration();

View File

@ -17,7 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.BulkOperationResults;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.TaskanaEngineProxyForTest;
import pro.taskana.common.internal.TaskanaEngineProxy;
import pro.taskana.common.internal.security.JaasExtension;
import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.task.api.TaskService;
@ -157,7 +157,7 @@ class SetOwnerAccTest extends AbstractAccTest {
void testSetOwnerWithAllTasksAndVariousExceptions() throws Exception {
resetDb(false);
List<TaskSummary> allTaskSummaries =
new TaskanaEngineProxyForTest(taskanaEngine)
new TaskanaEngineProxy(taskanaEngine)
.getEngine()
.runAsAdmin(() -> taskanaEngine.getTaskService().createTaskQuery().list());
List<String> allTaskIds =

View File

@ -36,19 +36,19 @@ class TaskRoutingAccTest extends AbstractAccTest {
.isInstanceOf(InvalidArgumentException.class);
((TaskImpl) taskToCreate).setDomain("DOMAIN_B");
Task createdTask = taskService.createTask(taskToCreate);
assertThat("WBI:100000000000000000000000000000000011")
.isEqualTo(createdTask.getWorkbasketSummary().getId());
assertThat(createdTask.getWorkbasketSummary().getId())
.isEqualTo("WBI:100000000000000000000000000000000011");
}
@WithAccessId(user = "admin")
@Test
void testCreateTaskWithNullWorkbasket() throws Exception {
TaskImpl createdTaskA = createTask("DOMAIN_A", "L12010");
assertThat("WBI:100000000000000000000000000000000001")
.isEqualTo(createdTaskA.getWorkbasketSummary().getId());
assertThat(createdTaskA.getWorkbasketSummary().getId())
.isEqualTo("WBI:100000000000000000000000000000000001");
TaskImpl createdTaskB = createTask("DOMAIN_B", "T21001");
assertThat("WBI:100000000000000000000000000000000011")
.isEqualTo(createdTaskB.getWorkbasketSummary().getId());
assertThat(createdTaskB.getWorkbasketSummary().getId())
.isEqualTo("WBI:100000000000000000000000000000000011");
assertThatThrownBy(() -> createTask(null, "L12010"))
.isInstanceOf(InvalidArgumentException.class);
}

View File

@ -10,7 +10,7 @@ import pro.taskana.common.api.CustomHoliday;
import pro.taskana.common.api.TaskanaEngine;
/** Test of configuration. */
class TaskanaEngineTestConfigurationTest {
class TaskanaEngineConfigurationTest {
@Test
void testCreateTaskanaEngine() throws Exception {

View File

@ -10,11 +10,11 @@ import pro.taskana.common.api.TaskanaEngine;
*
* @author bbr
*/
public class TaskanaEngineProxyForTest {
public class TaskanaEngineProxy {
private final InternalTaskanaEngine engine;
public TaskanaEngineProxyForTest(TaskanaEngine taskanaEngine) throws Exception {
public TaskanaEngineProxy(TaskanaEngine taskanaEngine) throws Exception {
Field internal = TaskanaEngineImpl.class.getDeclaredField("internalTaskanaEngineImpl");
internal.setAccessible(true);
engine = (InternalTaskanaEngine) internal.get(taskanaEngine);

View File

@ -36,11 +36,7 @@ public class TaskanaConfig {
@Bean
@Primary
public DataSource dataSource(DataSourceProperties properties) {
DataSource dataSource = properties.initializeDataSourceBuilder().build();
// if TaskanaEngineImpl runs with SpringManagedTransactionFactory, then
// there is no need to wrap the dataSource into TransactionAwareDataSourceProxy ...
// return new TransactionAwareDataSourceProxy(dataSource);
return dataSource;
return properties.initializeDataSourceBuilder().build();
}
@Bean
@ -53,16 +49,12 @@ public class TaskanaConfig {
@Bean
public SpringTaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource)
throws SQLException {
SpringTaskanaEngineConfiguration taskanaEngineConfiguration =
new SpringTaskanaEngineConfiguration(dataSource, true, false, schemaName);
return taskanaEngineConfiguration;
return new SpringTaskanaEngineConfiguration(dataSource, true, false, schemaName);
}
@Bean
public TaskanaEngine taskanaEngine(SpringTaskanaEngineConfiguration taskanaEngineConfiguration) {
TaskanaEngine taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
// taskanaEngine.setConnectionManagementMode(TaskanaEngine.ConnectionManagementMode.EXPLICIT);
return taskanaEngine;
return taskanaEngineConfiguration.buildTaskanaEngine();
}
@Bean
@ -85,7 +77,6 @@ public class TaskanaConfig {
return new ExampleBootstrap();
}
/** TODO. */
@Profile("inmemorydb")
@Configuration
@PropertySource("classpath:customdb.properties")

View File

@ -136,7 +136,7 @@ class ClassificationControllerIntTest {
ParameterizedTypeReference.forType(ClassificationRepresentationModel.class));
assertThat(responseEntity).isNotNull();
assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
newClassification =
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
@ -150,7 +150,7 @@ class ClassificationControllerIntTest {
new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()),
ParameterizedTypeReference.forType(ClassificationRepresentationModel.class));
assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
}
@Test
@ -192,7 +192,7 @@ class ClassificationControllerIntTest {
ParameterizedTypeReference.forType(ClassificationRepresentationModel.class));
assertThat(responseEntity).isNotNull();
assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
}
@Test
@ -212,7 +212,7 @@ class ClassificationControllerIntTest {
ParameterizedTypeReference.forType(ClassificationRepresentationModel.class));
assertThat(responseEntity).isNotNull();
assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
}
@Test
@ -231,7 +231,7 @@ class ClassificationControllerIntTest {
ParameterizedTypeReference.forType(ClassificationRepresentationModel.class));
assertThat(responseEntity).isNotNull();
assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
ResponseEntity<TaskanaPagedModel<ClassificationSummaryRepresentationModel>> response =
template.exchange(
@ -328,7 +328,6 @@ class ClassificationControllerIntTest {
HttpMethod.DELETE,
request,
ParameterizedTypeReference.forType(ClassificationSummaryRepresentationModel.class));
assertThat(HttpStatus.NO_CONTENT).isEqualTo(response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
ThrowingCallable httpCall =

View File

@ -456,8 +456,8 @@ class TaskControllerIntTest {
assertThat((response.getBody()).getContent()).hasSize(1);
assertThat(response.getBody().getRequiredLink(IanaLinkRelations.LAST).getHref())
.contains("page=14");
assertThat("TKI:100000000000000000000000000000000000")
.isEqualTo(response.getBody().getContent().iterator().next().getTaskId());
assertThat(response.getBody().getContent().iterator().next().getTaskId())
.isEqualTo("TKI:100000000000000000000000000000000000");
assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref())
@ -497,8 +497,8 @@ class TaskControllerIntTest {
assertThat((response.getBody()).getContent()).hasSize(5);
assertThat(response.getBody().getRequiredLink(IanaLinkRelations.LAST).getHref())
.contains("page=10");
assertThat("TKI:000000000000000000000000000000000005")
.isEqualTo(response.getBody().getContent().iterator().next().getTaskId());
assertThat(response.getBody().getContent().iterator().next().getTaskId())
.isEqualTo("TKI:000000000000000000000000000000000005");
assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref())
@ -591,7 +591,7 @@ class TaskControllerIntTest {
HttpMethod.POST,
new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()),
TASK_MODEL_TYPE);
assertThat(HttpStatus.CREATED).isEqualTo(responseCreate.getStatusCode());
assertThat(responseCreate.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(responseCreate.getBody()).isNotNull();
String taskIdOfCreatedTask = responseCreate.getBody().getTaskId();