List of usage examples for com.liferay.portal.kernel.service ServiceContext getPlid
public long getPlid()
From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java
License:Open Source License
@Override protected void doReceive(Message message) throws Exception { FlagsRequest flagsRequest = (FlagsRequest) message.getPayload(); // Service context ServiceContext serviceContext = flagsRequest.getServiceContext(); // Company//from www . j a va 2 s . com long companyId = serviceContext.getCompanyId(); Company company = _companyLocalService.getCompany(serviceContext.getCompanyId()); // Group Layout layout = _layoutLocalService.getLayout(serviceContext.getPlid()); Group group = layout.getGroup(); // Reporter user String reporterUserName = null; String reporterEmailAddress = null; User reporterUser = _userLocalService.getUserById(serviceContext.getUserId()); Locale locale = LocaleUtil.getDefault(); if (reporterUser.isDefaultUser()) { reporterUserName = LanguageUtil.get(locale, "anonymous"); } else { reporterUserName = reporterUser.getFullName(); reporterEmailAddress = reporterUser.getEmailAddress(); } // Reported user String reportedUserName = StringPool.BLANK; String reportedEmailAddress = StringPool.BLANK; String reportedURL = StringPool.BLANK; User reportedUser = _userLocalService.getUserById(flagsRequest.getReportedUserId()); if (reportedUser.isDefaultUser()) { reportedUserName = group.getDescriptiveName(); } else { reportedUserName = reportedUser.getFullName(); reportedEmailAddress = reportedUser.getEmailAddress(); reportedURL = reportedUser.getDisplayURL(serviceContext.getThemeDisplay()); } // Content String contentType = ResourceActionsUtil.getModelResource(locale, flagsRequest.getClassName()); // Reason String reason = LanguageUtil.get(locale, flagsRequest.getReason()); // Email FlagsGroupServiceConfiguration flagsGroupServiceConfiguration = ConfigurationProviderUtil .getCompanyConfiguration(FlagsGroupServiceConfiguration.class, companyId); String fromName = flagsGroupServiceConfiguration.emailFromName(); String fromAddress = flagsGroupServiceConfiguration.emailFromAddress(); String subject = ContentUtil.get(FlagsRequestMessageListener.class.getClassLoader(), flagsGroupServiceConfiguration.emailSubject()); String body = ContentUtil.get(FlagsRequestMessageListener.class.getClassLoader(), flagsGroupServiceConfiguration.emailBody()); // Recipients Set<User> recipients = getRecipients(companyId, serviceContext.getScopeGroupId()); for (User recipient : recipients) { try { notify(reporterUser.getUserId(), company, group, reporterEmailAddress, reporterUserName, reportedEmailAddress, reportedUserName, reportedURL, flagsRequest.getClassPK(), flagsRequest.getContentTitle(), contentType, flagsRequest.getContentURL(), reason, fromName, fromAddress, recipient.getFullName(), recipient.getEmailAddress(), subject, body, serviceContext); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe); } } } }
From source file:com.liferay.mentions.internal.service.MentionsWikiPageServiceWrapper.java
License:Open Source License
@Override public WikiPage updateStatus(long userId, WikiPage page, int status, ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws PortalException { int oldStatus = page.getStatus(); page = super.updateStatus(userId, page, status, serviceContext, workflowContext); WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = _configurationProvider .getConfiguration(WikiGroupServiceOverriddenConfiguration.class, new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME)); // Subscriptions if (status == WorkflowConstants.STATUS_APPROVED) { if (NotificationThreadLocal.isEnabled() && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditSendEmail())) { notifySubscribers(userId, page, (String) workflowContext.get(WorkflowConstants.CONTEXT_URL), serviceContext);//from ww w .ja v a2 s . c o m } } if ((status != WorkflowConstants.STATUS_APPROVED) || (oldStatus == WorkflowConstants.STATUS_IN_TRASH)) { return page; } long siteGroupId = PortalUtil.getSiteGroupId(page.getGroupId()); if (!MentionsUtil.isMentionsEnabled(siteGroupId)) { return page; } String contentURL = (String) serviceContext.getAttribute("contentURL"); if (Validator.isNull(contentURL)) { serviceContext.setAttribute("contentURL", workflowContext.get("url")); } String portalURL = serviceContext.getPortalURL(); String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(), serviceContext.getPlid(), page.getNodeId(), page.getTitle()); attachmentURLPrefix = portalURL + attachmentURLPrefix; String pageContent = _wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix); MentionsGroupServiceConfiguration mentionsGroupServiceConfiguration = _configurationProvider .getCompanyConfiguration(MentionsGroupServiceConfiguration.class, page.getCompanyId()); _mentionsNotifier.notify(page.getUserId(), page.getGroupId(), page.getTitle(), pageContent, WikiPage.class.getName(), page.getPageId(), mentionsGroupServiceConfiguration.assetEntryMentionEmailSubject(), mentionsGroupServiceConfiguration.assetEntryMentionEmailBody(), serviceContext); return page; }
From source file:com.liferay.mentions.internal.service.MentionsWikiPageServiceWrapper.java
License:Open Source License
protected String getDiffsURL(WikiPage page, WikiPage previousVersionPage, ServiceContext serviceContext) throws PortalException { if (previousVersionPage == null) { return StringPool.BLANK; }//from w ww. ja va 2 s .co m HttpServletRequest request = serviceContext.getRequest(); if (request == null) { return StringPool.BLANK; } PortletURL portletURL = null; long plid = serviceContext.getPlid(); if (plid == LayoutConstants.DEFAULT_PLID) { portletURL = PortalUtil.getControlPanelPortletURL(request, WikiPortletKeys.WIKI_ADMIN, PortletRequest.RENDER_PHASE); } else { portletURL = PortletURLFactoryUtil.create(request, WikiConstants.SERVICE_NAME, plid, PortletRequest.RENDER_PHASE); } portletURL.setParameter("mvcRenderCommandName", "/wiki/compare_versions"); portletURL.setParameter("nodeId", String.valueOf(page.getNodeId())); portletURL.setParameter("title", page.getTitle()); portletURL.setParameter("sourceVersion", String.valueOf(previousVersionPage.getVersion())); portletURL.setParameter("targetVersion", String.valueOf(page.getVersion())); portletURL.setParameter("type", "html"); return portletURL.toString(); }
From source file:com.liferay.mentions.internal.service.MentionsWikiPageServiceWrapper.java
License:Open Source License
protected void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext) throws PortalException { if (!page.isApproved() || Validator.isNull(pageURL)) { return;/*from ww w. j a v a 2s .c o m*/ } WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = _configurationProvider .getConfiguration(WikiGroupServiceOverriddenConfiguration.class, new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME)); boolean update = false; if (page.getVersion() > WikiPageConstants.VERSION_DEFAULT) { update = true; } if (!update && wikiGroupServiceOverriddenConfiguration.emailPageAddedEnabled()) { } else if (update && wikiGroupServiceOverriddenConfiguration.emailPageUpdatedEnabled()) { } else { return; } String portalURL = serviceContext.getPortalURL(); WikiPage previousVersionPage = getPreviousVersionPage(page); String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(), serviceContext.getPlid(), page.getNodeId(), page.getTitle()); attachmentURLPrefix = portalURL + attachmentURLPrefix; String pageDiffs = StringPool.BLANK; try { pageDiffs = _wikiEngineRenderer.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix); } catch (Exception e) { } String pageContent = null; if (Objects.equals(page.getFormat(), "creole")) { pageContent = _wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix); } else { pageContent = page.getContent(); pageContent = WikiUtil.processContent(pageContent); } String pageTitle = page.getTitle(); String fromName = wikiGroupServiceOverriddenConfiguration.emailFromName(); String fromAddress = wikiGroupServiceOverriddenConfiguration.emailFromAddress(); LocalizedValuesMap subjectLocalizedValuesMap = null; LocalizedValuesMap bodyLocalizedValuesMap = null; if (update) { subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedSubject(); bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedBody(); } else { subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedSubject(); bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedBody(); } SubscriptionSender subscriptionSender = new SubscriptionSender(); subscriptionSender.setClassName(page.getModelClassName()); subscriptionSender.setClassPK(page.getPageId()); subscriptionSender.setCompanyId(page.getCompanyId()); subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false); subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", DiffHtmlUtil.replaceStyles(pageDiffs), false); WikiNode node = page.getNode(); subscriptionSender.setContextAttributes("[$DIFFS_URL$]", getDiffsURL(page, previousVersionPage, serviceContext), "[$NODE_NAME$]", node.getName(), "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]", page.getSummary(), "[$PAGE_TITLE$]", pageTitle, "[$PAGE_URL$]", pageURL); subscriptionSender.setContextCreatorUserPrefix("PAGE"); subscriptionSender.setCreatorUserId(page.getUserId()); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(pageTitle); subscriptionSender.setEntryURL(pageURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); if (bodyLocalizedValuesMap != null) { subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap)); } if (subjectLocalizedValuesMap != null) { subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap)); } subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId()); int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (update) { notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } subscriptionSender.setNotificationType(notificationType); subscriptionSender.setPortletId(WikiPortletKeys.WIKI); subscriptionSender.setReplyToAddress(fromAddress); subscriptionSender.setScopeGroupId(page.getGroupId()); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.addPersistedSubscribers(User.class.getName(), userId); subscriptionSender.flushNotificationsAsync(); }
From source file:com.liferay.social.activity.customizer.interpreter.CustomWikiActivityInterpreter.java
License:Open Source License
protected String getAttachmentTitle(SocialActivity activity, WikiPageResource pageResource, ServiceContext serviceContext) throws Exception { int activityType = activity.getType(); if ((activityType == SocialActivityConstants.TYPE_ADD_ATTACHMENT) || (activityType == SocialActivityConstants.TYPE_MOVE_ATTACHMENT_TO_TRASH) || (activityType == SocialActivityConstants.TYPE_RESTORE_ATTACHMENT_FROM_TRASH)) { String link = null;/*from ww w.java 2 s .co m*/ FileEntry fileEntry = null; try { long fileEntryId = GetterUtil.getLong(activity.getExtraDataValue("fileEntryId")); fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId); } catch (NoSuchModelException nsme) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsme, nsme); } } String fileEntryTitle = activity.getExtraDataValue("fileEntryTitle"); if ((fileEntry != null) && !fileEntry.isInTrash()) { StringBundler sb = new StringBundler(9); sb.append(serviceContext.getPathMain()); sb.append("/wiki/get_page_attachment?p_l_id="); sb.append(serviceContext.getPlid()); sb.append("&nodeId="); sb.append(pageResource.getNodeId()); sb.append("&title="); sb.append(URLCodec.encodeURL(pageResource.getTitle())); sb.append("&fileName="); sb.append(fileEntryTitle); link = sb.toString(); } return wrapLink(link, fileEntryTitle); } return StringPool.BLANK; }
From source file:com.liferay.wiki.internal.service.WikiPageCustomServiceWrapper.java
License:Open Source License
protected String getDiffsURL(WikiPage page, WikiPage previousVersionPage, ServiceContext serviceContext) throws PortalException { if (previousVersionPage == null) { return StringPool.BLANK; }//from w w w . j a v a 2s .c o m HttpServletRequest request = serviceContext.getRequest(); if (request == null) { return StringPool.BLANK; } PortletURL portletURL = null; long plid = serviceContext.getPlid(); if (plid == LayoutConstants.DEFAULT_PLID) { portletURL = PortalUtil.getControlPanelPortletURL(request, WikiPortletKeys.WIKI_ADMIN, PortletRequest.RENDER_PHASE); } else { portletURL = PortletURLFactoryUtil.create(request, WikiPortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE); } portletURL.setParameter("mvcRenderCommandName", "/wiki/compare_versions"); portletURL.setParameter("nodeId", String.valueOf(page.getNodeId())); portletURL.setParameter("title", page.getTitle()); portletURL.setParameter("sourceVersion", String.valueOf(previousVersionPage.getVersion())); portletURL.setParameter("targetVersion", String.valueOf(page.getVersion())); portletURL.setParameter("type", "html"); return portletURL.toString(); }
From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java
License:Open Source License
protected void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext) throws PortalException { if (!page.isApproved() || Validator.isNull(pageURL)) { return;/* ww w . jav a2 s . c o m*/ } WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = configurationProvider .getConfiguration(WikiGroupServiceOverriddenConfiguration.class, new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME)); boolean update = false; if (page.getVersion() > WikiPageConstants.VERSION_DEFAULT) { update = true; } if (!update && wikiGroupServiceOverriddenConfiguration.emailPageAddedEnabled()) { } else if (update && wikiGroupServiceOverriddenConfiguration.emailPageUpdatedEnabled()) { } else { return; } String portalURL = serviceContext.getPortalURL(); WikiPage previousVersionPage = getPreviousVersionPage(page); String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(), serviceContext.getPlid(), page.getNodeId(), page.getTitle()); attachmentURLPrefix = portalURL + attachmentURLPrefix; String pageDiffs = StringPool.BLANK; try { pageDiffs = wikiEngineRenderer.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix); } catch (Exception e) { } String pageContent = null; if (Objects.equals(page.getFormat(), "creole")) { pageContent = wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix); } else { pageContent = page.getContent(); pageContent = WikiUtil.processContent(pageContent); } String pageTitle = page.getTitle(); String fromName = wikiGroupServiceOverriddenConfiguration.emailFromName(); String fromAddress = wikiGroupServiceOverriddenConfiguration.emailFromAddress(); LocalizedValuesMap subjectLocalizedValuesMap = null; LocalizedValuesMap bodyLocalizedValuesMap = null; if (update) { subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedSubject(); bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedBody(); } else { subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedSubject(); bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedBody(); } SubscriptionSender subscriptionSender = new SubscriptionSender(); subscriptionSender.setClassName(page.getModelClassName()); subscriptionSender.setClassPK(page.getPageId()); subscriptionSender.setCompanyId(page.getCompanyId()); subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false); subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", DiffHtmlUtil.replaceStyles(pageDiffs), false); WikiNode node = page.getNode(); subscriptionSender.setContextAttributes("[$DIFFS_URL$]", getDiffsURL(page, previousVersionPage, serviceContext), "[$NODE_NAME$]", node.getName(), "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]", page.getSummary(), "[$PAGE_TITLE$]", pageTitle, "[$PAGE_URL$]", pageURL); subscriptionSender.setContextCreatorUserPrefix("PAGE"); subscriptionSender.setCreatorUserId(page.getUserId()); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(pageTitle); subscriptionSender.setEntryURL(pageURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); if (bodyLocalizedValuesMap != null) { subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap)); } if (subjectLocalizedValuesMap != null) { subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap)); } subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId()); int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (update) { notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } subscriptionSender.setNotificationType(notificationType); subscriptionSender.setPortletId(WikiPortletKeys.WIKI); subscriptionSender.setReplyToAddress(fromAddress); subscriptionSender.setScopeGroupId(page.getGroupId()); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.addPersistedSubscribers(WikiNode.class.getName(), page.getNodeId()); subscriptionSender.addPersistedSubscribers(WikiPage.class.getName(), page.getResourcePrimKey()); subscriptionSender.flushNotificationsAsync(); }
From source file:com.liferay.wiki.web.internal.social.WikiActivityInterpreter.java
License:Open Source License
protected String getAttachmentTitle(SocialActivity activity, WikiPageResource pageResource, ServiceContext serviceContext) throws Exception { int activityType = activity.getType(); if ((activityType == SocialActivityConstants.TYPE_ADD_ATTACHMENT) || (activityType == SocialActivityConstants.TYPE_MOVE_ATTACHMENT_TO_TRASH) || (activityType == SocialActivityConstants.TYPE_RESTORE_ATTACHMENT_FROM_TRASH)) { String link = null;// w w w.j a v a2 s.c o m FileEntry fileEntry = null; try { long fileEntryId = GetterUtil.getLong(activity.getExtraDataValue("fileEntryId")); fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId); } catch (NoSuchModelException nsme) { } String fileEntryTitle = activity.getExtraDataValue("fileEntryTitle"); if ((fileEntry != null) && !fileEntry.isInTrash()) { StringBundler sb = new StringBundler(9); sb.append(serviceContext.getPathMain()); sb.append("/wiki/get_page_attachment?p_l_id="); sb.append(serviceContext.getPlid()); sb.append("&nodeId="); sb.append(pageResource.getNodeId()); sb.append("&title="); sb.append(HttpUtil.encodeURL(pageResource.getTitle())); sb.append("&fileName="); sb.append(fileEntryTitle); link = sb.toString(); } return wrapLink(link, fileEntryTitle); } return StringPool.BLANK; }