TSK-518: Move BulkOperationResults and ObjectReference to public API

This commit is contained in:
Konstantin Kläger 2018-06-06 09:28:00 +02:00 committed by Holger Hagen
parent c7ea6f8e63
commit ace632d814
36 changed files with 2491 additions and 2491 deletions

View File

@ -15,7 +15,6 @@ 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;
@ApplicationScoped
public class ExampleBootstrap {

View File

@ -9,7 +9,6 @@ import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ObjectReference;
@Stateless
public class TaskanaEjb {

View File

@ -1,84 +1,83 @@
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);
}
}
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;
@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);
}
}

View File

@ -3,8 +3,6 @@ package pro.taskana;
import java.time.Instant;
import java.util.Map;
import pro.taskana.impl.ObjectReference;
/**
* Attachment-Interface to specify Attachment Attributes.
*/

View File

@ -1,4 +1,4 @@
package pro.taskana.impl;
package pro.taskana;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package pro.taskana.impl;
package pro.taskana;
/**
* ObjectReference entity.

View File

@ -1,7 +1,5 @@
package pro.taskana;
import pro.taskana.impl.ObjectReference;
/**
* ObjectReferenceQuery for generating dynamic sql.
*/

View File

@ -5,7 +5,6 @@ import java.util.List;
import java.util.Map;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.impl.ObjectReference;
/**
* task-Interface to specify attribute interactions.

View File

@ -1,401 +1,399 @@
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;
}
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;
/**
* 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;
}

View File

@ -4,7 +4,6 @@ import java.time.Instant;
import java.util.List;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.impl.ObjectReference;
/**
* Interface for TaskSummary. This is a specific short model-object which only contains the most important information.

View File

@ -7,6 +7,7 @@ import java.util.Map;
import pro.taskana.Attachment;
import pro.taskana.AttachmentSummary;
import pro.taskana.ClassificationSummary;
import pro.taskana.ObjectReference;
/**
* Attachment entity.

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.BulkOperationResults;
import pro.taskana.TaskanaEngine;
import pro.taskana.mappings.JobMapper;

View File

@ -9,6 +9,7 @@ import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ObjectReference;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.TaskanaRuntimeException;

View File

@ -1,5 +1,7 @@
package pro.taskana.impl;
import pro.taskana.BulkOperationResults;
/**
* This interface must be implemented by classes that execut a single job.
*

View File

@ -10,6 +10,7 @@ import java.util.Map;
import pro.taskana.Attachment;
import pro.taskana.AttachmentSummary;
import pro.taskana.ClassificationSummary;
import pro.taskana.ObjectReference;
import pro.taskana.Task;
import pro.taskana.TaskState;
import pro.taskana.TaskSummary;

View File

@ -17,8 +17,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.Attachment;
import pro.taskana.BulkOperationResults;
import pro.taskana.Classification;
import pro.taskana.ClassificationSummary;
import pro.taskana.ObjectReference;
import pro.taskana.Task;
import pro.taskana.TaskQuery;
import pro.taskana.TaskService;

View File

@ -6,6 +6,7 @@ import java.util.List;
import pro.taskana.AttachmentSummary;
import pro.taskana.ClassificationSummary;
import pro.taskana.ObjectReference;
import pro.taskana.TaskState;
import pro.taskana.TaskSummary;
import pro.taskana.WorkbasketSummary;

View File

@ -8,6 +8,7 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.BulkOperationResults;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.mappings.AttachmentMapper;
import pro.taskana.mappings.ClassificationMapper;

View File

@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import pro.taskana.impl.ObjectReference;
import pro.taskana.ObjectReference;
/**
* This class is the mybatis mapping of ObjectReference.
*/

View File

@ -6,9 +6,9 @@ import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import pro.taskana.ObjectReference;
import pro.taskana.impl.ClassificationQueryImpl;
import pro.taskana.impl.ClassificationSummaryImpl;
import pro.taskana.impl.ObjectReference;
import pro.taskana.impl.ObjectReferenceQueryImpl;
import pro.taskana.impl.TaskQueryImpl;
import pro.taskana.impl.TaskSummaryImpl;

View File

