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

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

Introduction

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

Prototype

int STATUS_DENIED

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

Click Source Link

Usage

From source file:com.liferay.akismet.moderation.util.ModerationUtil.java

License:Open Source License

protected static DynamicQuery buildMBMessageDynamicQuery(long scopeGroupId, boolean discussion)
        throws PortalException {

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(MBMessage.class);

    Group group = GroupLocalServiceUtil.getGroup(scopeGroupId);

    if (!group.isCompany()) {
        Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

        Long[] scopeGroupIds = getChildScopeGroupIds(scopeGroupId);

        dynamicQuery.add(groupIdProperty.in(scopeGroupIds));
    }/*from  w  ww . ja  v  a  2 s.c o m*/

    Property categoryIdProperty = PropertyFactoryUtil.forName("categoryId");

    if (discussion) {
        dynamicQuery.add(categoryIdProperty.eq(MBCategoryConstants.DISCUSSION_CATEGORY_ID));
    } else {
        dynamicQuery.add(categoryIdProperty.ne(MBCategoryConstants.DISCUSSION_CATEGORY_ID));
    }

    Property statusProperty = PropertyFactoryUtil.forName("status");

    dynamicQuery.add(statusProperty.eq(WorkflowConstants.STATUS_DENIED));

    return dynamicQuery;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Updates the workflow status of the web content article.
 *
 * @param  userId the primary key of the user updating the web content
 *         article's status//from  w  ww  .j  a va2  s.  co  m
 * @param  article the web content article
 * @param  status the web content article's workflow status. For more
 *         information see {@link WorkflowConstants} for constants starting
 *         with the "STATUS_" prefix.
 * @param  articleURL the web content article's accessible URL
 * @param  serviceContext the service context to be applied. Can set the
 *         modification date, status date, and portlet preferences. With
 *         respect to social activities, by setting the service context's
 *         command to {@link Constants#UPDATE}, the invocation is considered
 *         a web content update activity; otherwise it is considered a web
 *         content add activity.
 * @param  workflowContext the web content article's configured workflow
 *         context
 * @return the updated web content article
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle updateStatus(long userId, JournalArticle article, int status, String articleURL,
        ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws PortalException {

    // Article

    User user = userLocalService.getUser(userId);
    Date now = new Date();

    if ((status == WorkflowConstants.STATUS_APPROVED)
            && (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT)
            && (article.getDisplayDate() != null) && now.before(article.getDisplayDate())) {

        status = WorkflowConstants.STATUS_SCHEDULED;
    }

    int oldStatus = article.getStatus();

    Date modifiedDate = serviceContext.getModifiedDate(now);

    article.setModifiedDate(modifiedDate);

    if (status == WorkflowConstants.STATUS_APPROVED) {
        Date expirationDate = article.getExpirationDate();

        if ((expirationDate != null) && expirationDate.before(now)) {
            article.setExpirationDate(null);
        }
    }

    if (status == WorkflowConstants.STATUS_EXPIRED) {
        article.setExpirationDate(now);
    }

    article.setStatus(status);
    article.setStatusByUserId(user.getUserId());
    article.setStatusByUserName(user.getFullName());
    article.setStatusDate(modifiedDate);

    journalArticlePersistence.update(article);

    if (isExpireAllArticleVersions(article.getCompanyId())) {
        setArticlesExpirationDate(article);
    }

    if (hasModifiedLatestApprovedVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) {

        if (status == WorkflowConstants.STATUS_APPROVED) {
            updateUrlTitles(article.getGroupId(), article.getArticleId(), article.getUrlTitle());

            // Asset

            String title = article.getTitleMapAsXML();
            String description = article.getDescriptionMapAsXML();

            if ((oldStatus != WorkflowConstants.STATUS_APPROVED)
                    && (article.getVersion() != JournalArticleConstants.VERSION_DEFAULT)) {

                AssetEntry draftAssetEntry = assetEntryLocalService.fetchEntry(JournalArticle.class.getName(),
                        article.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, article.getGroupId(),
                            article.getCreateDate(), article.getModifiedDate(), JournalArticle.class.getName(),
                            article.getResourcePrimKey(), article.getUuid(), getClassTypeId(article),
                            assetCategoryIds, assetTagNames, isListable(article), false, null, null, null, null,
                            ContentTypes.TEXT_HTML, title, description, description, null,
                            article.getLayoutUuid(), 0, 0, draftAssetEntry.getPriority());

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

                    assetEntryLocalService.deleteEntry(draftAssetEntry);
                }
            }

            if (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) {

                assetEntryLocalService.updateEntry(JournalArticle.class.getName(), article.getResourcePrimKey(),
                        article.getDisplayDate(), article.getExpirationDate(), isListable(article), true);
            }

            // Social

            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

            extraDataJSONObject.put("title", title);

            if (serviceContext.isCommandUpdate()) {
                SocialActivityManagerUtil.addActivity(user.getUserId(), article,
                        JournalActivityKeys.UPDATE_ARTICLE, extraDataJSONObject.toString(), 0);
            } else {
                SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), article,
                        JournalActivityKeys.ADD_ARTICLE, extraDataJSONObject.toString(), 0);
            }
        } else if (oldStatus == WorkflowConstants.STATUS_APPROVED) {
            updatePreviousApprovedArticle(article);
        }
    }

    if ((article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT)
            && (oldStatus != WorkflowConstants.STATUS_IN_TRASH)
            && (status != WorkflowConstants.STATUS_IN_TRASH)) {

        // Email

        if ((oldStatus == WorkflowConstants.STATUS_PENDING) && ((status == WorkflowConstants.STATUS_APPROVED)
                || (status == WorkflowConstants.STATUS_DENIED))) {

            String msg = "granted";

            if (status == WorkflowConstants.STATUS_DENIED) {
                msg = "denied";
            }

            try {
                PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

                articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(),
                        article.getArticleId());

                sendEmail(article, articleURL, preferences, msg, serviceContext);
            } catch (Exception e) {
                _log.error("Unable to send email to notify the change of status " + "to " + msg
                        + " for article " + article.getId() + ": " + e.getMessage());
            }
        }

        // Subscriptions

        String action = "update";

        if (article.getVersion() == 1.0) {
            action = "add";
        }

        notifySubscribers(user.getUserId(), article, action, serviceContext);
    }

    return article;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public List<ManagementBarFilterItem> getManagementBarStatusFilterItems()
        throws PortalException, PortletException {

    List<ManagementBarFilterItem> managementBarFilterItems = new ArrayList<>();

    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_ANY));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DRAFT));

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil.getWorkflowDefinitionLinksCount(
            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), JournalFolder.class.getName());

    if (workflowDefinitionLinksCount > 0) {
        managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_PENDING));
        managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DENIED));
    }/*from ww w. j  a va 2  s  . co m*/

    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_SCHEDULED));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_APPROVED));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_EXPIRED));

    return managementBarFilterItems;
}

