@Override public InputStream getContent() { if (inputStream == null) { try { inputStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new ContentStorageException("Error while opening file stream", e); } } return inputStream; }
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 getContentItemsForCase(String caseInstanceId) { permissionService.hasReadPermissionOnCase(SecurityUtils.getCurrentUserObject(), caseInstanceId); return createResultRepresentation(contentService.createContentItemQuery().scopeType("cmmn").scopeId(caseInstanceId).list()); }
protected ContentItemResponse createSimpleContentItem(ContentItemRequest contentItemRequest) { if (contentItemRequest.getName() == null) { throw new FlowableIllegalArgumentException("Content item name is required."); } ContentItem contentItem = contentService.newContentItem(); contentItem.setName(contentItemRequest.getName()); contentItem.setMimeType(contentItemRequest.getMimeType()); contentItem.setTaskId(contentItemRequest.getTaskId()); contentItem.setProcessInstanceId(contentItemRequest.getProcessInstanceId()); contentItem.setContentStoreId(contentItemRequest.getContentStoreId()); contentItem.setContentStoreName(contentItemRequest.getContentStoreName()); contentItem.setField(contentItemRequest.getField()); contentItem.setCreatedBy(contentItemRequest.getCreatedBy()); contentItem.setLastModifiedBy(contentItemRequest.getLastModifiedBy()); contentItem.setTenantId(contentItemRequest.getTenantId()); if (restApiInterceptor != null) { restApiInterceptor.createNewContentItem(contentItem); } contentService.saveContentItem(contentItem); return contentRestResponseFactory.createContentItemResponse(contentItem); }
public ContentItemResponse(ContentItem contentItem, String url) { setId(contentItem.getId()); setName(contentItem.getName()); setMimeType(contentItem.getMimeType()); setTaskId(contentItem.getTaskId()); setProcessInstanceId(contentItem.getProcessInstanceId()); setContentStoreId(contentItem.getContentStoreId()); setContentStoreName(contentItem.getContentStoreName()); setContentAvailable(contentItem.isContentAvailable()); setTenantId(contentItem.getTenantId()); setCreated(contentItem.getCreated()); setCreatedBy(contentItem.getCreatedBy()); setLastModified(contentItem.getLastModified()); setLastModifiedBy(contentItem.getLastModifiedBy()); setUrl(url); }
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 ResultListDataRepresentation getContentItemsForTask(String taskId) { permissionService.validateReadPermissionOnTask(SecurityUtils.getCurrentUserObject(), taskId); return createResultRepresentation(contentService.createContentItemQuery().taskId(taskId).list()); }
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()); }
/** * 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 InputStream execute(CommandContext commandContext) { if (contentItemId == null) { throw new FlowableIllegalArgumentException("contentItemId is null"); } ContentItem contentItem = CommandContextUtil.getContentItemEntityManager().findById(contentItemId); if (contentItem == null) { throw new FlowableObjectNotFoundException("content item could not be found with id " + contentItemId); } ContentStorage contentStorage = CommandContextUtil.getContentEngineConfiguration().getContentStorage(); ContentObject contentObject = contentStorage.getContentObject(contentItem.getContentStoreId()); return contentObject.getContent(); }
public ContentItemResponse createContentItemResponse(ContentItem contentItem, ContentRestUrlBuilder urlBuilder) { ContentItemResponse response = new ContentItemResponse(contentItem, urlBuilder.buildUrl(ContentRestUrls.URL_CONTENT_ITEM, contentItem.getId())); return response; }
public static ContentService getContentService(AbstractEngineConfiguration engineConfiguration) { ContentService contentService = null; ContentEngineConfigurationApi contentEngineConfiguration = getContentEngineConfiguration(engineConfiguration); if (contentEngineConfiguration != null) { contentService = contentEngineConfiguration.getContentService(); } return contentService; }
/** * @return a file reference for the given id, checking for existence based on the given flag. */ protected File getFileForId(String id, boolean shouldExist) { BigInteger idValue = null; try { idValue = new BigInteger(id); } catch (NumberFormatException nfe) { throw new ContentStorageException("Illegal ID value, only positive numbers are supported: " + id, nfe); } File path = converter.getPathForId(idValue); File file = new File(rootFolder, path.getPath()); if (shouldExist != file.exists()) { if (shouldExist) { throw new ContentNotFoundException("Content with id: " + id + " was not found (path: " + file.toString() + ")"); } else { throw new ContentNotFoundException("Content with id: " + id + " already exists."); } } return file; }
protected ContentItemRepresentation addContentItem(ContentItemRepresentation contentItemBody, String taskId, String processInstanceId, boolean isRelatedContent) { if (contentItemBody.getContentStoreId() == null || contentItemBody.getContentStoreName() == null || contentItemBody.getName() == null) { throw new BadRequestException("Name, source and sourceId are required parameters"); } User user = SecurityUtils.getCurrentUserObject(); ContentItem contentItem = contentService.newContentItem(); contentItem.setName(contentItemBody.getName()); contentItem.setProcessInstanceId(processInstanceId); contentItem.setTaskId(taskId); contentItem.setContentStoreId(contentItemBody.getContentStoreId()); contentItem.setContentStoreName(contentItemBody.getContentStoreName()); contentItem.setMimeType(contentItemBody.getMimeType()); contentItem.setCreatedBy(user.getId()); contentItem.setLastModifiedBy(user.getId()); contentService.saveContentItem(contentItem); return createContentItemResponse(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 static ContentService getContentService(CommandContext commandContext) { ContentService contentService = null; ContentEngineConfigurationApi contentEngineConfiguration = getContentEngineConfiguration(commandContext); if (contentEngineConfiguration != null) { contentService = contentEngineConfiguration.getContentService(); } return contentService; }
@Override public void deleteContentObject(String id) { try { File contentFile = getFileForId(id, true); contentFile.delete(); } catch (Exception e) { throw new ContentStorageException("Error while deleting content", e); } }
public static ContentService getContentService(CommandContext commandContext) { ContentService contentService = null; ContentEngineConfigurationApi contentEngineConfiguration = getContentEngineConfiguration(commandContext); if (contentEngineConfiguration != null) { contentService = contentEngineConfiguration.getContentService(); } return contentService; }
public BigInteger getIdForPath(File path) { BigInteger result = BigInteger.ZERO; BigInteger currentFactor = BigInteger.ONE; int depth = 0; File parent = path; while (parent != null && depth < iterationDepth) { try { result = result.add(new BigInteger(parent.getName()).multiply(currentFactor)); // Move on to next iteration parent = parent.getParentFile(); depth++; currentFactor = currentFactor.multiply(blockSize); } catch (NumberFormatException nfe) { throw new ContentStorageException("Illegal format of path segment: " + parent.getName(), nfe); } } return result; }
@Override public void deleteContentObject(String id) { try { File contentFile = getContentFile(id); File parentFile = contentFile.getParentFile(); contentFile.delete(); if (parentFile.listFiles().length == 0 && !id.startsWith(UNCATEGORIZED_PREFIX)) { parentFile.delete(); } } catch (Exception e) { throw new ContentStorageException("Error while deleting content", e); } }