use of org.activiti.rest.service.api.engine.AttachmentResponse in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method createAttachment.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.POST, produces = "application/json")
public AttachmentResponse createAttachment(@PathVariable String taskId, HttpServletRequest request, HttpServletResponse response) {
AttachmentResponse result = null;
Task task = getTaskFromRequest(taskId);
if (request instanceof MultipartHttpServletRequest) {
result = createBinaryAttachment((MultipartHttpServletRequest) request, task, response);
} else {
AttachmentRequest attachmentRequest = null;
try {
attachmentRequest = objectMapper.readValue(request.getInputStream(), AttachmentRequest.class);
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a AttachmentRequest instance", e);
}
if (attachmentRequest == null) {
throw new ActivitiIllegalArgumentException("AttachmentRequest properties not found in request");
}
result = createSimpleAttachment(attachmentRequest, task);
}
response.setStatus(HttpStatus.CREATED.value());
return result;
}
use of org.activiti.rest.service.api.engine.AttachmentResponse in project Activiti by Activiti.
the class RestResponseFactory method createAttachmentResponse.
public AttachmentResponse createAttachmentResponse(Attachment attachment, RestUrlBuilder urlBuilder) {
AttachmentResponse result = new AttachmentResponse();
result.setId(attachment.getId());
result.setName(attachment.getName());
result.setDescription(attachment.getDescription());
result.setTime(attachment.getTime());
result.setType(attachment.getType());
result.setUserId(attachment.getUserId());
if (attachment.getUrl() == null && attachment.getTaskId() != null) {
// Attachment content can be streamed
result.setContentUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, attachment.getTaskId(), attachment.getId()));
} else {
result.setExternalUrl(attachment.getUrl());
}
if (attachment.getTaskId() != null) {
result.setUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_ATTACHMENT, attachment.getTaskId(), attachment.getId()));
result.setTaskUrl(urlBuilder.buildUrl(RestUrls.URL_TASK, attachment.getTaskId()));
}
if (attachment.getProcessInstanceId() != null) {
result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, attachment.getProcessInstanceId()));
}
return result;
}
use of org.activiti.rest.service.api.engine.AttachmentResponse in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method getAttachments.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.GET, produces = "application/json")
public List<AttachmentResponse> getAttachments(@PathVariable String taskId, HttpServletRequest request) {
List<AttachmentResponse> result = new ArrayList<AttachmentResponse>();
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
for (Attachment attachment : taskService.getTaskAttachments(task.getId())) {
result.add(restResponseFactory.createAttachmentResponse(attachment));
}
return result;
}
Aggregations