From source file:com.liferay.lms.model.CompetenceClp.java

License:Open Source License

public boolean isDenied() {
    if (getStatus() == WorkflowConstants.STATUS_DENIED) {
        return true;
    } else {//from   w  w w . j  av a  2  s . c o  m
        return false;
    }
}

From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

public JournalArticle updateStatus(long userId, JournalArticle article, int status, String articleURL,
        ServiceContext serviceContext) throws PortalException, SystemException {

    // Article/*from w w  w . j  ava2  s.c o m*/

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    int oldStatus = article.getStatus();

    article.setModifiedDate(serviceContext.getModifiedDate(now));

    boolean neverExpire = false;

    if (status == WorkflowConstants.STATUS_APPROVED) {
        Date expirationDate = article.getExpirationDate();

        if ((expirationDate != null) && expirationDate.before(now)) {
            neverExpire = true;

            article.setExpirationDate(null);
        }
    }

    if (status == WorkflowConstants.STATUS_EXPIRED) {
        article.setExpirationDate(now);
    }

    article.setStatus(status);
    article.setStatusByUserId(user.getUserId());
    article.setStatusByUserName(user.getFullName());
    article.setStatusDate(serviceContext.getModifiedDate(now));

    journalArticlePersistence.update(article, false);

    if (isLatestVersion(article.getGroupId(), article.getArticleId(), article.getVersion())) {

        if (status == WorkflowConstants.STATUS_APPROVED) {
            updateUrlTitles(article.getGroupId(), article.getArticleId(), article.getUrlTitle());

            // Asset

            if ((oldStatus != WorkflowConstants.STATUS_APPROVED)
                    && (article.getVersion() != JournalArticleConstants.VERSION_DEFAULT)) {

                AssetEntry draftAssetEntry = null;

                try {
                    draftAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(),
                            article.getPrimaryKey());

                    Date[] dateInterval = getDateInterval(article.getGroupId(), article.getArticleId(),
                            article.getDisplayDate(), article.getExpirationDate());

                    Date displayDate = dateInterval[0];
                    Date expirationDate = dateInterval[1];

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

                    boolean visible = true;

                    if (article.getClassNameId() > 0) {
                        visible = false;
                    }

                    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, article.getGroupId(),
                            JournalArticle.class.getName(), article.getResourcePrimKey(), article.getUuid(),
                            getClassTypeId(article), assetCategoryIds, assetTagNames, visible, null, null,
                            displayDate, expirationDate, ContentTypes.TEXT_HTML, article.getTitle(),
                            article.getDescription(), article.getDescription(), null, article.getLayoutUuid(),
                            0, 0, null, false);

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

                    assetEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getPrimaryKey());
                } catch (NoSuchEntryException nsee) {
                }
            }

            if (article.getClassNameId() == 0) {
                AssetEntry assetEntry = assetEntryLocalService.updateVisible(JournalArticle.class.getName(),
                        article.getResourcePrimKey(), true);

                if (neverExpire) {
                    assetEntry.setExpirationDate(null);

                    assetEntryLocalService.updateAssetEntry(assetEntry, false);
                }
            }

            // Expando

            ExpandoBridge expandoBridge = article.getExpandoBridge();

            expandoBridge.setAttributes(serviceContext);

            // Indexer

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

            indexer.reindex(article);
        } else if (oldStatus == WorkflowConstants.STATUS_APPROVED) {
            updatePreviousApprovedArticle(article);
        }
    }

    if (article.getClassNameId() == 0) {

        // Email

        if ((oldStatus == WorkflowConstants.STATUS_PENDING) && ((status == WorkflowConstants.STATUS_APPROVED)
                || (status == WorkflowConstants.STATUS_DENIED))) {

            String msg = "granted";

            if (status == WorkflowConstants.STATUS_DENIED) {
                msg = "denied";
            }

            try {
                PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

                sendEmail(article, articleURL, preferences, msg, serviceContext);
            } catch (Exception e) {
                _log.error("Unable to send email to notify the change of status " + " to " + msg
                        + " for article " + article.getId() + ": " + e.getMessage());
            }
        }

        // Subscriptions

        notifySubscribers(article, serviceContext);
    }

    return article;
}

