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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations