public int createFileContent(CreateFileContentParams params) { validateCreateFileContentParams(params); CategoryEntity category = categoryDao.findByKey(new CategoryKey(params.categoryKey)); UserEntity runningUser = securityService.getImpersonatedPortalUser(); LegacyFileContentData contentdata = (LegacyFileContentData) fileContentResolver.resolveContentdata(params.fileContentData); List<BinaryDataAndBinary> binaryDataEntries = new ArrayList<BinaryDataAndBinary>(); binaryDataEntries.add( BinaryDataAndBinary.convertFromFileBinaryInput(params.fileContentData.binary)); CreateContentCommand createCommand = new CreateContentCommand(); createCommand.setAccessRightsStrategy( CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY); createCommand.setCreator(runningUser); createCommand.setStatus(ContentStatus.get(params.status)); createCommand.setPriority(0); createCommand.setCategory(category); createCommand.setLanguage(category.getUnitExcludeDeleted().getLanguage()); createCommand.setAvailableFrom(params.publishFrom); createCommand.setAvailableTo(params.publishTo); createCommand.setContentData(contentdata); createCommand.setContentName( new PrettyPathNameCreator(transliterate).generatePrettyPathName(contentdata.getTitle())); createCommand.setBinaryDatas(binaryDataEntries); createCommand.setUseCommandsBinaryDataToAdd(true); if (params.siteKey != null) { createCommand.setSiteKey(new SiteKey(params.siteKey)); } ContentKey contentKey = contentService.createContent(createCommand); return contentKey.toInt(); }
public int createContent(CreateContentParams params) throws ClientException { final CategoryEntity category = validateCreateContentParams(params); final CreateContentCommand command = new CreateContentCommand(); command.setPriority(0); command.setAvailableFrom(params.publishFrom); command.setAvailableTo(params.publishTo); command.setCategory(category); command.setLanguage(category.getUnitExcludeDeleted().getLanguage()); command.setStatus(ContentStatus.get(params.status)); command.setChangeComment(params.changeComment); // content data final ContentTypeEntity contentType = category.getContentType(); if (contentType == null) { throw new IllegalArgumentException( "Unable to create content in category " + category.getKey() + ". Category has no contenttype set."); } final ContentDataResolver customContentResolver = new ContentDataResolver(); final CustomContentData contentdata = customContentResolver.resolveContentdata(params.contentData, contentType); command.setContentData(contentdata); command.setContentName( new PrettyPathNameCreator(transliterate).generatePrettyPathName(contentdata.getTitle())); final List<BinaryDataAndBinary> binaryDatas = BinaryDataAndBinary.convertFromBinaryInputs(params.contentData.getBinaryInputs()); command.setBinaryDatas(binaryDatas); command.setUseCommandsBinaryDataToAdd(true); command.setAccessRightsStrategy( CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY); command.setCreator(securityService.getImpersonatedPortalUser()); if (params.siteKey != null) { command.setSiteKey(new SiteKey(params.siteKey)); } return contentService.createContent(command).toInt(); }
private CreateContentCommand createCreateContentCommand( String categoryName, ContentData contentData, String creatorUid) { CreateContentCommand createContentCommand = new CreateContentCommand(); createContentCommand.setCategory(fixture.findCategoryByName(categoryName)); createContentCommand.setCreator(fixture.findUserByName(creatorUid).getKey()); createContentCommand.setLanguage(fixture.findLanguageByCode("en")); createContentCommand.setStatus(ContentStatus.APPROVED); createContentCommand.setPriority(0); createContentCommand.setAccessRightsStrategy( CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY); createContentCommand.setContentData(contentData); createContentCommand.setAvailableFrom(DATE_TIME_2010_01_01.toDate()); createContentCommand.setAvailableTo(null); createContentCommand.setContentName("testcontent"); return createContentCommand; }