Merge pull request #46 from BerndBreier/TSK-53_logging_support

Tsk 53 logging support
This commit is contained in:
Holger Hagen 2017-12-04 12:04:38 +01:00 committed by GitHub
commit 12a607a76a
14 changed files with 665 additions and 112 deletions

View File

@ -1,11 +1,15 @@
package pro.taskana.impl; package pro.taskana.impl;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery; import pro.taskana.ClassificationQuery;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Classification; import pro.taskana.model.Classification;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -16,6 +20,7 @@ import java.util.List;
public class ClassificationQueryImpl implements ClassificationQuery { public class ClassificationQueryImpl implements ClassificationQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification"; private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification";
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl; private TaskanaEngineImpl taskanaEngineImpl;
private String[] parentClassificationId; private String[] parentClassificationId;
private String[] category; private String[] category;
@ -115,32 +120,50 @@ public class ClassificationQueryImpl implements ClassificationQuery {
@Override @Override
public List<Classification> list() { public List<Classification> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<Classification> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this); result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public List<Classification> list(int offset, int limit) { public List<Classification> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<Classification> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit); RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds); result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public Classification single() { public Classification single() {
LOGGER.debug("entry to single(), this = {}", this);
Classification result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this); result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
} }
} }
@ -247,4 +270,40 @@ public class ClassificationQueryImpl implements ClassificationQuery {
public void setValidUntil(Date[] validUntil) { public void setValidUntil(Date[] validUntil) {
this.validUntil = validUntil; this.validUntil = validUntil;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ClassificationQueryImpl [taskanaEngineImpl=");
builder.append(taskanaEngineImpl);
builder.append(", parentClassificationId=");
builder.append(Arrays.toString(parentClassificationId));
builder.append(", category=");
builder.append(Arrays.toString(category));
builder.append(", type=");
builder.append(Arrays.toString(type));
builder.append(", domain=");
builder.append(Arrays.toString(domain));
builder.append(", validInDomain=");
builder.append(validInDomain);
builder.append(", created=");
builder.append(Arrays.toString(created));
builder.append(", name=");
builder.append(Arrays.toString(name));
builder.append(", description=");
builder.append(description);
builder.append(", priority=");
builder.append(Arrays.toString(priority));
builder.append(", serviceLevel=");
builder.append(Arrays.toString(serviceLevel));
builder.append(", customFields=");
builder.append(Arrays.toString(customFields));
builder.append(", validFrom=");
builder.append(Arrays.toString(validFrom));
builder.append(", validUntil=");
builder.append(Arrays.toString(validUntil));
builder.append("]");
return builder.toString();
}
} }

View File

@ -6,6 +6,7 @@ import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.util.IdGenerator; import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Classification; import pro.taskana.model.Classification;
import pro.taskana.model.mappings.ClassificationMapper; import pro.taskana.model.mappings.ClassificationMapper;
@ -15,6 +16,9 @@ import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* This is the implementation of ClassificationService. * This is the implementation of ClassificationService.
*/ */
@ -22,6 +26,7 @@ public class ClassificationServiceImpl implements ClassificationService {
private static final String ID_PREFIX_CLASSIFICATION = "CLI"; private static final String ID_PREFIX_CLASSIFICATION = "CLI";
public static final Date CURRENT_CLASSIFICATIONS_VALID_UNTIL = Date.valueOf("9999-12-31"); public static final Date CURRENT_CLASSIFICATIONS_VALID_UNTIL = Date.valueOf("9999-12-31");
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
private ClassificationMapper classificationMapper; private ClassificationMapper classificationMapper;
private TaskanaEngine taskanaEngine; private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl; private TaskanaEngineImpl taskanaEngineImpl;
@ -35,13 +40,20 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override @Override
public List<Classification> getClassificationTree() throws NotAuthorizedException { public List<Classification> getClassificationTree() throws NotAuthorizedException {
LOGGER.debug("entry to getClassificationTree()");
List<Classification> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
List<Classification> rootClassifications; List<Classification> rootClassifications;
rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list(); rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
return this.populateChildClassifications(rootClassifications); result = this.populateChildClassifications(rootClassifications);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getClassificationTree(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@ -62,6 +74,7 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override @Override
public void addClassification(Classification classification) { public void addClassification(Classification classification) {
LOGGER.debug("entry to addClassification(classification = {})", classification);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION)); classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
@ -70,13 +83,16 @@ public class ClassificationServiceImpl implements ClassificationService {
this.setDefaultValues(classification); this.setDefaultValues(classification);
classificationMapper.insert(classification); classificationMapper.insert(classification);
LOGGER.debug("Method addClassification added classification {}.", classification);
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from addClassification()");
} }
} }
@Override @Override
public void updateClassification(Classification classification) { public void updateClassification(Classification classification) {
LOGGER.debug("entry to updateClassification(Classification = {})", classification);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
this.setDefaultValues(classification); this.setDefaultValues(classification);
@ -84,24 +100,29 @@ public class ClassificationServiceImpl implements ClassificationService {
Classification oldClassification = null; Classification oldClassification = null;
try { try {
oldClassification = this.getClassification(classification.getId(), classification.getDomain()); oldClassification = this.getClassification(classification.getId(), classification.getDomain());
LOGGER.debug("Method updateClassification() inserted classification {}.", classification);
// ! If you update an classification twice the same day, // ! If you update an classification twice the same day,
// the older version is valid from today until yesterday. // the older version is valid from today until yesterday.
if (!oldClassification.getDomain().equals(classification.getDomain())) { if (!oldClassification.getDomain().equals(classification.getDomain())) {
classification.setCreated(Date.valueOf(LocalDate.now())); classification.setCreated(Date.valueOf(LocalDate.now()));
classificationMapper.insert(classification); classificationMapper.insert(classification);
LOGGER.debug("Method updateClassification() inserted classification {}.", classification);
} else { } else {
oldClassification.setValidUntil(Date.valueOf(LocalDate.now().minusDays(1))); oldClassification.setValidUntil(Date.valueOf(LocalDate.now().minusDays(1)));
classificationMapper.update(oldClassification); classificationMapper.update(oldClassification);
classificationMapper.insert(classification); classificationMapper.insert(classification);
LOGGER.debug("Method updateClassification() updated old classification {} and inserted new {}.", oldClassification, classification);
} }
} catch (ClassificationNotFoundException e) { } catch (ClassificationNotFoundException e) {
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION)); classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
classification.setCreated(Date.valueOf(LocalDate.now())); classification.setCreated(Date.valueOf(LocalDate.now()));
classificationMapper.insert(classification); classificationMapper.insert(classification);
LOGGER.debug("Method updateClassification() inserted classification {}.", classification);
} }
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateClassification().");
} }
} }
@ -132,32 +153,40 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override @Override
public List<Classification> getAllClassificationsWithId(String id, String domain) { public List<Classification> getAllClassificationsWithId(String id, String domain) {
LOGGER.debug("entry to getAllClassificationsWithId(id = {}, domain = {})", id, domain);
List<Classification> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return classificationMapper.getAllClassificationsWithId(id, domain); result = classificationMapper.getAllClassificationsWithId(id, domain);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getAllClassificationsWithId(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public Classification getClassification(String id, String domain) throws ClassificationNotFoundException { public Classification getClassification(String id, String domain) throws ClassificationNotFoundException {
LOGGER.debug("entry to getClassification(id = {}, domain = {})", id, domain);
Classification result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL); result = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
if (classification == null) { if (result == null) {
classification = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL); result = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
} }
if (classification == null) { if (result == null) {
throw new ClassificationNotFoundException(id); throw new ClassificationNotFoundException(id);
} }
return classification; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getClassification(). Returning result {} ", result);
} }
} }
@Override @Override

