From 44c5f2dec4c077c6116f80972bff52c1740ee6bc Mon Sep 17 00:00:00 2001 From: BVier <26220150+BVier@users.noreply.github.com> Date: Tue, 25 Jul 2017 13:06:14 +0200 Subject: [PATCH] Add Customs and Domain (with functionalities) to Classification --- .../org/taskana/ClassificationService.java | 35 +++- .../impl/ClassificationServiceImpl.java | 31 +++- .../org/taskana/model/Classification.java | 90 ++++++++++ .../model/mappings/ClassificationMapper.java | 159 +++++++++++++----- .../src/main/resources/sql/taskana-schema.sql | 10 ++ .../ClassificationServiceImplIntTest.java | 20 +++ 6 files changed, 300 insertions(+), 45 deletions(-) diff --git a/lib/taskana-core/src/main/java/org/taskana/ClassificationService.java b/lib/taskana-core/src/main/java/org/taskana/ClassificationService.java index 563504892..d6a639db4 100644 --- a/lib/taskana-core/src/main/java/org/taskana/ClassificationService.java +++ b/lib/taskana-core/src/main/java/org/taskana/ClassificationService.java @@ -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 selectClassificationByDomain(String domain); + + /** + * Get all Classifications from a domain with a specific type. + * @param domain + * @param type + * @return + */ + List selectClassificationByDomainAndType(String domain, String type); + + /** + * Get all Classifications from a category for a domain. + * @param domain + * @param category + * @return + */ + List selectClassificationByDomainAndCategory(String domain, String category); + + /** + * Get all Classifications from a category and a type. + * @param category + * @param type + * @return + */ + List selectClassificationByCategoryAndType(String category, String type); + /** * Insert a new Classification. * @param classification diff --git a/lib/taskana-core/src/main/java/org/taskana/impl/ClassificationServiceImpl.java b/lib/taskana-core/src/main/java/org/taskana/impl/ClassificationServiceImpl.java index 79b496124..b4a8620ad 100644 --- a/lib/taskana-core/src/main/java/org/taskana/impl/ClassificationServiceImpl.java +++ b/lib/taskana-core/src/main/java/org/taskana/impl/ClassificationServiceImpl.java @@ -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 selectClassificationByDomain(String domain) { + return classificationMapper.findByDomain(domain); + } + + @Override + public List selectClassificationByDomainAndType(String domain, String type) { + return classificationMapper.getClassificationByDomainAndType(domain, type); + } + + @Override + public List selectClassificationByDomainAndCategory(String domain, String category) { + return classificationMapper.getClassificationByDomainAndCategory(domain, category); + } + + @Override + public List 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); } + } diff --git a/lib/taskana-core/src/main/java/org/taskana/model/Classification.java b/lib/taskana-core/src/main/java/org/taskana/model/Classification.java index 6b579b3a1..0a03c5a33 100644 --- a/lib/taskana-core/src/main/java/org/taskana/model/Classification.java +++ b/lib/taskana-core/src/main/java/org/taskana/model/Classification.java @@ -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 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; + } + } diff --git a/lib/taskana-core/src/main/java/org/taskana/model/mappings/ClassificationMapper.java b/lib/taskana-core/src/main/java/org/taskana/model/mappings/ClassificationMapper.java index da192aea2..b5f0b7cef 100644 --- a/lib/taskana-core/src/main/java/org/taskana/model/mappings/ClassificationMapper.java +++ b/lib/taskana-core/src/main/java/org/taskana/model/mappings/ClassificationMapper.java @@ -10,58 +10,141 @@ 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"), - @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") }) + @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 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") - @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") }) + @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 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"), - @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") }) + @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")}) 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 findByDomain(@Param("domain") String domain); + + @Select("") + List getClassificationByDomainAndCategory(@Param("domain") String domain, @Param("category") String category); + + @Select("") + List getClassificationByDomainAndType(@Param("domain") String domain, @Param("type") String type); + + @Select("") + List getClassificationByCategoryAndType(@Param("category") String category, @Param("type") String type); + } + diff --git a/lib/taskana-core/src/main/resources/sql/taskana-schema.sql b/lib/taskana-core/src/main/resources/sql/taskana-schema.sql index 01a5cd4f1..de7dc69bb 100644 --- a/lib/taskana-core/src/main/resources/sql/taskana-schema.sql +++ b/lib/taskana-core/src/main/resources/sql/taskana-schema.sql @@ -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) ); diff --git a/lib/taskana-core/src/test/java/org/taskana/impl/integration/ClassificationServiceImplIntTest.java b/lib/taskana-core/src/test/java/org/taskana/impl/integration/ClassificationServiceImplIntTest.java index c7eef72b2..82b143958 100644 --- a/lib/taskana-core/src/test/java/org/taskana/impl/integration/ClassificationServiceImplIntTest.java +++ b/lib/taskana-core/src/test/java/org/taskana/impl/integration/ClassificationServiceImplIntTest.java @@ -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); + } + }