From source file:fi.javaguru.akismet.mb.hook.action.EditMessageAction.java

License:Open Source License

protected void updateStatus(ActionRequest actionRequest, ActionResponse actionResponse)
        throws PortalException, SystemException {

    String cmd = actionRequest.getParameter("cmd");
    long messageId = GetterUtil.getLong(actionRequest.getParameter("messageId"));
    boolean spam = cmd.equals("SPAM");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    AkismetMBMessage akismetMBMessage = null;

    try {/*from   w w  w  . ja  v a  2  s .c om*/
        akismetMBMessage = AkismetMBMessageLocalServiceUtil.getByMessageId(messageId);

        if (akismetMBMessage.isSpam() != spam) {
            akismetMBMessage.setSpam(spam);

            AkismetMBMessageLocalServiceUtil.updateAkismetMBMessage(akismetMBMessage.getAkismetMBMessageId(),
                    akismetMBMessage.getUserId(), messageId, spam, akismetMBMessage.getAuthor(),
                    akismetMBMessage.getAuthorEmail(), akismetMBMessage.getAuthorUrl(),
                    akismetMBMessage.getContent(), akismetMBMessage.getPermalink(),
                    akismetMBMessage.getReferrer(), akismetMBMessage.getType(), akismetMBMessage.getUserAgent(),
                    akismetMBMessage.getUserIp(), serviceContext);
        }
    } catch (NoSuchMBMessageException nsme) {
        MBMessage mbMessage = MBMessageLocalServiceUtil.getMBMessage(messageId);

        User user = UserLocalServiceUtil.fetchUser(mbMessage.getUserId());

        String author = mbMessage.getUserName();
        String authorEmail = StringPool.BLANK;

        if (user != null) {
            author = user.getFullName();
            authorEmail = user.getEmailAddress();
        }

        String content = mbMessage.getSubject().concat("\n\n").concat(mbMessage.getBody());

        String permalink = serviceContext.getPortalURL().concat("/c/message_boards/find_entry?messageId=")
                .concat(String.valueOf(messageId));

        akismetMBMessage = AkismetMBMessageLocalServiceUtil.addAkismetMBMessage(mbMessage.getUserId(),
                messageId, spam, author, authorEmail, StringPool.BLANK, content, permalink,
                serviceContext.getCurrentURL(), AkismetComment.TYPE_COMMENT, StringPool.BLANK, StringPool.BLANK,
                serviceContext);
    }

    int status = WorkflowConstants.STATUS_APPROVED;

    if (spam) {
        status = WorkflowConstants.STATUS_DENIED;
    }

    MBMessageLocalServiceUtil.updateStatus(serviceContext.getUserId(), messageId, status, serviceContext);

    AkismetComment comment = new AkismetComment();

    comment.setAuthor(akismetMBMessage.getAuthor());
    comment.setAuthorEmail(akismetMBMessage.getAuthorEmail());
    comment.setContent(akismetMBMessage.getContent());
    comment.setPermalink(akismetMBMessage.getPermalink());
    comment.setType(akismetMBMessage.getType());
    comment.setUserAgent(akismetMBMessage.getUserAgent());
    comment.setUserIp(akismetMBMessage.getUserIp());

    long companyId = serviceContext.getCompanyId();

    String akismetApiKey = PrefsPropsUtil.getString(companyId, "akismet.api.key");

    try {
        Akismet akismet = new Akismet(akismetApiKey, serviceContext.getPortalURL());

        if (spam) {
            akismet.submitSpam(comment);
        } else {
            akismet.submitHam(comment);
        }
    } catch (AkismetException ae) {
        ae.printStackTrace();
    }
}

From source file:fi.javaguru.akismet.mb.hook.service.AkismetMBMessageLocalServiceImpl.java

License:Open Source License

protected void updateStatus(long userId, boolean spam, AkismetComment comment, MBMessage mbMessage,
        ServiceContext serviceContext) throws PortalException, SystemException {

    if (spam) {//w w  w .  j av  a2s  . c  o m
        mbMessage.setStatus(WorkflowConstants.STATUS_DENIED);

        super.updateStatus(userId, mbMessage.getMessageId(), WorkflowConstants.STATUS_DENIED, serviceContext);
    }

    updateAkismetMBMessage(mbMessage.getMessageId(), userId, spam, comment, serviceContext);
}