Example usage for com.liferay.portal.kernel.workflow WorkflowConstants CONTEXT_URL

List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants CONTEXT_URL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowConstants CONTEXT_URL.

Prototype

String CONTEXT_URL

To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants CONTEXT_URL.

Click Source Link

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;/*  ww w . j av a  2s . 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.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

protected BlogsEntry startWorkflowInstance(long userId, BlogsEntry entry, ServiceContext serviceContext)
        throws PortalException {

    Map<String, Serializable> workflowContext = new HashMap<>();

    workflowContext.put(WorkflowConstants.CONTEXT_URL, getEntryURL(entry, serviceContext));

    String userPortraitURL = StringPool.BLANK;
    String userURL = StringPool.BLANK;

    if (serviceContext.getThemeDisplay() != null) {
        User user = userPersistence.findByPrimaryKey(userId);

        userPortraitURL = user.getPortraitURL(serviceContext.getThemeDisplay());
        userURL = user.getDisplayURL(serviceContext.getThemeDisplay());
    }/* ww  w .ja va  2  s  . c o  m*/

    workflowContext.put(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL, userPortraitURL);
    workflowContext.put(WorkflowConstants.CONTEXT_USER_URL, userURL);

    return WorkflowHandlerRegistryUtil.startWorkflowInstance(entry.getCompanyId(), entry.getGroupId(), userId,
            BlogsEntry.class.getName(), entry.getEntryId(), entry, serviceContext, workflowContext);
}

From source file:com.liferay.blogs.test.util.BlogsTestUtil.java

License:Open Source License

protected static BlogsEntry updateStatus(BlogsEntry entry, ServiceContext serviceContext) throws Exception {

    Map<String, Serializable> workflowContext = new HashMap<>();

    workflowContext.put(WorkflowConstants.CONTEXT_URL, "http://localhost");
    workflowContext.put(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL, "http://localhost");
    workflowContext.put(WorkflowConstants.CONTEXT_USER_URL, "http://localhost");

    return BlogsEntryLocalServiceUtil.updateStatus(entry.getUserId(), entry.getEntryId(),
            WorkflowConstants.STATUS_APPROVED, serviceContext, workflowContext);
}

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

License:Open Source License

@Override
public void updateStatus(long userId, FileEntry fileEntry, FileVersion latestFileVersion, int oldStatus,
        int newStatus, ServiceContext serviceContext, Map<String, Serializable> workflowContext)
        throws PortalException {

    if (!_isEnabled(fileEntry)) {
        return;/*  w w w. j  a  va  2s  . co  m*/
    }

    super.updateStatus(userId, fileEntry, latestFileVersion, oldStatus, newStatus, serviceContext,
            workflowContext);

    if ((newStatus == WorkflowConstants.STATUS_APPROVED) && (oldStatus != WorkflowConstants.STATUS_IN_TRASH)
            && !fileEntry.isInTrash()) {

        // Subscriptions

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

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 .  j  a  va2  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.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java

License:Open Source License

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

    MBMessage message = super.updateStatus(userId, messageId, status, serviceContext, workflowContext);

    if (status == WorkflowConstants.STATUS_APPROVED) {
        notifySubscribers(userId, (MBMessage) message.clone(),
                (String) workflowContext.get(WorkflowConstants.CONTEXT_URL), serviceContext);
    }//from  w  ww .  jav a  2  s .c o m

    return message;
}

From source file:com.liferay.message.boards.test.util.MBTestUtil.java

License:Open Source License

protected static MBMessage updateStatus(MBMessage message, ServiceContext serviceContext) throws Exception {

    Map<String, Serializable> workflowContext = new HashMap<>();

    workflowContext.put(WorkflowConstants.CONTEXT_URL, "http://localhost");

    message = MBMessageLocalServiceUtil.updateStatus(message.getUserId(), message.getMessageId(),
            WorkflowConstants.STATUS_APPROVED, serviceContext, workflowContext);

    return message;
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public void startWorkflowInstance(long userId, DLFileVersion dlFileVersion, String syncEventType,
        ServiceContext serviceContext) throws PortalException {

    Map<String, Serializable> workflowContext = new HashMap<>();

    workflowContext.put(WorkflowConstants.CONTEXT_URL, getEntryURL(dlFileVersion, serviceContext));
    workflowContext.put("event", syncEventType);

    WorkflowHandlerRegistryUtil.startWorkflowInstance(dlFileVersion.getCompanyId(), dlFileVersion.getGroupId(),
            userId, DLFileEntryConstants.getClassName(), dlFileVersion.getFileVersionId(), dlFileVersion,
            serviceContext, workflowContext);
}

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/* w w w. j  a va 2  s. c  o 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);
}

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

License:Open Source License

protected WikiPage startWorkflowInstance(long userId, WikiPage page, ServiceContext serviceContext)
        throws PortalException {

    Map<String, Serializable> workflowContext = new HashMap<>();

    workflowContext.put(WorkflowConstants.CONTEXT_COMMAND, serviceContext.getCommand());
    workflowContext.put(WorkflowConstants.CONTEXT_URL, getPageURL(page, serviceContext));

    return WorkflowHandlerRegistryUtil.startWorkflowInstance(page.getCompanyId(), page.getGroupId(), userId,
            WikiPage.class.getName(), page.getPageId(), page, serviceContext, workflowContext);
}