TSK-53_logging_support_Initial implementation

This commit is contained in:
BerndBreier 2017-11-29 16:34:11 +01:00
parent ed0703cd9a
commit e9434c2497
13 changed files with 550 additions and 94 deletions

View File

@ -1,11 +1,15 @@
package pro.taskana.impl;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Classification;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@ -16,6 +20,7 @@ import java.util.List;
public class ClassificationQueryImpl implements ClassificationQuery {
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 String[] parentClassificationId;
private String[] category;
@ -115,32 +120,46 @@ public class ClassificationQueryImpl implements ClassificationQuery {
@Override
public List<Classification> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<Classification> result = null;
try {
taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public List<Classification> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<Classification> result = null;
try {
taskanaEngineImpl.openConnection();
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 {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public Classification single() {
LOGGER.debug("entry to single(), this = {}", this);
Classification result = null;
try {
taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
}
}
@ -247,4 +266,40 @@ public class ClassificationQueryImpl implements ClassificationQuery {
public void setValidUntil(Date[] 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.NotAuthorizedException;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Classification;
import pro.taskana.model.mappings.ClassificationMapper;
@ -15,6 +16,9 @@ import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the implementation of ClassificationService.
*/
@ -22,6 +26,7 @@ public class ClassificationServiceImpl implements ClassificationService {
private static final String ID_PREFIX_CLASSIFICATION = "CLI";
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 TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
@ -35,13 +40,18 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override
public List<Classification> getClassificationTree() throws NotAuthorizedException {
LOGGER.debug("entry to getClassificationTree()");
List<Classification> result = null;
try {
taskanaEngineImpl.openConnection();
List<Classification> rootClassifications;
rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
return this.populateChildClassifications(rootClassifications);
result = this.populateChildClassifications(rootClassifications);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getClassificationTree(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@ -62,7 +72,8 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override
public void addClassification(Classification classification) {
try {
LOGGER.debug("entry to addClassification(classification = {})", classification);
try {
taskanaEngineImpl.openConnection();
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
classification.setCreated(Date.valueOf(LocalDate.now()));
@ -70,13 +81,16 @@ public class ClassificationServiceImpl implements ClassificationService {
this.setDefaultValues(classification);
classificationMapper.insert(classification);
LOGGER.info("Method addClassification added classification {}.", classification);
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from addClassification()");
}
}
@Override
public void updateClassification(Classification classification) {
LOGGER.debug("entry to updateClassification(Classification = {})", classification);
try {
taskanaEngineImpl.openConnection();
this.setDefaultValues(classification);
@ -84,16 +98,19 @@ public class ClassificationServiceImpl implements ClassificationService {
Classification oldClassification = null;
try {
oldClassification = this.getClassification(classification.getId(), classification.getDomain());
LOGGER.info("Method updateClassification() inserted classification {}.", classification);
// ! If you update an classification twice the same day,
// the older version is valid from today until yesterday.
if (!oldClassification.getDomain().equals(classification.getDomain())) {
classification.setCreated(Date.valueOf(LocalDate.now()));
classificationMapper.insert(classification);
LOGGER.info("Method updateClassification() inserted classification {}.", classification);
} else {
oldClassification.setValidUntil(Date.valueOf(LocalDate.now().minusDays(1)));
classificationMapper.update(oldClassification);
classificationMapper.insert(classification);
LOGGER.info("Method updateClassification() updated old classification {} and inserted new {}.", oldClassification, classification);
}
} catch (ClassificationNotFoundException e) {
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
@ -102,6 +119,7 @@ public class ClassificationServiceImpl implements ClassificationService {
}
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateClassification().");
}
}
@ -132,32 +150,38 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override
public List<Classification> getAllClassificationsWithId(String id, String domain) {
LOGGER.debug("entry to getAllClassificationsWithId(id = {}, domain = {})", id, domain);
List<Classification> result = null;
try {
taskanaEngineImpl.openConnection();
return classificationMapper.getAllClassificationsWithId(id, domain);
result = classificationMapper.getAllClassificationsWithId(id, domain);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getAllClassificationsWithId(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public Classification getClassification(String id, String domain) throws ClassificationNotFoundException {
try {
LOGGER.debug("entry to getClassification(id = {}, domain = {})", id, domain);
Classification result = null;
try {
taskanaEngineImpl.openConnection();
Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
if (classification == null) {
classification = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
result = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
if (result == null) {
result = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
}
if (classification == null) {
if (result == null) {
throw new ClassificationNotFoundException(id);
}
return classification;
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getClassification(). Returning result {} ", result);
}
}
@Override

View File

@ -1,11 +1,15 @@
package pro.taskana.impl;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.ObjectReference;
/**
@ -15,6 +19,7 @@ import pro.taskana.model.ObjectReference;
public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
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 String[] company;
@ -59,32 +64,46 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
@Override
public List<ObjectReference> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<ObjectReference> result = null;
try {
taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public List<ObjectReference> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<ObjectReference> result = null;
try {
taskanaEngineImpl.openConnection();
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 {
taskanaEngineImpl.returnConnection();
}
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public ObjectReference single() {
LOGGER.debug("entry to single(), this = {}", this);
ObjectReference result = null;
try {
taskanaEngineImpl.openConnection();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
}
}
@ -127,4 +146,23 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
public void setValue(String[] 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

@ -1,14 +1,18 @@
package pro.taskana.impl;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
import pro.taskana.model.WorkbasketAuthorization;
@ -19,6 +23,7 @@ import pro.taskana.model.WorkbasketAuthorization;
public class TaskQueryImpl implements TaskQuery {
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;
@ -111,35 +116,49 @@ public class TaskQueryImpl implements TaskQuery {
@Override
public List<Task> list() throws NotAuthorizedException {
LOGGER.debug("entry to list(), this = {}", this);
List<Task> result = null;
try {
taskanaEngineImpl.openConnection();
checkAuthorization();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
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 {
taskanaEngineImpl.openConnection();
checkAuthorization();
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 {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public Task single() throws NotAuthorizedException {
LOGGER.debug("entry to single(), this = {}", this);
Task result = null;
try {
taskanaEngineImpl.openConnection();
checkAuthorization();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
}
}
@ -246,4 +265,35 @@ public class TaskQueryImpl implements TaskQuery {
public void setCustomFields(String[] 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

@ -11,6 +11,7 @@ import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.*;
import pro.taskana.model.mappings.ObjectReferenceMapper;
import pro.taskana.model.mappings.TaskMapper;
@ -51,6 +52,7 @@ public class TaskServiceImpl implements TaskService {
@Override
public Task claim(String id, String userName) throws TaskNotFoundException {
LOGGER.debug("entry to claim(id = {}, userName = {})", id, userName);
Task task = null;
try {
taskanaEngineImpl.openConnection();
@ -62,18 +64,21 @@ public class TaskServiceImpl implements TaskService {
task.setClaimed(now);
task.setState(TaskState.CLAIMED);
taskMapper.update(task);
LOGGER.debug("User '{}' claimed task '{}'.", userName, id);
LOGGER.info("Method claim() claimed task '{}' for user '{}'.", id, userName);
} else {
LOGGER.warn("Method claim() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id);
}
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from claim()");
}
return task;
}
@Override
public Task complete(String id) throws TaskNotFoundException {
LOGGER.debug("entry to complete(id = {})", id);
Task task = null;
try {
taskanaEngineImpl.openConnection();
@ -84,18 +89,21 @@ public class TaskServiceImpl implements TaskService {
task.setModified(now);
task.setState(TaskState.COMPLETED);
taskMapper.update(task);
LOGGER.debug("Task '{}' completed.", id);
LOGGER.debug("Method complete() completed Task '{}'.", id);
} else {
LOGGER.warn("Method complete() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id);
}
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from complete()");
}
return task;
}
@Override
public Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException {
LOGGER.debug("entry to create(task = {})", task);
try {
taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
@ -139,54 +147,71 @@ public class TaskServiceImpl implements TaskService {
this.taskMapper.insert(task);
LOGGER.debug("Task '{}' created.", task.getId());
LOGGER.info("Method create() created Task '{}'.", task.getId());
return task;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from create()");
}
}
@Override
public Task getTaskById(String id) throws TaskNotFoundException {
LOGGER.debug("entry to getTaskById(id = {})", id);
Task result = null;
try {
taskanaEngineImpl.openConnection();
Task task = taskMapper.findById(id);
if (task != null) {
return task;
result = taskMapper.findById(id);
if (result != null) {
return result;
} else {
LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id);
}
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getTaskById(). Returning result {} ", result);
}
}
@Override
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) {
LOGGER.debug("entry to getTaskCountForState(states = {})", LoggerUtils.listToString(states));
List<TaskStateCounter> result = null;
try {
taskanaEngineImpl.openConnection();
return taskMapper.getTaskCountForState(states);
result = taskMapper.getTaskCountForState(states);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTaskCountForState(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) {
LOGGER.debug("entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
workbasketId, daysInPast, LoggerUtils.listToString(states));
long result = -1;
try {
taskanaEngineImpl.openConnection();
LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
result = taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
return result;
} finally {
taskanaEngineImpl.returnConnection();
}
LOGGER.debug("exit from getTaskCountForWorkbasketByDaysInPastAndState(). Returning result {} ", result);
}
}
@Override
public Task transfer(String taskId, String destinationWorkbasketId)
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketId = {})", taskId, destinationWorkbasketId);
Task result = null;
try {
taskanaEngineImpl.openConnection();
Task task = getTaskById(taskId);
@ -210,37 +235,51 @@ public class TaskServiceImpl implements TaskService {
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
taskMapper.update(task);
return getTaskById(taskId);
result = getTaskById(taskId);
LOGGER.info("Method transfer() transferred Task '{}' to destination workbasket {}", taskId, destinationWorkbasketId);
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from transfer(). Returning result {} ", result);
}
}
@Override
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
List<TaskState> states) {
LOGGER.debug("entry to getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast = {}, states = {})", daysInPast, LoggerUtils.listToString(states));
List<DueWorkbasketCounter> result = null;
try {
taskanaEngineImpl.openConnection();
LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
result = taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
LOGGER.debug("entry to setTaskRead(taskIdt = {}, isRead = {})", taskId, isRead);
Task result = null;
try {
taskanaEngineImpl.openConnection();
Task task = getTaskById(taskId);
task.setRead(true);
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
taskMapper.update(task);
return getTaskById(taskId);
result = getTaskById(taskId);
LOGGER.info("Method setTaskRead() set read property of Task '{}' to {} ", result, isRead);
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from setTaskRead(taskId, isRead). Returning result {} ", result);
}
}

View File

@ -7,6 +7,7 @@ import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Workbasket;
import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketAuthorization;
@ -52,21 +53,26 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException {
LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId);
Workbasket result = null;
try {
taskanaEngineImpl.openConnection();
Workbasket workbasket = workbasketMapper.findById(workbasketId);
if (workbasket == null) {
result = workbasketMapper.findById(workbasketId);
if (result == null) {
LOGGER.warn("Method getWorkbasket() didn't find workbasket with id {}. Throwing WorkbasketNotFoundException", workbasketId);
throw new WorkbasketNotFoundException(workbasketId);
}
return workbasket;
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
}
}
@Override
public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) {
LOGGER.debug("entry to getWorkbaskets(permissions = {})", LoggerUtils.listToString(permissions));
List<Workbasket> result = null;
try {
taskanaEngineImpl.openConnection();
//use a set to avoid duplicates
@ -74,26 +80,35 @@ public class WorkbasketServiceImpl implements WorkbasketService {
for (String accessId : CurrentUserContext.getAccessIds()) {
workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId));
}
List<Workbasket> workbasketList = new ArrayList<Workbasket>();
workbasketList.addAll(workbaskets);
return workbasketList;
result = new ArrayList<Workbasket>();
result.addAll(workbaskets);
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbaskets(permissions). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public List<Workbasket> getWorkbaskets() {
LOGGER.debug("entry to getWorkbaskets()");
List<Workbasket> result = null;
try {
taskanaEngineImpl.openConnection();
return workbasketMapper.findAll();
result = workbasketMapper.findAll();
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public Workbasket createWorkbasket(Workbasket workbasket) {
LOGGER.debug("entry to createtWorkbasket(workbasket)", workbasket);
Workbasket result = null;
try {
taskanaEngineImpl.openConnection();
Timestamp now = new Timestamp(System.currentTimeMillis());
@ -103,26 +118,31 @@ public class WorkbasketServiceImpl implements WorkbasketService {
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
}
workbasketMapper.insert(workbasket);
LOGGER.debug("Workbasket '{}' created", workbasket.getId());
LOGGER.info("Method createWorkbasket() created Workbasket '{}'", workbasket);
if (workbasket.getDistributionTargets() != null) {
for (Workbasket distributionTarget : workbasket.getDistributionTargets()) {
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
distributionTarget.setCreated(now);
distributionTarget.setModified(now);
workbasketMapper.insert(distributionTarget);
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
LOGGER.info("Method createWorkbasket() created distributionTarget '{}'", distributionTarget);
}
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
LOGGER.info("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 {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result);
}
}
@Override
public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException {
LOGGER.debug("entry to updateWorkbasket(workbasket)", workbasket);
Workbasket result = null;
try {
taskanaEngineImpl.openConnection();
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
@ -133,66 +153,88 @@ public class WorkbasketServiceImpl implements WorkbasketService {
if (!oldDistributionTargets.contains(distributionTarget.getId())) {
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
workbasketMapper.insert(distributionTarget);
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
LOGGER.info(" Method updateWorkbasket() created distributionTarget '{}'", distributionTarget);
}
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
LOGGER.info("Method updateWorkbasket() created distributionTarget for '{}' and '{}'", workbasket.getId(), distributionTarget.getId());
} else {
oldDistributionTargets.remove(distributionTarget.getId());
}
}
distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets);
LOGGER.debug("Workbasket '{}' updated", workbasket.getId());
return workbasketMapper.findById(workbasket.getId());
LOGGER.info("Method updateWorkbasket() deleted distributionTargets for '{}' and old distribution targets {}",
workbasket.getId(), LoggerUtils.listToString(oldDistributionTargets));
LOGGER.info("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId());
result = workbasketMapper.findById(workbasket.getId());
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result);
}
}
@Override
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
LOGGER.debug("entry to createWorkbasketAuthorization(workbasketAccessItem = {})", workbasketAccessItem);
try {
taskanaEngineImpl.openConnection();
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
workbasketAccessMapper.insert(workbasketAccessItem);
LOGGER.info("Method createWorkbasketAuthorization() created workbaskteAccessItem {}", workbasketAccessItem);
return workbasketAccessItem;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from createWorkbasketAuthorization(workbasketAccessItem). Returning result {}", workbasketAccessItem);
}
}
@Override
public WorkbasketAccessItem getWorkbasketAuthorization(String id) {
try {
LOGGER.debug("entry to getWorkbasketAuthorization(id = {})", id);
WorkbasketAccessItem result = null;
try {
taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findById(id);
result = workbasketAccessMapper.findById(id);
return result;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getWorkbasketAuthorization(id). Returning result {}", result);
}
}
@Override
public void deleteWorkbasketAuthorization(String id) {
LOGGER.debug("entry to deleteWorkbasketAuthorization(id = {})", id);
try {
taskanaEngineImpl.openConnection();
workbasketAccessMapper.delete(id);
LOGGER.info("Method deleteWorkbasketAuthorization() deleted workbasketAccessItem wit Id {}", id);
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from deleteWorkbasketAuthorization(id).");
}
}
@Override
public List<WorkbasketAccessItem> getAllAuthorizations() {
LOGGER.debug("entry to getAllAuthorizations()");
List<WorkbasketAccessItem> result = null;
try {
taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findAll();
result = workbasketAccessMapper.findAll();
return result;
} finally {
taskanaEngineImpl.returnConnection();
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getAllAuthorizations(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@Override
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
throws NotAuthorizedException {
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketAuthorization = {})", workbasketId, workbasketAuthorization);
try {
taskanaEngineImpl.openConnection();
// Skip permission check is security is not enabled
@ -202,17 +244,20 @@ public class WorkbasketServiceImpl implements WorkbasketService {
}
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);
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
.findByWorkbasketAndAccessIdAndAuthorizations(workbasketId, accessIds, workbasketAuthorization.name());
if (accessItems.size() <= 0) {
LOGGER.debug("exit from checkAuthorization() with NotAuthorizedExeption");
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
+ "' on workbasket '" + workbasketId + "' is needed.");
}
LOGGER.debug("normal exit from checkAuthorization(). The user is authorized.");
} finally {
taskanaEngineImpl.returnConnection();
}
@ -220,22 +265,30 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
LOGGER.debug("entry to updateWorkbasketAuthorization(workbasketAccessItem = {}", workbasketAccessItem);
try {
taskanaEngineImpl.openConnection();
workbasketAccessMapper.update(workbasketAccessItem);
LOGGER.info("Method updateWorkbasketAuthorization() updated workbasketAccessItem {}", workbasketAccessItem);
return workbasketAccessItem;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateWorkbasketAuthorization(workbasketAccessItem). Returning {}", workbasketAccessItem);
}
}
@Override
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) {
LOGGER.debug("entry to getWorkbasketAuthorizations(workbasketId = {})", workbasketId);
List<WorkbasketAccessItem> result = null;
try {
taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findByWorkbasketId(workbasketId);
result = workbasketAccessMapper.findByWorkbasketId(workbasketId);
return result;
} finally {
taskanaEngineImpl.returnConnection();
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,34 @@
package pro.taskana.impl.util;
import java.util.List;
/**
* 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();
}
}
}

View File

@ -197,4 +197,54 @@ public class Classification {
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
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("ObjectReference(");
sb.append("id=" + id);
sb.append(", company=" + company);
sb.append(", system=" + system);
sb.append(", systemInstance=" + systemInstance);
sb.append(", type=" + type);
sb.append(", value=" + value);
return sb.toString();
StringBuilder builder = new StringBuilder();
builder.append("ObjectReference [id=");
builder.append(id);
builder.append(", company=");
builder.append(company);
builder.append(", system=");
builder.append(system);
builder.append(", systemInstance=");
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;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("TASK(");
sb.append("id=" + id);
sb.append(", created=" + created);
sb.append(", claimed=" + claimed);
sb.append(", completed=" + completed);
sb.append(", modified=" + modified);
sb.append(", planned=" + planned);
sb.append(", due=" + due);
sb.append(", name=" + name);
sb.append(", description=" + description);
sb.append(", priority=" + priority);
sb.append(", state=" + state);
sb.append(", classification=" + classification);
sb.append(", workbasketId=" + workbasketId);
sb.append(", businessProcessId=" + businessProcessId);
sb.append(", parentBusinessProcessId=" + parentBusinessProcessId);
sb.append(", owner=" + owner);
sb.append(", primaryObjRef=" + primaryObjRef);
sb.append(", isRead=" + isRead);
sb.append(", isTransferred=" + isTransferred);
sb.append(", custom1=" + custom1);
sb.append(", custom2=" + custom2);
sb.append(", custom3=" + custom3);
sb.append(", custom4=" + custom4);
sb.append(", custom5=" + custom5);
sb.append(", custom6=" + custom6);
sb.append(", custom7=" + custom7);
sb.append(", custom8=" + custom8);
sb.append(", custom9=" + custom9);
sb.append(", custom10=" + custom10);
sb.append(")");
return sb.toString();
StringBuilder builder = new StringBuilder();
builder.append("Task [id=");
builder.append(id);
builder.append(", created=");
builder.append(created);
builder.append(", claimed=");
builder.append(claimed);
builder.append(", completed=");
builder.append(completed);
builder.append(", modified=");
builder.append(modified);
builder.append(", planned=");
builder.append(planned);
builder.append(", due=");
builder.append(due);
builder.append(", name=");
builder.append(name);
builder.append(", description=");
builder.append(description);
builder.append(", priority=");
builder.append(priority);
builder.append(", state=");
builder.append(state);
builder.append(", classification=");
builder.append(classification);
builder.append(", workbasketId=");
builder.append(workbasketId);
builder.append(", businessProcessId=");
builder.append(businessProcessId);
builder.append(", parentBusinessProcessId=");
builder.append(parentBusinessProcessId);
builder.append(", owner=");
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) {
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) {
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) {
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();
}
}