public ResultListDataRepresentation getContentItemsForCase(String caseInstanceId) { permissionService.hasReadPermissionOnCase(SecurityUtils.getCurrentUserObject(), caseInstanceId); return createResultRepresentation(contentService.createContentItemQuery().scopeType("cmmn").scopeId(caseInstanceId).list()); }
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 ResultListDataRepresentation getContentItemsForProcessInstance(String processInstanceId) { // TODO: check if process exists if (!permissionService.hasReadPermissionOnProcessInstance(SecurityUtils.getCurrentUserObject(), processInstanceId)) { throw new NotPermittedException("You are not allowed to read the process with id: " + processInstanceId); } return createResultRepresentation(contentService.createContentItemQuery().processInstanceId(processInstanceId).list()); }
contentItemQuery.id(request.getId()); contentItemQuery.ids(request.getIds()); contentItemQuery.name(request.getName()); contentItemQuery.nameLike(request.getNameLike()); contentItemQuery.mimeType(request.getMimeType()); contentItemQuery.mimeTypeLike(request.getMimeTypeLike()); contentItemQuery.taskId(request.getTaskId()); contentItemQuery.taskIdLike(request.getTaskIdLike()); contentItemQuery.processInstanceId(request.getProcessInstanceId()); contentItemQuery.processInstanceIdLike(request.getProcessInstanceIdLike()); contentItemQuery.contentStoreId(request.getContentStoreId()); contentItemQuery.contentStoreIdLike(request.getContentStoreIdLike()); contentItemQuery.contentStoreName(request.getContentStoreName()); contentItemQuery.contentStoreNameLike(request.getContentStoreNameLike()); contentItemQuery.contentSize(request.getContentSize());
@Override public void enrichFormFields(FormInfo formInfo) { ContentService contentService = CommandContextUtil.getContentService(); if (contentService == null) { return; } SimpleFormModel formModel = (SimpleFormModel) formInfo.getFormModel(); if (formModel.getFields() != null) { for (FormField formField : formModel.getFields()) { if (FormFieldTypes.UPLOAD.equals(formField.getType())) { List<String> contentItemIds = null; if (formField.getValue() instanceof List) { contentItemIds = (List<String>) formField.getValue(); } else if (formField.getValue() instanceof String) { String[] splittedString = ((String) formField.getValue()).split(","); contentItemIds = new ArrayList<>(); Collections.addAll(contentItemIds, splittedString); } if (contentItemIds != null) { Set<String> contentItemIdSet = new HashSet<>(contentItemIds); List<ContentItem> contentItems = contentService.createContentItemQuery() .ids(contentItemIdSet) .list(); formField.setValue(contentItems); } } } } }
/** * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case * the DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop. */ public static void assertAndEnsureCleanDb(ContentEngine contentEngine) { LOGGER.debug("verifying that db is clean after test"); ContentService contentService = contentEngine.getContentEngineConfiguration().getContentService(); List<ContentItem> items = contentService.createContentItemQuery().list(); if (items != null && !items.isEmpty()) { throw new AssertionError("ContentItem is not empty"); } }
@Override public void enrichFormFields(FormInfo formInfo) { ContentService contentService = CommandContextUtil.getContentService(); if (contentService == null) { return; } SimpleFormModel formModel = (SimpleFormModel) formInfo.getFormModel(); if (formModel.getFields() != null) { for (FormField formField : formModel.getFields()) { if (FormFieldTypes.UPLOAD.equals(formField.getType())) { List<String> contentItemIds = null; if (formField.getValue() instanceof List) { contentItemIds = (List<String>) formField.getValue(); } else if (formField.getValue() instanceof String) { String[] splittedString = ((String) formField.getValue()).split(","); contentItemIds = new ArrayList<>(); Collections.addAll(contentItemIds, splittedString); } if (contentItemIds != null) { Set<String> contentItemIdSet = new HashSet<>(contentItemIds); List<ContentItem> contentItems = contentService.createContentItemQuery() .ids(contentItemIdSet) .list(); formField.setValue(contentItems); } } } } }
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 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()); }
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); } }