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;
}
}
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);
}
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) {
}
}
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) {
}
}
Aggregations