correct logging statements in merged files

This commit is contained in:
BerndBreier 2017-12-01 13:46:20 +01:00
parent e582bc660a
commit 7fb36ac156
5 changed files with 75 additions and 23 deletions

View File

@ -118,7 +118,8 @@ public class ClassificationServiceImpl implements ClassificationService {
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
classification.setCreated(Date.valueOf(LocalDate.now()));
classificationMapper.insert(classification);
}
LOGGER.info("Method updateClassification() inserted classification {}.", classification);
}
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from updateClassification().");

View File

@ -35,7 +35,7 @@ public class SummaryServiceImpl implements SummaryService {
taskanaEngineImpl.openConnection();
taskSummaries = summaryMapper.findTasksummariesByWorkbasketId(workbasketId);
} catch (Exception ex) {
LOGGER.error("Getting TASKSUMMARY failed internal.", ex);
LOGGER.warn("Getting TASKSUMMARY failed internally.", ex);
} finally {
if (taskSummaries == null) {
taskSummaries = new ArrayList<>();

View File

@ -1,8 +1,17 @@
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.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.TaskQuery;
import pro.taskana.TaskService;
import pro.taskana.TaskanaEngine;
@ -12,18 +21,16 @@ 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.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.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.
*/
@ -89,7 +96,7 @@ public class TaskServiceImpl implements TaskService {
task.setModified(now);
task.setState(TaskState.COMPLETED);
taskMapper.update(task);
LOGGER.debug("Method complete() completed Task '{}'.", id);
LOGGER.info("Method complete() completed Task '{}'.", id);
} else {
LOGGER.warn("Method complete() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id);
@ -112,15 +119,22 @@ 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(task = {})");
}
}
@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 {
taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.APPEND);
@ -276,7 +290,7 @@ public class TaskServiceImpl implements TaskService {
@Override
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
LOGGER.debug("entry to setTaskRead(taskIdt = {}, isRead = {})", taskId, isRead);
LOGGER.debug("entry to setTaskRead(taskId = {}, isRead = {})", taskId, isRead);
Task result = null;
try {
taskanaEngineImpl.openConnection();
@ -300,15 +314,21 @@ public class TaskServiceImpl implements TaskService {
@Override
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 {
taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.READ);
resultList = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState);
result = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState);
} finally {
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) {

View File

@ -153,6 +153,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngineImpl.openConnection();
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
workbasketMapper.update(workbasket);
LOGGER.info("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId());
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
for (Workbasket distributionTarget : distributionTargets) {
@ -171,8 +172,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
if (LOGGER.isInfoEnabled()) {
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;
@ -245,11 +244,13 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
throws NotAuthorizedException {
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketAuthorization = {})", workbasketId, workbasketAuthorization);
boolean isAuthorized = false;
try {
taskanaEngineImpl.openConnection();
// Skip permission check is security is not enabled
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
LOGGER.debug("Skipping permissions check since security is disabled.");
isAuthorized = true;
return;
}
@ -261,15 +262,15 @@ public class WorkbasketServiceImpl implements WorkbasketService {
.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.");
isAuthorized = true;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from checkAuthorization(). User is authorized = {}.", isAuthorized);
}
}

View File

@ -1,6 +1,9 @@
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.
@ -31,4 +34,31 @@ public final class LoggerUtils {
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();
}
}
}