Search in sources :

Example 36 with TaskSummary

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);
    }
}
Also used : Arrays(java.util.Arrays) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) IdGenerator(pro.taskana.impl.util.IdGenerator) LoggerFactory(org.slf4j.LoggerFactory) WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) CurrentUserContext(pro.taskana.security.CurrentUserContext) HashSet(java.util.HashSet) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.exceptions.SystemException) CustomPropertySelector(pro.taskana.mappings.CustomPropertySelector) Task(pro.taskana.Task) InvalidStateException(pro.taskana.exceptions.InvalidStateException) Duration(java.time.Duration) Map(java.util.Map) TaskState(pro.taskana.TaskState) WorkbasketPermission(pro.taskana.WorkbasketPermission) WorkbasketSummary(pro.taskana.WorkbasketSummary) TimeIntervalColumnHeader(pro.taskana.impl.report.impl.TimeIntervalColumnHeader) ClassificationSummary(pro.taskana.ClassificationSummary) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskanaEngine(pro.taskana.TaskanaEngine) Attachment(pro.taskana.Attachment) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) Logger(org.slf4j.Logger) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) Iterator(java.util.Iterator) Set(java.util.Set) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) AttachmentMapper(pro.taskana.mappings.AttachmentMapper) Classification(pro.taskana.Classification) LoggerUtils(pro.taskana.impl.util.LoggerUtils) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskMapper(pro.taskana.mappings.TaskMapper) List(java.util.List) Workbasket(pro.taskana.Workbasket) TaskanaRole(pro.taskana.TaskanaRole) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException) TaskQuery(pro.taskana.TaskQuery) Collections(java.util.Collections) Instant(java.time.Instant) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskanaException(pro.taskana.exceptions.TaskanaException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskSummary(pro.taskana.TaskSummary) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException)

Example 37 with TaskSummary

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().");
    }
}
Also used : JobMapper(pro.taskana.mappings.JobMapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) Classification(pro.taskana.Classification) TaskSummary(pro.taskana.TaskSummary)

Example 38 with TaskSummary

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());
}
Also used : TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 39 with TaskSummary

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());
}
Also used : TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 40 with TaskSummary

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());
}
Also used : TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

TaskSummary (pro.taskana.TaskSummary)58 Test (org.junit.Test)48 TaskService (pro.taskana.TaskService)47 WithAccessId (pro.taskana.security.WithAccessId)45 AbstractAccTest (acceptance.AbstractAccTest)44 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)17 KeyDomain (pro.taskana.KeyDomain)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)14 Instant (java.time.Instant)9 ArrayList (java.util.ArrayList)8 TimeInterval (pro.taskana.TimeInterval)8 Classification (pro.taskana.Classification)5 Task (pro.taskana.Task)5 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)5 NotAuthorizedToQueryWorkbasketException (pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException)5 TaskQuery (pro.taskana.TaskQuery)4 Workbasket (pro.taskana.Workbasket)3 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2