TSK-302: now using ClassificationResource

This commit is contained in:
Mustapha Zorgati 2018-02-19 21:28:55 +01:00 committed by Holger Hagen
parent 9d4f80dcaa
commit 5f460f0403
4 changed files with 110 additions and 6 deletions

View File

@ -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<List<Classification>> getClassifications(@RequestParam(required = false) String domain) {
public ResponseEntity<List<ClassificationResource>> getClassifications(@RequestParam(required = false) String domain) {
try {
ClassificationQuery query = classificationService.createClassificationQuery();
List<ClassificationSummary> summaries = domain != null ? query.domainIn(domain).list() : query.list();
List<Classification> export = new ArrayList<>();
List<ClassificationResource> 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);

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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()
);
}
}