List of usage examples for com.liferay.portal.kernel.repository.model Folder getFolderId
public long getFolderId();
From source file:com.liferay.adaptive.media.demo.internal.AMImageDemo.java
License:Open Source License
@Override public void portalInstanceRegistered(Company company) throws Exception { User user = _omniAdminUserDemoDataCreator.create(company.getCompanyId(), "alejandro.hernandez@liferay.com"); Group guestGroup = _groupLocalService.getGroup(company.getCompanyId(), "Guest"); Folder nonAMFolder = _rootFolderDemoDataCreator.create(user.getUserId(), guestGroup.getGroupId(), "Non Adaptive Media"); for (int i = 0; i < 5; i++) { FileEntry fileEntry = _fileEntryDemoDataCreator.create(user.getUserId(), nonAMFolder.getFolderId()); if (_log.isInfoEnabled()) { _log.info("Non adaptive media image created with file entry " + fileEntry.getFileEntryId()); }//from w w w . j a v a2 s. c om } _amImageConfigurationDemoDataCreator.create(company.getCompanyId()); Folder amFolder = _rootFolderDemoDataCreator.create(user.getUserId(), guestGroup.getGroupId(), "Adaptive Media"); for (int i = 0; i < 5; i++) { FileEntry fileEntry = _fileEntryDemoDataCreator.create(user.getUserId(), amFolder.getFolderId()); if (_log.isInfoEnabled()) { _log.info("Adaptive media image created with file entry " + fileEntry.getFileEntryId()); } } }
From source file:com.liferay.announcements.uad.exporter.AnnouncementsEntryUADEntityExporter.java
License:Open Source License
@Override public void export(UADEntity uadEntity) throws PortalException { AnnouncementsEntry announcementsEntry = _getAnnouncementsEntry(uadEntity); String json = getJSON(announcementsEntry); Folder folder = getFolder(announcementsEntry.getCompanyId(), AnnouncementsPortletKeys.ANNOUNCEMENTS, _FOLDER_NAME);/*w w w . j ava2 s .c om*/ try { InputStream is = new UnsyncByteArrayInputStream(json.getBytes(StringPool.UTF8)); PortletFileRepositoryUtil.addPortletFileEntry(folder.getGroupId(), announcementsEntry.getUserId(), Group.class.getName(), folder.getGroupId(), AnnouncementsPortletKeys.ANNOUNCEMENTS, folder.getFolderId(), is, uadEntity.getUADEntityId() + ".json", ContentTypes.APPLICATION_JSON, false); } catch (UnsupportedEncodingException uee) { throw new UADEntityExporterException(uee); } }
From source file:com.liferay.announcements.uad.exporter.AnnouncementsFlagUADEntityExporter.java
License:Open Source License
@Override public void export(UADEntity uadEntity) throws PortalException { AnnouncementsFlag announcementsFlag = _getAnnouncementsFlag(uadEntity); String json = getJSON(announcementsFlag); Folder folder = getFolder(announcementsFlag.getCompanyId(), AnnouncementsPortletKeys.ANNOUNCEMENTS, _FOLDER_NAME);/*from w ww.j a v a2 s.c om*/ try { InputStream is = new UnsyncByteArrayInputStream(json.getBytes(StringPool.UTF8)); PortletFileRepositoryUtil.addPortletFileEntry(folder.getGroupId(), announcementsFlag.getUserId(), Group.class.getName(), folder.getGroupId(), AnnouncementsPortletKeys.ANNOUNCEMENTS, folder.getFolderId(), is, uadEntity.getUADEntityId() + ".json", ContentTypes.APPLICATION_JSON, false); } catch (UnsupportedEncodingException uee) { throw new UADEntityExporterException(uee); } }
From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsEntryUADEntityExporterTest.java
License:Open Source License
private FileEntry _getFileEntry(long companyId, String uadEntityId) throws Exception { Group guestGroup = _groupLocalService.getGroup(companyId, GroupConstants.GUEST); Repository repository = PortletFileRepositoryUtil.getPortletRepository(guestGroup.getGroupId(), AnnouncementsPortletKeys.ANNOUNCEMENTS); Folder folder = PortletFileRepositoryUtil.getPortletFolder(repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "UADExport"); return PortletFileRepositoryUtil.getPortletFileEntry(guestGroup.getGroupId(), folder.getFolderId(), uadEntityId + ".json"); }
From source file:com.liferay.blogs.attachments.test.BlogsEntryAttachmentFileEntryHelperTest.java
License:Open Source License
protected List<BlogsEntryAttachmentFileEntryReference> getBlogsEntryAttachmentFileEntryReferences( FileEntry tempFileEntry) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), _user.getUserId());/*w w w . jav a2 s . com*/ BlogsEntry entry = BlogsEntryLocalServiceUtil.addEntry(_user.getUserId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext); List<FileEntry> tempFileEntries = new ArrayList<>(); tempFileEntries.add(tempFileEntry); Folder folder = BlogsEntryLocalServiceUtil.addAttachmentsFolder(_user.getUserId(), _group.getGroupId()); return _blogsEntryAttachmentFileEntryHelper.addBlogsEntryAttachmentFileEntries(_group.getGroupId(), _user.getUserId(), entry.getEntryId(), folder.getFolderId(), tempFileEntries); }
From source file:com.liferay.blogs.internal.exportimport.data.handler.test.BlogsEntryStagedModelDataHandlerTest.java
License:Open Source License
private void _assertOriginalImage(FileEntry imageFileEntry) throws Exception { Folder attachmentsFolder = BlogsEntryLocalServiceUtil.addAttachmentsFolder(TestPropsValues.getUserId(), liveGroup.getGroupId());//www . ja v a 2 s . c om List<FileEntry> attachments = PortletFileRepositoryUtil.getPortletFileEntries(liveGroup.getGroupId(), attachmentsFolder.getFolderId()); Assert.assertEquals(attachments.toString(), 1, attachments.size()); FileEntry originalFileEntry = attachments.get(0); Assert.assertEquals(imageFileEntry.getFileName(), originalFileEntry.getFileName()); }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Override public long addOriginalImageFileEntry(long userId, long groupId, long entryId, ImageSelector imageSelector) throws PortalException { byte[] imageBytes = imageSelector.getImageBytes(); if (imageBytes == null) { return 0; }/*from w w w .j av a 2 s. com*/ BlogsEntryAttachmentFileEntryHelper blogsEntryAttachmentFileEntryHelper = new BlogsEntryAttachmentFileEntryHelper(); Folder folder = addAttachmentsFolder(userId, groupId); FileEntry originalFileEntry = blogsEntryAttachmentFileEntryHelper.addBlogsEntryAttachmentFileEntry(groupId, userId, entryId, folder.getFolderId(), imageSelector.getImageTitle(), imageSelector.getImageMimeType(), imageBytes); return originalFileEntry.getFileEntryId(); }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected long addCoverImageFileEntry(long userId, long groupId, long entryId, ImageSelector imageSelector) throws PortalException { byte[] imageBytes = imageSelector.getImageBytes(); if (imageBytes == null) { return 0; }/*from ww w .j a v a 2 s. c o m*/ try { ImageSelectorProcessor imageSelectorProcessor = new ImageSelectorProcessor( imageSelector.getImageBytes()); imageBytes = imageSelectorProcessor.cropImage(imageSelector.getImageCropRegion()); if (imageBytes == null) { throw new EntryCoverImageCropException(); } Folder folder = addCoverImageFolder(userId, groupId); return addProcessedImageFileEntry(userId, groupId, entryId, folder.getFolderId(), imageSelector.getImageTitle(), imageSelector.getImageMimeType(), imageBytes); } catch (IOException ioe) { throw new EntryCoverImageCropException(); } }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected long addSmallImageFileEntry(long userId, long groupId, long entryId, ImageSelector imageSelector) throws PortalException { byte[] imageBytes = imageSelector.getImageBytes(); if (imageBytes == null) { return 0; }/*from w w w . j a va 2s . c om*/ try { BlogsGroupServiceSettings blogsGroupServiceSettings = BlogsGroupServiceSettings.getInstance(groupId); ImageSelectorProcessor imageSelectorProcessor = new ImageSelectorProcessor( imageSelector.getImageBytes()); imageBytes = imageSelectorProcessor.scaleImage(blogsGroupServiceSettings.getSmallImageWidth()); if (imageBytes == null) { throw new EntrySmallImageScaleException(); } Folder folder = addSmallImageFolder(userId, groupId); return addProcessedImageFileEntry(userId, groupId, entryId, folder.getFolderId(), imageSelector.getImageTitle(), imageSelector.getImageMimeType(), imageBytes); } catch (IOException ioe) { throw new EntrySmallImageScaleException(); } }
From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java
License:Open Source License
protected Object[] updateEntry(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long entryId = ParamUtil.getLong(actionRequest, "entryId"); String title = ParamUtil.getString(actionRequest, "title"); String subtitle = ParamUtil.getString(actionRequest, "subtitle"); String urlTitle = ParamUtil.getString(actionRequest, "urlTitle"); String description = StringPool.BLANK; boolean customAbstract = ParamUtil.getBoolean(actionRequest, "customAbstract"); if (customAbstract) { description = ParamUtil.getString(actionRequest, "description"); if (Validator.isNull(description)) { throw new EntryDescriptionException(); }/*from w w w. j av a2 s.co m*/ } String content = ParamUtil.getString(actionRequest, "content"); int displayDateMonth = ParamUtil.getInteger(actionRequest, "displayDateMonth"); int displayDateDay = ParamUtil.getInteger(actionRequest, "displayDateDay"); int displayDateYear = ParamUtil.getInteger(actionRequest, "displayDateYear"); int displayDateHour = ParamUtil.getInteger(actionRequest, "displayDateHour"); int displayDateMinute = ParamUtil.getInteger(actionRequest, "displayDateMinute"); int displayDateAmPm = ParamUtil.getInteger(actionRequest, "displayDateAmPm"); if (displayDateAmPm == Calendar.PM) { displayDateHour += 12; } boolean allowPingbacks = ParamUtil.getBoolean(actionRequest, "allowPingbacks"); boolean allowTrackbacks = ParamUtil.getBoolean(actionRequest, "allowTrackbacks"); String[] trackbacks = StringUtil.split(ParamUtil.getString(actionRequest, "trackbacks")); long coverImageFileEntryId = ParamUtil.getLong(actionRequest, "coverImageFileEntryId"); String coverImageURL = ParamUtil.getString(actionRequest, "coverImageURL"); String coverImageFileEntryCropRegion = ParamUtil.getString(actionRequest, "coverImageFileEntryCropRegion"); String coverImageCaption = ParamUtil.getString(actionRequest, "coverImageCaption"); long oldCoverImageId = 0; String oldCoverImageURL = StringPool.BLANK; long oldSmallImageId = 0; String oldSmallImageURL = StringPool.BLANK; if (entryId != 0) { BlogsEntry entry = _blogsEntryLocalService.getEntry(entryId); oldCoverImageId = entry.getCoverImageFileEntryId(); oldCoverImageURL = entry.getCoverImageURL(); oldSmallImageId = entry.getSmallImageId(); oldSmallImageURL = entry.getSmallImageURL(); } BlogsEntryImageSelectorHelper blogsEntryCoverImageSelectorHelper = new BlogsEntryImageSelectorHelper( coverImageFileEntryId, oldCoverImageId, coverImageFileEntryCropRegion, coverImageURL, oldCoverImageURL); ImageSelector coverImageImageSelector = blogsEntryCoverImageSelectorHelper.getImageSelector(); long smallImageFileEntryId = ParamUtil.getLong(actionRequest, "smallImageFileEntryId"); String smallImageURL = ParamUtil.getString(actionRequest, "smallImageURL"); BlogsEntryImageSelectorHelper blogsEntrySmallImageSelectorHelper = new BlogsEntryImageSelectorHelper( smallImageFileEntryId, oldSmallImageId, StringPool.BLANK, smallImageURL, oldSmallImageURL); ImageSelector smallImageImageSelector = blogsEntrySmallImageSelectorHelper.getImageSelector(); ServiceContext serviceContext = ServiceContextFactory.getInstance(BlogsEntry.class.getName(), actionRequest); BlogsEntry entry = null; List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = new ArrayList<>(); if (entryId <= 0) { // Add entry entry = _blogsEntryService.addEntry(title, subtitle, urlTitle, description, content, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, coverImageCaption, coverImageImageSelector, smallImageImageSelector, serviceContext); BlogsEntryAttachmentFileEntryHelper blogsEntryAttachmentFileEntryHelper = new BlogsEntryAttachmentFileEntryHelper(); List<FileEntry> tempBlogsEntryAttachments = blogsEntryAttachmentFileEntryHelper .getTempBlogsEntryAttachmentFileEntries(content); if (!tempBlogsEntryAttachments.isEmpty()) { Folder folder = _blogsEntryLocalService.addAttachmentsFolder(themeDisplay.getUserId(), entry.getGroupId()); blogsEntryAttachmentFileEntryReferences = blogsEntryAttachmentFileEntryHelper .addBlogsEntryAttachmentFileEntries(entry.getGroupId(), themeDisplay.getUserId(), entry.getEntryId(), folder.getFolderId(), tempBlogsEntryAttachments); content = blogsEntryAttachmentFileEntryHelper.updateContent(content, blogsEntryAttachmentFileEntryReferences); entry.setContent(content); _blogsEntryLocalService.updateBlogsEntry(entry); } for (FileEntry tempBlogsEntryAttachment : tempBlogsEntryAttachments) { PortletFileRepositoryUtil.deletePortletFileEntry(tempBlogsEntryAttachment.getFileEntryId()); } } else { // Update entry boolean sendEmailEntryUpdated = ParamUtil.getBoolean(actionRequest, "sendEmailEntryUpdated"); serviceContext.setAttribute("sendEmailEntryUpdated", sendEmailEntryUpdated); String emailEntryUpdatedComment = ParamUtil.getString(actionRequest, "emailEntryUpdatedComment"); serviceContext.setAttribute("emailEntryUpdatedComment", emailEntryUpdatedComment); entry = _blogsEntryLocalService.getEntry(entryId); BlogsEntryAttachmentFileEntryHelper blogsEntryAttachmentHelper = new BlogsEntryAttachmentFileEntryHelper(); List<FileEntry> tempBlogsEntryAttachmentFileEntries = blogsEntryAttachmentHelper .getTempBlogsEntryAttachmentFileEntries(content); if (!tempBlogsEntryAttachmentFileEntries.isEmpty()) { Folder folder = _blogsEntryLocalService.addAttachmentsFolder(themeDisplay.getUserId(), entry.getGroupId()); blogsEntryAttachmentFileEntryReferences = blogsEntryAttachmentHelper .addBlogsEntryAttachmentFileEntries(entry.getGroupId(), themeDisplay.getUserId(), entry.getEntryId(), folder.getFolderId(), tempBlogsEntryAttachmentFileEntries); content = blogsEntryAttachmentHelper.updateContent(content, blogsEntryAttachmentFileEntryReferences); } entry = _blogsEntryService.updateEntry(entryId, title, subtitle, urlTitle, description, content, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, coverImageCaption, coverImageImageSelector, smallImageImageSelector, serviceContext); for (FileEntry tempBlogsEntryAttachmentFileEntry : tempBlogsEntryAttachmentFileEntries) { PortletFileRepositoryUtil .deletePortletFileEntry(tempBlogsEntryAttachmentFileEntry.getFileEntryId()); } } if (blogsEntryCoverImageSelectorHelper.isFileEntryTempFile()) { _blogsEntryLocalService.addOriginalImageFileEntry(themeDisplay.getUserId(), entry.getGroupId(), entry.getEntryId(), coverImageImageSelector); PortletFileRepositoryUtil.deletePortletFileEntry(coverImageFileEntryId); } if (blogsEntrySmallImageSelectorHelper.isFileEntryTempFile()) { _blogsEntryLocalService.addOriginalImageFileEntry(themeDisplay.getUserId(), entry.getGroupId(), entry.getEntryId(), smallImageImageSelector); PortletFileRepositoryUtil.deletePortletFileEntry(smallImageFileEntryId); } return new Object[] { entry, blogsEntryAttachmentFileEntryReferences }; }