Search in sources :

Example 1 with AttachmentRequest

use of org.activiti.rest.service.api.engine.AttachmentRequest 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;
}
Also used : Task(org.activiti.engine.task.Task) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse) AttachmentRequest(org.activiti.rest.service.api.engine.AttachmentRequest) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 Task (org.activiti.engine.task.Task)1 AttachmentRequest (org.activiti.rest.service.api.engine.AttachmentRequest)1 AttachmentResponse (org.activiti.rest.service.api.engine.AttachmentResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)1