task/828: Unify and reduce the response and logger code in the controllers

This commit is contained in:
Jose Ignacio Recuerda Cambil 2019-03-11 16:23:17 +01:00 committed by Martin Rojas Miguel Angel
parent 114edfb50c
commit cbc2ff16ac
9 changed files with 158 additions and 113 deletions

View File

@ -46,26 +46,28 @@ public class AccessIdController {
"searchFor string '" + searchFor + "' is too short. Minimum searchFor length = "
+ ldapClient.getMinSearchForLength());
}
ResponseEntity<List<AccessIdResource>> response;
if (ldapClient.useLdap()) {
List<AccessIdResource> 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<AccessIdResource> accessIdUsers;
ResponseEntity<List<AccessIdResource>> 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;
}
}

View File

@ -114,11 +114,13 @@ public class ClassificationController extends AbstractPagingController {
PagedResources<ClassificationSummaryResource> pagedResources = assembler.toResources(classificationSummaries,
pageMetadata);
ResponseEntity<PagedResources<ClassificationSummaryResource>> 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<ClassificationResource> 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<ClassificationResource> 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<ClassificationResource> 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<String, String> params)

View File

@ -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<List<ClassificationResource>> 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<String, String> systemIds = getSystemIds();
List<ClassificationResource> classificationsResources = extractClassificationResourcesFromFile(file);
Map<Classification, String> childsInFile = mapChildsToParentKeys(classificationsResources, systemIds);
Map<Classification, String> 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<String> response = new ResponseEntity<>(HttpStatus.OK);
LOGGER.debug("Exit from importClassifications(), returning {}", response);
return response;
}
private Map<String, String> getSystemIds() {
@ -111,7 +111,7 @@ public class ClassificationDefinitionController {
}
private List<ClassificationResource> extractClassificationResourcesFromFile(MultipartFile file)
throws IOException, JsonParseException, JsonMappingException {
throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<ClassificationResource> classificationsDefinitions = mapper.readValue(file.getInputStream(),
@ -121,9 +121,9 @@ public class ClassificationDefinitionController {
return classificationsDefinitions;
}
private Map<Classification, String> mapChildsToParentKeys(List<ClassificationResource> classificationResources, Map<String, String> systemIds) {
LOGGER.debug("Entry to mapChildsToParentKeys()");
Map<Classification, String> childsInFile = new HashMap<>();
private Map<Classification, String> mapChildrenToParentKeys(List<ClassificationResource> classificationResources, Map<String, String> systemIds) {
LOGGER.debug("Entry to mapChildrenToParentKeys()");
Map<Classification, String> childrenInFile = new HashMap<>();
Set<String> 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<ClassificationResource> classificationResources,
@ -175,20 +175,20 @@ public class ClassificationDefinitionController {
LOGGER.debug("Exit from insertOrUpdateClassificationsWithoutParent()");
}
private void updateParentChildRelations(Map<Classification, String> childsInFile)
private void updateParentChildrenRelations(Map<Classification, String> 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,

View File

@ -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<TaskState> states) throws NotAuthorizedException,
InvalidArgumentException {
LOGGER.debug("Entry to getTasksStatusReport()");
ResponseEntity<ReportResource> 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<TaskState> 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<ReportResource> getTasksClassificationReport()
throws NotAuthorizedException, InvalidArgumentException {
LOGGER.debug("Entry to getTasksClassificationReport()");
ResponseEntity<ReportResource> 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<TimeIntervalColumnHeader> getTaskClassificationTimeInterval() {

View File

@ -126,11 +126,12 @@ public class TaskController extends AbstractPagingController {
TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries,
pageMetadata);
ResponseEntity<PagedResources<TaskSummaryResource>> 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}")

View File

@ -36,21 +36,41 @@ public class TaskanaEngineController {
@GetMapping(path = "/v1/domains", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<String>> getDomains() {
return new ResponseEntity<>(taskanaEngineConfiguration.getDomains(), HttpStatus.OK);
ResponseEntity<List<String>> 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<List<String>> getClassificationCategories(String type) {
LOGGER.debug("Entry to getClassificationCategories(type = {})", type);
ResponseEntity<List<String>> 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<List<String>> getClassificationTypes() {
return new ResponseEntity<>(taskanaEngineConfiguration.getClassificationTypes(), HttpStatus.OK);
ResponseEntity<List<String>> 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<TaskanaUserInfoResource> 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<Boolean> getIsHistoryProviderEnabled() {
return new ResponseEntity<>(((TaskanaEngineImpl) taskanaEngine).getHistoryEventProducer().isEnabled(),
ResponseEntity<Boolean> 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<VersionResource> response = new ResponseEntity<>(resource, HttpStatus.OK);
LOGGER.debug("Exit from currentVersion(), returning {}", response);
return response;
}
}

View File

@ -103,11 +103,12 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
workbasketAccessItems,
pageMetadata);
ResponseEntity<PagedResources<WorkbasketAccessItemResource>> 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<Void> response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
LOGGER.debug("Exit from removeWorkbasketAccessItems(), returning {}", response);
return response;
}
private WorkbasketAccessItemQuery getAccessIds(WorkbasketAccessItemQuery query,

View File

@ -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<WorkbasketSummaryResource> pagedResources = assembler.toResources(workbasketSummaries,
pageMetadata);
ResponseEntity<PagedResources<WorkbasketSummaryResource>> 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<WorkbasketResource> 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<WorkbasketAccessItemResource> accessItemListResource = accessItemListAssembler
.toResource(workbasketId, updatedWbAccessItems);
ResponseEntity<Resources<WorkbasketAccessItemResource>> 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<String> 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<DistributionTargetResource> distributionTargetListResource = distributionTargetListAssembler
.toResource(sourceWorkbasketId, distributionTargets);
ResponseEntity<Resources<DistributionTargetResource>> 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<Resources<DistributionTargetResource>> response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
LOGGER.debug("Exit from removeDistributionTargetForWorkbasketId(), returning {}", response);
return response;
}
private WorkbasketQuery applySortingParams(WorkbasketQuery query, MultiValueMap<String, String> params)

View File

@ -70,12 +70,12 @@ public class WorkbasketDefinitionController {
basketExports.add(workbasketDefinitionAssembler.toResource(workbasket));
}
ResponseEntity<List<WorkbasketDefinitionResource>> 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<String> response = new ResponseEntity<>(HttpStatus.OK);
LOGGER.debug("Exit from importWorkbaskets(), returning {}", response);
return response;
}
private String logicalId(WorkbasketSummary workbasket) {