use of org.kie.api.task.model.Attachment in project jbpm by kiegroup.
the class UserTaskServiceImpl method getAttachmentContentById.
@Override
public Object getAttachmentContentById(String deploymentId, Long taskId, Long attachmentId) {
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;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
// perform actual operation
TaskService taskService = engine.getTaskService();
Attachment attachment = ((InternalTaskService) taskService).getAttachmentById(attachmentId);
long documentContentId = attachment.getAttachmentContentId();
if (documentContentId > 0) {
Content contentById = taskService.getContentById(documentContentId);
if (contentById == null) {
return null;
}
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getDeploymentId());
Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), ctx.getEnvironment(), ctx.getClassloader());
return unmarshall;
}
return null;
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.task.model.Attachment in project jbpm by kiegroup.
the class UserTaskServiceEJBIntegrationTest method testAttachmentOperations.
@Test
public void testAttachmentOperations() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
assertNotNull(taskIds);
assertEquals(1, taskIds.size());
Long taskId = taskIds.get(0);
List<Attachment> attachments = userTaskService.getAttachmentsByTaskId(taskId);
assertNotNull(attachments);
assertEquals(0, attachments.size());
Long attId = userTaskService.addAttachment(taskId, "john", "my attachment", "String attachment");
assertNotNull(attId);
attachments = userTaskService.getAttachmentsByTaskId(taskId);
assertNotNull(attachments);
assertEquals(1, attachments.size());
String content = (String) userTaskService.getAttachmentContentById(taskId, attId);
assertNotNull(content);
assertEquals("String attachment", content);
Attachment attachment = userTaskService.getAttachmentById(taskId, attId);
assertNotNull(attachment);
assertEquals("john", attachment.getAttachedBy().getId());
assertEquals("my attachment", attachment.getName());
assertNotNull(attachment.getAttachmentContentId());
userTaskService.deleteAttachment(taskId, attId);
attachments = userTaskService.getAttachmentsByTaskId(taskId);
assertNotNull(attachments);
assertEquals(0, attachments.size());
}
Aggregations