List of usage examples for com.liferay.portal.kernel.service ServiceContextFactory getInstance
public static ServiceContext getInstance(String className, UploadPortletRequest uploadPortletRequest) throws PortalException
From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsAdminPortlet.java
License:Apache License
public void updateFtpSubscription(final ActionRequest request, final ActionResponse response) throws PortalException, SystemException { final ArrayList<String> errors = new ArrayList<>(); final ServiceContext serviceContext = ServiceContextFactory.getInstance(FtpSubscription.class.getName(), request);// w w w . j av a 2 s . com long ftpSubscriptionId = ParamUtil.getLong(request, "ftpSubscriptionId"); FtpSubscription ftpSubscriptionFromRequest = ftpSubscriptionFromRequest(request); if (!FtpSubscriptionValidator.validate(request, errors)) { for (final String error : errors) { SessionErrors.add(request, error); } request.setAttribute(DatafeedsPortletKeys.FTP_SUBSCRIPTION_ENTRY, ftpSubscriptionFromRequest); response.setRenderParameter("jspPage", editFtpSubscriptionJSP); return; } if (ftpSubscriptionId > 0) { // Updating try { FtpSubscription ftp = _ftpSubscriptionLocalService.getFtpSubscription(ftpSubscriptionId); if (ftp != null) { ftp.setModifiedDate(new Date()); ftp.setFtpHost(ParamUtil.getString(request, "ftpHost")); ftp.setFtpUser(ParamUtil.getString(request, "ftpUser")); ftp.setFtpPassword(ParamUtil.getString(request, "ftpPassword")); ftp.setFtpFolder(ParamUtil.getString(request, "ftpFolder")); ftp.setFtpDatafeedName(ParamUtil.getString(request, "ftpDatafeedName")); ftp.setFtpFile(ParamUtil.getString(request, "ftpFile")); ftp.setFtpDatafeedDescription(ParamUtil.getString(request, "ftpDatafeedDescription")); _ftpSubscriptionLocalService.updateFtpSubscription(ftp); SessionMessages.add(request, "ftp-subscription-added"); } } catch (final PortalException e) { errors.add("failed-to-update"); } catch (final SystemException e) { errors.add("failed-to-update"); } } else { // Adding try { _ftpSubscriptionLocalService.addFtpSubscription(ftpSubscriptionFromRequest, ftpSubscriptionFromRequest.getUserId(), serviceContext); } catch (final SystemException e) { errors.add("failed-to-add"); } } // response.setRenderParameter("jspPage", "/html/view2.jsp"); }
From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsPortlet.java
License:Apache License
protected MBMessage updateMessage(final ActionRequest actionRequest) throws Exception { final ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); final String className = ParamUtil.getString(actionRequest, "className"); final long classPK = ParamUtil.getLong(actionRequest, "classPK"); final String permissionClassName = ParamUtil.getString(actionRequest, "permissionClassName"); final long permissionClassPK = ParamUtil.getLong(actionRequest, "permissionClassPK"); final long permissionOwnerId = ParamUtil.getLong(actionRequest, "permissionOwnerId"); final long messageId = ParamUtil.getLong(actionRequest, "messageId"); final long threadId = ParamUtil.getLong(actionRequest, "threadId"); final long parentMessageId = ParamUtil.getLong(actionRequest, "parentMessageId"); final String subject = ParamUtil.getString(actionRequest, "subject"); final String body = ParamUtil.getString(actionRequest, "body"); final ServiceContext serviceContext = ServiceContextFactory.getInstance(MBMessage.class.getName(), actionRequest);//from w w w.j a v a2 s. c om final MBMessage message = null; /* * if (messageId <= 0) { message = * MBMessageServiceUtil.addDiscussionMessage( * serviceContext.getScopeGroupId(), className, classPK, * permissionClassName, permissionClassPK, permissionOwnerId, threadId, * parentMessageId, subject, body, serviceContext); } else { message = * MBMessageServiceUtil.updateDiscussionMessage( className, classPK, * permissionClassName, permissionClassPK, permissionOwnerId, messageId, * subject, body, serviceContext); } */ // Subscription final boolean subscribe = ParamUtil.getBoolean(actionRequest, "subscribe"); if (subscribe) { SubscriptionLocalServiceUtil.addSubscription(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), className, classPK); } return message; }
From source file:ch.inofix.referencemanager.web.internal.portlet.ReferenceManagerPortlet.java
License:Apache License
/** * // www.j ava 2 s. c o m * @param actionRequest * @param actionResponse * @since 1.0.0 * @throws Exception */ public void importBibTeXFile(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); File file = uploadPortletRequest.getFile("file"); String fileName = file.getName(); long userId = themeDisplay.getUserId(); long groupId = themeDisplay.getScopeGroupId(); boolean privateLayout = themeDisplay.getLayout().isPrivateLayout(); String servletContextName = request.getSession().getServletContext().getServletContextName(); String[] servletContextNames = new String[] { servletContextName }; Map<String, String[]> parameterMap = new HashMap<String, String[]>(actionRequest.getParameterMap()); parameterMap.put("servletContextNames", servletContextNames); if (Validator.isNotNull(file)) { String message = PortletUtil.translate("upload-successfull-import-will-finish-in-a-separate-thread"); ServiceContext serviceContext = ServiceContextFactory.getInstance(Reference.class.getName(), uploadPortletRequest); _referenceService.importReferencesInBackground(userId, fileName, groupId, privateLayout, parameterMap, file, serviceContext); SessionMessages.add(actionRequest, "request_processed", message); } else { SessionErrors.add(actionRequest, "file-not-found"); } }
From source file:ch.inofix.referencemanager.web.internal.portlet.ReferenceManagerPortlet.java
License:Apache License
/** * //from ww w . j a v a 2s. c om * @param actionRequest * @param actionResponse * @since 1.0.8 * @throws Exception */ protected void deleteGroupReferences(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String tabs1 = ParamUtil.getString(actionRequest, "tabs1"); ServiceContext serviceContext = ServiceContextFactory.getInstance(Reference.class.getName(), actionRequest); List<Reference> references = _referenceService.deleteGroupReferences(serviceContext.getScopeGroupId()); SessionMessages.add(actionRequest, REQUEST_PROCESSED, PortletUtil.translate("successfully-deleted-x-references", references.size())); actionResponse.setRenderParameter("tabs1", tabs1); }
From source file:com.liferay.asset.categories.admin.web.internal.portlet.AssetCategoryAdminPortlet.java
License:Open Source License
public void editCategory(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long categoryId = ParamUtil.getLong(actionRequest, "categoryId"); long parentCategoryId = ParamUtil.getLong(actionRequest, "parentCategoryId"); Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title"); Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description"); long vocabularyId = ParamUtil.getLong(actionRequest, "vocabularyId"); ServiceContext serviceContext = ServiceContextFactory.getInstance(AssetCategory.class.getName(), actionRequest);/*www .j a v a 2s .co m*/ if (categoryId <= 0) { // Add category _assetCategoryService.addCategory(serviceContext.getScopeGroupId(), parentCategoryId, titleMap, descriptionMap, vocabularyId, null, serviceContext); } else { // Update category List<AssetCategoryProperty> categoryProperties = _assetCategoryPropertyLocalService .getCategoryProperties(categoryId); String[] categoryPropertiesArray = getCategoryProperties(categoryProperties); _assetCategoryService.updateCategory(categoryId, parentCategoryId, titleMap, descriptionMap, vocabularyId, categoryPropertiesArray, serviceContext); } }
From source file:com.liferay.asset.categories.admin.web.internal.portlet.AssetCategoryAdminPortlet.java
License:Open Source License
public void editProperties(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long categoryId = ParamUtil.getLong(actionRequest, "categoryId", 0); AssetCategory category = _assetCategoryService.fetchCategory(categoryId); String[] categoryProperties = getCategoryProperties(actionRequest); ServiceContext serviceContext = ServiceContextFactory.getInstance(AssetCategory.class.getName(), actionRequest);/* ww w .j a v a2 s . com*/ _assetCategoryService.updateCategory(categoryId, category.getParentCategoryId(), category.getTitleMap(), category.getDescriptionMap(), category.getVocabularyId(), categoryProperties, serviceContext); }
From source file:com.liferay.asset.categories.admin.web.internal.portlet.AssetCategoryAdminPortlet.java
License:Open Source License
public void editVocabulary(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long vocabularyId = ParamUtil.getLong(actionRequest, "vocabularyId"); Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title"); Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description"); ServiceContext serviceContext = ServiceContextFactory.getInstance(AssetVocabulary.class.getName(), actionRequest);/*from ww w . j av a 2 s .c om*/ if (vocabularyId <= 0) { // Add vocabulary _assetVocabularyService.addVocabulary(serviceContext.getScopeGroupId(), StringPool.BLANK, titleMap, descriptionMap, getSettings(actionRequest), serviceContext); } else { // Update vocabulary _assetVocabularyService.updateVocabulary(vocabularyId, StringPool.BLANK, titleMap, descriptionMap, getSettings(actionRequest), serviceContext); } }
From source file:com.liferay.asset.categories.admin.web.internal.portlet.AssetCategoryAdminPortlet.java
License:Open Source License
public void moveCategory(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long categoryId = ParamUtil.getLong(actionRequest, "categoryId"); long parentCategoryId = ParamUtil.getLong(actionRequest, "parentCategoryId"); long vocabularyId = ParamUtil.getLong(actionRequest, "vocabularyId"); if ((vocabularyId <= 0) && (parentCategoryId <= 0)) { throw new NoSuchVocabularyException(); }//from www . j av a 2s .c o m if (vocabularyId <= 0) { AssetCategory parentCategory = _assetCategoryService.fetchCategory(parentCategoryId); vocabularyId = parentCategory.getVocabularyId(); } ServiceContext serviceContext = ServiceContextFactory.getInstance(AssetCategory.class.getName(), actionRequest); _assetCategoryService.moveCategory(categoryId, parentCategoryId, vocabularyId, serviceContext); }
From source file:com.liferay.asset.tags.admin.web.internal.portlet.AssetTagsAdminPortlet.java
License:Open Source License
public void editTag(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long tagId = ParamUtil.getLong(actionRequest, "tagId"); String name = ParamUtil.getString(actionRequest, "name"); ServiceContext serviceContext = ServiceContextFactory.getInstance(AssetTag.class.getName(), actionRequest); if (tagId <= 0) { // Add tag _assetTagService.addTag(serviceContext.getScopeGroupId(), name, serviceContext); } else {//from w w w . java 2 s .c o m // Update tag _assetTagService.updateTag(tagId, name, serviceContext); } }
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 a 2s . c o 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 }; }