Search in sources :

Example 1 with AttachmentResponse

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

Example 2 with AttachmentResponse

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;
}
Also used : AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse)

Example 3 with AttachmentResponse

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;
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse) Attachment(org.activiti.engine.task.Attachment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AttachmentResponse (org.activiti.rest.service.api.engine.AttachmentResponse)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ArrayList (java.util.ArrayList)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 Attachment (org.activiti.engine.task.Attachment)1 Task (org.activiti.engine.task.Task)1 AttachmentRequest (org.activiti.rest.service.api.engine.AttachmentRequest)1 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)1