Example usage for com.liferay.portal.kernel.util NotificationThreadLocal isEnabled

List of usage examples for com.liferay.portal.kernel.util NotificationThreadLocal isEnabled

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util NotificationThreadLocal isEnabled.

Prototype

public static boolean isEnabled() 

Source Link

Usage

From source file:com.liferay.akismet.hook.service.impl.AkismetWikiPageLocalServiceImpl.java

License:Open Source License

@Override
public WikiPage addPage(long userId, long nodeId, String title, double version, String content, String summary,
        boolean minorEdit, String format, boolean head, String parentTitle, String redirectTitle,
        ServiceContext serviceContext) throws PortalException {

    int workflowAction = serviceContext.getWorkflowAction();

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
        return super.addPage(userId, nodeId, title, content, summary, minorEdit, serviceContext);
    }/*from  w  w  w  .  jav  a 2 s  .c om*/

    WikiPage page = super.addPage(userId, nodeId, title, version, content, summary, minorEdit, format, head,
            parentTitle, redirectTitle, serviceContext);

    AkismetData akismetData = updateAkismetData(page, serviceContext);

    if (!isWikiEnabled(userId, nodeId, serviceContext)) {
        return page;
    }

    String akismetContent = page.getTitle() + "\n\n" + page.getContent();

    if (!AkismetUtil.isSpam(userId, akismetContent, akismetData)) {
        return super.updateStatus(userId, page.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED,
                serviceContext);
    }

    boolean notificationEnabled = false;

    try {
        notificationEnabled = NotificationThreadLocal.isEnabled();

        NotificationThreadLocal.setEnabled(false);

        page.setSummary(AkismetConstants.WIKI_PAGE_PENDING_APPROVAL);
        page.setStatus(WorkflowConstants.STATUS_APPROVED);

        return super.updateWikiPage(page);
    } finally {
        NotificationThreadLocal.setEnabled(notificationEnabled);
    }
}

From source file:com.liferay.akismet.hook.service.impl.AkismetWikiPageLocalServiceImpl.java

License:Open Source License

@Override
public WikiPage updatePage(long userId, long nodeId, String title, double version, String content,
        String summary, boolean minorEdit, String format, String parentTitle, String redirectTitle,
        ServiceContext serviceContext) throws PortalException {

    int workflowAction = serviceContext.getWorkflowAction();

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
        return super.updatePage(userId, nodeId, title, version, content, summary, minorEdit, format,
                parentTitle, redirectTitle, serviceContext);
    }//from w w  w  . jav a  2s. co  m

    WikiPage page = super.updatePage(userId, nodeId, title, version, content, summary, minorEdit, format,
            parentTitle, redirectTitle, serviceContext);

    AkismetData akismetData = updateAkismetData(page, serviceContext);

    if (!isWikiEnabled(userId, nodeId, serviceContext)) {
        return page;
    }

    String akismetContent = page.getTitle() + "\n\n" + page.getContent();

    if (!AkismetUtil.isSpam(userId, akismetContent, akismetData)) {
        return super.updateStatus(userId, page.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED,
                serviceContext);
    }

    boolean notificationEnabled = false;

    try {
        notificationEnabled = NotificationThreadLocal.isEnabled();

        NotificationThreadLocal.setEnabled(false);

        page.setSummary(AkismetConstants.WIKI_PAGE_PENDING_APPROVAL);
        page.setStatus(WorkflowConstants.STATUS_APPROVED);

        page = super.updateWikiPage(page);

        WikiPage previousPage = AkismetUtil.getWikiPage(page.getNodeId(), page.getTitle(), page.getVersion(),
                true);

        if (previousPage == null) {
            return page;
        }

        ServiceContext newServiceContext = new ServiceContext();

        newServiceContext.setFormDate(page.getModifiedDate());

        return super.revertPage(userId, nodeId, title, previousPage.getVersion(), newServiceContext);
    } finally {
        NotificationThreadLocal.setEnabled(notificationEnabled);
    }
}

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 w  w w  . ja  v  a2 s. c  om
        }
    }

    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.portlet.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