@ -1,111 +1,111 @@
package acceptance;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.BeforeClass;
import pro.taskana.Attachment;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.TimeInterval;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.database.TestDataGenerator;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.ObjectReference;
import pro.taskana.impl.configuration.DBCleaner;
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
/**
* Base class for all acceptance tests.
*/
public abstract class AbstractAccTest {
protected static TaskanaEngineConfiguration taskanaEngineConfiguration;
protected static TaskanaEngine taskanaEngine;
@BeforeClass
public static void setupTest() throws Exception {
resetDb();
}
public static void resetDb(boolean... dropTables) throws SQLException, IOException {
DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
if (dropTables == null || dropTables.length == 0) {
cleaner.clearDb(dataSource, true);
} else {
cleaner.clearDb(dataSource, dropTables[0]);
}
dataSource = TaskanaEngineConfigurationTest.getDataSource();
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
taskanaEngine.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
cleaner.clearDb(dataSource, false);
TestDataGenerator testDataGenerator = new TestDataGenerator();
testDataGenerator.generateTestData(dataSource);
}
protected ObjectReference createObjectReference(String company, String system, String systemInstance, String type,
String value) {
ObjectReference objectReference = new ObjectReference();
objectReference.setCompany(company);
objectReference.setSystem(system);
objectReference.setSystemInstance(systemInstance);
objectReference.setType(type);
objectReference.setValue(value);
return objectReference;
}
protected Map<String, String> createSimpleCustomProperties(int propertiesCount) {
HashMap<String, String> properties = new HashMap<>();
for (int i = 1; i <= propertiesCount; i++) {
properties.put("Property_" + i, "Property Value of Property_" + i);
}
return properties;
}
protected Attachment createAttachment(String classificationKey, ObjectReference objRef,
String channel, String receivedDate, Map<String, String> customAttributes)
throws ClassificationNotFoundException, NotAuthorizedException {
Attachment attachment = taskanaEngine.getTaskService().newAttachment();
attachment.setClassificationSummary(
taskanaEngine.getClassificationService().getClassification(classificationKey, "DOMAIN_A").asSummary());
attachment.setObjectReference(objRef);
attachment.setChannel(channel);
Instant receivedTimestamp = null;
if (receivedDate != null && receivedDate.length() < 11) {
// contains only the date, not the time
LocalDate date = LocalDate.parse(receivedDate);
receivedTimestamp = date.atStartOfDay().toInstant(ZoneOffset.UTC);
} else {
receivedTimestamp = Instant.parse(receivedDate);
}
attachment.setReceived(receivedTimestamp);
attachment.setCustomAttributes(customAttributes);
return attachment;
}
protected TimeInterval todaysInterval() {
Instant begin = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant();
Instant end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant();
return new TimeInterval(begin, end);
}
protected Instant getInstant(String datetime) {
return LocalDateTime.parse(datetime).atZone(ZoneId.systemDefault()).toInstant();
}
}
package acceptance;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.BeforeClass;
import pro.taskana.Attachment;
import pro.taskana.ObjectReference;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.TimeInterval;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.database.TestDataGenerator;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.configuration.DBCleaner;
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
/**
* Base class for all acceptance tests.
*/
public abstract class AbstractAccTest {
protected static TaskanaEngineConfiguration taskanaEngineConfiguration;
protected static TaskanaEngine taskanaEngine;
@BeforeClass
public static void setupTest() throws Exception {
resetDb();
}
public static void resetDb(boolean... dropTables) throws SQLException, IOException {
DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
if (dropTables == null || dropTables.length == 0) {
cleaner.clearDb(dataSource, true);
} else {
cleaner.clearDb(dataSource, dropTables[0]);
}
dataSource = TaskanaEngineConfigurationTest.getDataSource();
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
taskanaEngine.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
cleaner.clearDb(dataSource, false);
TestDataGenerator testDataGenerator = new TestDataGenerator();
testDataGenerator.generateTestData(dataSource);
}
protected ObjectReference createObjectReference(String company, String system, String systemInstance, String type,
String value) {
ObjectReference objectReference = new ObjectReference();
objectReference.setCompany(company);
objectReference.setSystem(system);
objectReference.setSystemInstance(systemInstance);
objectReference.setType(type);
objectReference.setValue(value);
return objectReference;
}
protected Map<String, String> createSimpleCustomProperties(int propertiesCount) {
HashMap<String, String> properties = new HashMap<>();
for (int i = 1; i <= propertiesCount; i++) {
properties.put("Property_" + i, "Property Value of Property_" + i);
}
return properties;
}
protected Attachment createAttachment(String classificationKey, ObjectReference objRef,
String channel, String receivedDate, Map<String, String> customAttributes)
throws ClassificationNotFoundException, NotAuthorizedException {
Attachment attachment = taskanaEngine.getTaskService().newAttachment();
attachment.setClassificationSummary(
taskanaEngine.getClassificationService().getClassification(classificationKey, "DOMAIN_A").asSummary());
attachment.setObjectReference(objRef);
attachment.setChannel(channel);
Instant receivedTimestamp = null;
if (receivedDate != null && receivedDate.length() < 11) {
// contains only the date, not the time
LocalDate date = LocalDate.parse(receivedDate);
receivedTimestamp = date.atStartOfDay().toInstant(ZoneOffset.UTC);
} else {
receivedTimestamp = Instant.parse(receivedDate);
}
attachment.setReceived(receivedTimestamp);
attachment.setCustomAttributes(customAttributes);
return attachment;
}
protected TimeInterval todaysInterval() {
Instant begin = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant();
Instant end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant();
return new TimeInterval(begin, end);
}
protected Instant getInstant(String datetime) {
return LocalDateTime.parse(datetime).atZone(ZoneId.systemDefault()).toInstant();
}
}

