Search in sources :

Example 46 with TaskPersistenceContext

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

the class GetTasksForProcessCommand method execute.

@Override
public List<TaskSummary> execute(Context context) {
    TaskContext ctx = (TaskContext) context;
    TaskPersistenceContext persistenceContext = ctx.getPersistenceContext();
    List<TaskSummary> tasks = (List<TaskSummary>) persistenceContext.queryWithParametersInTransaction("TasksByStatusByProcessId", persistenceContext.addParametersToMap("processInstanceId", processInstanceId, "status", statuses), ClassUtil.<List<TaskSummary>>castClass(List.class));
    return tasks;
}
Also used : TaskContext(org.kie.internal.task.api.TaskContext) TaskSummary(org.kie.api.task.model.TaskSummary) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 47 with TaskPersistenceContext

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

the class CleanUpCommand method execute.

@Override
public Void execute(Context context) {
    TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext();
    persistenceContext.executeUpdateString("delete from  NodeInstanceLog nid");
    persistenceContext.executeUpdateString("delete from  ProcessInstanceLog pid");
    persistenceContext.executeUpdateString("delete from  VariableInstanceLog vsd");
    persistenceContext.executeUpdateString("delete from  AuditTaskImpl vsd");
    return null;
}
Also used : TaskContext(org.kie.internal.task.api.TaskContext) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 48 with TaskPersistenceContext

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

the class AddTaskInputsCommand 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 inputContentId = task.getTaskData().getDocumentContentId();
    Content outputContent = persistenceContext.findContent(inputContentId);
    Map<String, Object> initialContent = new HashMap<String, Object>();
    Map<String, Object> mergedContent = values;
    if (outputContent == null) {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, values, 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(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
        if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
            // set initial content with data from storage before being altered by this values
            initialContent.putAll((Map<String, Object>) unmarshalledObject);
            ((Map<String, Object>) unmarshalledObject).putAll(values);
            mergedContent = ((Map<String, Object>) unmarshalledObject);
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
    }
    taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
    ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
    taskEventSupport.fireAfterTaskInputVariablesChanged(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

TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)48 Task (org.kie.api.task.model.Task)31 AuditTaskImpl (org.jbpm.services.task.audit.impl.model.AuditTaskImpl)19 TaskEventImpl (org.jbpm.services.task.audit.impl.model.TaskEventImpl)19 List (java.util.List)14 HashMap (java.util.HashMap)13 TaskContext (org.kie.internal.task.api.TaskContext)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 TaskContext (org.jbpm.services.task.commands.TaskContext)7 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)5 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)5 TaskContext (org.kie.api.task.TaskContext)5 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Date (java.util.Date)4 ClassUtil (org.jbpm.services.task.utils.ClassUtil)4 Content (org.kie.api.task.model.Content)4 Status (org.kie.api.task.model.Status)4