Search in sources :

Example 1 with ClassificationAlreadyExistException

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

the class ClassificationServiceImplTest method testCreateClassificationAlreadyExisting.

@Test(expected = ClassificationAlreadyExistException.class)
public void testCreateClassificationAlreadyExisting() throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = createDummyClassification();
    doReturn(classification).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain());
    doReturn(true).when(taskanaEngineImplMock).domainExists(any());
    try {
        cutSpy.createClassification(classification);
    } catch (ClassificationAlreadyExistException e) {
        verify(taskanaEngineImplMock, times(1)).openConnection();
        verify(classificationMapperMock, times(1)).findByKeyAndDomain(classification.getKey(), classification.getDomain());
        verify(taskanaEngineImplMock, times(1)).returnConnection();
        verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any());
        verify(taskanaEngineImplMock, times(1)).domainExists(any());
        verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
        throw e;
    }
}
Also used : Classification(pro.taskana.Classification) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) Test(org.junit.Test)

Example 2 with ClassificationAlreadyExistException

use of pro.taskana.exceptions.ClassificationAlreadyExistException 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 3 with ClassificationAlreadyExistException

use of pro.taskana.exceptions.ClassificationAlreadyExistException 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 4 with ClassificationAlreadyExistException

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

the class ClassificationServiceImplIntAutoCommitTest method testInsertClassifications.

@Test
public void testInsertClassifications() throws Exception {
    final String domain = "DOMAIN_A";
    final String key = "dummy-key";
    ClassificationImpl expectedClassification;
    Classification actualClassification;
    Classification actualClassification2;
    // empty classification (root)
    expectedClassification = (ClassificationImpl) this.createDummyClassificationWithUniqueKey("", "TASK");
    expectedClassification = (ClassificationImpl) classificationService.createClassification(expectedClassification);
    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.createDummyClassificationWithUniqueKey(domain, "TASK");
    expectedClassification.setKey(key);
    expectedClassification = (ClassificationImpl) classificationService.createClassification(expectedClassification);
    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.createDummyClassificationWithUniqueKey(domain, "TASK");
        expectedClassification.setKey(key);
        classificationService.createClassification(expectedClassification);
        fail("Should have thrown 'ClassificationAlreadyExistException' here.");
    } catch (ClassificationAlreadyExistException e) {
    }
    // new classification but root existing
    expectedClassification = (ClassificationImpl) this.createDummyClassificationWithUniqueKey("DOMAIN_B", "TASK");
    expectedClassification.setKey(key);
    classificationService.createClassification(expectedClassification);
    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));
    // verify that
    Classification rootResults = classificationService.getClassification(key, "");
    assertThat(rootResults, not(equalTo(null)));
    // invalid serviceLevel
    try {
        expectedClassification = (ClassificationImpl) this.createDummyClassificationWithUniqueKey(domain, "TASK");
        expectedClassification.setKey("");
        expectedClassification.setServiceLevel("ASAP");
        classificationService.createClassification(expectedClassification);
        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) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Aggregations

Classification (pro.taskana.Classification)4 ClassificationAlreadyExistException (pro.taskana.exceptions.ClassificationAlreadyExistException)4 Test (org.junit.Test)3 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)3 ClassificationImpl (pro.taskana.impl.ClassificationImpl)2 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 HttpStatus (org.springframework.http.HttpStatus)1 MediaType (org.springframework.http.MediaType)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 RequestBody (org.springframework.web.bind.annotation.RequestBody)1