View File

@ -1,11 +1,15 @@
package pro.taskana.impl; package pro.taskana.impl;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ObjectReferenceQuery; import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.ObjectReference; import pro.taskana.model.ObjectReference;
/** /**
@ -15,6 +19,7 @@ import pro.taskana.model.ObjectReference;
public class ObjectReferenceQueryImpl implements ObjectReferenceQuery { public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference"; private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference";
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectReferenceQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl; private TaskanaEngineImpl taskanaEngineImpl;
private String[] company; private String[] company;
@ -59,32 +64,50 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
@Override @Override
public List<ObjectReference> list() { public List<ObjectReference> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<ObjectReference> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this); result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public List<ObjectReference> list(int offset, int limit) { public List<ObjectReference> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<ObjectReference> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit); RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds); result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public ObjectReference single() { public ObjectReference single() {
LOGGER.debug("entry to single(), this = {}", this);
ObjectReference result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this); result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
} }
} }
@ -127,4 +150,23 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
public void setValue(String[] value) { public void setValue(String[] value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ObjectReferenceQueryImpl [taskanaEngineImpl=");
builder.append(taskanaEngineImpl);
builder.append(", company=");
builder.append(Arrays.toString(company));
builder.append(", system=");
builder.append(Arrays.toString(system));
builder.append(", systemInstance=");
builder.append(Arrays.toString(systemInstance));
builder.append(", type=");
builder.append(Arrays.toString(type));
builder.append(", value=");
builder.append(Arrays.toString(value));
builder.append("]");
return builder.toString();
}
} }

View File

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import pro.taskana.SummaryService; import pro.taskana.SummaryService;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.TaskSummary; import pro.taskana.model.TaskSummary;
import pro.taskana.model.mappings.SummaryMapper; import pro.taskana.model.mappings.SummaryMapper;
@ -28,17 +29,23 @@ public class SummaryServiceImpl implements SummaryService {
@Override @Override
public List<TaskSummary> getTaskSummariesByWorkbasketId(String workbasketId) { public List<TaskSummary> getTaskSummariesByWorkbasketId(String workbasketId) {
LOGGER.debug("entry to getTaskSummariesByWorkbasketId(workbasketId = {}", workbasketId);
List<TaskSummary> taskSummaries = new ArrayList<>(); List<TaskSummary> taskSummaries = new ArrayList<>();
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
taskSummaries = summaryMapper.findTasksummariesByWorkbasketId(workbasketId); taskSummaries = summaryMapper.findTasksummariesByWorkbasketId(workbasketId);
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.error("Getting TASKSUMMARY failed internal.", ex); LOGGER.error("Getting TASKSUMMARY failed internally.", ex);
} finally { } finally {
if (taskSummaries == null) { if (taskSummaries == null) {
taskSummaries = new ArrayList<>(); taskSummaries = new ArrayList<>();
} }
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = taskSummaries.size();
LOGGER.debug("exit from getTaskSummariesByWorkbasketId(workbasketId). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(taskSummaries));
}
} }
return taskSummaries; return taskSummaries;
} }

View File

@ -1,14 +1,18 @@
package pro.taskana.impl; package pro.taskana.impl;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery; import pro.taskana.ClassificationQuery;
import pro.taskana.ObjectReferenceQuery; import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskQuery; import pro.taskana.TaskQuery;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Task; import pro.taskana.model.Task;
import pro.taskana.model.TaskState; import pro.taskana.model.TaskState;
import pro.taskana.model.WorkbasketAuthorization; import pro.taskana.model.WorkbasketAuthorization;
@ -19,6 +23,7 @@ import pro.taskana.model.WorkbasketAuthorization;
public class TaskQueryImpl implements TaskQuery { public class TaskQueryImpl implements TaskQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks"; private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
private static final Logger LOGGER = LoggerFactory.getLogger(TaskQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl; private TaskanaEngineImpl taskanaEngineImpl;
@ -111,35 +116,53 @@ public class TaskQueryImpl implements TaskQuery {
@Override @Override
public List<Task> list() throws NotAuthorizedException { public List<Task> list() throws NotAuthorizedException {
LOGGER.debug("entry to list(), this = {}", this);
List<Task> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
checkAuthorization(); checkAuthorization();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this); result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public List<Task> list(int offset, int limit) throws NotAuthorizedException { public List<Task> list(int offset, int limit) throws NotAuthorizedException {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<Task> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
checkAuthorization(); checkAuthorization();
RowBounds rowBounds = new RowBounds(offset, limit); RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds); result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public Task single() throws NotAuthorizedException { public Task single() throws NotAuthorizedException {
LOGGER.debug("entry to single(), this = {}", this);
Task result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
checkAuthorization(); checkAuthorization();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this); result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
} }
} }
@ -246,4 +269,35 @@ public class TaskQueryImpl implements TaskQuery {
public void setCustomFields(String[] customFields) { public void setCustomFields(String[] customFields) {
this.customFields = customFields; this.customFields = customFields;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TaskQueryImpl [taskanaEngineImpl=");
builder.append(taskanaEngineImpl);
builder.append(", name=");
builder.append(Arrays.toString(name));
builder.append(", description=");
builder.append(description);
builder.append(", priority=");
builder.append(Arrays.toString(priority));
builder.append(", states=");
builder.append(Arrays.toString(states));
builder.append(", classificationQuery=");
builder.append(classificationQuery);
builder.append(", workbasketId=");
builder.append(Arrays.toString(workbasketId));
builder.append(", owner=");
builder.append(Arrays.toString(owner));
builder.append(", objectReferenceQuery=");
builder.append(objectReferenceQuery);
builder.append(", isRead=");
builder.append(isRead);
builder.append(", isTransferred=");
builder.append(isTransferred);
builder.append(", customFields=");
builder.append(Arrays.toString(customFields));
builder.append("]");
return builder.toString();
}
} }

View File

@ -1,8 +1,17 @@
package pro.taskana.impl; package pro.taskana.impl;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pro.taskana.TaskQuery; import pro.taskana.TaskQuery;
import pro.taskana.TaskService; import pro.taskana.TaskService;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
@ -11,18 +20,17 @@ import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator; import pro.taskana.impl.util.IdGenerator;
import pro.taskana.model.*; import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Classification;
import pro.taskana.model.DueWorkbasketCounter;
import pro.taskana.model.ObjectReference;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
import pro.taskana.model.TaskStateCounter;
import pro.taskana.model.WorkbasketAuthorization;
import pro.taskana.model.mappings.ObjectReferenceMapper; import pro.taskana.model.mappings.ObjectReferenceMapper;
import pro.taskana.model.mappings.TaskMapper; import pro.taskana.model.mappings.TaskMapper;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/** /**
* This is the implementation of TaskService. * This is the implementation of TaskService.
*/ */
@ -51,6 +59,7 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task claim(String id, String userName) throws TaskNotFoundException { public Task claim(String id, String userName) throws TaskNotFoundException {
LOGGER.debug("entry to claim(id = {}, userName = {})", id, userName);
Task task = null; Task task = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
@ -62,18 +71,21 @@ public class TaskServiceImpl implements TaskService {
task.setClaimed(now); task.setClaimed(now);
task.setState(TaskState.CLAIMED); task.setState(TaskState.CLAIMED);
taskMapper.update(task); taskMapper.update(task);
LOGGER.debug("User '{}' claimed task '{}'.", userName, id); LOGGER.debug("Method claim() claimed task '{}' for user '{}'.", id, userName);
} else { } else {
LOGGER.warn("Method claim() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id); throw new TaskNotFoundException(id);
} }
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from claim()");
} }
return task; return task;
} }
@Override @Override
public Task complete(String id) throws TaskNotFoundException { public Task complete(String id) throws TaskNotFoundException {
LOGGER.debug("entry to complete(id = {})", id);
Task task = null; Task task = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
@ -84,18 +96,21 @@ public class TaskServiceImpl implements TaskService {
task.setModified(now); task.setModified(now);
task.setState(TaskState.COMPLETED); task.setState(TaskState.COMPLETED);
taskMapper.update(task); taskMapper.update(task);
LOGGER.debug("Task '{}' completed.", id); LOGGER.debug("Method complete() completed Task '{}'.", id);
} else { } else {
LOGGER.warn("Method complete() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id); throw new TaskNotFoundException(id);
} }
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from complete()");
} }
return task; return task;
} }
@Override @Override
public Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException { public Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException {
LOGGER.debug("entry to create(task = {})", task);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND); taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
@ -104,15 +119,22 @@ public class TaskServiceImpl implements TaskService {
this.taskMapper.insert(task); this.taskMapper.insert(task);
LOGGER.debug("Task '{}' created.", task.getId()); LOGGER.debug("Method create() created Task '{}'.", task.getId());
return task; return task;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from create(task = {})");
} }
} }
@Override @Override
public Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name, String description, ObjectReference primaryObjectReference, Map<String, Object> customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { public Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name,
String description, ObjectReference primaryObjectReference, Map<String, Object> customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to createManualTask(workbasketId = {}, classificationId = {}, domain = {}, planned = {}, name = {},"
+ " description = {}, primaryObjectReference = {}, customAttributes = {})", workbasketId, classificationId, domain, planned, name,
description, primaryObjectReference, LoggerUtils.mapToString(customAttributes));
}
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.APPEND); taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.APPEND);
@ -139,54 +161,77 @@ public class TaskServiceImpl implements TaskService {
this.taskMapper.insert(task); this.taskMapper.insert(task);
LOGGER.debug("Task '{}' created.", task.getId()); LOGGER.debug("Method create() created Task '{}'.", task.getId());
return task; return task;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from create()");
} }
} }
@Override @Override
public Task getTaskById(String id) throws TaskNotFoundException { public Task getTaskById(String id) throws TaskNotFoundException {
LOGGER.debug("entry to getTaskById(id = {})", id);
Task result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Task task = taskMapper.findById(id); result = taskMapper.findById(id);
if (task != null) { if (result != null) {
return task; return result;
} else { } else {
LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id); throw new TaskNotFoundException(id);
} }
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getTaskById(). Returning result {} ", result);
} }
} }
@Override @Override
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) { public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to getTaskCountForState(states = {})", LoggerUtils.listToString(states));
}
List<TaskStateCounter> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return taskMapper.getTaskCountForState(states); result = taskMapper.getTaskCountForState(states);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTaskCountForState(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) { public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
workbasketId, daysInPast, LoggerUtils.listToString(states));
}
long result = -1;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
LocalDate time = LocalDate.now(); LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast); time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time); Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states); result = taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getTaskCountForWorkbasketByDaysInPastAndState(). Returning result {} ", result);
} }
} }
@Override @Override
public Task transfer(String taskId, String destinationWorkbasketId) public Task transfer(String taskId, String destinationWorkbasketId)
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException { throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketId = {})", taskId, destinationWorkbasketId);
Task result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Task task = getTaskById(taskId); Task task = getTaskById(taskId);
@ -210,37 +255,55 @@ public class TaskServiceImpl implements TaskService {
task.setModified(Timestamp.valueOf(LocalDateTime.now())); task.setModified(Timestamp.valueOf(LocalDateTime.now()));
taskMapper.update(task); taskMapper.update(task);
return getTaskById(taskId); result = getTaskById(taskId);
LOGGER.debug("Method transfer() transferred Task '{}' to destination workbasket {}", taskId, destinationWorkbasketId);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from transfer(). Returning result {} ", result);
} }
} }
@Override @Override
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast, public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
List<TaskState> states) { List<TaskState> states) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast = {}, states = {})", daysInPast, LoggerUtils.listToString(states));
}
List<DueWorkbasketCounter> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
LocalDate time = LocalDate.now(); LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast); time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time); Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states); result = taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException { public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
LOGGER.debug("entry to setTaskRead(taskId = {}, isRead = {})", taskId, isRead);
Task result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Task task = getTaskById(taskId); Task task = getTaskById(taskId);
task.setRead(true); task.setRead(true);
task.setModified(Timestamp.valueOf(LocalDateTime.now())); task.setModified(Timestamp.valueOf(LocalDateTime.now()));
taskMapper.update(task); taskMapper.update(task);
return getTaskById(taskId); result = getTaskById(taskId);
LOGGER.debug("Method setTaskRead() set read property of Task '{}' to {} ", result, isRead);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from setTaskRead(taskId, isRead). Returning result {} ", result);
} }
} }
@ -251,15 +314,21 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception { public List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception {
List<Task> resultList = null; LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId, taskState);
List<Task> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.READ); taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.READ);
resultList = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState); result = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState);
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTasksByWorkbasketIdAndState(workbasketId, taskState). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
} }
return (resultList == null) ? new ArrayList<>() : resultList; }
return (result == null) ? new ArrayList<>() : result;
} }
private void standardSettings(Task task) { private void standardSettings(Task task) {

View File

@ -7,6 +7,7 @@ import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator; import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Workbasket; import pro.taskana.model.Workbasket;
import pro.taskana.model.WorkbasketAccessItem; import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketAuthorization; import pro.taskana.model.WorkbasketAuthorization;
@ -52,21 +53,28 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override @Override
public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException { public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException {
LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId);
Workbasket result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Workbasket workbasket = workbasketMapper.findById(workbasketId); result = workbasketMapper.findById(workbasketId);
if (workbasket == null) { if (result == null) {
LOGGER.warn("Method getWorkbasket() didn't find workbasket with id {}. Throwing WorkbasketNotFoundException", workbasketId);
throw new WorkbasketNotFoundException(workbasketId); throw new WorkbasketNotFoundException(workbasketId);
} }
return result;
return workbasket;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
} }
} }
@Override @Override
public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) { public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to getWorkbaskets(permissions = {})", LoggerUtils.listToString(permissions));
}
List<Workbasket> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
//use a set to avoid duplicates //use a set to avoid duplicates
@ -74,26 +82,39 @@ public class WorkbasketServiceImpl implements WorkbasketService {
for (String accessId : CurrentUserContext.getAccessIds()) { for (String accessId : CurrentUserContext.getAccessIds()) {
workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId)); workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId));
} }
List<Workbasket> workbasketList = new ArrayList<Workbasket>(); result = new ArrayList<Workbasket>();
workbasketList.addAll(workbaskets); result.addAll(workbaskets);
return workbasketList; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbaskets(permissions). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public List<Workbasket> getWorkbaskets() { public List<Workbasket> getWorkbaskets() {
LOGGER.debug("entry to getWorkbaskets()");
List<Workbasket> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return workbasketMapper.findAll(); result = workbasketMapper.findAll();
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public Workbasket createWorkbasket(Workbasket workbasket) { public Workbasket createWorkbasket(Workbasket workbasket) {
LOGGER.debug("entry to createtWorkbasket(workbasket)", workbasket);
Workbasket result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Timestamp now = new Timestamp(System.currentTimeMillis()); Timestamp now = new Timestamp(System.currentTimeMillis());
@ -103,106 +124,138 @@ public class WorkbasketServiceImpl implements WorkbasketService {
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET)); workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
} }
workbasketMapper.insert(workbasket); workbasketMapper.insert(workbasket);
LOGGER.debug("Workbasket '{}' created", workbasket.getId()); LOGGER.debug("Method createWorkbasket() created Workbasket '{}'", workbasket);
if (workbasket.getDistributionTargets() != null) { if (workbasket.getDistributionTargets() != null) {
for (Workbasket distributionTarget : workbasket.getDistributionTargets()) { for (Workbasket distributionTarget : workbasket.getDistributionTargets()) {
if (workbasketMapper.findById(distributionTarget.getId()) == null) { if (workbasketMapper.findById(distributionTarget.getId()) == null) {
distributionTarget.setCreated(now); distributionTarget.setCreated(now);
distributionTarget.setModified(now); distributionTarget.setModified(now);
workbasketMapper.insert(distributionTarget); workbasketMapper.insert(distributionTarget);
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId()); LOGGER.debug("Method createWorkbasket() created distributionTarget '{}'", distributionTarget);
} }
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId()); distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
LOGGER.debug("Method createWorkbasket() created distributiontarget for source '{}' and target {}", workbasket.getId(), distributionTarget.getId());
} }
} }
return workbasketMapper.findById(workbasket.getId()); result = workbasketMapper.findById(workbasket.getId());
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result);
} }
} }
@Override @Override
public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException { public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException {
LOGGER.debug("entry to updateWorkbasket(workbasket)", workbasket);
Workbasket result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
workbasket.setModified(new Timestamp(System.currentTimeMillis())); workbasket.setModified(new Timestamp(System.currentTimeMillis()));
workbasketMapper.update(workbasket); workbasketMapper.update(workbasket);
LOGGER.debug("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId());
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId()); List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
List<Workbasket> distributionTargets = workbasket.getDistributionTargets(); List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
for (Workbasket distributionTarget : distributionTargets) { for (Workbasket distributionTarget : distributionTargets) {
if (!oldDistributionTargets.contains(distributionTarget.getId())) { if (!oldDistributionTargets.contains(distributionTarget.getId())) {
if (workbasketMapper.findById(distributionTarget.getId()) == null) { if (workbasketMapper.findById(distributionTarget.getId()) == null) {
workbasketMapper.insert(distributionTarget); workbasketMapper.insert(distributionTarget);
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId()); LOGGER.debug(" Method updateWorkbasket() created distributionTarget '{}'", distributionTarget);
} }
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId()); distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
LOGGER.debug("Method updateWorkbasket() created distributionTarget for '{}' and '{}'", workbasket.getId(), distributionTarget.getId());
} else { } else {
oldDistributionTargets.remove(distributionTarget.getId()); oldDistributionTargets.remove(distributionTarget.getId());
} }
} }
distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets); distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets);
LOGGER.debug("Workbasket '{}' updated", workbasket.getId()); if (LOGGER.isInfoEnabled()) {
return workbasketMapper.findById(workbasket.getId()); LOGGER.debug("Method updateWorkbasket() deleted distributionTargets for '{}' and old distribution targets {}",
workbasket.getId(), LoggerUtils.listToString(oldDistributionTargets));
}
result = workbasketMapper.findById(workbasket.getId());
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result);
} }
} }
@Override @Override
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) { public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
LOGGER.debug("entry to createWorkbasketAuthorization(workbasketAccessItem = {})", workbasketAccessItem);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION)); workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
workbasketAccessMapper.insert(workbasketAccessItem); workbasketAccessMapper.insert(workbasketAccessItem);
LOGGER.debug("Method createWorkbasketAuthorization() created workbaskteAccessItem {}", workbasketAccessItem);
return workbasketAccessItem; return workbasketAccessItem;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from createWorkbasketAuthorization(workbasketAccessItem). Returning result {}", workbasketAccessItem);
} }
} }
@Override @Override
public WorkbasketAccessItem getWorkbasketAuthorization(String id) { public WorkbasketAccessItem getWorkbasketAuthorization(String id) {
LOGGER.debug("entry to getWorkbasketAuthorization(id = {})", id);
WorkbasketAccessItem result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findById(id); result = workbasketAccessMapper.findById(id);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getWorkbasketAuthorization(id). Returning result {}", result);
} }
} }
@Override @Override
public void deleteWorkbasketAuthorization(String id) { public void deleteWorkbasketAuthorization(String id) {
LOGGER.debug("entry to deleteWorkbasketAuthorization(id = {})", id);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
workbasketAccessMapper.delete(id); workbasketAccessMapper.delete(id);
LOGGER.debug("Method deleteWorkbasketAuthorization() deleted workbasketAccessItem wit Id {}", id);
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from deleteWorkbasketAuthorization(id).");
} }
} }
@Override @Override
public List<WorkbasketAccessItem> getAllAuthorizations() { public List<WorkbasketAccessItem> getAllAuthorizations() {
LOGGER.debug("entry to getAllAuthorizations()");
List<WorkbasketAccessItem> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findAll(); result = workbasketAccessMapper.findAll();
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getAllAuthorizations(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
@Override @Override
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization) public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
throws NotAuthorizedException { throws NotAuthorizedException {
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketAuthorization = {})", workbasketId, workbasketAuthorization);
boolean isAuthorized = false;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
// Skip permission check is security is not enabled // Skip permission check is security is not enabled
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) { if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
LOGGER.debug("Skipping permissions check since security is disabled."); LOGGER.debug("Skipping permissions check since security is disabled.");
isAuthorized = true;
return; return;
} }
List<String> accessIds = CurrentUserContext.getAccessIds(); List<String> accessIds = CurrentUserContext.getAccessIds();
LOGGER.debug("Verifying that {} has the permission {} on workbasket {}", LOGGER.debug("checkAuthorization: Verifying that {} has the permission {} on workbasket {}",
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketId); CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketId);
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
@ -213,29 +266,42 @@ public class WorkbasketServiceImpl implements WorkbasketService {
+ "' on workbasket '" + workbasketId + "' is needed."); + "' on workbasket '" + workbasketId + "' is needed.");
} }
isAuthorized = true;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from checkAuthorization(). User is authorized = {}.", isAuthorized);
} }
} }
@Override @Override
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) { public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
LOGGER.debug("entry to updateWorkbasketAuthorization(workbasketAccessItem = {}", workbasketAccessItem);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
workbasketAccessMapper.update(workbasketAccessItem); workbasketAccessMapper.update(workbasketAccessItem);
LOGGER.debug("Method updateWorkbasketAuthorization() updated workbasketAccessItem {}", workbasketAccessItem);
return workbasketAccessItem; return workbasketAccessItem;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateWorkbasketAuthorization(workbasketAccessItem). Returning {}", workbasketAccessItem);
} }
} }
@Override @Override
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) { public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) {
LOGGER.debug("entry to getWorkbasketAuthorizations(workbasketId = {})", workbasketId);
List<WorkbasketAccessItem> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findByWorkbasketId(workbasketId); result = workbasketAccessMapper.findByWorkbasketId(workbasketId);
return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbasketAuthorizations(workbasketId). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
} }
} }
} }

