use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationServiceImpl method deleteClassification.
@Override
public void deleteClassification(String classificationKey, String domain) throws ClassificationInUseException, ClassificationNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to deleteClassification(key = {}, domain = {})", classificationKey, domain);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
try {
taskanaEngine.openConnection();
Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
if (classification == null) {
throw new ClassificationNotFoundException(classificationKey, domain, "The classification " + classificationKey + "wasn't found in the domain " + domain);
}
List<AttachmentSummaryImpl> attachments = taskanaEngine.getSqlSession().getMapper(AttachmentMapper.class).findAttachmentSummariesByClassificationId(classification.getId());
if (!attachments.isEmpty()) {
throw new ClassificationInUseException("Classification " + classification.getId() + " is used by Attachment " + attachments.get(0).getId());
}
if (domain.equals("")) {
// master mode - delete all associated classifications in every domain.
List<String> domains = this.classificationMapper.getDomainsForClassification(classificationKey);
domains.remove("");
for (String classificationDomain : domains) {
deleteClassification(classificationKey, classificationDomain);
}
}
TaskServiceImpl taskService = (TaskServiceImpl) taskanaEngine.getTaskService();
try {
List<TaskSummary> classificationTasks = taskService.createTaskQuery().classificationKeyIn(classificationKey).list();
if (classificationTasks.stream().anyMatch(t -> domain.equals(t.getClassificationSummary().getDomain()))) {
throw new ClassificationInUseException("There are Tasks that belong to this classification or a child classification. Please complete them and try again.");
}
} catch (NotAuthorizedToQueryWorkbasketException e) {
LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
}
List<String> childKeys = this.classificationMapper.getChildrenOfClassification(classification.getId());
for (String key : childKeys) {
this.deleteClassification(key, domain);
}
this.classificationMapper.deleteClassificationInDomain(classificationKey, domain);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteClassification()");
}
}
use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationController method createClassification.
@PostMapping
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<ClassificationResource> createClassification(@RequestBody ClassificationResource resource) throws NotAuthorizedException, ClassificationNotFoundException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
Classification classification = classificationMapper.toModel(resource);
classification = classificationService.createClassification(classification);
return ResponseEntity.status(HttpStatus.CREATED).body(classificationMapper.toResource(classification));
}
use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationServiceImplIntExplicitTest method testInsertAndClassificationQuery.
@Test
public void testInsertAndClassificationQuery() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
classificationService.createClassification(classification);
List<ClassificationSummary> list = classificationService.createClassificationQuery().validInDomainEquals(Boolean.TRUE).createdWithin(today()).list();
Assert.assertEquals(1, list.size());
}
use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationServiceImplIntExplicitTest method testFindWithClassificationMapperPriorityTypeAndParent.
@Test
public void testFindWithClassificationMapperPriorityTypeAndParent() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey("", "TASK");
classification.setPriority(Integer.decode("5"));
classificationService.createClassification(classification);
Classification classification1 = this.createNewClassificationWithUniqueKey("", "TASK");
classification1.setPriority(Integer.decode("3"));
classification1.setParentId(classification.getId());
classificationService.createClassification(classification1);
Classification classification2 = this.createNewClassificationWithUniqueKey("", "DOCUMENT");
classification2.setPriority(Integer.decode("5"));
classification2.setParentId(classification.getId());
classificationService.createClassification(classification2);
Classification classification3 = this.createNewClassificationWithUniqueKey("", "TASK");
classification3.setPriority(Integer.decode("5"));
classification3.setParentId(classification1.getId());
classificationService.createClassification(classification3);
List<ClassificationSummary> list = classificationService.createClassificationQuery().parentIdIn(classification.getId()).list();
Assert.assertEquals(2, list.size());
list = classificationService.createClassificationQuery().typeIn("TASK").priorityIn(Integer.decode("5")).list();
Assert.assertEquals(2, list.size());
list = classificationService.createClassificationQuery().priorityIn(Integer.decode("5")).typeIn("TASK").parentIdIn(classification1.getId()).list();
Assert.assertEquals(1, list.size());
connection.commit();
}
use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationServiceImplIntExplicitTest method testModifiedClassification.
@Test
public void testModifiedClassification() throws SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
connection.commit();
classification = classificationService.createClassification(classification);
String updatedDescription = "TEST SOMETHING";
classification.setDescription(updatedDescription);
classification = classificationService.updateClassification(classification);
connection.commit();
classification = classificationService.getClassification(classification.getKey(), classification.getDomain());
assertThat(classification.getDescription(), equalTo(updatedDescription));
}
Aggregations