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

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

Introduction

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

Prototype

int STATUS_IN_TRASH

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

Click Source Link

Usage

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

License:Open Source License

/**
 * Returns the latest web content article matching the group, article ID,
 * and workflow status.// w ww  . j  a  va  2  s.  c om
 *
 * @param  groupId the primary key of the web content article's group
 * @param  articleId the primary key of 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.
 * @return the latest matching web content article, or <code>null</code> if
 *         no matching web content article could be found
 */
@Override
public JournalArticle fetchLatestArticle(long groupId, String articleId, int status) {

    OrderByComparator<JournalArticle> orderByComparator = new ArticleVersionComparator();

    if (status == WorkflowConstants.STATUS_ANY) {
        return journalArticlePersistence.fetchByG_A_NotST_First(groupId, articleId,
                WorkflowConstants.STATUS_IN_TRASH, orderByComparator);
    }

    return journalArticlePersistence.fetchByG_A_ST_First(groupId, articleId, status, orderByComparator);
}

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

License:Open Source License

/**
 * Returns the latest indexable web content article matching the resource
 * primary key.//w  w w  .  ja  va  2  s .com
 *
 * @param  resourcePrimKey the primary key of the resource instance
 * @return the latest indexable web content article matching the resource
 *         primary key, or <code>null</code> if no matching web content
 *         article could be found
 */
@Override
public JournalArticle fetchLatestIndexableArticle(long resourcePrimKey) {
    OrderByComparator<JournalArticle> orderByComparator = new ArticleVersionComparator();

    int[] statuses = new int[] { WorkflowConstants.STATUS_APPROVED, WorkflowConstants.STATUS_IN_TRASH };

    List<JournalArticle> articles = journalArticlePersistence.findByR_I_S(resourcePrimKey, true, statuses, 0, 1,
            orderByComparator);

    if (articles.isEmpty()) {
        return null;
    }

    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);
    }//  w  ww . j a  v  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

/**
 * Moves the latest version of the web content article matching the group
 * and article ID to the recycle bin./*from w  w  w.ja  va 2 s  .  c om*/
 *
 * @param  userId the primary key of the user updating the web content
 *         article
 * @param  article the web content article
 * @return the updated web content article, which was moved to the Recycle
 *         Bin
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle moveArticleToTrash(long userId, JournalArticle article) throws PortalException {

    // Article

    if (article.isInTrash()) {
        throw new TrashEntryException();
    }

    int oldStatus = article.getStatus();

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        article.setStatus(WorkflowConstants.STATUS_DRAFT);
    }

    journalArticlePersistence.update(article);

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

    articleVersions = ListUtil.sort(articleVersions, new ArticleVersionComparator());

    List<ObjectValuePair<Long, Integer>> articleVersionStatusOVPs = new ArrayList<>();

    if ((articleVersions != null) && !articleVersions.isEmpty()) {
        articleVersionStatusOVPs = getArticleVersionStatuses(articleVersions);
    }

    article = updateStatus(userId, article.getId(), WorkflowConstants.STATUS_IN_TRASH,
            new HashMap<String, Serializable>(), new ServiceContext());

    // Trash

    JournalArticleResource articleResource = journalArticleResourceLocalService
            .getArticleResource(article.getResourcePrimKey());

    UnicodeProperties typeSettingsProperties = new UnicodeProperties();

    typeSettingsProperties.put("title", article.getArticleId());

    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, article.getGroupId(),
            JournalArticle.class.getName(), article.getResourcePrimKey(), articleResource.getUuid(), null,
            oldStatus, articleVersionStatusOVPs, typeSettingsProperties);

    String trashArticleId = TrashUtil.getTrashTitle(trashEntry.getEntryId());

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

        journalArticlePersistence.update(articleVersion);
    }

    articleResource.setArticleId(trashArticleId);

    journalArticleResourcePersistence.update(articleResource);

    article.setArticleId(trashArticleId);

    article = journalArticlePersistence.update(article);

    // Asset

    assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(), false);

    // Attachments

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

    // Comment

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

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

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

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(article.getCompanyId(),
                article.getGroupId(), JournalArticle.class.getName(), article.getId());
    }

    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   w w  w .  java2 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.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected JournalArticle getFirstArticle(long groupId, String articleId, int status,
        OrderByComparator<JournalArticle> orderByComparator) throws PortalException {

    if (status == WorkflowConstants.STATUS_ANY) {
        return journalArticlePersistence.findByG_A_NotST_First(groupId, articleId,
                WorkflowConstants.STATUS_IN_TRASH, orderByComparator);
    } else {/*from   w w w  . j a  va  2s  . c o m*/
        return journalArticlePersistence.findByG_A_ST_First(groupId, articleId, status, orderByComparator);
    }
}

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

