fixed states filter on TaskController
This commit is contained in:
parent
8278bb1e6e
commit
aa516d933c
|
@ -68,7 +68,8 @@ public interface TaskService {
|
|||
* @return the list of tasks, which reside in the workbasket
|
||||
* @throws NotAuthorizedException
|
||||
*/
|
||||
public List<Task> getTasksForWorkbasket(List<String> workbaskets, List<String> states) throws NotAuthorizedException;
|
||||
public List<Task> getTasksForWorkbasket(List<String> workbaskets, List<TaskState> states)
|
||||
throws NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* This method returns all Tasks
|
||||
|
@ -86,6 +87,14 @@ public interface TaskService {
|
|||
*/
|
||||
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states);
|
||||
|
||||
/**
|
||||
* This method returns all tasks with the specified states
|
||||
*
|
||||
* @param states all List with the needed states
|
||||
* @return a list of Tasks
|
||||
*/
|
||||
public List<Task> findTasks(List<TaskState> states);
|
||||
|
||||
/**
|
||||
* Count all Tasks in a given workbasket with daysInPast as Days from today
|
||||
* in the past and a specific state.
|
||||
|
@ -95,7 +104,8 @@ public interface TaskService {
|
|||
* @param states
|
||||
* @return
|
||||
*/
|
||||
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states);
|
||||
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast,
|
||||
List<TaskState> states);
|
||||
|
||||
/**
|
||||
* Put task into another basket
|
||||
|
@ -107,5 +117,7 @@ public interface TaskService {
|
|||
public Task transfer(String taskId, String workbasketId)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException;
|
||||
|
||||
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast, List<TaskState> states);
|
||||
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
|
||||
List<TaskState> states);
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.taskana.TaskService;
|
||||
import org.taskana.TaskanaEngine;
|
||||
import org.taskana.WorkbasketService;
|
||||
import org.taskana.exceptions.NotAuthorizedException;
|
||||
import org.taskana.exceptions.TaskNotFoundException;
|
||||
import org.taskana.exceptions.WorkbasketNotFoundException;
|
||||
|
@ -19,7 +18,6 @@ import org.taskana.model.DueWorkbasketCounter;
|
|||
import org.taskana.model.Task;
|
||||
import org.taskana.model.TaskState;
|
||||
import org.taskana.model.TaskStateCounter;
|
||||
import org.taskana.model.Workbasket;
|
||||
import org.taskana.model.WorkbasketAuthorization;
|
||||
import org.taskana.model.mappings.TaskMapper;
|
||||
|
||||
|
@ -99,7 +97,12 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getTasksForWorkbasket(List<String> workbasketIds, List<String> states)
|
||||
public List<Task> findTasks(List<TaskState> states) {
|
||||
return taskMapper.findByStates(states);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getTasksForWorkbasket(List<String> workbasketIds, List<TaskState> states)
|
||||
throws NotAuthorizedException {
|
||||
|
||||
for (String workbasket : workbasketIds) {
|
||||
|
@ -133,11 +136,13 @@ public class TaskServiceImpl implements TaskService {
|
|||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Task task = getTaskById(taskId);
|
||||
|
||||
// transfer requires TRANSFER in source and APPEND on destination workbasket
|
||||
// transfer requires TRANSFER in source and APPEND on destination
|
||||
// workbasket
|
||||
taskanaEngine.getWorkbasketService().checkPermission(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
taskanaEngine.getWorkbasketService().checkPermission(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
|
||||
|
||||
// if security is disabled, the implicit existance check on the destination workbasket has been skipped and needs to be performed
|
||||
// if security is disabled, the implicit existance check on the
|
||||
// destination workbasket has been skipped and needs to be performed
|
||||
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
||||
taskanaEngine.getWorkbasketService().getWorkbasket(destinationWorkbasketId);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,31 @@ public interface TaskMapper {
|
|||
@Result(property = "type", column = "TYPE"),
|
||||
@Result(property = "workbasketId", column = "WORKBASKETID"),
|
||||
@Result(property = "owner", column = "OWNER")})
|
||||
List<Task> findByWorkbasketIdsAndStates(@Param("workbasketIds") List<String> workbasketIds, @Param("states") List<String> states);
|
||||
List<Task> findByWorkbasketIdsAndStates(@Param("workbasketIds") List<String> workbasketIds, @Param("states") List<TaskState> states);
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT ID, TENANT_ID, CREATED, CLAIMED, COMPLETED, MODIFIED, PLANNED, DUE, NAME, DESCRIPTION, PRIORITY, STATE, TYPE, WORKBASKETID, OWNER "
|
||||
+ "FROM task "
|
||||
+ "WHERE STATE IN (<foreach item='item' collection='states' separator=',' >#{item}</foreach>) "
|
||||
+ "ORDER BY ID"
|
||||
+ "</script>")
|
||||
@Results(value = {
|
||||
@Result(property = "id", column = "ID"),
|
||||
@Result(property = "tenantId", column = "TENANT_ID"),
|
||||
@Result(property = "created", column = "CREATED"),
|
||||
@Result(property = "claimed", column = "CLAIMED"),
|
||||
@Result(property = "completed", column = "COMPLETED"),
|
||||
@Result(property = "modified", column = "MODIFIED"),
|
||||
@Result(property = "planned", column = "PLANNED"),
|
||||
@Result(property = "due", column = "DUE"),
|
||||
@Result(property = "name", column = "NAME"),
|
||||
@Result(property = "description", column = "DESCRIPTION"),
|
||||
@Result(property = "priority", column = "PRIORITY"),
|
||||
@Result(property = "state", column = "STATE"),
|
||||
@Result(property = "type", column = "TYPE"),
|
||||
@Result(property = "workbasketId", column = "WORKBASKETID"),
|
||||
@Result(property = "owner", column = "OWNER")})
|
||||
List<Task> findByStates(@Param("states") List<TaskState> states);
|
||||
|
||||
@Select("SELECT * FROM TASK")
|
||||
List<Task> findAll();
|
||||
|
@ -92,7 +116,7 @@ public interface TaskMapper {
|
|||
@Select("<script>"
|
||||
+ "SELECT STATE, COUNT (STATE) as counter "
|
||||
+ "FROM TASK "
|
||||
+ "WHERE STATE IN (<foreach collection='status' item='state' separator=','>#{state}</foreach>) "
|
||||
+ "WHERE STATE IN (<foreach collection='status' item='state' separator=','>#{item}</foreach>) "
|
||||
+ "GROUP BY STATE"
|
||||
+ "</script>")
|
||||
@Results({
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.taskana.rest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
@ -16,17 +18,15 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.taskana.TaskService;
|
||||
import org.taskana.TaskanaEngine;
|
||||
import org.taskana.exceptions.NotAuthorizedException;
|
||||
import org.taskana.exceptions.TaskNotFoundException;
|
||||
import org.taskana.model.Task;
|
||||
import org.taskana.model.TaskState;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = "/v1/tasks", produces = { MediaType.APPLICATION_JSON_VALUE })
|
||||
public class TaskController {
|
||||
|
||||
@Autowired
|
||||
TaskanaEngine taskanaEngine;
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
|
@ -34,15 +34,17 @@ public class TaskController {
|
|||
public ResponseEntity<List<Task>> getTasks(@RequestParam MultiValueMap<String, String> params)
|
||||
throws LoginException {
|
||||
try {
|
||||
|
||||
if (params.keySet().size() == 0) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(taskService.getTasks());
|
||||
}
|
||||
if (params.containsKey("workbasketid") && params.containsKey("state")) {
|
||||
System.out.println("HOLGER1");
|
||||
|
||||
if (params.containsKey("workbasketid") && params.containsKey("states")) {
|
||||
List<TaskState> states = extractStates(params);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(taskService.getTasksForWorkbasket(params.get("workbasketid"), params.get("state")));
|
||||
.body(taskService.getTasksForWorkbasket(params.get("workbasketid"), states));
|
||||
}
|
||||
if (params.containsKey("states")) {
|
||||
List<TaskState> states = extractStates(params);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(taskService.findTasks(states));
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(taskService.getTasksForWorkbasket(params.getFirst("workbasketid")));
|
||||
|
@ -51,6 +53,26 @@ public class TaskController {
|
|||
}
|
||||
}
|
||||
|
||||
private List<TaskState> extractStates(MultiValueMap<String, String> params) {
|
||||
List<TaskState> states = new ArrayList<>();
|
||||
params.get("states").stream().forEach(item -> {
|
||||
for (String state : Arrays.asList(item.split(","))) {
|
||||
switch (state) {
|
||||
case "READY":
|
||||
states.add(TaskState.READY);
|
||||
break;
|
||||
case "COMPLETED":
|
||||
states.add(TaskState.COMPLETED);
|
||||
break;
|
||||
case "CLAIMED":
|
||||
states.add(TaskState.CLAIMED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return states;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{taskId}")
|
||||
public ResponseEntity<Task> getTask(@PathVariable(value = "taskId") String taskId) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue