Search in sources :

Example 1 with TaskContext

use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.

the class GetTasksByVariableNameAndValueCommand method execute.

public List<TaskSummary> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    doCallbackUserOperation(userId, context);
    if (statuses == null) {
        statuses = new ArrayList<Status>();
        statuses.add(Status.Ready);
        statuses.add(Status.InProgress);
        statuses.add(Status.Reserved);
    }
    if (groupIds == null) {
        groupIds = doUserGroupCallbackOperation(userId, null, context);
        if (groupIds == null) {
            groupIds = new ArrayList<String>();
        }
    }
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    List<TaskSummary> tasks = (List<TaskSummary>) persistenceContext.queryWithParametersInTransaction("TasksByStatusByVariableNameAndValue", persistenceContext.addParametersToMap("userId", userId, "groupIds", groupIds, "variableName", variableName, "variableValue", variableValue, "status", statuses), ClassUtil.<List<TaskSummary>>castClass(List.class));
    return tasks;
}
Also used : Status(org.kie.api.task.model.Status) TaskContext(org.jbpm.services.task.commands.TaskContext) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 2 with TaskContext

use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.

the class CancelTaskDeadlineCommand method execute.

@Override
public Void 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);
    }
    logger.debug("About to cancel deadline {} on a task {}", deadlineId, task);
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    DeadlineType type = DeadlineType.START;
    Deadline deadline = deadlines.getStartDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
    if (deadline == null) {
        deadline = deadlines.getEndDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
        type = DeadlineType.END;
    }
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
    deadlinesService.unschedule(taskId, deadline, type);
    persistenceContext.removeDeadline(deadline);
    return null;
}
Also used : DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) Deadline(org.kie.internal.task.api.model.Deadline) Deadlines(org.kie.internal.task.api.model.Deadlines) DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) 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) Deadline(org.kie.internal.task.api.model.Deadline) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 3 with TaskContext

use of org.jbpm.services.task.commands.TaskContext 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 4 with TaskContext

use of org.jbpm.services.task.commands.TaskContext 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 5 with TaskContext

use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.

the class RemoveTaskDataCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskEventSupport taskEventSupport = context.getTaskEventSupport();
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    Task task = persistenceContext.findTask(taskId);
    // security check
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    long contentId = task.getTaskData().getDocumentContentId();
    if (!input) {
        contentId = task.getTaskData().getOutputContentId();
    }
    Content outputContent = persistenceContext.findContent(contentId);
    Map<String, Object> initialContent = new HashMap<>();
    Map<String, Object> mergedContent = new HashMap<>();
    if (outputContent != null) {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
        if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
            mergedContent.putAll(((Map<String, Object>) unmarshalledObject));
            // set initial content for the sake of listeners
            initialContent.putAll(mergedContent);
            variableNames.forEach(name -> mergedContent.remove(name));
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, mergedContent, mcontext.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
    }
    if (input) {
        taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
        ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
        taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
    } else {
        taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
        ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(mergedContent);
        taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, mergedContent);
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) TaskContext(org.jbpm.services.task.commands.TaskContext) HashMap(java.util.HashMap) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalContent(org.kie.internal.task.api.model.InternalContent) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Aggregations

TaskContext (org.jbpm.services.task.commands.TaskContext)14 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)9 Task (org.kie.api.task.model.Task)9 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)7 ArrayList (java.util.ArrayList)5 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 List (java.util.List)4 Deadlines (org.kie.internal.task.api.model.Deadlines)4 Map (java.util.Map)3 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)3 Context (org.kie.api.runtime.Context)3 Content (org.kie.api.task.model.Content)3 I18NText (org.kie.api.task.model.I18NText)3 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)3 ContentData (org.kie.internal.task.api.model.ContentData)3 InternalContent (org.kie.internal.task.api.model.InternalContent)3 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3