Merge pull request #8 from eberhardmayer/master2

added permission filter to workbaskets
This commit is contained in:
holgerhagen 2017-07-03 12:14:50 +02:00 committed by GitHub
commit 51a72a757e
11 changed files with 415 additions and 90 deletions

View File

@ -92,7 +92,8 @@ public interface WorkbasketService {
* if the workbasket do not exist
* @throws NotAuthorizedException
*/
public void checkPermission(String workbasketId, WorkbasketAuthorization authorization) throws NotAuthorizedException;
public void checkPermission(String workbasketId, WorkbasketAuthorization authorization)
throws NotAuthorizedException;
/**
* This method get one WorkbasketAuthorization with an id
@ -103,7 +104,7 @@ public interface WorkbasketService {
*/
public WorkbasketAccessItem getWorkbasketAuthorization(String id);
/**
/**
* Get all authorizations for a Workbasket.
*
* @param workbasketId
@ -111,4 +112,13 @@ public interface WorkbasketService {
*/
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId);
/**
* This method provides workbaskets via an permission
*
* @param permission
* as String like in this enum: {@link WorkbasketAuthorization}
* @return all filtered workbaskets
*/
List<Workbasket> getWorkbaskets(List<String> permission);
}

View File

@ -48,6 +48,12 @@ public class WorkbasketServiceImpl implements WorkbasketService {
return workbasket;
}
@Override
public List<Workbasket> getWorkbaskets(List<String> permissions) {
List<Workbasket> workbaskets = workbasketMapper.findByPermission(permissions, CurrentUserContext.getUserid());
return workbaskets;
}
@Override
public List<Workbasket> getWorkbaskets() {
List<Workbasket> workbaskets = workbasketMapper.findAll();

View File

@ -40,7 +40,7 @@ public interface WorkbasketMapper {
@Result(property = "distributionTargets", column = "ID", javaType = List.class, many = @Many(fetchType = FetchType.DEFAULT, select="findByDistributionTargets")) })
public List<Workbasket> findByDistributionTargets(@Param("id") String id);
@Select("Select * FROM WORKBASKET ORDER BY id")
@Select("SELECT * FROM WORKBASKET ORDER BY id")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "tenantId", column = "TENANT_ID"),
@ -51,6 +51,27 @@ public interface WorkbasketMapper {
@Result(property = "owner", column = "OWNER"),
@Result(property = "distributionTargets", column = "ID", javaType = List.class, many = @Many(fetchType = FetchType.DEFAULT, select="findByDistributionTargets")) })
public List<Workbasket> findAll();
@Select("<script>SELECT W.ID, W.TENANT_ID, W.CREATED, W.MODIFIED, W.NAME, W.DESCRIPTION, W.OWNER FROM WORKBASKET AS W "
+ "INNER JOIN WORKBASKET_ACCESS_LIST AS ACL "
+ "ON (W.ID = ACL.WORKBASKET_ID AND USER_ID = #{userId}) "
+ "WHERE <foreach collection='permissions' item='permission' separator=' AND '>"
+ "<if test=\"permission == 'OPEN'\">OPEN</if>"
+ "<if test=\"permission == 'READ'\">READ</if>"
+ "<if test=\"permission == 'APPEND'\">APPEND</if>"
+ "<if test=\"permission == 'TRANSFER'\">TRANSFER</if>"
+ "<if test=\"permission == 'DISTRIBUTE'\">DISTRIBUTE</if> = 1 </foreach> "
+ "ORDER BY id</script>")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "tenantId", column = "TENANT_ID"),
@Result(property = "created", column = "CREATED"),
@Result(property = "modified", column = "MODIFIED"),
@Result(property = "name", column = "NAME"),
@Result(property = "description", column = "DESCRIPTION"),
@Result(property = "owner", column = "OWNER"),
@Result(property = "distributionTargets", column = "ID", javaType = List.class, many = @Many(fetchType = FetchType.DEFAULT, select="findByDistributionTargets")) })
public List<Workbasket> findByPermission(@Param("permissions") List<String> permissions, @Param("userId") String userId);
@Insert("INSERT INTO WORKBASKET (ID, TENANT_ID, CREATED, MODIFIED, NAME, DESCRIPTION, OWNER) VALUES (#{workbasket.id}, #{workbasket.tenantId}, #{workbasket.created}, #{workbasket.modified}, #{workbasket.name}, #{workbasket.description}, #{workbasket.owner})")
@Options(keyProperty = "id", keyColumn="ID")
@ -62,4 +83,4 @@ public interface WorkbasketMapper {
@Delete("DELETE FROM WORKBASKET where id = #{id}")
public void delete(@Param("id") String id);
}
}

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>

