Merge pull request #11 from BVier/master

refactor category to classification
This commit is contained in:
Holger Hagen 2017-07-05 08:39:23 +02:00 committed by GitHub
commit 5be3188e72
21 changed files with 456 additions and 435 deletions

View File

@ -1,48 +0,0 @@
package org.taskana;
import org.taskana.model.Category;
import java.util.List;
public interface CategoryService {
/**
* Get all available Categories
*
* @return The List of all Categories
*/
public List<Category> selectCategories();
/**
* Get all Categories with given parent
*
* @param parentId
* the ID of the parent Category
* @return
*/
public List<Category> selectCategoriesByParentId(String parentId);
/**
* Get a Category for a given id
*
* @param id
* @return the requested Category
*/
public Category selectCategoryById(String id);
/**
* Insert a new Category
*
* @param category
* the category to insert
*/
public void insertCategory(Category category);
/**
* Update a Category
*
* @param category
* the Category to update
*/
public void updateCategory(Category category);
}

View File

@ -0,0 +1,48 @@
package org.taskana;
import org.taskana.model.Classification;
import java.util.List;
public interface ClassificationService {
/**
* Get all available Classifications
*
* @return The List of all Classifications
*/
public List<Classification> selectClassifications();
/**
* Get all Classifications with given parent
*
* @param parentId
* the ID of the parent Classification
* @return
*/
public List<Classification> selectClassificationsByParentId(String parentId);
/**
* Get a Classification for a given id
*
* @param id
* @return the requested Classification
*/
public Classification selectClassificationById(String id);
/**
* Insert a new Classification
*
* @param classification
* the classification to insert
*/
public void insertClassification(Classification classification);
/**
* Update a Classification
*
* @param classification
* the Classification to update
*/
public void updateClassification(Classification classification);
}

View File

