use of pro.taskana.exceptions.ConcurrencyException 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.ConcurrencyException in project taskana by Taskana.
the class ClassificationServiceImpl method updateClassification.
@Override
public Classification updateClassification(Classification classification) throws NotAuthorizedException, ConcurrencyException, ClassificationNotFoundException, InvalidArgumentException {
LOGGER.debug("entry to updateClassification(Classification = {})", classification);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
ClassificationImpl classificationImpl = null;
try {
taskanaEngine.openConnection();
classificationImpl = (ClassificationImpl) classification;
// Check if current object is based on the newest (by modified)
Classification oldClassification = this.getClassification(classificationImpl.getKey(), classificationImpl.getDomain());
if (!oldClassification.getModified().equals(classificationImpl.getModified())) {
throw new ConcurrencyException("The current Classification has been modified while editing. The values can not be updated. Classification=" + classificationImpl.toString());
}
classificationImpl.setModified(Instant.now());
this.initDefaultClassificationValues(classificationImpl);
// Update classification fields used by tasks
if (oldClassification.getCategory() != classificationImpl.getCategory()) {
List<TaskSummary> taskSumamries = taskanaEngine.getTaskService().createTaskQuery().classificationIdIn(oldClassification.getId()).list();
boolean categoryChanged = !(oldClassification.getCategory() == null ? classification.getCategory() == null : oldClassification.getCategory().equals(classification.getCategory()));
if (!taskSumamries.isEmpty() && categoryChanged) {
List<String> taskIds = new ArrayList<>();
taskSumamries.stream().forEach(ts -> taskIds.add(ts.getTaskId()));
taskMapper.updateClassificationCategoryOnChange(taskIds, classificationImpl.getCategory());
}
}
// Check if parentId changed and object does exist
if (!oldClassification.getParentId().equals(classificationImpl.getParentId())) {
if (classificationImpl.getParentId() != null && !classificationImpl.getParentId().isEmpty()) {
this.getClassification(classificationImpl.getParentId());
}
}
classificationMapper.update(classificationImpl);
boolean priorityChanged = oldClassification.getPriority() != classification.getPriority();
boolean serviceLevelChanged = oldClassification.getServiceLevel() != classification.getServiceLevel();
if (priorityChanged || serviceLevelChanged) {
Map<String, String> args = new HashMap<>();
args.put(TaskUpdateOnClassificationChangeExecutor.CLASSIFICATION_ID, classificationImpl.getId());
args.put(TaskUpdateOnClassificationChangeExecutor.PRIORITY_CHANGED, String.valueOf(priorityChanged));
args.put(TaskUpdateOnClassificationChangeExecutor.SERVICE_LEVEL_CHANGED, String.valueOf(serviceLevelChanged));
Job job = new Job();
job.setCreated(Instant.now());
job.setState(Job.State.READY);
job.setExecutor(TaskUpdateOnClassificationChangeExecutor.class.getName());
job.setArguments(args);
taskanaEngine.getSqlSession().getMapper(JobMapper.class).insertJob(job);
}
LOGGER.debug("Method updateClassification() updated the classification {}.", classificationImpl);
return classification;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from updateClassification().");
}
}
use of pro.taskana.exceptions.ConcurrencyException in project taskana by Taskana.
the class UpdateTaskAccTest method testThrowsExceptionIfTaskHasAlreadyBeenUpdated.
@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testThrowsExceptionIfTaskHasAlreadyBeenUpdated() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException {
TaskService taskService = taskanaEngine.getTaskService();
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
Task task2 = taskService.getTask("TKI:000000000000000000000000000000000000");
task.setCustomAttribute("1", "willi");
Task updatedTask = null;
updatedTask = taskService.updateTask(task);
updatedTask = taskService.getTask(updatedTask.getId());
task2.setCustomAttribute("2", "Walter");
try {
updatedTask = taskService.updateTask(task2);
} catch (ConcurrencyException ex) {
assertEquals("The task has already been updated by another user", ex.getMessage());
}
}
Aggregations