@Override
 public void afterTaskActivatedEvent(TaskEvent event) {
   String userId = "";
   Task ti = event.getTask();
   TaskPersistenceContext persistenceContext =
       ((TaskContext) event.getTaskContext()).getPersistenceContext();
   if (ti.getTaskData().getActualOwner() != null) {
     userId = ti.getTaskData().getActualOwner().getId();
   }
   persistenceContext.persist(
       new TaskEventImpl(
           ti.getId(),
           org.kie.internal.task.api.model.TaskEvent.TaskEventType.ACTIVATED,
           userId,
           new Date()));
   UserAuditTask task = persistenceContext.find(UserAuditTaskImpl.class, ti.getId());
   task.setStatus(ti.getTaskData().getStatus().name());
   persistenceContext.persist(task);
 }
 @Override
 public void afterTaskCompletedEvent(TaskEvent event) {
   String userId = "";
   Task ti = event.getTask();
   TaskPersistenceContext persistenceContext =
       ((TaskContext) event.getTaskContext()).getPersistenceContext();
   if (ti.getTaskData().getActualOwner() != null) {
     userId = ti.getTaskData().getActualOwner().getId();
   }
   persistenceContext.persist(
       new TaskEventImpl(
           ti.getId(),
           org.kie.internal.task.api.model.TaskEvent.TaskEventType.COMPLETED,
           userId,
           new Date()));
   UserAuditTask task = persistenceContext.find(UserAuditTaskImpl.class, ti.getId());
   if (task != null) {
     persistenceContext.remove(task);
     HistoryAuditTaskImpl historyAuditTaskImpl =
         new HistoryAuditTaskImpl(
             task.getActualOwner(),
             task.getTaskId(),
             ti.getTaskData().getStatus().name(),
             task.getActivationTime(),
             task.getName(),
             task.getDescription(),
             task.getPriority(),
             task.getCreatedBy(),
             task.getCreatedOn(),
             task.getDueDate(),
             task.getProcessInstanceId(),
             task.getProcessId(),
             task.getProcessSessionId(),
             task.getParentId());
     persistenceContext.persist(historyAuditTaskImpl);
   }
 }