use of pro.taskana.TaskSummary in project taskana by Taskana.
the class TaskServiceImpl method completeTasks.
@Override
public BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds) throws InvalidArgumentException {
try {
LOGGER.debug("entry to completeTasks(taskIds = {})", taskIds);
taskanaEngine.openConnection();
// Check pre-conditions with throwing Exceptions
if (taskIds == null) {
throw new InvalidArgumentException("TaskIds canĀ“t be used as NULL-Parameter.");
}
// process bulk-complete
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
if (!taskIds.isEmpty()) {
// remove null/empty taskIds with message
Iterator<String> taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
if (currentTaskId == null || currentTaskId.isEmpty()) {
bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed and invalid."));
taskIdIterator.remove();
}
}
// query for existing tasks, modify values and LOG missing ones.
List<TaskSummary> taskSummaries = this.createTaskQuery().idIn(taskIds.toArray(new String[0])).list();
Instant now = Instant.now();
taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
TaskSummaryImpl taskSummary = (TaskSummaryImpl) taskSummaries.stream().filter(ts -> currentTaskId.equals(ts.getTaskId())).findFirst().orElse(null);
if (taskSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "task with id " + currentTaskId + " was not found."));
taskIdIterator.remove();
} else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
taskIdIterator.remove();
} else if (!CurrentUserContext.getAccessIds().contains(taskSummary.getOwner())) {
bulkLog.addError(currentTaskId, new InvalidOwnerException("TaskOwner is" + taskSummary.getOwner() + ", but current User is " + CurrentUserContext.getUserid()));
taskIdIterator.remove();
} else {
taskSummary.setCompleted(now);
taskSummary.setModified(now);
taskSummary.setState(TaskState.COMPLETED);
}
}
if (!taskIds.isEmpty() && !taskSummaries.isEmpty()) {
taskMapper.updateCompleted(taskIds, (TaskSummaryImpl) taskSummaries.get(0));
}
}
return bulkLog;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from to completeTasks(taskIds = {})", taskIds);
}
}
use of pro.taskana.TaskSummary 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.TaskSummary in project taskana by Taskana.
the class QueryTasksByObjectReferenceAccTest method testQueryTasksByValueLikeOfObjectReference.
@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "group_2" })
@Test
public void testQueryTasksByValueLikeOfObjectReference() throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery().primaryObjectReferenceValueLike("%567%").list();
Assert.assertEquals(10L, results.size());
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class QueryTasksByObjectReferenceAccTest method testQueryTasksByExcactValueAndTypeOfObjectReference.
@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "group_2" })
@Test
public void testQueryTasksByExcactValueAndTypeOfObjectReference() throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery().primaryObjectReferenceTypeIn("SDNR").primaryObjectReferenceValueIn("11223344").list();
Assert.assertEquals(10L, results.size());
}
use of pro.taskana.TaskSummary in project taskana by Taskana.
the class QueryTasksByObjectReferenceAccTest method testQueryTasksByExcactValueOfObjectReference.
@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "group_2" })
@Test
public void testQueryTasksByExcactValueOfObjectReference() throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery().primaryObjectReferenceValueIn("11223344", "22334455").list();
Assert.assertEquals(32L, results.size());
}
Aggregations