View File

@ -0,0 +1,64 @@
package pro.taskana.impl.util;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* Util methods for logging.
* @author bbr
*
*/
public final class LoggerUtils {
private LoggerUtils() {
}
/**
* make a String for logging from a list of objects.
* @param list
* @return A String representation of the list.
*/
public static <T> String listToString(List<T> list) {
if (list == null || list.isEmpty()) {
return "[]";
} else {
StringBuilder builder = new StringBuilder();
builder.append("[");
for (T t : list) {
builder.append(t.toString());
builder.append(";");
}
builder.append("]");
return builder.toString();
}
}
/**
* make a String for logging from a map.
*
* @param map the map to be stringified
* @return A String representation of the map.
*/
public static <K, V> String mapToString(Map<K, V> map) {
if (map == null || map.isEmpty()) {
return "[]";
} else {
StringBuilder builder = new StringBuilder();
builder.append("[");
Set<Entry<K, V>> entrySet = map.entrySet();
for (Entry<K, V> entry : entrySet) {
builder.append("(");
builder.append(entry.getKey());
builder.append(" , ");
builder.append(entry.getValue());
builder.append(")");
builder.append(" , ");
}
builder.append("]");
return builder.toString();
}
}
}

View File

@ -197,4 +197,54 @@ public class Classification {
this.validUntil = validUntil; this.validUntil = validUntil;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Classification [id=");
builder.append(id);
builder.append(", parentClassificationId=");
builder.append(parentClassificationId);
builder.append(", category=");
builder.append(category);
builder.append(", type=");
builder.append(type);
builder.append(", domain=");
builder.append(domain);
builder.append(", isValidInDomain=");
builder.append(isValidInDomain);
builder.append(", created=");
builder.append(created);
builder.append(", name=");
builder.append(name);
builder.append(", description=");
builder.append(description);
builder.append(", priority=");
builder.append(priority);
builder.append(", serviceLevel=");
builder.append(serviceLevel);
builder.append(", custom1=");
builder.append(custom1);
builder.append(", custom2=");
builder.append(custom2);
builder.append(", custom3=");
builder.append(custom3);
builder.append(", custom4=");
builder.append(custom4);
builder.append(", custom5=");
builder.append(custom5);
builder.append(", custom6=");
builder.append(custom6);
builder.append(", custom7=");
builder.append(custom7);
builder.append(", custom8=");
builder.append(custom8);
builder.append(", validFrom=");
builder.append(validFrom);
builder.append(", validUntil=");
builder.append(validUntil);
builder.append("]");
return builder.toString();
}
} }

