Search in sources :

Example 1 with ClassificationImpl

use of pro.taskana.impl.ClassificationImpl in project taskana by Taskana.

the class TaskServiceImplIntAutocommitTest method shouldNotTransferByFailingSecurity.

@WithAccessId(userName = "User", groupNames = { "businessadmin" })
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException, TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    final String user = CurrentUserContext.getUserid();
    // Set up Security for this Test
    dataSource = TaskanaEngineConfigurationTest.getDataSource();
    taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, true);
    taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
    taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
    taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
    taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
    classificationService = taskanaEngine.getClassificationService();
    workbasketService = taskanaEngine.getWorkbasketService();
    ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("KEY", "DOMAIN_A", "TASK");
    classification.setCategory("EXTERNAL");
    classification.setName("Transfert-Task Classification");
    classificationService.createClassification(classification);
    WorkbasketImpl wb = (WorkbasketImpl) workbasketService.newWorkbasket("k5", "DOMAIN_A");
    wb.setName("BASE WB");
    wb.setDescription("Normal base WB");
    wb.setOwner(user);
    wb.setType(WorkbasketType.TOPIC);
    wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
    createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
    WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket("key77", "DOMAIN_A");
    wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
    wbNoAppend.setDescription("Workbasket without permission APPEND on Task");
    wbNoAppend.setOwner(user);
    wbNoAppend.setType(WorkbasketType.PERSONAL);
    wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
    createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
    WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket("k99", "DOMAIN_B");
    wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
    wbNoTransfer.setDescription("Workbasket without permission TRANSFER on Task");
    wbNoTransfer.setOwner(user);
    wbNoTransfer.setType(WorkbasketType.CLEARANCE);
    wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
    createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
    TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wb.getId());
    task.setName("Task Name");
    task.setDescription("Task used for transfer Test");
    task.setOwner(user);
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = (TaskImpl) taskServiceImpl.createTask(task);
    // Check failing with missing APPEND
    try {
        task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wbNoAppend.getId());
        fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
    } catch (NotAuthorizedException e) {
        if (!e.getMessage().contains("APPEND")) {
            fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
        }
        assertThat(task.isTransferred(), equalTo(false));
        assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
        assertThat(task.getWorkbasketKey(), equalTo(wb.getKey()));
    }
    // Check failing with missing TRANSFER
    task.setId("");
    task.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
    task.setWorkbasketKey(null);
    task = (TaskImpl) taskServiceImpl.createTask(task);
    try {
        task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wb.getId());
        fail("Transfer Task should be FAILD, because there are no TRANSFER-Rights on current WB.");
    } catch (NotAuthorizedException e) {
        if (!e.getMessage().contains("TRANSFER")) {
            fail("Transfer Task should be FAILD, because there are no APPEND-Rights on current WB.");
        }
        assertThat(task.isTransferred(), equalTo(false));
        assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
    }
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) TaskImpl(pro.taskana.impl.TaskImpl) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 2 with ClassificationImpl

use of pro.taskana.impl.ClassificationImpl in project taskana by Taskana.

the class ClassificationMapperTest method resourceToClassification.

@Test
public void resourceToClassification() throws NotAuthorizedException {
    // given
    ClassificationResource classificationResource = new ClassificationResource();
    classificationResource.setClassificationId("1");
    classificationResource.setKey("12");
    classificationResource.setName("TestB");
    classificationResource.setType("AB");
    classificationResource.setDomain("DOMAIN_B");
    classificationResource.setApplicationEntryPoint("Test");
    classificationResource.setCategory("ABC");
    classificationResource.setCreated("2010-01-01T12:00:00Z");
    classificationResource.setModified("2011-11-11T11:00:00Z");
    classificationResource.setCustom1("Custom");
    classificationResource.setCustom2("Custom2");
    classificationResource.setCustom1("Custom1");
    classificationResource.setCustom3("Custom3");
    classificationResource.setCustom4("Custom4");
    classificationResource.setCustom5("Custom5");
    classificationResource.setCustom6("Custom6");
    classificationResource.setCustom7("Custom7");
    classificationResource.setCustom8("Custom8");
    classificationResource.setParentId("2");
    classificationResource.setPriority(2);
    classificationResource.setApplicationEntryPoint("12");
    classificationResource.setServiceLevel("P1D");
    classificationResource.setDescription("Test");
    // when
    ClassificationImpl classification = (ClassificationImpl) classificationMapper.toModel(classificationResource);
    // then
    testEquality(classification, classificationResource);
}
Also used : ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationImpl(pro.taskana.impl.ClassificationImpl) Test(org.junit.Test)

