use of pro.taskana.Classification in project taskana by Taskana.
the class ClassificationServiceImpl method getClassification.
@Override
public Classification getClassification(String id) throws ClassificationNotFoundException {
if (id == null) {
throw new ClassificationNotFoundException(id, "Classification for id " + id + " was not found.");
}
LOGGER.debug("entry to getClassification(id = {})", id);
Classification result = null;
try {
taskanaEngine.openConnection();
result = classificationMapper.findById(id);
if (result == null) {
LOGGER.error("Classification for id {} was not found. Throwing ClassificationNotFoundException", id);
throw new ClassificationNotFoundException(id, "Classification for id " + id + " was not found");
}
return result;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from getClassification(). Returning result {} ", result);
}
}
use of pro.taskana.Classification 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.Classification in project taskana by Taskana.
the class DeleteClassificationAccTest method testDeleteClassificationInDomain.
@WithAccessId(userName = "dummy", groupNames = { "businessadmin" })
@Test
public void testDeleteClassificationInDomain() throws SQLException, ClassificationNotFoundException, NotAuthorizedException, ClassificationInUseException {
classificationService.deleteClassification("L140101", "DOMAIN_A");
Classification classification = classificationService.getClassification("L140101", "DOMAIN_A");
assertNotNull(classification);
assertEquals("", classification.getDomain());
}
use of pro.taskana.Classification in project taskana by Taskana.
the class CreateClassificationAccTest method testCreateClassificationOfUnknownType.
@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test(expected = InvalidArgumentException.class)
public void testCreateClassificationOfUnknownType() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
Classification classification = classificationService.newClassification("Key3", "DOMAIN_A", "UNKNOWN_TYPE");
classification = classificationService.createClassification(classification);
}
use of pro.taskana.Classification in project taskana by Taskana.
the class CreateClassificationAccTest method testCreateClassificationInUnknownDomain.
@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test(expected = DomainNotFoundException.class)
public void testCreateClassificationInUnknownDomain() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
Classification classification = classificationService.newClassification("Key3", "UNKNOWN_DOMAIN", "TASK");
classification = classificationService.createClassification(classification);
}
Aggregations