Search in sources :

Example 1 with AddAttachmentCommand

use of org.jbpm.services.task.commands.AddAttachmentCommand in project jbpm by kiegroup.

the class UserTaskServiceImpl method addAttachment.

@Override
public Long addAttachment(String deploymentId, Long taskId, String userId, String name, Object attachment) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    if (manager instanceof InternalRuntimeManager) {
        attachment = process(attachment, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        InternalAttachment att = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
        att.setName(name);
        att.setAccessType(AccessType.Inline);
        att.setAttachedAt(new Date());
        att.setAttachedBy(TaskModelProvider.getFactory().newUser(userId));
        att.setContentType(attachment.getClass().getName());
        return ((InternalTaskService) taskService).execute(new AddAttachmentCommand(taskId, att, attachment));
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) AddAttachmentCommand(org.jbpm.services.task.commands.AddAttachmentCommand) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 UserTaskService (org.jbpm.services.api.UserTaskService)1 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)1 AddAttachmentCommand (org.jbpm.services.task.commands.AddAttachmentCommand)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 TaskService (org.kie.api.task.TaskService)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1 InternalTaskService (org.kie.internal.task.api.InternalTaskService)1 InternalAttachment (org.kie.internal.task.api.model.InternalAttachment)1