Search in sources :

Example 16 with InternalTask

use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.

the class TaskDeadlinesServiceImpl method unschedule.

public void unschedule(long taskId, Deadline deadline, DeadlineType type) {
    Task task = persistenceContext.findTask(taskId);
    String deploymentId = task.getTaskData().getDeploymentId();
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService != null && timerService instanceof GlobalTimerService) {
        TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadline.getId(), type, deploymentId, task.getTaskData().getProcessInstanceId());
        logger.debug("unscheduling timer job for deadline {} {} and task {}  using timer service {}", deadlineJob.getId(), deadline.getId(), taskId, timerService);
        JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
        if (jobHandle == null) {
            jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
        }
        timerService.removeJob(jobHandle);
        // mark the deadlines so they won't be rescheduled again
        deadline.setEscalated(true);
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 17 with InternalTask

use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.

the class ProcessSubTaskCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskInstanceService instanceService = context.getTaskInstanceService();
    TaskQueryService queryService = context.getTaskQueryService();
    Task task = queryService.getTaskInstanceById(taskId);
    if (task == null) {
        return null;
    }
    Task parentTask = null;
    if (task.getTaskData().getParentId() != -1) {
        parentTask = queryService.getTaskInstanceById(task.getTaskData().getParentId());
    }
    if (parentTask != null) {
        if (((InternalTask) parentTask).getSubTaskStrategy() != null && ((InternalTask) parentTask).getSubTaskStrategy().equals(SubTasksStrategy.EndParentOnAllSubTasksEnd)) {
            List<TaskSummary> subTasks = queryService.getSubTasksByParent(parentTask.getId());
            // If there are no more sub tasks or if the last sub task is the one that we are completing now
            if (subTasks.isEmpty() || (subTasks.size() == 1 && subTasks.get(0).getId().equals(taskId))) {
                // Completing parent task if all the sub task has being completed, including the one that we are completing now
                instanceService.complete(parentTask.getId(), "Administrator", data);
            }
        }
    }
    if (((InternalTask) task).getSubTaskStrategy() != null && ((InternalTask) task).getSubTaskStrategy().equals(SubTasksStrategy.SkipAllSubTasksOnParentSkip)) {
        List<TaskSummary> subTasks = queryService.getSubTasksByParent(task.getId());
        for (TaskSummary taskSummary : subTasks) {
            Task subTask = queryService.getTaskInstanceById(taskSummary.getId());
            // Exit each sub task because the parent task was aborted
            instanceService.skip(subTask.getId(), "Administrator");
        }
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskSummary(org.kie.api.task.model.TaskSummary) TaskQueryService(org.kie.internal.task.api.TaskQueryService)

Example 18 with InternalTask

use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.

the class ListTaskNotificationsCommand method execute.

@Override
public List<TaskNotification> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Language lang = factory.newLanguage();
    lang.setMapkey("en-UK");
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    List<TaskNotification> notificationsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
        Notification n = d.getEscalations().get(0).getNotifications().get(0);
        EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
        return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskNotification> notificationsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
        Notification n = d.getEscalations().get(0).getNotifications().get(0);
        EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
        return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskNotification> result = new ArrayList<>();
    result.addAll(notificationsNotStarted);
    result.addAll(notificationsNotCompleted);
    if (activeOnly) {
        logger.debug("Removing already completed deadlines from the result");
        result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
    }
    return result;
}
Also used : Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) LoggerFactory(org.slf4j.LoggerFactory) I18NText(org.kie.api.task.model.I18NText) TaskModelProvider(org.kie.internal.task.api.TaskModelProvider) TaskNotification(org.jbpm.services.api.admin.TaskNotification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Collectors(java.util.stream.Collectors) Language(org.kie.internal.task.api.model.Language) ArrayList(java.util.ArrayList) TaskNotificationImpl(org.jbpm.kie.services.impl.admin.TaskNotificationImpl) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) List(java.util.List) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) Notification(org.kie.internal.task.api.model.Notification) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) EmailNotification(org.kie.internal.task.api.model.EmailNotification) TaskNotification(org.jbpm.services.api.admin.TaskNotification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Notification(org.kie.internal.task.api.model.Notification) TaskNotificationImpl(org.jbpm.kie.services.impl.admin.TaskNotificationImpl) Deadlines(org.kie.internal.task.api.model.Deadlines) Language(org.kie.internal.task.api.model.Language) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskNotification(org.jbpm.services.api.admin.TaskNotification)

Example 19 with InternalTask

use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.

the class ListTaskReassignmentsCommand method execute.

@Override
public List<TaskReassignment> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    List<TaskReassignment> reassignmantsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getReassignments().isEmpty()).map(d -> {
        Reassignment r = d.getEscalations().get(0).getReassignments().get(0);
        return new TaskReassignmentImpl(d.getId(), get(r.getDocumentation()), d.getDate(), r.getPotentialOwners(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskReassignment> reassignmantsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getReassignments().isEmpty()).map(d -> {
        Reassignment r = d.getEscalations().get(0).getReassignments().get(0);
        return new TaskReassignmentImpl(d.getId(), get(r.getDocumentation()), d.getDate(), r.getPotentialOwners(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskReassignment> result = new ArrayList<>();
    result.addAll(reassignmantsNotStarted);
    result.addAll(reassignmantsNotCompleted);
    if (activeOnly) {
        logger.debug("Removing already completed deadlines from the result");
        result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
    }
    return result;
}
Also used : Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) I18NText(org.kie.api.task.model.I18NText) TaskReassignmentImpl(org.jbpm.kie.services.impl.admin.TaskReassignmentImpl) Collectors(java.util.stream.Collectors) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) ArrayList(java.util.ArrayList) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) List(java.util.List) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) Reassignment(org.kie.internal.task.api.model.Reassignment) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) ArrayList(java.util.ArrayList) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskReassignmentImpl(org.jbpm.kie.services.impl.admin.TaskReassignmentImpl) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) Reassignment(org.kie.internal.task.api.model.Reassignment)