License:Open Source License

/**
 * Moves the web content article from the Recycle Bin to the folder.
 *
 * @param  groupId the primary key of the web content article's group
 * @param  articleId the primary key of the web content article
 * @param  newFolderId the primary key of the web content article's new
 *         folder//from   w w  w  .java 2 s  .co m
 * @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
 *         com.liferay.portal.kernel.util.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 the folder
 */
@Override
public JournalArticle moveArticleFromTrash(long groupId, String articleId, long newFolderId,
        ServiceContext serviceContext) throws PortalException {

    JournalArticle article = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_IN_TRASH);

    JournalArticlePermission.check(getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);

    return journalArticleLocalService.moveArticleFromTrash(getUserId(), groupId, article, newFolderId,
            serviceContext);
}

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

License:Open Source License

/**
 * Restores the web content article from the Recycle Bin.
 *
 * @param groupId the primary key of the web content article's group
 * @param articleId the primary key of the web content article
 *///  w  w w .  j a v  a 2s. c  o m
@Override
public void restoreArticleFromTrash(long groupId, String articleId) throws PortalException {

    JournalArticle article = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_IN_TRASH);

    restoreArticleFromTrash(article.getResourcePrimKey());
}

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

License:Open Source License

@Override
public JournalFolder moveFolderFromTrash(long userId, long folderId, long parentFolderId,
        ServiceContext serviceContext) throws PortalException {

    JournalFolder folder = journalFolderPersistence.findByPrimaryKey(folderId);

    if (!folder.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }//w ww .j  av a  2 s  . c o  m

    if (folder.isInTrashExplicitly()) {
        restoreFolderFromTrash(userId, folderId);
    } else {

        // Folder

        TrashVersion trashVersion = trashVersionLocalService.fetchVersion(JournalFolder.class.getName(),
                folderId);

        int status = WorkflowConstants.STATUS_APPROVED;

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

        updateStatus(userId, folder, status);

        // Trash

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

        // Folders and articles

        List<Object> foldersAndArticles = journalFolderLocalService.getFoldersAndArticles(folder.getGroupId(),
                folder.getFolderId(), WorkflowConstants.STATUS_IN_TRASH);

        restoreDependentsFromTrash(foldersAndArticles);
    }

    return journalFolderLocalService.moveFolder(folderId, parentFolderId, serviceContext);
}

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

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//w w  w . j a v a 2  s .c om
public JournalFolder moveFolderToTrash(long userId, long folderId) throws PortalException {

    // Folder

    JournalFolder folder = journalFolderPersistence.findByPrimaryKey(folderId);

    if (folder.isInTrash()) {
        throw new TrashEntryException();
    }

    String title = folder.getName();

    folder = updateStatus(userId, folder, WorkflowConstants.STATUS_IN_TRASH);

    // Trash

    UnicodeProperties typeSettingsProperties = new UnicodeProperties();

    typeSettingsProperties.put("title", folder.getName());

    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, folder.getGroupId(),
            JournalFolder.class.getName(), folder.getFolderId(), folder.getUuid(), null,
            WorkflowConstants.STATUS_APPROVED, null, typeSettingsProperties);

    folder.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId()));

    journalFolderPersistence.update(folder);

    // Folders and articles

    List<Object> foldersAndArticles = journalFolderLocalService.getFoldersAndArticles(folder.getGroupId(),
            folder.getFolderId());

    moveDependentsToTrash(foldersAndArticles, trashEntry.getEntryId());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", title);

    SocialActivityManagerUtil.addActivity(userId, folder, SocialActivityConstants.TYPE_MOVE_TO_TRASH,
            extraDataJSONObject.toString(), 0);

    return folder;
}