From 7fb36ac1565ab98abe54c34247405c2edfb8e9d1 Mon Sep 17 00:00:00 2001 From: BerndBreier <33351391+BerndBreier@users.noreply.github.com> Date: Fri, 1 Dec 2017 13:46:20 +0100 Subject: [PATCH] correct logging statements in merged files --- .../impl/ClassificationServiceImpl.java | 3 +- .../pro/taskana/impl/SummaryServiceImpl.java | 2 +- .../pro/taskana/impl/TaskServiceImpl.java | 54 +++++++++++++------ .../taskana/impl/WorkbasketServiceImpl.java | 9 ++-- .../pro/taskana/impl/util/LoggerUtils.java | 30 +++++++++++ 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java index 59282a3bc..8932d1e60 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java @@ -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()."); diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/SummaryServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/SummaryServiceImpl.java index a76dd4091..d2c45afb8 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/SummaryServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/SummaryServiceImpl.java @@ -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<>(); diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java index 597f6cee2..2a2ee2223 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java @@ -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 customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { + public Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name, + String description, ObjectReference primaryObjectReference, Map 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 getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception { - List resultList = null; + LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId, taskState); + List 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) { diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java index 4bce2e6b0..508cc8c83 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java @@ -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 oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId()); List 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); } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/util/LoggerUtils.java b/lib/taskana-core/src/main/java/pro/taskana/impl/util/LoggerUtils.java index 3a771a90b..d7aca98fc 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/util/LoggerUtils.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/util/LoggerUtils.java @@ -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 String mapToString(Map map) { + if (map == null || map.isEmpty()) { + return "[]"; + } else { + StringBuilder builder = new StringBuilder(); + builder.append("["); + Set> entrySet = map.entrySet(); + for (Entry entry : entrySet) { + builder.append("("); + builder.append(entry.getKey()); + builder.append(" , "); + builder.append(entry.getValue()); + builder.append(")"); + builder.append(" , "); + } + builder.append("]"); + return builder.toString(); + } + + } }