Search in sources :

Example 36 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class QueryTasksAccTest method testQueryForCustom2.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1" })
@Test
public void testQueryForCustom2() throws SQLException, NotAuthorizedException, InvalidArgumentException {
    TaskService taskService = taskanaEngine.getTaskService();
    List<TaskSummary> results = taskService.createTaskQuery().customAttributeLike("2", "%a%", "%b%", "%c%", "%d%", "%e%", "%f%", "%g%", "%h%", "%i%", "%j%", "%k%", "%l%", "%m%", "%n%", "%o%", "%p%", "%q%", "%r%", "%s%", "%w%").list();
    assertThat(results.size(), equalTo(1));
    String[] ids = results.stream().map(t -> {
        try {
            return t.getCustomAttribute("2");
        } catch (InvalidArgumentException e) {
            e.printStackTrace();
            return "";
        }
    }).collect(Collectors.toList()).toArray(new String[0]);
    List<TaskSummary> result2 = taskService.createTaskQuery().customAttributeIn("2", ids).list();
    assertThat(result2.size(), equalTo(1));
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 37 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class QueryClassificationAccTest method testGetClassificationsForKeyAndCategories.

@Test
public void testGetClassificationsForKeyAndCategories() throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
    ClassificationService classificationService = taskanaEngine.getClassificationService();
    List<ClassificationSummary> classifications = classificationService.createClassificationQuery().keyIn("T2100", "L10000").categoryIn("EXTERNAL", "MANUAL").list();
    assertNotNull(classifications);
    assertEquals(5, classifications.size());
    List<ClassificationSummary> externCategory = classifications.stream().filter(c -> c.getCategory().equals("EXTERNAL")).collect(Collectors.toList());
    assertEquals(2, externCategory.size());
    List<ClassificationSummary> manualCategory = classifications.stream().filter(c -> c.getCategory().equals("MANUAL")).collect(Collectors.toList());
    assertEquals(3, manualCategory.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 38 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class CreateClassificationAccTest method testCreateClassificationWithInvalidValues.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test
public void testCreateClassificationWithInvalidValues() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    long amountOfClassificationsBefore = classificationService.createClassificationQuery().count();
    // Check key NULL
    try {
        Classification classification = classificationService.newClassification(null, "DOMAIN_A", "TASK");
        classification = classificationService.createClassification(classification);
    } catch (InvalidArgumentException e) {
    // nothing to do
    }
    // Check invalid ServiceLevel
    try {
        Classification classification = classificationService.newClassification("Key2", "DOMAIN_B", "TASK");
        classification.setServiceLevel("abc");
        classification = classificationService.createClassification(classification);
    } catch (InvalidArgumentException e) {
    // nothing to do
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) Classification(pro.taskana.Classification) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 39 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class WorkbasketServiceImpl method updateWorkbasketAccessItem.

@Override
public WorkbasketAccessItem updateWorkbasketAccessItem(WorkbasketAccessItem workbasketAccessItem) throws InvalidArgumentException, NotAuthorizedException {
    LOGGER.debug("entry to updateWorkbasketAccessItem(workbasketAccessItem = {}", workbasketAccessItem);
    taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
    WorkbasketAccessItemImpl accessItem = (WorkbasketAccessItemImpl) workbasketAccessItem;
    try {
        taskanaEngine.openConnection();
        WorkbasketAccessItem originalItem = workbasketAccessMapper.findById(accessItem.getId());
        if ((originalItem.getAccessId() != null && !originalItem.getAccessId().equals(accessItem.getAccessId())) || (originalItem.getWorkbasketId() != null && !originalItem.getWorkbasketId().equals(accessItem.getWorkbasketId()))) {
            throw new InvalidArgumentException("AccessId and WorkbasketId must not be changed in updateWorkbasketAccessItem calls");
        }
        workbasketAccessMapper.update(accessItem);
        LOGGER.debug("Method updateWorkbasketAccessItem() updated workbasketAccessItem {}", accessItem);
        return accessItem;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from updateWorkbasketAccessItem(workbasketAccessItem). Returning {}", accessItem);
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem)

Example 40 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class WorkbasketServiceImpl method setWorkbasketAccessItems.

@Override
public void setWorkbasketAccessItems(String workbasketId, List<WorkbasketAccessItem> wbAccessItems) throws InvalidArgumentException, NotAuthorizedException {
    LOGGER.debug("entry to setWorkbasketAccessItems(workbasketAccessItems = {})", wbAccessItems.toString());
    taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
    List<WorkbasketAccessItemImpl> newItems = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        // Check pre-conditions and set ID
        if (!wbAccessItems.isEmpty()) {
            for (WorkbasketAccessItem workbasketAccessItem : wbAccessItems) {
                WorkbasketAccessItemImpl wbAccessItemImpl = (WorkbasketAccessItemImpl) workbasketAccessItem;
                if (wbAccessItemImpl.getWorkbasketId() == null) {
                    LOGGER.error("setWorkbasketAccessItem failed because WorkbasketAccessItem {} has a null workbasketId. Throwing InvalidArgumentException.", workbasketAccessItem);
                    throw new InvalidArgumentException("Checking the preconditions of the current WorkbasketAccessItem failed - WBID is NULL. WorkbasketAccessItem=" + workbasketAccessItem.toString());
                } else if (!wbAccessItemImpl.getWorkbasketId().equals(workbasketId)) {
                    LOGGER.error("setWorkbasketAccessItem failed because WorkbasketAccessItem {} does not refer to workbasket {}. Throwing InvalidArgumentException.", workbasketAccessItem, workbasketId);
                    throw new InvalidArgumentException("Checking the preconditions of the current WorkbasketAccessItem failed - the WBID does not match. Target-WBID='" + workbasketId + "' WorkbasketAccessItem=" + workbasketAccessItem.toString());
                }
                if (wbAccessItemImpl.getId() == null || wbAccessItemImpl.getId().isEmpty()) {
                    wbAccessItemImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
                }
                newItems.add(wbAccessItemImpl);
            }
            // delete all current ones
            workbasketAccessMapper.deleteAllAccessItemsForWorkbasketId(workbasketId);
            // add all
            newItems.stream().forEach(item -> workbasketAccessMapper.insert(item));
        }
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from setWorkbasketAccessItems(workbasketAccessItems = {})", wbAccessItems.toString());
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList)

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