Search in sources :

Example 11 with AuditTaskImpl

use of org.jbpm.services.task.audit.impl.model.AuditTaskImpl 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 12 with AuditTaskImpl

use of org.jbpm.services.task.audit.impl.model.AuditTaskImpl 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)

Example 13 with AuditTaskImpl

use of org.jbpm.services.task.audit.impl.model.AuditTaskImpl in project jbpm by kiegroup.

the class JPATaskLifeCycleEventListener method afterTaskStartedEvent.

@Override
public void afterTaskStartedEvent(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.STARTED, 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 14 with AuditTaskImpl

use of org.jbpm.services.task.audit.impl.model.AuditTaskImpl in project jbpm by kiegroup.

the class JPATaskLifeCycleEventListener method afterTaskAddedEvent.

@Override
public void afterTaskAddedEvent(TaskEvent event) {
    String userId = event.getTaskContext().getUserId();
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        if (ti.getTaskData().getProcessId() != null) {
            userId = ti.getTaskData().getProcessId();
        }
        AuditTaskImpl auditTaskImpl = new AuditTaskImpl(ti.getId(), ti.getName(), ti.getTaskData().getStatus().name(), ti.getTaskData().getActivationTime(), (ti.getTaskData().getActualOwner() != null) ? ti.getTaskData().getActualOwner().getId() : "", ti.getDescription(), ti.getPriority(), (ti.getTaskData().getCreatedBy() != null) ? ti.getTaskData().getCreatedBy().getId() : "", ti.getTaskData().getCreatedOn(), ti.getTaskData().getExpirationTime(), ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getProcessId(), ti.getTaskData().getProcessSessionId(), ti.getTaskData().getDeploymentId(), ti.getTaskData().getParentId(), ti.getTaskData().getWorkItemId());
        persistenceContext.persist(auditTaskImpl);
        persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.ADDED, 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) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl)

Example 15 with AuditTaskImpl

use of org.jbpm.services.task.audit.impl.model.AuditTaskImpl in project jbpm by kiegroup.

the class JPATaskLifeCycleEventListener method afterTaskClaimedEvent.

@Override
public void afterTaskClaimedEvent(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.CLAIMED, 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)

Aggregations

AuditTaskImpl (org.jbpm.services.task.audit.impl.model.AuditTaskImpl)19 Task (org.kie.api.task.model.Task)19 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)18 TaskEventImpl (org.jbpm.services.task.audit.impl.model.TaskEventImpl)17 Date (java.util.Date)3 HashMap (java.util.HashMap)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)1 DeleteAuditEventsCommand (org.jbpm.services.task.audit.commands.DeleteAuditEventsCommand)1 DeleteBAMTaskSummariesCommand (org.jbpm.services.task.audit.commands.DeleteBAMTaskSummariesCommand)1 GetAuditEventsCommand (org.jbpm.services.task.audit.commands.GetAuditEventsCommand)1 GetBAMTaskSummariesCommand (org.jbpm.services.task.audit.commands.GetBAMTaskSummariesCommand)1 BAMTaskSummaryImpl (org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl)1 TaskIndexerManager (org.jbpm.services.task.audit.variable.TaskIndexerManager)1 TaskLifeCycleEventListener (org.jbpm.services.task.lifecycle.listeners.TaskLifeCycleEventListener)1 PersistableEventListener (org.jbpm.services.task.persistence.PersistableEventListener)1