Example 20 with InternalTask

use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.

the class ScheduleTaskDeadlineCommand method execute.

@Override
public Long execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    logger.debug("About to schedule {} on a task {}", deadline, task);
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    if (type.equals(DeadlineType.START)) {
        deadlines.getStartDeadlines().add(deadline);
    } else {
        deadlines.getEndDeadlines().add(deadline);
    }
    doCallbackOperationForTaskDeadlines(deadlines, context);
    persistenceContext.persistDeadline(deadline);
    persistenceContext.updateTask(task);
    logger.debug("Task updated and deadline stored with id {}", deadline.getId());
    TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
    long fireAfterDuration = DateTimeUtils.parseDuration(timeExpression);
    deadline.setDate(new Date(System.currentTimeMillis() + fireAfterDuration));
    logger.debug("Deadline expiration time set to {} and duration {}", deadline.getDate(), fireAfterDuration);
    deadlinesService.schedule(taskId, deadline.getId(), fireAfterDuration, type);
    logger.debug("Deadline on task {} successfully scheduled to fire at {}", task, deadline.getDate());
    return deadline.getId();
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Date(java.util.Date) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Aggregations

InternalTask (org.kie.internal.task.api.model.InternalTask)50 Task (org.kie.api.task.model.Task)29 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)21 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)18 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)17 InputStreamReader (java.io.InputStreamReader)16 Reader (java.io.Reader)16 User (org.kie.api.task.model.User)16 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)15 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)15 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Date (java.util.Date)12 HashMap (java.util.HashMap)11 ContentData (org.kie.internal.task.api.model.ContentData)11 InternalContent (org.kie.internal.task.api.model.InternalContent)11 I18NText (org.kie.api.task.model.I18NText)10 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)8 TaskSummary (org.kie.api.task.model.TaskSummary)6 StringReader (java.io.StringReader)5