Example 3 with ClassificationImpl

use of pro.taskana.impl.ClassificationImpl in project taskana by Taskana.

the class ClassificationMapperTest method classificationToResource.

@Test
public void classificationToResource() throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
    // given
    ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("DOMAIN_A", "1", "A");
    classification.setId("1");
    classification.setCategory("ABC");
    classification.setName("Classification 1");
    classification.setIsValidInDomain(false);
    classification.setCustom1("Custom1");
    classification.setCustom2("Custom2");
    classification.setCustom3("Custom3");
    classification.setCustom4("Custom4");
    classification.setCustom5("Custom5");
    classification.setCustom6("Custom6");
    classification.setCustom7("Custom7");
    classification.setCustom8("Custom8");
    classification.setParentId("2");
    classification.setPriority(2);
    classification.setApplicationEntryPoint("12");
    classification.setServiceLevel("P1D");
    classification.setDescription("Test");
    classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
    classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
    // when
    ClassificationResource classificationResource = classificationMapper.toResource(classification);
    // then
    testEquality(classification, classificationResource);
}
Also used : ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationImpl(pro.taskana.impl.ClassificationImpl) Test(org.junit.Test)

Example 4 with ClassificationImpl

use of pro.taskana.impl.ClassificationImpl in project taskana by Taskana.

the class ClassificationServiceImplIntExplicitTest method testInsertClassification.

@Test
public void testInsertClassification() throws SQLException, ClassificationNotFoundException, ClassificationAlreadyExistException, NotAuthorizedException, DomainNotFoundException, InvalidArgumentException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    final String domain = "DOMAIN_A";
    final String key = "dummy-key";
    ClassificationImpl expectedClassification;
    Classification actualClassification;
    Classification actualClassification2;
    // empty classification (root)
    expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey("", "TASK");
    expectedClassification = (ClassificationImpl) classificationService.createClassification(expectedClassification);
    connection.commit();
    actualClassification = classificationService.getClassification(expectedClassification.getKey(), expectedClassification.getDomain());
    assertThat(actualClassification, not(equalTo(null)));
    assertThat(actualClassification.getCreated(), not(equalTo(null)));
    assertThat(actualClassification.getId(), not(equalTo(null)));
    assertThat(actualClassification.getId(), startsWith(ID_PREFIX_CLASSIFICATION));
    // specific to domain + root
    expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey(domain, "TASK");
    expectedClassification.setKey(key);
    expectedClassification = (ClassificationImpl) classificationService.createClassification(expectedClassification);
    connection.commit();
    actualClassification = classificationService.getClassification(expectedClassification.getKey(), expectedClassification.getDomain());
    actualClassification2 = classificationService.getClassification(expectedClassification.getKey(), "");
    assertThat(actualClassification, not(equalTo(null)));
    assertThat(actualClassification.getCreated(), not(equalTo(null)));
    assertThat(actualClassification.getId(), not(equalTo(null)));
    assertThat(actualClassification.getKey(), equalTo(key));
    assertThat(actualClassification.getDomain(), equalTo(domain));
    assertThat(actualClassification.getId(), startsWith(ID_PREFIX_CLASSIFICATION));
    assertThat(actualClassification2, not(equalTo(null)));
    assertThat(actualClassification2.getCreated(), not(equalTo(null)));
    assertThat(actualClassification2.getId(), not(equalTo(null)));
    assertThat(actualClassification2.getId(), not(equalTo(actualClassification.getId())));
    assertThat(actualClassification2.getKey(), equalTo(key));
    assertThat(actualClassification2.getDomain(), equalTo(""));
    assertThat(actualClassification2.getId(), startsWith(ID_PREFIX_CLASSIFICATION));
    // does exist already
    try {
        expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey(domain, "TASK");
        expectedClassification.setKey(key);
        classificationService.createClassification(expectedClassification);
        connection.commit();
        fail("Should have thrown 'ClassificationAlreadyExistException' here.");
    } catch (ClassificationAlreadyExistException e) {
    }
    // new classification but root existing
    expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey("", "TASK");
    expectedClassification.setKey(key);
    expectedClassification.setDomain("DOMAIN_B");
    classificationService.createClassification(expectedClassification);
    connection.commit();
    actualClassification = classificationService.getClassification(key, "DOMAIN_B");
    assertThat(actualClassification, not(equalTo(null)));
    assertThat(actualClassification.getCreated(), not(equalTo(null)));
    assertThat(actualClassification.getId(), not(equalTo(null)));
    assertThat(actualClassification.getKey(), equalTo(key));
    assertThat(actualClassification.getDomain(), equalTo("DOMAIN_B"));
    assertThat(actualClassification.getId(), startsWith(ID_PREFIX_CLASSIFICATION));
    Classification rootResult = classificationService.getClassification(key, "");
    assertThat(rootResult, not(equalTo(null)));
    // invalid serviceLevel
    try {
        expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey("", "TASK");
        expectedClassification.setDomain(domain);
        expectedClassification.setKey("");
        expectedClassification.setServiceLevel("ASAP");
        classificationService.createClassification(expectedClassification);
        connection.commit();
        fail("Should have thrown IllegalArgumentException, because ServiceLevel is invalid.");
    } catch (InvalidArgumentException e) {
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) Classification(pro.taskana.Classification) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) Connection(java.sql.Connection) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Example 5 with ClassificationImpl

