use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationServiceImplTest method testUpdateClassificationParentNotExisting.
@Test(expected = ClassificationNotFoundException.class)
public void testUpdateClassificationParentNotExisting() throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, ConcurrencyException, InvalidArgumentException {
Instant now = Instant.now();
ClassificationImpl oldClassification = (ClassificationImpl) createDummyClassification();
oldClassification.setParentId("SOME ID");
oldClassification.setCreated(now);
oldClassification.setModified(now);
Classification classification = createDummyClassification();
classification.setParentId("DIFFERENT ID - FOR CHECKING PARENT");
((ClassificationImpl) classification).setCreated(oldClassification.getCreated());
((ClassificationImpl) classification).setModified(oldClassification.getModified());
doReturn(oldClassification).when(cutSpy).getClassification(classification.getKey(), classification.getDomain());
doReturn(null).when(classificationMapperMock).findById(classification.getParentId());
try {
cutSpy.updateClassification(classification);
} catch (ClassificationNotFoundException e) {
verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any());
verify(taskanaEngineImplMock, times(2)).openConnection();
verify(cutSpy, times(1)).getClassification(classification.getKey(), classification.getDomain());
verify(cutSpy, times(1)).getClassification(classification.getParentId());
verify(classificationMapperMock, times(1)).findById(classification.getParentId());
verify(taskanaEngineImplMock, times(2)).returnConnection();
verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
throw e;
}
}
use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationController method updateClassification.
@PutMapping
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<ClassificationResource> updateClassification(@RequestBody ClassificationResource resource) throws NotAuthorizedException, ClassificationNotFoundException, ConcurrencyException, ClassificationAlreadyExistException, DomainNotFoundException, InvalidArgumentException {
Classification classification = classificationMapper.toModel(resource);
classification = classificationService.updateClassification(classification);
return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification));
}
use of pro.taskana.Classification 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);
}
use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImpl method createTask.
@Override
public Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidArgumentException {
LOGGER.debug("entry to createTask(task = {})", taskToCreate);
TaskImpl task = (TaskImpl) taskToCreate;
try {
taskanaEngine.openConnection();
if (task.getId() != "" && task.getId() != null) {
throw new TaskAlreadyExistException(task.getId());
} else {
LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId());
Workbasket workbasket;
if (task.getWorkbasketSummary().getId() != null) {
workbasket = workbasketService.getWorkbasket(task.getWorkbasketSummary().getId());
} else if (task.getWorkbasketKey() != null) {
workbasket = workbasketService.getWorkbasket(task.getWorkbasketKey(), task.getDomain());
} else {
throw new InvalidArgumentException("Cannot create a task outside a workbasket");
}
task.setWorkbasketSummary(workbasket.asSummary());
task.setDomain(workbasket.getDomain());
workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
String classificationKey = task.getClassificationKey();
if (classificationKey == null || classificationKey.length() == 0) {
throw new InvalidArgumentException("classificationKey of task must not be empty");
}
Classification classification = this.classificationService.getClassification(classificationKey, workbasket.getDomain());
task.setClassificationSummary(classification.asSummary());
validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
standardSettings(task, classification, prioDurationFromAttachments);
this.taskMapper.insert(task);
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
}
return task;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from createTask(task = {})", task);
}
}
use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImpl method classificationChanged.
BulkOperationResults<String, Exception> classificationChanged(String taskId, String classificationId) throws TaskNotFoundException, NotAuthorizedException, ClassificationNotFoundException {
LOGGER.debug("entry to classificationChanged(taskId = {} , classificationId = {} )", taskId, classificationId);
TaskImpl task = null;
BulkOperationResults<String, Exception> bulkLog = new BulkOperationResults<>();
try {
taskanaEngine.openConnection();
if (taskId == null || taskId.isEmpty() || classificationId == null || classificationId.isEmpty()) {
return bulkLog;
}
task = taskMapper.findById(taskId);
List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(task.getId());
if (attachmentImpls == null) {
attachmentImpls = new ArrayList<>();
}
List<Attachment> attachments = augmentAttachmentsByClassification(attachmentImpls, bulkLog);
task.setAttachments(attachments);
Classification classification = classificationService.getClassification(classificationId);
task.setClassificationSummary(classification.asSummary());
PrioDurationHolder prioDurationFromAttachments = handleAttachmentsOnClassificationUpdate(task);
updateClassificationRelatedProperties(task, task, prioDurationFromAttachments);
task.setModified(Instant.now());
taskMapper.update(task);
return bulkLog;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteTask(). ");
}
}
Aggregations