Search in sources :

Example 1 with Deadline

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

the class AddTaskCommand method scheduleDeadlines.

private void scheduleDeadlines(final List<? extends Deadline> deadlines, final long now, final long taskId, DeadlineType type, TaskDeadlinesService deadlineService) {
    for (Deadline deadline : deadlines) {
        if (!deadline.isEscalated()) {
            // only escalate when true - typically this would only be true
            // if the user is requested that the notification should never be escalated
            Date date = deadline.getDate();
            deadlineService.schedule(taskId, deadline.getId(), date.getTime() - now, type);
        }
    }
}
Also used : Deadline(org.kie.internal.task.api.model.Deadline) Date(java.util.Date)

Example 2 with Deadline

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

the class UserTaskAdminServiceImpl method notify.

protected Long notify(String deploymentId, long taskId, String timeExpression, DeadlineType type, Notification notification) throws TaskNotFoundException {
    UserTaskInstanceDesc task = runtimeDataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    List<Escalation> escalations = new ArrayList<Escalation>();
    Deadline taskDeadline = TaskModelProvider.getFactory().newDeadline();
    taskDeadline.setEscalations(escalations);
    Escalation escalation = TaskModelProvider.getFactory().newEscalation();
    escalations.add(escalation);
    escalation.setName("Admin notification for task " + taskId);
    List<Notification> notifications = new ArrayList<Notification>();
    notifications.add(notification);
    escalation.setNotifications(notifications);
    return userTaskService.execute(task.getDeploymentId(), ProcessInstanceIdContext.get(task.getProcessInstanceId()), new ScheduleTaskDeadlineCommand(identityProvider.getName(), taskId, type, taskDeadline, timeExpression));
}
Also used : Escalation(org.kie.internal.task.api.model.Escalation) Deadline(org.kie.internal.task.api.model.Deadline) ArrayList(java.util.ArrayList) ScheduleTaskDeadlineCommand(org.jbpm.kie.services.impl.admin.commands.ScheduleTaskDeadlineCommand) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) TaskNotification(org.jbpm.services.api.admin.TaskNotification) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification)

Example 3 with Deadline

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

the class CancelTaskDeadlineCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    logger.debug("About to cancel deadline {} on a task {}", deadlineId, task);
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    DeadlineType type = DeadlineType.START;
    Deadline deadline = deadlines.getStartDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
    if (deadline == null) {
        deadline = deadlines.getEndDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
        type = DeadlineType.END;
    }
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
    deadlinesService.unschedule(taskId, deadline, type);
    persistenceContext.removeDeadline(deadline);
    return null;
}
Also used : DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) Deadline(org.kie.internal.task.api.model.Deadline) Deadlines(org.kie.internal.task.api.model.Deadlines) DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Deadline(org.kie.internal.task.api.model.Deadline) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 4 with Deadline

use of org.kie.internal.task.api.model.Deadline 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 5 with Deadline

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

the class CollectionUtils method readDeadlinesList.

public static List<Deadline> readDeadlinesList(ObjectInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    List<Deadline> list = new ArrayList<Deadline>(size);
    for (int i = 0; i < size; i++) {
        Deadline item = new DeadlineImpl();
        item.readExternal(in);
        list.add(item);
    }
    return list;
}
Also used : DeadlineImpl(org.jbpm.services.task.impl.model.DeadlineImpl) Deadline(org.kie.internal.task.api.model.Deadline) ArrayList(java.util.ArrayList)

Aggregations

Deadline (org.kie.internal.task.api.model.Deadline)11 ArrayList (java.util.ArrayList)6 Escalation (org.kie.internal.task.api.model.Escalation)6 Notification (org.kie.internal.task.api.model.Notification)4 Task (org.kie.api.task.model.Task)3 Deadlines (org.kie.internal.task.api.model.Deadlines)3 Reassignment (org.kie.internal.task.api.model.Reassignment)3 Date (java.util.Date)2 ScheduleTaskDeadlineCommand (org.jbpm.kie.services.impl.admin.commands.ScheduleTaskDeadlineCommand)2 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)2 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)2 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)2 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)2 UserInfo (org.kie.internal.task.api.UserInfo)2 EmailNotification (org.kie.internal.task.api.model.EmailNotification)2 InternalTask (org.kie.internal.task.api.model.InternalTask)2 NotificationEvent (org.kie.internal.task.api.model.NotificationEvent)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1