use of org.camunda.bpm.engine.rest.dto.task.AttachmentDto in project camunda-bpm-platform by camunda.
the class TaskAttachmentResourceImpl method getAttachments.
@Override
public List<AttachmentDto> getAttachments() {
if (!isHistoryEnabled()) {
return Collections.emptyList();
}
ensureTaskExists(Status.NOT_FOUND);
List<Attachment> taskAttachments = engine.getTaskService().getTaskAttachments(taskId);
List<AttachmentDto> attachments = new ArrayList<AttachmentDto>();
for (Attachment attachment : taskAttachments) {
attachments.add(AttachmentDto.fromAttachment(attachment));
}
return attachments;
}
use of org.camunda.bpm.engine.rest.dto.task.AttachmentDto in project camunda-bpm-platform by camunda.
the class TaskAttachmentResourceImpl method addAttachment.
@Override
public AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload) {
ensureHistoryEnabled(Status.FORBIDDEN);
ensureTaskExists(Status.BAD_REQUEST);
FormPart attachmentNamePart = payload.getNamedPart("attachment-name");
FormPart attachmentTypePart = payload.getNamedPart("attachment-type");
FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description");
FormPart contentPart = payload.getNamedPart("content");
FormPart urlPart = payload.getNamedPart("url");
if (urlPart == null && contentPart == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "No content or url to remote content exists to create the task attachment.");
}
String attachmentName = null;
String attachmentDescription = null;
String attachmentType = null;
if (attachmentNamePart != null) {
attachmentName = attachmentNamePart.getTextContent();
}
if (attachmentDescriptionPart != null) {
attachmentDescription = attachmentDescriptionPart.getTextContent();
}
if (attachmentTypePart != null) {
attachmentType = attachmentTypePart.getTextContent();
}
Attachment attachment = null;
try {
if (contentPart != null) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(contentPart.getBinaryContent());
attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream);
} else if (urlPart != null) {
attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.getTextContent());
}
} catch (ProcessEngineException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null");
}
URI uri = uriInfo.getBaseUriBuilder().path(rootResourcePath).path(TaskRestService.PATH).path(taskId + "/attachment/" + attachment.getId()).build();
AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment);
// GET /
attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self");
return attachmentDto;
}
Aggregations