Search in sources :

Example 11 with InternalContent

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

the class RemoveTaskDataCommand 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 contentId = task.getTaskData().getDocumentContentId();
    if (!input) {
        contentId = task.getTaskData().getOutputContentId();
    }
    Content outputContent = persistenceContext.findContent(contentId);
    Map<String, Object> initialContent = new HashMap<>();
    Map<String, Object> mergedContent = new HashMap<>();
    if (outputContent != null) {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
        if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
            mergedContent.putAll(((Map<String, Object>) unmarshalledObject));
            // set initial content for the sake of listeners
            initialContent.putAll(mergedContent);
            variableNames.forEach(name -> mergedContent.remove(name));
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, mergedContent, mcontext.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
    }
    if (input) {
        taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
        ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
        taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
    } else {
        taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
        ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(mergedContent);
        taskEventSupport.fireAfterTaskOutputVariablesChanged(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 12 with InternalContent

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

the class UpdateTaskCommand 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) && !isOwner(userId, task.getPeopleAssignments().getPotentialOwners(), task.getTaskData().getActualOwner(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin or potential owner of task " + taskId);
    }
    taskEventSupport.fireBeforeTaskUpdated(task, context);
    // process task meta data
    if (userTask.getFormName() != null) {
        ((InternalTask) task).setFormName(userTask.getFormName());
    }
    if (userTask.getName() != null) {
        ((InternalTask) task).setName(userTask.getName());
    }
    if (userTask.getDescription() != null) {
        ((InternalTask) task).setDescription(userTask.getDescription());
    }
    if (userTask.getPriority() != null) {
        ((InternalTask) task).setPriority(userTask.getPriority());
    }
    if (userTask.getDueDate() != null) {
        ((InternalTaskData) task.getTaskData()).setExpirationTime(userTask.getDueDate());
    }
    // process task inputs
    long inputContentId = task.getTaskData().getDocumentContentId();
    Content inputContent = persistenceContext.findContent(inputContentId);
    Map<String, Object> mergedContent = inputs;
    if (inputs != null) {
        if (inputContent == null) {
            ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
            ContentData outputContentData = ContentMarshallerHelper.marshal(task, inputs, 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(inputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
            if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
                ((Map<String, Object>) unmarshalledObject).putAll(inputs);
                mergedContent = ((Map<String, Object>) unmarshalledObject);
            }
            ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
            ((InternalContent) inputContent).setContent(outputContentData.getContent());
            persistenceContext.persistContent(inputContent);
        }
        ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
    }
    if (outputs != null) {
        // process task outputs
        context.getTaskContentService().addOutputContent(taskId, outputs);
    }
    persistenceContext.updateTask(task);
    // finally trigger event support after the updates
    taskEventSupport.fireAfterTaskUpdated(task, context);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) InternalTask(org.kie.internal.task.api.model.InternalTask) 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) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 13 with InternalContent

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

the class AddAttachmentCommand method execute.

public Long execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Attachment attachmentImpl = attachment;
    if (attachmentImpl == null) {
        attachmentImpl = jaxbAttachment;
    }
    Content contentImpl = content;
    if (contentImpl == null) {
        contentImpl = jaxbContent;
    }
    if (rawContent != null && contentImpl == null) {
        Task task = context.getPersistenceContext().findTask(taskId);
        contentImpl = TaskModelProvider.getFactory().newContent();
        ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getTaskData().getDeploymentId());
        ((InternalContent) contentImpl).setContent(ContentMarshallerHelper.marshallContent(task, rawContent, ctx.getEnvironment()));
        ((InternalAttachment) attachmentImpl).setSize(contentImpl.getContent().length);
    }
    doCallbackOperationForAttachment(attachmentImpl, context);
    return context.getTaskAttachmentService().addAttachment(taskId, attachmentImpl, contentImpl);
}
Also used : Task(org.kie.api.task.model.Task) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) JaxbAttachment(org.jbpm.services.task.impl.model.xml.JaxbAttachment) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalContent(org.kie.internal.task.api.model.InternalContent) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 14 with InternalContent

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

the class TaskInstanceServiceImpl method setOutput.

public void setOutput(long taskId, String userId, Object outputContentData) {
    Task task = persistenceContext.findTask(taskId);
    ContentData contentData = ContentMarshallerHelper.marshal(task, outputContentData, environment);
    Content content = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content).setContent(contentData.getContent());
    persistenceContext.persistContent(content);
    persistenceContext.setOutputToTask(content, contentData, task);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalContent(org.kie.internal.task.api.model.InternalContent)

Example 15 with InternalContent

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

the class TaskInstanceServiceImpl method setFault.

public void setFault(long taskId, String userId, FaultData fault) {
    Task task = persistenceContext.findTask(taskId);
    Content content = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content).setContent(fault.getContent());
    persistenceContext.persistContent(content);
    persistenceContext.setFaultToTask(content, fault, task);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalContent(org.kie.internal.task.api.model.InternalContent)

Aggregations

InternalContent (org.kie.internal.task.api.model.InternalContent)25 ContentData (org.kie.internal.task.api.model.ContentData)20 InternalTask (org.kie.internal.task.api.model.InternalTask)17 Test (org.junit.Test)15 InputStreamReader (java.io.InputStreamReader)14 Reader (java.io.Reader)14 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 Task (org.kie.api.task.model.Task)13 Content (org.kie.api.task.model.Content)11 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)11 User (org.kie.api.task.model.User)11 HashMap (java.util.HashMap)10 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)10 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)10 Date (java.util.Date)8 ArrayList (java.util.ArrayList)7 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)5 Map (java.util.Map)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4