use of pro.taskana.exceptions.ClassificationNotFoundException in project taskana by Taskana.
the class QueryClassificationAccTest method testGetClassificationsForTypeAndParent.
@Test
public void testGetClassificationsForTypeAndParent() throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
List<ClassificationSummary> classifications = classificationService.createClassificationQuery().typeIn("TASK", "DOCUMENT").parentIdIn("").list();
assertNotNull(classifications);
assertEquals(25, classifications.size());
List<ClassificationSummary> documentTypes = classifications.stream().filter(c -> c.getType().equals("DOCUMENT")).collect(Collectors.toList());
assertEquals(2, documentTypes.size());
List<ClassificationSummary> taskTypes = classifications.stream().filter(c -> c.getType().equals("TASK")).collect(Collectors.toList());
assertEquals(23, taskTypes.size());
}
use of pro.taskana.exceptions.ClassificationNotFoundException in project taskana by Taskana.
the class ClassificationServiceImplTest method testGetClassificationThrowingNotFoundException.
@Test(expected = ClassificationNotFoundException.class)
public void testGetClassificationThrowingNotFoundException() throws ClassificationNotFoundException {
Classification classification = createDummyClassification();
doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain());
doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), "");
try {
cutSpy.getClassification(classification.getKey(), classification.getDomain());
} catch (ClassificationNotFoundException e) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(classificationMapperMock, times(1)).findByKeyAndDomain(classification.getKey(), classification.getDomain());
verify(classificationMapperMock, times(1)).findByKeyAndDomain(classification.getKey(), "");
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
throw e;
}
}
use of pro.taskana.exceptions.ClassificationNotFoundException in project taskana by Taskana.
the class TaskServiceImpl method augmentAttachmentsByClassification.
private List<Attachment> augmentAttachmentsByClassification(List<AttachmentImpl> attachmentImpls, BulkOperationResults<String, Exception> bulkLog) {
List<Attachment> result = new ArrayList<>();
if (attachmentImpls == null || attachmentImpls.isEmpty()) {
return result;
}
Set<String> classificationIds = attachmentImpls.stream().map(t -> t.getClassificationSummary().getId()).collect(Collectors.toSet());
List<ClassificationSummary> classifications = classificationService.createClassificationQuery().idIn(classificationIds.toArray(new String[0])).list();
for (AttachmentImpl att : attachmentImpls) {
ClassificationSummary classificationSummary = classifications.stream().filter(cl -> cl.getId().equals(att.getClassificationSummary().getId())).findFirst().orElse(null);
if (classificationSummary == null) {
String id = att.getClassificationSummary().getId();
bulkLog.addError(att.getClassificationSummary().getId(), new ClassificationNotFoundException(id, "When processing task updates due to change of classification, the classification with id " + id + " was not found."));
} else {
att.setClassificationSummary(classificationSummary);
result.add(att);
}
}
return result;
}
use of pro.taskana.exceptions.ClassificationNotFoundException 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.exceptions.ClassificationNotFoundException 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);
}
Aggregations