Search in sources :

Example 6 with InvalidArgumentException

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());
}
Also used : Task(pro.taskana.Task) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskService(pro.taskana.TaskService) Instant(java.time.Instant) ArrayList(java.util.ArrayList) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Workbasket(pro.taskana.Workbasket) TaskanaException(pro.taskana.exceptions.TaskanaException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 7 with InvalidArgumentException

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());
}
Also used : SQLException(java.sql.SQLException) List(java.util.List) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) Assert.assertNotNull(org.junit.Assert.assertNotNull) ClassificationService(pro.taskana.ClassificationService) AbstractAccTest(acceptance.AbstractAccTest) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Test(org.junit.Test) ClassificationSummary(pro.taskana.ClassificationSummary) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) ClassificationSummary(pro.taskana.ClassificationSummary) ClassificationService(pro.taskana.ClassificationService) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test)

Example 8 with InvalidArgumentException

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);
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) ClassificationSummary(pro.taskana.ClassificationSummary) Attachment(pro.taskana.Attachment) Duration(java.time.Duration)

Example 9 with InvalidArgumentException

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);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) ClassificationService(pro.taskana.ClassificationService) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) ClassificationSummary(pro.taskana.ClassificationSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) MediaType(org.springframework.http.MediaType) Classification(pro.taskana.Classification) ClassificationMapper(pro.taskana.rest.resource.mapper.ClassificationMapper) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) ResponseEntity(org.springframework.http.ResponseEntity) ClassificationQuery(pro.taskana.ClassificationQuery) Transactional(org.springframework.transaction.annotation.Transactional) ResponseEntity(org.springframework.http.ResponseEntity) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with InvalidArgumentException

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);
}
Also used : PageMetadata(org.springframework.hateoas.PagedResources.PageMetadata) TaskSummaryResourcesAssembler(pro.taskana.rest.resource.mapper.TaskSummaryResourcesAssembler) TaskSummaryResource(pro.taskana.rest.resource.TaskSummaryResource) ResponseEntity(org.springframework.http.ResponseEntity) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskQuery(pro.taskana.TaskQuery) TaskSummary(pro.taskana.TaskSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)41 Test (org.junit.Test)24 AbstractAccTest (acceptance.AbstractAccTest)21 WithAccessId (pro.taskana.security.WithAccessId)19 TaskService (pro.taskana.TaskService)18 TaskSummary (pro.taskana.TaskSummary)16 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)12 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Task (pro.taskana.Task)7 Workbasket (pro.taskana.Workbasket)7 Classification (pro.taskana.Classification)6 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)6 SQLException (java.sql.SQLException)5 ClassificationSummary (pro.taskana.ClassificationSummary)5 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)5 WorkbasketService (pro.taskana.WorkbasketService)5 Instant (java.time.Instant)4 Collectors (java.util.stream.Collectors)4