View File

@ -62,14 +62,21 @@ public class ObjectReference {
@Override @Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder builder = new StringBuilder();
sb.append("ObjectReference("); builder.append("ObjectReference [id=");
sb.append("id=" + id); builder.append(id);
sb.append(", company=" + company); builder.append(", company=");
sb.append(", system=" + system); builder.append(company);
sb.append(", systemInstance=" + systemInstance); builder.append(", system=");
sb.append(", type=" + type); builder.append(system);
sb.append(", value=" + value); builder.append(", systemInstance=");
return sb.toString(); builder.append(systemInstance);
builder.append(", type=");
builder.append(type);
builder.append(", value=");
builder.append(value);
builder.append("]");
return builder.toString();
} }
} }

View File

@ -281,39 +281,71 @@ public class Task {
this.custom10 = custom10; this.custom10 = custom10;
} }
@Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder builder = new StringBuilder();
sb.append("TASK("); builder.append("Task [id=");
sb.append("id=" + id); builder.append(id);
sb.append(", created=" + created); builder.append(", created=");
sb.append(", claimed=" + claimed); builder.append(created);
sb.append(", completed=" + completed); builder.append(", claimed=");
sb.append(", modified=" + modified); builder.append(claimed);
sb.append(", planned=" + planned); builder.append(", completed=");
sb.append(", due=" + due); builder.append(completed);
sb.append(", name=" + name); builder.append(", modified=");
sb.append(", description=" + description); builder.append(modified);
sb.append(", priority=" + priority); builder.append(", planned=");
sb.append(", state=" + state); builder.append(planned);
sb.append(", classification=" + classification); builder.append(", due=");
sb.append(", workbasketId=" + workbasketId); builder.append(due);
sb.append(", businessProcessId=" + businessProcessId); builder.append(", name=");
sb.append(", parentBusinessProcessId=" + parentBusinessProcessId); builder.append(name);
sb.append(", owner=" + owner); builder.append(", description=");
sb.append(", primaryObjRef=" + primaryObjRef); builder.append(description);
sb.append(", isRead=" + isRead); builder.append(", priority=");
sb.append(", isTransferred=" + isTransferred); builder.append(priority);
sb.append(", custom1=" + custom1); builder.append(", state=");
sb.append(", custom2=" + custom2); builder.append(state);
sb.append(", custom3=" + custom3); builder.append(", classification=");
sb.append(", custom4=" + custom4); builder.append(classification);
sb.append(", custom5=" + custom5); builder.append(", workbasketId=");
sb.append(", custom6=" + custom6); builder.append(workbasketId);
sb.append(", custom7=" + custom7); builder.append(", businessProcessId=");
sb.append(", custom8=" + custom8); builder.append(businessProcessId);
sb.append(", custom9=" + custom9); builder.append(", parentBusinessProcessId=");
sb.append(", custom10=" + custom10); builder.append(parentBusinessProcessId);
sb.append(")"); builder.append(", owner=");
return sb.toString(); builder.append(owner);
builder.append(", primaryObjRef=");
builder.append(primaryObjRef);
builder.append(", isRead=");
builder.append(isRead);
builder.append(", isTransferred=");
builder.append(isTransferred);
builder.append(", customAttributes=");
builder.append(customAttributes);
builder.append(", custom1=");
builder.append(custom1);
builder.append(", custom2=");
builder.append(custom2);
builder.append(", custom3=");
builder.append(custom3);
builder.append(", custom4=");
builder.append(custom4);
builder.append(", custom5=");
builder.append(custom5);
builder.append(", custom6=");
builder.append(custom6);
builder.append(", custom7=");
builder.append(custom7);
builder.append(", custom8=");
builder.append(custom8);
builder.append(", custom9=");
builder.append(custom9);
builder.append(", custom10=");
builder.append(custom10);
builder.append("]");
return builder.toString();
} }
} }

