From cbc2ff16ac237bb923dbef4574b532bb20d90dcc Mon Sep 17 00:00:00 2001 From: Jose Ignacio Recuerda Cambil Date: Mon, 11 Mar 2019 16:23:17 +0100 Subject: [PATCH] task/828: Unify and reduce the response and logger code in the controllers --- .../pro/taskana/rest/AccessIdController.java | 40 +++++++++------- .../rest/ClassificationController.java | 31 +++++++----- .../ClassificationDefinitionController.java | 40 ++++++++-------- .../pro/taskana/rest/MonitorController.java | 47 ++++++++----------- .../java/pro/taskana/rest/TaskController.java | 5 +- .../taskana/rest/TaskanaEngineController.java | 43 +++++++++++++---- .../rest/WorkbasketAccessItemController.java | 10 ++-- .../taskana/rest/WorkbasketController.java | 44 ++++++++++------- .../rest/WorkbasketDefinitionController.java | 11 +++-- 9 files changed, 158 insertions(+), 113 deletions(-) diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java index 7ba049cf4..f5fe37717 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java @@ -46,26 +46,28 @@ public class AccessIdController { "searchFor string '" + searchFor + "' is too short. Minimum searchFor length = " + ldapClient.getMinSearchForLength()); } + ResponseEntity> response; if (ldapClient.useLdap()) { List accessIdUsers = ldapClient.searchUsersAndGroups(searchFor); + response = new ResponseEntity<>(accessIdUsers, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from validateAccessIds(), returning {}", new ResponseEntity<>(accessIdUsers, HttpStatus.OK)); + LOGGER.debug("Exit from validateAccessIds(), returning {}", response); } - return new ResponseEntity<>(accessIdUsers, HttpStatus.OK); + return response; } else if (ldapCache != null) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from validateAccessIds(), returning {}", new ResponseEntity<>( - ldapCache.findMatchingAccessId(searchFor, ldapClient.getMaxNumberOfReturnedAccessIds()), - HttpStatus.OK)); - } - - return new ResponseEntity<>( + response = new ResponseEntity<>( ldapCache.findMatchingAccessId(searchFor, ldapClient.getMaxNumberOfReturnedAccessIds()), HttpStatus.OK); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Exit from validateAccessIds(), returning {}", response); + } + + return response; } else { - LOGGER.debug("Exit from validateAccessIds(), returning {}", new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND)); - return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND); + response = new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND); + LOGGER.debug("Exit from validateAccessIds(), returning {}", response); + return response; } } @@ -79,24 +81,28 @@ public class AccessIdController { } } List accessIdUsers; + ResponseEntity> response; if (ldapClient.useLdap()) { accessIdUsers = ldapClient.searchUsersAndGroups(accessId); accessIdUsers.addAll(ldapClient.searchGroupsofUsersIsMember(accessId)); + response = new ResponseEntity<>(accessIdUsers, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getGroupsByAccessId(), returning {}", new ResponseEntity<>(accessIdUsers, HttpStatus.OK)); + LOGGER.debug("Exit from getGroupsByAccessId(), returning {}", response); } - return new ResponseEntity<>(accessIdUsers, HttpStatus.OK); + return response; } else if (ldapCache != null) { accessIdUsers = ldapCache.findGroupsOfUser(accessId, ldapClient.getMaxNumberOfReturnedAccessIds()); + response = new ResponseEntity<>(accessIdUsers, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getGroupsByAccessId(), returning {}", new ResponseEntity<>(accessIdUsers, HttpStatus.OK)); + LOGGER.debug("Exit from getGroupsByAccessId(), returning {}", response); } - return new ResponseEntity<>(accessIdUsers, HttpStatus.OK); + return response; } else { - LOGGER.debug("Exit from getGroupsByAccessId(), returning {}", new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND)); - return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND); + response = new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND); + LOGGER.debug("Exit from getGroupsByAccessId(), returning {}", response); + return response; } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java index 8ffccfd08..099ff1ab7 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java @@ -114,11 +114,13 @@ public class ClassificationController extends AbstractPagingController { PagedResources pagedResources = assembler.toResources(classificationSummaries, pageMetadata); + ResponseEntity> response = new ResponseEntity<>(pagedResources, + HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getClassifications(), returning {}", new ResponseEntity<>(pagedResources, HttpStatus.OK)); + LOGGER.debug("Exit from getClassifications(), returning {}", response); } - return new ResponseEntity<>(pagedResources, HttpStatus.OK); + return response; } @GetMapping(path = "/{classificationId}") @@ -128,11 +130,13 @@ public class ClassificationController extends AbstractPagingController { ConcurrencyException, DomainNotFoundException, InvalidArgumentException { LOGGER.debug("Entry to getClassification(classificationId= {})", classificationId); Classification classification = classificationService.getClassification(classificationId); + ResponseEntity response = new ResponseEntity<>( + classificationResourceAssembler.toResource(classification), HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getClassification(), returning {}", ResponseEntity.status(HttpStatus.OK).body(classificationResourceAssembler.toResource(classification))); + LOGGER.debug("Exit from getClassification(), returning {}", response); } - return ResponseEntity.status(HttpStatus.OK).body(classificationResourceAssembler.toResource(classification)); + return response; } @PostMapping @@ -147,13 +151,14 @@ public class ClassificationController extends AbstractPagingController { Classification classification = classificationResourceAssembler.toModel(resource); classification = classificationService.createClassification(classification); + + ResponseEntity response = new ResponseEntity<>( + classificationResourceAssembler.toResource(classification), HttpStatus.CREATED); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from createClassification(), returning {}", ResponseEntity.status(HttpStatus.CREATED) - .body(classificationResourceAssembler.toResource(classification))); + LOGGER.debug("Exit from createClassification(), returning {}", response); } - return ResponseEntity.status(HttpStatus.CREATED) - .body(classificationResourceAssembler.toResource(classification)); + return response; } @PutMapping(path = "/{classificationId}") @@ -163,14 +168,15 @@ public class ClassificationController extends AbstractPagingController { throws NotAuthorizedException, ClassificationNotFoundException, ConcurrencyException, ClassificationAlreadyExistException, DomainNotFoundException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Entry to updateClassification(classificationId= {}, resource= {})", classificationId, resource); + LOGGER.debug("Entry to updateClassification(classificationId= {}, resource= {})", classificationId, + resource); } ResponseEntity result; if (classificationId.equals(resource.classificationId)) { Classification classification = classificationResourceAssembler.toModel(resource); classification = classificationService.updateClassification(classification); - result = ResponseEntity.ok(classificationResourceAssembler.toResource(classification)); + result = new ResponseEntity<>(classificationResourceAssembler.toResource(classification), HttpStatus.OK); } else { throw new InvalidArgumentException( "ClassificationId ('" + classificationId @@ -190,8 +196,9 @@ public class ClassificationController extends AbstractPagingController { throws ClassificationNotFoundException, ClassificationInUseException, NotAuthorizedException { LOGGER.debug("Entry to deleteClassification(classificationId= {})", classificationId); classificationService.deleteClassification(classificationId); - LOGGER.debug("Exit from deleteClassification(), returning {}", ResponseEntity.status(HttpStatus.NO_CONTENT).build()); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); + LOGGER.debug("Exit from deleteClassification(), returning {}", response); + return response; } private ClassificationQuery applySortingParams(ClassificationQuery query, MultiValueMap params) diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java index 2fb1a4a5e..713be3749 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java @@ -37,10 +37,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.HashSet; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Set; @@ -78,11 +76,12 @@ public class ClassificationDefinitionController { export.add(classificationResourceAssembler.toDefinition(classification)); } + ResponseEntity> response = new ResponseEntity<>(export, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from exportClassifications(), returning {}", new ResponseEntity<>(export, HttpStatus.OK)); + LOGGER.debug("Exit from exportClassifications(), returning {}", response); } - return new ResponseEntity<>(export, HttpStatus.OK); + return response; } @PostMapping @@ -95,11 +94,12 @@ public class ClassificationDefinitionController { Map systemIds = getSystemIds(); List classificationsResources = extractClassificationResourcesFromFile(file); - Map childsInFile = mapChildsToParentKeys(classificationsResources, systemIds); + Map childrenInFile = mapChildrenToParentKeys(classificationsResources, systemIds); insertOrUpdateClassificationsWithoutParent(classificationsResources, systemIds); - updateParentChildRelations(childsInFile); - LOGGER.debug("Exit from importClassifications(), returning {}", new ResponseEntity<>(HttpStatus.OK)); - return new ResponseEntity<>(HttpStatus.OK); + updateParentChildrenRelations(childrenInFile); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + LOGGER.debug("Exit from importClassifications(), returning {}", response); + return response; } private Map getSystemIds() { @@ -111,7 +111,7 @@ public class ClassificationDefinitionController { } private List extractClassificationResourcesFromFile(MultipartFile file) - throws IOException, JsonParseException, JsonMappingException { + throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); List classificationsDefinitions = mapper.readValue(file.getInputStream(), @@ -121,9 +121,9 @@ public class ClassificationDefinitionController { return classificationsDefinitions; } - private Map mapChildsToParentKeys(List classificationResources, Map systemIds) { - LOGGER.debug("Entry to mapChildsToParentKeys()"); - Map childsInFile = new HashMap<>(); + private Map mapChildrenToParentKeys(List classificationResources, Map systemIds) { + LOGGER.debug("Entry to mapChildrenToParentKeys()"); + Map childrenInFile = new HashMap<>(); Set newKeysWithDomain = new HashSet<>(); classificationResources.forEach(cl -> newKeysWithDomain.add(cl.getKey() + "|" + cl.getDomain())); @@ -142,15 +142,15 @@ public class ClassificationDefinitionController { String parentKeyAndDomain = cl.parentKey + "|" + cl.domain; if (!cl.getParentKey().isEmpty() && !cl.getParentKey().equals("")) { if (newKeysWithDomain.contains(parentKeyAndDomain) || systemIds.containsKey(parentKeyAndDomain)) { - childsInFile.put(classificationResourceAssembler.toModel(cl), cl.getParentKey()); + childrenInFile.put(classificationResourceAssembler.toModel(cl), cl.getParentKey()); } } } if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from mapChildsToParentKeys(), returning {}", LoggerUtils.mapToString(childsInFile)); + LOGGER.debug("Exit from mapChildrenToParentKeys(), returning {}", LoggerUtils.mapToString(childrenInFile)); } - return childsInFile; + return childrenInFile; } private void insertOrUpdateClassificationsWithoutParent(List classificationResources, @@ -175,20 +175,20 @@ public class ClassificationDefinitionController { LOGGER.debug("Exit from insertOrUpdateClassificationsWithoutParent()"); } - private void updateParentChildRelations(Map childsInFile) + private void updateParentChildrenRelations(Map childrenInFile) throws ClassificationNotFoundException, NotAuthorizedException, ConcurrencyException, InvalidArgumentException { - LOGGER.debug("Entry to updateParentChildRelations()"); - for (Classification childRes : childsInFile.keySet()) { + LOGGER.debug("Entry to updateParentChildrenRelations()"); + for (Classification childRes : childrenInFile.keySet()) { Classification child = classificationService .getClassification(childRes.getKey(), childRes.getDomain()); - String parentKey = childsInFile.get(childRes); + String parentKey = childrenInFile.get(childRes); String parentId = classificationService.getClassification(parentKey, childRes.getDomain()).getId(); child.setParentKey(parentKey); child.setParentId(parentId); classificationService.updateClassification(child); } - LOGGER.debug("Exit from updateParentChildRelations()"); + LOGGER.debug("Exit from updateParentChildrenRelations()"); } private void updateExistingClassification(ClassificationResource cl, diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java index 29c33ba4b..a19fee041 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java @@ -23,8 +23,8 @@ import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.report.TimeIntervalColumnHeader; import pro.taskana.monitor.ClassificationTimeIntervalColumnHeader; import pro.taskana.monitor.WorkbasketTimeIntervalColumnHeader; -import pro.taskana.rest.resource.ReportResource; import pro.taskana.rest.resource.ReportAssembler; +import pro.taskana.rest.resource.ReportResource; /** * Controller for all monitoring endpoints. @@ -32,6 +32,7 @@ import pro.taskana.rest.resource.ReportAssembler; @RestController @RequestMapping(path = "/v1/monitor", produces = "application/hal+json") public class MonitorController { + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorController.class); @Autowired @@ -46,16 +47,14 @@ public class MonitorController { @RequestParam(required = false) List states) throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksStatusReport()"); + ResponseEntity response = new ResponseEntity<>(reportAssembler.toResource( + taskMonitorService.createTaskStatusReportBuilder().stateIn(states).domainIn(domains).buildReport(), + domains, states), HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getTasksStatusReport(), returning {}", reportAssembler.toResource( - taskMonitorService.createTaskStatusReportBuilder().stateIn(states).domainIn(domains).buildReport(), - domains, states)); + LOGGER.debug("Exit from getTasksStatusReport(), returning {}", response); } - return ResponseEntity.status(HttpStatus.OK) - .body(reportAssembler.toResource( - taskMonitorService.createTaskStatusReportBuilder().stateIn(states).domainIn(domains).buildReport(), - domains, states)); + return response; } @GetMapping(path = "/tasks-workbasket-report") @@ -65,19 +64,16 @@ public class MonitorController { @RequestParam(value = "states") List states) throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksWorkbasketReport()"); + ResponseEntity response = new ResponseEntity<>(reportAssembler.toResource( + taskMonitorService.createWorkbasketReportBuilder() + .stateIn(states) + .withColumnHeaders(getTasksWorkbasketsTimeInterval(daysInPast)).buildReport(), daysInPast, states), + HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getTasksWorkbasketReport(), returning {}", reportAssembler.toResource( - taskMonitorService.createWorkbasketReportBuilder() - .stateIn(states) - .withColumnHeaders(getTasksWorkbasketsTimeInterval(daysInPast)).buildReport(), daysInPast, states)); + LOGGER.debug("Exit from getTasksWorkbasketReport(), returning {}", response); } - return ResponseEntity.status(HttpStatus.OK) - .body(reportAssembler.toResource( - taskMonitorService.createWorkbasketReportBuilder() - .stateIn(states) - .withColumnHeaders(getTasksWorkbasketsTimeInterval(daysInPast)).buildReport(), daysInPast, states)); - + return response; } @GetMapping(path = "/tasks-classification-report") @@ -85,18 +81,15 @@ public class MonitorController { public ResponseEntity getTasksClassificationReport() throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksClassificationReport()"); + ResponseEntity response = new ResponseEntity<>(reportAssembler.toResource( + taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(getTaskClassificationTimeInterval()) + .buildReport()), HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getTasksClassificationReport(), returning {}", reportAssembler.toResource( - taskMonitorService.createClassificationReportBuilder() - .withColumnHeaders(getTaskClassificationTimeInterval()) - .buildReport())); + LOGGER.debug("Exit from getTasksClassificationReport(), returning {}", response); } - return ResponseEntity.status(HttpStatus.OK) - .body(reportAssembler.toResource( - taskMonitorService.createClassificationReportBuilder() - .withColumnHeaders(getTaskClassificationTimeInterval()) - .buildReport())); + return response; } private List getTaskClassificationTimeInterval() { diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java index 93ef72a70..bef355a44 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java @@ -126,11 +126,12 @@ public class TaskController extends AbstractPagingController { TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler(); PagedResources pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries, pageMetadata); + ResponseEntity> response = new ResponseEntity<>(pagedResources, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getTasks(), returning {}", new ResponseEntity<>(pagedResources, HttpStatus.OK)); + LOGGER.debug("Exit from getTasks(), returning {}", response); } - return new ResponseEntity<>(pagedResources, HttpStatus.OK); + return response; } @GetMapping(path = "/{taskId}") diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java index d9db0f95c..f34beaacf 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java @@ -36,21 +36,41 @@ public class TaskanaEngineController { @GetMapping(path = "/v1/domains", produces = {MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity> getDomains() { - return new ResponseEntity<>(taskanaEngineConfiguration.getDomains(), HttpStatus.OK); + ResponseEntity> response = new ResponseEntity<>(taskanaEngineConfiguration.getDomains(), + HttpStatus.OK); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Exit from getDomains(), returning {}", response); + } + return response; } @GetMapping(path = "/v1/classification-categories", produces = {MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity> getClassificationCategories(String type) { + LOGGER.debug("Entry to getClassificationCategories(type = {})", type); + ResponseEntity> response; if (type != null) { - return new ResponseEntity<>(taskanaEngineConfiguration.getClassificationCategoriesByType(type), + response = new ResponseEntity<>(taskanaEngineConfiguration.getClassificationCategoriesByType(type), HttpStatus.OK); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Exit from getClassificationCategories(), returning {}", response); + } + return response; } - return new ResponseEntity<>(taskanaEngineConfiguration.getAllClassificationCategories(), HttpStatus.OK); + response = new ResponseEntity<>(taskanaEngineConfiguration.getAllClassificationCategories(), HttpStatus.OK); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Exit from getClassificationCategories(), returning {}", response); + } + return response; } @GetMapping(path = "/v1/classification-types", produces = {MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity> getClassificationTypes() { - return new ResponseEntity<>(taskanaEngineConfiguration.getClassificationTypes(), HttpStatus.OK); + ResponseEntity> response = new ResponseEntity<>( + taskanaEngineConfiguration.getClassificationTypes(), HttpStatus.OK); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Exit from getClassificationTypes(), returning {}", response); + } + return response; } @GetMapping(path = "/v1/current-user-info", produces = {MediaType.APPLICATION_JSON_VALUE}) @@ -64,17 +84,21 @@ public class TaskanaEngineController { resource.getRoles().add(role); } } + ResponseEntity response = new ResponseEntity<>(resource, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getCurrentUserInfo(), returning {}", new ResponseEntity<>(resource, HttpStatus.OK)); + LOGGER.debug("Exit from getCurrentUserInfo(), returning {}", response); } - return new ResponseEntity<>(resource, HttpStatus.OK); + return response; } @GetMapping(path = "/v1/history-provider-enabled", produces = {MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity getIsHistoryProviderEnabled() { - return new ResponseEntity<>(((TaskanaEngineImpl) taskanaEngine).getHistoryEventProducer().isEnabled(), + ResponseEntity response = new ResponseEntity<>( + ((TaskanaEngineImpl) taskanaEngine).getHistoryEventProducer().isEnabled(), HttpStatus.OK); + LOGGER.debug("Exit from getIsHistoryProviderEnabled(), returning {}", response); + return response; } /** @@ -87,7 +111,8 @@ public class TaskanaEngineController { LOGGER.debug("Entry to currentVersion()"); VersionResource resource = new VersionResource(); resource.setVersion(TaskanaEngineConfiguration.class.getPackage().getImplementationVersion()); - LOGGER.debug("Exit from currentVersion(), returning {}", new ResponseEntity<>(resource, HttpStatus.OK)); - return new ResponseEntity<>(resource, HttpStatus.OK); + ResponseEntity response = new ResponseEntity<>(resource, HttpStatus.OK); + LOGGER.debug("Exit from currentVersion(), returning {}", response); + return response; } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java index c10870152..b1fd53b0b 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java @@ -103,11 +103,12 @@ public class WorkbasketAccessItemController extends AbstractPagingController { workbasketAccessItems, pageMetadata); + ResponseEntity> response = new ResponseEntity<>(pagedResources, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getWorkbasketAccessItems(), returning {}", new ResponseEntity<>(pagedResources, HttpStatus.OK)); + LOGGER.debug("Exit from getWorkbasketAccessItems(), returning {}", response); } - return new ResponseEntity<>(pagedResources, HttpStatus.OK); + return response; } /** @@ -136,8 +137,9 @@ public class WorkbasketAccessItemController extends AbstractPagingController { accessId + " corresponding to a group, not a user. You just can remove access items for a user"); } - LOGGER.debug("Exit from removeWorkbasketAccessItems(), returning {}", ResponseEntity.status(HttpStatus.NO_CONTENT).build()); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); + LOGGER.debug("Exit from removeWorkbasketAccessItems(), returning {}", response); + return response; } private WorkbasketAccessItemQuery getAccessIds(WorkbasketAccessItemQuery query, diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java index bc1b82904..fd604900d 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java @@ -43,14 +43,14 @@ import pro.taskana.exceptions.WorkbasketAlreadyExistException; import pro.taskana.exceptions.WorkbasketInUseException; import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.impl.util.LoggerUtils; -import pro.taskana.rest.resource.DistributionTargetResource; -import pro.taskana.rest.resource.WorkbasketAccessItemResource; -import pro.taskana.rest.resource.WorkbasketResource; -import pro.taskana.rest.resource.WorkbasketSummaryResource; import pro.taskana.rest.resource.DistributionTargetListAssembler; +import pro.taskana.rest.resource.DistributionTargetResource; import pro.taskana.rest.resource.WorkbasketAccessItemAssembler; import pro.taskana.rest.resource.WorkbasketAccessItemListAssembler; +import pro.taskana.rest.resource.WorkbasketAccessItemResource; +import pro.taskana.rest.resource.WorkbasketResource; import pro.taskana.rest.resource.WorkbasketResourceAssembler; +import pro.taskana.rest.resource.WorkbasketSummaryResource; import pro.taskana.rest.resource.WorkbasketSummaryResourcesAssembler; /** @@ -60,6 +60,7 @@ import pro.taskana.rest.resource.WorkbasketSummaryResourcesAssembler; @EnableHypermediaSupport(type = HypermediaType.HAL) @RequestMapping(path = "/v1/workbaskets", produces = "application/hal+json") public class WorkbasketController extends AbstractPagingController { + private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketController.class); private static final String LIKE = "%"; @@ -135,11 +136,13 @@ public class WorkbasketController extends AbstractPagingController { PagedResources pagedResources = assembler.toResources(workbasketSummaries, pageMetadata); + ResponseEntity> response = new ResponseEntity<>(pagedResources, + HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getWorkbaskets(), returning {}", new ResponseEntity<>(pagedResources, HttpStatus.OK)); + LOGGER.debug("Exit from getWorkbaskets(), returning {}", response); } - return new ResponseEntity<>(pagedResources, HttpStatus.OK); + return response; } @GetMapping(path = "/{workbasketId}") @@ -163,8 +166,10 @@ public class WorkbasketController extends AbstractPagingController { throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, WorkbasketInUseException { LOGGER.debug("Entry to markWorkbasketForDeletion(workbasketId= {})", workbasketId); - LOGGER.debug("Exit from markWorkbasketForDeletion(), returning {}", new ResponseEntity<>(workbasketService.deleteWorkbasket(workbasketId), HttpStatus.ACCEPTED)); - return new ResponseEntity<>(workbasketService.deleteWorkbasket(workbasketId), HttpStatus.ACCEPTED); + ResponseEntity response = new ResponseEntity<>(workbasketService.deleteWorkbasket(workbasketId), HttpStatus.ACCEPTED); + LOGGER.debug("Exit from markWorkbasketForDeletion(), returning {}", + response); + return response; } @PostMapping @@ -178,11 +183,12 @@ public class WorkbasketController extends AbstractPagingController { Workbasket workbasket = workbasketResourceAssembler.toModel(workbasketResource); workbasket = workbasketService.createWorkbasket(workbasket); + ResponseEntity response = new ResponseEntity<>(workbasketResourceAssembler.toResource(workbasket), HttpStatus.CREATED); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from createWorkbasket(), returning {}", new ResponseEntity<>(workbasketResourceAssembler.toResource(workbasket), HttpStatus.CREATED)); + LOGGER.debug("Exit from createWorkbasket(), returning {}", response); } - return new ResponseEntity<>(workbasketResourceAssembler.toResource(workbasket), HttpStatus.CREATED); + return response; } @PutMapping(path = "/{workbasketId}") @@ -249,11 +255,12 @@ public class WorkbasketController extends AbstractPagingController { Resources accessItemListResource = accessItemListAssembler .toResource(workbasketId, updatedWbAccessItems); + ResponseEntity> response = new ResponseEntity<>(accessItemListResource, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from setWorkbasketAccessItems(), returning {}", new ResponseEntity<>(accessItemListResource, HttpStatus.OK)); + LOGGER.debug("Exit from setWorkbasketAccessItems(), returning {}", response); } - return new ResponseEntity<>(accessItemListResource, HttpStatus.OK); + return response; } @GetMapping(path = "/{workbasketId}/distribution-targets") @@ -280,7 +287,8 @@ public class WorkbasketController extends AbstractPagingController { @PathVariable(value = "workbasketId") String sourceWorkbasketId, @RequestBody List targetWorkbasketIds) throws WorkbasketNotFoundException, NotAuthorizedException { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Entry to getTasksStatusReport(workbasketId= {}, targetWorkbasketIds´= {})", sourceWorkbasketId, + LOGGER.debug("Entry to getTasksStatusReport(workbasketId= {}, targetWorkbasketIds´= {})", + sourceWorkbasketId, LoggerUtils.listToString(targetWorkbasketIds)); } @@ -290,11 +298,12 @@ public class WorkbasketController extends AbstractPagingController { Resources distributionTargetListResource = distributionTargetListAssembler .toResource(sourceWorkbasketId, distributionTargets); + ResponseEntity> response = new ResponseEntity<>(distributionTargetListResource, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from getTasksStatusReport(), returning {}", new ResponseEntity<>(distributionTargetListResource, HttpStatus.OK)); + LOGGER.debug("Exit from getTasksStatusReport(), returning {}", response); } - return new ResponseEntity<>(distributionTargetListResource, HttpStatus.OK); + return response; } @DeleteMapping(path = "/distribution-targets/{workbasketId}") @@ -308,8 +317,9 @@ public class WorkbasketController extends AbstractPagingController { workbasketService.removeDistributionTarget(source.getId(), targetWorkbasketId); } - LOGGER.debug("Exit from removeDistributionTargetForWorkbasketId(), returning {}", new ResponseEntity<>(HttpStatus.NO_CONTENT)); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); + ResponseEntity> response = new ResponseEntity<>(HttpStatus.NO_CONTENT); + LOGGER.debug("Exit from removeDistributionTargetForWorkbasketId(), returning {}", response); + return response; } private WorkbasketQuery applySortingParams(WorkbasketQuery query, MultiValueMap params) diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java index 3e338f784..de0309468 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java @@ -70,12 +70,12 @@ public class WorkbasketDefinitionController { basketExports.add(workbasketDefinitionAssembler.toResource(workbasket)); } + ResponseEntity> response = new ResponseEntity<>(basketExports, HttpStatus.OK); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exit from exportWorkbaskets(), returning {}", - new ResponseEntity<>(basketExports, HttpStatus.OK)); + LOGGER.debug("Exit from exportWorkbaskets(), returning {}", response); } - return new ResponseEntity<>(basketExports, HttpStatus.OK); + return response; } /** @@ -152,8 +152,9 @@ public class WorkbasketDefinitionController { // no verification necessary since the workbasket was already imported in step 1. idConversion.get(definition.getWorkbasket().getWorkbasketId()), distributionTargets); } - LOGGER.debug("Exit from importWorkbaskets(), returning {}", new ResponseEntity<>(HttpStatus.OK)); - return new ResponseEntity<>(HttpStatus.OK); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + LOGGER.debug("Exit from importWorkbaskets(), returning {}", response); + return response; } private String logicalId(WorkbasketSummary workbasket) {