use of org.activiti.engine.task.Attachment in project Activiti by Activiti.
the class HistoricTaskDetailPanel method populateRelatedContent.
protected void populateRelatedContent(Table table, List<Attachment> attachments) {
if (!attachments.isEmpty()) {
table.setVisible(true);
}
for (Attachment attachment : attachments) {
AttachmentRenderer renderer = attachmentRendererManager.getRenderer(attachment);
Item attachmentItem = table.addItem(attachment.getId());
// Simple renderer that just shows a popup window with the attachment
RelatedContentComponent relatedContentComponent = new RelatedContentComponent() {
public void showAttachmentDetail(Attachment attachment) {
AttachmentDetailPopupWindow popup = new AttachmentDetailPopupWindow(attachment);
ExplorerApp.get().getViewManager().showPopupWindow(popup);
}
};
attachmentItem.getItemProperty("name").setValue(renderer.getOverviewComponent(attachment, relatedContentComponent));
attachmentItem.getItemProperty("type").setValue(new Embedded(null, renderer.getImage(attachment)));
}
table.setPageLength(table.size());
}
use of org.activiti.engine.task.Attachment in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method createBinaryAttachment.
protected AttachmentResponse createBinaryAttachment(MultipartHttpServletRequest request, Task task, HttpServletResponse response) {
String name = null;
String description = null;
String type = null;
Map<String, String[]> paramMap = request.getParameterMap();
for (String parameterName : paramMap.keySet()) {
if (paramMap.get(parameterName).length > 0) {
if (parameterName.equalsIgnoreCase("name")) {
name = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("description")) {
description = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("type")) {
type = paramMap.get(parameterName)[0];
}
}
}
if (name == null) {
throw new ActivitiIllegalArgumentException("Attachment name is required.");
}
if (request.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Attachment content is required.");
}
MultipartFile file = request.getFileMap().values().iterator().next();
if (file == null) {
throw new ActivitiIllegalArgumentException("Attachment content is required.");
}
try {
Attachment createdAttachment = taskService.createAttachment(type, task.getId(), task.getProcessInstanceId(), name, description, file.getInputStream());
response.setStatus(HttpStatus.CREATED.value());
return restResponseFactory.createAttachmentResponse(createdAttachment);
} catch (Exception e) {
throw new ActivitiException("Error creating attachment response", e);
}
}
use of org.activiti.engine.task.Attachment in project Activiti by Activiti.
the class TaskAttachmentResource method getAttachment.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}", method = RequestMethod.GET, produces = "application/json")
public AttachmentResponse getAttachment(@PathVariable("taskId") String taskId, @PathVariable("attachmentId") String attachmentId, HttpServletRequest request) {
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
Attachment attachment = taskService.getAttachment(attachmentId);
if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
}
return restResponseFactory.createAttachmentResponse(attachment);
}
use of org.activiti.engine.task.Attachment in project Activiti by Activiti.
the class TaskServiceTest method testTaskAttachmentWithProcessInstanceId.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskAttachmentWithProcessInstanceId() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
String processInstanceId = processInstance.getId();
taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com");
Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0);
assertEquals("weatherforcast", attachment.getName());
assertEquals("temperatures and more", attachment.getDescription());
assertEquals("web page", attachment.getType());
assertEquals(processInstanceId, attachment.getProcessInstanceId());
assertNull(attachment.getTaskId());
assertEquals("http://weather.com", attachment.getUrl());
assertNull(taskService.getAttachmentContent(attachment.getId()));
// Finally, clean up
taskService.deleteAttachment(attachment.getId());
// TODO: Bad API design. Need to fix attachment/comment properly
((TaskServiceImpl) taskService).deleteComments(null, processInstanceId);
}
}
use of org.activiti.engine.task.Attachment in project Activiti by Activiti.
the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricProcessInstanceDelete.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testAttachmentEntityEventsOnHistoricProcessInstanceDelete() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// Create link-attachment
Attachment attachment = taskService.createAttachment("test", null, processInstance.getId(), "attachment name", "description", "http://activiti.org");
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), null);
historyService.deleteHistoricProcessInstance(processInstance.getId());
assertEquals(1, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
Attachment attachmentFromEvent = (Attachment) event.getEntity();
assertEquals(attachment.getId(), attachmentFromEvent.getId());
}
}
Aggregations