Search in sources :

Example 6 with TaskEventSupport

use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.

the class ExecuteReminderCommand method executedeadLine.

private Void executedeadLine(TaskContext ctx, TaskPersistenceContext persistenceContext, Task task, DeadlineSummary deadlineSummary, TaskData taskData) {
    Deadline deadline = persistenceContext.findDeadline(deadlineSummary.getDeadlineId());
    if (task == null || deadline == null) {
        return null;
    }
    if (taskData != null) {
        UserInfo userInfo = (UserInfo) ctx.get(EnvironmentName.TASK_USER_INFO);
        // check if task is still in valid status
        if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
            Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
            if (deadline == null || deadline.getEscalations() == null) {
                return null;
            }
            TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
            taskEventSupport.fireBeforeTaskNotified(task, ctx);
            for (Escalation escalation : deadline.getEscalations()) {
                for (Notification notification : escalation.getNotifications()) {
                    if (notification.getNotificationType() == NotificationType.Email) {
                        logger.debug("Sending an Email");
                        NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
                    }
                }
            }
            taskEventSupport.fireAfterTaskNotified(task, ctx);
        }
    }
    return null;
}
Also used : Deadline(org.kie.internal.task.api.model.Deadline) Escalation(org.kie.internal.task.api.model.Escalation) UserInfo(org.kie.internal.task.api.UserInfo) NotificationEvent(org.kie.internal.task.api.model.NotificationEvent) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification)

Example 7 with TaskEventSupport

use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.

the class AddPeopleAssignmentsCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskEventSupport taskEventSupport = context.getTaskEventSupport();
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    // security check
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    List<OrganizationalEntity> entityList = Arrays.asList(entities);
    AssignmentType assignmentType = null;
    switch(type) {
        case POT_OWNER:
            if (removeExisting) {
                task.getPeopleAssignments().getPotentialOwners().clear();
            }
            task.getPeopleAssignments().getPotentialOwners().addAll(entityList);
            assignmentType = AssignmentType.POT_OWNER;
            break;
        case EXCL_OWNER:
            if (removeExisting) {
                ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().clear();
            }
            ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().addAll(entityList);
            assignmentType = AssignmentType.EXCL_OWNER;
            break;
        case ADMIN:
            if (removeExisting) {
                task.getPeopleAssignments().getBusinessAdministrators().clear();
            }
            task.getPeopleAssignments().getBusinessAdministrators().addAll(entityList);
            assignmentType = AssignmentType.ADMIN;
            break;
        default:
            break;
    }
    taskEventSupport.fireBeforeTaskAssignmentsAddedEvent(task, context, assignmentType, entityList);
    doCallbackOperationForPeopleAssignments(((InternalPeopleAssignments) task.getPeopleAssignments()), context);
    taskEventSupport.fireAfterTaskAssignmentsAddedEvent(task, context, assignmentType, entityList);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) TaskContext(org.jbpm.services.task.commands.TaskContext) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) AssignmentType(org.kie.api.task.TaskLifeCycleEventListener.AssignmentType) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport)

Example 8 with TaskEventSupport

use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.

the class AddTaskInputsCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskEventSupport taskEventSupport = context.getTaskEventSupport();
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    Task task = persistenceContext.findTask(taskId);
    // security check
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    long inputContentId = task.getTaskData().getDocumentContentId();
    Content outputContent = persistenceContext.findContent(inputContentId);
    Map<String, Object> initialContent = new HashMap<String, Object>();
    Map<String, Object> mergedContent = values;
    if (outputContent == null) {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, values, mcontext.getEnvironment());
        Content content = TaskModelProvider.getFactory().newContent();
        ((InternalContent) content).setContent(outputContentData.getContent());
        persistenceContext.persistContent(content);
        ((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
    } else {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
        if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
            // set initial content with data from storage before being altered by this values
            initialContent.putAll((Map<String, Object>) unmarshalledObject);
            ((Map<String, Object>) unmarshalledObject).putAll(values);
            mergedContent = ((Map<String, Object>) unmarshalledObject);
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
    }
    taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
    ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
    taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) TaskContext(org.jbpm.services.task.commands.TaskContext) HashMap(java.util.HashMap) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalContent(org.kie.internal.task.api.model.InternalContent) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 9 with TaskEventSupport

use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.

the class RemovePeopleAssignmentsCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskEventSupport taskEventSupport = context.getTaskEventSupport();
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    // security check
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    List<OrganizationalEntity> entityList = Arrays.asList(entities);
    AssignmentType assignmentType = null;
    taskEventSupport.fireBeforeTaskUpdated(task, context);
    switch(type) {
        case POT_OWNER:
            assignmentType = AssignmentType.POT_OWNER;
            taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
            task.getPeopleAssignments().getPotentialOwners().removeAll(entityList);
            break;
        case EXCL_OWNER:
            assignmentType = AssignmentType.EXCL_OWNER;
            taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
            ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().removeAll(entityList);
            break;
        case ADMIN:
            assignmentType = AssignmentType.ADMIN;
            taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
            task.getPeopleAssignments().getBusinessAdministrators().removeAll(entityList);
            break;
        default:
            break;
    }
    taskEventSupport.fireAfterTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) TaskContext(org.jbpm.services.task.commands.TaskContext) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) AssignmentType(org.kie.api.task.TaskLifeCycleEventListener.AssignmentType) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport)

Aggregations

TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)9 Task (org.kie.api.task.model.Task)7 TaskContext (org.jbpm.services.task.commands.TaskContext)5 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)5 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)5 Map (java.util.Map)4 Content (org.kie.api.task.model.Content)4 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)4 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)4 HashMap (java.util.HashMap)3 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 UserInfo (org.kie.internal.task.api.UserInfo)3 ContentData (org.kie.internal.task.api.model.ContentData)3 InternalContent (org.kie.internal.task.api.model.InternalContent)3 Notification (org.kie.internal.task.api.model.Notification)3 NotificationEvent (org.kie.internal.task.api.model.NotificationEvent)3 AssignmentType (org.kie.api.task.TaskLifeCycleEventListener.AssignmentType)2 TaskData (org.kie.api.task.model.TaskData)2 Deadline (org.kie.internal.task.api.model.Deadline)2 EmailNotification (org.kie.internal.task.api.model.EmailNotification)2