public WikiPage updateStatus(long userId, WikiPage page, int status, ServiceContext serviceContext)
        throws PortalException, SystemException {

    // Page/*from  w  w  w .  j  av a 2s . co m*/

    User user = userPersistence.findByPrimaryKey(userId);
    WikiNode node = wikiNodePersistence.findByPrimaryKey(page.getNodeId());

    Date now = new Date();

    int oldStatus = page.getStatus();

    page.setStatus(status);
    page.setStatusByUserId(userId);
    page.setStatusByUserName(user.getFullName());
    page.setStatusDate(now);

    if (status == WorkflowConstants.STATUS_APPROVED) {

        // Asset

        if ((oldStatus != WorkflowConstants.STATUS_APPROVED)
                && (page.getVersion() != WikiPageConstants.VERSION_DEFAULT)) {

            try {
                AssetEntry draftAssetEntry = assetEntryLocalService.getEntry(WikiPage.class.getName(),
                        page.getPrimaryKey());

                long[] assetCategoryIds = draftAssetEntry.getCategoryIds();
                String[] assetTagNames = draftAssetEntry.getTagNames();

                List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(draftAssetEntry.getEntryId(),
                        AssetLinkConstants.TYPE_RELATED);

                long[] assetLinkEntryIds = StringUtil
                        .split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);

                AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, page.getGroupId(),
                        WikiPage.class.getName(), page.getResourcePrimKey(), page.getUuid(), 0,
                        assetCategoryIds, assetTagNames, true, null, null, null, null, ContentTypes.TEXT_HTML,
                        page.getTitle(), null, null, null, null, 0, 0, null, false);

                // Asset Links

                assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
                        AssetLinkConstants.TYPE_RELATED);

                assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId());
            } catch (NoSuchEntryException nsee) {
            }
        }

        assetEntryLocalService.updateVisible(WikiPage.class.getName(), page.getResourcePrimKey(), true);

        // Social

        int activity = WikiActivityKeys.ADD_PAGE;

        if (page.getVersion() > 1.1) {
            activity = WikiActivityKeys.UPDATE_PAGE;
        }

        socialActivityLocalService.addActivity(userId, page.getGroupId(), WikiPage.class.getName(),
                page.getResourcePrimKey(), activity, StringPool.BLANK, 0);

        // Subscriptions

        if (!page.isMinorEdit() && NotificationThreadLocal.isEnabled()) {
            boolean update = false;

            if (page.getVersion() > 1.1) {
                update = true;
            }

            notifySubscribers(node, page, serviceContext, update);
        }

        // Indexer

        Indexer indexer = IndexerRegistryUtil.getIndexer(WikiPage.class);

        indexer.reindex(page);

        // Cache

        clearPageCache(page);

        // Head

        page.setHead(true);

        List<WikiPage> pages = wikiPagePersistence.findByN_T_H(page.getNodeId(), page.getTitle(), true);

        for (WikiPage curPage : pages) {
            if (!curPage.equals(page)) {
                curPage.setHead(false);

                wikiPagePersistence.update(curPage, false);
            }
        }
    } else {

        // Head

        page.setHead(false);

        List<WikiPage> pages = wikiPagePersistence.findByN_T_S(page.getNodeId(), page.getTitle(),
                WorkflowConstants.STATUS_APPROVED);

        for (WikiPage curPage : pages) {
            if (!curPage.equals(page)) {
                curPage.setHead(true);

                wikiPagePersistence.update(curPage, false);

                break;
            }
        }
    }

    return wikiPagePersistence.update(page, false);
}

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

