use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TransferTaskAccTest method testBulkTransferTaskWithExceptions.
@WithAccessId(userName = "teamlead_1", groupNames = { "group_1" })
@Test
public void testBulkTransferTaskWithExceptions() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, InvalidStateException, InvalidOwnerException {
TaskService taskService = taskanaEngine.getTaskService();
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket("USER_1_1", "DOMAIN_A");
Instant before = Instant.now();
ArrayList<String> taskIdList = new ArrayList<>();
// working
taskIdList.add("TKI:000000000000000000000000000000000006");
// NotAuthorized
taskIdList.add("TKI:000000000000000000000000000000000041");
// InvalidArgument
taskIdList.add("");
// InvalidArgument (added with ""), duplicate
taskIdList.add(null);
// TaskNotFound
taskIdList.add("TKI:000000000000000000000000000000000099");
BulkOperationResults<String, TaskanaException> results = taskService.transferTasks("WBI:100000000000000000000000000000000006", taskIdList);
assertTrue(results.containsErrors());
assertThat(results.getErrorMap().values().size(), equalTo(3));
// react to result
for (String taskId : results.getErrorMap().keySet()) {
TaskanaException ex = results.getErrorForId(taskId);
if (ex instanceof NotAuthorizedException) {
System.out.println("NotAuthorizedException on bulkTransfer for taskId=" + taskId);
} else if (ex instanceof InvalidArgumentException) {
System.out.println("InvalidArgumentException on bulkTransfer for EMPTY/NULL taskId='" + taskId + "'");
} else if (ex instanceof TaskNotFoundException) {
System.out.println("TaskNotFoundException on bulkTransfer for taskId=" + taskId);
} else {
fail("Impossible failure Entry registered");
}
}
Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000006");
assertNotNull(transferredTask);
assertTrue(transferredTask.isTransferred());
assertFalse(transferredTask.isRead());
assertEquals(TaskState.READY, transferredTask.getState());
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
assertFalse(transferredTask.getModified().isBefore(before));
assertThat(transferredTask.getOwner(), equalTo(null));
transferredTask = taskService.getTask("TKI:000000000000000000000000000000000002");
assertNotNull(transferredTask);
assertFalse(transferredTask.isTransferred());
assertEquals("USER_1_1", transferredTask.getWorkbasketKey());
}
use of pro.taskana.exceptions.InvalidArgumentException 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.InvalidArgumentException in project taskana by Taskana.
the class TaskServiceImpl method handleAttachments.
private PrioDurationHolder handleAttachments(TaskImpl task) throws InvalidArgumentException {
List<Attachment> attachments = task.getAttachments();
if (attachments == null || attachments.isEmpty()) {
return new PrioDurationHolder(null, Integer.MIN_VALUE);
}
Duration minDuration = MAX_DURATION;
int maxPrio = Integer.MIN_VALUE;
Iterator<Attachment> i = attachments.iterator();
while (i.hasNext()) {
Attachment attachment = i.next();
if (attachment == null) {
i.remove();
} else {
ObjectReference objRef = attachment.getObjectReference();
validateObjectReference(objRef, "ObjectReference", "Attachment");
if (attachment.getClassificationSummary() == null) {
throw new InvalidArgumentException("Classification of attachment " + attachment + " must not be null");
} else {
ClassificationSummary classificationSummary = attachment.getClassificationSummary();
if (classificationSummary != null) {
PrioDurationHolder newPrioDuraton = getNewPrioDuration(maxPrio, minDuration, classificationSummary.getPriority(), classificationSummary.getServiceLevel());
maxPrio = newPrioDuraton.getPrio();
minDuration = newPrioDuraton.getDuration();
}
}
}
}
if (minDuration != null && MAX_DURATION.equals(minDuration)) {
minDuration = null;
}
return new PrioDurationHolder(minDuration, maxPrio);
}
use of pro.taskana.exceptions.InvalidArgumentException 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.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TaskController method getTasks.
@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException, NotAuthorizedException {
TaskQuery query = taskService.createTaskQuery();
query = applyFilterParams(query, params);
query = applySortingParams(query, params);
PageMetadata pageMetadata = null;
List<TaskSummary> taskSummaries = null;
String page = params.getFirst(PAGING_PAGE);
String pageSize = params.getFirst(PAGING_PAGE_SIZE);
if (page != null && pageSize != null) {
// paging
long totalElements = query.count();
pageMetadata = initPageMetadata(pageSize, page, totalElements);
taskSummaries = query.listPage((int) pageMetadata.getNumber(), (int) pageMetadata.getSize());
} else if (page == null && pageSize == null) {
// not paging
taskSummaries = query.list();
} else {
throw new InvalidArgumentException("Paging information is incomplete.");
}
TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries, pageMetadata);
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
Aggregations