View File

@ -1,46 +1,50 @@
package org.taskana.impl;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.taskana.CategoryService;
import org.taskana.TaskanaEngine;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.taskana.model.Category;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import javax.security.auth.login.LoginException;
import java.io.FileNotFoundException;
import java.sql.SQLException;
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;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.taskana.model.Category;
import org.taskana.model.mappings.CategoryMapper;
@RunWith(MockitoJUnitRunner.class)
public class CategoryServiceImplTest {
static int counter = 0;
private CategoryService categoryService;
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:workbasket-test-db" + counter++);
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
@InjectMocks
CategoryServiceImpl categoryService;
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
categoryService = te.getCategoryService();
}
@Mock
CategoryMapper categoryMapper;
@Test
public void testInsertCategory() {
doNothing().when(categoryMapper).insert(any());
Category category = new Category();
category.setId("0");
categoryService.insertCategory(category);
when(categoryMapper.findById(any())).thenReturn(category);
Assert.assertNotNull(categoryService.selectCategoryById(category.getId()));
}
@Test
public void testFindAllCategories() {
doNothing().when(categoryMapper).insert(any());
Category category0 = new Category();
category0.setId("0");
category0.setParentCategoryId("");
@ -49,12 +53,19 @@ public class CategoryServiceImplTest {
category1.setId("1");
category1.setParentCategoryId("");
categoryService.insertCategory(category1);
List<Category> categories = new ArrayList<>();
categories.add(category0);
when(categoryMapper.findByParentId("")).thenReturn(categories);
Assert.assertEquals(2, categoryService.selectCategories().size());
verify(categoryMapper, atLeast(2)).insert(any());
Assert.assertEquals(1, categoryService.selectCategories().size());
}
@Test
public void testFindByParentCategory() {
doNothing().when(categoryMapper).insert(any());
Category category0 = new Category();
category0.setId("0");
category0.setParentCategoryId("0");
@ -64,11 +75,21 @@ public class CategoryServiceImplTest {
category1.setParentCategoryId("0");
categoryService.insertCategory(category1);
List<Category> categories = new ArrayList<>();
categories.add(category0);
categories.add(category1);
when(categoryMapper.findByParentId(any())).thenReturn(categories);
verify(categoryMapper, atLeast(2)).insert(any());
Assert.assertEquals(2, categoryService.selectCategoriesByParentId("0").size());
}
@Test
public void testModifiedCategory() {
doNothing().when(categoryMapper).insert(any());
doNothing().when(categoryMapper).update(any());
Category category = new Category();
categoryService.insertCategory(category);
category.setDescription("TEST EVERYTHING");

View File

@ -1,53 +1,55 @@
package org.taskana.impl;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import javax.security.auth.login.LoginException;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.taskana.TaskanaEngine;
import org.taskana.WorkbasketService;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.taskana.exceptions.NotAuthorizedException;
import org.taskana.exceptions.WorkbasketNotFoundException;
import org.taskana.model.Workbasket;
import org.taskana.model.WorkbasketAccessItem;
import org.taskana.model.mappings.DistributionTargetMapper;
import org.taskana.model.mappings.WorkbasketAccessMapper;
import org.taskana.model.mappings.WorkbasketMapper;
@RunWith(MockitoJUnitRunner.class)
public class WorkbasketServiceImplTest {
WorkbasketService workbasketServiceImpl;
static int counter = 0;
@InjectMocks
WorkbasketServiceImpl workbasketServiceImpl;
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:workbasket-test-db2" + counter++);
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
workbasketServiceImpl = te.getWorkbasketService();
}
@Mock
WorkbasketMapper workbasketMapper;
@Mock
DistributionTargetMapper distributionTargetMapper;
@Mock
WorkbasketAccessMapper workbasketAccessMapper;
@Test
public void testInsertWorkbasket() throws NotAuthorizedException {
int before = workbasketServiceImpl.getWorkbaskets().size();
doNothing().when(workbasketMapper).insert(any());
Workbasket workbasket = new Workbasket();
workbasket.setId("1");
workbasketServiceImpl.createWorkbasket(workbasket);
Assert.assertEquals(before + 1, workbasketServiceImpl.getWorkbaskets().size());
Assert.assertEquals("1", workbasket.getId());
}
@Test
public void testSelectAllWorkbaskets() throws NotAuthorizedException {
int before = workbasketServiceImpl.getWorkbaskets().size();
doNothing().when(workbasketMapper).insert(any());
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
workbasketServiceImpl.createWorkbasket(workbasket0);
@ -57,11 +59,14 @@ public class WorkbasketServiceImplTest {
Workbasket workbasket2 = new Workbasket();
workbasket2.setId("2");
workbasketServiceImpl.createWorkbasket(workbasket2);
Assert.assertEquals(before + 3, workbasketServiceImpl.getWorkbaskets().size());
verify(workbasketMapper, atLeast(3)).insert(any());
}
@Test
public void testSelectWorkbasket() throws WorkbasketNotFoundException, NotAuthorizedException {
doNothing().when(workbasketMapper).insert(any());
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
workbasketServiceImpl.createWorkbasket(workbasket0);
@ -71,6 +76,11 @@ public class WorkbasketServiceImplTest {
Workbasket workbasket2 = new Workbasket();
workbasket2.setId("2");
workbasketServiceImpl.createWorkbasket(workbasket2);
verify(workbasketMapper, atLeast(3)).insert(any());
when(workbasketMapper.findById(any())).thenReturn(workbasket2);
Workbasket foundWorkbasket = workbasketServiceImpl.getWorkbasket("2");
Assert.assertEquals("2", foundWorkbasket.getId());
}
@ -82,6 +92,8 @@ public class WorkbasketServiceImplTest {
@Test
public void testSelectWorkbasketWithDistribution() throws WorkbasketNotFoundException, NotAuthorizedException {
doNothing().when(workbasketMapper).insert(any());
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
Workbasket workbasket1 = new Workbasket();
@ -92,6 +104,9 @@ public class WorkbasketServiceImplTest {
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workbasketServiceImpl.createWorkbasket(workbasket2);
when(workbasketMapper.findById(any())).thenReturn(workbasket2);
Workbasket foundWorkbasket = workbasketServiceImpl.getWorkbasket("2");
Assert.assertEquals("2", foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
@ -99,6 +114,8 @@ public class WorkbasketServiceImplTest {
@Test
public void testUpdateWorkbasket() throws Exception {
doNothing().when(workbasketMapper).insert(any());
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
Workbasket workbasket1 = new Workbasket();
@ -114,48 +131,57 @@ public class WorkbasketServiceImplTest {
workbasket2.getDistributionTargets().clear();
workbasket2.getDistributionTargets().add(workbasket3);
Thread.sleep(100);
doNothing().when(workbasketMapper).update(any());
workbasketServiceImpl.updateWorkbasket(workbasket2);
when(workbasketMapper.findById("2")).thenReturn(workbasket2);
Workbasket foundBasket = workbasketServiceImpl.getWorkbasket(workbasket2.getId());
when(workbasketMapper.findById("1")).thenReturn(workbasket1);
when(workbasketMapper.findById("3")).thenReturn(workbasket1);
List<Workbasket> distributionTargets = foundBasket.getDistributionTargets();
Assert.assertEquals(1, distributionTargets.size());
Assert.assertEquals("3", distributionTargets.get(0).getId());
Assert.assertNotEquals(workbasketServiceImpl.getWorkbasket("2").getCreated(),
workbasketServiceImpl.getWorkbasket("2").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("1").getCreated(),
workbasketServiceImpl.getWorkbasket("1").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("3").getCreated(),
workbasketServiceImpl.getWorkbasket("3").getModified());
Assert.assertNotEquals(workbasketServiceImpl.getWorkbasket("2").getCreated(), workbasketServiceImpl.getWorkbasket("2").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("1").getCreated(), workbasketServiceImpl.getWorkbasket("1").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("3").getCreated(), workbasketServiceImpl.getWorkbasket("3").getModified());
}
@Test
public void testInsertWorkbasketAccessUser() throws NotAuthorizedException {
doNothing().when(workbasketAccessMapper).insert(any());
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketId("1");
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
accessItem = workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertEquals(1, workbasketServiceImpl.getAllAuthorizations().size());
Assert.assertNotNull(accessItem.getId());
}
@Test
public void testUpdateWorkbasketAccessUser() throws NotAuthorizedException {
doNothing().when(workbasketAccessMapper).insert(any());
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketId("1");
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
accessItem = workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertEquals(1, workbasketServiceImpl.getAllAuthorizations().size());
Assert.assertNotNull(accessItem.getId());
doNothing().when(workbasketAccessMapper).update(any());
accessItem.setUserId("Zaphod Beeblebrox");
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
Assert.assertEquals("Zaphod Beeblebrox", workbasketServiceImpl.getWorkbasketAuthorization(accessItem.getId()).getUserId());
Assert.assertEquals("Zaphod Beeblebrox", accessItem.getUserId());
}
}

View File

@ -0,0 +1,79 @@
package org.taskana.impl.integration;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.taskana.CategoryService;
import org.taskana.TaskanaEngine;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.taskana.model.Category;
import javax.security.auth.login.LoginException;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.time.LocalDate;
public class CategoryServiceImplIntTest {
static int counter = 0;
private CategoryService categoryService;
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test-db-category" + counter++);
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
categoryService = te.getCategoryService();
}
@Test
public void testInsertCategory() {
Category category = new Category();
category.setId("0");
categoryService.insertCategory(category);
Assert.assertNotNull(categoryService.selectCategoryById(category.getId()));
}
@Test
public void testFindAllCategories() {
Category category0 = new Category();
category0.setId("0");
category0.setParentCategoryId("");
categoryService.insertCategory(category0);
Category category1 = new Category();
category1.setId("1");
category1.setParentCategoryId("");
categoryService.insertCategory(category1);
Assert.assertEquals(2, categoryService.selectCategories().size());
}
@Test
public void testFindByParentCategory() {
Category category0 = new Category();
category0.setId("0");
category0.setParentCategoryId("0");
categoryService.insertCategory(category0);
Category category1 = new Category();
category1.setId("1");
category1.setParentCategoryId("0");
categoryService.insertCategory(category1);
Assert.assertEquals(2, categoryService.selectCategoriesByParentId("0").size());
}
@Test
public void testModifiedCategory() {
Category category = new Category();
categoryService.insertCategory(category);
category.setDescription("TEST EVERYTHING");
categoryService.updateCategory(category);
Assert.assertEquals(category.getModified().toString(), LocalDate.now().toString());
}
}

View File

@ -1,4 +1,4 @@
package org.taskana.impl;
package org.taskana.impl.integration;
import java.io.FileNotFoundException;
import java.sql.SQLException;
@ -10,6 +10,8 @@ import org.taskana.TaskanaEngine;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.taskana.exceptions.NotAuthorizedException;
import org.taskana.exceptions.TaskNotFoundException;
import org.taskana.impl.TaskServiceImpl;
import org.taskana.impl.TaskanaEngineImpl;
import org.taskana.model.Task;
public class TaskServiceImplTransactionTest {
@ -17,7 +19,7 @@ public class TaskServiceImplTransactionTest {
@Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:workbasket-test-db45");
ds.setURL("jdbc:h2:mem:test-db-taskservice-int1");
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, true, false);
@ -42,7 +44,7 @@ public class TaskServiceImplTransactionTest {
public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:workbasket-test-db46");
ds.setURL("jdbc:h2:mem:test-db-taskservice-int2");
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);

View File

@ -0,0 +1,161 @@
package org.taskana.impl.integration;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.security.auth.login.LoginException;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.taskana.TaskanaEngine;
import org.taskana.WorkbasketService;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.taskana.exceptions.NotAuthorizedException;
import org.taskana.exceptions.WorkbasketNotFoundException;
import org.taskana.model.Workbasket;
import org.taskana.model.WorkbasketAccessItem;
public class WorkbasketServiceImplIntTest {
WorkbasketService workbasketServiceImpl;
static int counter = 0;
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test-db-workbasket" + counter++);
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
workbasketServiceImpl = te.getWorkbasketService();
}
@Test
public void testInsertWorkbasket() throws NotAuthorizedException {
int before = workbasketServiceImpl.getWorkbaskets().size();
Workbasket workbasket = new Workbasket();
workbasket.setId("1");
workbasketServiceImpl.createWorkbasket(workbasket);
Assert.assertEquals(before + 1, workbasketServiceImpl.getWorkbaskets().size());
}
@Test
public void testSelectAllWorkbaskets() throws NotAuthorizedException {
int before = workbasketServiceImpl.getWorkbaskets().size();
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
workbasketServiceImpl.createWorkbasket(workbasket0);
Workbasket workbasket1 = new Workbasket();
workbasket1.setId("1");
workbasketServiceImpl.createWorkbasket(workbasket1);
Workbasket workbasket2 = new Workbasket();
workbasket2.setId("2");
workbasketServiceImpl.createWorkbasket(workbasket2);
Assert.assertEquals(before + 3, workbasketServiceImpl.getWorkbaskets().size());
}
@Test
public void testSelectWorkbasket() throws WorkbasketNotFoundException, NotAuthorizedException {
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
workbasketServiceImpl.createWorkbasket(workbasket0);
Workbasket workbasket1 = new Workbasket();
workbasket1.setId("1");
workbasketServiceImpl.createWorkbasket(workbasket1);
Workbasket workbasket2 = new Workbasket();
workbasket2.setId("2");
workbasketServiceImpl.createWorkbasket(workbasket2);
Workbasket foundWorkbasket = workbasketServiceImpl.getWorkbasket("2");
Assert.assertEquals("2", foundWorkbasket.getId());
}
@Test(expected = WorkbasketNotFoundException.class)
public void testGetWorkbasketFail() throws WorkbasketNotFoundException {
workbasketServiceImpl.getWorkbasket("fail");
}
@Test
public void testSelectWorkbasketWithDistribution() throws WorkbasketNotFoundException, NotAuthorizedException {
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
Workbasket workbasket1 = new Workbasket();
workbasket1.setId("1");
Workbasket workbasket2 = new Workbasket();
workbasket2.setId("2");
workbasket2.setDistributionTargets(new ArrayList<>());
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workbasketServiceImpl.createWorkbasket(workbasket2);
Workbasket foundWorkbasket = workbasketServiceImpl.getWorkbasket("2");
Assert.assertEquals("2", foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
}
@Test
public void testUpdateWorkbasket() throws Exception {
Workbasket workbasket0 = new Workbasket();
workbasket0.setId("0");
Workbasket workbasket1 = new Workbasket();
workbasket1.setId("1");
Workbasket workbasket2 = new Workbasket();
workbasket2.setId("2");
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workbasketServiceImpl.createWorkbasket(workbasket2);
Workbasket workbasket3 = new Workbasket();
workbasket3.setId("3");
workbasket2.getDistributionTargets().clear();
workbasket2.getDistributionTargets().add(workbasket3);
Thread.sleep(100);
workbasketServiceImpl.updateWorkbasket(workbasket2);
Workbasket foundBasket = workbasketServiceImpl.getWorkbasket(workbasket2.getId());
List<Workbasket> distributionTargets = foundBasket.getDistributionTargets();
Assert.assertEquals(1, distributionTargets.size());
Assert.assertEquals("3", distributionTargets.get(0).getId());
Assert.assertNotEquals(workbasketServiceImpl.getWorkbasket("2").getCreated(),
workbasketServiceImpl.getWorkbasket("2").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("1").getCreated(),
workbasketServiceImpl.getWorkbasket("1").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("3").getCreated(),
workbasketServiceImpl.getWorkbasket("3").getModified());
}
@Test
public void testInsertWorkbasketAccessUser() throws NotAuthorizedException {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketId("1");
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertEquals(1, workbasketServiceImpl.getAllAuthorizations().size());
}
@Test
public void testUpdateWorkbasketAccessUser() throws NotAuthorizedException {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketId("1");
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertEquals(1, workbasketServiceImpl.getAllAuthorizations().size());
accessItem.setUserId("Zaphod Beeblebrox");
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
Assert.assertEquals("Zaphod Beeblebrox", workbasketServiceImpl.getWorkbasketAuthorization(accessItem.getId()).getUserId());
}
}

View File

@ -1,16 +1,20 @@
package org.taskana.rest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.taskana.WorkbasketService;
import org.taskana.exceptions.NotAuthorizedException;
@ -26,8 +30,17 @@ public class WorkbasketController {
private WorkbasketService workbasketService;
@GetMapping
public List<Workbasket> getWorkbaskets() {
return workbasketService.getWorkbaskets();
public List<Workbasket> getWorkbaskets(@RequestParam MultiValueMap<String, String> params) {
if (params.containsKey("requiredPermission")) {
List<String> permissions = new ArrayList<>();
params.get("requiredPermission").stream().forEach(item -> {
permissions.addAll(Arrays.asList(item.split(",")));
});
return workbasketService.getWorkbaskets(permissions);
} else {
return workbasketService.getWorkbaskets();
}
}
@RequestMapping(value = "/{workbasketid}")

View File

@ -12,12 +12,11 @@ export class RestConnectorService {
constructor(private http: Http) { }
getAllWorkBaskets(): Observable<Workbasket[]> {
return this.http.get(environment.taskanaRestUrl + "/v1/workbaskets", this.createAuthorizationHeader())
return this.http.get(environment.taskanaRestUrl + "/v1/workbaskets?requiredPermission=OPEN", this.createAuthorizationHeader())
.map(res => res.json());
}
findTaskWithWorkbaskets(basketName: string): Observable<Task[]> {
return this.http.get(environment.taskanaRestUrl + "/v1/tasks?workbasketid=" + basketName + "&state=READY&state=CLAIMED", this.createAuthorizationHeader())
.map(res => res.json());
}
@ -42,7 +41,7 @@ export class RestConnectorService {
.map(res => res.json());
}
private createAuthorizationHeader(){
private createAuthorizationHeader() {
let headers: Headers = new Headers();
headers.append("Authorization", "Basic TWF4OnRlc3Q=");