Search in sources :

Example 1 with TaskData

use of org.kie.api.task.model.TaskData in project jbpm by kiegroup.

the class ETaskOperationTest method checkTaskStatus.

private TaskData checkTaskStatus(Long taskId, Status status) {
    Task task = ejb.getTask(taskId);
    Assertions.assertThat(task.getId()).isEqualTo(taskId);
    TaskData taskData = task.getTaskData();
    Assertions.assertThat(taskData.getStatus()).isEqualTo(status);
    return taskData;
}
Also used : Task(org.kie.api.task.model.Task) TaskData(org.kie.api.task.model.TaskData)

Example 2 with TaskData

use of org.kie.api.task.model.TaskData in project jbpm by kiegroup.

the class ExecuteDeadlinesCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Void execute(Context context) {
    TaskContext ctx = (TaskContext) context;
    UserInfo userInfo = (UserInfo) context.get(EnvironmentName.TASK_USER_INFO);
    TaskPersistenceContext persistenceContext = ctx.getPersistenceContext();
    try {
        Task task = persistenceContext.findTask(taskId);
        Deadline deadline = persistenceContext.findDeadline(deadlineId);
        if (task == null || deadline == null) {
            return null;
        }
        TaskData taskData = task.getTaskData();
        if (taskData != null) {
            // check if task is still in valid status
            if (type.isValidStatus(taskData.getStatus())) {
                Map<String, Object> variables = null;
                Content content = persistenceContext.findContent(taskData.getDocumentContentId());
                if (content != null) {
                    ContentMarshallerContext mContext = ctx.getTaskContentService().getMarshallerContext(task);
                    Object objectFromBytes = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader());
                    if (objectFromBytes instanceof Map) {
                        variables = (Map<String, Object>) objectFromBytes;
                    } else {
                        variables = new HashMap<String, Object>();
                        variables.put("content", objectFromBytes);
                    }
                } else {
                    variables = Collections.emptyMap();
                }
                if (deadline == null || deadline.getEscalations() == null) {
                    return null;
                }
                TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
                for (Escalation escalation : deadline.getEscalations()) {
                    // run reassignment first to allow notification to be send to new potential owners
                    if (!escalation.getReassignments().isEmpty()) {
                        taskEventSupport.fireBeforeTaskReassigned(task, ctx);
                        // get first and ignore the rest.
                        Reassignment reassignment = escalation.getReassignments().get(0);
                        logger.debug("Reassigning to {}", reassignment.getPotentialOwners());
                        ((InternalTaskData) task.getTaskData()).setStatus(Status.Ready);
                        List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>(reassignment.getPotentialOwners());
                        ((InternalPeopleAssignments) task.getPeopleAssignments()).setPotentialOwners(potentialOwners);
                        ((InternalTaskData) task.getTaskData()).setActualOwner(null);
                        // use assignment service to directly assign actual owner if enabled
                        AssignmentService assignmentService = AssignmentServiceProvider.get();
                        if (assignmentService.isEnabled()) {
                            assignmentService.assignTask(task, ctx);
                        }
                        taskEventSupport.fireAfterTaskReassigned(task, ctx);
                    }
                    for (Notification notification : escalation.getNotifications()) {
                        if (notification.getNotificationType() == NotificationType.Email) {
                            taskEventSupport.fireBeforeTaskNotified(task, ctx);
                            logger.debug("Sending an Email");
                            NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
                            taskEventSupport.fireAfterTaskNotified(task, ctx);
                        }
                    }
                }
            }
        }
        deadline.setEscalated(true);
        persistenceContext.updateDeadline(deadline);
        persistenceContext.updateTask(task);
    } catch (Exception e) {
        logger.error("Error when executing deadlines", e);
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) Escalation(org.kie.internal.task.api.model.Escalation) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) UserInfo(org.kie.internal.task.api.UserInfo) AssignmentService(org.jbpm.services.task.assignment.AssignmentService) Notification(org.kie.internal.task.api.model.Notification) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) TaskData(org.kie.api.task.model.TaskData) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Deadline(org.kie.internal.task.api.model.Deadline) NotificationEvent(org.kie.internal.task.api.model.NotificationEvent) Reassignment(org.kie.internal.task.api.model.Reassignment) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) Content(org.kie.api.task.model.Content) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with TaskData