use of pro.taskana.impl.ClassificationImpl in project taskana by Taskana.

the class TaskServiceImplIntExplicitTest method shouldNotTransferByFailingSecurity.

@WithAccessId(userName = "User", groupNames = { "businessadmin" })
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException, TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    final String user = "User";
    // Set up Security for this Test
    dataSource = TaskanaEngineConfigurationTest.getDataSource();
    taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, true);
    taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
    taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
    taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
    taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
    classificationService = taskanaEngine.getClassificationService();
    workbasketService = taskanaEngine.getWorkbasketService();
    ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("KEY", "DOMAIN_A", "TASK");
    classification.setCategory("EXTERNAL");
    classification.setName("Transfert-Task Classification");
    classificationService.createClassification(classification);
    WorkbasketImpl wb = (WorkbasketImpl) workbasketService.newWorkbasket("wbKey1", "DOMAIN_A");
    wb.setName("BASE WB");
    wb.setDescription("Normal base WB");
    wb.setOwner(user);
    wb.setType(WorkbasketType.GROUP);
    wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
    createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
    WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket("keyNoAppend", "DOMAIN_B");
    wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
    wbNoAppend.setDescription("Workbasket without permission APPEND on Task");
    wbNoAppend.setOwner(user);
    wbNoAppend.setType(WorkbasketType.CLEARANCE);
    wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
    createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
    WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket("keyNoTransfer", "DOMAIN_A");
    wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
    wbNoTransfer.setDescription("Workbasket without permission TRANSFER on Task");
    wbNoTransfer.setOwner(user);
    wbNoTransfer.setType(WorkbasketType.GROUP);
    wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
    createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
    TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wb.getId());
    task.setName("Task Name");
    task.setDescription("Task used for transfer Test");
    task.setOwner(user);
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = (TaskImpl) taskServiceImpl.createTask(task);
    // Check failing with missing APPEND
    try {
        task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wbNoAppend.getId());
        fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
    } catch (NotAuthorizedException e) {
        if (!e.getMessage().contains("APPEND")) {
            fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
        }
        assertThat(task.isTransferred(), equalTo(false));
        assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
        assertThat(task.getWorkbasketKey(), equalTo(wb.getKey()));
    }
    // Check failing with missing TRANSFER
    task.setId("");
    task.setWorkbasketKey(wbNoTransfer.getKey());
    task.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
    task = (TaskImpl) taskServiceImpl.createTask(task);
    try {
        task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wb.getId());
        fail("Transfer Task should be FAILD, because there are no TRANSFER-Rights on current WB.");
    } catch (NotAuthorizedException e) {
        if (!e.getMessage().contains("TRANSFER")) {
            fail("Transfer Task should be FAILD, because there are no APPEND-Rights on current WB.");
        }
        assertThat(task.isTransferred(), equalTo(false));
        assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
    }
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) TaskImpl(pro.taskana.impl.TaskImpl) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

ClassificationImpl (pro.taskana.impl.ClassificationImpl)9 Test (org.junit.Test)8 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)6 TaskImpl (pro.taskana.impl.TaskImpl)4 WorkbasketImpl (pro.taskana.impl.WorkbasketImpl)4 WithAccessId (pro.taskana.security.WithAccessId)3 Connection (java.sql.Connection)2 Classification (pro.taskana.Classification)2 Task (pro.taskana.Task)2 Workbasket (pro.taskana.Workbasket)2 TaskanaEngineConfiguration (pro.taskana.configuration.TaskanaEngineConfiguration)2 ClassificationAlreadyExistException (pro.taskana.exceptions.ClassificationAlreadyExistException)2 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)2 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)2 ClassificationResource (pro.taskana.rest.resource.ClassificationResource)2