Search in sources :

Example 11 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method beforeTaskReleasedEvent.

@Override
public void beforeTaskReleasedEvent(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.RELEASED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId));
    } 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)

Example 12 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskFailedEvent.

@Override
public void afterTaskFailedEvent(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.FAILED, 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.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 13 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskOutputVariableChangedEvent.

@Override
public void afterTaskOutputVariableChangedEvent(TaskEvent event, Map<String, Object> variables) {
    String userId = event.getTaskContext().getUserId();
    Task task = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    // first cleanup previous values if any
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("type", VariableType.OUTPUT);
    params.put("taskId", task.getId());
    int removed = persistenceContext.executeUpdate("DeleteTaskVariableForTask", params);
    logger.debug("Deleted {} output variables logs for task id {}", removed, task.getId());
    if (variables == null || variables.isEmpty()) {
        return;
    }
    indexAndPersistVariables(task, variables, persistenceContext, VariableType.OUTPUT);
    String message = "Task output data updated";
    persistenceContext.persist(new TaskEventImpl(task.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, task.getTaskData().getProcessInstanceId(), task.getTaskData().getWorkItemId(), userId, message));
    AuditTaskImpl auditTaskImpl = getAuditTask(event, persistenceContext, task);
    if (auditTaskImpl == null) {
        logger.warn("Unable find audit task entry for task id {} '{}', skipping audit task update", task.getId(), task.getName());
        return;
    }
    auditTaskImpl.setLastModificationDate(event.getEventDate());
    persistenceContext.merge(auditTaskImpl);
}
Also used : Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) 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 14 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskCompletedEvent.

@Override
public void afterTaskCompletedEvent(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.COMPLETED, 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.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 15 with TaskPersistenceContext

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

the class JPATaskLifeCycleEventListener method afterTaskUpdatedEvent.

@Override
public void afterTaskUpdatedEvent(TaskEvent event) {
    String userId = event.getTaskContext().getUserId();
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        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;
        }
        if ((ti.getDescription() != null && !ti.getDescription().equals(auditTaskImpl.getDescription())) || (ti.getDescription() == null && auditTaskImpl.getDescription() != null)) {
            String message = "Updated Description {From: " + auditTaskImpl.getDescription() + ", to: " + ti.getDescription() + "}";
            persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId, message));
        }
        if ((ti.getName() != null && !ti.getName().equals(auditTaskImpl.getName())) || (ti.getName() == null && auditTaskImpl.getName() != null)) {
            String message = "Updated Name {From: " + auditTaskImpl.getName() + ", to: " + ti.getName() + "}";
            persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId, message));
        }
        if (auditTaskImpl.getPriority() != ti.getPriority()) {
            String message = "Updated Priority {From: " + auditTaskImpl.getPriority() + ", to: " + ti.getPriority() + "}";
            persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId, message));
        }
        if ((auditTaskImpl.getDueDate() != null && ti.getTaskData().getExpirationTime() != null && auditTaskImpl.getDueDate().getTime() != ti.getTaskData().getExpirationTime().getTime()) || (auditTaskImpl.getDueDate() == null && ti.getTaskData().getExpirationTime() != null) || (auditTaskImpl.getDueDate() != null && ti.getTaskData().getExpirationTime() == null)) {
            String message = "Updated DueDate {From: " + auditTaskImpl.getDueDate() + ", to: " + ti.getTaskData().getExpirationTime() + "}";
            persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId, message));
        }
        auditTaskImpl.setDescription(ti.getDescription());
        auditTaskImpl.setName(ti.getName());
        auditTaskImpl.setPriority(ti.getPriority());
        auditTaskImpl.setDueDate(ti.getTaskData().getExpirationTime());
        auditTaskImpl.setLastModificationDate(event.getEventDate());
        persistenceContext.merge(auditTaskImpl);
    } catch (Exception e) {
        e.printStackTrace();
    } 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)

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