From f750dcf94d750163acfb700ca100192eaacef4e4 Mon Sep 17 00:00:00 2001 From: Marcel Lengl <52546181+LenglBoy@users.noreply.github.com> Date: Mon, 18 Dec 2017 12:28:09 +0100 Subject: [PATCH] TSK-39: Introduced an interface for 'Task', added Methods, solved conflicts, fixed some test issues. --- .../java/pro/taskana/ExampleBootstrap.java | 21 +- .../src/test/java/pro/taskana/TaskanaEjb.java | 12 +- .../java/pro/taskana/TaskanaRestTest.java | 9 +- .../src/main/java/pro/taskana/Task.java | 295 ++++++++++++++++++ .../src/main/java/pro/taskana/TaskQuery.java | 1 - .../main/java/pro/taskana/TaskService.java | 11 +- .../impl/ClassificationServiceImpl.java | 1 + .../{model/Task.java => impl/TaskImpl.java} | 59 +++- .../java/pro/taskana/impl/TaskQueryImpl.java | 6 +- .../pro/taskana/impl/TaskServiceImpl.java | 40 ++- .../taskana/model/mappings/QueryMapper.java | 4 +- .../taskana/model/mappings/TaskMapper.java | 10 +- .../impl/ClassificationServiceImplTest.java | 16 - .../pro/taskana/impl/TaskQueryImplTest.java | 4 +- .../pro/taskana/impl/TaskServiceImplTest.java | 214 ++++++------- .../TaskServiceImplIntAutocommitTest.java | 15 +- .../TaskServiceImplIntExplicitTest.java | 58 ++-- .../java/pro/taskana/ExampleBootstrap.java | 3 +- .../java/pro/taskana/TaskanaComponent.java | 3 +- .../rest/ClassificationController.java | 12 +- .../java/pro/taskana/rest/TaskController.java | 2 +- .../pro/taskana/rest/query/TaskFilter.java | 2 +- 22 files changed, 566 insertions(+), 232 deletions(-) create mode 100644 lib/taskana-core/src/main/java/pro/taskana/Task.java rename lib/taskana-core/src/main/java/pro/taskana/{model/Task.java => impl/TaskImpl.java} (90%) diff --git a/lib/taskana-cdi-example/src/main/java/pro/taskana/ExampleBootstrap.java b/lib/taskana-cdi-example/src/main/java/pro/taskana/ExampleBootstrap.java index 8169dde1b..c8bb7498f 100644 --- a/lib/taskana-cdi-example/src/main/java/pro/taskana/ExampleBootstrap.java +++ b/lib/taskana-cdi-example/src/main/java/pro/taskana/ExampleBootstrap.java @@ -1,18 +1,17 @@ package pro.taskana; +import javax.annotation.PostConstruct; +import javax.ejb.EJB; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.Initialized; +import javax.enterprise.event.Observes; + import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException; -import pro.taskana.model.Task; - -import javax.annotation.PostConstruct; -import javax.ejb.EJB; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.Initialized; -import javax.enterprise.event.Observes; @ApplicationScoped public class ExampleBootstrap { @@ -23,14 +22,14 @@ public class ExampleBootstrap { @PostConstruct public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidStateException, InvalidOwnerException { System.out.println("---------------------------> Start App"); - Task task = taskanaEjb.getTaskService().createTask(new Task()); + Task task = taskanaEjb.getTaskService().newTask(); + task = taskanaEjb.getTaskService().createTask(task); System.out.println("---------------------------> Task started: " + task.getId()); taskanaEjb.getTaskService().claim(task.getId()); System.out.println( "---------------------------> Task claimed: " + taskanaEjb.getTaskService().getTaskById(task.getId()).getOwner()); - // taskService.complete(task.getId()); - // System.out.println("---------------------------> Task completed"); + taskanaEjb.getTaskService().completeTask(task.getId()); + System.out.println("---------------------------> Task completed"); } - } diff --git a/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaEjb.java b/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaEjb.java index 33303a279..9d2d610cd 100644 --- a/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaEjb.java +++ b/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaEjb.java @@ -1,12 +1,11 @@ package pro.taskana; +import javax.ejb.Stateless; +import javax.inject.Inject; + import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.WorkbasketNotFoundException; -import pro.taskana.model.Task; - -import javax.ejb.Stateless; -import javax.inject.Inject; @Stateless public class TaskanaEjb { @@ -33,8 +32,9 @@ public class TaskanaEjb { } public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { - Task t = taskService.createTask(new Task()); - System.out.println("---------------->" + t.getId()); + Task task = taskService.newTask(); + taskService.createTask(task); + System.out.println("---------------->" + task.getId()); throw new RuntimeException(); } diff --git a/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaRestTest.java b/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaRestTest.java index 576a33ab8..e689f7585 100644 --- a/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaRestTest.java +++ b/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaRestTest.java @@ -19,7 +19,6 @@ import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException; -import pro.taskana.model.Task; import pro.taskana.model.Workbasket; @Path("/test") @@ -42,14 +41,14 @@ public class TaskanaRestTest { classification.setKey("TEST"); taskanaEjb.getClassificationService().createClassification(classification); - Task task = new Task(); + Task task = taskanaEjb.getTaskService().newTask(); task.setClassification(classification); task.setWorkbasketId(workbasket.getId()); - Task result = taskanaEjb.getTaskService().createTask(task); + Task resultTask = taskanaEjb.getTaskService().createTask(task); - logger.info(result.getId() + ":" + result.getOwner()); - return Response.status(200).entity(result.getId()).build(); + logger.info(resultTask.getId() + ":" + resultTask.getOwner()); + return Response.status(200).entity(resultTask.getId()).build(); } @POST diff --git a/lib/taskana-core/src/main/java/pro/taskana/Task.java b/lib/taskana-core/src/main/java/pro/taskana/Task.java new file mode 100644 index 000000000..493bb58f1 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/Task.java @@ -0,0 +1,295 @@ +package pro.taskana; + +import java.sql.Timestamp; +import java.util.Map; + +import pro.taskana.model.ObjectReference; +import pro.taskana.model.TaskState; + +/** + * task-Interface to specify attribute interactions. + */ +public interface Task { + + /** + * Returns the current id of the task. + * @return taskId + */ + String getId(); + + /** + * Returns the time when the task was {@link TaskState#READY}. + * @return created as exact {@link Timestamp} + */ + Timestamp getCreated(); + + /** + * Returns the time when the task was set to {@link TaskState#CLAIMED} by/to a user. + * @return claimed as exact {@link Timestamp} + */ + Timestamp getClaimed(); + + /** + * Returns the time when the task was set into {@link TaskState#COMPLETED}. + * @return completed as exact {@link Timestamp} + */ + Timestamp getCompleted(); + + /** + * Returns the time when the task was modified the last time. + * @return modified as exact {@link Timestamp} + */ + Timestamp getModified(); + + /** + * Returns the time when the work on this task was planned to be started. + * @return planned as exact {@link Timestamp} + */ + Timestamp getPlanned(); + + /** + * Sets the time when the work on this task should be started. + * @param planned as exact {@link Timestamp} + */ + void setPlanned(Timestamp planned); + + /** + * Returns the time when this task should be finished. + * @return due as exact {@link Timestamp} + */ + Timestamp getDue(); + + /** + * Return the name of the current task. + * @return name of the task + */ + String getName(); + + /** + * Sets the name of the current task. + * @param name of the task + */ + void setName(String name); + + /** + * Return the task-description. + * @return description of a task + */ + String getDescription(); + + /** + * Sets the description of the task. + * @param description of the task + */ + void setDescription(String description); + + /** + * Returns the numeric priority of a task. + * @return priority of the task + */ + int getPriority(); + + /** + * Returns the current {@link TaskState} of the task. + * @return taskState + */ + TaskState getState(); + + /** + * Returns the {@link Classification} of the task. + * @return classification for specification + */ + Classification getClassification(); + + /** + * Sets the {@link Classification} to specify this kind of task. + * @param classification of the task + */ + void setClassification(Classification classification); + + /** + * Returns the id of the Workbasket where the task is stored in. + * @return workbasketId + */ + String getWorkbasketId(); + + /** + * Sets the id of the Workbasket where the task should be stored in. + * @param workbasketId + */ + void setWorkbasketId(String workbasketId); + + /** + * Returns the businessProcessId of a task. + * @return businessProcessId + */ + String getBusinessProcessId(); + + /** + * Returns the parentBusinessProcessId of a task. + * @return parentBusinessProcessId + */ + String getParentBusinessProcessId(); + + /** + * Return the id of the task-owner. + * @return taskOwnerId + */ + String getOwner(); + + /** + * Sets the ownerId of this task. + * @param taskOwnerId + */ + void setOwner(String taskOwnerId); + + /** + * Returns the {@link ObjectReference primaryObjectReference} of the task. + * @return primaryObjRef to task main-subject + */ + ObjectReference getPrimaryObjRef(); + + /** + * Sets the {@link ObjectReference primaryObjectReference} of the task. + * @param primaryObjRef to task main-subject + */ + void setPrimaryObjRef(ObjectReference primaryObjRef); + + /** + * Return the isRead-flag, which flags a task as viewed at least one time. + * @return isRead-flag + */ + boolean isRead(); + + /** + * Return the isTransferred-flag, which flags a task as transfered into an other workbasket. + * @return isTransferred-flag + */ + boolean isTransferred(); + + /** + * Returns a collection of customAttributes with a max. amount of 10 entries. + * @return customAttributes as {@link Map} + */ + Map getCustomAttributes(); + + /** + * Return the key for the 1. customAttribute. + * @return custom1 + */ + String getCustom1(); + + /** + * Sets the key for customAttribute1. + * @param custom1 + */ + void setCustom1(String custom1); + + /** + * Return the key for the 2. customAttribute. + * @return custom2 + */ + String getCustom2(); + + /** + * Sets the key for customAttribute2. + * @param custom2 + */ + void setCustom2(String custom2); + + /** + * Return the key for the 3. customAttribute. + * @return custom3 + */ + String getCustom3(); + + /** + * Sets the key for customAttribute3. + * @param custom3 + */ + void setCustom3(String custom3); + + /** + * Return the key for the 4. customAttribute. + * @return custom4 + */ + String getCustom4(); + + /** + * Sets the key for customAttribute4. + * @param custom4 + */ + void setCustom4(String custom4); + + /** + * Return the key for the 5. customAttribute. + * @return custom5 + */ + String getCustom5(); + + /** + * Sets the key for customAttribute25. + * @param custom5 + */ + void setCustom5(String custom5); + + /** + * Return the key for the 6. customAttribute. + * @return custom6 + */ + String getCustom6(); + + /** + * Sets the key for customAttribute6. + * @param custom6 + */ + void setCustom6(String custom6); + + /** + * Return the key for the 7. customAttribute. + * @return custom7 + */ + String getCustom7(); + + /** + * Sets the key for customAttribute7. + * @param custom7 + */ + void setCustom7(String custom7); + + /** + * Return the key for the 8. customAttribute. + * @return custom8 + */ + String getCustom8(); + + /** + * Sets the key for customAttribute8. + * @param custom8 + */ + void setCustom8(String custom8); + + /** + * Return the key for the 9. customAttribute. + * @return custom9 + */ + String getCustom9(); + + /** + * Sets the key for customAttribute9. + * @param custom9 + */ + void setCustom9(String custom9); + + /** + * Return the key for the 10. customAttribute. + * @return custom10 + */ + String getCustom10(); + + /** + * Sets the key for customAttribute10. + * @param custom10 + */ + void setCustom10(String custom10); +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java b/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java index 0873ee681..ffeefcb1c 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java +++ b/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java @@ -1,7 +1,6 @@ package pro.taskana; import pro.taskana.exceptions.NotAuthorizedException; -import pro.taskana.model.Task; import pro.taskana.model.TaskState; /** diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskService.java b/lib/taskana-core/src/main/java/pro/taskana/TaskService.java index 3b3a03676..60c24ebaa 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/TaskService.java +++ b/lib/taskana-core/src/main/java/pro/taskana/TaskService.java @@ -8,7 +8,6 @@ import pro.taskana.exceptions.InvalidStateException; 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.model.TaskSummary; @@ -86,7 +85,7 @@ public interface TaskService { /** * Create and persist a task. * - * @param task + * @param taskToCreate * the transient task object to be persisted * @return the created and persisted task * @throws NotAuthorizedException @@ -96,7 +95,7 @@ public interface TaskService { * @throws ClassificationNotFoundException * thrown if the {@link Classification} referenced by the task is not found */ - Task createTask(Task task) + Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException; /** @@ -174,4 +173,10 @@ public interface TaskService { * if a Work basket can“t be located. */ List getTaskSummariesByWorkbasketId(String workbasketId) throws WorkbasketNotFoundException; + + /** + * Returns a not persisted instance of {@link Task}. + * @return task - with default values + */ + Task newTask(); } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java index 781f8d3dd..4dacca611 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java @@ -105,6 +105,7 @@ public class ClassificationServiceImpl implements ClassificationService { classificationMapper.insert(classificationImpl); LOGGER.debug("Method createClassification created classification {}.", classification); if (classificationImpl.getDomain() != "") { + classificationImpl.setId(UUID.randomUUID().toString()); classificationImpl.setDomain(""); classificationMapper.insert(classificationImpl); LOGGER.debug("Method createClassification created classification {}.", classification); diff --git a/lib/taskana-core/src/main/java/pro/taskana/model/Task.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskImpl.java similarity index 90% rename from lib/taskana-core/src/main/java/pro/taskana/model/Task.java rename to lib/taskana-core/src/main/java/pro/taskana/impl/TaskImpl.java index 3c046bc1a..5e908c533 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/model/Task.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskImpl.java @@ -1,15 +1,18 @@ -package pro.taskana.model; +package pro.taskana.impl; import java.sql.Timestamp; import java.util.Collections; import java.util.Map; import pro.taskana.Classification; +import pro.taskana.Task; +import pro.taskana.model.ObjectReference; +import pro.taskana.model.TaskState; /** * Task entity. */ -public class Task { +public class TaskImpl implements Task { private String id; private Timestamp created; @@ -43,6 +46,9 @@ public class Task { private String custom9; private String custom10; + TaskImpl() { } + + @Override public String getId() { return id; } @@ -51,6 +57,7 @@ public class Task { this.id = id; } + @Override public Timestamp getCreated() { return created; } @@ -59,6 +66,7 @@ public class Task { this.created = created; } + @Override public Timestamp getClaimed() { return claimed; } @@ -67,6 +75,7 @@ public class Task { this.claimed = claimed; } + @Override public Timestamp getCompleted() { return completed; } @@ -75,22 +84,27 @@ public class Task { this.completed = completed; } + @Override public Timestamp getModified() { return modified; } + public void setModified(Timestamp modified) { this.modified = modified; } + @Override public Timestamp getPlanned() { return planned; } + @Override public void setPlanned(Timestamp planned) { this.planned = planned; } + @Override public Timestamp getDue() { return due; } @@ -99,22 +113,27 @@ public class Task { this.due = due; } + @Override public String getName() { return name; } + @Override public void setName(String name) { this.name = name; } + @Override public String getDescription() { return description; } + @Override public void setDescription(String description) { this.description = description; } + @Override public int getPriority() { return priority; } @@ -123,6 +142,7 @@ public class Task { this.priority = priority; } + @Override public TaskState getState() { return state; } @@ -131,30 +151,37 @@ public class Task { this.state = state; } + @Override public Classification getClassification() { return classification; } + @Override public void setClassification(Classification classification) { this.classification = classification; } + @Override public String getWorkbasketId() { return workbasketId; } + @Override public void setWorkbasketId(String workbasketId) { this.workbasketId = workbasketId; } + @Override public String getBusinessProcessId() { return businessProcessId; } + public void setBusinessProcessId(String businessProcessId) { this.businessProcessId = businessProcessId; } + @Override public String getParentBusinessProcessId() { return parentBusinessProcessId; } @@ -163,22 +190,27 @@ public class Task { this.parentBusinessProcessId = parentBusinessProcessId; } + @Override public String getOwner() { return owner; } + @Override public void setOwner(String owner) { this.owner = owner; } + @Override public ObjectReference getPrimaryObjRef() { return primaryObjRef; } + @Override public void setPrimaryObjRef(ObjectReference primaryObjRef) { this.primaryObjRef = primaryObjRef; } + @Override public boolean isRead() { return isRead; } @@ -187,6 +219,7 @@ public class Task { this.isRead = isRead; } + @Override public boolean isTransferred() { return isTransferred; } @@ -195,6 +228,7 @@ public class Task { this.isTransferred = isTransferred; } + @Override public Map getCustomAttributes() { return customAttributes; } @@ -203,82 +237,102 @@ public class Task { this.customAttributes = customAttributes; } + @Override public String getCustom1() { return custom1; } + @Override public void setCustom1(String custom1) { this.custom1 = custom1; } + @Override public String getCustom2() { return custom2; } + @Override public void setCustom2(String custom2) { this.custom2 = custom2; } + @Override public String getCustom3() { return custom3; } + @Override public void setCustom3(String custom3) { this.custom3 = custom3; } + @Override public String getCustom4() { return custom4; } + @Override public void setCustom4(String custom4) { this.custom4 = custom4; } + @Override public String getCustom5() { return custom5; } + @Override public void setCustom5(String custom5) { this.custom5 = custom5; } + @Override public String getCustom6() { return custom6; } + @Override public void setCustom6(String custom6) { this.custom6 = custom6; } + @Override public String getCustom7() { return custom7; } + @Override public void setCustom7(String custom7) { this.custom7 = custom7; } + @Override public String getCustom8() { return custom8; } + @Override public void setCustom8(String custom8) { this.custom8 = custom8; } + @Override public String getCustom9() { return custom9; } + @Override public void setCustom9(String custom9) { this.custom9 = custom9; } + @Override public String getCustom10() { return custom10; } + @Override public void setCustom10(String custom10) { this.custom10 = custom10; } @@ -349,5 +403,4 @@ public class Task { builder.append("]"); return builder.toString(); } - } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java index 2471c0282..f8ec5d5e6 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java @@ -9,11 +9,11 @@ import org.slf4j.LoggerFactory; import pro.taskana.ClassificationQuery; import pro.taskana.ObjectReferenceQuery; +import pro.taskana.Task; 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; @@ -152,9 +152,9 @@ public class TaskQueryImpl implements TaskQuery { } @Override - public Task single() throws NotAuthorizedException { + public TaskImpl single() throws NotAuthorizedException { LOGGER.debug("entry to single(), this = {}", this); - Task result = null; + TaskImpl result = null; try { taskanaEngineImpl.openConnection(); checkAuthorization(); diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java index 67058c913..33b6c57e3 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import pro.taskana.Classification; +import pro.taskana.Task; import pro.taskana.TaskQuery; import pro.taskana.TaskService; import pro.taskana.TaskanaEngine; @@ -23,7 +24,6 @@ import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.impl.util.IdGenerator; import pro.taskana.impl.util.LoggerUtils; import pro.taskana.model.ObjectReference; -import pro.taskana.model.Task; import pro.taskana.model.TaskState; import pro.taskana.model.TaskSummary; import pro.taskana.model.WorkbasketAuthorization; @@ -74,10 +74,10 @@ public class TaskServiceImpl implements TaskService { throws TaskNotFoundException, InvalidStateException, InvalidOwnerException { String userId = CurrentUserContext.getUserid(); LOGGER.debug("entry to claim(id = {}, forceClaim = {}, userId = {})", taskId, forceClaim, userId); - Task task = null; + TaskImpl task = null; try { taskanaEngineImpl.openConnection(); - task = getTaskById(taskId); + task = (TaskImpl) getTaskById(taskId); TaskState state = task.getState(); if (state == TaskState.COMPLETED) { LOGGER.warn("Method claim() found that task {} is already completed. Throwing InvalidStateException", @@ -115,10 +115,10 @@ public class TaskServiceImpl implements TaskService { public Task completeTask(String taskId, boolean isForced) throws TaskNotFoundException, InvalidOwnerException, InvalidStateException { LOGGER.debug("entry to completeTask(id = {}, isForced {})", taskId, isForced); - Task task = null; + TaskImpl task = null; try { taskanaEngineImpl.openConnection(); - task = this.getTaskById(taskId); + task = (TaskImpl) this.getTaskById(taskId); // check pre-conditions for non-forced invocation if (!isForced) { if (task.getClaimed() == null || task.getState() != TaskState.CLAIMED) { @@ -135,7 +135,7 @@ public class TaskServiceImpl implements TaskService { } else { // CLAIM-forced, if task was not already claimed before. if (task.getClaimed() == null || task.getState() != TaskState.CLAIMED) { - task = this.claim(taskId, true); + task = (TaskImpl) this.claim(taskId, true); } } Timestamp now = new Timestamp(System.currentTimeMillis()); @@ -152,18 +152,19 @@ public class TaskServiceImpl implements TaskService { } @Override - public Task createTask(Task task) + public Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { - LOGGER.debug("entry to createTask(task = {})", task); + LOGGER.debug("entry to createTask(task = {})", taskToCreate); try { taskanaEngineImpl.openConnection(); + TaskImpl task = (TaskImpl) taskToCreate; workbasketService.getWorkbasket(task.getWorkbasketId()); workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND); Classification classification = task.getClassification(); if (classification == null) { throw new ClassificationNotFoundException(null); } - taskanaEngine.getClassificationService().getClassification(classification.getKey(), ""); + taskanaEngine.getClassificationService().getClassification(classification.getKey(), classification.getDomain()); standardSettings(task); @@ -203,7 +204,7 @@ public class TaskServiceImpl implements TaskService { Task result = null; try { taskanaEngineImpl.openConnection(); - Task task = getTaskById(taskId); + TaskImpl task = (TaskImpl) getTaskById(taskId); // transfer requires TRANSFER in source and APPEND on destination workbasket workbasketService.checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND); @@ -240,7 +241,7 @@ public class TaskServiceImpl implements TaskService { Task result = null; try { taskanaEngineImpl.openConnection(); - Task task = getTaskById(taskId); + TaskImpl task = (TaskImpl) getTaskById(taskId); task.setRead(true); task.setModified(Timestamp.valueOf(LocalDateTime.now())); taskMapper.update(task); @@ -263,24 +264,25 @@ public class TaskServiceImpl implements TaskService { throws WorkbasketNotFoundException, NotAuthorizedException { LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId, taskState); - List result = null; + List results = new ArrayList<>(); try { taskanaEngineImpl.openConnection(); workbasketService.checkAuthorization(workbasketId, WorkbasketAuthorization.READ); - result = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState); + List tasks = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState); + tasks.stream().forEach(t -> results.add((Task) t)); } finally { taskanaEngineImpl.returnConnection(); if (LOGGER.isDebugEnabled()) { - int numberOfResultObjects = result == null ? 0 : result.size(); + int numberOfResultObjects = results == null ? 0 : results.size(); LOGGER.debug( "exit from getTasksByWorkbasketIdAndState(workbasketId, taskState). Returning {} resulting Objects: {} ", - numberOfResultObjects, LoggerUtils.listToString(result)); + numberOfResultObjects, LoggerUtils.listToString(results)); } } - return (result == null) ? new ArrayList<>() : result; + return (results == null) ? new ArrayList<>() : results; } - private void standardSettings(Task task) { + private void standardSettings(TaskImpl task) { Timestamp now = new Timestamp(System.currentTimeMillis()); task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK)); task.setState(TaskState.READY); @@ -357,4 +359,8 @@ public class TaskServiceImpl implements TaskService { return taskSummaries; } + @Override + public Task newTask() { + return new TaskImpl(); + } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java b/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java index 8464cb920..0cf650e90 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java @@ -10,11 +10,11 @@ import org.apache.ibatis.annotations.Select; import pro.taskana.impl.ClassificationQueryImpl; import pro.taskana.impl.ObjectReferenceQueryImpl; +import pro.taskana.impl.TaskImpl; import pro.taskana.impl.TaskQueryImpl; import pro.taskana.model.ClassificationImpl; import pro.taskana.impl.WorkbasketQueryImpl; import pro.taskana.model.ObjectReference; -import pro.taskana.model.Task; import pro.taskana.model.Workbasket; /** @@ -95,7 +95,7 @@ public interface QueryMapper { @Result(property = "custom8", column = "CUSTOM_8"), @Result(property = "custom9", column = "CUSTOM_9"), @Result(property = "custom10", column = "CUSTOM_10") }) - List queryTasks(TaskQueryImpl taskQuery); + List queryTasks(TaskQueryImpl taskQuery); @Select("