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);
}
}
Aggregations