use of org.kie.api.task.model.TaskData in project jbpm by kiegroup.

the class ExecuteReminderCommand method execute.

@Override
public Void execute(Context context) {
    TaskContext ctx = (TaskContext) context;
    UserInfo userInfo = (UserInfo) context.get(EnvironmentName.TASK_USER_INFO);
    TaskPersistenceContext persistenceContext = ctx.getPersistenceContext();
    try {
        Task task = persistenceContext.findTask(taskId);
        TaskData taskData = task.getTaskData();
        List<DeadlineSummary> resultList = null;
        resultList = getAlldeadlines(persistenceContext, taskData);
        TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
        if (resultList == null || resultList.size() == 0) {
            if (taskData.getActualOwner() == null)
                return null;
            if (taskData != null) {
                // check if task is still in valid status
                if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
                    taskEventSupport.fireBeforeTaskNotified(task, ctx);
                    logger.debug("Sending an Email");
                    Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
                    Notification notification = buildDefaultNotification(taskData, task);
                    NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
                    taskEventSupport.fireAfterTaskNotified(task, ctx);
                }
            }
        } else {
            for (DeadlineSummary deadlineSummary : resultList) {
                executedeadLine(ctx, persistenceContext, task, deadlineSummary, taskData);
            }
        }
    } catch (Exception e) {
        logger.error("Error when executing deadlines", e);
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) DeadlineSummary(org.kie.internal.task.api.model.DeadlineSummary) UserInfo(org.kie.internal.task.api.UserInfo) NotificationEvent(org.kie.internal.task.api.model.NotificationEvent) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) TaskData(org.kie.api.task.model.TaskData) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport)

Example 4 with TaskData

use of org.kie.api.task.model.TaskData in project jbpm by kiegroup.

the class ETaskOperationTest method checkTaskStatusAndActualOwner.

private TaskData checkTaskStatusAndActualOwner(Long taskId, Status status, String user) {
    TaskData taskData = checkTaskStatus(taskId, status);
    if (user != null) {
        Assertions.assertThat(taskData.getActualOwner()).isNotNull();
        Assertions.assertThat(taskData.getActualOwner().getId()).isEqualTo(user);
    } else {
        Assertions.assertThat(taskData.getActualOwner()).isNull();
    }
    return taskData;
}
Also used : TaskData(org.kie.api.task.model.TaskData)

Example 5 with TaskData

use of org.kie.api.task.model.TaskData in project jbpm by kiegroup.

the class ETaskOperationTest method testAbortWorkItem.

/**
 * See ETaskOperationTest.testCompleteWorkItem() for reason why another user is used.
 */
@Test()
public void testAbortWorkItem() {
    ProcessInstance pi = startHumanTaskProcess("root", "Root's task 2");
    Long taskId = ejb.getTasksByProcessInstanceId(pi.getId()).get(0);
    Task task = ejb.getTask(taskId);
    Assertions.assertThat(task).isNotNull();
    TaskData taskData = task.getTaskData();
    ejb.abortWorkItem(taskData.getWorkItemId());
    ProcessInstanceDesc log = ejb.getProcessInstanceById(pi.getId());
    Assertions.assertThat(log).isNotNull();
    Assertions.assertThat(log.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : Task(org.kie.api.task.model.Task) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) TaskData(org.kie.api.task.model.TaskData) RemoteEjbTest(org.jbpm.remote.ejb.test.RemoteEjbTest) Test(org.junit.Test)

Aggregations

TaskData (org.kie.api.task.model.TaskData)6 Task (org.kie.api.task.model.Task)4 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)2 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)2 UserInfo (org.kie.internal.task.api.UserInfo)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 Notification (org.kie.internal.task.api.model.Notification)2 NotificationEvent (org.kie.internal.task.api.model.NotificationEvent)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RemoteEjbTest (org.jbpm.remote.ejb.test.RemoteEjbTest)1 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)1 AssignmentService (org.jbpm.services.task.assignment.AssignmentService)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 Test (org.junit.Test)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 Content (org.kie.api.task.model.Content)1 Group (org.kie.api.task.model.Group)1 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)1