Search in sources :

Example 1 with TaskContext

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

the class JPATaskLifeCycleEventListener method assignmentsUpadted.

protected void assignmentsUpadted(TaskEvent event, AssignmentType type, List<OrganizationalEntity> entities, String messageSufix) {
    if (entities == null || entities.isEmpty()) {
        return;
    }
    String userId = event.getTaskContext().getUserId();
    Task task = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    StringBuilder message = new StringBuilder();
    switch(type) {
        case POT_OWNER:
            message.append("Potential owners [");
            break;
        case EXCL_OWNER:
            message.append("Excluded owners [");
            break;
        case ADMIN:
            message.append("Business administrators [");
            break;
        default:
            break;
    }
    String entitiesAsString = entities.stream().map(oe -> oe.getId()).collect(Collectors.joining(","));
    message.append(entitiesAsString);
    message.append(messageSufix);
    persistenceContext.persist(new TaskEventImpl(task.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, task.getTaskData().getProcessInstanceId(), task.getTaskData().getWorkItemId(), userId, message.toString()));
}
Also used : PersistableEventListener(org.jbpm.services.task.persistence.PersistableEventListener) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) Date(java.util.Date) TaskVariable(org.kie.internal.task.api.TaskVariable) TaskEventImpl(org.jbpm.services.task.audit.impl.model.TaskEventImpl) VariableType(org.kie.internal.task.api.TaskVariable.VariableType) LoggerFactory(org.slf4j.LoggerFactory) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl) HashMap(java.util.HashMap) ClassUtil(org.jbpm.services.task.utils.ClassUtil) Collectors(java.util.stream.Collectors) TaskLifeCycleEventListener(org.jbpm.services.task.lifecycle.listeners.TaskLifeCycleEventListener) TaskEvent(org.kie.api.task.TaskEvent) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) TaskIndexerManager(org.jbpm.services.task.audit.variable.TaskIndexerManager) List(java.util.List) TaskContext(org.kie.internal.task.api.TaskContext) EntityManagerFactory(javax.persistence.EntityManagerFactory) Map(java.util.Map) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) Task(org.kie.api.task.model.Task) TaskEventImpl(org.jbpm.services.task.audit.impl.model.TaskEventImpl) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 2 with TaskContext

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

the class JPATaskLifeCycleEventListener method afterTaskForwardedEvent.

@Override
public void afterTaskForwardedEvent(TaskEvent event) {
    String userId = event.getTaskContext().getUserId();
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        StringBuilder message = new StringBuilder();
        String entitiesAsString = (ti.getPeopleAssignments().getPotentialOwners()).stream().map(oe -> oe.getId()).collect(Collectors.joining(","));
        message.append("Forward to [" + entitiesAsString + "]");
        persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.FORWARDED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId, message.toString()));
        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 : PersistableEventListener(org.jbpm.services.task.persistence.PersistableEventListener) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) Date(java.util.Date) TaskVariable(org.kie.internal.task.api.TaskVariable) TaskEventImpl(org.jbpm.services.task.audit.impl.model.TaskEventImpl) VariableType(org.kie.internal.task.api.TaskVariable.VariableType) LoggerFactory(org.slf4j.LoggerFactory) AuditTaskImpl(org.jbpm.services.task.audit.impl.model.AuditTaskImpl) HashMap(java.util.HashMap) ClassUtil(org.jbpm.services.task.utils.ClassUtil) Collectors(java.util.stream.Collectors) TaskLifeCycleEventListener(org.jbpm.services.task.lifecycle.listeners.TaskLifeCycleEventListener) TaskEvent(org.kie.api.task.TaskEvent) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) TaskIndexerManager(org.jbpm.services.task.audit.variable.TaskIndexerManager) List(java.util.List) TaskContext(org.kie.internal.task.api.TaskContext) EntityManagerFactory(javax.persistence.EntityManagerFactory) Map(java.util.Map) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) 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 3 with TaskContext

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

the class DeleteAuditEventsCommand method execute.

@Override
public Void execute(Context context) {
    TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext();
    if (this.taskId != null) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("taskId", this.taskId);
        persistenceContext.executeUpdate("deleteTaskEventsForTask", params);
    } else {
        persistenceContext.executeUpdate("deleteAllTaskEvents", null);
    }
    return null;
}
Also used : TaskContext(org.kie.internal.task.api.TaskContext) HashMap(java.util.HashMap) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 4 with TaskContext

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

the class DeleteBAMTaskSummariesCommand method execute.

@Override
public Void execute(Context context) {
    TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext();
    if (this.taskId != null) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("taskId", this.taskId);
        persistenceContext.executeUpdate("deleteBAMTaskSummariesForTask", params);
    } else {
        persistenceContext.executeUpdate("deleteAllBAMTaskSummaries", null);
    }
    return null;
}
Also used : TaskContext(org.kie.internal.task.api.TaskContext) HashMap(java.util.HashMap) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 5 with TaskContext

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

the class GetAllAdminAuditTasksByUserCommand method execute.

@Override
public List<AuditTask> execute(Context context) {
    TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext();
    boolean userExists = doCallbackUserOperation(userId, (TaskContext) context);
    List<String> groupIds = doUserGroupCallbackOperation(userId, null, (TaskContext) context);
    // Adding the user to check for groups and user as Business Administrators
    groupIds.add(userId);
    List<AuditTask> groupTasks = persistenceContext.queryWithParametersInTransaction("getAllAdminAuditTasksByUser", persistenceContext.addParametersToMap("businessAdmins", groupIds, "firstResult", filter.getOffset(), "maxResults", filter.getCount()), ClassUtil.<List<AuditTask>>castClass(List.class));
    return groupTasks;
}
Also used : TaskContext(org.kie.internal.task.api.TaskContext) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) AuditTask(org.kie.internal.task.api.AuditTask)

Aggregations

TaskContext (org.kie.internal.task.api.TaskContext)9 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)9 List (java.util.List)6 HashMap (java.util.HashMap)4 AuditTask (org.kie.internal.task.api.AuditTask)3 Arrays (java.util.Arrays)2 Date (java.util.Date)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 AuditTaskImpl (org.jbpm.services.task.audit.impl.model.AuditTaskImpl)2 TaskEventImpl (org.jbpm.services.task.audit.impl.model.TaskEventImpl)2 TaskIndexerManager (org.jbpm.services.task.audit.variable.TaskIndexerManager)2 TaskLifeCycleEventListener (org.jbpm.services.task.lifecycle.listeners.TaskLifeCycleEventListener)2 PersistableEventListener (org.jbpm.services.task.persistence.PersistableEventListener)2 ClassUtil (org.jbpm.services.task.utils.ClassUtil)2 TaskEvent (org.kie.api.task.TaskEvent)2 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)2 Task (org.kie.api.task.model.Task)2 TaskVariable (org.kie.internal.task.api.TaskVariable)2