Example usage for com.liferay.portal.kernel.comment CommentManagerUtil moveDiscussionToTrash

List of usage examples for com.liferay.portal.kernel.comment CommentManagerUtil moveDiscussionToTrash

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.comment CommentManagerUtil moveDiscussionToTrash.

Prototype

public static void moveDiscussionToTrash(String className, long classPK) 

Source Link

Usage

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

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override/*from   w  ww  .ja v a2 s.  c o  m*/
public BlogsEntry updateStatus(long userId, long entryId, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    // Entry

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

    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);

    int oldStatus = entry.getStatus();

    if ((status == WorkflowConstants.STATUS_APPROVED) && now.before(entry.getDisplayDate())) {

        status = WorkflowConstants.STATUS_SCHEDULED;
    }

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

    if ((status == WorkflowConstants.STATUS_APPROVED) && Validator.isNull(entry.getUrlTitle())) {

        entry.setUrlTitle(getUniqueUrlTitle(entryId, entry.getGroupId(), entry.getTitle()));
    }

    blogsEntryPersistence.update(entry);

    // Statistics

    blogsStatsUserLocalService.updateStatsUser(entry.getGroupId(), entry.getUserId(), entry.getDisplayDate());

    AssetEntry assetEntry = assetEntryLocalService.fetchEntry(BlogsEntry.class.getName(), entryId);

    if ((assetEntry == null) || (assetEntry.getPublishDate() == null)) {
        serviceContext.setCommand(Constants.ADD);
    }

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", entry.getTitle());

    if (status == WorkflowConstants.STATUS_APPROVED) {

        // Asset

        assetEntryLocalService.updateEntry(BlogsEntry.class.getName(), entryId, entry.getDisplayDate(), null,
                true, true);

        // Social

        if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH)
                && (oldStatus != WorkflowConstants.STATUS_SCHEDULED)) {

            if (serviceContext.isCommandUpdate()) {
                SocialActivityManagerUtil.addActivity(user.getUserId(), entry, BlogsActivityKeys.UPDATE_ENTRY,
                        extraDataJSONObject.toString(), 0);
            } else {
                SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), entry,
                        BlogsActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), 0);
            }
        }

        // Trash

        if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
            if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
                CommentManagerUtil.restoreDiscussionFromTrash(BlogsEntry.class.getName(), entryId);
            }

            trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entryId);
        }

        if (oldStatus != WorkflowConstants.STATUS_IN_TRASH) {

            // Subscriptions

            notifySubscribers(userId, entry, serviceContext, workflowContext);

            // Ping

            String[] trackbacks = (String[]) serviceContext.getAttribute("trackbacks");
            Boolean pingOldTrackbacks = ParamUtil.getBoolean(serviceContext, "pingOldTrackbacks");

            pingGoogle(entry, serviceContext);
            pingPingback(entry, serviceContext);
            pingTrackbacks(entry, trackbacks, pingOldTrackbacks, serviceContext);
        }
    } else {

        // Asset

        assetEntryLocalService.updateVisible(BlogsEntry.class.getName(), entryId, false);

        // Social

        if ((status == WorkflowConstants.STATUS_SCHEDULED)
                && (oldStatus != WorkflowConstants.STATUS_IN_TRASH)) {

            if (serviceContext.isCommandUpdate()) {
                SocialActivityManagerUtil.addActivity(user.getUserId(), entry, BlogsActivityKeys.UPDATE_ENTRY,
                        extraDataJSONObject.toString(), 0);
            } else {
                SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), entry,
                        BlogsActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), 0);
            }
        }

        // Trash

        if (status == WorkflowConstants.STATUS_IN_TRASH) {
            if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
                CommentManagerUtil.moveDiscussionToTrash(BlogsEntry.class.getName(), entryId);
            }

            trashEntryLocalService.addTrashEntry(userId, entry.getGroupId(), BlogsEntry.class.getName(),
                    entry.getEntryId(), entry.getUuid(), null, oldStatus, null, null);
        } else if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
            if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
                CommentManagerUtil.restoreDiscussionFromTrash(BlogsEntry.class.getName(), entryId);
            }

            trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entryId);
        }
    }

    return entry;
}

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 ww .  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.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

@Override
public WikiPage movePageToTrash(long userId, WikiPage page) throws PortalException {

    if (page.isInTrash()) {
        throw new TrashEntryException();
    }//from   w  w  w .j  a va 2 s.  c o  m

    // Page

    int oldStatus = page.getStatus();
    String oldTitle = page.getTitle();

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

        wikiPagePersistence.update(page);
    }

    List<WikiPage> pageVersions = wikiPagePersistence.findByR_N_H(page.getResourcePrimKey(), page.getNodeId(),
            false);

    pageVersions = ListUtil.sort(pageVersions, new PageVersionComparator());

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

    if ((pageVersions != null) && !pageVersions.isEmpty()) {
        pageVersionStatusOVPs = getPageVersionStatuses(pageVersions);
    }

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

    // Trash

    WikiPageResource pageResource = wikiPageResourcePersistence.fetchByPrimaryKey(page.getResourcePrimKey());

    UnicodeProperties typeSettingsProperties = new UnicodeProperties();

    typeSettingsProperties.put("title", page.getTitle());

    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, page.getGroupId(),
            WikiPage.class.getName(), page.getResourcePrimKey(), page.getUuid(), null, oldStatus,
            pageVersionStatusOVPs, typeSettingsProperties);

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

    for (WikiPage pageVersion : pageVersions) {
        pageVersion.setTitle(trashTitle);
        pageVersion.setStatus(WorkflowConstants.STATUS_IN_TRASH);

        wikiPagePersistence.update(pageVersion);
    }

    pageResource.setTitle(trashTitle);

    wikiPageResourcePersistence.update(pageResource);

    page.setTitle(trashTitle);

    wikiPagePersistence.update(page);

    // Child pages

    moveDependentChildPagesToTrash(page.getNodeId(), oldTitle, trashTitle, trashEntry.getEntryId(), true);

    // Redirect pages

    moveDependentRedirectorPagesToTrash(page.getNodeId(), oldTitle, trashTitle, trashEntry.getEntryId(), true);

    // Asset

    assetEntryLocalService.updateVisible(WikiPage.class.getName(), page.getResourcePrimKey(), false);

    // Attachments

    for (FileEntry fileEntry : page.getAttachmentsFileEntries()) {
        PortletFileRepositoryUtil.movePortletFileEntryToTrash(userId, fileEntry.getFileEntryId());
    }

    // Comment

    CommentManagerUtil.moveDiscussionToTrash(WikiPage.class.getName(), page.getResourcePrimKey());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", TrashUtil.getOriginalTitle(page.getTitle()));
    extraDataJSONObject.put("version", page.getVersion());

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

    // Indexer

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

    indexer.reindex(page);

    // Workflow

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
        workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(page.getCompanyId(), page.getGroupId(),
                WikiPage.class.getName(), page.getPageId());
    }

    return page;
}