From 5f460f040304d97e935b2ae051a8cea82bcb2e31 Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Mon, 19 Feb 2018 21:28:55 +0100 Subject: [PATCH] TSK-302: now using ClassificationResource --- .../ClassificationDefinitionController.java | 19 ++++-- .../pro/taskana/rest/RestApplication.java | 6 ++ .../rest/resource/ClassificationResource.java | 58 +++++++++++++++++++ .../resource/mapper/ClassificationMapper.java | 33 +++++++++++ 4 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 rest/src/main/java/pro/taskana/rest/resource/ClassificationResource.java create mode 100644 rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java diff --git a/rest/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java b/rest/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java index 6eb725555..1f5587b8e 100644 --- a/rest/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java +++ b/rest/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java @@ -1,5 +1,8 @@ package pro.taskana.rest; +import java.util.ArrayList; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -8,14 +11,14 @@ 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 pro.taskana.Classification; import pro.taskana.ClassificationQuery; import pro.taskana.ClassificationService; import pro.taskana.ClassificationSummary; import pro.taskana.exceptions.ClassificationNotFoundException; - -import java.util.ArrayList; -import java.util.List; +import pro.taskana.rest.resource.ClassificationResource; +import pro.taskana.rest.resource.mapper.ClassificationMapper; @RestController @RequestMapping(path = "/v1/classificationdefinitions", produces = {MediaType.APPLICATION_JSON_VALUE}) @@ -24,15 +27,19 @@ public class ClassificationDefinitionController { @Autowired private ClassificationService classificationService; + @Autowired + private ClassificationMapper classificationMapper; + @RequestMapping(method = RequestMethod.GET) - public ResponseEntity> getClassifications(@RequestParam(required = false) String domain) { + public ResponseEntity> getClassifications(@RequestParam(required = false) String domain) { try { ClassificationQuery query = classificationService.createClassificationQuery(); List summaries = domain != null ? query.domainIn(domain).list() : query.list(); - List export = new ArrayList<>(); + List export = new ArrayList<>(); for (ClassificationSummary summary : summaries) { - export.add(classificationService.getClassification(summary.getKey(), summary.getDomain())); + Classification classification = classificationService.getClassification(summary.getKey(), summary.getDomain()); + export.add(classificationMapper.toResource(classification)); } return new ResponseEntity<>(export, HttpStatus.OK); diff --git a/rest/src/main/java/pro/taskana/rest/RestApplication.java b/rest/src/main/java/pro/taskana/rest/RestApplication.java index 3f96b4bd2..50938294f 100644 --- a/rest/src/main/java/pro/taskana/rest/RestApplication.java +++ b/rest/src/main/java/pro/taskana/rest/RestApplication.java @@ -23,6 +23,7 @@ import pro.taskana.TaskService; import pro.taskana.TaskanaEngine; import pro.taskana.WorkbasketService; import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.rest.resource.mapper.ClassificationMapper; import pro.taskana.rest.resource.mapper.WorkbasketDefinitionMapper; import pro.taskana.rest.resource.mapper.WorkbasketSummaryMapper; import pro.taskana.sampledata.SampleDataGenerator; @@ -66,6 +67,11 @@ public class RestApplication { return new WorkbasketDefinitionMapper(); } + @Bean + public ClassificationMapper getClassificationMapper() { + return new ClassificationMapper(); + } + @Bean @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public TaskanaEngine getTaskanaEngine() throws SQLException { diff --git a/rest/src/main/java/pro/taskana/rest/resource/ClassificationResource.java b/rest/src/main/java/pro/taskana/rest/resource/ClassificationResource.java new file mode 100644 index 000000000..50ce06653 --- /dev/null +++ b/rest/src/main/java/pro/taskana/rest/resource/ClassificationResource.java @@ -0,0 +1,58 @@ +package pro.taskana.rest.resource; + +import java.time.Instant; + +import org.springframework.hateoas.ResourceSupport; + +public class ClassificationResource extends ResourceSupport { + public String classificationId; + public String key; + public String parentId; + public String category; + public String type; + public String domain; + public boolean isValidInDomain; + public Instant created; + public String name; + public String description; + public int priority; + public String serviceLevel; // PddDThhHmmM + public String applicationEntryPoint; + public String custom1; + public String custom2; + public String custom3; + public String custom4; + public String custom5; + public String custom6; + public String custom7; + public String custom8; + + public ClassificationResource(String classificationId, String key, String parentId, String category, String type, String domain, + boolean isValidInDomain, Instant created, String name, String description, + int priority, String serviceLevel, String applicationEntryPoint, String custom1, + String custom2, String custom3, String custom4, String custom5, String custom6, + String custom7, String custom8) { + super(); + this.classificationId = classificationId; + this.key = key; + this.parentId = parentId; + this.category = category; + this.type = type; + this.domain = domain; + this.isValidInDomain = isValidInDomain; + this.created = created; + this.name = name; + this.description = description; + this.priority = priority; + this.serviceLevel = serviceLevel; + this.applicationEntryPoint = applicationEntryPoint; + this.custom1 = custom1; + this.custom2 = custom2; + this.custom3 = custom3; + this.custom4 = custom4; + this.custom5 = custom5; + this.custom6 = custom6; + this.custom7 = custom7; + this.custom8 = custom8; + } +} diff --git a/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java b/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java new file mode 100644 index 000000000..618ab26b8 --- /dev/null +++ b/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java @@ -0,0 +1,33 @@ +package pro.taskana.rest.resource.mapper; + +import pro.taskana.Classification; +import pro.taskana.rest.resource.ClassificationResource; + +public class ClassificationMapper { + + public ClassificationResource toResource(Classification classification) { + return new ClassificationResource( + classification.getId(), + classification.getKey(), + classification.getParentId(), + classification.getCategory(), + classification.getType(), + classification.getDomain(), + classification.getIsValidInDomain(), + classification.getCreated(), + classification.getName(), + classification.getDescription(), + classification.getPriority(), + classification.getServiceLevel(), + classification.getApplicationEntryPoint(), + classification.getCustom1(), + classification.getCustom2(), + classification.getCustom3(), + classification.getCustom4(), + classification.getCustom5(), + classification.getCustom6(), + classification.getCustom7(), + classification.getCustom8() + ); + } +}