From f0b8e6742a0b37b44d32b0956182f5a33f68dffa Mon Sep 17 00:00:00 2001 From: Marcel Lengl <52546181+LenglBoy@users.noreply.github.com> Date: Mon, 27 Nov 2017 09:44:13 +0100 Subject: [PATCH] =?UTF-8?q?Review-fixed=20(Classification).=20Domain=20ber?= =?UTF-8?q?=C3=BCcksichtigt,=20Status=20im=20Controller=20inzugef=C3=BCgt,?= =?UTF-8?q?=20ValidUntil=20ber=C3=BCcksichtigt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ClassificationServiceImpl.java | 10 +++---- .../model/mappings/ClassificationMapper.java | 17 +++++++++--- .../impl/ClassificationServiceImplTest.java | 22 ++++++++++------ .../rest/ClassificationController.java | 26 +++++++++++++------ .../sql/sample-data/classification.sql | 8 +++--- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java index da9631cb1..0c6244c51 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java @@ -114,13 +114,13 @@ public class ClassificationServiceImpl implements ClassificationService { @Override public Classification getClassification(String id, String domain) { - Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL); - - if (classification == null) { - return classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL); + Classification classification; + if (domain == null) { + classification = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL); } else { - return classification; + classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL); } + return classification; } @Override diff --git a/lib/taskana-core/src/main/java/pro/taskana/model/mappings/ClassificationMapper.java b/lib/taskana-core/src/main/java/pro/taskana/model/mappings/ClassificationMapper.java index e31e08c4c..71a33f0df 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/model/mappings/ClassificationMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/model/mappings/ClassificationMapper.java @@ -1,16 +1,24 @@ package pro.taskana.model.mappings; -import org.apache.ibatis.annotations.*; -import pro.taskana.model.Classification; - import java.sql.Date; import java.util.List; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import pro.taskana.model.Classification; + /** * This class is the mybatis mapping of classifications. */ public interface ClassificationMapper { + String VALID_UNTIL = "9999-12-31"; + @Select("SELECT 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, VALID_FROM, VALID_UNTIL " + "FROM CLASSIFICATION " + "WHERE ID = #{id}" @@ -41,7 +49,8 @@ public interface ClassificationMapper { @Select("SELECT 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, VALID_FROM, VALID_UNTIL " + "FROM CLASSIFICATION " - + "WHERE ID = #{id}") + + "WHERE ID = #{id} " + + "AND VALID_UNTIL = '" + VALID_UNTIL + "'") @Results({@Result(property = "id", column = "ID"), @Result(property = "parentClassificationId", column = "PARENT_CLASSIFICATION_ID"), @Result(property = "category", column = "CATEGORY"), diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java index 02a7a5028..3e934c233 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java @@ -1,5 +1,18 @@ package pro.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.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.Date; +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; @@ -7,19 +20,12 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; + import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.persistence.TestClassificationQuery; import pro.taskana.model.Classification; import pro.taskana.model.mappings.ClassificationMapper; -import java.sql.Date; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - /** * Unit Test for ClassificationServiceImpl. * @author EH diff --git a/rest/src/main/java/pro/taskana/rest/ClassificationController.java b/rest/src/main/java/pro/taskana/rest/ClassificationController.java index 8d31b9782..c6dd87d32 100644 --- a/rest/src/main/java/pro/taskana/rest/ClassificationController.java +++ b/rest/src/main/java/pro/taskana/rest/ClassificationController.java @@ -20,24 +20,34 @@ public class ClassificationController { @Autowired private ClassificationService classificationService; - @RequestMapping + @RequestMapping(method = RequestMethod.GET) public ResponseEntity> getClassifications() { try { List classificationTree = classificationService.getClassificationTree(); - return ResponseEntity.status(HttpStatus.CREATED).body(classificationTree); + return ResponseEntity.status(HttpStatus.OK).body(classificationTree); } catch (Exception e) { return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); } } - @RequestMapping(value = "/{classificationId}") - public Classification getClassification(@PathVariable String classificationId) { - return classificationService.getClassification(classificationId, "nova-domain"); + @RequestMapping(value = "/{classificationId}", method = RequestMethod.GET) + public ResponseEntity getClassification(@PathVariable String classificationId) { + try { + Classification classification = classificationService.getClassification(classificationId, ""); + return ResponseEntity.status(HttpStatus.OK).body(classification); + } catch(Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } } - @RequestMapping(value = "/{classificationId}/{domain}") - public Classification getClassification(@PathVariable String classificationId, @PathVariable String domain) { - return classificationService.getClassification(classificationId, domain); + @RequestMapping(value = "/{classificationId}/{domain}", method = RequestMethod.GET) + public ResponseEntity getClassification(@PathVariable String classificationId, @PathVariable String domain) { + try { + Classification classification = classificationService.getClassification(classificationId, domain); + return ResponseEntity.status(HttpStatus.OK).body(classification); + } catch(Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } } @RequestMapping(method = RequestMethod.POST) diff --git a/rest/src/main/resources/sql/sample-data/classification.sql b/rest/src/main/resources/sql/sample-data/classification.sql index f19e1ca6d..42b036c04 100644 --- a/rest/src/main/resources/sql/sample-data/classification.sql +++ b/rest/src/main/resources/sql/sample-data/classification.sql @@ -1,9 +1,9 @@ INSERT INTO CLASSIFICATION VALUES ('1', '', 'EXTERN', 'BRIEF','nova-domain', TRUE, CURRENT_TIMESTAMP, 'ROOT', 'DESC', 1, 'P1D', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, '9999-12-31'); INSERT INTO CLASSIFICATION VALUES ('2', '1','MANUELL', 'BRIEF', 'nova-domain', TRUE, CURRENT_TIMESTAMP, 'CHILD', 'DESC', 1, 'P1D', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, '9999-12-31'); -INSERT INTO CLASSIFICATION VALUES ('3', '1','MASCHINELL', 'BRIEF', 'nova-domain', FALSE, CURRENT_TIMESTAMP, 'ANOTHER CHILD', 'DESC', 1, 'P2D', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO CLASSIFICATION VALUES ('4', '2','PROZESS', 'EXCEL-SHEET', 'nova-domain', TRUE, CURRENT_TIMESTAMP, 'GRANDCHILD', 'DESC', 1, 'P1DT4H12S', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); +INSERT INTO CLASSIFICATION VALUES ('3', '1','MASCHINELL', 'BRIEF', '', FALSE, CURRENT_TIMESTAMP, 'ANOTHER CHILD', 'DESC', 1, 'P2D', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, '9999-12-31'); +INSERT INTO CLASSIFICATION VALUES ('4', '2','PROZESS', 'EXCEL-SHEET', '', TRUE, CURRENT_TIMESTAMP, 'GRANDCHILD', 'DESC', 1, 'P1DT4H12S', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, '9999-12-31'); -INSERT INTO CLASSIFICATION VALUES('13', '3', 'MANUELL', '', 'nova-domain', TRUE, CURRENT_TIMESTAMP, 'ANOTHER GRANDCHILD', 'DESC', 3, 'P3DT12H', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO CLASSIFICATION VALUES('14', '4', 'MANUELL', '', 'nova-domain', FALSE, CURRENT_TIMESTAMP, 'BIG GRANDCHILD', 'DESC', 2, 'P2DT12H', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); +INSERT INTO CLASSIFICATION VALUES('13', '3', 'MANUELL', '', '', TRUE, CURRENT_TIMESTAMP, 'ANOTHER GRANDCHILD', 'DESC', 3, 'P3DT12H', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); +INSERT INTO CLASSIFICATION VALUES('14', '4', 'MANUELL', '', '', FALSE, CURRENT_TIMESTAMP, 'BIG GRANDCHILD', 'DESC', 2, 'P2DT12H', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); INSERT INTO CLASSIFICATION VALUES('15', '3', 'PROZESS', 'MINDMAP', 'nova-domain', FALSE, CURRENT_TIMESTAMP, 'SMALL GRANDCHILD', 'DESC', 4, 'P5DT12H', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); INSERT INTO CLASSIFICATION VALUES('16', '4', 'MANUELL', '', 'nova-domain', TRUE, CURRENT_TIMESTAMP, 'NO GRANDCHILD', 'DESC', 3, 'P3DT', 'custom 1', 'custom 2', 'custom 3', 'custom 4', 'custom 5', 'custom 6', 'custom 7', 'custom 8', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);