Search in sources :

Example 11 with Content

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

the class TaskContentServiceImpl method loadContentData.

@SuppressWarnings("unchecked")
protected Map<String, Object> loadContentData(Long contentId, Task task) {
    if (contentId != null) {
        Map<String, Object> data = null;
        Content contentById = getContentById(contentId);
        if (contentById != null) {
            ContentMarshallerContext mContext = getMarshallerContext(task);
            Object unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), mContext.getEnvironment(), mContext.getClassloader());
            if (!(unmarshalledObject instanceof Map)) {
                data = new HashMap<String, Object>();
                data.put("Content", unmarshalledObject);
            } else {
                data = (Map<String, Object>) unmarshalledObject;
            }
            return data;
        }
    }
    return null;
}
Also used : Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 12 with Content

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

the class TaskContentServiceImpl method deleteDocumentContent.

public void deleteDocumentContent(long taskId, long contentId) {
    Task task = persistenceContext.findTask(taskId);
    ((InternalTaskData) task.getTaskData()).setDocumentContentId(-1);
    Content content = persistenceContext.findContent(contentId);
    persistenceContext.removeContent(content);
}
Also used : Task(org.kie.api.task.model.Task) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData)

Example 13 with Content

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

the class TaskContentServiceImpl method getAllContentByTaskId.

public List<Content> getAllContentByTaskId(long taskId) {
    Task task = persistenceContext.findTask(taskId);
    long inputContentId = task.getTaskData().getDocumentContentId();
    long outputContentId = task.getTaskData().getOutputContentId();
    long faultContentId = task.getTaskData().getFaultContentId();
    List<Content> allContent = new ArrayList<Content>();
    allContent.add(persistenceContext.findContent(inputContentId));
    allContent.add(persistenceContext.findContent(outputContentId));
    allContent.add(persistenceContext.findContent(faultContentId));
    return allContent;
}
Also used : Task(org.kie.api.task.model.Task) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) ArrayList(java.util.ArrayList)

Example 14 with Content

use of org.kie.api.task.model.Content 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 15 with Content

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

the class ExecuteReminderCommand method getVariables.

@SuppressWarnings("unchecked")
private Map<String, Object> getVariables(TaskContext ctx, TaskPersistenceContext persistenceContext, Task task, TaskData taskData) {
    Map<String, Object> variables;
    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();
    }
    return variables;
}
Also used : Content(org.kie.api.task.model.Content) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Aggregations

Content (org.kie.api.task.model.Content)40 Task (org.kie.api.task.model.Task)32 HashMap (java.util.HashMap)23 Map (java.util.Map)21 InternalContent (org.kie.internal.task.api.model.InternalContent)17 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)15 InternalTask (org.kie.internal.task.api.model.InternalTask)14 ContentData (org.kie.internal.task.api.model.ContentData)11 Test (org.junit.Test)10 JaxbContent (org.jbpm.services.task.impl.model.xml.JaxbContent)9 StringReader (java.io.StringReader)8 TaskService (org.kie.api.task.TaskService)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)6 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 InternalTaskService (org.kie.internal.task.api.InternalTaskService)5 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4 Attachment (org.kie.api.task.model.Attachment)4