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

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

Introduction

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

Prototype

int STATUS_APPROVED

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

Click Source Link

Usage

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

License:Open Source License

/**
 * Returns the web content article matching the URL title that is currently
 * displayed or next to be displayed if no article is currently displayed.
 *
 * @param  groupId the primary key of the web content article's group
 * @param  urlTitle the web content article's accessible URL title
 * @return the web content article matching the URL title that is currently
 *         displayed, or next one to be displayed if no version of the
 *         article is currently displayed
 */// ww w.j ava  2s.  com
@Override
public JournalArticle getDisplayArticleByUrlTitle(long groupId, String urlTitle) throws PortalException {

    List<JournalArticle> articles = null;

    OrderByComparator<JournalArticle> orderByComparator = new ArticleVersionComparator();

    articles = journalArticlePersistence.findByG_UT_ST(groupId, urlTitle, WorkflowConstants.STATUS_APPROVED,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator);

    if (articles.isEmpty()) {
        throw new NoSuchArticleException(
                "No JournalArticle exists with the key {groupId=" + groupId + ", urlTitle=" + urlTitle + "}");
    }

    Date now = new Date();

    for (JournalArticle article : articles) {
        Date displayDate = article.getDisplayDate();
        Date expirationDate = article.getExpirationDate();

        if ((displayDate != null) && displayDate.before(now)
                && ((expirationDate == null) || expirationDate.after(now))) {

            return article;
        }
    }

    return articles.get(0);
}

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

License:Open Source License

@Override
public List<JournalArticle> getIndexableArticlesByDDMStructureKey(String[] ddmStructureKeys) {

    if (isReindexAllArticleVersions()) {
        return getStructureArticles(ddmStructureKeys);
    }//from   www .  jav  a2s  . c o m

    QueryDefinition<JournalArticle> approvedQueryDefinition = new QueryDefinition<>(
            WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            new ArticleVersionComparator());

    List<JournalArticle> articles = new ArrayList<>();

    articles.addAll(journalArticleFinder.findByG_C_S(0, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
            ddmStructureKeys, approvedQueryDefinition));

    QueryDefinition<JournalArticle> trashQueryDefinition = new QueryDefinition<>(
            WorkflowConstants.STATUS_IN_TRASH, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            new ArticleVersionComparator());

    articles.addAll(journalArticleFinder.findByG_C_S(0, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
            ddmStructureKeys, trashQueryDefinition));

    return articles;
}

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

License:Open Source License

/**
 * Returns the latest web content article matching the resource primary key
 * and workflow status, optionally preferring articles with approved
 * workflow status.//from www  .  j av a 2  s.c  o m
 *
 * @param  resourcePrimKey the primary key of the resource instance
 * @param  status the web content article's workflow status. For more
 *         information see {@link WorkflowConstants} for constants starting
 *         with the "STATUS_" prefix.
 * @param  preferApproved whether to prefer returning the latest matching
 *         article that has workflow status {@link
 *         WorkflowConstants#STATUS_APPROVED} over returning one that has a
 *         different status
 * @return the latest web content article matching the resource primary key
 *         and workflow status, optionally preferring articles with approved
 *         workflow status
 */
@Override
public JournalArticle getLatestArticle(long resourcePrimKey, int status, boolean preferApproved)
        throws PortalException {

    List<JournalArticle> articles = null;

    OrderByComparator<JournalArticle> orderByComparator = new ArticleVersionComparator();

    if (status == WorkflowConstants.STATUS_ANY) {
        if (preferApproved) {
            articles = journalArticlePersistence.findByR_ST(resourcePrimKey, WorkflowConstants.STATUS_APPROVED,
                    0, 1, orderByComparator);
        }

        if (ListUtil.isEmpty(articles)) {
            articles = journalArticlePersistence.findByResourcePrimKey(resourcePrimKey, 0, 1,
                    orderByComparator);
        }
    } else {
        articles = journalArticlePersistence.findByR_ST(resourcePrimKey, status, 0, 1, orderByComparator);
    }

    if (articles.isEmpty()) {
        throw new NoSuchArticleException(
                "No JournalArticle exists with the key {resourcePrimKey=" + resourcePrimKey + "}");
    }

    return articles.get(0);
}

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

License:Open Source License

/**
 * Returns the previously approved version of the web content article. For
 * more information on the approved workflow status, see {@link
 * WorkflowConstants#STATUS_APPROVED}./*w  ww .  jav a  2 s  . c o  m*/
 *
 * @param  article the web content article
 * @return the previously approved version of the web content article, or
 *         the current web content article if there are no previously
 *         approved web content articles
 */
@Override
public JournalArticle getPreviousApprovedArticle(JournalArticle article) {
    List<JournalArticle> approvedArticles = journalArticlePersistence.findByG_A_ST(article.getGroupId(),
            article.getArticleId(), WorkflowConstants.STATUS_APPROVED, 0, 2);

    if (approvedArticles.isEmpty()
            || ((approvedArticles.size() == 1) && (article.getStatus() == WorkflowConstants.STATUS_APPROVED))) {

        return article;
    }

    JournalArticle previousApprovedArticle = approvedArticles.get(0);

    if (article.getStatus() == WorkflowConstants.STATUS_APPROVED) {
        previousApprovedArticle = approvedArticles.get(1);
    }

    return previousApprovedArticle;
}

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

License:Open Source License

/**
 * Moves the web content article from the Recycle Bin to a new folder.
 *
 * @param  userId the primary key of the user updating the web content
 *         article/* w  w  w.ja  v a 2s  .com*/
 * @param  groupId the primary key of the web content article's group
 * @param  article the web content article
 * @param  newFolderId the primary key of the web content article's new
 *         folder
 * @param  serviceContext the service context to be applied. Can set the
 *         modification date, portlet preferences, and can set whether to
 *         add the default command update for the web content article. 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.
 * @return the updated web content article, which was moved from the Recycle
 *         Bin to a new folder
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle moveArticleFromTrash(long userId, long groupId, JournalArticle article, long newFolderId,
        ServiceContext serviceContext) throws PortalException {

    if (!article.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }

    if (article.isInTrashExplicitly()) {
        restoreArticleFromTrash(userId, article);
    } else {

        // Article

        TrashVersion trashVersion = trashVersionLocalService.fetchVersion(JournalArticle.class.getName(),
                article.getResourcePrimKey());

        int status = WorkflowConstants.STATUS_APPROVED;

        if (trashVersion != null) {
            status = trashVersion.getStatus();
        }

        updateStatus(userId, article, status, null, serviceContext, new HashMap<String, Serializable>());

        // Attachments

        for (FileEntry fileEntry : article.getImagesFileEntries()) {
            PortletFileRepositoryUtil.restorePortletFileEntryFromTrash(userId, fileEntry.getFileEntryId());
        }

        // Trash

        if (trashVersion != null) {
            trashVersionLocalService.deleteTrashVersion(trashVersion);
        }
    }

    return moveArticle(groupId, article.getArticleId(), newFolderId, serviceContext);
}

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

License:Open Source License

/**
 * Restores the web content article from the Recycle Bin.
 *
 * @param  userId the primary key of the user restoring the web content
 *         article//w  w  w. j  ava  2  s . c o  m
 * @param  article the web content article
 * @return the restored web content article from the Recycle Bin
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle restoreArticleFromTrash(long userId, JournalArticle article) throws PortalException {

    // Article

    if (!article.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }

    String trashArticleId = TrashUtil.getOriginalTitle(article.getArticleId());

    List<JournalArticle> articleVersions = journalArticlePersistence.findByG_A(article.getGroupId(),
            article.getArticleId());

    for (JournalArticle articleVersion : articleVersions) {
        articleVersion.setArticleId(trashArticleId);

        journalArticlePersistence.update(articleVersion);
    }

    article.setArticleId(trashArticleId);

    journalArticlePersistence.update(article);

    JournalArticleResource articleResource = journalArticleResourcePersistence
            .fetchByPrimaryKey(article.getResourcePrimKey());

    articleResource.setArticleId(trashArticleId);

    journalArticleResourcePersistence.update(articleResource);

    TrashEntry trashEntry = trashEntryLocalService.getEntry(JournalArticle.class.getName(),
            article.getResourcePrimKey());

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setScopeGroupId(article.getGroupId());

    updateStatus(userId, article, trashEntry.getStatus(), null, serviceContext,
            new HashMap<String, Serializable>());

    // Trash

    List<TrashVersion> trashVersions = trashVersionLocalService.getVersions(trashEntry.getEntryId());

    boolean visible = false;

    for (TrashVersion trashVersion : trashVersions) {
        JournalArticle trashArticleVersion = journalArticlePersistence
                .findByPrimaryKey(trashVersion.getClassPK());

        trashArticleVersion.setStatus(trashVersion.getStatus());

        if (trashVersion.getStatus() == WorkflowConstants.STATUS_APPROVED) {
            visible = true;
        }

        journalArticlePersistence.update(trashArticleVersion);
    }

    trashEntryLocalService.deleteEntry(JournalArticle.class.getName(), article.getResourcePrimKey());

    if (visible) {
        assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(),
                true);
    }

    // Comment

    if (isArticleCommentsEnabled(article.getCompanyId())) {
        CommentManagerUtil.restoreDiscussionFromTrash(JournalArticle.class.getName(),
                article.getResourcePrimKey());
    }

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", article.getTitleMapAsXML());

    SocialActivityManagerUtil.addActivity(userId, article, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
            extraDataJSONObject.toString(), 0);

    return article;
}

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   www.  j a  v  a 2  s .c  om*/
 * @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.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void checkArticlesByDisplayDate(Date displayDate) throws PortalException {

    String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(),
            PortletProvider.Action.EDIT);

    List<JournalArticle> articles = journalArticlePersistence.findByLtD_S(displayDate,
            WorkflowConstants.STATUS_SCHEDULED);

    for (JournalArticle article : articles) {
        long userId = PortalUtil.getValidUserId(article.getCompanyId(), article.getUserId());

        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setCommand(Constants.UPDATE);

        String layoutFullURL = PortalUtil.getLayoutFullURL(article.getGroupId(), portletId);

        serviceContext.setLayoutFullURL(layoutFullURL);

        serviceContext.setScopeGroupId(article.getGroupId());

        journalArticleLocalService.updateStatus(userId, article, WorkflowConstants.STATUS_APPROVED, null,
                serviceContext, new HashMap<String, Serializable>());
    }/*from  w ww  .j  a  v a 2s.co m*/
}

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

License:Open Source License

protected void checkArticlesByExpirationDate(Date expirationDate) throws PortalException {

    List<JournalArticle> articles = journalArticleFinder.findByExpirationDate(
            JournalArticleConstants.CLASSNAME_ID_DEFAULT,
            new Date(expirationDate.getTime() + getArticleCheckInterval()),
            new QueryDefinition<JournalArticle>(WorkflowConstants.STATUS_APPROVED));

    if (_log.isDebugEnabled()) {
        _log.debug("Expiring " + articles.size() + " articles");
    }/*  w w  w  .  jav  a  2  s  .  c o m*/

    for (JournalArticle article : articles) {
        if (isExpireAllArticleVersions(article.getCompanyId())) {
            List<JournalArticle> currentArticles = journalArticlePersistence.findByG_A(article.getGroupId(),
                    article.getArticleId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    new ArticleVersionComparator(true));

            for (JournalArticle currentArticle : currentArticles) {
                if ((currentArticle.getExpirationDate() == null)
                        || (currentArticle.getVersion() > article.getVersion())) {

                    continue;
                }

                currentArticle.setExpirationDate(article.getExpirationDate());
                currentArticle.setStatus(WorkflowConstants.STATUS_EXPIRED);

                journalArticlePersistence.update(currentArticle);
            }
        } else {
            article.setStatus(WorkflowConstants.STATUS_EXPIRED);

            journalArticlePersistence.update(article);
        }

        updatePreviousApprovedArticle(article);

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

        indexer.reindex(article);
    }

    if (_previousCheckDate == null) {
        _previousCheckDate = new Date(expirationDate.getTime() - getArticleCheckInterval());
    }
}

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

License:Open Source License

protected boolean hasModifiedLatestApprovedVersion(long groupId, String articleId, double version) {

    JournalArticle article = fetchLatestArticle(groupId, articleId, WorkflowConstants.STATUS_APPROVED);

    if ((article == null) || (article.getVersion() <= version)) {
        return true;
    }//from   w w w  . ja v a  2s.  c o m

    return false;
}