View File

@ -23,4 +23,15 @@ public class TaskStateCounter {
public void setState(TaskState state) { public void setState(TaskState state) {
this.state = state; this.state = state;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TaskStateCounter [state=");
builder.append(state);
builder.append(", counter=");
builder.append(counter);
builder.append("]");
return builder.toString();
}
} }

View File

@ -72,4 +72,27 @@ public class Workbasket {
public void setDistributionTargets(List<Workbasket> distributionTargets) { public void setDistributionTargets(List<Workbasket> distributionTargets) {
this.distributionTargets = distributionTargets; this.distributionTargets = distributionTargets;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Workbasket [id=");
builder.append(id);
builder.append(", created=");
builder.append(created);
builder.append(", modified=");
builder.append(modified);
builder.append(", name=");
builder.append(name);
builder.append(", description=");
builder.append(description);
builder.append(", owner=");
builder.append(owner);
builder.append(", distributionTargets=");
builder.append(distributionTargets);
builder.append("]");
return builder.toString();
}
} }

View File

@ -150,4 +150,44 @@ public class WorkbasketAccessItem {
public void setPermCustom8(boolean permCustom8) { public void setPermCustom8(boolean permCustom8) {
this.permCustom8 = permCustom8; this.permCustom8 = permCustom8;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WorkbasketAccessItem [id=");
builder.append(id);
builder.append(", workbasketId=");
builder.append(workbasketId);
builder.append(", accessId=");
builder.append(accessId);
builder.append(", permRead=");
builder.append(permRead);
builder.append(", permOpen=");
builder.append(permOpen);
builder.append(", permAppend=");
builder.append(permAppend);
builder.append(", permTransfer=");
builder.append(permTransfer);
builder.append(", permDistribute=");
builder.append(permDistribute);
builder.append(", permCustom1=");
builder.append(permCustom1);
builder.append(", permCustom2=");
builder.append(permCustom2);
builder.append(", permCustom3=");
builder.append(permCustom3);
builder.append(", permCustom4=");
builder.append(permCustom4);
builder.append(", permCustom5=");
builder.append(permCustom5);
builder.append(", permCustom6=");
builder.append(permCustom6);
builder.append(", permCustom7=");
builder.append(permCustom7);
builder.append(", permCustom8=");
builder.append(permCustom8);
builder.append("]");
return builder.toString();
}
} }