Add Customs and Domain (with functionalities) to Classification

This commit is contained in:
BVier 2017-07-25 13:06:14 +02:00
parent 7720ad5aca
commit 44c5f2dec4
6 changed files with 300 additions and 45 deletions

View File

@ -1,10 +1,10 @@
package org.taskana;
import java.util.List;
import org.taskana.model.Classification;
import org.taskana.persistence.ClassificationQuery;
import java.util.List;
/**
* This class manages the classifications.
*/
@ -31,6 +31,37 @@ public interface ClassificationService {
*/
Classification selectClassificationById(String id);
/**
* Get all Classifications from a domain.
* @param domain
* @return
*/
List<Classification> selectClassificationByDomain(String domain);
/**
* Get all Classifications from a domain with a specific type.
* @param domain
* @param type
* @return
*/
List<Classification> selectClassificationByDomainAndType(String domain, String type);
/**
* Get all Classifications from a category for a domain.
* @param domain
* @param category
* @return
*/
List<Classification> selectClassificationByDomainAndCategory(String domain, String category);
/**
* Get all Classifications from a category and a type.
* @param category
* @param type
* @return
*/
List<Classification> selectClassificationByCategoryAndType(String category, String type);
/**
* Insert a new Classification.
* @param classification

View File

@ -1,10 +1,5 @@
package org.taskana.impl;
import java.sql.Date;
import java.time.Duration;
import java.time.LocalDate;
import java.util.List;
import org.taskana.ClassificationService;
import org.taskana.TaskanaEngine;
import org.taskana.impl.persistence.ClassificationQueryImpl;
@ -13,6 +8,11 @@ import org.taskana.model.Classification;
import org.taskana.model.mappings.ClassificationMapper;
import org.taskana.persistence.ClassificationQuery;
import java.sql.Date;
import java.time.Duration;
import java.time.LocalDate;
import java.util.List;
/**
* This is the implementation of ClassificationService.
*/
@ -72,6 +72,26 @@ public class ClassificationServiceImpl implements ClassificationService {
return classificationMapper.findById(id);
}
@Override
public List<Classification> selectClassificationByDomain(String domain) {
return classificationMapper.findByDomain(domain);
}
@Override
public List<Classification> selectClassificationByDomainAndType(String domain, String type) {
return classificationMapper.getClassificationByDomainAndType(domain, type);
}
@Override
public List<Classification> selectClassificationByDomainAndCategory(String domain, String category) {
return classificationMapper.getClassificationByDomainAndCategory(domain, category);
}
@Override
public List<Classification> selectClassificationByCategoryAndType(String category, String type) {
return classificationMapper.getClassificationByCategoryAndType(category, type);
}
private void checkServiceLevel(Classification classification) {
if (classification.getServiceLevel() != null) {
try {
@ -86,4 +106,5 @@ public class ClassificationServiceImpl implements ClassificationService {
public ClassificationQuery createClassificationQuery() {
return new ClassificationQueryImpl(taskanaEngine);
}
}

View File

@ -14,6 +14,8 @@ public class Classification {
private String parentClassificationId;
private String category;
private String type;
private String domain;
private Boolean isValidInDomain;
private Date created;
private Date modified;
private String name;
@ -21,6 +23,14 @@ public class Classification {
private int priority;
private String serviceLevel; // PddDThhHmmM
private List<Classification> children = new ArrayList<>();
private String custom1;
private String custom2;
private String custom3;
private String custom4;
private String custom5;
private String custom6;
private String custom7;
private String custom8;
public String getId() {
return id;
@ -62,6 +72,22 @@ public class Classification {
this.category = category;
}
public String getDomain() {
return this.domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public Boolean getValidInDomain() {
return isValidInDomain;
}
public void setValidInDomain(Boolean validInDomain) {
isValidInDomain = validInDomain;
}
public Date getCreated() {
return created;
}
@ -122,4 +148,68 @@ public class Classification {
this.children = children;
}
public String getCustom1() {
return custom1;
}
public void setCustom1(String custom1) {
this.custom1 = custom1;
}
public String getCustom2() {
return custom2;
}
public void setCustom2(String custom2) {
this.custom2 = custom2;
}
public String getCustom3() {
return custom3;
}
public void setCustom3(String custom3) {
this.custom3 = custom3;
}
public String getCustom4() {
return custom4;
}
public void setCustom4(String custom4) {
this.custom4 = custom4;
}
public String getCustom5() {
return custom5;
}
public void setCustom5(String custom5) {
this.custom5 = custom5;
}
public String getCustom6() {
return custom6;
}
public void setCustom6(String custom6) {
this.custom6 = custom6;
}
public String getCustom7() {
return custom7;
}
public void setCustom7(String custom7) {
this.custom7 = custom7;
}
public String getCustom8() {
return custom8;
}
public void setCustom8(String custom8) {
this.custom8 = custom8;
}
}

View File

@ -10,7 +10,7 @@ import java.util.List;
*/
public interface ClassificationMapper {
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL "
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8 "
+ "FROM CLASSIFICATION "
+ "ORDER BY ID")
@Results({@Result(property = "id", column = "ID"),
@ -18,15 +18,25 @@ public interface ClassificationMapper {
@Result(property = "parentClassificationId", column = "PARENT_CLASSIFICATION_ID"),
@Result(property = "category", column = "CATEGORY"),
@Result(property = "type", column = "TYPE"),
@Result(property = "domain", column = "DOMAIN"),
@Result(property = "isValidInDomain", column = "VALID_IN_DOMAIN"),
@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") })
@Result(property = "serviceLevel", column = "SERVICE_LEVEL"),
@Result(property = "custom1", column = "CUSTOM_1"),
@Result(property = "custom2", column = "CUSTOM_2"),
@Result(property = "custom3", column = "CUSTOM_3"),
@Result(property = "custom4", column = "CUSTOM_4"),
@Result(property = "custom5", column = "CUSTOM_5"),
@Result(property = "custom6", column = "CUSTOM_6"),
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8")})
List<Classification> findAll();
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL "
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8 "
+ "FROM CLASSIFICATION "
+ "WHERE PARENT_CLASSIFICATION_ID = #{parentClassificationId} "
+ "ORDER BY ID")
@ -35,15 +45,25 @@ public interface ClassificationMapper {
@Result(property = "parentClassificationId", column = "PARENT_CLASSIFICATION_ID"),
@Result(property = "category", column = "CATEGORY"),
@Result(property = "type", column = "TYPE"),
@Result(property = "domain", column = "DOMAIN"),
@Result(property = "isValidInDomain", column = "VALID_IN_DOMAIN"),
@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") })
@Result(property = "serviceLevel", column = "SERVICE_LEVEL"),
@Result(property = "custom1", column = "CUSTOM_1"),
@Result(property = "custom2", column = "CUSTOM_2"),
@Result(property = "custom3", column = "CUSTOM_3"),
@Result(property = "custom4", column = "CUSTOM_4"),
@Result(property = "custom5", column = "CUSTOM_5"),
@Result(property = "custom6", column = "CUSTOM_6"),
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8")})
List<Classification> findByParentId(@Param("parentClassificationId") String parentId);
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL "
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8 "
+ "FROM CLASSIFICATION "
+ "WHERE ID = #{id}")
@Results({@Result(property = "id", column = "ID"),
@ -51,17 +71,80 @@ public interface ClassificationMapper {
@Result(property = "parentClassificationId", column = "PARENT_CLASSIFICATION_ID"),
@Result(property = "category", column = "CATEGORY"),
@Result(property = "type", column = "TYPE"),
@Result(property = "domain", column = "DOMAIN"),
@Result(property = "isValidInDomain", column = "VALID_IN_DOMAIN"),
@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") })
@Result(property = "serviceLevel", column = "SERVICE_LEVEL"),
@Result(property = "custom1", column = "CUSTOM_1"),
@Result(property = "custom2", column = "CUSTOM_2"),
@Result(property = "custom3", column = "CUSTOM_3"),
@Result(property = "custom4", column = "CUSTOM_4"),
@Result(property = "custom5", column = "CUSTOM_5"),
@Result(property = "custom6", column = "CUSTOM_6"),
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8")})
Classification findById(@Param("id") String id);
@Insert("INSERT INTO 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})")
@Insert("INSERT INTO CLASSIFICATION (ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8) VALUES (#{classification.id}, #{classification.tenantId}, #{classification.parentClassificationId}, #{classification.category}, #{classification.type}, #{classification.domain}, #{classification.isValidInDomain}, #{classification.created}, #{classification.name}, #{classification.description}, #{classification.priority}, #{classification.serviceLevel}, #{classification.custom1}, #{classification.custom2}, #{classification.custom3}, #{classification.custom4}, #{classification.custom5}, #{classification.custom6}, #{classification.custom7}, #{classification.custom8})")
void insert(@Param("classification") Classification classification);
@Update(value = "UPDATE 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}")
@Update(value = "UPDATE 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}, DOMAIN = #{classification.domain}, VALID_IN_DOMAIN = #{classification.isValidInDomain}, MODIFIED = #{classification.modified}, CUSTOM_1 = #{classification.custom1}, CUSTOM_2 = #{classification.custom2}, CUSTOM_3 = #{classification.custom3}, CUSTOM_4 = #{classification.custom4}, CUSTOM_5 = #{classification.custom5}, CUSTOM_6 = #{classification.custom6}, CUSTOM_7 = #{classification.custom7}, CUSTOM_8 = #{classification.custom8} WHERE ID = #{classification.id}")
void update(@Param("classification") Classification classification);
@Select("SELECT ID, TENANT_ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, MODIFIED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8"
+ "FROM CLASSIFICATION "
+ "WHERE DOMAIN = #{domain}"
+ "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 = "domain", column = "DOMAIN"),
@Result(property = "isValidInDomain", column = "VALID_IN_DOMAIN"),
@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"),
@Result(property = "custom1", column = "CUSTOM_1"),
@Result(property = "custom2", column = "CUSTOM_2"),
@Result(property = "custom3", column = "CUSTOM_3"),
@Result(property = "custom4", column = "CUSTOM_4"),
@Result(property = "custom5", column = "CUSTOM_5"),
@Result(property = "custom6", column = "CUSTOM_6"),
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8")})
List<Classification> findByDomain(@Param("domain") String domain);
@Select("<script>"
+ "SELECT * "
+ "FROM CLASSIFICATION "
+ "WHERE DOMAIN = #{domain} "
+ "AND CATEGORY = #{category} "
+ "</script>")
List<Classification> getClassificationByDomainAndCategory(@Param("domain") String domain, @Param("category") String category);
@Select("<script>"
+ "SELECT * "
+ "FROM CLASSIFICATION "
+ "WHERE DOMAIN = #{domain} "
+ "AND TYPE = #{type} "
+ "</script>")
List<Classification> getClassificationByDomainAndType(@Param("domain") String domain, @Param("type") String type);
@Select("<script>"
+ "SELECT * "
+ "FROM CLASSIFICATION "
+ "WHERE CATEGORY = #{category} "
+ "AND TYPE = #{type} "
+ "</script>")
List<Classification> getClassificationByCategoryAndType(@Param("category") String category, @Param("type") String type);
}

View File

@ -62,12 +62,22 @@ CREATE TABLE CLASSIFICATION(
PARENT_CLASSIFICATION_ID VARCHAR(255),
CATEGORY VARCHAR(255),
TYPE VARCHAR(255),
DOMAIN VARCHAR(255),
VALID_IN_DOMAIN BOOLEAN NULL,
CREATED DATE NULL,
MODIFIED DATE NULL,
NAME VARCHAR(255) NULL,
DESCRIPTION VARCHAR(255) NULL,
PRIORITY INT NULL,
SERVICE_LEVEL VARCHAR(255) NULL,
CUSTOM_1 VARCHAR(255) NULL,
CUSTOM_2 VARCHAR(255) NULL,
CUSTOM_3 VARCHAR(255) NULL,
CUSTOM_4 VARCHAR(255) NULL,
CUSTOM_5 VARCHAR(255) NULL,
CUSTOM_6 VARCHAR(255) NULL,
CUSTOM_7 VARCHAR(255) NULL,
CUSTOM_8 VARCHAR(255) NULL,
PRIMARY KEY (ID)
);

View File

@ -80,4 +80,24 @@ public class ClassificationServiceImplIntTest {
Assert.assertEquals(classification.getModified().toString(), LocalDate.now().toString());
}
@Test
public void testFindByDomainAndCategory() {
Classification classification1 = new Classification();
classification1.setDomain("domain1");
classification1.setCategory("category1");
classificationService.insertClassification(classification1);
Classification classification2 = new Classification();
classification2.setDomain("domain2");
classification2.setCategory("category1");
classificationService.insertClassification(classification2);
Classification classification3 = new Classification();
classification3.setDomain("domain1");
classification3.setCategory("category2");
classificationService.insertClassification(classification3);
int sizeOfReturn = classificationService.selectClassificationByDomainAndCategory("domain1", "category1").size();
Assert.assertEquals(sizeOfReturn, 1);
}
}