Search in sources :

Example 1 with TaskPersistenceContext

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

the class TotalCompletionTimeLoadCalculator method getUserActiveTaskLists.

/**
 * Retrieves a list of tasks that the users are currently assigned to, and which
 * are waiting to be worked on or are being worked on
 * @param users The list of users that we are interested in
 * @param context The TaskContext which is associated with the new task
 * @return A list of TaskInfo objects
 */
private synchronized List<TaskInfo> getUserActiveTaskLists(List<User> users, TaskContext context) {
    TaskPersistenceContext taskContext = ((org.jbpm.services.task.commands.TaskContext) context).getPersistenceContext();
    Map<String, Object> params = new HashMap<>();
    params.put("owners", users);
    return taskContext.queryStringWithParametersInTransaction(TASK_LIST_QUERY, params, ClassUtil.<List<TaskInfo>>castClass(List.class));
}
Also used : TaskContext(org.kie.api.task.TaskContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 2 with TaskPersistenceContext

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

the class TotalCompletionTimeLoadCalculator method calculateAverageDuration.

/**
 * Calculates the average duration for a target task, using a query
 * against the BAMTaskSummary table
 * @param context Used to retrieve a PersistenceContext
 * @param processId The identifier for the process definition containing the target task
 * @param deploymentId The identifier for the deployment which contains the target task
 * @param name The name of the target task
 * @return
 */
private Double calculateAverageDuration(TaskContext context, String processId, String deploymentId, String name) {
    Double avgDur = new Double(1);
    TaskPersistenceContext taskContext = ((org.jbpm.services.task.commands.TaskContext) context).getPersistenceContext();
    Map<String, Object> params = new HashMap<>();
    params.put("procid", processId);
    params.put("depid", deploymentId);
    params.put("taskname", name);
    List<TaskAverageDuration> durations = taskContext.queryStringWithParametersInTransaction(TASK_AVG_DURATION, params, ClassUtil.<List<TaskAverageDuration>>castClass(List.class));
    if (durations != null && !durations.isEmpty()) {
        avgDur = durations.get(0).getAverageDuration();
        logger.debug("Retrieved duration is {}", avgDur);
    }
    return avgDur;
}
Also used : TaskContext(org.kie.api.task.TaskContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 3 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskStoppedEvent.

@Override
public void afterTaskStoppedEvent(TaskEvent event) {
    String userId = event.getTaskContext().getUserId();
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.STOPPED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId));
        AuditTaskImpl auditTaskImpl = getAuditTask(event, persistenceContext, ti);
        if (auditTaskImpl == null) {
            logger.warn("Unable find audit task entry for task id {} '{}', skipping audit task update", ti.getId(), ti.getName());
            return;
        }
        auditTaskImpl.setDescription(ti.getDescription());
        auditTaskImpl.setStatus(ti.getTaskData().getStatus().name());
        auditTaskImpl.setActualOwner(getActualOwner(ti));
        auditTaskImpl.setLastModificationDate(event.getEventDate());
        persistenceContext.merge(auditTaskImpl);
    } finally {
        cleanup(persistenceContext);
    }
}
Also used : Task(org.kie.api.task.model.Task) TaskEventImpl(org.jbpm.services.task.audit.impl.model.TaskEventImpl) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl)

Example 4 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskActivatedEvent.

@Override
public void afterTaskActivatedEvent(TaskEvent event) {
    String userId = event.getTaskContext().getUserId();
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.ACTIVATED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId));
        AuditTaskImpl auditTaskImpl = getAuditTask(event, persistenceContext, ti);
        if (auditTaskImpl == null) {
            logger.warn("Unable find audit task entry for task id {} '{}', skipping audit task update", ti.getId(), ti.getName());
            return;
        }
        auditTaskImpl.setStatus(ti.getTaskData().getStatus().name());
        auditTaskImpl.setActualOwner(getActualOwner(ti));
        auditTaskImpl.setDescription(ti.getDescription());
        auditTaskImpl.setLastModificationDate(event.getEventDate());
        persistenceContext.merge(auditTaskImpl);
    } finally {
        cleanup(persistenceContext);
    }
}
Also used : Task(org.kie.api.task.model.Task) TaskEventImpl(org.jbpm.services.task.audit.impl.model.TaskEventImpl) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl)

Example 5 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskNominatedEvent.

@Override
public void afterTaskNominatedEvent(TaskEvent event) {
    String userId = event.getTaskContext().getUserId();
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.NOMINATED, userId, new Date()));
        AuditTaskImpl auditTaskImpl = getAuditTask(event, persistenceContext, ti);
        if (auditTaskImpl == null) {
            logger.warn("Unable find audit task entry for task id {} '{}', skipping audit task update", ti.getId(), ti.getName());
            return;
        }
        auditTaskImpl.setDescription(ti.getDescription());
        auditTaskImpl.setName(ti.getName());
        auditTaskImpl.setActivationTime(ti.getTaskData().getActivationTime());
        auditTaskImpl.setPriority(ti.getPriority());
        auditTaskImpl.setDueDate(ti.getTaskData().getExpirationTime());
        auditTaskImpl.setStatus(ti.getTaskData().getStatus().name());
        auditTaskImpl.setActualOwner(getActualOwner(ti));
        auditTaskImpl.setLastModificationDate(event.getEventDate());
        persistenceContext.merge(auditTaskImpl);
    } finally {
        cleanup(persistenceContext);
    }
}
Also used : Task(org.kie.api.task.model.Task) TaskEventImpl(org.jbpm.services.task.audit.impl.model.TaskEventImpl) Date(java.util.Date) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl)

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