Example usage for com.liferay.portal.kernel.service ServiceContext getPortalURL

List of usage examples for com.liferay.portal.kernel.service ServiceContext getPortalURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ServiceContext getPortalURL.

Prototype

public String getPortalURL() 

Source Link

Document

Returns the URL of this service context's portal, including the protocol, domain, and non-default port relative to the company instance and any virtual host.

Usage

From source file:com.liferay.document.library.web.internal.social.DLFileEntryActivityInterpreter.java

License:Open Source License

protected String getFolderLink(FileEntry fileEntry, ServiceContext serviceContext) {

    StringBundler sb = new StringBundler(6);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/find_folder?groupId=");
    sb.append(fileEntry.getRepositoryId());
    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());/*from   ww w  .  ja  v  a  2  s . c  om*/

    return sb.toString();
}

From source file:com.liferay.invitation.invite.members.service.impl.MemberRequestLocalServiceImpl.java

License:Open Source License

protected String getCreateAccountURL(MemberRequest memberRequest, ServiceContext serviceContext)
        throws PortalException {

    String createAccountURL = (String) serviceContext.getAttribute("createAccountURL");

    if (Validator.isNull(createAccountURL)) {
        createAccountURL = serviceContext.getPortalURL();
    }/*from www  .  j  av a 2  s . c o  m*/

    if (!workflowDefinitionLinkLocalService.hasWorkflowDefinitionLink(memberRequest.getCompanyId(),
            WorkflowConstants.DEFAULT_GROUP_ID, User.class.getName(), 0)) {

        String redirectURL = getRedirectURL(serviceContext);

        redirectURL = addParameterWithPortletNamespace(redirectURL, "key", memberRequest.getKey());

        createAccountURL = addParameterWithPortletNamespace(createAccountURL, "redirect", redirectURL);
    }

    return createAccountURL;
}

From source file:com.liferay.invitation.invite.members.service.impl.MemberRequestLocalServiceImpl.java

License:Open Source License

protected String getLoginURL(MemberRequest memberRequest, ServiceContext serviceContext) {

    String loginURL = (String) serviceContext.getAttribute("loginURL");

    if (Validator.isNull(loginURL)) {
        loginURL = serviceContext.getPortalURL();
    }// w  ww.jav a2 s . c o m

    String redirectURL = getRedirectURL(serviceContext);

    redirectURL = addParameterWithPortletNamespace(redirectURL, "key", memberRequest.getKey());

    return HttpUtil.addParameter(loginURL, "redirect", redirectURL);
}

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   www  . ja  v  a  2  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 void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext)
        throws PortalException {

    if (!page.isApproved() || Validator.isNull(pageURL)) {
        return;/*from   w  ww.  j av  a 2  s  .  co 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.message.boards.web.internal.social.MBMessageActivityInterpreter.java

License:Open Source License

@Override
protected String getBody(SocialActivity activity, ServiceContext serviceContext) throws Exception {

    MBMessage message = _mbMessageLocalService.getMessage(activity.getClassPK());

    if (message.getCategoryId() <= 0) {
        return StringPool.BLANK;
    }//from w  ww .  ja  v a  2  s. co  m

    StringBundler sb = new StringBundler(4);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/message_boards/find_category?mbCategoryId=");
    sb.append(message.getCategoryId());

    String categoryLink = sb.toString();

    categoryLink = addNoSuchEntryRedirect(categoryLink, MBCategory.class.getName(), message.getCategoryId(),
            serviceContext);

    return wrapLink(categoryLink, "go-to-category", serviceContext);
}

From source file:com.liferay.message.boards.web.internal.social.MBThreadActivityInterpreter.java

License:Open Source License

@Override
protected String getBody(SocialActivity activity, ServiceContext serviceContext) throws Exception {

    MBMessage message = getMessage(activity);

    if (message.getCategoryId() <= 0) {
        return StringPool.BLANK;
    }/* ww  w. j a v  a 2  s .c om*/

    StringBundler sb = new StringBundler(4);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/message_boards/find_category?mbCategoryId=");
    sb.append(message.getCategoryId());

    String categoryLink = sb.toString();

    categoryLink = addNoSuchEntryRedirect(categoryLink, MBCategory.class.getName(), message.getCategoryId(),
            serviceContext);

    return wrapLink(categoryLink, "go-to-category", serviceContext);
}

From source file:com.liferay.recommend.service.impl.RecommendEntityLocalServiceImpl.java

License:Open Source License

/**
 * NOTE FOR DEVELOPERS://  ww  w  .j av a  2  s. co m
 *
 * Never reference this class directly. Always use {@link com.liferay.recommend.service.RecommendEntityLocalServiceUtil} to access the recommend entity local service.
 */
private JSONArray _createJsonArrayFromWikiPageAssetEntries(ServiceContext serviceContext,
        List<AssetEntry> topViewedEntries) {

    JSONArray recommendationsJSONArray = JSONFactoryUtil.createJSONArray();

    WikiTextExtractor wikiTextExtractor = new WikiTextExtractor();

    wikiTextExtractor.setTitleSeparator("|");

    for (AssetEntry assetEntry : topViewedEntries) {
        if (_log.isDebugEnabled()) {
            _log.debug("Top Entry: " + assetEntry);
        }

        AssetRenderer<?> assetRenderer = assetEntry.getAssetRenderer();

        if ((assetRenderer != null) && (assetRenderer.getAssetObject() instanceof WikiPage)) {

            WikiPage wikiPage = (WikiPage) assetRenderer.getAssetObject();

            String userPortraitUrl = null;

            try {
                ThemeDisplay themeDisplay = new ThemeDisplay();

                User user = _userLocalService.fetchUser(assetEntry.getUserId());

                userPortraitUrl = user.getPortraitURL(themeDisplay);
            } catch (PortalException pe) {
                _log.error("Error while retrieving user portrait URL", pe);
            }

            String url = serviceContext.getPortalURL() + "/share/" + _getNormalizedTitle(assetEntry.getTitle());

            JSONObject entryJSONObject = JSONFactoryUtil.createJSONObject();

            entryJSONObject.put("id", assetEntry.getClassPK());

            entryJSONObject.put("userName", assetEntry.getUserName());

            entryJSONObject.put("viewCount", assetEntry.getViewCount());

            entryJSONObject.put("title", assetEntry.getTitle());

            entryJSONObject.put("contentSample",
                    wikiTextExtractor.truncateWikiContent(wikiPage.getContent(), wikiPage.getFormat(), 1000));

            entryJSONObject.put("url", url);

            entryJSONObject.put("userPortraitUrl", userPortraitUrl);

            recommendationsJSONArray.put(entryJSONObject);
        }
    }

    return recommendationsJSONArray;
}

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;/*from w  w  w  .  j a  v a 2  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();
}