@ -22,11 +22,11 @@ public interface TaskanaEngine {
public WorkbasketService getWorkbasketService();
/**
* The CategoryService can be used for operations on all Categories
* The ClassificationService can be used for operations on all Categories
*
* @return the TaskService
*/
public CategoryService getCategoryService();
public ClassificationService getClassificationService();
/**
* The Taskana configuration

View File

@ -1,73 +0,0 @@
package org.taskana.impl;
import org.taskana.CategoryService;
import org.taskana.model.Category;
import org.taskana.model.mappings.CategoryMapper;
import java.sql.Date;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
public class CategoryServiceImpl implements CategoryService {
private CategoryMapper categoryMapper;
public CategoryServiceImpl(CategoryMapper categoryMapper) {
super();
this.categoryMapper = categoryMapper;
}
@Override
public List<Category> selectCategories() {
final List<Category> rootCategories = categoryMapper.findByParentId("");
populateChildcategories(rootCategories);
return rootCategories;
}
private void populateChildcategories(final List<Category> categories) {
for (Category category : categories) {
List<Category> childCategories = categoryMapper.findByParentId(category.getId());
category.setChildren(childCategories);
populateChildcategories(childCategories);
}
}
@Override
public List<Category> selectCategoriesByParentId(String parentId) {
return categoryMapper.findByParentId(parentId);
}
@Override
public void insertCategory(Category category) {
category.setId(UUID.randomUUID().toString());
category.setCreated(Date.valueOf(LocalDate.now()));
category.setModified(Date.valueOf(LocalDate.now()));
this.checkServiceLevel(category);
categoryMapper.insert(category);
}
@Override
public void updateCategory(Category category) {
category.setModified(Date.valueOf(LocalDate.now()));
this.checkServiceLevel(category);
categoryMapper.update(category);
}
@Override
public Category selectCategoryById(String id) {
return categoryMapper.findById(id);
}
private void checkServiceLevel(Category category){
if(category.getServiceLevel()!= null){
try {
java.time.Duration.parse(category.getServiceLevel());
} catch (Exception e){
throw new IllegalArgumentException("Invalid timestamp. Please use the format 'PddDThhHmmM'");
}
}
}
}

View File

@ -0,0 +1,73 @@
package org.taskana.impl;
import org.taskana.ClassificationService;
import org.taskana.model.Classification;
import org.taskana.model.mappings.ClassificationMapper;
import java.sql.Date;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
public class ClassificationServiceImpl implements ClassificationService {
private ClassificationMapper classificationMapper;
public ClassificationServiceImpl(ClassificationMapper classificationMapper) {
super();
this.classificationMapper = classificationMapper;
}
@Override
public List<Classification> selectClassifications() {
final List<Classification> rootClassifications = classificationMapper.findByParentId("");
populateChildClassifications(rootClassifications);
return rootClassifications;
}
private void populateChildClassifications(final List<Classification> classifications) {
for (Classification classification : classifications) {
List<Classification> childClassifications = classificationMapper.findByParentId(classification.getId());
classification.setChildren(childClassifications);
populateChildClassifications(childClassifications);
}
}
@Override
public List<Classification> selectClassificationsByParentId(String parentId) {
return classificationMapper.findByParentId(parentId);
}
@Override
public void insertClassification(Classification classification) {
classification.setId(UUID.randomUUID().toString());
classification.setCreated(Date.valueOf(LocalDate.now()));
classification.setModified(Date.valueOf(LocalDate.now()));
this.checkServiceLevel(classification);
classificationMapper.insert(classification);
}
@Override
public void updateClassification(Classification classification) {
classification.setModified(Date.valueOf(LocalDate.now()));
this.checkServiceLevel(classification);
classificationMapper.update(classification);
}
@Override
public Classification selectClassificationById(String id) {
return classificationMapper.findById(id);
}
private void checkServiceLevel(Classification classification){
if(classification.getServiceLevel()!= null){
try {
java.time.Duration.parse(classification.getServiceLevel());
} catch (Exception e){
throw new IllegalArgumentException("Invalid timestamp. Please use the format 'PddDThhHmmM'");
}
}
}
}

View File

@ -8,12 +8,12 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
import org.taskana.CategoryService;
import org.taskana.ClassificationService;
import org.taskana.TaskService;
import org.taskana.TaskanaEngine;
import org.taskana.WorkbasketService;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.taskana.model.mappings.CategoryMapper;
import org.taskana.model.mappings.ClassificationMapper;
import org.taskana.model.mappings.DistributionTargetMapper;
import org.taskana.model.mappings.TaskMapper;
import org.taskana.model.mappings.WorkbasketAccessMapper;
@ -30,7 +30,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
private TaskMapper taskMapper;
private WorkbasketMapper workbasketMapper;
private DistributionTargetMapper distributionTargetMapper;
private CategoryMapper categoryMapper;
private ClassificationMapper classificationMapper;
private WorkbasketAccessMapper workbasketAccessMapper;
private TaskServiceImpl taskServiceImpl;
@ -45,7 +45,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
this.taskMapper = session.getMapper(TaskMapper.class);
this.workbasketMapper = session.getMapper(WorkbasketMapper.class);
this.distributionTargetMapper = session.getMapper(DistributionTargetMapper.class);
this.categoryMapper = session.getMapper(CategoryMapper.class);
this.classificationMapper = session.getMapper(ClassificationMapper.class);
this.workbasketAccessMapper = session.getMapper(WorkbasketAccessMapper.class);
}
@ -63,8 +63,8 @@ public class TaskanaEngineImpl implements TaskanaEngine {
}
@Override
public CategoryService getCategoryService() {
return new CategoryServiceImpl(this.categoryMapper);
public ClassificationService getClassificationService() {
return new ClassificationServiceImpl(this.classificationMapper);
}
@Override
@ -94,7 +94,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
configuration.addMapper(TaskMapper.class);
configuration.addMapper(WorkbasketMapper.class);
configuration.addMapper(DistributionTargetMapper.class);
configuration.addMapper(CategoryMapper.class);
configuration.addMapper(ClassificationMapper.class);
configuration.addMapper(WorkbasketAccessMapper.class);
return new SqlSessionFactoryBuilder().build(configuration);
}

View File

@ -5,20 +5,22 @@ import java.util.ArrayList;
import java.util.List;
/**
* Category entity
* Classification entity
*/
public class Category {
public class Classification {
private String id;
private String tenantId;
private String parentCategoryId;
private String parentClassificationId;
private String category;
private String type;
private Date created;
private Date modified;
private String name;
private String description;
private int priority;
private String serviceLevel; //PddDThhHmmM
private List<Category> children = new ArrayList<>();
private List<Classification> children = new ArrayList<>();
public String getId() {
return id;
@ -36,12 +38,28 @@ public class Category {
this.tenantId = tenantId;
}
public String getParentCategoryId() {
return parentCategoryId;
public String getParentClassificationId() {
return parentClassificationId;
}
public void setParentCategoryId(String parentCategoryId) {
this.parentCategoryId = parentCategoryId;
public void setParentClassificationId(String parentClassificationId) {
this.parentClassificationId = parentClassificationId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public Date getCreated() {
@ -92,15 +110,16 @@ public class Category {
this.serviceLevel = serviceLevel;
}
public List<Category> getChildren() {
public List<Classification> getChildren() {
return children;
}
public void addChild(Category child) {
public void addChild(Classification child) {
children.add(child);
}
public void setChildren(List<Category> children) {
public void setChildren(List<Classification> children) {
this.children = children;
}
}

View File

@ -1,35 +0,0 @@
package org.taskana.model.mappings;
import org.apache.ibatis.annotations.*;
import org.taskana.model.Category;
import java.util.List;
public interface CategoryMapper {
@Select("SELECT * FROM BUSINESS_CATEGORY ORDER BY ID")
@Results({
@Result(property="id", column="ID"),
@Result(property="tenantId", column="TENANT_ID"),
@Result(property="parentCategoryId", column="PARENT_CATEGORY_ID"),
@Result(property="created", column="CREATED"),
@Result(property="modified", column="MODIFIED"),
@Result(property="name", column="NAME"),
@Result(property="description", column="DESCRIPTION"),
@Result(property="priority", column="PRIORITY"),
@Result(property="serviceLevel", column="SERVICE_LEVEL")
})
List<Category> findAll();
@Select("SELECT * FROM BUSINESS_CATEGORY WHERE PARENT_CATEGORY_ID = #{parentCategoryId} ORDER BY ID")
List<Category> findByParentId(@Param("parentCategoryId") String parentId);
@Select("SELECT * FROM BUSINESS_CATEGORY WHERE ID = #{categoryId}")
Category findById(@Param("categoryId") String categoryId);
@Insert("INSERT INTO BUSINESS_CATEGORY (ID, TENANT_ID, PARENT_CATEGORY_ID, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES (#{category.id}, #{category.tenantId}, #{category.parentCategoryId}, #{category.created}, #{category.name}, #{category.description}, #{category.priority}, #{category.serviceLevel})")
void insert(@Param("category") Category category);
@Update(value = "UPDATE BUSINESS_CATEGORY SET TENANT_ID = #{category.tenantId}, PARENT_CATEGORY_ID = #{category.parentCategoryId}, NAME = #{category.name}, DESCRIPTION = #{category.description}, PRIORITY = #{category.priority}, SERVICE_LEVEL = #{category.serviceLevel}, MODIFIED = #{category.modified} WHERE ID = #{category.id}")
void update(@Param("category") Category category);
}

View File

@ -0,0 +1,37 @@
package org.taskana.model.mappings;
import org.apache.ibatis.annotations.*;
import org.taskana.model.Classification;
import java.util.List;
public interface ClassificationMapper {
@Select("SELECT * FROM BUSINESS_CLASSIFICATION ORDER BY ID")
@Results({
@Result(property="id", column="ID"),
@Result(property="tenantId", column="TENANT_ID"),
@Result(property="parentClassificationId", column="PARENT_CLASSIFICATION_ID"),
@Result(property="category", column="CATEGORY"),
@Result(property="type", column="TYPE"),
@Result(property="created", column="CREATED"),
@Result(property="modified", column="MODIFIED"),
@Result(property="name", column="NAME"),
@Result(property="description", column="DESCRIPTION"),
@Result(property="priority", column="PRIORITY"),
@Result(property="serviceLevel", column="SERVICE_LEVEL")
})
List<Classification> findAll();
@Select("SELECT * FROM BUSINESS_CLASSIFICATION WHERE PARENT_CLASSIFICATION_ID = #{parentClassificationId} ORDER BY ID")
List<Classification> findByParentId(@Param("parentClassificationId") String parentId);
@Select("SELECT * FROM BUSINESS_CLASSIFICATION WHERE ID = #{classificationId}")
Classification findById(@Param("classificationId") String classificationId);
@Insert("INSERT INTO BUSINESS_CLASSIFICATION (ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES (#{classification.id}, #{classification.tenantId}, #{classification.parentClassificationId}, #{classification.category}, #{classification.type}, #{classification.created}, #{classification.name}, #{classification.description}, #{classification.priority}, #{classification.serviceLevel})")
void insert(@Param("classification") Classification classification);
@Update(value = "UPDATE BUSINESS_CLASSIFICATION SET TENANT_ID = #{classification.tenantId}, PARENT_CLASSIFICATION_ID = #{classification.parentClassificationId}, CATEGORY = #{classification.category}, TYPE = #{classification.type}, NAME = #{classification.name}, DESCRIPTION = #{classification.description}, PRIORITY = #{classification.priority}, SERVICE_LEVEL = #{classification.serviceLevel}, MODIFIED = #{classification.modified} WHERE ID = #{classification.id}")
void update(@Param("classification") Classification classification);
}

View File

@ -37,10 +37,12 @@ CREATE TABLE IF NOT EXISTS DISTRIBUTION_TARGETS(
PRIMARY KEY (SOURCE_ID, TARGET_ID)
);
CREATE TABLE IF NOT EXISTS BUSINESS_CATEGORY(
CREATE TABLE IF NOT EXISTS BUSINESS_CLASSIFICATION(
ID varchar(255) NOT NULL,
TENANT_ID varchar(255) NULL,
PARENT_CATEGORY_ID varchar(255),
PARENT_CLASSIFICATION_ID varchar(255),
CATEGORY varchar(255),
TYPE varchar(255),
CREATED DATE NULL,
MODIFIED DATE NULL,
NAME varchar(255) NULL,

View File

@ -1,100 +0,0 @@
package org.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.verify;
import static org.mockito.Mockito.when;
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 {
@InjectMocks
CategoryServiceImpl categoryService;
@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("");
categoryService.insertCategory(category0);
Category category1 = new Category();
category1.setId("1");
category1.setParentCategoryId("");
categoryService.insertCategory(category1);
List<Category> categories = new ArrayList<>();
categories.add(category0);
when(categoryMapper.findByParentId("")).thenReturn(categories);
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");
categoryService.insertCategory(category0);
Category category1 = new Category();
category1.setId("1");
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");
categoryService.updateCategory(category);
Assert.assertEquals(category.getModified().toString(), LocalDate.now().toString());
}
}

View File

@ -0,0 +1,97 @@
package org.taskana.impl;
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.Classification;
import org.taskana.model.mappings.ClassificationMapper;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class ClassificationServiceImplTest {
@InjectMocks
ClassificationServiceImpl classificationService;
@Mock
ClassificationMapper classificationMapper;
@Test
public void testInsertClassification() {
doNothing().when(classificationMapper).insert(any());
Classification classification = new Classification();
classification.setId("0");
classificationService.insertClassification(classification);
when(classificationMapper.findById(any())).thenReturn(classification);
Assert.assertNotNull(classificationService.selectClassificationById(classification.getId()));
}
@Test
public void testFindAllClassifications() {
doNothing().when(classificationMapper).insert(any());
Classification classification0 = new Classification();
classification0.setId("0");
classification0.setParentClassificationId("");
classificationService.insertClassification(classification0);
Classification classification1 = new Classification();
classification1.setId("1");
classification1.setParentClassificationId("");
classificationService.insertClassification(classification1);
List<Classification> classifications = new ArrayList<>();
classifications.add(classification0);
when(classificationMapper.findByParentId("")).thenReturn(classifications);
verify(classificationMapper, atLeast(2)).insert(any());
Assert.assertEquals(1, classificationService.selectClassifications().size());
}
@Test
public void testFindByParentClassification() {
doNothing().when(classificationMapper).insert(any());
Classification classification0 = new Classification();
classification0.setId("0");
classification0.setParentClassificationId("0");
classificationService.insertClassification(classification0);
Classification classification1 = new Classification();
classification1.setId("1");
classification1.setParentClassificationId("0");
classificationService.insertClassification(classification1);
List<Classification> classifications = new ArrayList<>();
classifications.add(classification0);
classifications.add(classification1);
when(classificationMapper.findByParentId(any())).thenReturn(classifications);
verify(classificationMapper, atLeast(2)).insert(any());
Assert.assertEquals(2, classificationService.selectClassificationsByParentId("0").size());
}
@Test
public void testModifiedClassification() {
doNothing().when(classificationMapper).insert(any());
doNothing().when(classificationMapper).update(any());
Classification classification = new Classification();
classificationService.insertClassification(classification);
classification.setDescription("TEST EVERYTHING");
classificationService.updateClassification(classification);
Assert.assertEquals(classification.getModified().toString(), LocalDate.now().toString());
}
}

View File

@ -1,79 +0,0 @@
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

@ -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.ClassificationService;
import org.taskana.TaskanaEngine;
import org.taskana.configuration.TaskanaEngineConfiguration;
import org.taskana.model.Classification;
import javax.security.auth.login.LoginException;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.time.LocalDate;
public class ClassificationServiceImplIntTest {
static int counter = 0;
private ClassificationService classificationService;
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test-db-classification" + counter++);
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
classificationService = te.getClassificationService();
}
@Test
public void testInsertClassification() {
Classification classification = new Classification();
classification.setId("0");
classificationService.insertClassification(classification);
Assert.assertNotNull(classificationService.selectClassificationById(classification.getId()));
}
@Test
public void testFindAllClassifications() {
Classification classification0 = new Classification();
classification0.setId("0");
classification0.setParentClassificationId("");
classificationService.insertClassification(classification0);
Classification classification1 = new Classification();
classification1.setId("1");
classification1.setParentClassificationId("");
classificationService.insertClassification(classification1);
Assert.assertEquals(2, classificationService.selectClassifications().size());
}
@Test
public void testFindByParentClassification() {
Classification classification0 = new Classification();
classification0.setId("0");
classification0.setParentClassificationId("0");
classificationService.insertClassification(classification0);
Classification classification1 = new Classification();
classification1.setId("1");
classification1.setParentClassificationId("0");
classificationService.insertClassification(classification1);
Assert.assertEquals(2, classificationService.selectClassificationsByParentId("0").size());
}
@Test
public void testModifiedClassification() {
Classification classification = new Classification();
classificationService.insertClassification(classification);
classification.setDescription("TEST EVERYTHING");
classificationService.updateClassification(classification);
Assert.assertEquals(classification.getModified().toString(), LocalDate.now().toString());
}
}

View File

@ -1,8 +1,5 @@
package org.taskana.impl.integration;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Assert;
import org.junit.Test;
@ -14,12 +11,15 @@ import org.taskana.impl.TaskServiceImpl;
import org.taskana.impl.TaskanaEngineImpl;
import org.taskana.model.Task;
import java.io.FileNotFoundException;
import java.sql.SQLException;
public class TaskServiceImplTransactionTest {
@Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test-db-taskservice-int1");
ds.setURL("jdbc:h2:~/data/test-db-taskservice-int1");
ds.setPassword("sa");
ds.setUser("sa");
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, true, false);

View File

@ -1,53 +0,0 @@
/**
*
*/
package org.taskana.rest;
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.web.bind.annotation.*;
import org.taskana.CategoryService;
import org.taskana.model.Category;
@RestController
@RequestMapping(path = "/v1/categories", produces = { MediaType.APPLICATION_JSON_VALUE })
public class CategoryController {
@Autowired
private CategoryService categoryService;
@RequestMapping
public List<Category> getCategories() {
return categoryService.selectCategories();
}
@RequestMapping(value = "/{categoryId}")
public Category getCategory(@PathVariable String categoryId) {
return categoryService.selectCategoryById(categoryId);
}
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Category> createCategory(@RequestBody Category category) {
try {
categoryService.insertCategory(category);
return ResponseEntity.status(HttpStatus.CREATED).body(category);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Category> updateCategory(@RequestBody Category category) {
try {
categoryService.updateCategory(category);
return ResponseEntity.status(HttpStatus.CREATED).body(category);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}

View File

@ -0,0 +1,53 @@
/**
*
*/
package org.taskana.rest;
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.web.bind.annotation.*;
import org.taskana.ClassificationService;
import org.taskana.model.Classification;
import java.util.List;
@RestController
@RequestMapping(path = "/v1/classifications", produces = { MediaType.APPLICATION_JSON_VALUE })
public class ClassificationController {
@Autowired
private ClassificationService classificationService;
@RequestMapping
public List<Classification> getClassifications() {
return classificationService.selectClassifications();
}
@RequestMapping(value = "/{classificationId}")
public Classification getClassification(@PathVariable String classificationId) {
return classificationService.selectClassificationById(classificationId);
}
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Classification> createClassification(@RequestBody Classification classification) {
try {
classificationService.insertClassification(classification);
return ResponseEntity.status(HttpStatus.CREATED).body(classification);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Classification> updateClassification(@RequestBody Classification classification) {
try {
classificationService.updateClassification(classification);
return ResponseEntity.status(HttpStatus.CREATED).body(classification);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}

View File

@ -1,9 +1,6 @@
package org.taskana.rest;
import java.sql.SQLException;
import javax.annotation.PostConstruct;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -14,7 +11,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.SpringHandlerInstantiator;
import org.taskana.CategoryService;
import org.taskana.ClassificationService;
import org.taskana.TaskService;
import org.taskana.TaskanaEngine;
import org.taskana.WorkbasketService;
@ -23,7 +20,8 @@ import org.taskana.model.Workbasket;
import org.taskana.rest.serialization.WorkbasketMixIn;
import org.taskana.sampledata.SampleDataGenerator;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import javax.annotation.PostConstruct;
import java.sql.SQLException;
@SpringBootApplication
public class RestApplication {
@ -35,8 +33,8 @@ public class RestApplication {
}
@Bean
public CategoryService getCategoryService() throws Exception {
return getTaskanaEngine().getCategoryService();
public ClassificationService getClassificationService() throws Exception {
return getTaskanaEngine().getClassificationService();
}
@Bean

View File

@ -1,16 +1,14 @@
package org.taskana.sampledata;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.taskana.rest.RestApplication;
import javax.sql.DataSource;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.SQLException;
public class SampleDataGenerator {
@ -23,7 +21,7 @@ public class SampleDataGenerator {
private static final String WORKBASKET = SQL + TEST_DATA + "/workbasket.sql";
private static final String DISTRIBUTION_TARGETS = SQL + TEST_DATA + "/distribution-targets.sql";
private static final String WORKBASKET_ACCESS_LIST = SQL + TEST_DATA + "/workbasket-access-list.sql";
private static final String CATEGORY = SQL + TEST_DATA + "/category.sql";
private static final String CATEGORY = SQL + TEST_DATA + "/classification.sql";
public SampleDataGenerator(DataSource dataSource) throws SQLException {

View File

@ -1,4 +0,0 @@
INSERT INTO BUSINESS_CATEGORY (ID, TENANT_ID, PARENT_CATEGORY_ID, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('1', 'NT', '', CURRENT_TIMESTAMP, 'ROOT', 'DESC', 1, 'SLA');
INSERT INTO BUSINESS_CATEGORY (ID, TENANT_ID, PARENT_CATEGORY_ID, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('2', 'NT', '1', CURRENT_TIMESTAMP, 'CHILD', 'DESC', 1, 'SLA');
INSERT INTO BUSINESS_CATEGORY (ID, TENANT_ID, PARENT_CATEGORY_ID, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('3', 'NT', '1', CURRENT_TIMESTAMP, 'ANOTHER CHILD', 'DESC', 1, 'SLA');
INSERT INTO BUSINESS_CATEGORY (ID, TENANT_ID, PARENT_CATEGORY_ID, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('4', 'NT', '2', CURRENT_TIMESTAMP, 'GRANDCHILD', 'DESC', 1, 'SLA');

View File

@ -0,0 +1,9 @@
INSERT INTO BUSINESS_CLASSIFICATION (ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('1', 'NT', '', 'EXTERN', 'BRIEF', CURRENT_TIMESTAMP, 'ROOT', 'DESC', 1, 'P1D');
INSERT INTO BUSINESS_CLASSIFICATION (ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('2', 'NT', '1','MANUELL', 'BRIEF', CURRENT_TIMESTAMP, 'CHILD', 'DESC', 1, 'P1D');
INSERT INTO BUSINESS_CLASSIFICATION (ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('3', 'NT', '1','MASCHINELL', 'BRIEF', CURRENT_TIMESTAMP, 'ANOTHER CHILD', 'DESC', 1, 'P2D');
INSERT INTO BUSINESS_CLASSIFICATION (ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL) VALUES ('4', 'NT', '2','PROZESS', 'EXCEL-SHEET', CURRENT_TIMESTAMP, 'GRANDCHILD', 'DESC', 1, 'P1DT4H12S');
INSERT INTO BUSINESS_CLASSIFICATION VALUES('13', 'NT', '3', 'MANUELL', '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'ANOTHER GRANDCHILD', 'DESC', 3, 'P3DT12H', NULL);
INSERT INTO BUSINESS_CLASSIFICATION VALUES('14', 'NT', '4', 'MANUELL', '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'BIG GRANDCHILD', 'DESC', 2, 'P2DT12H', NULL);
INSERT INTO BUSINESS_CLASSIFICATION VALUES('15', 'NT', '3', 'PROZESS', 'MINDMAP', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'SMALL GRANDCHILD', 'DESC', 4, 'P5DT12H', NULL);
INSERT INTO BUSINESS_CLASSIFICATION VALUES('16', 'NT', '4', 'MANUELL', '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'NO GRANDCHILD', 'DESC', 3, 'P3DT', NULL);