Merge branch 'master' of https://github.com/Taskana/taskana into TSK-65
This commit is contained in:
commit
7135973bb3
|
@ -8,6 +8,7 @@ import javax.enterprise.event.Observes;
|
|||
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.Task;
|
||||
|
||||
@ApplicationScoped
|
||||
|
@ -17,7 +18,7 @@ public class ExampleBootstrap {
|
|||
private TaskanaEjb taskanaEjb;
|
||||
|
||||
@PostConstruct
|
||||
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException {
|
||||
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
System.out.println("---------------------------> Start App");
|
||||
Task task = taskanaEjb.getTaskService().create(new Task());
|
||||
System.out.println("---------------------------> Task started: " + task.getId());
|
||||
|
|
|
@ -4,6 +4,7 @@ import javax.ejb.Stateless;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.Task;
|
||||
|
||||
@Stateless
|
||||
|
@ -16,7 +17,7 @@ public class TaskanaEjb {
|
|||
return taskService;
|
||||
}
|
||||
|
||||
public void triggerRollback() throws NotAuthorizedException {
|
||||
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Task t = taskService.create(new Task());
|
||||
System.out.println("---------------->" + t.getId());
|
||||
throw new RuntimeException();
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.Task;
|
||||
|
||||
@Path("/test")
|
||||
|
@ -23,14 +24,14 @@ public class TaskanaRestTest {
|
|||
private TaskanaEjb taskanaEjb;
|
||||
|
||||
@GET
|
||||
public Response startTask() throws NotAuthorizedException {
|
||||
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Task result = taskanaEjb.getTaskService().create(new Task());
|
||||
logger.info(result.getId() + ":" + result.getOwner());
|
||||
return Response.status(200).entity(result.getId()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response rollbackTask() throws NotAuthorizedException {
|
||||
public Response rollbackTask() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
taskanaEjb.triggerRollback();
|
||||
return Response.status(204).build();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pro.taskana;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
|
@ -31,7 +32,7 @@ public interface ClassificationService {
|
|||
* @param domain
|
||||
* @return If exist: domain-specific classification, else default classification
|
||||
*/
|
||||
Classification getClassification(String id, String domain);
|
||||
Classification getClassification(String id, String domain) throws ClassificationNotFoundException;
|
||||
|
||||
/**
|
||||
* Insert a new Classification.
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package pro.taskana;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.DueWorkbasketCounter;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.TaskStateCounter;
|
||||
import pro.taskana.model.*;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Task Service manages all operations on tasks.
|
||||
|
@ -21,17 +21,19 @@ public interface TaskService {
|
|||
* task id
|
||||
* @param userName
|
||||
* user who claims the task
|
||||
* @return modified claimed Task
|
||||
* @throws TaskNotFoundException
|
||||
*/
|
||||
void claim(String id, String userName) throws TaskNotFoundException;
|
||||
Task claim(String id, String userName) throws TaskNotFoundException;
|
||||
|
||||
/**
|
||||
* Set task to completed.
|
||||
* @param taskId
|
||||
* the task id
|
||||
* @return changed Task after update.
|
||||
* @throws TaskNotFoundException
|
||||
*/
|
||||
void complete(String taskId) throws TaskNotFoundException;
|
||||
Task complete(String taskId) throws TaskNotFoundException;
|
||||
|
||||
/**
|
||||
* Create a task by a task object.
|
||||
|
@ -39,8 +41,21 @@ public interface TaskService {
|
|||
* @return the created task
|
||||
* @throws NotAuthorizedException
|
||||
*/
|
||||
Task create(Task task) throws NotAuthorizedException;
|
||||
Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Create a task manually by filling the fields.
|
||||
* @param workbasketId not null
|
||||
* @param classificationId not null
|
||||
* @param domain
|
||||
* @param planned
|
||||
* @param name
|
||||
* @param description
|
||||
* @param primaryObjectReference
|
||||
* @param customAttributes
|
||||
* @return
|
||||
*/
|
||||
Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name, String description, ObjectReference primaryObjectReference, Map<String, Object> customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException;
|
||||
/**
|
||||
* Get the details of a task.
|
||||
* @param taskId
|
||||
|
@ -95,4 +110,16 @@ public interface TaskService {
|
|||
*/
|
||||
TaskQuery createTaskQuery();
|
||||
|
||||
/**
|
||||
* Getting a list of all Tasks which got matching workbasketIds and states.
|
||||
*
|
||||
* @param workbasketId where the tasks need to be in.
|
||||
* @param taskState which is required for the request,
|
||||
* @return a filled/empty list of tasks with attributes which are matching given params.
|
||||
*
|
||||
* @throws WorkbasketNotFoundException if the workbasketId can´t be resolved to a existing workbasket.
|
||||
* @throws NotAuthorizedException if the current user got no rights for reading on this workbasket.
|
||||
* @throws Exception if no result can be found by @{link TaskMapper}.
|
||||
*/
|
||||
List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package pro.taskana.exceptions;
|
||||
|
||||
/**
|
||||
* This exception will be thrown if a specific task is not in the database.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ClassificationNotFoundException extends NotFoundException {
|
||||
|
||||
public ClassificationNotFoundException(String id) {
|
||||
super("Classification '" + id + "' not found");
|
||||
}
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.ClassificationQuery;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,6 +20,7 @@ import java.util.List;
|
|||
public class ClassificationQueryImpl implements ClassificationQuery {
|
||||
|
||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationQueryImpl.class);
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
private String[] parentClassificationId;
|
||||
private String[] category;
|
||||
|
@ -115,32 +120,50 @@ public class ClassificationQueryImpl implements ClassificationQuery {
|
|||
|
||||
@Override
|
||||
public List<Classification> list() {
|
||||
LOGGER.debug("entry to list(), this = {}", this);
|
||||
List<Classification> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Classification> list(int offset, int limit) {
|
||||
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
|
||||
List<Classification> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
RowBounds rowBounds = new RowBounds(offset, limit);
|
||||
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classification single() {
|
||||
LOGGER.debug("entry to single(), this = {}", this);
|
||||
Classification result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from single(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,4 +270,40 @@ public class ClassificationQueryImpl implements ClassificationQuery {
|
|||
public void setValidUntil(Date[] validUntil) {
|
||||
this.validUntil = validUntil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ClassificationQueryImpl [taskanaEngineImpl=");
|
||||
builder.append(taskanaEngineImpl);
|
||||
builder.append(", parentClassificationId=");
|
||||
builder.append(Arrays.toString(parentClassificationId));
|
||||
builder.append(", category=");
|
||||
builder.append(Arrays.toString(category));
|
||||
builder.append(", type=");
|
||||
builder.append(Arrays.toString(type));
|
||||
builder.append(", domain=");
|
||||
builder.append(Arrays.toString(domain));
|
||||
builder.append(", validInDomain=");
|
||||
builder.append(validInDomain);
|
||||
builder.append(", created=");
|
||||
builder.append(Arrays.toString(created));
|
||||
builder.append(", name=");
|
||||
builder.append(Arrays.toString(name));
|
||||
builder.append(", description=");
|
||||
builder.append(description);
|
||||
builder.append(", priority=");
|
||||
builder.append(Arrays.toString(priority));
|
||||
builder.append(", serviceLevel=");
|
||||
builder.append(Arrays.toString(serviceLevel));
|
||||
builder.append(", customFields=");
|
||||
builder.append(Arrays.toString(customFields));
|
||||
builder.append(", validFrom=");
|
||||
builder.append(Arrays.toString(validFrom));
|
||||
builder.append(", validUntil=");
|
||||
builder.append(Arrays.toString(validUntil));
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package pro.taskana.impl;
|
|||
import pro.taskana.ClassificationQuery;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.Classification;
|
||||
import pro.taskana.model.mappings.ClassificationMapper;
|
||||
|
||||
|
@ -14,6 +16,9 @@ import java.time.LocalDate;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This is the implementation of ClassificationService.
|
||||
*/
|
||||
|
@ -21,6 +26,7 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
|
||||
private static final String ID_PREFIX_CLASSIFICATION = "CLI";
|
||||
public static final Date CURRENT_CLASSIFICATIONS_VALID_UNTIL = Date.valueOf("9999-12-31");
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
|
||||
private ClassificationMapper classificationMapper;
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
@ -34,13 +40,20 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
|
||||
@Override
|
||||
public List<Classification> getClassificationTree() throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to getClassificationTree()");
|
||||
List<Classification> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
List<Classification> rootClassifications;
|
||||
rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
|
||||
return this.populateChildClassifications(rootClassifications);
|
||||
result = this.populateChildClassifications(rootClassifications);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getClassificationTree(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +74,8 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
|
||||
@Override
|
||||
public void addClassification(Classification classification) {
|
||||
try {
|
||||
LOGGER.debug("entry to addClassification(classification = {})", classification);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||
|
@ -69,39 +83,46 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
this.setDefaultValues(classification);
|
||||
|
||||
classificationMapper.insert(classification);
|
||||
LOGGER.debug("Method addClassification added classification {}.", classification);
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from addClassification()");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClassification(Classification classification) {
|
||||
LOGGER.debug("entry to updateClassification(Classification = {})", classification);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
this.setDefaultValues(classification);
|
||||
|
||||
Classification oldClassification = this.getClassification(classification.getId(), classification.getDomain());
|
||||
|
||||
if (oldClassification == null) {
|
||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||
classificationMapper.insert(classification);
|
||||
} else {
|
||||
Classification oldClassification = null;
|
||||
try {
|
||||
oldClassification = this.getClassification(classification.getId(), classification.getDomain());
|
||||
LOGGER.debug("Method updateClassification() inserted classification {}.", classification);
|
||||
|
||||
// ! If you update an classification twice the same day,
|
||||
// the older version is valid from today until yesterday.
|
||||
if (!oldClassification.getDomain().equals(classification.getDomain())) {
|
||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||
classificationMapper.insert(classification);
|
||||
LOGGER.debug("Method updateClassification() inserted classification {}.", classification);
|
||||
} else {
|
||||
oldClassification.setValidUntil(Date.valueOf(LocalDate.now().minusDays(1)));
|
||||
classificationMapper.update(oldClassification);
|
||||
classificationMapper.insert(classification);
|
||||
LOGGER.debug("Method updateClassification() updated old classification {} and inserted new {}.", oldClassification, classification);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} catch (ClassificationNotFoundException e) {
|
||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||
classificationMapper.insert(classification);
|
||||
LOGGER.debug("Method updateClassification() inserted classification {}.", classification);
|
||||
}
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from updateClassification().");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,29 +153,40 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
|
||||
@Override
|
||||
public List<Classification> getAllClassificationsWithId(String id, String domain) {
|
||||
LOGGER.debug("entry to getAllClassificationsWithId(id = {}, domain = {})", id, domain);
|
||||
List<Classification> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return classificationMapper.getAllClassificationsWithId(id, domain);
|
||||
result = classificationMapper.getAllClassificationsWithId(id, domain);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getAllClassificationsWithId(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classification getClassification(String id, String domain) {
|
||||
try {
|
||||
public Classification getClassification(String id, String domain) throws ClassificationNotFoundException {
|
||||
LOGGER.debug("entry to getClassification(id = {}, domain = {})", id, domain);
|
||||
Classification result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
if (classification == null) {
|
||||
return classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
} else {
|
||||
return classification;
|
||||
result = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
if (result == null) {
|
||||
result = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
}
|
||||
if (result == null) {
|
||||
throw new ClassificationNotFoundException(id);
|
||||
}
|
||||
return result;
|
||||
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from getClassification(). Returning result {} ", result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.ObjectReferenceQuery;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.ObjectReference;
|
||||
|
||||
/**
|
||||
|
@ -15,6 +19,7 @@ import pro.taskana.model.ObjectReference;
|
|||
public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
|
||||
|
||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectReferenceQueryImpl.class);
|
||||
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
private String[] company;
|
||||
|
@ -59,32 +64,50 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
|
|||
|
||||
@Override
|
||||
public List<ObjectReference> list() {
|
||||
LOGGER.debug("entry to list(), this = {}", this);
|
||||
List<ObjectReference> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectReference> list(int offset, int limit) {
|
||||
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
|
||||
List<ObjectReference> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
RowBounds rowBounds = new RowBounds(offset, limit);
|
||||
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
}
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectReference single() {
|
||||
LOGGER.debug("entry to single(), this = {}", this);
|
||||
ObjectReference result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from single(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,4 +150,23 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
|
|||
public void setValue(String[] value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ObjectReferenceQueryImpl [taskanaEngineImpl=");
|
||||
builder.append(taskanaEngineImpl);
|
||||
builder.append(", company=");
|
||||
builder.append(Arrays.toString(company));
|
||||
builder.append(", system=");
|
||||
builder.append(Arrays.toString(system));
|
||||
builder.append(", systemInstance=");
|
||||
builder.append(Arrays.toString(systemInstance));
|
||||
builder.append(", type=");
|
||||
builder.append(Arrays.toString(type));
|
||||
builder.append(", value=");
|
||||
builder.append(Arrays.toString(value));
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import pro.taskana.SummaryService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.TaskSummary;
|
||||
import pro.taskana.model.mappings.SummaryMapper;
|
||||
|
||||
|
@ -28,17 +29,23 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
|
||||
@Override
|
||||
public List<TaskSummary> getTaskSummariesByWorkbasketId(String workbasketId) {
|
||||
LOGGER.debug("entry to getTaskSummariesByWorkbasketId(workbasketId = {}", workbasketId);
|
||||
List<TaskSummary> taskSummaries = new ArrayList<>();
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskSummaries = summaryMapper.findTasksummariesByWorkbasketId(workbasketId);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Getting TASKSUMMARY failed internal.", ex);
|
||||
} finally {
|
||||
LOGGER.error("Getting TASKSUMMARY failed internally.", ex);
|
||||
} finally {
|
||||
if (taskSummaries == null) {
|
||||
taskSummaries = new ArrayList<>();
|
||||
}
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = taskSummaries.size();
|
||||
LOGGER.debug("exit from getTaskSummariesByWorkbasketId(workbasketId). Returning {} resulting Objects: {} ",
|
||||
numberOfResultObjects, LoggerUtils.listToString(taskSummaries));
|
||||
}
|
||||
}
|
||||
return taskSummaries;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.ClassificationQuery;
|
||||
import pro.taskana.ObjectReferenceQuery;
|
||||
import pro.taskana.TaskQuery;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
|
@ -19,6 +23,7 @@ import pro.taskana.model.WorkbasketAuthorization;
|
|||
public class TaskQueryImpl implements TaskQuery {
|
||||
|
||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskQueryImpl.class);
|
||||
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
|
@ -111,35 +116,53 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
|
||||
@Override
|
||||
public List<Task> list() throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to list(), this = {}", this);
|
||||
List<Task> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
checkAuthorization();
|
||||
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> list(int offset, int limit) throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
|
||||
List<Task> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
checkAuthorization();
|
||||
RowBounds rowBounds = new RowBounds(offset, limit);
|
||||
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task single() throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to single(), this = {}", this);
|
||||
Task result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
checkAuthorization();
|
||||
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from single(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,4 +269,35 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
public void setCustomFields(String[] customFields) {
|
||||
this.customFields = customFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("TaskQueryImpl [taskanaEngineImpl=");
|
||||
builder.append(taskanaEngineImpl);
|
||||
builder.append(", name=");
|
||||
builder.append(Arrays.toString(name));
|
||||
builder.append(", description=");
|
||||
builder.append(description);
|
||||
builder.append(", priority=");
|
||||
builder.append(Arrays.toString(priority));
|
||||
builder.append(", states=");
|
||||
builder.append(Arrays.toString(states));
|
||||
builder.append(", classificationQuery=");
|
||||
builder.append(classificationQuery);
|
||||
builder.append(", workbasketId=");
|
||||
builder.append(Arrays.toString(workbasketId));
|
||||
builder.append(", owner=");
|
||||
builder.append(Arrays.toString(owner));
|
||||
builder.append(", objectReferenceQuery=");
|
||||
builder.append(objectReferenceQuery);
|
||||
builder.append(", isRead=");
|
||||
builder.append(isRead);
|
||||
builder.append(", isTransferred=");
|
||||
builder.append(isTransferred);
|
||||
builder.append(", customFields=");
|
||||
builder.append(Arrays.toString(customFields));
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@ package pro.taskana.impl;
|
|||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -12,10 +15,13 @@ import org.slf4j.LoggerFactory;
|
|||
import pro.taskana.TaskQuery;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.Classification;
|
||||
import pro.taskana.model.DueWorkbasketCounter;
|
||||
import pro.taskana.model.ObjectReference;
|
||||
import pro.taskana.model.Task;
|
||||
|
@ -35,6 +41,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
private static final String ID_PREFIX_OBJECTR_EFERENCE = "ORI";
|
||||
private static final String ID_PREFIX_TASK = "TKI";
|
||||
private static final String ID_PREFIX_BUSINESS_PROCESS = "BPI";
|
||||
private static final String TYPE_MANUAL = "MANUAL";
|
||||
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
@ -51,10 +58,12 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void claim(String id, String userName) throws TaskNotFoundException {
|
||||
public Task claim(String id, String userName) throws TaskNotFoundException {
|
||||
LOGGER.debug("entry to claim(id = {}, userName = {})", id, userName);
|
||||
Task task = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Task task = taskMapper.findById(id);
|
||||
task = taskMapper.findById(id);
|
||||
if (task != null) {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setOwner(userName);
|
||||
|
@ -62,114 +71,167 @@ public class TaskServiceImpl implements TaskService {
|
|||
task.setClaimed(now);
|
||||
task.setState(TaskState.CLAIMED);
|
||||
taskMapper.update(task);
|
||||
LOGGER.debug("User '{}' claimed task '{}'.", userName, id);
|
||||
LOGGER.debug("Method claim() claimed task '{}' for user '{}'.", id, userName);
|
||||
} else {
|
||||
LOGGER.warn("Method claim() didn't find task with id {}. Throwing TaskNotFoundException", id);
|
||||
throw new TaskNotFoundException(id);
|
||||
}
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from claim()");
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(String id) throws TaskNotFoundException {
|
||||
public Task complete(String id) throws TaskNotFoundException {
|
||||
LOGGER.debug("entry to complete(id = {})", id);
|
||||
Task task = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Task task = taskMapper.findById(id);
|
||||
task = taskMapper.findById(id);
|
||||
if (task != null) {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setCompleted(now);
|
||||
task.setModified(now);
|
||||
task.setState(TaskState.COMPLETED);
|
||||
taskMapper.update(task);
|
||||
LOGGER.debug("Task '{}' completed.", id);
|
||||
LOGGER.debug("Method complete() completed Task '{}'.", id);
|
||||
} else {
|
||||
LOGGER.warn("Method complete() didn't find task with id {}. Throwing TaskNotFoundException", id);
|
||||
throw new TaskNotFoundException(id);
|
||||
}
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from complete()");
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task create(Task task) throws NotAuthorizedException {
|
||||
public Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
LOGGER.debug("entry to create(task = {})", task);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
||||
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
|
||||
task.setState(TaskState.READY);
|
||||
task.setCreated(now);
|
||||
task.setModified(now);
|
||||
task.setRead(false);
|
||||
task.setTransferred(false);
|
||||
standardSettings(task);
|
||||
|
||||
// if no business process id is provided, a unique id is created.
|
||||
if (task.getBusinessProcessId() == null) {
|
||||
task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
|
||||
}
|
||||
|
||||
// insert ObjectReference if needed.
|
||||
if (task.getPrimaryObjRef() != null) {
|
||||
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
||||
if (objectReference == null) {
|
||||
objectReference = task.getPrimaryObjRef();
|
||||
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
|
||||
this.objectReferenceMapper.insert(objectReference);
|
||||
}
|
||||
task.setPrimaryObjRef(objectReference);
|
||||
}
|
||||
this.taskMapper.insert(task);
|
||||
|
||||
LOGGER.debug("Task '{}' created.", task.getId());
|
||||
LOGGER.debug("Method create() created Task '{}'.", task.getId());
|
||||
return task;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from create(task = {})");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name,
|
||||
String description, ObjectReference primaryObjectReference, Map<String, Object> customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("entry to createManualTask(workbasketId = {}, classificationId = {}, domain = {}, planned = {}, name = {},"
|
||||
+ " description = {}, primaryObjectReference = {}, customAttributes = {})", workbasketId, classificationId, domain, planned, name,
|
||||
description, primaryObjectReference, LoggerUtils.mapToString(customAttributes));
|
||||
}
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.APPEND);
|
||||
|
||||
taskanaEngine.getWorkbasketService().getWorkbasket(workbasketId);
|
||||
Classification classification = taskanaEngine.getClassificationService().getClassification(classificationId, domain);
|
||||
|
||||
if (!TYPE_MANUAL.equals(classification.getCategory())) {
|
||||
throw new NotAuthorizedException("You're not allowed to add a task manually to a '" + classification.getCategory() + "'- Classification!");
|
||||
}
|
||||
|
||||
Task task = new Task();
|
||||
|
||||
task.setWorkbasketId(workbasketId);
|
||||
task.setClassification(classification);
|
||||
task.setPlanned(planned);
|
||||
task.setPrimaryObjRef(primaryObjectReference);
|
||||
task.setCustomAttributes(customAttributes);
|
||||
task.setName(name);
|
||||
task.setDescription(description);
|
||||
|
||||
this.standardSettings(task);
|
||||
this.setCustomAttributes(task);
|
||||
|
||||
this.taskMapper.insert(task);
|
||||
|
||||
LOGGER.debug("Method create() created Task '{}'.", task.getId());
|
||||
return task;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from create()");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task getTaskById(String id) throws TaskNotFoundException {
|
||||
LOGGER.debug("entry to getTaskById(id = {})", id);
|
||||
Task result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Task task = taskMapper.findById(id);
|
||||
if (task != null) {
|
||||
return task;
|
||||
result = taskMapper.findById(id);
|
||||
if (result != null) {
|
||||
return result;
|
||||
} else {
|
||||
LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
|
||||
throw new TaskNotFoundException(id);
|
||||
}
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from getTaskById(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("entry to getTaskCountForState(states = {})", LoggerUtils.listToString(states));
|
||||
}
|
||||
List<TaskStateCounter> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return taskMapper.getTaskCountForState(states);
|
||||
result = taskMapper.getTaskCountForState(states);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getTaskCountForState(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
|
||||
workbasketId, daysInPast, LoggerUtils.listToString(states));
|
||||
}
|
||||
long result = -1;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
LocalDate time = LocalDate.now();
|
||||
time = time.minusDays(daysInPast);
|
||||
Date fromDate = Date.valueOf(time);
|
||||
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
|
||||
result = taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
}
|
||||
LOGGER.debug("exit from getTaskCountForWorkbasketByDaysInPastAndState(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task transfer(String taskId, String destinationWorkbasketId)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketId = {})", taskId, destinationWorkbasketId);
|
||||
Task result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Task task = getTaskById(taskId);
|
||||
|
@ -193,37 +255,55 @@ public class TaskServiceImpl implements TaskService {
|
|||
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
|
||||
taskMapper.update(task);
|
||||
|
||||
return getTaskById(taskId);
|
||||
result = getTaskById(taskId);
|
||||
LOGGER.debug("Method transfer() transferred Task '{}' to destination workbasket {}", taskId, destinationWorkbasketId);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from transfer(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
|
||||
List<TaskState> states) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("entry to getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast = {}, states = {})", daysInPast, LoggerUtils.listToString(states));
|
||||
}
|
||||
List<DueWorkbasketCounter> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
LocalDate time = LocalDate.now();
|
||||
time = time.minusDays(daysInPast);
|
||||
Date fromDate = Date.valueOf(time);
|
||||
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
|
||||
result = taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
|
||||
numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
|
||||
LOGGER.debug("entry to setTaskRead(taskId = {}, isRead = {})", taskId, isRead);
|
||||
Task result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Task task = getTaskById(taskId);
|
||||
task.setRead(true);
|
||||
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
|
||||
taskMapper.update(task);
|
||||
return getTaskById(taskId);
|
||||
result = getTaskById(taskId);
|
||||
LOGGER.debug("Method setTaskRead() set read property of Task '{}' to {} ", result, isRead);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from setTaskRead(taskId, isRead). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,4 +311,105 @@ public class TaskServiceImpl implements TaskService {
|
|||
public TaskQuery createTaskQuery() {
|
||||
return new TaskQueryImpl(taskanaEngine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception {
|
||||
LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId, taskState);
|
||||
List<Task> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.READ);
|
||||
result = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState);
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getTasksByWorkbasketIdAndState(workbasketId, taskState). Returning {} resulting Objects: {} ",
|
||||
numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
return (result == null) ? new ArrayList<>() : result;
|
||||
}
|
||||
|
||||
private void standardSettings(Task task) {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
|
||||
task.setState(TaskState.READY);
|
||||
task.setCreated(now);
|
||||
task.setModified(now);
|
||||
task.setRead(false);
|
||||
task.setTransferred(false);
|
||||
|
||||
if (task.getPlanned() == null) {
|
||||
task.setPlanned(now);
|
||||
}
|
||||
|
||||
// if no business process id is provided, a unique id is created.
|
||||
if (task.getBusinessProcessId() == null) {
|
||||
task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
|
||||
}
|
||||
|
||||
// insert Classification specifications if Classification is given.
|
||||
Classification classification = task.getClassification();
|
||||
if (classification != null) {
|
||||
if (classification.getServiceLevel() != null) {
|
||||
Duration serviceLevel = Duration.parse(task.getClassification().getServiceLevel());
|
||||
LocalDateTime due = task.getPlanned().toLocalDateTime().plus(serviceLevel);
|
||||
task.setDue(Timestamp.valueOf(due));
|
||||
}
|
||||
|
||||
if (task.getName() == null) {
|
||||
task.setName(classification.getName());
|
||||
}
|
||||
|
||||
if (task.getDescription() == null) {
|
||||
task.setDescription(classification.getDescription());
|
||||
}
|
||||
|
||||
if (task.getPriority() == 0) {
|
||||
task.setPriority(classification.getPriority());
|
||||
}
|
||||
}
|
||||
|
||||
// insert ObjectReference if needed.
|
||||
if (task.getPrimaryObjRef() != null) {
|
||||
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
||||
if (objectReference == null) {
|
||||
objectReference = task.getPrimaryObjRef();
|
||||
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
|
||||
this.objectReferenceMapper.insert(objectReference);
|
||||
}
|
||||
task.setPrimaryObjRef(objectReference);
|
||||
}
|
||||
}
|
||||
|
||||
private void setCustomAttributes(Task task) {
|
||||
if (task.getCustomAttributes() != null) {
|
||||
for (String custom : task.getCustomAttributes().keySet()) {
|
||||
if (task.getCustom1() == null) {
|
||||
task.setCustom1(custom);
|
||||
} else if (task.getCustom2() == null) {
|
||||
task.setCustom2(custom);
|
||||
} else if (task.getCustom3() == null) {
|
||||
task.setCustom3(custom);
|
||||
} else if (task.getCustom4() == null) {
|
||||
task.setCustom4(custom);
|
||||
} else if (task.getCustom5() == null) {
|
||||
task.setCustom5(custom);
|
||||
} else if (task.getCustom6() == null) {
|
||||
task.setCustom6(custom);
|
||||
} else if (task.getCustom7() == null) {
|
||||
task.setCustom7(custom);
|
||||
} else if (task.getCustom8() == null) {
|
||||
task.setCustom8(custom);
|
||||
} else if (task.getCustom9() == null) {
|
||||
task.setCustom9(custom);
|
||||
} else if (task.getCustom10() == null) {
|
||||
task.setCustom10(custom);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import pro.taskana.WorkbasketService;
|
|||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.Workbasket;
|
||||
import pro.taskana.model.WorkbasketAccessItem;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
|
@ -52,21 +53,28 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
|
||||
@Override
|
||||
public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException {
|
||||
LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId);
|
||||
Workbasket result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Workbasket workbasket = workbasketMapper.findById(workbasketId);
|
||||
if (workbasket == null) {
|
||||
result = workbasketMapper.findById(workbasketId);
|
||||
if (result == null) {
|
||||
LOGGER.warn("Method getWorkbasket() didn't find workbasket with id {}. Throwing WorkbasketNotFoundException", workbasketId);
|
||||
throw new WorkbasketNotFoundException(workbasketId);
|
||||
}
|
||||
|
||||
return workbasket;
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("entry to getWorkbaskets(permissions = {})", LoggerUtils.listToString(permissions));
|
||||
}
|
||||
List<Workbasket> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
//use a set to avoid duplicates
|
||||
|
@ -74,26 +82,39 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
for (String accessId : CurrentUserContext.getAccessIds()) {
|
||||
workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId));
|
||||
}
|
||||
List<Workbasket> workbasketList = new ArrayList<Workbasket>();
|
||||
workbasketList.addAll(workbaskets);
|
||||
return workbasketList;
|
||||
result = new ArrayList<Workbasket>();
|
||||
result.addAll(workbaskets);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getWorkbaskets(permissions). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Workbasket> getWorkbaskets() {
|
||||
LOGGER.debug("entry to getWorkbaskets()");
|
||||
List<Workbasket> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return workbasketMapper.findAll();
|
||||
result = workbasketMapper.findAll();
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Workbasket createWorkbasket(Workbasket workbasket) {
|
||||
LOGGER.debug("entry to createtWorkbasket(workbasket)", workbasket);
|
||||
Workbasket result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
|
@ -103,106 +124,138 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
|
||||
}
|
||||
workbasketMapper.insert(workbasket);
|
||||
LOGGER.debug("Workbasket '{}' created", workbasket.getId());
|
||||
LOGGER.debug("Method createWorkbasket() created Workbasket '{}'", workbasket);
|
||||
if (workbasket.getDistributionTargets() != null) {
|
||||
for (Workbasket distributionTarget : workbasket.getDistributionTargets()) {
|
||||
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
|
||||
distributionTarget.setCreated(now);
|
||||
distributionTarget.setModified(now);
|
||||
workbasketMapper.insert(distributionTarget);
|
||||
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
|
||||
LOGGER.debug("Method createWorkbasket() created distributionTarget '{}'", distributionTarget);
|
||||
}
|
||||
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
||||
LOGGER.debug("Method createWorkbasket() created distributiontarget for source '{}' and target {}", workbasket.getId(), distributionTarget.getId());
|
||||
}
|
||||
}
|
||||
return workbasketMapper.findById(workbasket.getId());
|
||||
result = workbasketMapper.findById(workbasket.getId());
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to updateWorkbasket(workbasket)", workbasket);
|
||||
Workbasket result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
|
||||
workbasketMapper.update(workbasket);
|
||||
LOGGER.debug("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId());
|
||||
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
|
||||
List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
|
||||
for (Workbasket distributionTarget : distributionTargets) {
|
||||
if (!oldDistributionTargets.contains(distributionTarget.getId())) {
|
||||
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
|
||||
workbasketMapper.insert(distributionTarget);
|
||||
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
|
||||
LOGGER.debug(" Method updateWorkbasket() created distributionTarget '{}'", distributionTarget);
|
||||
}
|
||||
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
||||
LOGGER.debug("Method updateWorkbasket() created distributionTarget for '{}' and '{}'", workbasket.getId(), distributionTarget.getId());
|
||||
} else {
|
||||
oldDistributionTargets.remove(distributionTarget.getId());
|
||||
}
|
||||
}
|
||||
distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets);
|
||||
LOGGER.debug("Workbasket '{}' updated", workbasket.getId());
|
||||
return workbasketMapper.findById(workbasket.getId());
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.debug("Method updateWorkbasket() deleted distributionTargets for '{}' and old distribution targets {}",
|
||||
workbasket.getId(), LoggerUtils.listToString(oldDistributionTargets));
|
||||
}
|
||||
result = workbasketMapper.findById(workbasket.getId());
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
||||
LOGGER.debug("entry to createWorkbasketAuthorization(workbasketAccessItem = {})", workbasketAccessItem);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
|
||||
workbasketAccessMapper.insert(workbasketAccessItem);
|
||||
LOGGER.debug("Method createWorkbasketAuthorization() created workbaskteAccessItem {}", workbasketAccessItem);
|
||||
return workbasketAccessItem;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from createWorkbasketAuthorization(workbasketAccessItem). Returning result {}", workbasketAccessItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketAccessItem getWorkbasketAuthorization(String id) {
|
||||
try {
|
||||
LOGGER.debug("entry to getWorkbasketAuthorization(id = {})", id);
|
||||
WorkbasketAccessItem result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return workbasketAccessMapper.findById(id);
|
||||
result = workbasketAccessMapper.findById(id);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from getWorkbasketAuthorization(id). Returning result {}", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWorkbasketAuthorization(String id) {
|
||||
LOGGER.debug("entry to deleteWorkbasketAuthorization(id = {})", id);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
workbasketAccessMapper.delete(id);
|
||||
LOGGER.debug("Method deleteWorkbasketAuthorization() deleted workbasketAccessItem wit Id {}", id);
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from deleteWorkbasketAuthorization(id).");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkbasketAccessItem> getAllAuthorizations() {
|
||||
LOGGER.debug("entry to getAllAuthorizations()");
|
||||
List<WorkbasketAccessItem> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return workbasketAccessMapper.findAll();
|
||||
result = workbasketAccessMapper.findAll();
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getAllAuthorizations(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
|
||||
throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketAuthorization = {})", workbasketId, workbasketAuthorization);
|
||||
boolean isAuthorized = false;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
// Skip permission check is security is not enabled
|
||||
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
||||
LOGGER.debug("Skipping permissions check since security is disabled.");
|
||||
isAuthorized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> accessIds = CurrentUserContext.getAccessIds();
|
||||
LOGGER.debug("Verifying that {} has the permission {} on workbasket {}",
|
||||
LOGGER.debug("checkAuthorization: Verifying that {} has the permission {} on workbasket {}",
|
||||
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketId);
|
||||
|
||||
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
|
||||
|
@ -213,29 +266,42 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
+ "' on workbasket '" + workbasketId + "' is needed.");
|
||||
}
|
||||
|
||||
isAuthorized = true;
|
||||
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from checkAuthorization(). User is authorized = {}.", isAuthorized);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
||||
LOGGER.debug("entry to updateWorkbasketAuthorization(workbasketAccessItem = {}", workbasketAccessItem);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
workbasketAccessMapper.update(workbasketAccessItem);
|
||||
LOGGER.debug("Method updateWorkbasketAuthorization() updated workbasketAccessItem {}", workbasketAccessItem);
|
||||
return workbasketAccessItem;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from updateWorkbasketAuthorization(workbasketAccessItem). Returning {}", workbasketAccessItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) {
|
||||
LOGGER.debug("entry to getWorkbasketAuthorizations(workbasketId = {})", workbasketId);
|
||||
List<WorkbasketAccessItem> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
return workbasketAccessMapper.findByWorkbasketId(workbasketId);
|
||||
result = workbasketAccessMapper.findByWorkbasketId(workbasketId);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getWorkbasketAuthorizations(workbasketId). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package pro.taskana.impl.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Util methods for logging.
|
||||
* @author bbr
|
||||
*
|
||||
*/
|
||||
public final class LoggerUtils {
|
||||
|
||||
private LoggerUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* make a String for logging from a list of objects.
|
||||
* @param list
|
||||
* @return A String representation of the list.
|
||||
*/
|
||||
public static <T> String listToString(List<T> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return "[]";
|
||||
} else {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[");
|
||||
for (T t : list) {
|
||||
builder.append(t.toString());
|
||||
builder.append(";");
|
||||
}
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* make a String for logging from a map.
|
||||
*
|
||||
* @param map the map to be stringified
|
||||
* @return A String representation of the map.
|
||||
*/
|
||||
public static <K, V> String mapToString(Map<K, V> map) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
return "[]";
|
||||
} else {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[");
|
||||
Set<Entry<K, V>> entrySet = map.entrySet();
|
||||
for (Entry<K, V> entry : entrySet) {
|
||||
builder.append("(");
|
||||
builder.append(entry.getKey());
|
||||
builder.append(" , ");
|
||||
builder.append(entry.getValue());
|
||||
builder.append(")");
|
||||
builder.append(" , ");
|
||||
}
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -197,4 +197,54 @@ public class Classification {
|
|||
this.validUntil = validUntil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Classification [id=");
|
||||
builder.append(id);
|
||||
builder.append(", parentClassificationId=");
|
||||
builder.append(parentClassificationId);
|
||||
builder.append(", category=");
|
||||
builder.append(category);
|
||||
builder.append(", type=");
|
||||
builder.append(type);
|
||||
builder.append(", domain=");
|
||||
builder.append(domain);
|
||||
builder.append(", isValidInDomain=");
|
||||
builder.append(isValidInDomain);
|
||||
builder.append(", created=");
|
||||
builder.append(created);
|
||||
builder.append(", name=");
|
||||
builder.append(name);
|
||||
builder.append(", description=");
|
||||
builder.append(description);
|
||||
builder.append(", priority=");
|
||||
builder.append(priority);
|
||||
builder.append(", serviceLevel=");
|
||||
builder.append(serviceLevel);
|
||||
builder.append(", custom1=");
|
||||
builder.append(custom1);
|
||||
builder.append(", custom2=");
|
||||
builder.append(custom2);
|
||||
builder.append(", custom3=");
|
||||
builder.append(custom3);
|
||||
builder.append(", custom4=");
|
||||
builder.append(custom4);
|
||||
builder.append(", custom5=");
|
||||
builder.append(custom5);
|
||||
builder.append(", custom6=");
|
||||
builder.append(custom6);
|
||||
builder.append(", custom7=");
|
||||
builder.append(custom7);
|
||||
builder.append(", custom8=");
|
||||
builder.append(custom8);
|
||||
builder.append(", validFrom=");
|
||||
builder.append(validFrom);
|
||||
builder.append(", validUntil=");
|
||||
builder.append(validUntil);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -62,14 +62,21 @@ public class ObjectReference {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("ObjectReference(");
|
||||
sb.append("id=" + id);
|
||||
sb.append(", company=" + company);
|
||||
sb.append(", system=" + system);
|
||||
sb.append(", systemInstance=" + systemInstance);
|
||||
sb.append(", type=" + type);
|
||||
sb.append(", value=" + value);
|
||||
return sb.toString();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ObjectReference [id=");
|
||||
builder.append(id);
|
||||
builder.append(", company=");
|
||||
builder.append(company);
|
||||
builder.append(", system=");
|
||||
builder.append(system);
|
||||
builder.append(", systemInstance=");
|
||||
builder.append(systemInstance);
|
||||
builder.append(", type=");
|
||||
builder.append(type);
|
||||
builder.append(", value=");
|
||||
builder.append(value);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -281,39 +281,71 @@ public class Task {
|
|||
this.custom10 = custom10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("TASK(");
|
||||
sb.append("id=" + id);
|
||||
sb.append(", created=" + created);
|
||||
sb.append(", claimed=" + claimed);
|
||||
sb.append(", completed=" + completed);
|
||||
sb.append(", modified=" + modified);
|
||||
sb.append(", planned=" + planned);
|
||||
sb.append(", due=" + due);
|
||||
sb.append(", name=" + name);
|
||||
sb.append(", description=" + description);
|
||||
sb.append(", priority=" + priority);
|
||||
sb.append(", state=" + state);
|
||||
sb.append(", classification=" + classification);
|
||||
sb.append(", workbasketId=" + workbasketId);
|
||||
sb.append(", businessProcessId=" + businessProcessId);
|
||||
sb.append(", parentBusinessProcessId=" + parentBusinessProcessId);
|
||||
sb.append(", owner=" + owner);
|
||||
sb.append(", primaryObjRef=" + primaryObjRef);
|
||||
sb.append(", isRead=" + isRead);
|
||||
sb.append(", isTransferred=" + isTransferred);
|
||||
sb.append(", custom1=" + custom1);
|
||||
sb.append(", custom2=" + custom2);
|
||||
sb.append(", custom3=" + custom3);
|
||||
sb.append(", custom4=" + custom4);
|
||||
sb.append(", custom5=" + custom5);
|
||||
sb.append(", custom6=" + custom6);
|
||||
sb.append(", custom7=" + custom7);
|
||||
sb.append(", custom8=" + custom8);
|
||||
sb.append(", custom9=" + custom9);
|
||||
sb.append(", custom10=" + custom10);
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Task [id=");
|
||||
builder.append(id);
|
||||
builder.append(", created=");
|
||||
builder.append(created);
|
||||
builder.append(", claimed=");
|
||||
builder.append(claimed);
|
||||
builder.append(", completed=");
|
||||
builder.append(completed);
|
||||
builder.append(", modified=");
|
||||
builder.append(modified);
|
||||
builder.append(", planned=");
|
||||
builder.append(planned);
|
||||
builder.append(", due=");
|
||||
builder.append(due);
|
||||
builder.append(", name=");
|
||||
builder.append(name);
|
||||
builder.append(", description=");
|
||||
builder.append(description);
|
||||
builder.append(", priority=");
|
||||
builder.append(priority);
|
||||
builder.append(", state=");
|
||||
builder.append(state);
|
||||
builder.append(", classification=");
|
||||
builder.append(classification);
|
||||
builder.append(", workbasketId=");
|
||||
builder.append(workbasketId);
|
||||
builder.append(", businessProcessId=");
|
||||
builder.append(businessProcessId);
|
||||
builder.append(", parentBusinessProcessId=");
|
||||
builder.append(parentBusinessProcessId);
|
||||
builder.append(", owner=");
|
||||
builder.append(owner);
|
||||
builder.append(", primaryObjRef=");
|
||||
builder.append(primaryObjRef);
|
||||
builder.append(", isRead=");
|
||||
builder.append(isRead);
|
||||
builder.append(", isTransferred=");
|
||||
builder.append(isTransferred);
|
||||
builder.append(", customAttributes=");
|
||||
builder.append(customAttributes);
|
||||
builder.append(", custom1=");
|
||||
builder.append(custom1);
|
||||
builder.append(", custom2=");
|
||||
builder.append(custom2);
|
||||
builder.append(", custom3=");
|
||||
builder.append(custom3);
|
||||
builder.append(", custom4=");
|
||||
builder.append(custom4);
|
||||
builder.append(", custom5=");
|
||||
builder.append(custom5);
|
||||
builder.append(", custom6=");
|
||||
builder.append(custom6);
|
||||
builder.append(", custom7=");
|
||||
builder.append(custom7);
|
||||
builder.append(", custom8=");
|
||||
builder.append(custom8);
|
||||
builder.append(", custom9=");
|
||||
builder.append(custom9);
|
||||
builder.append(", custom10=");
|
||||
builder.append(custom10);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,4 +23,15 @@ public class TaskStateCounter {
|
|||
public void setState(TaskState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("TaskStateCounter [state=");
|
||||
builder.append(state);
|
||||
builder.append(", counter=");
|
||||
builder.append(counter);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,4 +72,27 @@ public class Workbasket {
|
|||
public void setDistributionTargets(List<Workbasket> distributionTargets) {
|
||||
this.distributionTargets = distributionTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Workbasket [id=");
|
||||
builder.append(id);
|
||||
builder.append(", created=");
|
||||
builder.append(created);
|
||||
builder.append(", modified=");
|
||||
builder.append(modified);
|
||||
builder.append(", name=");
|
||||
builder.append(name);
|
||||
builder.append(", description=");
|
||||
builder.append(description);
|
||||
builder.append(", owner=");
|
||||
builder.append(owner);
|
||||
builder.append(", distributionTargets=");
|
||||
builder.append(distributionTargets);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -150,4 +150,44 @@ public class WorkbasketAccessItem {
|
|||
public void setPermCustom8(boolean permCustom8) {
|
||||
this.permCustom8 = permCustom8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("WorkbasketAccessItem [id=");
|
||||
builder.append(id);
|
||||
builder.append(", workbasketId=");
|
||||
builder.append(workbasketId);
|
||||
builder.append(", accessId=");
|
||||
builder.append(accessId);
|
||||
builder.append(", permRead=");
|
||||
builder.append(permRead);
|
||||
builder.append(", permOpen=");
|
||||
builder.append(permOpen);
|
||||
builder.append(", permAppend=");
|
||||
builder.append(permAppend);
|
||||
builder.append(", permTransfer=");
|
||||
builder.append(permTransfer);
|
||||
builder.append(", permDistribute=");
|
||||
builder.append(permDistribute);
|
||||
builder.append(", permCustom1=");
|
||||
builder.append(permCustom1);
|
||||
builder.append(", permCustom2=");
|
||||
builder.append(permCustom2);
|
||||
builder.append(", permCustom3=");
|
||||
builder.append(permCustom3);
|
||||
builder.append(", permCustom4=");
|
||||
builder.append(permCustom4);
|
||||
builder.append(", permCustom5=");
|
||||
builder.append(permCustom5);
|
||||
builder.append(", permCustom6=");
|
||||
builder.append(permCustom6);
|
||||
builder.append(", permCustom7=");
|
||||
builder.append(permCustom7);
|
||||
builder.append(", permCustom8=");
|
||||
builder.append(permCustom8);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,4 +96,39 @@ public interface TaskMapper {
|
|||
@Delete("DELETE FROM TASK WHERE ID = #{id}")
|
||||
void delete(String id);
|
||||
|
||||
@Select("SELECT ID, CREATED, CLAIMED, COMPLETED, MODIFIED, PLANNED, DUE, NAME, DESCRIPTION, PRIORITY, STATE, CLASSIFICATION_ID, WORKBASKETID, OWNER, PRIMARY_OBJ_REF_ID, IS_READ, IS_TRANSFERRED, CUSTOM_ATTRIBUTES, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8, CUSTOM_9, CUSTOM_10 "
|
||||
+ "FROM TASK "
|
||||
+ "WHERE WORKBASKETID = #{workbasketId} "
|
||||
+ "AND STATE = #{taskState}")
|
||||
@Results(value = {
|
||||
@Result(property = "id", column = "ID"),
|
||||
@Result(property = "created", column = "CREATED"),
|
||||
@Result(property = "claimed", column = "CLAIMED"),
|
||||
@Result(property = "completed", column = "COMPLETED"),
|
||||
@Result(property = "modified", column = "MODIFIED"),
|
||||
@Result(property = "planned", column = "PLANNED"),
|
||||
@Result(property = "due", column = "DUE"),
|
||||
@Result(property = "name", column = "NAME"),
|
||||
@Result(property = "description", column = "DESCRIPTION"),
|
||||
@Result(property = "priority", column = "PRIORITY"),
|
||||
@Result(property = "state", column = "STATE"),
|
||||
@Result(property = "classification", column = "CLASSIFICATION_ID", javaType = Classification.class, one = @One(select = CLASSIFICATION_FINDBYID)),
|
||||
@Result(property = "workbasketId", column = "WORKBASKETID"),
|
||||
@Result(property = "owner", column = "OWNER"),
|
||||
@Result(property = "primaryObjRef", column = "PRIMARY_OBJ_REF_ID", javaType = ObjectReference.class, one = @One(select = OBJECTREFERENCEMAPPER_FINDBYID)),
|
||||
@Result(property = "isRead", column = "IS_READ"),
|
||||
@Result(property = "isTransferred", column = "IS_TRANSFERRED"),
|
||||
@Result(property = "customAttributes", column = "CUSTOM_ATTRIBUTES", jdbcType = JdbcType.BLOB, javaType = Map.class, typeHandler = MapTypeHandler.class),
|
||||
@Result(property = "custom1", column = "CUSTOM_1"),
|
||||
@Result(property = "custom2", column = "CUSTOM_2"),
|
||||
@Result(property = "custom3", column = "CUSTOM_3"),
|
||||
@Result(property = "custom4", column = "CUSTOM_4"),
|
||||
@Result(property = "custom5", column = "CUSTOM_5"),
|
||||
@Result(property = "custom6", column = "CUSTOM_6"),
|
||||
@Result(property = "custom7", column = "CUSTOM_7"),
|
||||
@Result(property = "custom8", column = "CUSTOM_8"),
|
||||
@Result(property = "custom9", column = "CUSTOM_9"),
|
||||
@Result(property = "custom10", column = "CUSTOM_10")
|
||||
})
|
||||
List<Task> findTasksByWorkbasketIdAndState(@Param("workbasketId") String workbasketId, @Param("taskState") TaskState taskState);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -20,11 +7,19 @@ import org.mockito.InjectMocks;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.model.Classification;
|
||||
import pro.taskana.model.mappings.ClassificationMapper;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit Test for ClassificationServiceImpl.
|
||||
* @author EH
|
||||
|
@ -43,7 +38,7 @@ public class ClassificationServiceImplTest {
|
|||
TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
@Test
|
||||
public void testAddClassification() {
|
||||
public void testAddClassification() throws ClassificationNotFoundException {
|
||||
doNothing().when(classificationMapper).insert(any());
|
||||
|
||||
Classification classification = new Classification();
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -14,19 +8,30 @@ import org.mockito.Mock;
|
|||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.ObjectReference;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.Workbasket;
|
||||
import pro.taskana.model.*;
|
||||
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
||||
import pro.taskana.model.mappings.TaskMapper;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit Test for TaskServiceImpl.
|
||||
* @author EH
|
||||
|
@ -35,29 +40,38 @@ import pro.taskana.model.mappings.TaskMapper;
|
|||
public class TaskServiceImplTest {
|
||||
|
||||
private static final int SLEEP_TIME = 100;
|
||||
@Mock
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
|
||||
@InjectMocks
|
||||
TaskServiceImpl taskServiceImpl;
|
||||
@Mock
|
||||
TaskanaEngineImpl taskanaEngine;
|
||||
@Mock
|
||||
TaskanaEngineImpl taskanaEngineImpl;
|
||||
@Mock
|
||||
TaskMapper taskMapper;
|
||||
@Mock
|
||||
ObjectReferenceMapper objectReferenceMapper;
|
||||
@Mock
|
||||
WorkbasketService workbasketService;
|
||||
private TaskServiceImpl cut;
|
||||
|
||||
@Mock
|
||||
private TaskanaEngineConfiguration taskanaEngineConfigurationMock;
|
||||
|
||||
@Mock
|
||||
private TaskanaEngineImpl taskanaEngineMock;
|
||||
|
||||
@Mock
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
@Mock
|
||||
private TaskMapper taskMapperMock;
|
||||
|
||||
@Mock
|
||||
private ObjectReferenceMapper objectReferenceMapperMock;
|
||||
|
||||
@Mock
|
||||
private WorkbasketService workbasketServiceMock;
|
||||
|
||||
@Mock
|
||||
private ClassificationService classificationServiceMock;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
Mockito.when(taskanaEngine.getWorkbasketService()).thenReturn(workbasketService);
|
||||
doReturn(workbasketServiceMock).when(taskanaEngineMock).getWorkbasketService();
|
||||
doReturn(classificationServiceMock).when(taskanaEngineMock).getClassificationService();
|
||||
try {
|
||||
Mockito.doNothing().when(workbasketService).checkAuthorization(any(), any());
|
||||
Mockito.doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||
} catch (NotAuthorizedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -66,144 +80,530 @@ public class TaskServiceImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSimpleTask() throws NotAuthorizedException {
|
||||
Mockito.doNothing().when(taskMapper).insert(any());
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
task.setWorkbasketId("1");
|
||||
task.setBusinessProcessId("BPI1");
|
||||
task.setParentBusinessProcessId("PBPI1");
|
||||
task = taskServiceImpl.create(task);
|
||||
Assert.assertNull(task.getOwner());
|
||||
Assert.assertNotNull(task.getCreated());
|
||||
Assert.assertNotNull(task.getModified());
|
||||
Assert.assertNull(task.getCompleted());
|
||||
Assert.assertEquals(task.getWorkbasketId(), "1");
|
||||
Assert.assertEquals(task.getBusinessProcessId(), "BPI1");
|
||||
Assert.assertEquals(task.getParentBusinessProcessId(), "PBPI1");
|
||||
Assert.assertEquals(task.getState(), TaskState.READY);
|
||||
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
||||
|
||||
Task actualTask = cut.create(expectedTask);
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||
verify(taskMapperMock, times(1)).insert(expectedTask);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
assertNull(actualTask.getOwner());
|
||||
assertNotNull(actualTask.getCreated());
|
||||
assertNotNull(actualTask.getModified());
|
||||
assertNull(actualTask.getCompleted());
|
||||
assertThat(actualTask.getWorkbasketId(), equalTo(expectedTask.getWorkbasketId()));
|
||||
assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
|
||||
assertThat(actualTask.getState(), equalTo(TaskState.READY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClaim() throws Exception {
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
ObjectReference expectedObjectReference = new ObjectReference();
|
||||
expectedObjectReference.setId("1");
|
||||
expectedObjectReference.setType("DUMMY");
|
||||
|
||||
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
||||
expectedTask.setPrimaryObjRef(new ObjectReference());
|
||||
|
||||
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||
Mockito.doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(any());
|
||||
|
||||
Task actualTask = cut.create(expectedTask);
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||
verify(objectReferenceMapperMock, times(1)).findByObjectReference(any());
|
||||
verify(taskMapperMock, times(1)).insert(expectedTask);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertNull(actualTask.getOwner());
|
||||
assertNotNull(actualTask.getCreated());
|
||||
assertNotNull(actualTask.getModified());
|
||||
assertNull(actualTask.getCompleted());
|
||||
assertThat(actualTask.getWorkbasketId(), equalTo(expectedTask.getWorkbasketId()));
|
||||
assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
|
||||
assertThat(actualTask.getState(), equalTo(TaskState.READY));
|
||||
assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
ObjectReference expectedObjectReference = new ObjectReference();
|
||||
expectedObjectReference.setId("1");
|
||||
expectedObjectReference.setType("DUMMY");
|
||||
|
||||
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
||||
expectedTask.setPrimaryObjRef(expectedObjectReference);
|
||||
|
||||
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||
Mockito.doNothing().when(objectReferenceMapperMock).insert(any());
|
||||
Mockito.doReturn(null).when(objectReferenceMapperMock).findByObjectReference(any());
|
||||
|
||||
Task actualTask = cut.create(expectedTask);
|
||||
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||
verify(objectReferenceMapperMock, times(1)).findByObjectReference(any());
|
||||
verify(objectReferenceMapperMock, times(1)).insert(any());
|
||||
verify(taskMapperMock, times(1)).insert(expectedTask);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertNull(actualTask.getOwner());
|
||||
assertNotNull(actualTask.getCreated());
|
||||
assertNotNull(actualTask.getModified());
|
||||
assertNull(actualTask.getCompleted());
|
||||
assertThat(actualTask.getWorkbasketId(), equalTo(expectedTask.getWorkbasketId()));
|
||||
assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
|
||||
assertThat(actualTask.getState(), equalTo(TaskState.READY));
|
||||
assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateManualTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
ObjectReference expectedObjectReference = new ObjectReference();
|
||||
expectedObjectReference.setId("1");
|
||||
expectedObjectReference.setType("DUMMY");
|
||||
|
||||
Classification classification = new Classification();
|
||||
classification.setName("Name");
|
||||
classification.setCategory("MANUAL");
|
||||
|
||||
Mockito.doReturn(classification).when(classificationServiceMock).getClassification(any(), any());
|
||||
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||
Mockito.doNothing().when(objectReferenceMapperMock).insert(any());
|
||||
|
||||
Task manualTask = cut.createManualTask("workbasketId", "classification", "domain", null, null, "simply awesome task", expectedObjectReference, null);
|
||||
|
||||
Task manualTask2 = cut.createManualTask("workbasketId", "classification", "domain", Timestamp.valueOf(LocalDateTime.now().minusHours(1)), "Task2", "simply awesome task", expectedObjectReference, null);
|
||||
|
||||
verify(taskanaEngineImpl, times(2)).openConnection();
|
||||
verify(taskanaEngineMock, times(2 + 2)).getWorkbasketService();
|
||||
verify(taskanaEngineMock, times(2)).getClassificationService();
|
||||
verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
|
||||
verify(workbasketServiceMock, times(2)).getWorkbasket(any());
|
||||
verify(objectReferenceMapperMock, times(2)).findByObjectReference(any());
|
||||
verify(objectReferenceMapperMock, times(2)).insert(any());
|
||||
verify(taskMapperMock, times(1)).insert(manualTask);
|
||||
verify(taskMapperMock, times(1)).insert(manualTask2);
|
||||
verify(taskanaEngineImpl, times(2)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertNull(manualTask.getOwner());
|
||||
assertNotNull(manualTask.getCreated());
|
||||
assertNotNull(manualTask.getModified());
|
||||
assertNull(manualTask.getCompleted());
|
||||
assertNull(manualTask.getDue());
|
||||
assertThat(manualTask.getWorkbasketId(), equalTo(manualTask2.getWorkbasketId()));
|
||||
assertThat(manualTask.getName(), equalTo(classification.getName()));
|
||||
assertThat(manualTask.getState(), equalTo(TaskState.READY));
|
||||
assertThat(manualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||
assertThat(manualTask.getName(), not(manualTask2.getName()));
|
||||
assertThat(manualTask.getPlanned(), not(manualTask2.getPlanned()));
|
||||
assertThat(manualTask2.getPlanned(), not(manualTask2.getCreated()));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void testCreateThrowingAuthorizedOnWorkbasket() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
try {
|
||||
Mockito.doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||
Task task = new Task();
|
||||
task.setWorkbasketId("1");
|
||||
task.setBusinessProcessId("BPI1");
|
||||
task.setParentBusinessProcessId("PBPI1");
|
||||
|
||||
cut.create(task);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
try {
|
||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||
Task task = new Task();
|
||||
task.setWorkbasketId("1");
|
||||
|
||||
cut.create(task);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClaimSuccessfulToOwner() throws Exception {
|
||||
Task expectedTask = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
|
||||
Thread.sleep(SLEEP_TIME); // to have different timestamps
|
||||
taskServiceImpl.claim(task.getId(), "John Does");
|
||||
task = taskServiceImpl.getTaskById(task.getId());
|
||||
Assert.assertEquals(task.getState(), TaskState.CLAIMED);
|
||||
Assert.assertNotEquals(task.getCreated(), task.getModified());
|
||||
Assert.assertNotNull(task.getClaimed());
|
||||
Assert.assertEquals(task.getOwner(), "John Does");
|
||||
String expectedOwner = "John Does";
|
||||
|
||||
Task acturalTask = cut.claim(expectedTask.getId(), expectedOwner);
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
|
||||
verify(taskMapperMock, times(1)).update(any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertThat(acturalTask.getState(), equalTo(TaskState.CLAIMED));
|
||||
assertThat(acturalTask.getCreated(), not(equalTo(expectedTask.getModified())));
|
||||
assertThat(acturalTask.getClaimed(), not(equalTo(null)));
|
||||
assertThat(acturalTask.getOwner(), equalTo(expectedOwner));
|
||||
}
|
||||
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testClaimFailsWithNonExistingTaskId() throws TaskNotFoundException {
|
||||
taskServiceImpl.claim("test", "John Doe");
|
||||
public void testClaimThrowinTaskNotFoundException() throws TaskNotFoundException {
|
||||
try {
|
||||
Task expectedTask = null;
|
||||
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(any());
|
||||
|
||||
cut.claim("1", "OWNER");
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).findById(any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplete() throws Exception {
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
|
||||
public void testCompleteTask() throws TaskNotFoundException, InterruptedException {
|
||||
Task expectedTask = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
Thread.sleep(SLEEP_TIME); // to have different timestamps
|
||||
taskServiceImpl.complete(task.getId());
|
||||
task = taskServiceImpl.getTaskById(task.getId());
|
||||
Assert.assertEquals(task.getState(), TaskState.COMPLETED);
|
||||
Assert.assertNotEquals(task.getCreated(), task.getModified());
|
||||
Assert.assertNotNull(task.getCompleted());
|
||||
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
|
||||
|
||||
Task actualTask = cut.complete(expectedTask.getId());
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
|
||||
verify(taskMapperMock, times(1)).update(any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertThat(actualTask.getState(), equalTo(TaskState.COMPLETED));
|
||||
assertThat(actualTask.getCreated(), not(equalTo(expectedTask.getModified())));
|
||||
assertThat(actualTask.getCompleted(), not(equalTo(null)));
|
||||
}
|
||||
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testCompleteFailsWithNonExistingTaskId() throws TaskNotFoundException {
|
||||
taskServiceImpl.complete("test");
|
||||
String invalidTaskId = "";
|
||||
try {
|
||||
cut.complete(invalidTaskId);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).findById(invalidTaskId);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferTaskZuDestinationWorkbasket()
|
||||
public void testTransferTaskToDestinationWorkbasketWithoutSecurity()
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Workbasket workbasket2 = createWorkbasket2();
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
Workbasket destinationWorkbasket = createWorkbasket("2");
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
final int workServiceMockCalls = 3;
|
||||
task.setRead(true);
|
||||
doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
|
||||
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
|
||||
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
|
||||
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||
doNothing().when(taskMapperMock).update(any());
|
||||
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||
doNothing().when(workbasketServiceMock).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||
|
||||
Mockito.when(taskanaEngine.getWorkbasketService().getWorkbasket("2")).thenReturn(workbasket2);
|
||||
Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(workServiceMockCalls)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||
verify(taskanaEngineMock, times(1)).getConfiguration();
|
||||
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
|
||||
verify(workbasketServiceMock, times(1)).getWorkbasket(destinationWorkbasket.getId());
|
||||
verify(taskMapperMock, times(1)).update(any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertThat(actualTask.isRead(), equalTo(false));
|
||||
assertThat(actualTask.isTransferred(), equalTo(true));
|
||||
assertThat(actualTask.getWorkbasketId(), equalTo(destinationWorkbasket.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferTaskToDestinationWorkbasketUsingSecurityTrue()
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
Workbasket destinationWorkbasket = createWorkbasket("2");
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
task.setRead(true);
|
||||
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
|
||||
doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
|
||||
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||
doNothing().when(taskMapperMock).update(any());
|
||||
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||
doNothing().when(workbasketServiceMock).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||
|
||||
// taskanaEngine.getConfiguration().isSecurityEnabled())
|
||||
Mockito.when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
|
||||
Mockito.when(taskanaEngineConfiguration.isSecurityEnabled()).thenReturn(false);
|
||||
Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
|
||||
|
||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
||||
taskServiceImpl.transfer(task.getId(), "2");
|
||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "2");
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(2)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||
verify(taskanaEngineMock, times(1)).getConfiguration();
|
||||
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
|
||||
verify(taskMapperMock, times(1)).update(any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
Assert.assertTrue(task.isTransferred());
|
||||
Assert.assertFalse(task.isRead());
|
||||
assertThat(actualTask.isRead(), equalTo(false));
|
||||
assertThat(actualTask.isTransferred(), equalTo(true));
|
||||
assertThat(actualTask.getWorkbasketId(), equalTo(destinationWorkbasket.getId()));
|
||||
}
|
||||
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityDisabled()
|
||||
public void testTransferDestinationWorkbasketDoesNotExist()
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService)
|
||||
.checkAuthorization(eq("invalidWorkbasketId"), any());
|
||||
|
||||
String destinationWorkbasketId = "2";
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||
|
||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
||||
taskServiceImpl.transfer(task.getId(), "invalidWorkbasketId");
|
||||
try {
|
||||
cutSpy.transfer(task.getId(), destinationWorkbasketId);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityEnabled()
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testTransferTaskDoesNotExist()
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService).checkAuthorization(eq("invalidWorkbasketId"), any());
|
||||
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
||||
|
||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
||||
taskServiceImpl.transfer(task.getId(), "invalidWorkbasketId");
|
||||
try {
|
||||
cutSpy.transfer(task.getId(), "2");
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void testTransferNotAuthorizationOnWorkbasketAppend()
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
String destinationWorkbasketId = "2";
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
|
||||
try {
|
||||
cutSpy.transfer(task.getId(), destinationWorkbasketId);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void testTransferNotAuthorizationOnWorkbasketTransfer()
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||
String destinationWorkbasketId = "2";
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
|
||||
|
||||
try {
|
||||
cutSpy.transfer(task.getId(), destinationWorkbasketId);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineMock, times(2)).getWorkbasketService();
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_setTheReadFlag_when_taskIsRead() throws TaskNotFoundException {
|
||||
createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
public void testGetTaskCountForState() {
|
||||
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
|
||||
List<TaskStateCounter> expectedResult = new ArrayList<>();
|
||||
doReturn(expectedResult).when(taskMapperMock).getTaskCountForState(taskStates);
|
||||
|
||||
Task readTask = taskServiceImpl.setTaskRead("1", true);
|
||||
Assert.assertTrue(readTask.isRead());
|
||||
List<TaskStateCounter> actualResult = cut.getTaskCountForState(taskStates);
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).getTaskCountForState(taskStates);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
assertThat(actualResult, equalTo(expectedResult));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_InsertObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
||||
Mockito.when(objectReferenceMapper.findByObjectReference(any())).thenReturn(null);
|
||||
public void testGetTaskCountForWorkbasketByDaysInPastAndState() {
|
||||
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
|
||||
final long daysInPast = 10L;
|
||||
final long expectedResult = 5L;
|
||||
String workbasketId = "1";
|
||||
doReturn(expectedResult).when(taskMapperMock).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(), any());
|
||||
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setSystem("Sol");
|
||||
task.setPrimaryObjRef(primaryObjRef);
|
||||
Task createdTask = taskServiceImpl.create(task);
|
||||
long actualResult = cut.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, daysInPast, taskStates);
|
||||
|
||||
Assert.assertNotNull(createdTask.getPrimaryObjRef());
|
||||
Assert.assertNotNull(createdTask.getPrimaryObjRef().getId());
|
||||
Assert.assertEquals("Sol", createdTask.getPrimaryObjRef().getSystem());
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(), any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
assertThat(actualResult, equalTo(expectedResult));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_LinkObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
||||
public void testGetTaskCountByWorkbasketAndDaysInPastAndState() {
|
||||
final long daysInPast = 10L;
|
||||
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
|
||||
List<DueWorkbasketCounter> expectedResult = new ArrayList<>();
|
||||
doReturn(expectedResult).when(taskMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
|
||||
|
||||
List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast, taskStates);
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
assertThat(actualResult, equalTo(expectedResult));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetTaskReadWIthExistingTask() throws TaskNotFoundException {
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setSystem("Sol");
|
||||
task.setPrimaryObjRef(primaryObjRef);
|
||||
task.setModified(null);
|
||||
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||
doNothing().when(taskMapperMock).update(task);
|
||||
|
||||
ObjectReference returnPrimaryObjRef = new ObjectReference();
|
||||
returnPrimaryObjRef.setId("1");
|
||||
returnPrimaryObjRef.setSystem("Sol");
|
||||
Task actualTask = cutSpy.setTaskRead("1", true);
|
||||
|
||||
Mockito.when(objectReferenceMapper.findByObjectReference(any())).thenReturn(returnPrimaryObjRef);
|
||||
Task createdTask = taskServiceImpl.create(task);
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).update(task);
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
assertThat(actualTask.getModified(), not(equalTo(null)));
|
||||
assertThat(actualTask.isRead(), equalTo(true));
|
||||
}
|
||||
|
||||
Assert.assertNotNull(createdTask.getPrimaryObjRef());
|
||||
Assert.assertEquals("1", createdTask.getPrimaryObjRef().getId());
|
||||
Assert.assertEquals("Sol", createdTask.getPrimaryObjRef().getSystem());
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testSetTaskReadTaskNotBeFound() throws TaskNotFoundException {
|
||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||
task.setModified(null);
|
||||
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
||||
|
||||
try {
|
||||
cutSpy.setTaskRead("1", true);
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTaskByIdWithExistingTask() throws TaskNotFoundException {
|
||||
Task expectedTask = createUnitTestTask("1", "DUMMY-TASK", "1");
|
||||
doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
|
||||
|
||||
Task actualTask = cut.getTaskById(expectedTask.getId());
|
||||
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
assertThat(actualTask, equalTo(expectedTask));
|
||||
}
|
||||
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testGetTaskByIdWhereTaskDoesNotExist() throws Exception {
|
||||
Task task = createUnitTestTask("1", "DUMMY-TASK", "1");
|
||||
doThrow(TaskNotFoundException.class).when(taskMapperMock).findById(task.getId());
|
||||
|
||||
try {
|
||||
cut.getTaskById(task.getId());
|
||||
} catch (Exception e) {
|
||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||
verify(taskMapperMock, times(1)).findById(task.getId());
|
||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private Task createUnitTestTask(String id, String name, String workbasketId) {
|
||||
|
@ -214,15 +614,13 @@ public class TaskServiceImplTest {
|
|||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setCreated(now);
|
||||
task.setModified(now);
|
||||
Mockito.when(taskMapper.findById(any())).thenReturn(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
private Workbasket createWorkbasket2() {
|
||||
Workbasket workbasket2 = new Workbasket();
|
||||
workbasket2.setId("2");
|
||||
workbasket2.setName("Workbasket 2");
|
||||
return workbasket2;
|
||||
private Workbasket createWorkbasket(String id) {
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setId(id);
|
||||
workbasket.setName("Workbasket " + id);
|
||||
return workbasket;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,31 +1,26 @@
|
|||
package pro.taskana.impl.integration;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.*;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Integration Test for ClassificationServiceImpl with connection management mode AUTOCOMMIT.
|
||||
* @author EH
|
||||
|
@ -59,7 +54,7 @@ public class ClassificationServiceImplIntAutoCommitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertClassification() {
|
||||
public void testInsertClassification() throws ClassificationNotFoundException {
|
||||
Classification classification = new Classification();
|
||||
classificationService.addClassification(classification);
|
||||
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
package pro.taskana.impl.integration;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.*;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
|
@ -7,27 +22,6 @@ import java.sql.SQLException;
|
|||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
/**
|
||||
* Integration Test for ClassificationServiceImpl with connection management mode EXPLICIT.
|
||||
* @author BBR
|
||||
|
@ -62,7 +56,7 @@ public class ClassificationServiceImplIntExplicitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertClassification() throws SQLException {
|
||||
public void testInsertClassification() throws SQLException, ClassificationNotFoundException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
|||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.ClassificationQueryImpl;
|
||||
import pro.taskana.impl.ObjectReferenceQueryImpl;
|
||||
import pro.taskana.impl.TaskServiceImpl;
|
||||
|
@ -64,7 +65,8 @@ public class TaskServiceImplIntAutocommitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException,
|
||||
WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
|
@ -80,7 +82,7 @@ public class TaskServiceImplIntAutocommitTest {
|
|||
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testStartTransactionFail()
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
|
@ -95,7 +97,7 @@ public class TaskServiceImplIntAutocommitTest {
|
|||
|
||||
@Test
|
||||
public void testCreateTaskInTaskanaWithDefaultDb()
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
|
||||
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||
|
@ -111,7 +113,7 @@ public class TaskServiceImplIntAutocommitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
|
|
|
@ -7,8 +7,12 @@ import java.security.PrivilegedActionException;
|
|||
import java.security.PrivilegedExceptionAction;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.security.auth.Subject;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
@ -28,8 +32,10 @@ import pro.taskana.ObjectReferenceQuery;
|
|||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.ClassificationQueryImpl;
|
||||
import pro.taskana.impl.ObjectReferenceQueryImpl;
|
||||
import pro.taskana.impl.TaskServiceImpl;
|
||||
|
@ -37,11 +43,13 @@ import pro.taskana.impl.TaskanaEngineImpl;
|
|||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.model.Classification;
|
||||
import pro.taskana.model.ObjectReference;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.Workbasket;
|
||||
import pro.taskana.security.SamplePrincipal;
|
||||
|
||||
|
||||
/**
|
||||
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
|
||||
* @author EH
|
||||
|
@ -99,7 +107,7 @@ public class TaskServiceImplIntExplicitTest {
|
|||
public Object run() {
|
||||
try {
|
||||
do_testStart();
|
||||
} catch (TaskNotFoundException | FileNotFoundException | NotAuthorizedException | SQLException e) {
|
||||
} catch (TaskNotFoundException | FileNotFoundException | NotAuthorizedException | SQLException | WorkbasketNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
@ -107,7 +115,7 @@ public class TaskServiceImplIntExplicitTest {
|
|||
});
|
||||
}
|
||||
|
||||
public void do_testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
public void do_testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
Task task = new Task();
|
||||
|
@ -127,7 +135,7 @@ public class TaskServiceImplIntExplicitTest {
|
|||
public void testStartTransactionFail() throws Throwable {
|
||||
try {
|
||||
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws TaskNotFoundException, FileNotFoundException, NotAuthorizedException, SQLException {
|
||||
public Object run() throws TaskNotFoundException, FileNotFoundException, NotAuthorizedException, SQLException, WorkbasketNotFoundException {
|
||||
do_testStartTransactionFail();
|
||||
return null;
|
||||
}
|
||||
|
@ -140,7 +148,7 @@ public class TaskServiceImplIntExplicitTest {
|
|||
}
|
||||
|
||||
public void do_testStartTransactionFail()
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
||||
|
@ -166,7 +174,7 @@ public class TaskServiceImplIntExplicitTest {
|
|||
public Object run() {
|
||||
try {
|
||||
do_testCreateTaskInTaskanaWithDefaultDb();
|
||||
} catch (TaskNotFoundException | FileNotFoundException | NotAuthorizedException | SQLException e) {
|
||||
} catch (TaskNotFoundException | FileNotFoundException | NotAuthorizedException | SQLException | WorkbasketNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
@ -175,7 +183,7 @@ public class TaskServiceImplIntExplicitTest {
|
|||
}
|
||||
|
||||
public void do_testCreateTaskInTaskanaWithDefaultDb()
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
|
||||
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
|
@ -196,13 +204,13 @@ public class TaskServiceImplIntExplicitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void should_ReturnList_when_BuilderIsUsed() {
|
||||
public void testCreateManualTask() {
|
||||
Subject.doAs(subject, new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
try {
|
||||
do_should_ReturnList_when_BuilderIsUsed();
|
||||
} catch (NotAuthorizedException | SQLException e) {
|
||||
do_testCreateManualTask();
|
||||
} catch (NotAuthorizedException | SQLException | WorkbasketNotFoundException | ClassificationNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
@ -210,7 +218,133 @@ public class TaskServiceImplIntExplicitTest {
|
|||
});
|
||||
}
|
||||
|
||||
public void do_should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
||||
public void do_testCreateManualTask() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setName("workbasket1");
|
||||
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
|
||||
|
||||
Classification classification = new Classification();
|
||||
classification.setDomain("domain");
|
||||
classification.setCategory("MANUAL");
|
||||
classification.setName("classification name");
|
||||
classification.setServiceLevel("P1D");
|
||||
taskanaEngine.getClassificationService().addClassification(classification);
|
||||
|
||||
ObjectReference objectReference = new ObjectReference();
|
||||
objectReference.setCompany("Novatec");
|
||||
objectReference.setSystem("System");
|
||||
objectReference.setSystemInstance("2");
|
||||
objectReference.setValue("4444");
|
||||
objectReference.setType("type");
|
||||
|
||||
Task test = taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", null, "Name", null, objectReference, null);
|
||||
|
||||
Assert.assertEquals(test.getPlanned(), test.getCreated());
|
||||
Assert.assertNotNull(test.getDue());
|
||||
|
||||
Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
|
||||
Map<String, Object> customs = new HashMap<String, Object>();
|
||||
customs.put("Daimler", "Tons of money. And cars. And gold.");
|
||||
customs.put("Audi", 2);
|
||||
|
||||
Task test2 = taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", tomorrow, "Name2", "desc", objectReference, customs);
|
||||
|
||||
Assert.assertEquals(test.getClassification().getId(), test2.getClassification().getId());
|
||||
Assert.assertTrue(test.getDue().before(test2.getDue()));
|
||||
}
|
||||
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void createManualTaskShouldThrowWorkbasketNotFoundException() throws Throwable {
|
||||
try {
|
||||
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws NotAuthorizedException, SQLException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
do_createManualTaskShouldThrowWorkbasketNotFoundException();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
if (e.getCause() != null) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void do_createManualTaskShouldThrowWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setName("wb");
|
||||
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
|
||||
|
||||
taskServiceImpl.createManualTask("1", "classification", "domain", null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = ClassificationNotFoundException.class)
|
||||
public void createManualTaskShouldThrowClassificationNotFoundException() throws Throwable {
|
||||
try {
|
||||
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws NotAuthorizedException, SQLException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
do_createManualTaskShouldThrowClassificationNotFoundException();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
if (e.getCause() != null) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void do_createManualTaskShouldThrowClassificationNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setName("wb");
|
||||
workbasket.setId("1");
|
||||
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
|
||||
|
||||
Classification classification = new Classification();
|
||||
taskanaEngine.getClassificationService().addClassification(classification);
|
||||
|
||||
taskServiceImpl.createManualTask(workbasket.getId(), "classification", "domain", null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void createManualTaskShouldThrowNotAuthorizedException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setName("wb");
|
||||
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
|
||||
|
||||
Classification classification = new Classification();
|
||||
taskanaEngine.getClassificationService().addClassification(classification);
|
||||
|
||||
taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_ReturnList_when_BuilderIsUsed() {
|
||||
Subject.doAs(subject, new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
try {
|
||||
do_should_ReturnList_when_BuilderIsUsed();
|
||||
} catch (NotAuthorizedException | SQLException | WorkbasketNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void do_should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.Task;
|
||||
|
||||
@Component
|
||||
|
@ -17,7 +18,7 @@ public class ExampleBootstrap {
|
|||
private TaskService taskService;
|
||||
|
||||
@PostConstruct
|
||||
public void test() throws TaskNotFoundException, NotAuthorizedException {
|
||||
public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
System.out.println("---------------------------> Start App");
|
||||
Task task = new Task();
|
||||
task.setName("Spring example task");
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.Task;
|
||||
|
||||
@Component
|
||||
|
@ -17,7 +18,7 @@ public class TaskanaComponent {
|
|||
return taskService;
|
||||
}
|
||||
|
||||
public void triggerRollback() throws NotAuthorizedException {
|
||||
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
task.setWorkbasketId("1");
|
||||
|
|
|
@ -21,7 +21,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import pro.taskana.TaskService;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.rest.query.TaskFilter;
|
||||
|
||||
@RestController
|
||||
|
@ -32,6 +34,7 @@ public class TaskController {
|
|||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private TaskFilter taskLogic;
|
||||
|
||||
|
@ -45,6 +48,7 @@ public class TaskController {
|
|||
}
|
||||
return ResponseEntity.status(HttpStatus.OK).body(taskLogic.inspectPrams(params));
|
||||
} catch (NotAuthorizedException e) {
|
||||
logger.error("Somthing went wrong whith the Authorisation, while getting all Tasks.", e);
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +59,26 @@ public class TaskController {
|
|||
Task task = taskService.getTaskById(taskId);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(task);
|
||||
} catch (TaskNotFoundException e) {
|
||||
logger.error("The searched Task couldn´t be found or does not exist.", e);
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/workbasket/{workbasketId}/state/{taskState}")
|
||||
public ResponseEntity<List<Task>> getTasksByWorkbasketIdAndState(
|
||||
@PathVariable(value = "workbasketId") String workbasketId, @PathVariable(value = "taskState") TaskState taskState) {
|
||||
try {
|
||||
List<Task> taskList = taskService.getTasksByWorkbasketIdAndState(workbasketId, taskState);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(taskList);
|
||||
} catch (WorkbasketNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
} catch (NotAuthorizedException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{taskId}/claim")
|
||||
public ResponseEntity<Task> claimTask(@PathVariable String taskId, @RequestBody String userName) {
|
||||
// TODO verify user
|
||||
|
@ -67,6 +87,7 @@ public class TaskController {
|
|||
Task updatedTask = taskService.getTaskById(taskId);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(updatedTask);
|
||||
} catch (TaskNotFoundException e) {
|
||||
logger.error("The given Task coundn´t be found/claimd or does not Exist.", e);
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class WorkbasketController {
|
|||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public ResponseEntity<?> createWorkbasket(@RequestBody Workbasket workbasket) {
|
||||
Workbasket createdWorkbasket = workbasketService.createWorkbasket(workbasket);
|
||||
|
|
Loading…
Reference in New Issue