View File

@ -9,11 +9,11 @@ import java.util.List;
import org.junit.Test;
import acceptance.AbstractAccTest;
import pro.taskana.ObjectReference;
import pro.taskana.TaskQuery;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.ObjectReference;
/**
* Acceptance test for all "get classification" scenarios.

View File

@ -11,12 +11,12 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.ObjectReference;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskQuery;
import pro.taskana.TaskService;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.ObjectReference;
import pro.taskana.security.JAASRunner;
/**

View File

@ -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.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");
}
}
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.BulkOperationResults;
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.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");
}
}

View File

@ -19,6 +19,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.BulkOperationResults;
import pro.taskana.Task;
import pro.taskana.TaskService;
import pro.taskana.TaskState;
@ -31,7 +32,6 @@ import pro.taskana.exceptions.NotAuthorizedException;
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;

View File

@ -22,6 +22,7 @@ import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.ClassificationSummary;
import pro.taskana.ObjectReference;
import pro.taskana.Task;
import pro.taskana.TaskService;
import pro.taskana.TaskState;
@ -34,7 +35,6 @@ 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;
import pro.taskana.impl.TaskImpl;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;

View File

@ -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.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);
}
}
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.BulkOperationResults;
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.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);
}
}

View File

@ -1,6 +1,7 @@
package pro.taskana.impl;
import pro.taskana.Attachment;
import pro.taskana.ObjectReference;
/**
* This class contains helper methods for Junit Tests.

View File

@ -14,6 +14,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.ObjectReference;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;

View File

@ -22,6 +22,7 @@ import org.junit.runner.RunWith;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
import pro.taskana.KeyDomain;
import pro.taskana.ObjectReference;
import pro.taskana.Task;
import pro.taskana.TaskState;
import pro.taskana.TaskSummary;
@ -46,7 +47,6 @@ import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ClassificationImpl;
import pro.taskana.impl.JunitHelper;
import pro.taskana.impl.ObjectReference;
import pro.taskana.impl.TaskImpl;
import pro.taskana.impl.TaskServiceImpl;
import pro.taskana.impl.TaskanaEngineImpl;

View File

@ -1,50 +1,49 @@
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");
}
}
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;
@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");
}
}

View File

@ -10,7 +10,6 @@ import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ObjectReference;
@Component
@Transactional

View File

@ -9,8 +9,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import pro.taskana.BulkOperationResults;
import pro.taskana.TaskanaEngine;
import pro.taskana.impl.BulkOperationResults;
import pro.taskana.impl.JobRunner;
import pro.taskana.impl.util.LoggerUtils;

View File

@ -8,8 +8,8 @@ import java.util.Map;
import org.springframework.hateoas.ResourceSupport;
import pro.taskana.Attachment;
import pro.taskana.ObjectReference;
import pro.taskana.TaskState;
import pro.taskana.impl.ObjectReference;
/**
* Resource class for {@link pro.taskana.Task}.

View File

@ -9,8 +9,8 @@ import org.springframework.hateoas.ResourceSupport;
import org.springframework.hateoas.core.Relation;
import pro.taskana.Attachment;
import pro.taskana.ObjectReference;
import pro.taskana.TaskState;
import pro.taskana.impl.ObjectReference;
/**
* Resource class for {@link pro.taskana.WorkbasketSummary}.