Search in sources :

Example 6 with TaskContext

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

Example 7 with TaskContext

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

the class UpdateTaskCommand 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) && !isOwner(userId, task.getPeopleAssignments().getPotentialOwners(), task.getTaskData().getActualOwner(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin or potential owner of task " + taskId);
    }
    taskEventSupport.fireBeforeTaskUpdated(task, context);
    // process task meta data
    if (userTask.getFormName() != null) {
        ((InternalTask) task).setFormName(userTask.getFormName());
    }
    if (userTask.getName() != null) {
        ((InternalTask) task).setName(userTask.getName());
    }
    if (userTask.getDescription() != null) {
        ((InternalTask) task).setDescription(userTask.getDescription());
    }
    if (userTask.getPriority() != null) {
        ((InternalTask) task).setPriority(userTask.getPriority());
    }
    if (userTask.getDueDate() != null) {
        ((InternalTaskData) task.getTaskData()).setExpirationTime(userTask.getDueDate());
    }
    // process task inputs
    long inputContentId = task.getTaskData().getDocumentContentId();
    Content inputContent = persistenceContext.findContent(inputContentId);
    Map<String, Object> mergedContent = inputs;
    if (inputs != null) {
        if (inputContent == null) {
            ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
            ContentData outputContentData = ContentMarshallerHelper.marshal(task, inputs, mcontext.getEnvironment());
            Content content = TaskModelProvider.getFactory().newContent();
            ((InternalContent) content).setContent(outputContentData.getContent());
            persistenceContext.persistContent(content);
            ((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
        } else {
            ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
            Object unmarshalledObject = ContentMarshallerHelper.unmarshall(inputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
            if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
                ((Map<String, Object>) unmarshalledObject).putAll(inputs);
                mergedContent = ((Map<String, Object>) unmarshalledObject);
            }
            ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
            ((InternalContent) inputContent).setContent(outputContentData.getContent());
            persistenceContext.persistContent(inputContent);
        }
        ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
    }
    if (outputs != null) {
        // process task outputs
        context.getTaskContentService().addOutputContent(taskId, outputs);
    }
    persistenceContext.updateTask(task);
    // finally trigger event support after the updates
    taskEventSupport.fireAfterTaskUpdated(task, context);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) InternalTask(org.kie.internal.task.api.model.InternalTask) 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) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 8 with TaskContext

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

the class AbstractTaskAuditQueryCommand method execute.

@Override
public List<R> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskAuditQueryCriteriaUtil queryCriteriaUtil = new TaskAuditQueryCriteriaUtil(context.getPersistenceContext());
    List<Q> implResult = queryCriteriaUtil.doCriteriaQuery(getQueryWhere(), getQueryType());
    return QueryCriteriaUtil.convertListToInterfaceList(implResult, getResultType());
}
Also used : TaskContext(org.jbpm.services.task.commands.TaskContext) TaskAuditQueryCriteriaUtil(org.jbpm.services.task.audit.service.TaskAuditQueryCriteriaUtil)

Example 9 with TaskContext

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

the class BAMTaskSummaryQueryCommand method execute.

@Override
public List<BAMTaskSummaryImpl> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskAuditQueryCriteriaUtil queryCriteriaUtil = new TaskAuditQueryCriteriaUtil(context.getPersistenceContext());
    return queryCriteriaUtil.doCriteriaQuery(getQueryWhere(), BAMTaskSummaryImpl.class);
}
Also used : TaskContext(org.jbpm.services.task.commands.TaskContext) TaskAuditQueryCriteriaUtil(org.jbpm.services.task.audit.service.TaskAuditQueryCriteriaUtil)

Example 10 with TaskContext

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

the class GetTasksByVariableNameCommand 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("TasksByStatusByVariableName", persistenceContext.addParametersToMap("userId", userId, "groupIds", groupIds, "variableName", variableName, "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)

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