@Override
public WikiPage updateStatus(long userId, WikiPage page, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    // Page//from   w w  w  . j a v  a 2s . co m

    User user = userPersistence.findByPrimaryKey(userId);

    int oldStatus = page.getStatus();

    page.setStatus(status);
    page.setStatusByUserId(userId);
    page.setStatusByUserName(user.getFullName());
    page.setStatusDate(new Date());

    wikiPagePersistence.update(page);

    if (status == WorkflowConstants.STATUS_APPROVED) {
        String cmd = GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_COMMAND));

        if (cmd.equals(Constants.RENAME)) {
            long resourcePrimKey = page.getResourcePrimKey();

            WikiPage oldPage = getPage(resourcePrimKey, true);

            page = doRenamePage(userId, page.getNodeId(), oldPage.getTitle(), page.getTitle(), serviceContext);
        }

        // Asset

        if ((oldStatus != WorkflowConstants.STATUS_APPROVED)
                && (page.getVersion() != WikiPageConstants.VERSION_DEFAULT)) {

            AssetEntry draftAssetEntry = assetEntryLocalService.fetchEntry(WikiPage.class.getName(),
                    page.getPrimaryKey());

            if (draftAssetEntry != null) {
                long[] assetCategoryIds = draftAssetEntry.getCategoryIds();
                String[] assetTagNames = draftAssetEntry.getTagNames();

                List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(draftAssetEntry.getEntryId(),
                        AssetLinkConstants.TYPE_RELATED, false);

                long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

                AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, page.getGroupId(),
                        page.getCreateDate(), page.getModifiedDate(), WikiPage.class.getName(),
                        page.getResourcePrimKey(), page.getUuid(), 0, assetCategoryIds, assetTagNames, true,
                        true, null, null, page.getCreateDate(), null, ContentTypes.TEXT_HTML, page.getTitle(),
                        null, null, null, null, 0, 0, null);

                // Asset Links

                assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
                        AssetLinkConstants.TYPE_RELATED);

                SystemEventHierarchyEntryThreadLocal.push(WikiPage.class);

                try {
                    assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId());
                } finally {
                    SystemEventHierarchyEntryThreadLocal.pop(WikiPage.class);
                }
            }
        }

        assetEntryLocalService.updateVisible(WikiPage.class.getName(), page.getResourcePrimKey(), true);

        // Social

        WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = configurationProvider
                .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                        new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

        if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH) && (!page.isMinorEdit()
                || wikiGroupServiceOverriddenConfiguration.pageMinorEditAddSocialActivity())) {

            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

            extraDataJSONObject.put("title", page.getTitle());
            extraDataJSONObject.put("version", page.getVersion());

            int type = WikiActivityKeys.UPDATE_PAGE;

            if (serviceContext.isCommandAdd()) {
                type = WikiActivityKeys.ADD_PAGE;
            }

            SocialActivityManagerUtil.addActivity(userId, page, type, extraDataJSONObject.toString(), 0);
        }

        // Subscriptions

        if (NotificationThreadLocal.isEnabled()
                && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditSendEmail())) {

            notifySubscribers(userId, page, (String) workflowContext.get(WorkflowConstants.CONTEXT_URL),
                    serviceContext);
        }

        // Cache

        clearPageCache(page);
    }

    // Head

    if (status == WorkflowConstants.STATUS_APPROVED) {
        page.setHead(true);

        List<WikiPage> pages = wikiPagePersistence.findByN_T_H(page.getNodeId(), page.getTitle(), true);

        for (WikiPage curPage : pages) {
            if (!curPage.equals(page)) {
                curPage.setHead(false);

                wikiPagePersistence.update(curPage);
            }
        }
    } else if (status != WorkflowConstants.STATUS_IN_TRASH) {
        page.setHead(false);

        List<WikiPage> pages = wikiPagePersistence.findByN_T_S(page.getNodeId(), page.getTitle(),
                WorkflowConstants.STATUS_APPROVED);

        for (WikiPage curPage : pages) {
            if (!curPage.equals(page)) {
                curPage.setHead(true);

                wikiPagePersistence.update(curPage);

                break;
            }
        }
    }

    // Indexer

    Indexer<WikiPage> indexer = IndexerRegistryUtil.nullSafeGetIndexer(WikiPage.class);

    indexer.reindex(page);

    return wikiPagePersistence.update(page);
}