Search in sources :

Example 1 with ClassificationResource

use of pro.taskana.rest.resource.ClassificationResource in project taskana by Taskana.

the class ClassificationDefinitionController method importClassifications.

@PostMapping(path = "/import")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> importClassifications(@RequestBody List<ClassificationResource> classificationResources) throws InvalidArgumentException {
    Map<String, String> systemIds = classificationService.createClassificationQuery().list().stream().collect(Collectors.toMap(i -> i.getKey() + "|" + i.getDomain(), ClassificationSummary::getId));
    try {
        for (ClassificationResource classificationResource : classificationResources) {
            if (systemIds.containsKey(classificationResource.key + "|" + classificationResource.domain)) {
                classificationService.updateClassification(classificationMapper.toModel(classificationResource));
            } else {
                classificationResource.classificationId = null;
                classificationService.createClassification(classificationMapper.toModel(classificationResource));
            }
        }
    } catch (NotAuthorizedException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    } catch (ClassificationNotFoundException | DomainNotFoundException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } catch (ClassificationAlreadyExistException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    // TODO why is this occuring???
    } catch (ConcurrencyException e) {
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) ClassificationService(pro.taskana.ClassificationService) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) ClassificationSummary(pro.taskana.ClassificationSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) MediaType(org.springframework.http.MediaType) Classification(pro.taskana.Classification) ClassificationMapper(pro.taskana.rest.resource.mapper.ClassificationMapper) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) ResponseEntity(org.springframework.http.ResponseEntity) ClassificationQuery(pro.taskana.ClassificationQuery) Transactional(org.springframework.transaction.annotation.Transactional) ResponseEntity(org.springframework.http.ResponseEntity) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ClassificationResource

use of pro.taskana.rest.resource.ClassificationResource in project taskana by Taskana.

the class ClassificationMapperTest method resourceToClassification.

@Test
public void resourceToClassification() throws NotAuthorizedException {
    // given
    ClassificationResource classificationResource = new ClassificationResource();
    classificationResource.setClassificationId("1");
    classificationResource.setKey("12");
    classificationResource.setName("TestB");
    classificationResource.setType("AB");
    classificationResource.setDomain("DOMAIN_B");
    classificationResource.setApplicationEntryPoint("Test");
    classificationResource.setCategory("ABC");
    classificationResource.setCreated("2010-01-01T12:00:00Z");
    classificationResource.setModified("2011-11-11T11:00:00Z");
    classificationResource.setCustom1("Custom");
    classificationResource.setCustom2("Custom2");
    classificationResource.setCustom1("Custom1");
    classificationResource.setCustom3("Custom3");
    classificationResource.setCustom4("Custom4");
    classificationResource.setCustom5("Custom5");
    classificationResource.setCustom6("Custom6");
    classificationResource.setCustom7("Custom7");
    classificationResource.setCustom8("Custom8");
    classificationResource.setParentId("2");
    classificationResource.setPriority(2);
    classificationResource.setApplicationEntryPoint("12");
    classificationResource.setServiceLevel("P1D");
    classificationResource.setDescription("Test");
    // when
    ClassificationImpl classification = (ClassificationImpl) classificationMapper.toModel(classificationResource);
    // then
    testEquality(classification, classificationResource);
}
Also used : ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationImpl(pro.taskana.impl.ClassificationImpl) Test(org.junit.Test)

Example 3 with ClassificationResource

use of pro.taskana.rest.resource.ClassificationResource in project taskana by Taskana.

the class ClassificationMapperTest method classificationToResource.

@Test
public void classificationToResource() throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
    // given
    ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("DOMAIN_A", "1", "A");
    classification.setId("1");
    classification.setCategory("ABC");
    classification.setName("Classification 1");
    classification.setIsValidInDomain(false);
    classification.setCustom1("Custom1");
    classification.setCustom2("Custom2");
    classification.setCustom3("Custom3");
    classification.setCustom4("Custom4");
    classification.setCustom5("Custom5");
    classification.setCustom6("Custom6");
    classification.setCustom7("Custom7");
    classification.setCustom8("Custom8");
    classification.setParentId("2");
    classification.setPriority(2);
    classification.setApplicationEntryPoint("12");
    classification.setServiceLevel("P1D");
    classification.setDescription("Test");
    classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
    classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
    // when
    ClassificationResource classificationResource = classificationMapper.toResource(classification);
    // then
    testEquality(classification, classificationResource);
}
Also used : ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationImpl(pro.taskana.impl.ClassificationImpl) Test(org.junit.Test)

Example 4 with ClassificationResource

use of pro.taskana.rest.resource.ClassificationResource in project taskana by Taskana.

the class ClassificationMapper method toResource.

public ClassificationResource toResource(Classification classification) throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
    ClassificationResource resource = new ClassificationResource();
    BeanUtils.copyProperties(classification, resource);
    // need to be set by hand, because they are named different, or have different types
    resource.setClassificationId(classification.getId());
    resource.setCreated(classification.getCreated().toString());
    resource.setModified(classification.getModified().toString());
    return addLinks(resource, classification);
}
Also used : ClassificationResource(pro.taskana.rest.resource.ClassificationResource)

Example 5 with ClassificationResource

use of pro.taskana.rest.resource.ClassificationResource in project taskana by Taskana.

the class ClassificationDefinitionController method getClassifications.

@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<List<ClassificationResource>> getClassifications(@RequestParam(required = false) String domain) throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
    ClassificationQuery query = classificationService.createClassificationQuery();
    List<ClassificationSummary> summaries = domain != null ? query.domainIn(domain).list() : query.list();
    List<ClassificationResource> export = new ArrayList<>();
    for (ClassificationSummary summary : summaries) {
        Classification classification = classificationService.getClassification(summary.getKey(), summary.getDomain());
        export.add(classificationMapper.toResource(classification));
    }
    return new ResponseEntity<>(export, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ClassificationSummary(pro.taskana.ClassificationSummary) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) Classification(pro.taskana.Classification) ArrayList(java.util.ArrayList) ClassificationQuery(pro.taskana.ClassificationQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ClassificationResource (pro.taskana.rest.resource.ClassificationResource)5 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Classification (pro.taskana.Classification)2 ClassificationQuery (pro.taskana.ClassificationQuery)2 ClassificationSummary (pro.taskana.ClassificationSummary)2 ClassificationImpl (pro.taskana.impl.ClassificationImpl)2 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 HttpStatus (org.springframework.http.HttpStatus)1 MediaType (org.springframework.http.MediaType)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 RequestBody (org.springframework.web.bind.annotation.RequestBody)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1