TSK-525: Replace force flags by separate methods
This commit is contained in:
parent
fd564b3053
commit
000a728f4e
|
@ -1,84 +1,84 @@
|
|||
package pro.taskana;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationAlreadyExistException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.DomainNotFoundException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
@Path("/test")
|
||||
public class TaskanaRestTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TaskanaRestTest.class);
|
||||
|
||||
@EJB
|
||||
private TaskanaEjb taskanaEjb;
|
||||
|
||||
@Inject
|
||||
private ClassificationService classificationService;
|
||||
|
||||
@GET
|
||||
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, ClassificationAlreadyExistException, InvalidWorkbasketException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
|
||||
Workbasket workbasket = taskanaEjb.getWorkbasketService().newWorkbasket("key", "cdiDomain");
|
||||
workbasket.setName("wb");
|
||||
workbasket.setType(WorkbasketType.PERSONAL);
|
||||
taskanaEjb.getWorkbasketService().createWorkbasket(workbasket);
|
||||
Classification classification = classificationService.newClassification("TEST", "cdiDomain", "t1");
|
||||
taskanaEjb.getClassificationService().createClassification(classification);
|
||||
|
||||
Task task = taskanaEjb.getTaskService().newTask(workbasket.getKey());
|
||||
task.setClassificationKey(classification.getKey());
|
||||
ObjectReference objRef = new ObjectReference();
|
||||
objRef.setCompany("aCompany");
|
||||
objRef.setSystem("aSystem");
|
||||
objRef.setSystemInstance("anInstance");
|
||||
objRef.setType("aType");
|
||||
objRef.setValue("aValue");
|
||||
task.setPrimaryObjRef(objRef);
|
||||
|
||||
Task result = taskanaEjb.getTaskService().createTask(task);
|
||||
|
||||
logger.info(result.getId() + ":" + result.getOwner());
|
||||
return Response.status(200).entity(result.getId()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response rollbackTask()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||
InvalidWorkbasketException, TaskAlreadyExistException, InvalidArgumentException {
|
||||
taskanaEjb.triggerRollback();
|
||||
return Response.status(204).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
public void completeTask(@PathParam("id") String id)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, ClassificationNotFoundException,
|
||||
NotAuthorizedException {
|
||||
logger.info(id);
|
||||
taskanaEjb.getTaskService().completeTask(id, true);
|
||||
}
|
||||
|
||||
}
|
||||
package pro.taskana;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationAlreadyExistException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.DomainNotFoundException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
@Path("/test")
|
||||
public class TaskanaRestTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TaskanaRestTest.class);
|
||||
|
||||
@EJB
|
||||
private TaskanaEjb taskanaEjb;
|
||||
|
||||
@Inject
|
||||
private ClassificationService classificationService;
|
||||
|
||||
@GET
|
||||
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, ClassificationAlreadyExistException, InvalidWorkbasketException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
|
||||
Workbasket workbasket = taskanaEjb.getWorkbasketService().newWorkbasket("key", "cdiDomain");
|
||||
workbasket.setName("wb");
|
||||
workbasket.setType(WorkbasketType.PERSONAL);
|
||||
taskanaEjb.getWorkbasketService().createWorkbasket(workbasket);
|
||||
Classification classification = classificationService.newClassification("TEST", "cdiDomain", "t1");
|
||||
taskanaEjb.getClassificationService().createClassification(classification);
|
||||
|
||||
Task task = taskanaEjb.getTaskService().newTask(workbasket.getKey());
|
||||
task.setClassificationKey(classification.getKey());
|
||||
ObjectReference objRef = new ObjectReference();
|
||||
objRef.setCompany("aCompany");
|
||||
objRef.setSystem("aSystem");
|
||||
objRef.setSystemInstance("anInstance");
|
||||
objRef.setType("aType");
|
||||
objRef.setValue("aValue");
|
||||
task.setPrimaryObjRef(objRef);
|
||||
|
||||
Task result = taskanaEjb.getTaskService().createTask(task);
|
||||
|
||||
logger.info(result.getId() + ":" + result.getOwner());
|
||||
return Response.status(200).entity(result.getId()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response rollbackTask()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||
InvalidWorkbasketException, TaskAlreadyExistException, InvalidArgumentException {
|
||||
taskanaEjb.triggerRollback();
|
||||
return Response.status(204).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
public void completeTask(@PathParam("id") String id)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, ClassificationNotFoundException,
|
||||
NotAuthorizedException {
|
||||
logger.info(id);
|
||||
taskanaEjb.getTaskService().forceCompleteTask(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,411 +1,401 @@
|
|||
package pro.taskana;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.TaskanaException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.BulkOperationResults;
|
||||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
/**
|
||||
* The Task Service manages all operations on tasks.
|
||||
*/
|
||||
public interface TaskService {
|
||||
|
||||
/**
|
||||
* Claim an existing task for the current user.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task to be claimed
|
||||
* @return claimed Task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task with taskId was not found
|
||||
* @throws InvalidStateException
|
||||
* if the state of the task with taskId is not READY
|
||||
* @throws InvalidOwnerException
|
||||
* if the task with taskId is claimed by some else
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task claim(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Claim an existing task for the current user. Enable forced claim.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task to be claimed
|
||||
* @param forceClaim
|
||||
* if true, claim is performed even if the task is already claimed by someone else
|
||||
* @return claimed Task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task with taskId was not found
|
||||
* @throws InvalidStateException
|
||||
* if the state of the task with taskId is not READY
|
||||
* @throws InvalidOwnerException
|
||||
* if the task with taskId is claimed by someone else
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task claim(String taskId, boolean forceClaim)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Unclaim a existing Task which was claimed and owned by you before.
|
||||
*
|
||||
* @param taskId
|
||||
* id of the task which should be unclaimed.
|
||||
* @return updated unclaimed task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task can´t be found or does not exist
|
||||
* @throws InvalidStateException
|
||||
* when the task is already completed.
|
||||
* @throws InvalidOwnerException
|
||||
* when the task is claimed by another user.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task cancelClaim(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Unclaim a existing Task which was claimed and owned by you before. Also there can be enabled a force flag for
|
||||
* admins.
|
||||
*
|
||||
* @param taskId
|
||||
* id of the task which should be unclaimed.
|
||||
* @param forceCancel
|
||||
* force the cancellation of claim. If true, the task is unclaimed even if it was claimed by another
|
||||
* user.
|
||||
* @return updated unclaimed task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task can´t be found or does not exist
|
||||
* @throws InvalidStateException
|
||||
* when the task is already completed.
|
||||
* @throws InvalidOwnerException
|
||||
* when forceCancel is false and the task is claimed by another user.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task cancelClaim(String taskId, boolean forceCancel)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Complete a claimed Task as owner/admin and update State and Timestamps.
|
||||
*
|
||||
* @param taskId
|
||||
* - Id of the Task which should be completed.
|
||||
* @return Task - updated task after completion.
|
||||
* @throws InvalidStateException
|
||||
* when Task wasn´t claimed before.
|
||||
* @throws TaskNotFoundException
|
||||
* if the given Task can´t be found in DB.
|
||||
* @throws InvalidOwnerException
|
||||
* if current user is not the task-owner or administrator.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task completeTask(String taskId)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Complete a claimed Task and update State and Timestamps.
|
||||
*
|
||||
* @param taskId
|
||||
* - Id of the Task which should be completed.
|
||||
* @param isForced
|
||||
* - Flag which can complete a Task in every case if Task does exist.
|
||||
* @return Task - updated task after completion.
|
||||
* @throws InvalidStateException
|
||||
* when Task wasn´t claimed before.
|
||||
* @throws TaskNotFoundException
|
||||
* if the given Task can´t be found in DB.
|
||||
* @throws InvalidOwnerException
|
||||
* if current user is not the task-owner or administrator.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task completeTask(String taskId, boolean isForced)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Persists a not persisted Task which does not exist already.
|
||||
*
|
||||
* @param taskToCreate
|
||||
* the transient task object to be persisted
|
||||
* @return the created and persisted task
|
||||
* @throws TaskAlreadyExistException
|
||||
* when the Task does already exist.
|
||||
* @throws NotAuthorizedException
|
||||
* thrown if the current user is not authorized to create that task
|
||||
* @throws WorkbasketNotFoundException
|
||||
* thrown if the work basket referenced by the task is not found
|
||||
* @throws ClassificationNotFoundException
|
||||
* thrown if the {@link Classification} referenced by the task is not found
|
||||
* @throws InvalidArgumentException
|
||||
* thrown if the primary ObjectReference is invalid
|
||||
*/
|
||||
Task createTask(Task taskToCreate)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||
TaskAlreadyExistException, InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Get the details of a task by Id without checking permissions.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task
|
||||
* @return the Task
|
||||
* @throws TaskNotFoundException
|
||||
* thrown of the {@link Task} with taskId is not found
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no READ permission for the workbasket the task is in.
|
||||
*/
|
||||
Task getTask(String taskId) throws TaskNotFoundException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag.
|
||||
*
|
||||
* @param taskId
|
||||
* The id of the {@link Task} to be transferred
|
||||
* @param destinationWorkbasketId
|
||||
* The Id of the target work basket
|
||||
* @return the transferred task
|
||||
* @throws TaskNotFoundException
|
||||
* Thrown if the {@link Task} with taskId was not found.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* Thrown if the target work basket was not found.
|
||||
* @throws NotAuthorizedException
|
||||
* Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket
|
||||
* @throws InvalidWorkbasketException
|
||||
* Thrown if either the source or the target workbasket has a missing required property
|
||||
* @throws InvalidStateException
|
||||
* Thrown if the task is in a state which does not allow transferring
|
||||
*/
|
||||
Task transfer(String taskId, String destinationWorkbasketId)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
|
||||
InvalidStateException;
|
||||
|
||||
/**
|
||||
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag.
|
||||
*
|
||||
* @param taskId
|
||||
* The id of the {@link Task} to be transferred
|
||||
* @param workbasketKey
|
||||
* The key of the target work basket
|
||||
* @param domain
|
||||
* The domain of the target work basket
|
||||
* @return the transferred task
|
||||
* @throws TaskNotFoundException
|
||||
* Thrown if the {@link Task} with taskId was not found.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* Thrown if the target work basket was not found.
|
||||
* @throws NotAuthorizedException
|
||||
* Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket
|
||||
* @throws InvalidWorkbasketException
|
||||
* Thrown if either the source or the target workbasket has a missing required property
|
||||
* @throws InvalidStateException
|
||||
* Thrown if the task is in a state which does not allow transferring
|
||||
*/
|
||||
Task transfer(String taskId, String workbasketKey, String domain)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
|
||||
InvalidStateException;
|
||||
|
||||
/**
|
||||
* Marks a task as read.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task to be updated
|
||||
* @param isRead
|
||||
* the new status of the read flag.
|
||||
* @return the updated Task
|
||||
* @throws TaskNotFoundException
|
||||
* Thrown if the {@link Task} with taskId was not found
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* This method provides a query builder for quering the database.
|
||||
*
|
||||
* @return a {@link TaskQuery}
|
||||
*/
|
||||
TaskQuery createTaskQuery();
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Task}.
|
||||
*
|
||||
* @param workbasketId
|
||||
* the id of the workbasket to which the task belongs
|
||||
* @return an empty new Task
|
||||
*/
|
||||
Task newTask(String workbasketId);
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Task}.
|
||||
*
|
||||
* @param workbasketKey
|
||||
* the key of the workbasket to which the task belongs
|
||||
* @param domain
|
||||
* the domain of the workbasket to which the task belongs
|
||||
* @return an empty new Task
|
||||
*/
|
||||
Task newTask(String workbasketKey, String domain);
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Attachment}.
|
||||
*
|
||||
* @return an empty new Attachment
|
||||
*/
|
||||
Attachment newAttachment();
|
||||
|
||||
/**
|
||||
* Update a task.
|
||||
*
|
||||
* @param task
|
||||
* the task to be updated in the database
|
||||
* @return the updated task
|
||||
* @throws InvalidArgumentException
|
||||
* if the task to be updated contains invalid properties like e.g. invalid object references
|
||||
* @throws TaskNotFoundException
|
||||
* if the id of the task is not found in the database
|
||||
* @throws ConcurrencyException
|
||||
* if the task has already been updated by another user
|
||||
* @throws InvalidWorkbasketException
|
||||
* if the updated task refers to a workbasket that has missing required properties
|
||||
* @throws ClassificationNotFoundException
|
||||
* if the updated task refers to a classification that cannot be found
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the updated task refers to a work basket that cannot be found
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user is not authorized to update the task
|
||||
* @throws AttachmentPersistenceException
|
||||
* if an Attachment with ID will be added multiple times without using the task-methods.
|
||||
*/
|
||||
Task updateTask(Task task) throws InvalidArgumentException, TaskNotFoundException, ConcurrencyException,
|
||||
WorkbasketNotFoundException, ClassificationNotFoundException, InvalidWorkbasketException,
|
||||
NotAuthorizedException, AttachmentPersistenceException;
|
||||
|
||||
/**
|
||||
* Transfers a list of tasks to an other workbasket. Exceptions will be thrown if the caller got no permissions on
|
||||
* the target or it doesn´t exist. Other Exceptions will be stored and returned in the end.
|
||||
*
|
||||
* @param destinationWorkbasketId
|
||||
* target workbasket id
|
||||
* @param taskIds
|
||||
* source task which will be moved
|
||||
* @return Bulkresult with ID and Error in it for failed transactions.
|
||||
* @throws NotAuthorizedException
|
||||
* if the caller hasn´t permissions on tarket WB.
|
||||
* @throws InvalidArgumentException
|
||||
* if the method paramesters are EMPTY or NULL.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the target WB can´t be found.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> transferTasks(String destinationWorkbasketId, List<String> taskIds)
|
||||
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Transfers a list of tasks to an other workbasket. Exceptions will be thrown if the caller got no permissions on
|
||||
* the target or it doesn´t exist. Other Exceptions will be stored and returned in the end.
|
||||
*
|
||||
* @param destinationWorkbasketKey
|
||||
* target workbasket key
|
||||
* @param destinationWorkbasketDomain
|
||||
* target workbasket domain
|
||||
* @param taskIds
|
||||
* source task which will be moved
|
||||
* @return Bulkresult with ID and Error in it for failed transactions.
|
||||
* @throws NotAuthorizedException
|
||||
* if the caller hasn´t permissions on tarket WB.
|
||||
* @throws InvalidArgumentException
|
||||
* if the method paramesters are EMPTY or NULL.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the target WB can´t be found.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> transferTasks(String destinationWorkbasketKey,
|
||||
String destinationWorkbasketDomain, List<String> taskIds)
|
||||
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Deletes the task with the given Id.
|
||||
*
|
||||
* @param taskId
|
||||
* The Id of the task to delete.
|
||||
* @throws TaskNotFoundException
|
||||
* If the given Id does not refer to an existing task.
|
||||
* @throws InvalidStateException
|
||||
* If the state of the referenced task is not Completed.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user is not member of role ADMIN
|
||||
*/
|
||||
void deleteTask(String taskId) throws TaskNotFoundException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Deletes the task with the given Id.
|
||||
*
|
||||
* @param taskId
|
||||
* The Id of the task to delete.
|
||||
* @param forceDelete
|
||||
* force the deletion. If true, a task is deleted even if it is not in state completed.
|
||||
* @throws TaskNotFoundException
|
||||
* If the given Id does not refer to an existing task.
|
||||
* @throws InvalidStateException
|
||||
* If the state of the referenced task is not Completed and forceDelet is false.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user is not member of role ADMIN
|
||||
*/
|
||||
void deleteTask(String taskId, boolean forceDelete)
|
||||
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Deletes a list of tasks.
|
||||
*
|
||||
* @param tasks
|
||||
* the ids of the tasks to delete.
|
||||
* @return the result of the operations with Id and Exception for each failed task deletion.
|
||||
* @throws InvalidArgumentException
|
||||
* if the TaskIds parameter is NULL
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> deleteTasks(List<String> tasks) throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Completes a list of tasks.
|
||||
*
|
||||
* @param taskIds
|
||||
* of the tasks which should be completed.
|
||||
* @return the result of the operations with Id and Exception for each failed task completion.
|
||||
* @throws InvalidArgumentException
|
||||
* If the taskId parameter is NULL.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds)
|
||||
throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Completes tasks with a matching {@link ObjectReference}.
|
||||
*
|
||||
* @param selectionCriteria
|
||||
* the {@link ObjectReference} that is used to select the tasks.
|
||||
* @param customFieldsToUpdate
|
||||
* a {@link Map} that contains as key the identification of the custom field and as value the
|
||||
* corresponding new value of that custom field. The key for identification of the custom field must be a
|
||||
* String with value "1", "2" ... "16" as in the setCustomAttribute or getCustomAttribute method of
|
||||
* {@link Task}
|
||||
* @return a list of the Ids of all modified tasks
|
||||
* @throws InvalidArgumentException
|
||||
* If the customFieldsToUpdate map contains an invalid key or if the selectionCriteria is invalid
|
||||
*/
|
||||
List<String> updateTasks(ObjectReference selectionCriteria,
|
||||
Map<String, String> customFieldsToUpdate) throws InvalidArgumentException;
|
||||
}
|
||||
package pro.taskana;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.TaskanaException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.BulkOperationResults;
|
||||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
/**
|
||||
* The Task Service manages all operations on tasks.
|
||||
*/
|
||||
public interface TaskService {
|
||||
|
||||
/**
|
||||
* Claim an existing task for the current user.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task to be claimed
|
||||
* @return claimed Task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task with taskId was not found
|
||||
* @throws InvalidStateException
|
||||
* if the state of the task with taskId is not READY
|
||||
* @throws InvalidOwnerException
|
||||
* if the task with taskId is claimed by some else
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task claim(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Claim an existing task for the current user even if it is already claimed by someone else.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task to be claimed
|
||||
* @return claimed Task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task with taskId was not found
|
||||
* @throws InvalidStateException
|
||||
* if the state of the task with taskId is not READY
|
||||
* @throws InvalidOwnerException
|
||||
* if the task with taskId is claimed by someone else
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task forceClaim(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Cancel the claim of an existing task if it was claimed by the current user before.
|
||||
*
|
||||
* @param taskId
|
||||
* id of the task which should be unclaimed.
|
||||
* @return updated unclaimed task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task can´t be found or does not exist
|
||||
* @throws InvalidStateException
|
||||
* when the task is already completed.
|
||||
* @throws InvalidOwnerException
|
||||
* when the task is claimed by another user.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task cancelClaim(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Cancel the claim of an existing task even if it was claimed by another user.
|
||||
*
|
||||
* @param taskId
|
||||
* id of the task which should be unclaimed.
|
||||
* @return updated unclaimed task
|
||||
* @throws TaskNotFoundException
|
||||
* if the task can´t be found or does not exist
|
||||
* @throws InvalidStateException
|
||||
* when the task is already completed.
|
||||
* @throws InvalidOwnerException
|
||||
* when forceCancel is false and the task is claimed by another user.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task forceCancelClaim(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Complete a claimed Task as owner/admin and update State and Timestamps.
|
||||
*
|
||||
* @param taskId
|
||||
* - Id of the Task which should be completed.
|
||||
* @return Task - updated task after completion.
|
||||
* @throws InvalidStateException
|
||||
* when Task wasn´t claimed before.
|
||||
* @throws TaskNotFoundException
|
||||
* if the given Task can´t be found in DB.
|
||||
* @throws InvalidOwnerException
|
||||
* if current user is not the task-owner or administrator.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task completeTask(String taskId)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Complete a Task and update State and Timestamps in every case if the Task exists.
|
||||
*
|
||||
* @param taskId
|
||||
* - Id of the Task which should be completed.
|
||||
* @return Task - updated task after completion.
|
||||
* @throws InvalidStateException
|
||||
* when Task wasn´t claimed before.
|
||||
* @throws TaskNotFoundException
|
||||
* if the given Task can´t be found in DB.
|
||||
* @throws InvalidOwnerException
|
||||
* if current user is not the task-owner or administrator.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task forceCompleteTask(String taskId)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Persists a not persisted Task which does not exist already.
|
||||
*
|
||||
* @param taskToCreate
|
||||
* the transient task object to be persisted
|
||||
* @return the created and persisted task
|
||||
* @throws TaskAlreadyExistException
|
||||
* when the Task does already exist.
|
||||
* @throws NotAuthorizedException
|
||||
* thrown if the current user is not authorized to create that task
|
||||
* @throws WorkbasketNotFoundException
|
||||
* thrown if the work basket referenced by the task is not found
|
||||
* @throws ClassificationNotFoundException
|
||||
* thrown if the {@link Classification} referenced by the task is not found
|
||||
* @throws InvalidArgumentException
|
||||
* thrown if the primary ObjectReference is invalid
|
||||
*/
|
||||
Task createTask(Task taskToCreate)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||
TaskAlreadyExistException, InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Get the details of a task by Id without checking permissions.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task
|
||||
* @return the Task
|
||||
* @throws TaskNotFoundException
|
||||
* thrown of the {@link Task} with taskId is not found
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no READ permission for the workbasket the task is in.
|
||||
*/
|
||||
Task getTask(String taskId) throws TaskNotFoundException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag.
|
||||
*
|
||||
* @param taskId
|
||||
* The id of the {@link Task} to be transferred
|
||||
* @param destinationWorkbasketId
|
||||
* The Id of the target work basket
|
||||
* @return the transferred task
|
||||
* @throws TaskNotFoundException
|
||||
* Thrown if the {@link Task} with taskId was not found.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* Thrown if the target work basket was not found.
|
||||
* @throws NotAuthorizedException
|
||||
* Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket
|
||||
* @throws InvalidWorkbasketException
|
||||
* Thrown if either the source or the target workbasket has a missing required property
|
||||
* @throws InvalidStateException
|
||||
* Thrown if the task is in a state which does not allow transferring
|
||||
*/
|
||||
Task transfer(String taskId, String destinationWorkbasketId)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
|
||||
InvalidStateException;
|
||||
|
||||
/**
|
||||
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag.
|
||||
*
|
||||
* @param taskId
|
||||
* The id of the {@link Task} to be transferred
|
||||
* @param workbasketKey
|
||||
* The key of the target work basket
|
||||
* @param domain
|
||||
* The domain of the target work basket
|
||||
* @return the transferred task
|
||||
* @throws TaskNotFoundException
|
||||
* Thrown if the {@link Task} with taskId was not found.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* Thrown if the target work basket was not found.
|
||||
* @throws NotAuthorizedException
|
||||
* Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket
|
||||
* @throws InvalidWorkbasketException
|
||||
* Thrown if either the source or the target workbasket has a missing required property
|
||||
* @throws InvalidStateException
|
||||
* Thrown if the task is in a state which does not allow transferring
|
||||
*/
|
||||
Task transfer(String taskId, String workbasketKey, String domain)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
|
||||
InvalidStateException;
|
||||
|
||||
/**
|
||||
* Marks a task as read.
|
||||
*
|
||||
* @param taskId
|
||||
* the id of the task to be updated
|
||||
* @param isRead
|
||||
* the new status of the read flag.
|
||||
* @return the updated Task
|
||||
* @throws TaskNotFoundException
|
||||
* Thrown if the {@link Task} with taskId was not found
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the workbasket the task is in
|
||||
*/
|
||||
Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* This method provides a query builder for quering the database.
|
||||
*
|
||||
* @return a {@link TaskQuery}
|
||||
*/
|
||||
TaskQuery createTaskQuery();
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Task}.
|
||||
*
|
||||
* @param workbasketId
|
||||
* the id of the workbasket to which the task belongs
|
||||
* @return an empty new Task
|
||||
*/
|
||||
Task newTask(String workbasketId);
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Task}.
|
||||
*
|
||||
* @param workbasketKey
|
||||
* the key of the workbasket to which the task belongs
|
||||
* @param domain
|
||||
* the domain of the workbasket to which the task belongs
|
||||
* @return an empty new Task
|
||||
*/
|
||||
Task newTask(String workbasketKey, String domain);
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Attachment}.
|
||||
*
|
||||
* @return an empty new Attachment
|
||||
*/
|
||||
Attachment newAttachment();
|
||||
|
||||
/**
|
||||
* Update a task.
|
||||
*
|
||||
* @param task
|
||||
* the task to be updated in the database
|
||||
* @return the updated task
|
||||
* @throws InvalidArgumentException
|
||||
* if the task to be updated contains invalid properties like e.g. invalid object references
|
||||
* @throws TaskNotFoundException
|
||||
* if the id of the task is not found in the database
|
||||
* @throws ConcurrencyException
|
||||
* if the task has already been updated by another user
|
||||
* @throws InvalidWorkbasketException
|
||||
* if the updated task refers to a workbasket that has missing required properties
|
||||
* @throws ClassificationNotFoundException
|
||||
* if the updated task refers to a classification that cannot be found
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the updated task refers to a work basket that cannot be found
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user is not authorized to update the task
|
||||
* @throws AttachmentPersistenceException
|
||||
* if an Attachment with ID will be added multiple times without using the task-methods.
|
||||
*/
|
||||
Task updateTask(Task task) throws InvalidArgumentException, TaskNotFoundException, ConcurrencyException,
|
||||
WorkbasketNotFoundException, ClassificationNotFoundException, InvalidWorkbasketException,
|
||||
NotAuthorizedException, AttachmentPersistenceException;
|
||||
|
||||
/**
|
||||
* Transfers a list of tasks to an other workbasket. Exceptions will be thrown if the caller got no permissions on
|
||||
* the target or it doesn´t exist. Other Exceptions will be stored and returned in the end.
|
||||
*
|
||||
* @param destinationWorkbasketId
|
||||
* target workbasket id
|
||||
* @param taskIds
|
||||
* source task which will be moved
|
||||
* @return Bulkresult with ID and Error in it for failed transactions.
|
||||
* @throws NotAuthorizedException
|
||||
* if the caller hasn´t permissions on tarket WB.
|
||||
* @throws InvalidArgumentException
|
||||
* if the method paramesters are EMPTY or NULL.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the target WB can´t be found.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> transferTasks(String destinationWorkbasketId, List<String> taskIds)
|
||||
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Transfers a list of tasks to an other workbasket. Exceptions will be thrown if the caller got no permissions on
|
||||
* the target or it doesn´t exist. Other Exceptions will be stored and returned in the end.
|
||||
*
|
||||
* @param destinationWorkbasketKey
|
||||
* target workbasket key
|
||||
* @param destinationWorkbasketDomain
|
||||
* target workbasket domain
|
||||
* @param taskIds
|
||||
* source task which will be moved
|
||||
* @return Bulkresult with ID and Error in it for failed transactions.
|
||||
* @throws NotAuthorizedException
|
||||
* if the caller hasn´t permissions on tarket WB.
|
||||
* @throws InvalidArgumentException
|
||||
* if the method paramesters are EMPTY or NULL.
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the target WB can´t be found.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> transferTasks(String destinationWorkbasketKey,
|
||||
String destinationWorkbasketDomain, List<String> taskIds)
|
||||
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Deletes the task with the given Id.
|
||||
*
|
||||
* @param taskId
|
||||
* The Id of the task to delete.
|
||||
* @throws TaskNotFoundException
|
||||
* If the given Id does not refer to an existing task.
|
||||
* @throws InvalidStateException
|
||||
* If the state of the referenced task is not Completed.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user is not member of role ADMIN
|
||||
*/
|
||||
void deleteTask(String taskId) throws TaskNotFoundException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Deletes the task with the given Id even if it is not completed.
|
||||
*
|
||||
* @param taskId
|
||||
* The Id of the task to delete.
|
||||
* @throws TaskNotFoundException
|
||||
* If the given Id does not refer to an existing task.
|
||||
* @throws InvalidStateException
|
||||
* If the state of the referenced task is not Completed and forceDelet is false.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user is not member of role ADMIN
|
||||
*/
|
||||
void forceDeleteTask(String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Deletes a list of tasks.
|
||||
*
|
||||
* @param tasks
|
||||
* the ids of the tasks to delete.
|
||||
* @return the result of the operations with Id and Exception for each failed task deletion.
|
||||
* @throws InvalidArgumentException
|
||||
* if the TaskIds parameter is NULL
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> deleteTasks(List<String> tasks) throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Completes a list of tasks.
|
||||
*
|
||||
* @param taskIds
|
||||
* of the tasks which should be completed.
|
||||
* @return the result of the operations with Id and Exception for each failed task completion.
|
||||
* @throws InvalidArgumentException
|
||||
* If the taskId parameter is NULL.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds)
|
||||
throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Completes tasks with a matching {@link ObjectReference}.
|
||||
*
|
||||
* @param selectionCriteria
|
||||
* the {@link ObjectReference} that is used to select the tasks.
|
||||
* @param customFieldsToUpdate
|
||||
* a {@link Map} that contains as key the identification of the custom field and as value the
|
||||
* corresponding new value of that custom field. The key for identification of the custom field must be a
|
||||
* String with value "1", "2" ... "16" as in the setCustomAttribute or getCustomAttribute method of
|
||||
* {@link Task}
|
||||
* @return a list of the Ids of all modified tasks
|
||||
* @throws InvalidArgumentException
|
||||
* If the customFieldsToUpdate map contains an invalid key or if the selectionCriteria is invalid
|
||||
*/
|
||||
List<String> updateTasks(ObjectReference selectionCriteria,
|
||||
Map<String, String> customFieldsToUpdate) throws InvalidArgumentException;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,137 +1,137 @@
|
|||
package acceptance.task;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.TaskanaException;
|
||||
import pro.taskana.impl.BulkOperationResults;
|
||||
import pro.taskana.security.JAASRunner;
|
||||
import pro.taskana.security.WithAccessId;
|
||||
|
||||
/**
|
||||
* Acceptance test for all "delete task" scenarios.
|
||||
*/
|
||||
@RunWith(JAASRunner.class)
|
||||
public class DeleteTaskAccTest extends AbstractAccTest {
|
||||
|
||||
public DeleteTaskAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void testDeleteSingleTaskNotAuthorized()
|
||||
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
taskService.deleteTask("TKI:000000000000000000000000000000000037");
|
||||
fail("NotAuthorizedException should have been thrown");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1", "admin"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testDeleteSingleTask() throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000036");
|
||||
|
||||
taskService.deleteTask(task.getId());
|
||||
|
||||
taskService.getTask("TKI:000000000000000000000000000000000036");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1", "admin"})
|
||||
@Test(expected = InvalidStateException.class)
|
||||
public void testThrowsExceptionIfTaskIsNotCompleted()
|
||||
throws TaskNotFoundException, InvalidStateException, SQLException, NotAuthorizedException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||
|
||||
taskService.deleteTask(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1", "admin"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testForceDeleteTaskIfNotCompleted()
|
||||
throws SQLException, TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||
try {
|
||||
taskService.deleteTask(task.getId());
|
||||
fail("Should not be possible to delete claimed task without force flag");
|
||||
} catch (InvalidStateException ex) {
|
||||
taskService.deleteTask(task.getId(), true);
|
||||
}
|
||||
|
||||
taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testBulkDeleteTask() throws TaskNotFoundException, InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ArrayList<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000037");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000038");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
assertFalse(results.containsErrors());
|
||||
taskService.getTask("TKI:000000000000000000000000000000000038");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testBulkDeleteTasksWithException()
|
||||
throws TaskNotFoundException, InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ArrayList<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000039");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000040");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000028");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
String expectedFailedId = "TKI:000000000000000000000000000000000028";
|
||||
assertTrue(results.containsErrors());
|
||||
List<String> failedTaskIds = results.getFailedIds();
|
||||
assertTrue(failedTaskIds.size() == 1);
|
||||
assertTrue(expectedFailedId.equals(failedTaskIds.get(0)));
|
||||
assertTrue(results.getErrorMap().get(expectedFailedId).getClass() == InvalidStateException.class);
|
||||
|
||||
Task notDeletedTask = taskService.getTask("TKI:000000000000000000000000000000000028");
|
||||
assertTrue(notDeletedTask != null);
|
||||
taskService.getTask("TKI:000000000000000000000000000000000040");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package acceptance.task;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.TaskanaException;
|
||||
import pro.taskana.impl.BulkOperationResults;
|
||||
import pro.taskana.security.JAASRunner;
|
||||
import pro.taskana.security.WithAccessId;
|
||||
|
||||
/**
|
||||
* Acceptance test for all "delete task" scenarios.
|
||||
*/
|
||||
@RunWith(JAASRunner.class)
|
||||
public class DeleteTaskAccTest extends AbstractAccTest {
|
||||
|
||||
public DeleteTaskAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void testDeleteSingleTaskNotAuthorized()
|
||||
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
taskService.deleteTask("TKI:000000000000000000000000000000000037");
|
||||
fail("NotAuthorizedException should have been thrown");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1", "admin"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testDeleteSingleTask() throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000036");
|
||||
|
||||
taskService.deleteTask(task.getId());
|
||||
|
||||
taskService.getTask("TKI:000000000000000000000000000000000036");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1", "admin"})
|
||||
@Test(expected = InvalidStateException.class)
|
||||
public void testThrowsExceptionIfTaskIsNotCompleted()
|
||||
throws TaskNotFoundException, InvalidStateException, SQLException, NotAuthorizedException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||
|
||||
taskService.deleteTask(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1", "admin"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testForceDeleteTaskIfNotCompleted()
|
||||
throws SQLException, TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||
try {
|
||||
taskService.deleteTask(task.getId());
|
||||
fail("Should not be possible to delete claimed task without force flag");
|
||||
} catch (InvalidStateException ex) {
|
||||
taskService.forceDeleteTask(task.getId());
|
||||
}
|
||||
|
||||
taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testBulkDeleteTask() throws TaskNotFoundException, InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ArrayList<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000037");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000038");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
assertFalse(results.containsErrors());
|
||||
taskService.getTask("TKI:000000000000000000000000000000000038");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testBulkDeleteTasksWithException()
|
||||
throws TaskNotFoundException, InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ArrayList<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000039");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000040");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000028");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
String expectedFailedId = "TKI:000000000000000000000000000000000028";
|
||||
assertTrue(results.containsErrors());
|
||||
List<String> failedTaskIds = results.getFailedIds();
|
||||
assertTrue(failedTaskIds.size() == 1);
|
||||
assertTrue(expectedFailedId.equals(failedTaskIds.get(0)));
|
||||
assertTrue(results.getErrorMap().get(expectedFailedId).getClass() == InvalidStateException.class);
|
||||
|
||||
Task notDeletedTask = taskService.getTask("TKI:000000000000000000000000000000000028");
|
||||
assertTrue(notDeletedTask != null);
|
||||
taskService.getTask("TKI:000000000000000000000000000000000040");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,302 +1,302 @@
|
|||
package acceptance.task;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskState;
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.TaskanaException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.BulkOperationResults;
|
||||
import pro.taskana.security.JAASRunner;
|
||||
import pro.taskana.security.WithAccessId;
|
||||
|
||||
/**
|
||||
* Acceptance test for all "work on task" scenarios. This includes claim, complete...
|
||||
*/
|
||||
@RunWith(JAASRunner.class)
|
||||
public class WorkOnTaskAccTest extends AbstractAccTest {
|
||||
|
||||
public WorkOnTaskAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testClaimTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000025");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000025");
|
||||
assertNotNull(claimedTask);
|
||||
assertEquals(TaskState.CLAIMED, claimedTask.getState());
|
||||
assertNotNull(claimedTask.getClaimed());
|
||||
assertNotEquals(claimedTask.getCreated(), claimedTask.getModified());
|
||||
assertEquals(claimedTask.getClaimed(), claimedTask.getModified());
|
||||
assertTrue(claimedTask.isRead());
|
||||
assertEquals("user_1_2", claimedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testThrowsExceptionIfTaskIsAlreadyClaimed()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000026");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testClaimAlreadyClaimedByCallerTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testForceClaimTaskWhichIsAlreadyClaimedByAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000028");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testCancelClaimTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||
|
||||
taskService.cancelClaim(claimedTask.getId());
|
||||
|
||||
Task unclaimedTask = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||
assertNotNull(unclaimedTask);
|
||||
assertEquals(TaskState.READY, unclaimedTask.getState());
|
||||
assertNull(unclaimedTask.getClaimed());
|
||||
assertTrue(unclaimedTask.isRead());
|
||||
assertNull(unclaimedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testThrowsExceptionIfCancelClaimOfTaskFromAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000030");
|
||||
|
||||
taskService.cancelClaim(claimedTask.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testForceCancelClaimOfTaskFromAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000031");
|
||||
|
||||
taskService.cancelClaim(claimedTask.getId(), true);
|
||||
|
||||
Task unclaimedTask = taskService.getTask("TKI:000000000000000000000000000000000031");
|
||||
assertNotNull(unclaimedTask);
|
||||
assertEquals(TaskState.READY, unclaimedTask.getState());
|
||||
assertNull(unclaimedTask.getClaimed());
|
||||
assertTrue(unclaimedTask.isRead());
|
||||
assertNull(unclaimedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testCompleteTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
Instant before = Instant.now().minus(Duration.ofSeconds(3L));
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000032");
|
||||
|
||||
taskService.completeTask(claimedTask.getId());
|
||||
|
||||
Task completedTask = taskService.getTask("TKI:000000000000000000000000000000000032");
|
||||
assertNotNull(completedTask);
|
||||
assertEquals(TaskState.COMPLETED, completedTask.getState());
|
||||
assertNotNull(completedTask.getCompleted());
|
||||
assertEquals(completedTask.getCompleted(), completedTask.getModified());
|
||||
assertTrue(completedTask.getCompleted().isAfter(before));
|
||||
assertTrue(completedTask.getModified().isAfter(before));
|
||||
assertTrue(completedTask.isRead());
|
||||
assertEquals("user_1_2", completedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testForceCompleteUnclaimedTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000033");
|
||||
|
||||
taskService.completeTask(claimedTask.getId(), true);
|
||||
|
||||
Task completedTask = taskService.getTask("TKI:000000000000000000000000000000000033");
|
||||
assertNotNull(completedTask);
|
||||
assertEquals(TaskState.COMPLETED, completedTask.getState());
|
||||
assertNotNull(completedTask.getCompleted());
|
||||
assertEquals(completedTask.getCompleted(), completedTask.getModified());
|
||||
assertTrue(completedTask.isRead());
|
||||
assertEquals("user_1_2", completedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testThrowsExceptionIfCompletingClaimedTaskOfAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000034");
|
||||
|
||||
taskService.completeTask(claimedTask.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testForceCompleteClaimedTaskOfAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000035");
|
||||
|
||||
taskService.completeTask(claimedTask.getId(), true);
|
||||
|
||||
Task completedTask = taskService.getTask("TKI:000000000000000000000000000000000035");
|
||||
assertNotNull(completedTask);
|
||||
assertEquals(TaskState.COMPLETED, completedTask.getState());
|
||||
assertNotNull(completedTask.getCompleted());
|
||||
assertEquals(completedTask.getCompleted(), completedTask.getModified());
|
||||
assertTrue(completedTask.isRead());
|
||||
assertEquals("user_1_2", completedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testBulkCompleteTasks()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
ConcurrencyException, AttachmentPersistenceException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000100");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000101");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.completeTasks(taskIdList);
|
||||
|
||||
assertFalse(results.containsErrors());
|
||||
Task completedTask1 = taskService.getTask("TKI:000000000000000000000000000000000100");
|
||||
assertEquals(TaskState.COMPLETED, completedTask1.getState());
|
||||
assertNotNull(completedTask1.getCompleted());
|
||||
Task completedTask2 = taskService.getTask("TKI:000000000000000000000000000000000101");
|
||||
assertEquals(TaskState.COMPLETED, completedTask2.getState());
|
||||
assertNotNull(completedTask2.getCompleted());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testBulkDeleteTasksWithException()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
ConcurrencyException, AttachmentPersistenceException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000102");
|
||||
taskIdList.add("TKI:000000000000000000000000000000003333");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
assertTrue(results.containsErrors());
|
||||
assertThat(results.getErrorMap().size(), equalTo(2));
|
||||
assertTrue(results.getErrorForId("TKI:000000000000000000000000000000003333") instanceof TaskNotFoundException);
|
||||
assertTrue(results.getErrorForId("TKI:000000000000000000000000000000000102") instanceof InvalidStateException);
|
||||
}
|
||||
|
||||
}
|
||||
package acceptance.task;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskState;
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.TaskanaException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.BulkOperationResults;
|
||||
import pro.taskana.security.JAASRunner;
|
||||
import pro.taskana.security.WithAccessId;
|
||||
|
||||
/**
|
||||
* Acceptance test for all "work on task" scenarios. This includes claim, complete...
|
||||
*/
|
||||
@RunWith(JAASRunner.class)
|
||||
public class WorkOnTaskAccTest extends AbstractAccTest {
|
||||
|
||||
public WorkOnTaskAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testClaimTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000025");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000025");
|
||||
assertNotNull(claimedTask);
|
||||
assertEquals(TaskState.CLAIMED, claimedTask.getState());
|
||||
assertNotNull(claimedTask.getClaimed());
|
||||
assertNotEquals(claimedTask.getCreated(), claimedTask.getModified());
|
||||
assertEquals(claimedTask.getClaimed(), claimedTask.getModified());
|
||||
assertTrue(claimedTask.isRead());
|
||||
assertEquals("user_1_2", claimedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testThrowsExceptionIfTaskIsAlreadyClaimed()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000026");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testClaimAlreadyClaimedByCallerTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testForceClaimTaskWhichIsAlreadyClaimedByAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000028");
|
||||
|
||||
taskService.claim(task.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testCancelClaimTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||
|
||||
taskService.cancelClaim(claimedTask.getId());
|
||||
|
||||
Task unclaimedTask = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||
assertNotNull(unclaimedTask);
|
||||
assertEquals(TaskState.READY, unclaimedTask.getState());
|
||||
assertNull(unclaimedTask.getClaimed());
|
||||
assertTrue(unclaimedTask.isRead());
|
||||
assertNull(unclaimedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testThrowsExceptionIfCancelClaimOfTaskFromAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000030");
|
||||
|
||||
taskService.cancelClaim(claimedTask.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testForceCancelClaimOfTaskFromAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000031");
|
||||
|
||||
taskService.forceCancelClaim(claimedTask.getId());
|
||||
|
||||
Task unclaimedTask = taskService.getTask("TKI:000000000000000000000000000000000031");
|
||||
assertNotNull(unclaimedTask);
|
||||
assertEquals(TaskState.READY, unclaimedTask.getState());
|
||||
assertNull(unclaimedTask.getClaimed());
|
||||
assertTrue(unclaimedTask.isRead());
|
||||
assertNull(unclaimedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testCompleteTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
Instant before = Instant.now().minus(Duration.ofSeconds(3L));
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000032");
|
||||
|
||||
taskService.completeTask(claimedTask.getId());
|
||||
|
||||
Task completedTask = taskService.getTask("TKI:000000000000000000000000000000000032");
|
||||
assertNotNull(completedTask);
|
||||
assertEquals(TaskState.COMPLETED, completedTask.getState());
|
||||
assertNotNull(completedTask.getCompleted());
|
||||
assertEquals(completedTask.getCompleted(), completedTask.getModified());
|
||||
assertTrue(completedTask.getCompleted().isAfter(before));
|
||||
assertTrue(completedTask.getModified().isAfter(before));
|
||||
assertTrue(completedTask.isRead());
|
||||
assertEquals("user_1_2", completedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testForceCompleteUnclaimedTask()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000033");
|
||||
|
||||
taskService.forceCompleteTask(claimedTask.getId());
|
||||
|
||||
Task completedTask = taskService.getTask("TKI:000000000000000000000000000000000033");
|
||||
assertNotNull(completedTask);
|
||||
assertEquals(TaskState.COMPLETED, completedTask.getState());
|
||||
assertNotNull(completedTask.getCompleted());
|
||||
assertEquals(completedTask.getCompleted(), completedTask.getModified());
|
||||
assertTrue(completedTask.isRead());
|
||||
assertEquals("user_1_2", completedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test(expected = InvalidOwnerException.class)
|
||||
public void testThrowsExceptionIfCompletingClaimedTaskOfAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000034");
|
||||
|
||||
taskService.completeTask(claimedTask.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testForceCompleteClaimedTaskOfAnotherUser()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000035");
|
||||
|
||||
taskService.forceCompleteTask(claimedTask.getId());
|
||||
|
||||
Task completedTask = taskService.getTask("TKI:000000000000000000000000000000000035");
|
||||
assertNotNull(completedTask);
|
||||
assertEquals(TaskState.COMPLETED, completedTask.getState());
|
||||
assertNotNull(completedTask.getCompleted());
|
||||
assertEquals(completedTask.getCompleted(), completedTask.getModified());
|
||||
assertTrue(completedTask.isRead());
|
||||
assertEquals("user_1_2", completedTask.getOwner());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testBulkCompleteTasks()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
ConcurrencyException, AttachmentPersistenceException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000100");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000101");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.completeTasks(taskIdList);
|
||||
|
||||
assertFalse(results.containsErrors());
|
||||
Task completedTask1 = taskService.getTask("TKI:000000000000000000000000000000000100");
|
||||
assertEquals(TaskState.COMPLETED, completedTask1.getState());
|
||||
assertNotNull(completedTask1.getCompleted());
|
||||
Task completedTask2 = taskService.getTask("TKI:000000000000000000000000000000000101");
|
||||
assertEquals(TaskState.COMPLETED, completedTask2.getState());
|
||||
assertNotNull(completedTask2.getCompleted());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void testBulkDeleteTasksWithException()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
||||
ConcurrencyException, AttachmentPersistenceException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000102");
|
||||
taskIdList.add("TKI:000000000000000000000000000000003333");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
assertTrue(results.containsErrors());
|
||||
assertThat(results.getErrorMap().size(), equalTo(2));
|
||||
assertTrue(results.getErrorForId("TKI:000000000000000000000000000000003333") instanceof TaskNotFoundException);
|
||||
assertTrue(results.getErrorForId("TKI:000000000000000000000000000000000102") instanceof InvalidStateException);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,50 +1,50 @@
|
|||
package pro.taskana;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
@Component
|
||||
@Transactional
|
||||
public class ExampleBootstrap {
|
||||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@PostConstruct
|
||||
public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, InvalidStateException, InvalidOwnerException, InvalidWorkbasketException,
|
||||
TaskAlreadyExistException, InvalidArgumentException {
|
||||
System.out.println("---------------------------> Start App");
|
||||
Task task = taskService.newTask("1");
|
||||
task.setName("Spring example task");
|
||||
ObjectReference objRef = new ObjectReference();
|
||||
objRef.setCompany("aCompany");
|
||||
objRef.setSystem("aSystem");
|
||||
objRef.setSystemInstance("anInstance");
|
||||
objRef.setType("aType");
|
||||
objRef.setValue("aValue");
|
||||
task.setPrimaryObjRef(objRef);
|
||||
task = taskService.createTask(task);
|
||||
System.out.println("---------------------------> Task started: " + task.getId());
|
||||
taskService.claim(task.getId());
|
||||
System.out.println(
|
||||
"---------------------------> Task claimed: " + taskService.getTask(task.getId()).getOwner());
|
||||
taskService.completeTask(task.getId(), true);
|
||||
System.out.println("---------------------------> Task completed");
|
||||
}
|
||||
|
||||
}
|
||||
package pro.taskana;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
@Component
|
||||
@Transactional
|
||||
public class ExampleBootstrap {
|
||||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@PostConstruct
|
||||
public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, InvalidStateException, InvalidOwnerException, InvalidWorkbasketException,
|
||||
TaskAlreadyExistException, InvalidArgumentException {
|
||||
System.out.println("---------------------------> Start App");
|
||||
Task task = taskService.newTask("1");
|
||||
task.setName("Spring example task");
|
||||
ObjectReference objRef = new ObjectReference();
|
||||
objRef.setCompany("aCompany");
|
||||
objRef.setSystem("aSystem");
|
||||
objRef.setSystemInstance("anInstance");
|
||||
objRef.setType("aType");
|
||||
objRef.setValue("aValue");
|
||||
task.setPrimaryObjRef(objRef);
|
||||
task = taskService.createTask(task);
|
||||
System.out.println("---------------------------> Task started: " + task.getId());
|
||||
taskService.claim(task.getId());
|
||||
System.out.println(
|
||||
"---------------------------> Task claimed: " + taskService.getTask(task.getId()).getOwner());
|
||||
taskService.forceCompleteTask(task.getId());
|
||||
System.out.println("---------------------------> Task completed");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,369 +1,369 @@
|
|||
package pro.taskana.rest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.PagedResources.PageMetadata;
|
||||
import org.springframework.hateoas.config.EnableHypermediaSupport;
|
||||
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import pro.taskana.BaseQuery.SortDirection;
|
||||
import pro.taskana.KeyDomain;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskQuery;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskState;
|
||||
import pro.taskana.TaskSummary;
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.rest.resource.TaskResource;
|
||||
import pro.taskana.rest.resource.TaskSummaryResource;
|
||||
import pro.taskana.rest.resource.assembler.TaskResourceAssembler;
|
||||
import pro.taskana.rest.resource.assembler.TaskSummaryResourcesAssembler;
|
||||
|
||||
/**
|
||||
* Controller for all {@link Task} related endpoints.
|
||||
*/
|
||||
@RestController
|
||||
@EnableHypermediaSupport(type = HypermediaType.HAL)
|
||||
@RequestMapping(path = "/v1/tasks", produces = "application/hal+json")
|
||||
public class TaskController extends AbstractPagingController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskController.class);
|
||||
|
||||
private static final String STATE = "state";
|
||||
private static final String STATE_VALUE_CLAIMED = "CLAIMED";
|
||||
private static final String STATE_VALUE_COMPLETED = "COMPLETED";
|
||||
private static final String STATE_VALUE_READY = "READY";
|
||||
private static final String PRIORITY = "priority";
|
||||
private static final String NAME = "name";
|
||||
private static final String OWNER = "owner";
|
||||
private static final String DOMAIN = "domain";
|
||||
private static final String WORKBASKET_ID = "workbasket-id";
|
||||
private static final String WORKBASKET_KEY = "workbasket-key";
|
||||
private static final String CLASSIFICATION_KEY = "classification.key";
|
||||
private static final String POR_VALUE = "por.value";
|
||||
private static final String POR_TYPE = "por.type";
|
||||
private static final String POR_SYSTEM_INSTANCE = "por.instance";
|
||||
private static final String POR_SYSTEM = "por.system";
|
||||
private static final String POR_COMPANY = "por.company";
|
||||
private static final String DUE = "due";
|
||||
private static final String PLANNED = "planned";
|
||||
|
||||
private static final String SORT_BY = "sortBy";
|
||||
private static final String SORT_DIRECTION = "order";
|
||||
|
||||
private static final String PAGING_PAGE = "page";
|
||||
private static final String PAGING_PAGE_SIZE = "page-size";
|
||||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private TaskResourceAssembler taskResourceAssembler;
|
||||
|
||||
@GetMapping
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(
|
||||
@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskQuery query = taskService.createTaskQuery();
|
||||
query = applyFilterParams(query, params);
|
||||
query = applySortingParams(query, params);
|
||||
|
||||
PageMetadata pageMetadata = null;
|
||||
List<TaskSummary> taskSummaries = null;
|
||||
String page = params.getFirst(PAGING_PAGE);
|
||||
String pageSize = params.getFirst(PAGING_PAGE_SIZE);
|
||||
params.remove(PAGING_PAGE);
|
||||
params.remove(PAGING_PAGE_SIZE);
|
||||
validateNoInvalidParameterIsLeft(params);
|
||||
if (page != null && pageSize != null) {
|
||||
// paging
|
||||
long totalElements = query.count();
|
||||
pageMetadata = initPageMetadata(pageSize, page,
|
||||
totalElements);
|
||||
taskSummaries = query.listPage((int) pageMetadata.getNumber(),
|
||||
(int) pageMetadata.getSize());
|
||||
} else if (page == null && pageSize == null) {
|
||||
// not paging
|
||||
taskSummaries = query.list();
|
||||
} else {
|
||||
throw new InvalidArgumentException("Paging information is incomplete.");
|
||||
}
|
||||
|
||||
TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
|
||||
PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries,
|
||||
pageMetadata);
|
||||
|
||||
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{taskId}")
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> getTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, NotAuthorizedException {
|
||||
Task task = taskService.getTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(task),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/{taskId}/claim")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> claimTask(@PathVariable String taskId, @RequestBody String userName)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException {
|
||||
// TODO verify user
|
||||
taskService.claim(taskId);
|
||||
Task updatedTask = taskService.getTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{taskId}/complete")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> completeTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException {
|
||||
taskService.completeTask(taskId, true);
|
||||
Task updatedTask = taskService.getTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{taskId}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> deleteTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
taskService.deleteTask(taskId, true);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> createTask(@RequestBody TaskResource taskResource)
|
||||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
|
||||
Task createdTask = taskService.createTask(taskResourceAssembler.toModel(taskResource));
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(createdTask),
|
||||
HttpStatus.CREATED);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/{taskId}/transfer/{workbasketKey}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> transferTask(@PathVariable String taskId, @PathVariable String workbasketKey)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
|
||||
InvalidStateException {
|
||||
Task updatedTask = taskService.transfer(taskId, workbasketKey);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping(path = "/{taskId}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> updateTask(
|
||||
@PathVariable(value = "taskId") String taskId,
|
||||
@RequestBody TaskResource taskResource) throws TaskNotFoundException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException,
|
||||
NotAuthorizedException, AttachmentPersistenceException {
|
||||
ResponseEntity<TaskResource> result;
|
||||
if (taskId.equals(taskResource.getTaskId())) {
|
||||
Task task = taskResourceAssembler.toModel(taskResource);
|
||||
task = taskService.updateTask(task);
|
||||
result = ResponseEntity.ok(taskResourceAssembler.toResource(task));
|
||||
} else {
|
||||
throw new InvalidArgumentException(
|
||||
"TaskId ('" + taskId
|
||||
+ "') is not identical with the taskId of to object in the payload which should be updated. ID=('"
|
||||
+ taskResource.getTaskId() + "')");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private TaskQuery applyFilterParams(TaskQuery taskQuery, MultiValueMap<String, String> params)
|
||||
throws NotAuthorizedException, InvalidArgumentException {
|
||||
|
||||
// apply filters
|
||||
if (params.containsKey(NAME)) {
|
||||
String[] names = extractCommaSeparatedFields(params.get(NAME));
|
||||
taskQuery.nameIn(names);
|
||||
params.remove(NAME);
|
||||
}
|
||||
if (params.containsKey(PRIORITY)) {
|
||||
String[] prioritesInString = extractCommaSeparatedFields(params.get(PRIORITY));
|
||||
int[] priorites = extractPriorities(prioritesInString);
|
||||
taskQuery.priorityIn(priorites);
|
||||
params.remove(PRIORITY);
|
||||
}
|
||||
if (params.containsKey(STATE)) {
|
||||
TaskState[] states = extractStates(params);
|
||||
taskQuery.stateIn(states);
|
||||
params.remove(STATE);
|
||||
}
|
||||
if (params.containsKey(CLASSIFICATION_KEY)) {
|
||||
String[] classificationKeys = extractCommaSeparatedFields(params.get(CLASSIFICATION_KEY));
|
||||
taskQuery.classificationKeyIn(classificationKeys);
|
||||
params.remove(CLASSIFICATION_KEY);
|
||||
}
|
||||
if (params.containsKey(WORKBASKET_ID)) {
|
||||
String[] workbaskets = extractCommaSeparatedFields(params.get(WORKBASKET_ID));
|
||||
taskQuery.workbasketIdIn(workbaskets);
|
||||
params.remove(WORKBASKET_ID);
|
||||
}
|
||||
if (params.containsKey(WORKBASKET_KEY)) {
|
||||
String[] domains = null;
|
||||
if (params.get(DOMAIN) != null) {
|
||||
domains = extractCommaSeparatedFields(params.get(DOMAIN));
|
||||
}
|
||||
if (domains == null || domains.length != 1) {
|
||||
throw new InvalidArgumentException("workbasket-key requires excactly one domain as second parameter.");
|
||||
}
|
||||
String[] workbasketKeys = extractCommaSeparatedFields(params.get(WORKBASKET_KEY));
|
||||
KeyDomain[] keyDomains = new KeyDomain[workbasketKeys.length];
|
||||
for (int i = 0; i < workbasketKeys.length; i++) {
|
||||
keyDomains[i] = new KeyDomain(workbasketKeys[i], domains[0]);
|
||||
}
|
||||
taskQuery.workbasketKeyDomainIn(keyDomains);
|
||||
params.remove(WORKBASKET_KEY);
|
||||
params.remove(DOMAIN);
|
||||
}
|
||||
if (params.containsKey(OWNER)) {
|
||||
String[] owners = extractCommaSeparatedFields(params.get(OWNER));
|
||||
taskQuery.ownerIn(owners);
|
||||
params.remove(OWNER);
|
||||
}
|
||||
if (params.containsKey(POR_COMPANY)) {
|
||||
String[] companies = extractCommaSeparatedFields(params.get(POR_COMPANY));
|
||||
taskQuery.primaryObjectReferenceCompanyIn(companies);
|
||||
params.remove(POR_COMPANY);
|
||||
}
|
||||
if (params.containsKey(POR_SYSTEM)) {
|
||||
String[] systems = extractCommaSeparatedFields(params.get(POR_SYSTEM));
|
||||
taskQuery.primaryObjectReferenceSystemIn(systems);
|
||||
params.remove(POR_SYSTEM);
|
||||
}
|
||||
if (params.containsKey(POR_SYSTEM_INSTANCE)) {
|
||||
String[] systemInstances = extractCommaSeparatedFields(params.get(POR_SYSTEM_INSTANCE));
|
||||
taskQuery.primaryObjectReferenceSystemInstanceIn(systemInstances);
|
||||
params.remove(POR_SYSTEM_INSTANCE);
|
||||
}
|
||||
if (params.containsKey(POR_TYPE)) {
|
||||
String[] types = extractCommaSeparatedFields(params.get(POR_TYPE));
|
||||
taskQuery.primaryObjectReferenceTypeIn(types);
|
||||
params.remove(POR_TYPE);
|
||||
}
|
||||
if (params.containsKey(POR_VALUE)) {
|
||||
String[] values = extractCommaSeparatedFields(params.get(POR_VALUE));
|
||||
taskQuery.primaryObjectReferenceValueIn(values);
|
||||
params.remove(POR_VALUE);
|
||||
}
|
||||
return taskQuery;
|
||||
}
|
||||
|
||||
private TaskQuery applySortingParams(TaskQuery taskQuery, MultiValueMap<String, String> params)
|
||||
throws NotAuthorizedException, InvalidArgumentException {
|
||||
|
||||
// sorting
|
||||
String sortBy = params.getFirst(SORT_BY);
|
||||
if (sortBy != null) {
|
||||
SortDirection sortDirection;
|
||||
if (params.getFirst(SORT_DIRECTION) != null && "desc".equals(params.getFirst(SORT_DIRECTION))) {
|
||||
sortDirection = SortDirection.DESCENDING;
|
||||
} else {
|
||||
sortDirection = SortDirection.ASCENDING;
|
||||
}
|
||||
switch (sortBy) {
|
||||
case (CLASSIFICATION_KEY):
|
||||
taskQuery = taskQuery.orderByClassificationKey(sortDirection);
|
||||
break;
|
||||
case (POR_TYPE):
|
||||
taskQuery = taskQuery.orderByPrimaryObjectReferenceType(sortDirection);
|
||||
break;
|
||||
case (POR_VALUE):
|
||||
taskQuery = taskQuery.orderByPrimaryObjectReferenceValue(sortDirection);
|
||||
break;
|
||||
case (STATE):
|
||||
taskQuery = taskQuery.orderByState(sortDirection);
|
||||
break;
|
||||
case (NAME):
|
||||
taskQuery = taskQuery.orderByName(sortDirection);
|
||||
break;
|
||||
case (DUE):
|
||||
taskQuery = taskQuery.orderByDue(sortDirection);
|
||||
break;
|
||||
case (PLANNED):
|
||||
taskQuery = taskQuery.orderByPlanned(sortDirection);
|
||||
break;
|
||||
case (PRIORITY):
|
||||
taskQuery = taskQuery.orderByPriority(sortDirection);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException("Unknown filter attribute: " + sortBy);
|
||||
}
|
||||
}
|
||||
params.remove(SORT_BY);
|
||||
params.remove(SORT_DIRECTION);
|
||||
return taskQuery;
|
||||
}
|
||||
|
||||
private int[] extractPriorities(String[] prioritesInString) {
|
||||
int[] priorites = new int[prioritesInString.length];
|
||||
for (int i = 0; i < prioritesInString.length; i++) {
|
||||
priorites[i] = Integer.getInteger(prioritesInString[i]);
|
||||
}
|
||||
return priorites;
|
||||
}
|
||||
|
||||
private TaskState[] extractStates(MultiValueMap<String, String> params) throws InvalidArgumentException {
|
||||
List<TaskState> states = new ArrayList<>();
|
||||
for (String item : params.get(STATE)) {
|
||||
for (String state : item.split(",")) {
|
||||
switch (state) {
|
||||
case STATE_VALUE_READY:
|
||||
states.add(TaskState.READY);
|
||||
break;
|
||||
case STATE_VALUE_COMPLETED:
|
||||
states.add(TaskState.COMPLETED);
|
||||
break;
|
||||
case STATE_VALUE_CLAIMED:
|
||||
states.add(TaskState.CLAIMED);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException("Unknown status '" + state + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
return states.toArray(new TaskState[0]);
|
||||
}
|
||||
}
|
||||
package pro.taskana.rest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.PagedResources.PageMetadata;
|
||||
import org.springframework.hateoas.config.EnableHypermediaSupport;
|
||||
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import pro.taskana.BaseQuery.SortDirection;
|
||||
import pro.taskana.KeyDomain;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskQuery;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskState;
|
||||
import pro.taskana.TaskSummary;
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.rest.resource.TaskResource;
|
||||
import pro.taskana.rest.resource.TaskSummaryResource;
|
||||
import pro.taskana.rest.resource.assembler.TaskResourceAssembler;
|
||||
import pro.taskana.rest.resource.assembler.TaskSummaryResourcesAssembler;
|
||||
|
||||
/**
|
||||
* Controller for all {@link Task} related endpoints.
|
||||
*/
|
||||
@RestController
|
||||
@EnableHypermediaSupport(type = HypermediaType.HAL)
|
||||
@RequestMapping(path = "/v1/tasks", produces = "application/hal+json")
|
||||
public class TaskController extends AbstractPagingController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskController.class);
|
||||
|
||||
private static final String STATE = "state";
|
||||
private static final String STATE_VALUE_CLAIMED = "CLAIMED";
|
||||
private static final String STATE_VALUE_COMPLETED = "COMPLETED";
|
||||
private static final String STATE_VALUE_READY = "READY";
|
||||
private static final String PRIORITY = "priority";
|
||||
private static final String NAME = "name";
|
||||
private static final String OWNER = "owner";
|
||||
private static final String DOMAIN = "domain";
|
||||
private static final String WORKBASKET_ID = "workbasket-id";
|
||||
private static final String WORKBASKET_KEY = "workbasket-key";
|
||||
private static final String CLASSIFICATION_KEY = "classification.key";
|
||||
private static final String POR_VALUE = "por.value";
|
||||
private static final String POR_TYPE = "por.type";
|
||||
private static final String POR_SYSTEM_INSTANCE = "por.instance";
|
||||
private static final String POR_SYSTEM = "por.system";
|
||||
private static final String POR_COMPANY = "por.company";
|
||||
private static final String DUE = "due";
|
||||
private static final String PLANNED = "planned";
|
||||
|
||||
private static final String SORT_BY = "sortBy";
|
||||
private static final String SORT_DIRECTION = "order";
|
||||
|
||||
private static final String PAGING_PAGE = "page";
|
||||
private static final String PAGING_PAGE_SIZE = "page-size";
|
||||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private TaskResourceAssembler taskResourceAssembler;
|
||||
|
||||
@GetMapping
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(
|
||||
@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskQuery query = taskService.createTaskQuery();
|
||||
query = applyFilterParams(query, params);
|
||||
query = applySortingParams(query, params);
|
||||
|
||||
PageMetadata pageMetadata = null;
|
||||
List<TaskSummary> taskSummaries = null;
|
||||
String page = params.getFirst(PAGING_PAGE);
|
||||
String pageSize = params.getFirst(PAGING_PAGE_SIZE);
|
||||
params.remove(PAGING_PAGE);
|
||||
params.remove(PAGING_PAGE_SIZE);
|
||||
validateNoInvalidParameterIsLeft(params);
|
||||
if (page != null && pageSize != null) {
|
||||
// paging
|
||||
long totalElements = query.count();
|
||||
pageMetadata = initPageMetadata(pageSize, page,
|
||||
totalElements);
|
||||
taskSummaries = query.listPage((int) pageMetadata.getNumber(),
|
||||
(int) pageMetadata.getSize());
|
||||
} else if (page == null && pageSize == null) {
|
||||
// not paging
|
||||
taskSummaries = query.list();
|
||||
} else {
|
||||
throw new InvalidArgumentException("Paging information is incomplete.");
|
||||
}
|
||||
|
||||
TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
|
||||
PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries,
|
||||
pageMetadata);
|
||||
|
||||
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{taskId}")
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> getTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, NotAuthorizedException {
|
||||
Task task = taskService.getTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(task),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/{taskId}/claim")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> claimTask(@PathVariable String taskId, @RequestBody String userName)
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException {
|
||||
// TODO verify user
|
||||
taskService.claim(taskId);
|
||||
Task updatedTask = taskService.getTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{taskId}/complete")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> completeTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException {
|
||||
taskService.forceCompleteTask(taskId);
|
||||
Task updatedTask = taskService.getTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{taskId}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> deleteTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
|
||||
taskService.forceDeleteTask(taskId);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> createTask(@RequestBody TaskResource taskResource)
|
||||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
|
||||
Task createdTask = taskService.createTask(taskResourceAssembler.toModel(taskResource));
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(createdTask),
|
||||
HttpStatus.CREATED);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/{taskId}/transfer/{workbasketKey}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> transferTask(@PathVariable String taskId, @PathVariable String workbasketKey)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
|
||||
InvalidStateException {
|
||||
Task updatedTask = taskService.transfer(taskId, workbasketKey);
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping(path = "/{taskId}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> updateTask(
|
||||
@PathVariable(value = "taskId") String taskId,
|
||||
@RequestBody TaskResource taskResource) throws TaskNotFoundException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException,
|
||||
NotAuthorizedException, AttachmentPersistenceException {
|
||||
ResponseEntity<TaskResource> result;
|
||||
if (taskId.equals(taskResource.getTaskId())) {
|
||||
Task task = taskResourceAssembler.toModel(taskResource);
|
||||
task = taskService.updateTask(task);
|
||||
result = ResponseEntity.ok(taskResourceAssembler.toResource(task));
|
||||
} else {
|
||||
throw new InvalidArgumentException(
|
||||
"TaskId ('" + taskId
|
||||
+ "') is not identical with the taskId of to object in the payload which should be updated. ID=('"
|
||||
+ taskResource.getTaskId() + "')");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private TaskQuery applyFilterParams(TaskQuery taskQuery, MultiValueMap<String, String> params)
|
||||
throws NotAuthorizedException, InvalidArgumentException {
|
||||
|
||||
// apply filters
|
||||
if (params.containsKey(NAME)) {
|
||||
String[] names = extractCommaSeparatedFields(params.get(NAME));
|
||||
taskQuery.nameIn(names);
|
||||
params.remove(NAME);
|
||||
}
|
||||
if (params.containsKey(PRIORITY)) {
|
||||
String[] prioritesInString = extractCommaSeparatedFields(params.get(PRIORITY));
|
||||
int[] priorites = extractPriorities(prioritesInString);
|
||||
taskQuery.priorityIn(priorites);
|
||||
params.remove(PRIORITY);
|
||||
}
|
||||
if (params.containsKey(STATE)) {
|
||||
TaskState[] states = extractStates(params);
|
||||
taskQuery.stateIn(states);
|
||||
params.remove(STATE);
|
||||
}
|
||||
if (params.containsKey(CLASSIFICATION_KEY)) {
|
||||
String[] classificationKeys = extractCommaSeparatedFields(params.get(CLASSIFICATION_KEY));
|
||||
taskQuery.classificationKeyIn(classificationKeys);
|
||||
params.remove(CLASSIFICATION_KEY);
|
||||
}
|
||||
if (params.containsKey(WORKBASKET_ID)) {
|
||||
String[] workbaskets = extractCommaSeparatedFields(params.get(WORKBASKET_ID));
|
||||
taskQuery.workbasketIdIn(workbaskets);
|
||||
params.remove(WORKBASKET_ID);
|
||||
}
|
||||
if (params.containsKey(WORKBASKET_KEY)) {
|
||||
String[] domains = null;
|
||||
if (params.get(DOMAIN) != null) {
|
||||
domains = extractCommaSeparatedFields(params.get(DOMAIN));
|
||||
}
|
||||
if (domains == null || domains.length != 1) {
|
||||
throw new InvalidArgumentException("workbasket-key requires excactly one domain as second parameter.");
|
||||
}
|
||||
String[] workbasketKeys = extractCommaSeparatedFields(params.get(WORKBASKET_KEY));
|
||||
KeyDomain[] keyDomains = new KeyDomain[workbasketKeys.length];
|
||||
for (int i = 0; i < workbasketKeys.length; i++) {
|
||||
keyDomains[i] = new KeyDomain(workbasketKeys[i], domains[0]);
|
||||
}
|
||||
taskQuery.workbasketKeyDomainIn(keyDomains);
|
||||
params.remove(WORKBASKET_KEY);
|
||||
params.remove(DOMAIN);
|
||||
}
|
||||
if (params.containsKey(OWNER)) {
|
||||
String[] owners = extractCommaSeparatedFields(params.get(OWNER));
|
||||
taskQuery.ownerIn(owners);
|
||||
params.remove(OWNER);
|
||||
}
|
||||
if (params.containsKey(POR_COMPANY)) {
|
||||
String[] companies = extractCommaSeparatedFields(params.get(POR_COMPANY));
|
||||
taskQuery.primaryObjectReferenceCompanyIn(companies);
|
||||
params.remove(POR_COMPANY);
|
||||
}
|
||||
if (params.containsKey(POR_SYSTEM)) {
|
||||
String[] systems = extractCommaSeparatedFields(params.get(POR_SYSTEM));
|
||||
taskQuery.primaryObjectReferenceSystemIn(systems);
|
||||
params.remove(POR_SYSTEM);
|
||||
}
|
||||
if (params.containsKey(POR_SYSTEM_INSTANCE)) {
|
||||
String[] systemInstances = extractCommaSeparatedFields(params.get(POR_SYSTEM_INSTANCE));
|
||||
taskQuery.primaryObjectReferenceSystemInstanceIn(systemInstances);
|
||||
params.remove(POR_SYSTEM_INSTANCE);
|
||||
}
|
||||
if (params.containsKey(POR_TYPE)) {
|
||||
String[] types = extractCommaSeparatedFields(params.get(POR_TYPE));
|
||||
taskQuery.primaryObjectReferenceTypeIn(types);
|
||||
params.remove(POR_TYPE);
|
||||
}
|
||||
if (params.containsKey(POR_VALUE)) {
|
||||
String[] values = extractCommaSeparatedFields(params.get(POR_VALUE));
|
||||
taskQuery.primaryObjectReferenceValueIn(values);
|
||||
params.remove(POR_VALUE);
|
||||
}
|
||||
return taskQuery;
|
||||
}
|
||||
|
||||
private TaskQuery applySortingParams(TaskQuery taskQuery, MultiValueMap<String, String> params)
|
||||
throws NotAuthorizedException, InvalidArgumentException {
|
||||
|
||||
// sorting
|
||||
String sortBy = params.getFirst(SORT_BY);
|
||||
if (sortBy != null) {
|
||||
SortDirection sortDirection;
|
||||
if (params.getFirst(SORT_DIRECTION) != null && "desc".equals(params.getFirst(SORT_DIRECTION))) {
|
||||
sortDirection = SortDirection.DESCENDING;
|
||||
} else {
|
||||
sortDirection = SortDirection.ASCENDING;
|
||||
}
|
||||
switch (sortBy) {
|
||||
case (CLASSIFICATION_KEY):
|
||||
taskQuery = taskQuery.orderByClassificationKey(sortDirection);
|
||||
break;
|
||||
case (POR_TYPE):
|
||||
taskQuery = taskQuery.orderByPrimaryObjectReferenceType(sortDirection);
|
||||
break;
|
||||
case (POR_VALUE):
|
||||
taskQuery = taskQuery.orderByPrimaryObjectReferenceValue(sortDirection);
|
||||
break;
|
||||
case (STATE):
|
||||
taskQuery = taskQuery.orderByState(sortDirection);
|
||||
break;
|
||||
case (NAME):
|
||||
taskQuery = taskQuery.orderByName(sortDirection);
|
||||
break;
|
||||
case (DUE):
|
||||
taskQuery = taskQuery.orderByDue(sortDirection);
|
||||
break;
|
||||
case (PLANNED):
|
||||
taskQuery = taskQuery.orderByPlanned(sortDirection);
|
||||
break;
|
||||
case (PRIORITY):
|
||||
taskQuery = taskQuery.orderByPriority(sortDirection);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException("Unknown filter attribute: " + sortBy);
|
||||
}
|
||||
}
|
||||
params.remove(SORT_BY);
|
||||
params.remove(SORT_DIRECTION);
|
||||
return taskQuery;
|
||||
}
|
||||
|
||||
private int[] extractPriorities(String[] prioritesInString) {
|
||||
int[] priorites = new int[prioritesInString.length];
|
||||
for (int i = 0; i < prioritesInString.length; i++) {
|
||||
priorites[i] = Integer.getInteger(prioritesInString[i]);
|
||||
}
|
||||
return priorites;
|
||||
}
|
||||
|
||||
private TaskState[] extractStates(MultiValueMap<String, String> params) throws InvalidArgumentException {
|
||||
List<TaskState> states = new ArrayList<>();
|
||||
for (String item : params.get(STATE)) {
|
||||
for (String state : item.split(",")) {
|
||||
switch (state) {
|
||||
case STATE_VALUE_READY:
|
||||
states.add(TaskState.READY);
|
||||
break;
|
||||
case STATE_VALUE_COMPLETED:
|
||||
states.add(TaskState.COMPLETED);
|
||||
break;
|
||||
case STATE_VALUE_CLAIMED:
|
||||
states.add(TaskState.CLAIMED);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException("Unknown status '" + state + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
return states.toArray(new TaskState[0]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue