protected ContentItem getContentItemFromRequest(String contentItemId) { ContentItem contentItem = contentService.createContentItemQuery().id(contentItemId).singleResult(); if (contentItem == null) { throw new FlowableObjectNotFoundException("Could not find a content item with id '" + contentItemId + "'.", ContentItem.class); } if (restApiInterceptor != null) { restApiInterceptor.accessContentItemInfoById(contentItem); } return contentItem; } }
public ContentItemRepresentation getContent(String contentId) { ContentItem contentItem = contentService.createContentItemQuery().id(contentId).singleResult(); if (contentItem == null) { throw new NotFoundException("No content found with id: " + contentId); } if (!permissionService.canDownloadContent(SecurityUtils.getCurrentUserObject(), contentItem)) { throw new NotPermittedException("You are not allowed to view the content with id: " + contentId); } return createContentItemResponse(contentItem); }
public void getRawContent(String contentId, HttpServletResponse response) { ContentItem contentItem = contentService.createContentItemQuery().id(contentId).singleResult(); if (contentItem == null) { throw new NotFoundException("No content found with id: " + contentId); } if (!contentItem.isContentAvailable()) { throw new NotFoundException("Raw content not yet available for id: " + contentId); } if (!permissionService.canDownloadContent(SecurityUtils.getCurrentUserObject(), contentItem)) { throw new NotPermittedException("You are not allowed to read the content with id: " + contentId); } // Set correct mine-type if (contentItem.getMimeType() != null) { response.setContentType(contentItem.getMimeType()); } // Write content response try (InputStream inputstream = contentService.getContentItemData(contentId)) { IOUtils.copy(inputstream, response.getOutputStream()); } catch (IOException e) { throw new InternalServerErrorException("Error while writing raw content data for content: " + contentId, e); } }
public void deleteContent(String contentId, HttpServletResponse response) { ContentItem contentItem = contentService.createContentItemQuery().id(contentId).singleResult(); if (contentItem == null) { throw new NotFoundException("No content found with id: " + contentId); } if (!permissionService.hasWritePermissionOnRelatedContent(SecurityUtils.getCurrentUserObject(), contentItem)) { throw new NotPermittedException("You are not allowed to delete the content with id: " + contentId); } if (contentItem.getField() != null) { // Not allowed to delete content that has been added as part of a form throw new NotPermittedException("You are not allowed to delete the content with id: " + contentId); } contentService.deleteContentItem(contentItem.getId()); }