Skip to content

Commit

Permalink
TSK-90 Use task.workbasketKey as foreign key into workbasket and reje…
Browse files Browse the repository at this point in the history
…ct implicit creation of distribution targets
  • Loading branch information
BerndBreier authored and holgerhagen committed Dec 20, 2017
1 parent 791025f commit 193e3c3
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public TaskQuery createTaskQuery() {
@Override
public List<Task> getTasksByWorkbasketKeyAndState(String workbasketKey, TaskState taskState)
throws WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getTasksByWorkbasketKeyAndState(workbasketId = {}, taskState = {})", workbasketKey,
LOGGER.debug("entry to getTasksByWorkbasketKeyAndState(workbasketKey = {}, taskState = {})", workbasketKey,
taskState);
List<Task> results = new ArrayList<>();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public Workbasket createWorkbasket(Workbasket newWorkbasket)
public Workbasket updateWorkbasket(Workbasket workbasketToUpdate)
throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException {
LOGGER.debug("entry to updateWorkbasket(workbasket)", workbasketToUpdate);

Workbasket result = null;
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketToUpdate;
try {
Expand Down
13 changes: 11 additions & 2 deletions lib/taskana-core/src/main/java/pro/taskana/model/TaskSummary.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package pro.taskana.model;

/**
* Entity which contains the most important
* informations about a Task.
* Entity which contains the most important informations about a Task.
*/
public class TaskSummary {

Expand All @@ -16,12 +15,15 @@ public class TaskSummary {
public String getTaskId() {
return taskId;
}

public void setTaskId(String taskId) {
this.taskId = taskId;
}

public String getTaskName() {
return taskName;
}

public void setTaskName(String taskName) {
this.taskName = taskName;
}
Expand All @@ -33,21 +35,27 @@ public String getWorkbasketKey() {
public void setWorkbasketKey(String workbasketKey) {
this.workbasketKey = workbasketKey;
}

public String getWorkbasketName() {
return workbasketName;
}

public void setWorkbasketName(String workbasketName) {
this.workbasketName = workbasketName;
}

public String getClassificationKey() {
return classificationKey;
}

public void setClassificationKey(String classificationKey) {
this.classificationKey = classificationKey;
}

public String getClassificationName() {
return classificationName;
}

public void setClassificationName(String classificationName) {
this.classificationName = classificationName;
}
Expand Down Expand Up @@ -140,4 +148,5 @@ public String toString() {
builder.append("]");
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class WorkbasketAccessItem {
private boolean permCustom7;
private boolean permCustom8;


public String getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import pro.taskana.impl.TaskImpl;
import pro.taskana.impl.TaskQueryImpl;
import pro.taskana.impl.WorkbasketImpl;
import pro.taskana.model.ClassificationImpl;
import pro.taskana.impl.WorkbasketQueryImpl;
import pro.taskana.model.ClassificationImpl;
import pro.taskana.model.ObjectReference;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pro.taskana.model.mappings;

import java.sql.Date;
import java.util.List;
import java.util.Map;

Expand All @@ -18,6 +19,7 @@
import pro.taskana.impl.TaskImpl;
import pro.taskana.impl.persistence.MapTypeHandler;
import pro.taskana.model.ClassificationImpl;
import pro.taskana.model.DueWorkbasketCounter;
import pro.taskana.model.ObjectReference;
import pro.taskana.model.TaskState;
import pro.taskana.model.TaskSummary;
Expand Down Expand Up @@ -71,6 +73,12 @@ public interface TaskMapper {
})
TaskImpl findById(@Param("id") String id);

@Results({@Result(column = "DUE_DATE", property = "due"),
@Result(column = "WORKBASKET_KEY", property = "workbasketKey"),
@Result(column = "counter", property = "taskCounter")})
List<DueWorkbasketCounter> getTaskCountByWorkbasketIdAndDaysInPastAndState(@Param("fromDate") Date fromDate,
@Param("status") List<TaskState> states);

@Insert("INSERT INTO TASK(ID, CREATED, CLAIMED, COMPLETED, MODIFIED, PLANNED, DUE, NAME, DESCRIPTION, PRIORITY, STATE, CLASSIFICATION_KEY, WORKBASKET_KEY, BUSINESS_PROCESS_ID, PARENT_BUSINESS_PROCESS_ID, 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) "
+ "VALUES(#{id}, #{created}, #{claimed}, #{completed}, #{modified}, #{planned}, #{due}, #{name}, #{description}, #{priority}, #{state}, #{classification.key}, #{workbasketKey}, #{businessProcessId}, #{parentBusinessProcessId}, #{owner}, #{primaryObjRef.id}, #{isRead}, #{isTransferred}, #{customAttributes,jdbcType=BLOB,javaType=java.util.Map,typeHandler=pro.taskana.impl.persistence.MapTypeHandler}, #{custom1}, #{custom2}, #{custom3}, #{custom4}, #{custom5}, #{custom6}, #{custom7}, #{custom8}, #{custom9}, #{custom10})")
@Options(keyProperty = "id", keyColumn = "ID")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package pro.taskana.model.mappings;

import org.apache.ibatis.annotations.*;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import pro.taskana.model.WorkbasketAccessItem;

import java.util.List;
/**
* This class is the mybatis mapping of workbasket access items.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public interface WorkbasketMapper {
+ "<if test=\"authorization.name() == 'CUSTOM_8'\">PERM_CUSTOM_8</if> = 1 </foreach> "
+ "ORDER BY id</script>")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "id", column = "ID"),
@Result(property = "key", column = "KEY"),
@Result(property = "created", column = "CREATED"),
@Result(property = "modified", column = "MODIFIED"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotF
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasketByKey(any());
verify(taskanaEngineMock, times(1)).getClassificationService();

verify(classificationServiceMock, times(1)).getClassification(any(), any());
verify(taskMapperMock, times(1)).insert(expectedTask);
verify(taskanaEngineImpl, times(1)).returnConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void testStartTransactionFail()
classification.setKey("TEST");
taskanaEngine.getClassificationService().createClassification(classification);

Task task = taskServiceImpl.newTask();
TaskImpl task = (TaskImpl) taskServiceImpl.newTask();
task.setName("Unit Test Task");
task.setWorkbasketKey(wb.getKey());
task.setClassification(classification);
Expand Down Expand Up @@ -284,7 +284,10 @@ public void shouldThrowWorkbasketNotFoundExceptionByInvalidWorkbasketParameter()
wb.setName("wb");
wb.setType(WorkbasketType.GROUP);
wb.setDomain("novatec");
workbasketService.createWorkbasket(wb);
taskServiceImpl.getTaskSummariesByWorkbasketKey("1");
wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
workbasketService.createWorkbasket(wb);
taskServiceImpl.getTaskSummariesByWorkbasketKey("1");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorize
wb.setKey("k1");
workbasketService.createWorkbasket(wb);

Task test = taskServiceImpl.newTask();
test.setWorkbasketKey("k1");
test.setPrimaryObjRef(objectReference);
test.setPlanned(tomorrow);
test.setClassification(classification);
test = taskServiceImpl.createTask(test);

Task task = this.generateDummyTask();
task.setClassification(classification);
task.setName("Name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,11 @@ public void testGetWorkbasketsForCurrentUserAndPermission()
throws NotAuthorizedException, InvalidWorkbasketException, WorkbasketNotFoundException {
generateSampleDataForQuery();

String userName = "eberhardt";
String userName = "Bernd";
String[] groupNames = {"group2", "group3"};
List<WorkbasketAuthorization> authorizations = new ArrayList<WorkbasketAuthorization>();

authorizations.add(WorkbasketAuthorization.OPEN);
Assert.assertTrue(1 == getWorkbasketsForPrincipalesAndPermissions(userName, groupNames, authorizations));

userName = "Bernd";
Assert.assertTrue(2 == getWorkbasketsForPrincipalesAndPermissions(userName, groupNames, authorizations));

authorizations.add(WorkbasketAuthorization.CUSTOM_4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ public void testSelectWorkbasketWithDistribution()
workbasket1.setName("Megabasket");
workbasket1.setDomain("D2");
workbasket1.setType(WorkbasketType.GROUP);
workBasketService.createWorkbasket(workbasket1);
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workBasketService.createWorkbasket(workbasket1);
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
Expand Down Expand Up @@ -228,8 +228,8 @@ public void testUpdateWorkbasket() throws Exception {
workbasket0.setName("Superbasket");
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");

workBasketService.createWorkbasket(workbasket0);

WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
Expand All @@ -256,7 +256,7 @@ public void testUpdateWorkbasket() throws Exception {
workbasket3.setName("hm ... irgend ein basket");
workbasket3.setType(WorkbasketType.GROUP);
workbasket3.setDomain("novatec");
workbasket3 = workBasketService.createWorkbasket(workbasket3);
workBasketService.createWorkbasket(workbasket3);
workbasket2.getDistributionTargets().clear();
workbasket2.getDistributionTargets().add(workbasket3);
Thread.sleep(SLEEP_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundE
throw new RuntimeException();
}


}
6 changes: 3 additions & 3 deletions rest/src/main/java/pro/taskana/rest/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public ResponseEntity<Task> createTask(@RequestBody Task task) {
}
}

@RequestMapping(method = RequestMethod.POST, value = "/{taskId}/transfer/{workbasketId}")
public ResponseEntity<Task> transferTask(@PathVariable String taskId, @PathVariable String workbasketId) {
@RequestMapping(method = RequestMethod.POST, value = "/{taskId}/transfer/{workbasketKey}")
public ResponseEntity<Task> transferTask(@PathVariable String taskId, @PathVariable String workbasketKey) {
try {
Task updatedTask = taskService.transfer(taskId, workbasketId);
Task updatedTask = taskService.transfer(taskId, workbasketKey);
return ResponseEntity.status(HttpStatus.CREATED).body(updatedTask);
} catch (Exception e) {
logger.error("Something went wrong: ", e);
Expand Down
6 changes: 3 additions & 3 deletions rest/src/main/java/pro/taskana/rest/WorkbasketController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public ResponseEntity<?> updateWorkbasket(@PathVariable(value = "workbasketkey")
}
}

@RequestMapping(value = "/{workbasketid}/authorizations", method = RequestMethod.GET)
@RequestMapping(value = "/{workbasketkey}/authorizations", method = RequestMethod.GET)
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(
@PathVariable(value = "workbasketid") String workbasketId) {
return workbasketService.getWorkbasketAuthorizations(workbasketId);
@PathVariable(value = "workbasketkey") String workbasketKey) {
return workbasketService.getWorkbasketAuthorizations(workbasketKey);
}

@RequestMapping(value = "/authorizations", method = RequestMethod.POST)
Expand Down
1 change: 0 additions & 1 deletion rest/src/main/java/pro/taskana/rest/query/TaskFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public List<Task> inspectPrams(MultiValueMap<String, String> params) throws NotA
}
if (params.containsKey(WORKBASKET_KEY)) {
String[] workbaskets = extractCommaSeperatedFields(params.get(WORKBASKET_KEY));
taskQuery.workbasketKeyIn(workbaskets);
}
if (params.containsKey(OWNER)) {
String[] owners = extractCommaSeperatedFields(params.get(OWNER));
Expand Down
2 changes: 2 additions & 0 deletions rest/src/main/resources/sql/sample-data/task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ INSERT INTO TASK VALUES('10', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, null, CURREN
INSERT INTO TASK VALUES('11', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, null, CURRENT_TIMESTAMP, 'Task11', 'Lorem ipsum dolor sit amet. ', 1, 'COMPLETED', '3', 'key2', 'BPI11', 'PBPI11', 'Stefan', '2', false, false, null, null, null, null, null, null, null, null, null, null, null);
INSERT INTO TASK VALUES('12', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, null, CURRENT_TIMESTAMP, 'Task12', 'Lorem ipsum dolor sit amet.', 1, 'COMPLETED', '4', 'key2', 'BPI12', 'PBPI12', 'Frank', '3', false, false, null, null, null, null, null, null, null, null, null, null, null);


INSERT INTO TASK VALUES('13', CURRENT_TIMESTAMP, null, null, CURRENT_TIMESTAMP, null, CURRENT_TIMESTAMP, 'Task12', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus massa turpis, pellentesque ut libero sit aet, malesuada suscipit dolor. Sed volutpat euismod felis sit amet molestie. Fusce ornare purus dui. ', 1, 'READY', '13', 'key2', 'BPI13', 'PBPI13', 'Frank', '1', false, false, null, null, null, null, null, null, null, null, null, null, null);
INSERT INTO TASK VALUES('14', CURRENT_TIMESTAMP, null, null, CURRENT_TIMESTAMP, null, CURRENT_TIMESTAMP, 'Task6', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis vulputate nibh ut malesuada. Etiam ac dictum tellus, nec cursus nunc. Curabitur velit eros, feugiat volutpat laoreet vitae, cursus eu dui. Nulla ut purus sem. Vivamus aliquet odio vitae erat cursus, vitae mattis urna mollis. Nam quam tellus, auctor id volutpat congue, viverra vitae ante. Duis nisi dolor, elementum et mattis at, maximus id velit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis eu condimentum risus. Praesent libero velit, facilisis sit amet maximus non, scelerisque ullamcorper leo. Ut sit amet iaculis eros. Mauris sagittis nibh lacus, at facilisis magna suscipit at. Aliquam finibus tempor odio id commodo. Vivamus aliquam, justo id porta imperdiet, mi.', 1, 'READY', '14', 'key1', 'BPI14', 'PBPI14', 'Frank', '2', false, false, null, null, null, null, null, null, null, null, null, null, null);

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('1', 'key1', 'Elena', true, true, true, true, true, false, false, false, false, false, false, false, false);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('2', 'key2', 'Max', true, true, true, true, true, true, true, true, true, false, false, false, false);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('3', 'key3', 'Simone', true, true, true, true, true, true, true, true, true, true, true, true, true);

0 comments on commit 193e3c3

Please sign in to comment.