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

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

Introduction

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

Prototype

public boolean isCommandAdd() 

Source Link

Document

Returns true if this service context contains an add command (i.e.

Usage

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, BlogsEntry entry, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    String entryURL = (String) workflowContext.get(WorkflowConstants.CONTEXT_URL);

    if (!entry.isApproved() || Validator.isNull(entryURL)) {
        return;/*from  ww  w .j a  va  2 s. c  om*/
    }

    BlogsGroupServiceSettings blogsGroupServiceSettings = BlogsGroupServiceSettings
            .getInstance(entry.getGroupId());

    boolean sendEmailEntryUpdated = GetterUtil.getBoolean(serviceContext.getAttribute("sendEmailEntryUpdated"));

    if (serviceContext.isCommandAdd() && blogsGroupServiceSettings.isEmailEntryAddedEnabled()) {
    } else if (sendEmailEntryUpdated && serviceContext.isCommandUpdate()
            && blogsGroupServiceSettings.isEmailEntryUpdatedEnabled()) {
    } else {
        return;
    }

    Group group = groupPersistence.findByPrimaryKey(entry.getGroupId());

    String entryTitle = entry.getTitle();

    String fromName = blogsGroupServiceSettings.getEmailFromName();
    String fromAddress = blogsGroupServiceSettings.getEmailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryUpdatedSubject();
        bodyLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryAddedSubject();
        bodyLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryAddedBody();
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            BlogsPermission.RESOURCE_NAME);

    subscriptionSender.setClassPK(entry.getEntryId());
    subscriptionSender.setClassName(entry.getModelClassName());
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttribute("[$BLOGS_ENTRY_CONTENT$]",
            StringUtil.shorten(HtmlUtil.stripHtml(entry.getContent()), 500), false);
    subscriptionSender.setContextAttributes("[$BLOGS_ENTRY_CREATE_DATE$]",
            Time.getSimpleDate(entry.getCreateDate(), "yyyy/MM/dd"), "[$BLOGS_ENTRY_DESCRIPTION$]",
            entry.getDescription(), "[$BLOGS_ENTRY_SITE_NAME$]",
            group.getDescriptiveName(serviceContext.getLocale()), "[$BLOGS_ENTRY_STATUS_BY_USER_NAME$]",
            entry.getStatusByUserName(), "[$BLOGS_ENTRY_TITLE$]", entryTitle, "[$BLOGS_ENTRY_UPDATE_COMMENT$]",
            HtmlUtil.replaceNewLine(
                    GetterUtil.getString(serviceContext.getAttribute("emailEntryUpdatedComment"))),
            "[$BLOGS_ENTRY_URL$]", entryURL, "[$BLOGS_ENTRY_USER_PORTRAIT_URL$]",
            workflowContext.get(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL), "[$BLOGS_ENTRY_USER_URL$]",
            workflowContext.get(WorkflowConstants.CONTEXT_USER_URL));
    subscriptionSender.setContextCreatorUserPrefix("BLOGS_ENTRY");
    subscriptionSender.setCreatorUserId(entry.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    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("blogs_entry", entry.getEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(),
            PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(BlogsEntry.class.getName(), entry.getGroupId());

    subscriptionSender.addPersistedSubscribers(BlogsEntry.class.getName(), entry.getEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, BookmarksEntry entry, ServiceContext serviceContext)
        throws PortalException {

    String layoutFullURL = serviceContext.getLayoutFullURL();

    if (!entry.isApproved() || Validator.isNull(layoutFullURL)) {
        return;//from www  .  j ava 2  s.  c om
    }

    BookmarksGroupServiceOverriddenConfiguration bookmarksGroupServiceOverriddenConfiguration = configurationProvider
            .getConfiguration(BookmarksGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(entry.getGroupId(), BookmarksConstants.SERVICE_NAME));

    if ((serviceContext.isCommandAdd()
            && !bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedEnabled())
            || (serviceContext.isCommandUpdate()
                    && !bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedEnabled())) {

        return;
    }

    String statusByUserName = StringPool.BLANK;

    try {
        User user = userLocalService.getUserById(serviceContext.getGuestOrUserId());

        statusByUserName = user.getFullName();
    } catch (Exception e) {
        _log.error(e, e);
    }

    String entryTitle = entry.getName();

    StringBundler sb = new StringBundler(7);

    sb.append(layoutFullURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("bookmarks");
    sb.append(StringPool.SLASH);
    sb.append("folder");
    sb.append(StringPool.SLASH);
    sb.append(entry.getFolderId());

    String entryURL = sb.toString();

    String fromName = bookmarksGroupServiceOverriddenConfiguration.emailFromName();
    String fromAddress = bookmarksGroupServiceOverriddenConfiguration.emailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedSubject();
        bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedSubject();
        bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedBody();
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            BookmarksResourcePermissionChecker.RESOURCE_NAME);

    subscriptionSender.setClassName(entry.getModelClassName());
    subscriptionSender.setClassPK(entry.getEntryId());
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttributes("[$BOOKMARKS_ENTRY_STATUS_BY_USER_NAME$]", statusByUserName,
            "[$BOOKMARKS_ENTRY_URL$]", entryURL);
    subscriptionSender.setContextCreatorUserPrefix("BOOKMARKS_ENTRY");
    subscriptionSender.setCreatorUserId(entry.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    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("bookmarks_entry", entry.getEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(BookmarksPortletKeys.BOOKMARKS);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    BookmarksFolder folder = entry.getFolder();

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), ancestorFolderId);
        }
    }

    subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), entry.getGroupId());

    subscriptionSender.addPersistedSubscribers(BookmarksEntry.class.getName(), entry.getEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.document.library.internal.service.SubscriptionDLAppHelperLocalServiceWrapper.java

License:Open Source License

protected void notifySubscribers(long userId, FileVersion fileVersion, String entryURL,
        ServiceContext serviceContext) throws PortalException {

    if (!fileVersion.isApproved() || Validator.isNull(entryURL)) {
        return;//from   ww  w .  j a v  a  2s . c  o m
    }

    DLGroupServiceSettings dlGroupServiceSettings = DLGroupServiceSettings
            .getInstance(fileVersion.getGroupId());

    boolean commandUpdate = false;

    if (serviceContext.isCommandUpdate() || Constants.CHECKIN.equals(serviceContext.getCommand())) {

        commandUpdate = true;
    }

    if (serviceContext.isCommandAdd() && dlGroupServiceSettings.isEmailFileEntryAddedEnabled()) {
    } else if (commandUpdate && dlGroupServiceSettings.isEmailFileEntryUpdatedEnabled()) {
    } else {
        return;
    }

    String entryTitle = fileVersion.getTitle();

    String fromName = dlGroupServiceSettings.getEmailFromName();
    String fromAddress = dlGroupServiceSettings.getEmailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (commandUpdate) {
        subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedSubject();
        bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedSubject();
        bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedBody();
    }

    FileEntry fileEntry = fileVersion.getFileEntry();

    Folder folder = null;

    long folderId = fileEntry.getFolderId();

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        folder = _dlAppLocalService.getFolder(folderId);
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            DLPermission.RESOURCE_NAME);

    DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

    DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService
            .getDLFileEntryType(dlFileEntry.getFileEntryTypeId());

    subscriptionSender.setClassPK(fileVersion.getFileEntryId());
    subscriptionSender.setClassName(DLFileEntryConstants.getClassName());
    subscriptionSender.setCompanyId(fileVersion.getCompanyId());

    if (folder != null) {
        subscriptionSender.setContextAttribute("[$FOLDER_NAME$]", folder.getName(), true);
    } else {
        subscriptionSender.setLocalizedContextAttribute("[$FOLDER_NAME$]",
                new EscapableLocalizableFunction(locale -> LanguageUtil.get(locale, "home")));
    }

    subscriptionSender.setContextAttributes("[$DOCUMENT_STATUS_BY_USER_NAME$]",
            fileVersion.getStatusByUserName(), "[$DOCUMENT_TITLE$]", entryTitle, "[$DOCUMENT_URL$]", entryURL);
    subscriptionSender.setContextCreatorUserPrefix("DOCUMENT");
    subscriptionSender.setCreatorUserId(fileVersion.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    subscriptionSender.setLocalizedContextAttribute("[$DOCUMENT_TYPE$]",
            new EscapableLocalizableFunction(locale -> dlFileEntryType.getName(locale)));
    subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    subscriptionSender.setMailId("file_entry", fileVersion.getFileEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (commandUpdate) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(FileEntry.class.getName(), PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(fileVersion.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), fileVersion.getGroupId());

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), ancestorFolderId);
        }
    }

    if (dlFileEntryType.getFileEntryTypeId() == DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {

        subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(), fileVersion.getGroupId());
    } else {
        subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(),
                dlFileEntryType.getFileEntryTypeId());
    }

    subscriptionSender.addPersistedSubscribers(DLFileEntry.class.getName(), fileEntry.getFileEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java

License:Open Source License

protected void notifySubscribers(long userId, MBMessage message, String messageURL,
        ServiceContext serviceContext) throws PortalException {

    if (!message.isApproved() || Validator.isNull(messageURL)) {
        return;//from w ww. jav  a  2  s  .co m
    }

    if (message.isDiscussion()) {
        try {
            notifyDiscussionSubscribers(userId, message, serviceContext);
        } catch (Exception e) {
            _log.error(e, e);
        }

        return;
    }

    MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings.getInstance(message.getGroupId());

    if (serviceContext.isCommandAdd() && mbGroupServiceSettings.isEmailMessageAddedEnabled()) {
    } else if (serviceContext.isCommandUpdate() && mbGroupServiceSettings.isEmailMessageUpdatedEnabled()) {
    } else {
        return;
    }

    Company company = _companyLocalService.getCompany(message.getCompanyId());

    User user = _userLocalService.getUser(userId);

    String emailAddress = user.getEmailAddress();
    String fullName = user.getFullName();

    if (message.isAnonymous()) {
        emailAddress = StringPool.BLANK;
        fullName = serviceContext.translate("anonymous");
    }

    MBCategory category = message.getCategory();

    List<Long> categoryIds = new ArrayList<>();

    categoryIds.add(message.getCategoryId());

    if (message.getCategoryId() != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

        categoryIds.addAll(category.getAncestorCategoryIds());
    }

    String entryTitle = message.getSubject();

    String fromName = mbGroupServiceSettings.getEmailFromName();
    String fromAddress = mbGroupServiceSettings.getEmailFromAddress();

    String replyToAddress = StringPool.BLANK;

    if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
        replyToAddress = MBUtil.getReplyToAddress(message.getCategoryId(), message.getMessageId(),
                company.getMx(), fromAddress);
    }

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageUpdatedSubject();
        bodyLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageUpdatedBody();
    } else {
        subjectLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageAddedSubject();
        bodyLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageAddedBody();
    }

    boolean htmlFormat = mbGroupServiceSettings.isEmailHtmlFormat();

    String messageBody = message.getBody();

    if (htmlFormat && message.isFormatBBCode()) {
        try {
            messageBody = BBCodeTranslatorUtil.getHTML(messageBody);

            HttpServletRequest request = serviceContext.getRequest();

            if (request != null) {
                ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

                messageBody = MBUtil.replaceMessageBodyPaths(themeDisplay, messageBody);
            }
        } catch (Exception e) {
            _log.error(StringBundler.concat("Unable to parse message ", String.valueOf(message.getMessageId()),
                    ": ", e.getMessage()));
        }
    }

    String inReplyTo = null;
    String messageSubject = message.getSubject();
    String messageSubjectPrefix = StringPool.BLANK;

    if (message.getParentMessageId() != MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) {

        MBMessage parentMessage = _mbMessageLocalService.getMessage(message.getParentMessageId());

        Date modifiedDate = parentMessage.getModifiedDate();

        inReplyTo = _portal.getMailId(company.getMx(), MBUtil.MESSAGE_POP_PORTLET_PREFIX,
                message.getCategoryId(), parentMessage.getMessageId(), modifiedDate.getTime());

        if (messageSubject.startsWith(MBMessageConstants.MESSAGE_SUBJECT_PREFIX_RE)) {

            messageSubjectPrefix = MBMessageConstants.MESSAGE_SUBJECT_PREFIX_RE;

            messageSubject = messageSubject.substring(messageSubjectPrefix.length());
        }
    }

    SubscriptionSender subscriptionSender = getSubscriptionSender(userId, category, message, messageURL,
            entryTitle, htmlFormat, messageBody, messageSubject, messageSubjectPrefix, inReplyTo, fromName,
            fromAddress, replyToAddress, emailAddress, fullName, subjectLocalizedValuesMap,
            bodyLocalizedValuesMap, serviceContext);

    subscriptionSender.addPersistedSubscribers(MBCategory.class.getName(), message.getGroupId());

    for (long categoryId : categoryIds) {
        if (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
            subscriptionSender.addPersistedSubscribers(MBCategory.class.getName(), categoryId);
        }
    }

    subscriptionSender.addPersistedSubscribers(MBThread.class.getName(), message.getThreadId());

    subscriptionSender.flushNotificationsAsync();

    if (!MailingListThreadLocal.isSourceMailingList()) {
        for (long categoryId : categoryIds) {
            MBSubscriptionSender sourceMailingListSubscriptionSender = getSubscriptionSender(userId, category,
                    message, messageURL, entryTitle, htmlFormat, messageBody, messageSubject,
                    messageSubjectPrefix, inReplyTo, fromName, fromAddress, replyToAddress, emailAddress,
                    fullName, subjectLocalizedValuesMap, bodyLocalizedValuesMap, serviceContext);

            sourceMailingListSubscriptionSender.setBulk(false);

            sourceMailingListSubscriptionSender.addMailingListSubscriber(message.getGroupId(), categoryId);

            sourceMailingListSubscriptionSender.flushNotificationsAsync();
        }
    }
}

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 www.  j a  v  a2 s  . c  om

    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);
}